improve simulation egornomics a bit

This commit is contained in:
Yehowshua Immanuel 2025-04-19 21:51:30 -04:00
parent f2a464b090
commit 2d9bc945c5
4 changed files with 67 additions and 46 deletions

View file

@ -1,24 +1,37 @@
package Util(
(|>),
BasicResult(..),
simulate_for) where
terminateSimNoError,
terminateSimWithError,
dynamicAssert
) where
import CBindings
infixr 0 |>
data BasicResult = Success
| Failure
deriving (Bits, Eq, FShow)
(|>) :: (a -> b) -> a -> b
f |> x = f x;
simulate_for :: (Bits a n, Arith a, Eq a) => Reg a -> Reg a -> Rules
simulate_for curr_cycle end_cycle =
rules
"count_cycle_rule": when True ==> action
curr_cycle := curr_cycle + 1
if curr_cycle == end_cycle
then
$finish
else
$display "cycle = " curr_cycle
assertMessage :: String -> String -> String
assertMessage which mess =
letseq pos = getStringPosition mess -- get position of original message literal
in (which +++" assertion failed: " +++ printPosition pos +++ mess)
dynamicAssert :: Bool -> String -> Action
dynamicAssert = if not testAssert then (\ _ _ -> noAction)
else (\ b s -> if b then noAction else
action
$display (assertMessage "Dynamic" s)
restoreTerminal
$finish 1
)
terminateSimNoError :: Action
terminateSimNoError = do
restoreTerminal
$finish 0
terminateSimWithError :: Action
terminateSimWithError = do
restoreTerminal
$finish 1