38 lines
920 B
Haskell
38 lines
920 B
Haskell
package Util(
|
|
(|>),
|
|
terminateSimNoError,
|
|
terminateSimWithError,
|
|
dynamicAssert
|
|
) where
|
|
|
|
import CBindings
|
|
|
|
infixr 0 |>
|
|
|
|
(|>) :: (a -> b) -> a -> b
|
|
f |> x = f x;
|
|
|
|
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
|