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

View file

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

View file

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

View file

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