aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-12-23 11:25:40 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-12-23 11:25:40 +0000
commit42381c9f461da5c248c0504173012ce386010711 (patch)
treee0da2914da271d1a81b3ace440f6076e2621c4f1 /src
parent5f2aa04817e7a6a9cb93b2ac6a09ad0956d7ab3f (diff)
downloadverismith-42381c9f461da5c248c0504173012ce386010711.tar.gz
verismith-42381c9f461da5c248c0504173012ce386010711.zip
Start implementing the nesting functionality
Diffstat (limited to 'src')
-rw-r--r--src/Test/VeriFuzz/Mutate.hs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/Test/VeriFuzz/Mutate.hs b/src/Test/VeriFuzz/Mutate.hs
index 1c8f44a..dd391fb 100644
--- a/src/Test/VeriFuzz/Mutate.hs
+++ b/src/Test/VeriFuzz/Mutate.hs
@@ -13,7 +13,28 @@ more random patterns, such as nesting wires instead of creating new ones.
module Test.VeriFuzz.Mutate where
+import Control.Lens
+import Data.Maybe (catMaybes)
+import Test.VeriFuzz.Internal.Shared
import Test.VeriFuzz.VerilogAST
-nestId :: ModuleDecl -> Identifier -> ModuleDecl
-nestId mod id = (error "FIXME: nestId")
+-- | Return if the 'Identifier' is in a 'ModuleDecl'.
+inPort :: Identifier -> ModuleDecl -> Bool
+inPort id mod = any (\a -> a ^. portName == id) $ mod ^. modPorts
+
+-- | Find the last assignment of a specific wire/reg to an expression, and
+-- returns that expression.
+findAssign :: Identifier -> [ModuleItem] -> Maybe Expression
+findAssign id items =
+ safe last . catMaybes $ isAssign <$> items
+ where
+ isAssign (Assign ca)
+ | ca ^. contAssignNetLVal == id = Just $ ca ^. contAssignExpr
+ | otherwise = Nothing
+
+-- | 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
+ | otherwise = mod