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,7 +1,6 @@
package TagEngine(
MkTagType,
MkTagType(..),
TagEngine(..),
Util.BasicResult(..),
mkTagEngine) where
import Vector

View file

@ -2,6 +2,10 @@ package TagEngineTester(mkTagEngineTester) where
import TagEngine
import ActionSeq
import Printf
import Util
type NumTags = 5
mkTagEngineTester :: Module Empty
mkTagEngineTester = do
@ -26,39 +30,44 @@ mkTagEngineTester = do
in
actionSeq $
do requestTagAction
|> do requestTagAction
|> do requestTagAction
|> do requestTagAction
|> do requestTagAction
do
let expectedTag = 4
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
let expectedTag = 3
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
let expectedTag = 2
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
let expectedTag = 1
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
let expectedTag = 0
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do retireTagAction 2
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|> do
retireTagAction 4
requestTagAction
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
let expectedTag :: MkTagType NumTags
expectedTag = 2
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
retireTagAction 4
requestTagAction
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
|> do $finish
-- |> do retireTagAction 4
-- |> do retireTagAction 4
-- |> do retireTagAction 0
-- |> do requestTagAction
-- |> do requestTagAction
-- |> do retireTagAction 1
-- |> do requestTagAction
-- |> do $finish
retireTagAction 2
let expectedTag = 3
tag <- tagEngine.requestTag
dynamicAssert (tag == expectedTag) ""
|> do
terminateSimNoError
addRules $
rules
-- "counter": when True ==>
-- do
-- count := count + 1
-- $display "count : " (fshow count)
"testIncrement": when (runOnce == False) ==>
"start unit test": when (runOnce == False) ==>
do
s.start
runOnce := True

View file

@ -7,9 +7,9 @@ import BRAM
import CBindings
import Bus
import TagEngine
import List
import ActionSeq
import Vector
import BusTypes

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