aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2019-02-02 13:44:07 +0000
committerYann Herklotz <ymherklotz@gmail.com>2019-02-02 13:44:07 +0000
commite14fbc146d93bdebbf22c0a9ceb58ee3459de4b7 (patch)
tree1faed956889009651ba799a39e93e78afae1adf3 /src
parent533415896b4bf22ad98b4758122c98eb555768df (diff)
downloadverismith-e14fbc146d93bdebbf22c0a9ceb58ee3459de4b7.tar.gz
verismith-e14fbc146d93bdebbf22c0a9ceb58ee3459de4b7.zip
Add mutation to declare other wires
Diffstat (limited to 'src')
-rw-r--r--src/VeriFuzz/Gen.hs35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/VeriFuzz/Gen.hs b/src/VeriFuzz/Gen.hs
index 9eecdbf..5bf1af1 100644
--- a/src/VeriFuzz/Gen.hs
+++ b/src/VeriFuzz/Gen.hs
@@ -13,6 +13,7 @@ Various useful generators.
module VeriFuzz.Gen where
import Control.Lens
+import Data.Foldable (fold)
import qualified Data.Text as T
import Test.QuickCheck (Gen)
import qualified Test.QuickCheck as QC
@@ -21,6 +22,18 @@ import VeriFuzz.ASTGen
import VeriFuzz.Mutate
import VeriFuzz.Random
+toId :: Int -> Identifier
+toId = Identifier . ("w"<>) . T.pack . show
+
+toPort :: Identifier -> Gen Port
+toPort ident = do
+ i <- abs <$> QC.arbitrary
+ return $ Port Wire i ident
+
+sumSize :: [Port] -> Int
+sumSize ports =
+ sum $ ports ^.. traverse . portSize
+
random :: [Identifier] -> (Expr -> ContAssign) -> Gen ModItem
random ctx fun = do
expr <- QC.sized (exprWithContext ctx)
@@ -29,14 +42,22 @@ random ctx fun = do
randomAssigns :: [Identifier] -> [Gen ModItem]
randomAssigns ids = random ids . ContAssign <$> ids
-randomMod :: Gen ModDecl
-randomMod = do
- let ids = toId <$> [1..100]
- sequence_ $ randomAssigns ids
- return $ ModDecl "" [] [] []
+randomOrdAssigns :: [Identifier] -> [Identifier] -> [Gen ModItem]
+randomOrdAssigns inp ids =
+ snd $ foldr gen (inp, []) ids
where
- toId :: Int -> Identifier
- toId = Identifier . ("w"<>) . T.pack . show
+ gen cid (i, o) = (cid : i, o ++ [random i $ ContAssign cid])
+
+randomMod :: Int -> Int -> Gen ModDecl
+randomMod inps total = do
+ let ids = toId <$> [1..total]
+ x <- sequence . randomOrdAssigns (take inps ids) $ drop inps ids
+ ident <- sequence $ toPort <$> ids
+ let inputs = take inps ident
+ let other = drop inps ident
+ let y = ModCA . ContAssign "y" . fold $ Id <$> drop inps ids
+ let yport = [Port Wire (sumSize other) "y"]
+ return . initMod . declareMod other .ModDecl "test_module" yport inputs $ x ++ [y]
fromGraph :: Gen ModDecl
fromGraph = do