aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2019-01-01 14:20:07 +0100
committerYann Herklotz <ymherklotz@gmail.com>2019-01-01 14:20:07 +0100
commit45b60c6cafd2949dbbd9eafdbb433e20668a0a87 (patch)
tree414bb8686af2efc39f0e6a66f07b02725c4d4b69 /src
parent50f0039fb733cef73a749c098b63fff202641ea1 (diff)
downloadverismith-45b60c6cafd2949dbbd9eafdbb433e20668a0a87.tar.gz
verismith-45b60c6cafd2949dbbd9eafdbb433e20668a0a87.zip
Add string instance to expression
Diffstat (limited to 'src')
-rw-r--r--src/Test/VeriFuzz/Verilog/AST.hs54
1 files changed, 42 insertions, 12 deletions
diff --git a/src/Test/VeriFuzz/Verilog/AST.hs b/src/Test/VeriFuzz/Verilog/AST.hs
index 83616dc..8a4692e 100644
--- a/src/Test/VeriFuzz/Verilog/AST.hs
+++ b/src/Test/VeriFuzz/Verilog/AST.hs
@@ -23,6 +23,9 @@ import qualified Test.QuickCheck as QC
import Test.VeriFuzz.Circuit
import Test.VeriFuzz.Graph.Random
+-- | 'Source' class which determines that source code is able to be generated
+-- from the data structure using 'genSource'. This will be stored in 'Text' and
+-- can then be processed further.
class Source a where
genSource :: a -> Text
@@ -41,14 +44,22 @@ instance Semigroup Identifier where
instance Monoid Identifier where
mempty = Identifier mempty
+-- | Verilog syntax for adding a delay, which is represented as @#num@.
newtype Delay = Delay { _delay :: Int }
deriving (Eq)
+-- | Verilog syntax for an event, such as @\@x@, which is used for always blocks
data Event = EId Identifier
| EExpr Expr
| EAll
deriving (Eq)
+-- | Type that represents the left hand side of an assignment, which can be a
+-- concatenation such as in:
+--
+-- @
+-- {a, b, c} = 32'h94238;
+-- @
data LVal = RegId Identifier
| RegExpr { _regExprId :: Identifier
, _regExpr :: Expr
@@ -108,17 +119,17 @@ data Expr = Number { _numSize :: Int
}
| Id { _exprId :: Identifier }
| Concat { _concatExpr :: [Expr] }
- | UnOp { _exprUnOp :: UnaryOperator
- , _exprPrim :: Expr
- }
- | BinOp { _exprLhs :: Expr
- , _exprBinOp :: BinaryOperator
- , _exprRhs :: Expr
- }
- | Cond { _exprCond :: Expr
- , _exprTrue :: Expr
- , _exprFalse :: Expr
- }
+ | UnOp { _exprUnOp :: UnaryOperator
+ , _exprPrim :: Expr
+ }
+ | BinOp { _exprLhs :: Expr
+ , _exprBinOp :: BinaryOperator
+ , _exprRhs :: Expr
+ }
+ | Cond { _exprCond :: Expr
+ , _exprTrue :: Expr
+ , _exprFalse :: Expr
+ }
| Str { _exprStr :: Text }
deriving (Eq)
@@ -138,6 +149,10 @@ instance Monoid Expr where
mempty = 0
mconcat = Concat
+instance IsString Expr where
+ fromString = Str . fromString
+
+-- | Constant expression, which are known before simulation at compilation time.
newtype ConstExpr = ConstExpr { _constNum :: Int }
deriving (Eq)
@@ -155,16 +170,31 @@ data PortDir = PortIn -- ^ Input direction for port (@input@).
| PortInOut -- ^ Inout direction for port (@inout@).
deriving (Eq)
+-- | Currently, only @wire@ and @reg@ are supported, as the other net types are
+-- not that common and not a priority.
data PortType = Wire
| Reg { _regSigned :: Bool }
deriving (Eq)
--- | Port declaration.
+-- | Port declaration. It contains information about the type of the port, the
+-- size, and the port name. It used to also contain information about if it was
+-- an input or output port. However, this is not always necessary and was more
+-- cumbersome than useful, as a lot of ports can be declared without input and
+-- output port.
+--
+-- This is now implemented inside 'ModDecl' itself, which uses a list of output
+-- and input ports.
data Port = Port { _portType :: PortType
, _portSize :: Int
, _portName :: Identifier
} deriving (Eq)
+-- | This is currently a type because direct module declaration should also be
+-- added:
+--
+-- @
+-- mod a(.y(y1), .x1(x11), .x2(x22));
+-- @
newtype ModConn = ModConn { _modConn :: Expr }
deriving (Eq)