aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Icarus.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/VeriFuzz/Icarus.hs')
-rw-r--r--src/VeriFuzz/Icarus.hs61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/VeriFuzz/Icarus.hs b/src/VeriFuzz/Icarus.hs
index 45e932f..f848958 100644
--- a/src/VeriFuzz/Icarus.hs
+++ b/src/VeriFuzz/Icarus.hs
@@ -52,21 +52,24 @@ defaultIcarus = Icarus "iverilog" "vvp"
addDisplay :: [Stmnt] -> [Stmnt]
addDisplay s = concat $ transpose
- [s, replicate l $ TimeCtrl 1 Nothing, replicate l . SysTaskEnable $ Task "display" ["%b", Id "y"]]
- where l = length s
+ [ s
+ , replicate l $ TimeCtrl 1 Nothing
+ , replicate l . SysTaskEnable $ Task "display" ["%b", Id "y"]
+ ]
+ where l = length s
assignFunc :: [Port] -> ByteString -> Stmnt
assignFunc inp bs = NonBlockAssign . Assign conc Nothing . Number (B.length bs * 8) $ bsToI bs
- where conc = RegConcat (portToExpr <$> inp)
+ where conc = RegConcat (portToExpr <$> inp)
convert :: Text -> ByteString
convert =
- toStrict
- . (encode :: Integer -> L.ByteString)
- . maybe 0 fst
- . listToMaybe
- . readInt 2 (`elem` ("01" :: String)) digitToInt
- . T.unpack
+ toStrict
+ . (encode :: Integer -> L.ByteString)
+ . maybe 0 fst
+ . listToMaybe
+ . readInt 2 (`elem` ("01" :: String)) digitToInt
+ . T.unpack
mask :: Text -> Text
mask = T.replace "x" "0"
@@ -76,26 +79,26 @@ callback b t = b <> convert (mask t)
runSimIcarus :: Icarus -> ModDecl -> [ByteString] -> Sh ByteString
runSimIcarus sim m bss = do
- let tb = ModDecl
- "main"
- []
- []
- [ Initial
- $ fold (addDisplay $ assignFunc (m ^. modInPorts) <$> bss)
- <> (SysTaskEnable $ Task "finish" [])
- ]
- let newtb = instantiateMod m tb
- let modWithTb = VerilogSrc $ Description <$> [newtb, m]
- writefile "main.v" $ genSource modWithTb
- runSimWithFile sim "main.v" bss
+ let tb = ModDecl
+ "main"
+ []
+ []
+ [ Initial
+ $ fold (addDisplay $ assignFunc (m ^. modInPorts) <$> bss)
+ <> (SysTaskEnable $ Task "finish" [])
+ ]
+ let newtb = instantiateMod m tb
+ let modWithTb = VerilogSrc $ Description <$> [newtb, m]
+ writefile "main.v" $ genSource modWithTb
+ runSimWithFile sim "main.v" bss
runSimIcarusWithFile :: Icarus -> FilePath -> [ByteString] -> Sh ByteString
runSimIcarusWithFile sim f _ = do
- dir <- pwd
- echoP "Icarus: Compile"
- _ <- logger dir "icarus" $ run (icarusPath sim) ["-o", "main", toTextIgnore f]
- echoP "Icarus: Run"
- B.take 8 . BA.convert . (hash :: ByteString -> Digest SHA256) <$> logger
- dir
- "vvp"
- (runFoldLines (mempty :: ByteString) callback (vvpPath sim) ["main"])
+ dir <- pwd
+ echoP "Icarus: Compile"
+ _ <- logger dir "icarus" $ run (icarusPath sim) ["-o", "main", toTextIgnore f]
+ echoP "Icarus: Run"
+ B.take 8 . BA.convert . (hash :: ByteString -> Digest SHA256) <$> logger
+ dir
+ "vvp"
+ (runFoldLines (mempty :: ByteString) callback (vvpPath sim) ["main"])