aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-12-23 12:03:20 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-12-23 12:03:20 +0000
commit23abbde989d2809ef2b87f30ce16f58c54f175de (patch)
tree5b6c912b55120d90ffbe8cd7bd8d2e9331392207 /src
parent434c2828ab622c4b9d07a1f1a8a09ede0696f4e0 (diff)
downloadverismith-23abbde989d2809ef2b87f30ce16f58c54f175de.tar.gz
verismith-23abbde989d2809ef2b87f30ce16f58c54f175de.zip
Add nesting to the SourceText
Diffstat (limited to 'src')
-rw-r--r--src/Test/VeriFuzz/Mutate.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Test/VeriFuzz/Mutate.hs b/src/Test/VeriFuzz/Mutate.hs
index dd391fb..3e7acae 100644
--- a/src/Test/VeriFuzz/Mutate.hs
+++ b/src/Test/VeriFuzz/Mutate.hs
@@ -11,6 +11,8 @@ Functions to mutate the Verilog AST from "Test.VeriFuzz.VerilogAST" to generate
more random patterns, such as nesting wires instead of creating new ones.
-}
+{-# LANGUAGE OverloadedStrings #-}
+
module Test.VeriFuzz.Mutate where
import Control.Lens
@@ -32,9 +34,22 @@ findAssign id items =
| ca ^. contAssignNetLVal == id = Just $ ca ^. contAssignExpr
| otherwise = Nothing
+idTrans :: Identifier -> Expression -> Expression -> Expression
+idTrans i expr (PrimExpr (PrimId id))
+ | id == i = expr
+ | otherwise = (PrimExpr (PrimId id))
+idTrans _ _ e = e
+
-- | Nest expressions for a specific 'Identifier'. If the 'Identifier' is not found,
-- the AST is not changed.
nestId :: Identifier -> ModuleDecl -> ModuleDecl
nestId id mod
- | not $ inPort id mod = mod
+ | not $ inPort id mod = mod & get %~ trans
| otherwise = mod
+ where
+ get = moduleItems . traverse . _Assign . contAssignExpr
+ trans = transformOf traverseExpr . idTrans id . PrimExpr . PrimId $ Identifier "RANDOM"
+
+nestSource :: Identifier -> SourceText -> SourceText
+nestSource id src =
+ src & getSourceText . traverse . getDescription %~ nestId id