Copyright | (c) 2018-2022 Yann Herklotz |
---|---|
License | GPL-3 |
Maintainer | yann [at] yannherklotz [dot] com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Verismith.Verilog.Mutate
Description
Functions to mutate the Verilog AST from Verismith.Verilog.AST to generate more random patterns, such as nesting wires instead of creating new ones.
Synopsis
- class Mutate a where
- inPort :: Identifier -> ModDecl ann -> Bool
- findAssign :: Identifier -> [ModItem ann] -> Maybe Expr
- idTrans :: Identifier -> Expr -> Expr -> Expr
- replace :: Identifier -> Expr -> Expr -> Expr
- nestId :: Identifier -> ModDecl ann -> ModDecl ann
- nestSource :: Identifier -> Verilog ann -> Verilog ann
- nestUpTo :: Int -> Verilog ann -> Verilog ann
- allVars :: ModDecl ann -> [Identifier]
- instantiateMod :: ModDecl ann -> ModDecl ann -> ModDecl ann
- instantiateMod_ :: ModDecl ann -> ModItem ann
- instantiateModSpec_ :: Bool -> Text -> ModDecl ann -> ModItem ann
- filterChar :: Text -> [Identifier] -> [Identifier]
- initMod :: ModDecl ann -> ModDecl ann
- makeIdFrom :: Show a => a -> Identifier -> Identifier
- makeTop :: Bool -> Int -> ModDecl ann -> ModDecl ann
- makeTopAssert :: ModDecl ann -> ModDecl ann
- simplify :: Expr -> Expr
- removeId :: [Identifier] -> Expr -> Expr
- combineAssigns :: Port -> [ModItem ann] -> [ModItem ann]
- combineAssigns_ :: Bool -> Port -> [Port] -> ModItem ann
- declareMod :: [Port] -> ModDecl ann -> ModDecl ann
- fromPort :: Port -> Identifier
Documentation
Instances
inPort :: Identifier -> ModDecl ann -> Bool Source #
Return if the Identifier
is in a '(ModDecl ann)'.
findAssign :: Identifier -> [ModItem ann] -> Maybe Expr Source #
Find the last assignment of a specific wire/reg to an expression, and returns that expression.
idTrans :: Identifier -> Expr -> Expr -> Expr Source #
Transforms an expression by replacing an Identifier with an
expression. This is used inside transformOf
and traverseExpr
to replace
the Identifier
recursively.
replace :: Identifier -> Expr -> Expr -> Expr Source #
Replaces the identifier recursively in an expression.
nestId :: Identifier -> ModDecl ann -> ModDecl ann Source #
Nest expressions for a specific Identifier
. If the Identifier
is not
found, the AST is not changed.
This could be improved by instead of only using the last assignment to the wire that one finds, to use the assignment to the wire before the current expression. This would require a different approach though.
nestSource :: Identifier -> Verilog ann -> Verilog ann Source #
Replaces an identifier by a expression in all the module declaration.
nestUpTo :: Int -> Verilog ann -> Verilog ann Source #
Nest variables in the format w[0-9]*
up to a certain number.
allVars :: ModDecl ann -> [Identifier] Source #
instantiateMod :: ModDecl ann -> ModDecl ann -> ModDecl ann Source #
Add a Module Instantiation using ModInst
from the first module passed to
it to the body of the second module. It first has to make all the inputs into
reg
.
>>>
render $ instantiateMod m main
module main; wire [(3'h4):(1'h0)] y; reg [(3'h4):(1'h0)] x; m m1(y, x); endmodule
instantiateMod_ :: ModDecl ann -> ModItem ann Source #
Instantiate without adding wire declarations. It also does not count the current instantiations of the same module.
>>>
GenVerilog $ instantiateMod_ m
m m(y, x);
instantiateModSpec_ :: Bool -> Text -> ModDecl ann -> ModItem ann Source #
Instantiate without adding wire declarations. It also does not count the current instantiations of the same module.
>>>
GenVerilog $ instantiateModSpec_ "_" m
m m(.y(y), .x(x));
filterChar :: Text -> [Identifier] -> [Identifier] Source #
initMod :: ModDecl ann -> ModDecl ann Source #
Initialise all the inputs and outputs to a module.
>>>
GenVerilog $ initMod m
module m(y, x); output wire [(3'h4):(1'h0)] y; input wire [(3'h4):(1'h0)] x; endmodule
makeIdFrom :: Show a => a -> Identifier -> Identifier Source #
Make an Identifier
from and existing Identifier and an object with a
Show
instance to make it unique.
makeTop :: Bool -> Int -> ModDecl ann -> ModDecl ann Source #
Make top level module for equivalence verification. Also takes in how many modules to instantiate.
makeTopAssert :: ModDecl ann -> ModDecl ann Source #
Make a top module with an assert that requires y_1
to always be equal to
y_2
, which can then be proven using a formal verification tool.
simplify :: Expr -> Expr Source #
Simplify an Expr
by using constants to remove BinaryOperator
and
simplify expressions. To make this work effectively, it should be run until
no more changes were made to the expression.
>>>
GenVerilog . simplify $ (Id "x") + 0
x
>>>
GenVerilog . simplify $ (Id "y") + (Id "x")
(y + x)
removeId :: [Identifier] -> Expr -> Expr Source #
Remove all Identifier
that do not appeare in the input list from an
Expr
. The identifier will be replaced by 1'b0
, which can then later be
simplified further.
>>>
GenVerilog . removeId ["x"] $ Id "x" + Id "y"
(x + (1'h0))
declareMod :: [Port] -> ModDecl ann -> ModDecl ann Source #
Provide declarations for all the ports that are passed to it. If they are registers, it should assign them to 0.
fromPort :: Port -> Identifier Source #