aboutsummaryrefslogtreecommitdiffstats
path: root/src/Test/VeriFuzz/Verilog/Mutate.hs
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-12-30 19:44:40 +0100
committerYann Herklotz <ymherklotz@gmail.com>2018-12-30 19:44:40 +0100
commitcabb2cec0bde620c49b1d7a36cd8226f579c1023 (patch)
treea3f0cfcd487f5c58179706d75f5ef70917c9a760 /src/Test/VeriFuzz/Verilog/Mutate.hs
parent9f2bb8aff3198d36ac847dde67e4e630cd8b889f (diff)
downloadverismith-cabb2cec0bde620c49b1d7a36cd8226f579c1023.tar.gz
verismith-cabb2cec0bde620c49b1d7a36cd8226f579c1023.zip
[Fix #13, Fix #15] Fix type errors and add inst functions
Diffstat (limited to 'src/Test/VeriFuzz/Verilog/Mutate.hs')
-rw-r--r--src/Test/VeriFuzz/Verilog/Mutate.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Test/VeriFuzz/Verilog/Mutate.hs b/src/Test/VeriFuzz/Verilog/Mutate.hs
index 6993fef..e9d7aed 100644
--- a/src/Test/VeriFuzz/Verilog/Mutate.hs
+++ b/src/Test/VeriFuzz/Verilog/Mutate.hs
@@ -21,11 +21,9 @@ import Test.VeriFuzz.Verilog.AST
-- | Return if the 'Identifier' is in a 'ModDecl'.
inPort :: Identifier -> ModDecl -> Bool
-inPort id mod = inInput || inOutput
+inPort id mod = inInput
where
- inInput = any (\a -> a ^. portName == id) $ mod ^. modInPorts
- inOutput = fromMaybe False . safe head $ (==id) <$>
- mod ^.. modOutPort . _Just . portName
+ inInput = any (\a -> a ^. portName == id) $ mod ^. modInPorts ++ mod ^. modOutPorts
-- | Find the last assignment of a specific wire/reg to an expression, and
-- returns that expression.
@@ -78,12 +76,17 @@ nestUpTo i src =
foldl (flip nestSource) src $ Identifier . fromNode <$> [1..i]
-- | Add a Module Instantiation using 'ModInst' from the first module passed to
--- it to the body of the second module.
+-- it to the body of the second module. It first has to make all the inputs into
+-- @reg@.
instantiateMod :: ModDecl -> ModDecl -> ModDecl
instantiateMod mod main =
- main
+ main & moduleItems %~ ((out ++ regIn)++)
+ where
+ out = Decl <$> mod ^. modOutPorts
+ regIn = Decl <$> (mod ^. modInPorts & traverse . portType .~ Reg False)
-- | Initialise all the inputs and outputs to a module.
initMod :: ModDecl -> ModDecl
-initMod mod =
- mod
+initMod mod = mod & moduleItems %~ (inOut++)
+ where
+ inOut = Decl <$> (mod ^. modOutPorts) ++ (mod ^. modInPorts)