Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Identifier = String
- data Binop (inTp :: BaseType) (outTp :: BaseType) where
- And :: Binop BaseBoolType BaseBoolType
- Or :: Binop BaseBoolType BaseBoolType
- Xor :: Binop BaseBoolType BaseBoolType
- Eq :: Binop tp BaseBoolType
- Ne :: Binop tp BaseBoolType
- Lt :: Binop (BaseBVType w) BaseBoolType
- Le :: Binop (BaseBVType w) BaseBoolType
- BVAnd :: Binop (BaseBVType w) (BaseBVType w)
- BVOr :: Binop (BaseBVType w) (BaseBVType w)
- BVXor :: Binop (BaseBVType w) (BaseBVType w)
- BVAdd :: Binop (BaseBVType w) (BaseBVType w)
- BVSub :: Binop (BaseBVType w) (BaseBVType w)
- BVMul :: Binop (BaseBVType w) (BaseBVType w)
- BVDiv :: Binop (BaseBVType w) (BaseBVType w)
- BVRem :: Binop (BaseBVType w) (BaseBVType w)
- BVPow :: Binop (BaseBVType w) (BaseBVType w)
- BVShiftL :: Binop (BaseBVType w) (BaseBVType w)
- BVShiftR :: Binop (BaseBVType w) (BaseBVType w)
- BVShiftRA :: Binop (BaseBVType w) (BaseBVType w)
- binopType :: Binop inTp outTp -> BaseTypeRepr inTp -> BaseTypeRepr outTp
- data Unop (tp :: BaseType) where
- Not :: Unop BaseBoolType
- BVNot :: Unop (BaseBVType w)
- data IExp (tp :: BaseType) where
- Ident :: BaseTypeRepr tp -> Identifier -> IExp tp
- iexpType :: IExp tp -> BaseTypeRepr tp
- data LHS
- data Exp (tp :: BaseType) where
- IExp :: IExp tp -> Exp tp
- Binop :: Binop inTp outTp -> IExp inTp -> IExp inTp -> Exp outTp
- Unop :: Unop tp -> IExp tp -> Exp tp
- BVRotateL :: NatRepr w -> IExp tp -> BV w -> Exp tp
- BVRotateR :: NatRepr w -> IExp tp -> BV w -> Exp tp
- Mux :: IExp BaseBoolType -> IExp tp -> IExp tp -> Exp tp
- Bit :: IExp (BaseBVType w) -> Integer -> Exp BaseBoolType
- BitSelect :: (1 <= len, (start + len) <= w) => IExp (BaseBVType w) -> NatRepr start -> NatRepr len -> Exp (BaseBVType len)
- Concat :: 1 <= w => NatRepr w -> [Some IExp] -> Exp (BaseBVType w)
- BVLit :: 1 <= w => NatRepr w -> BV w -> Exp (BaseBVType w)
- BoolLit :: Bool -> Exp BaseBoolType
- expType :: Exp tp -> BaseTypeRepr tp
- mkLet :: Exp tp -> VerilogM sym n (IExp tp)
- signed :: IExp tp -> VerilogM sym n (IExp tp)
- binop :: Binop inTp outTp -> IExp inTp -> IExp inTp -> VerilogM sym n (IExp outTp)
- scalMult :: 1 <= w => NatRepr w -> Binop (BaseBVType w) (BaseBVType w) -> BV w -> IExp (BaseBVType w) -> VerilogM sym n (IExp (BaseBVType w))
- data BVConst = BVConst (Pair NatRepr BV)
- litBV :: 1 <= w => NatRepr w -> BV w -> VerilogM sym n (IExp (BaseBVType w))
- litBool :: Bool -> VerilogM sym n (IExp BaseBoolType)
- unop :: Unop tp -> IExp tp -> VerilogM sym n (IExp tp)
- mux :: IExp BaseBoolType -> IExp tp -> IExp tp -> VerilogM sym n (IExp tp)
- bit :: IExp (BaseBVType w) -> Integer -> VerilogM sym n (IExp BaseBoolType)
- bitSelect :: (1 <= len, (idx + len) <= w) => IExp (BaseBVType w) -> NatRepr idx -> NatRepr len -> VerilogM sym n (IExp (BaseBVType len))
- concat2 :: (w ~ (w1 + w2), 1 <= w) => NatRepr w -> IExp (BaseBVType w1) -> IExp (BaseBVType w2) -> VerilogM sym n (IExp (BaseBVType w))
- data Item where
- Input :: BaseTypeRepr tp -> Identifier -> Item
- Output :: BaseTypeRepr tp -> Identifier -> Item
- Wire :: BaseTypeRepr tp -> Identifier -> Item
- Assign :: LHS -> Exp tp -> Item
- data ModuleState sym n = ModuleState {
- vsInputs :: [(Some BaseTypeRepr, Identifier)]
- vsOutputs :: [(Some BaseTypeRepr, Bool, Identifier, Some Exp)]
- vsWires :: [(Some BaseTypeRepr, Bool, Identifier, Some Exp)]
- vsFreshIdent :: Int
- vsExpCache :: IdxCache n IExp
- vsBVCache :: Map BVConst Identifier
- vsBoolCache :: Map Bool Identifier
- vsSym :: sym
- newtype VerilogM sym n a = VerilogM (StateT (ModuleState sym n) (ExceptT String IO) a)
- newtype Module sym n = Module (ModuleState sym n)
- mkModule :: sym -> VerilogM sym n (IExp tp) -> ExceptT String IO (Module sym n)
- initModuleState :: sym -> IO (ModuleState sym n)
- runVerilogM :: VerilogM sym n a -> ModuleState sym n -> ExceptT String IO (a, ModuleState sym n)
- execVerilogM :: sym -> VerilogM sym n a -> ExceptT String IO (ModuleState sym n)
- addFreshInput :: BaseTypeRepr tp -> Identifier -> VerilogM sym n Identifier
- addOutput :: BaseTypeRepr tp -> Identifier -> Exp tp -> VerilogM sym n ()
- addWire :: BaseTypeRepr tp -> Bool -> Identifier -> Exp tp -> VerilogM sym n ()
- freshIdentifier :: String -> VerilogM sym n Identifier
- addFreshWire :: BaseTypeRepr tp -> Bool -> String -> Exp tp -> VerilogM sym n Identifier
Documentation
type Identifier = String Source #
data Binop (inTp :: BaseType) (outTp :: BaseType) where Source #
A type for Verilog binary operators that enforces well-typedness, including bitvector size constraints.
And :: Binop BaseBoolType BaseBoolType | |
Or :: Binop BaseBoolType BaseBoolType | |
Xor :: Binop BaseBoolType BaseBoolType | |
Eq :: Binop tp BaseBoolType | |
Ne :: Binop tp BaseBoolType | |
Lt :: Binop (BaseBVType w) BaseBoolType | |
Le :: Binop (BaseBVType w) BaseBoolType | |
BVAnd :: Binop (BaseBVType w) (BaseBVType w) | |
BVOr :: Binop (BaseBVType w) (BaseBVType w) | |
BVXor :: Binop (BaseBVType w) (BaseBVType w) | |
BVAdd :: Binop (BaseBVType w) (BaseBVType w) | |
BVSub :: Binop (BaseBVType w) (BaseBVType w) | |
BVMul :: Binop (BaseBVType w) (BaseBVType w) | |
BVDiv :: Binop (BaseBVType w) (BaseBVType w) | |
BVRem :: Binop (BaseBVType w) (BaseBVType w) | |
BVPow :: Binop (BaseBVType w) (BaseBVType w) | |
BVShiftL :: Binop (BaseBVType w) (BaseBVType w) | |
BVShiftR :: Binop (BaseBVType w) (BaseBVType w) | |
BVShiftRA :: Binop (BaseBVType w) (BaseBVType w) |
binopType :: Binop inTp outTp -> BaseTypeRepr inTp -> BaseTypeRepr outTp Source #
data Unop (tp :: BaseType) where Source #
A type for Verilog unary operators that enforces well-typedness.
Not :: Unop BaseBoolType | |
BVNot :: Unop (BaseBVType w) |
data IExp (tp :: BaseType) where Source #
A type for Verilog expression names that enforces well-typedness. This type exists essentially to pair a name and type to avoid needing to repeat them and ensure that all uses of the name are well-typed.
Ident :: BaseTypeRepr tp -> Identifier -> IExp tp |
iexpType :: IExp tp -> BaseTypeRepr tp Source #
data Exp (tp :: BaseType) where Source #
A type for Verilog expressions that enforces well-typedness, including bitvector size constraints.
IExp :: IExp tp -> Exp tp | |
Binop :: Binop inTp outTp -> IExp inTp -> IExp inTp -> Exp outTp | |
Unop :: Unop tp -> IExp tp -> Exp tp | |
BVRotateL :: NatRepr w -> IExp tp -> BV w -> Exp tp | |
BVRotateR :: NatRepr w -> IExp tp -> BV w -> Exp tp | |
Mux :: IExp BaseBoolType -> IExp tp -> IExp tp -> Exp tp | |
Bit :: IExp (BaseBVType w) -> Integer -> Exp BaseBoolType | |
BitSelect :: (1 <= len, (start + len) <= w) => IExp (BaseBVType w) -> NatRepr start -> NatRepr len -> Exp (BaseBVType len) | |
Concat :: 1 <= w => NatRepr w -> [Some IExp] -> Exp (BaseBVType w) | |
BVLit :: 1 <= w => NatRepr w -> BV w -> Exp (BaseBVType w) | |
BoolLit :: Bool -> Exp BaseBoolType |
expType :: Exp tp -> BaseTypeRepr tp Source #
mkLet :: Exp tp -> VerilogM sym n (IExp tp) Source #
Create a let binding, associating a name with an expression. In Verilog, this is a new "wire".
signed :: IExp tp -> VerilogM sym n (IExp tp) Source #
Indicate than an expression name is signed. This causes arithmetic operations involving this name to be interpreted as signed operations.
binop :: Binop inTp outTp -> IExp inTp -> IExp inTp -> VerilogM sym n (IExp outTp) Source #
Apply a binary operation to two expressions and bind the result to a new, returned name.
scalMult :: 1 <= w => NatRepr w -> Binop (BaseBVType w) (BaseBVType w) -> BV w -> IExp (BaseBVType w) -> VerilogM sym n (IExp (BaseBVType w)) Source #
A special binary operation for scalar multiplication. This avoids
the need to call litBV
at every call site.
A wrapper around the BV type allowing it to be put into a map or set. We use this to make sure we generate only one instance of each distinct constant.
litBV :: 1 <= w => NatRepr w -> BV w -> VerilogM sym n (IExp (BaseBVType w)) Source #
Return the (possibly-cached) name for a literal bitvector value.
litBool :: Bool -> VerilogM sym n (IExp BaseBoolType) Source #
Return the (possibly-cached) name for a literal Boolean value.
unop :: Unop tp -> IExp tp -> VerilogM sym n (IExp tp) Source #
Apply a unary operation to an expression and bind the result to a new, returned name.
mux :: IExp BaseBoolType -> IExp tp -> IExp tp -> VerilogM sym n (IExp tp) Source #
Create a conditional, with the given condition, true, and false branches, and bind the result to a new, returned name.
bit :: IExp (BaseBVType w) -> Integer -> VerilogM sym n (IExp BaseBoolType) Source #
Extract a single bit from a bit vector and bind the result to a new, returned name.
bitSelect :: (1 <= len, (idx + len) <= w) => IExp (BaseBVType w) -> NatRepr idx -> NatRepr len -> VerilogM sym n (IExp (BaseBVType len)) Source #
Extract a range of bits from a bit vector and bind the result to a
new, returned name. The two NatRepr
values are the starting index
and the number of bits to extract, respectively.
concat2 :: (w ~ (w1 + w2), 1 <= w) => NatRepr w -> IExp (BaseBVType w1) -> IExp (BaseBVType w2) -> VerilogM sym n (IExp (BaseBVType w)) Source #
Concatenate two bit vectors and bind the result to a new, returned name.
A data type for items that may show up in a Verilog module.
Input :: BaseTypeRepr tp -> Identifier -> Item | |
Output :: BaseTypeRepr tp -> Identifier -> Item | |
Wire :: BaseTypeRepr tp -> Identifier -> Item | |
Assign :: LHS -> Exp tp -> Item |
data ModuleState sym n Source #
Necessary monadic operations
ModuleState | |
|
Instances
MonadState (ModuleState sym n) (VerilogM sym n) Source # | |
Defined in What4.Protocol.VerilogWriter.AST get :: VerilogM sym n (ModuleState sym n) # put :: ModuleState sym n -> VerilogM sym n () # state :: (ModuleState sym n -> (a, ModuleState sym n)) -> VerilogM sym n a # |
newtype VerilogM sym n a Source #
Instances
Module (ModuleState sym n) |
mkModule :: sym -> VerilogM sym n (IExp tp) -> ExceptT String IO (Module sym n) Source #
Create a Verilog module in the context of a given What4 symbolic backend and a monadic computation that returns an expression name that corresponds to the module's output.
initModuleState :: sym -> IO (ModuleState sym n) Source #
runVerilogM :: VerilogM sym n a -> ModuleState sym n -> ExceptT String IO (a, ModuleState sym n) Source #
execVerilogM :: sym -> VerilogM sym n a -> ExceptT String IO (ModuleState sym n) Source #
addFreshInput :: BaseTypeRepr tp -> Identifier -> VerilogM sym n Identifier Source #
Returns and records a fresh input with the given type and with a name constructed from the given base.
addOutput :: BaseTypeRepr tp -> Identifier -> Exp tp -> VerilogM sym n () Source #
Add an output to the current Verilog module state, given a type, a name, and an initializer expression.
addWire :: BaseTypeRepr tp -> Bool -> Identifier -> Exp tp -> VerilogM sym n () Source #
Add a new wire to the current Verilog module state, given a type, a signedness flag, a name, and an initializer expression.
freshIdentifier :: String -> VerilogM sym n Identifier Source #
Create a fresh identifier by concatenating the given base with the current fresh identifier counter.
addFreshWire :: BaseTypeRepr tp -> Bool -> String -> Exp tp -> VerilogM sym n Identifier Source #
Add a new wire to the current Verilog module state, given a type, a signedness flag, the prefix of a name, and an initializer expression. The name prefix will be freshened by appending current value of the fresh variable counter.