aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-12-04 16:54:56 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-12-04 16:54:56 +0000
commitd08ff5fbf2b40746cacc8e799f6c7b5b0b932669 (patch)
treeaabda213406a77af5b8b1b59239cf9c174f89c78 /src
parent3d5626b32bb66b66a503dd60995d7ece80084d56 (diff)
downloadverismith-d08ff5fbf2b40746cacc8e799f6c7b5b0b932669.tar.gz
verismith-d08ff5fbf2b40746cacc8e799f6c7b5b0b932669.zip
[Fix #1] Fix the negative number generation
Diffstat (limited to 'src')
-rw-r--r--src/Test/VeriFuzz/CodeGen.hs5
-rw-r--r--src/Test/VeriFuzz/VerilogAST.hs2
2 files changed, 5 insertions, 2 deletions
diff --git a/src/Test/VeriFuzz/CodeGen.hs b/src/Test/VeriFuzz/CodeGen.hs
index eb99d6b..85f1d1c 100644
--- a/src/Test/VeriFuzz/CodeGen.hs
+++ b/src/Test/VeriFuzz/CodeGen.hs
@@ -58,9 +58,12 @@ genExpr _ = "TODO"
genPrimary :: Primary -> Text
genPrimary (PrimNum num) =
- sh (num ^. numSize) <> "'d" <> sh (num ^. numVal)
+ neg <> sh (num ^. numSize) <> "'d" <> (sh . abs) n
where
sh = T.pack . show
+ abs x = if x <= 0 then -x else x
+ n = num ^. numVal
+ neg = if n <= 0 then "-" else ""
genPrimary (PrimId ident) = ident ^. getIdentifier
genBinaryOperator :: BinaryOperator -> Text
diff --git a/src/Test/VeriFuzz/VerilogAST.hs b/src/Test/VeriFuzz/VerilogAST.hs
index 48d01a5..41c855a 100644
--- a/src/Test/VeriFuzz/VerilogAST.hs
+++ b/src/Test/VeriFuzz/VerilogAST.hs
@@ -77,7 +77,7 @@ instance QC.Arbitrary Identifier where
(QC.shuffle (['a'..'z'] <> ['A'..'Z']) >>= QC.sublistOf)
instance QC.Arbitrary Number where
- arbitrary = Number <$> QC.arbitrary <*> QC.arbitrary
+ arbitrary = Number <$> (suchThat QC.arbitrary (>=0)) <*> QC.arbitrary
instance QC.Arbitrary BinaryOperator where
arbitrary = QC.elements [BinAnd, BinOr, BinXor]