diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-31 13:06:56 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-12-31 13:06:56 +0100 |
commit | b679d2c6b19f647a3af98019426dfd05e8e103e9 (patch) | |
tree | bacc46287a4f2bdb7fbac59c0dc3c983342d23ea | |
parent | 619965e928c10caf6fe430cf09c9bc09352ba071 (diff) | |
download | verismith-b679d2c6b19f647a3af98019426dfd05e8e103e9.tar.gz verismith-b679d2c6b19f647a3af98019426dfd05e8e103e9.zip |
Finish module instantiation
-rw-r--r-- | src/Test/VeriFuzz/Verilog/AST.hs | 6 | ||||
-rw-r--r-- | src/Test/VeriFuzz/Verilog/Mutate.hs | 15 | ||||
-rw-r--r-- | verifuzz.cabal | 1 |
3 files changed, 16 insertions, 6 deletions
diff --git a/src/Test/VeriFuzz/Verilog/AST.hs b/src/Test/VeriFuzz/Verilog/AST.hs index 3ae595f..85c3e99 100644 --- a/src/Test/VeriFuzz/Verilog/AST.hs +++ b/src/Test/VeriFuzz/Verilog/AST.hs @@ -385,6 +385,12 @@ instance QC.Arbitrary VerilogSrc where instance IsString Identifier where fromString = Identifier . T.pack +instance Semigroup Identifier where + (Identifier a) <> (Identifier b) = Identifier (a <> b) + +instance Monoid Identifier where + mempty = Identifier mempty + -- Traversal Instance traverseExpr :: Traversal' Expression Expression diff --git a/src/Test/VeriFuzz/Verilog/Mutate.hs b/src/Test/VeriFuzz/Verilog/Mutate.hs index 847d890..1d58007 100644 --- a/src/Test/VeriFuzz/Verilog/Mutate.hs +++ b/src/Test/VeriFuzz/Verilog/Mutate.hs @@ -20,10 +20,6 @@ import Test.VeriFuzz.Internal.Shared import Test.VeriFuzz.Verilog.AST import Test.VeriFuzz.Verilog.CodeGen --- $setup --- >>> let mod = (ModDecl (Identifier "m") [Port (PortNet Wire) 5 (Identifier "y")] [Port (PortNet Wire) 5 "x"] []) --- >>> let main = (ModDecl "main" [] [] []) - -- | Return if the 'Identifier' is in a 'ModDecl'. inPort :: Identifier -> ModDecl -> Bool inPort id mod = inInput @@ -80,6 +76,10 @@ nestUpTo :: Int -> VerilogSrc -> VerilogSrc nestUpTo i src = foldl (flip nestSource) src $ Identifier . fromNode <$> [1..i] +-- $setup +-- >>> let mod = (ModDecl (Identifier "m") [Port (PortNet Wire) 5 (Identifier "y")] [Port (PortNet Wire) 5 "x"] []) +-- >>> let main = (ModDecl "main" [] [] []) + -- | Add a Module Instantiation using 'ModInst' from the first module passed to -- it to the body of the second module. It first has to make all the inputs into -- @reg@. @@ -88,14 +88,19 @@ nestUpTo i src = -- module main; -- wire [4:0] y; -- reg [4:0] x; +-- m m1(y, x); -- endmodule -- <BLANKLINE> instantiateMod :: ModDecl -> ModDecl -> ModDecl instantiateMod mod main = - main & moduleItems %~ ((out ++ regIn)++) + main & moduleItems %~ ((out ++ regIn ++ [inst])++) where out = Decl Nothing <$> mod ^. modOutPorts 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 . PrimExpr . PrimId <$> + (mod ^.. modOutPorts . traverse . portName) ++ (mod ^.. modInPorts . traverse . portName) -- | Initialise all the inputs and outputs to a module. -- diff --git a/verifuzz.cabal b/verifuzz.cabal index 56ba3cd..fcc4965 100644 --- a/verifuzz.cabal +++ b/verifuzz.cabal @@ -92,7 +92,6 @@ test-suite verifuzz-test test-suite verifuzz-doctest default-language: Haskell2010 type: exitcode-stdio-1.0 - ghc-options: -threaded hs-source-dirs: tests main-is: Doctest.hs build-depends: base >= 4 && < 5 |