aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/VeriFuzz/Internal')
-rw-r--r--src/VeriFuzz/Internal/AST.hs72
-rw-r--r--src/VeriFuzz/Internal/Simulator.hs13
2 files changed, 79 insertions, 6 deletions
diff --git a/src/VeriFuzz/Internal/AST.hs b/src/VeriFuzz/Internal/AST.hs
new file mode 100644
index 0000000..b8f569b
--- /dev/null
+++ b/src/VeriFuzz/Internal/AST.hs
@@ -0,0 +1,72 @@
+{-|
+Module : VeriFuzz.Internal.AST
+Description : Defaults and common functions.
+Copyright : (c) 2018-2019, Yann Herklotz Grave
+License : BSD-3
+Maintainer : ymherklotz [at] gmail [dot] com
+Stability : experimental
+Portability : POSIX
+
+Defaults and common functions.
+-}
+
+module VeriFuzz.Internal.AST where
+
+import Control.Lens
+import Data.Text (Text)
+import VeriFuzz.AST
+
+regDecl :: Identifier -> ModItem
+regDecl = Decl Nothing . Port (Reg False) 1
+
+wireDecl :: Identifier -> ModItem
+wireDecl = Decl Nothing . Port Wire 1
+
+-- | Create an empty module.
+emptyMod :: ModDecl
+emptyMod = ModDecl "" [] [] []
+
+-- | Set a module name for a module declaration.
+setModName :: Text -> ModDecl -> ModDecl
+setModName str = modId .~ Identifier str
+
+-- | Add a input port to the module declaration.
+addModPort :: Port -> ModDecl -> ModDecl
+addModPort port = modInPorts %~ (:) port
+
+addDescription :: Description -> VerilogSrc -> VerilogSrc
+addDescription desc = getVerilogSrc %~ (:) desc
+
+testBench :: ModDecl
+testBench = ModDecl
+ "main"
+ []
+ []
+ [ regDecl "a"
+ , regDecl "b"
+ , wireDecl "c"
+ , ModInst "and" "and_gate" [ModConn $ Id "c", ModConn $ Id "a", ModConn $ Id "b"]
+ , Initial $ SeqBlock
+ [ BlockAssign . Assign (RegId "a") Nothing $ Number 1 1
+ , BlockAssign . Assign (RegId "b") Nothing $ Number 1 1
+ -- , TimeCtrl (Delay 1) . Just . SysTaskEnable $ Task "display"
+ -- [ Str "%d & %d = %d"
+ -- , PrimExpr $ PrimId "a"
+ -- , PrimExpr $ PrimId "b"
+ -- , PrimExpr $ PrimId "c"
+ -- ]
+ -- , SysTaskEnable $ Task "finish" []
+ ]
+ ]
+
+addTestBench :: VerilogSrc -> VerilogSrc
+addTestBench = addDescription $ Description testBench
+
+defaultPort :: Identifier -> Port
+defaultPort = Port Wire 1
+
+portToExpr :: Port -> Expr
+portToExpr (Port _ _ i) = Id i
+
+modName :: ModDecl -> Text
+modName = view $ modId . getIdentifier
diff --git a/src/VeriFuzz/Internal/Simulator.hs b/src/VeriFuzz/Internal/Simulator.hs
index 4f8fd5a..0abdf8f 100644
--- a/src/VeriFuzz/Internal/Simulator.hs
+++ b/src/VeriFuzz/Internal/Simulator.hs
@@ -14,13 +14,14 @@ Template file for different configuration files.
module VeriFuzz.Internal.Simulator where
-import Data.Text (Text)
-import qualified Data.Text as T
-import Prelude hiding (FilePath)
+import Data.Text (Text)
+import qualified Data.Text as T
+import Prelude hiding (FilePath)
import Shelly
-import Text.Shakespeare.Text (st)
-import VeriFuzz.Simulator.General
-import VeriFuzz.Verilog
+import Text.Shakespeare.Text (st)
+import VeriFuzz.AST
+import VeriFuzz.General
+import VeriFuzz.Internal.AST
-- brittany-disable-next-binding
yosysSatConfig :: (Simulator a, Simulator b) => a -> Maybe b -> ModDecl -> Text