aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2019-01-09 18:44:34 +0000
committerYann Herklotz <ymherklotz@gmail.com>2019-01-09 18:44:34 +0000
commitf82c12ecccbdf1e185a95bed8c8382936903f976 (patch)
treeaea6b4b1bc16d18e45ce951419047e08dbd61ee4 /src
parent4476d87f229aa4615d9b42f1124b657361a110c3 (diff)
downloadverismith-f82c12ecccbdf1e185a95bed8c8382936903f976.tar.gz
verismith-f82c12ecccbdf1e185a95bed8c8382936903f976.zip
[Fix #20] Add more examples and finish makeTop
Diffstat (limited to 'src')
-rw-r--r--src/Test/VeriFuzz/Verilog/Mutate.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Test/VeriFuzz/Verilog/Mutate.hs b/src/Test/VeriFuzz/Verilog/Mutate.hs
index ab9f0ac..367516a 100644
--- a/src/Test/VeriFuzz/Verilog/Mutate.hs
+++ b/src/Test/VeriFuzz/Verilog/Mutate.hs
@@ -76,6 +76,9 @@ nestUpTo :: Int -> VerilogSrc -> VerilogSrc
nestUpTo i src =
foldl (flip nestSource) src $ Identifier . fromNode <$> [1..i]
+allVars :: ModDecl -> [Identifier]
+allVars mod =
+ (mod ^.. modOutPorts . traverse . portName) ++ (mod ^.. modInPorts . traverse . portName)
-- $setup
-- >>> let mod = (ModDecl (Identifier "m") [Port Wire 5 (Identifier "y")] [Port Wire 5 "x"] [])
-- >>> let main = (ModDecl "main" [] [] [])
@@ -99,6 +102,18 @@ instantiateMod mod main =
regIn = Decl Nothing <$> (mod ^. modInPorts & traverse . portType .~ Reg False)
inst = ModInst (mod ^. moduleId) (mod ^. moduleId <> (Identifier . showT $ count+1)) conns
count = length . filter (==mod ^. moduleId) $ main ^.. moduleItems . traverse . modInstId
+ conns = ModConn . Id <$> allVars mod
+
+-- | Instantiate without adding wire declarations. It also does not count the
+-- current instantiations of the same module.
+--
+-- >>> instantiateMod_ mod main
+-- m m(y, x);
+-- <BLANKLINE>
+instantiateMod_ :: ModDecl -> ModItem
+instantiateMod_ mod =
+ ModInst (mod ^. moduleId) (mod ^. moduleId) conns
+ where
conns = ModConn . Id <$>
(mod ^.. modOutPorts . traverse . portName) ++ (mod ^.. modInPorts . traverse . portName)
@@ -115,3 +130,19 @@ initMod mod = mod & moduleItems %~ ((out ++ inp)++)
where
out = Decl (Just PortOut) <$> (mod ^. modOutPorts)
inp = Decl (Just PortIn) <$> (mod ^. modInPorts)
+
+makeIdFrom :: (Show a) => a -> Identifier -> Identifier
+makeIdFrom a i =
+ (i<>) . Identifier . ("_"<>) $ showT a
+
+-- | Make top level module for equivalence verification. Also takes in how many
+-- modules to instantiate.
+makeTop :: Int -> ModDecl -> ModDecl
+makeTop i m =
+ ModDecl (m ^. moduleId) ys (m ^. modInPorts) modItems
+ where
+ ys = Port Wire 90 . (flip makeIdFrom) "y" <$> [1..i]
+ modItems = instantiateMod_ . modN <$> [1..i]
+ modN n = m
+ & moduleId %~ makeIdFrom n
+ & modOutPorts .~ [Port Wire 90 (makeIdFrom n "y")]