blob: ca5505c08079a326b705114b9d2c5f22ab9b1b9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
{-|
Module : Test.VeriFuzz.Default
Description : Defaults and common functions.
Copyright : (c) Yann Herklotz Grave 2018
License : GPL-3
Maintainer : ymherklotz@gmail.com
Stability : experimental
Portability : POSIX
Defaults and common functions.
-}
{-# LANGUAGE OverloadedStrings #-}
module Test.VeriFuzz.Helpers where
import Control.Lens
import Data.Text (Text)
import qualified Data.Text
import Test.VeriFuzz.VerilogAST
regDecl :: Text -> ModItem
regDecl = Decl . Port Nothing (Just $ Reg False) . Identifier
wireDecl :: Text -> ModItem
wireDecl = Decl . Port Nothing (Just $ PortNet Wire) . Identifier
modConn :: Text -> ModConn
modConn = ModConn . PrimExpr . PrimId . Identifier
-- | Create a number expression which will be stored in a primary expression.
numExpr :: Int -> Int -> Expression
numExpr = ((PrimExpr . PrimNum) .) . Number
-- | Create an empty module.
emptyMod :: ModDecl
emptyMod = ModDecl (Identifier "") [] []
-- | Set a module name for a module declaration.
setModName :: Text -> ModDecl -> ModDecl
setModName str = moduleId .~ Identifier str
-- | Add a port to the module declaration.
addModPort :: Port -> ModDecl -> ModDecl
addModPort port = modPorts %~ (:) port
addDescription :: Description -> SourceText -> SourceText
addDescription desc = getSourceText %~ (:) desc
testBench :: ModDecl
testBench =
ModDecl "main" []
[ regDecl "a"
, regDecl "b"
, wireDecl "c"
, ModInst "and" "and_gate"
[ modConn "c"
, modConn "a"
, modConn "b"
]
, Initial $ SeqBlock
[ BlockAssign . Assign (RegId "a") Nothing . PrimExpr . PrimNum $ Number 1 1
, BlockAssign . Assign (RegId "b") Nothing . PrimExpr . PrimNum $ Number 1 1
-- , TimeCtrl (Delay 1) . Just . SysTaskEnable $ Task "display"
-- [ ExprStr "%d & %d = %d"
-- , PrimExpr $ PrimId "a"
-- , PrimExpr $ PrimId "b"
-- , PrimExpr $ PrimId "c"
-- ]
-- , SysTaskEnable $ Task "finish" []
]
]
addTestBench :: SourceText -> SourceText
addTestBench = addDescription $ Description testBench
|