python2verilog.ir package¶
Submodules¶
python2verilog.ir.context module¶
The context of a generator
Includes the function, its representation and its usage information
- class Context(_frozen: bool = False, name: str = '', testbench_suffix: str = '_tb', is_generator: bool = False, prefix: str = '', test_cases: list[tuple[int, ...]] = <factory>, py_func: function | None = None, py_string: str | None = None, _py_ast: ~ast.FunctionDef | None = None, input_types: list[type[~typing.Any]] | None = None, output_types: list[type[~typing.Any]] | None = None, optimization_level: int = -1, mode: ~python2verilog.api.modes.Modes = Modes.NO_WRITE, _local_vars: list[~python2verilog.ir.expressions.Var] = <factory>, _input_vars: list[~python2verilog.ir.expressions.Var] | None = None, _output_vars: list[~python2verilog.ir.expressions.ExclusiveVar] | None = None, _states: set[str] = <factory>, signals: ~python2verilog.ir.signals.ProtocolSignals = <python2verilog.ir.signals.ProtocolSignals object>, state_var: ~python2verilog.ir.expressions.Var = _state, _done_state: ~python2verilog.ir.expressions.State = _state_done, idle_state: ~python2verilog.ir.expressions.State = _state_idle, _entry_state: ~python2verilog.ir.expressions.State | None = None, namespace: dict[str, ~python2verilog.ir.context.Context] = <factory>, generator_instances: dict[str, ~python2verilog.ir.instance.Instance] = <factory>)[source]¶
Bases:
GenericReprAndStr
Context needed by the Intermediate Representation E.g. variables, I/O, parameters, localparam
- add_local_var(var: Var)[source]¶
Appends to global vars with restrictions.
Good for appending Vars created from Python source
- add_special_local_var(var: Var)[source]¶
Appends to local vars without restrictions.
Good for appending Vars created internally (e.g. inline function calls)
- property done_state¶
The ready state
- property entry_state¶
The first state that does work in the graph representation
- input_types: list[type[Any]] | None = None¶
- is_generator: bool = False¶
- name: str = ''¶
- optimization_level: int = -1¶
- output_types: list[type[Any]] | None = None¶
- prefix: str = ''¶
- property py_ast¶
Python ast node rooted at function
- py_func: function | None = None¶
- py_string: str | None = None¶
- signals: ProtocolSignals = <python2verilog.ir.signals.ProtocolSignals object>¶
- property states¶
State variables
- test_cases: list[tuple[int, ...]]¶
- property testbench_name: str¶
Returns test bench module name in the generated verilog
- testbench_suffix: str = '_tb'¶
python2verilog.ir.expressions module¶
Intermediate Representation Expressions
Represents the subset of Python expressions that are synthesizable
- class Add(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> + <right>
- class BinOp(left: Expression, oper: str, right: Expression)[source]¶
Bases:
UBinOp
<left> <op> <right>
In verilog the signed specifier is used. For mixed unsigned and signed operations, the following page explains well https://www.01signal.com/verilog-design/arithmetic/signed-wire-reg/
- class Div(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> / <right>
- class ExclusiveVar(py_name: str, ver_name: str = '', width: int = 32, is_signed: bool = True, initial_value: str = '0', exclusive_group: str | None = None, **_)[source]¶
Bases:
Var
Exclusive Variable
Can only be set once before a clock cycle must occur, used by the optimizer to determine if it needs to make a edge clocked or not
- class Expression(string: str)[source]¶
Bases:
GenericRepr
An expression that can be equated
- class FloorDiv(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> // <right>
Follows Python conventions
- class Int(value: int)[source]¶
Bases:
Expression
Signed integer literal
- class LessThan(left: Expression, right: Expression)[source]¶
Bases:
UBinOp
<left> < <right>
- class Mod(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> % <right>
- class Mul(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> * <right>
- class Pow(left: Expression, right: Expression)[source]¶
Bases:
UBinOp
<left> ** <right>
- class State(name, width: int = 32, isSigned: bool = True, initial_value: str = '0')[source]¶
Bases:
Var
State constant
- class Sub(left: Expression, right: Expression)[source]¶
Bases:
BinOp
<left> - <right>
- class Ternary(condition: Expression, left: Expression, right: Expression)[source]¶
Bases:
Expression
<condition> ? <left> : <right>
- class UBinOp(left: Expression, oper: str, right: Expression)[source]¶
Bases:
Expression
Unsigned BinOp Is usually better for comparators
- class UInt(value: int)[source]¶
Bases:
Expression
Unsigned integer literal
- class UnaryOp(oper: str, expr: Expression)[source]¶
Bases:
Expression
<op>(<expr>)
- class Unknown[source]¶
Bases:
Expression
Unknown or “don’t care” value
- class Var(py_name: str, ver_name: str = '', width: int = 32, is_signed: bool = True, initial_value: str = '0', **_)[source]¶
Bases:
Expression
Named-variable
python2verilog.ir.graph module¶
Graph representation of the logic
Naming convention: Vertex Edge Element := Vertex | Edge
- class AssignNode(unique_id: str, *args, lvalue: Var, rvalue: Expression, child: Edge | None = None, **kwargs)[source]¶
Bases:
BasicNode
Represents a non-blocking assignment, i.e. assignments that do not block the execution of the next statements, without a clock cycle having to pass
- class BasicElement(unique_id: str, *args, child: Element | None = None, **kwargs)[source]¶
Bases:
Element
Basic element with a single child
- property optimal_child¶
Optimal child or child otherwise
- class BasicNode(unique_id: str, *args, child: Edge | None = None, **kwargs)[source]¶
Bases:
Node
,BasicElement
Basic node. Has one child.
- class ClockedEdge(unique_id: str, *args, child: Element | None = None, **kwargs)[source]¶
Bases:
Edge
Represents a clocked edge, i.e. a clock cycle has to pass for the next node to be executed
- class Edge(unique_id: str, *args, child: Element | None = None, **kwargs)[source]¶
Bases:
BasicElement
Represents an edge between two vertices
- class Element(unique_id: str, name: str = '')[source]¶
Bases:
object
Element, base class for vertex or edge
- class IfElseNode(unique_id: str, *args, true_edge: Edge, false_edge: Edge, condition: Expression, **kwargs)[source]¶
-
Represents an if-else statement
- exclusions()[source]¶
Yields all exclusion groups that will be read or written to within this group of nonclocked nodes.
The reason reads are also included is because checking a callee’s ready signal more than once in a clock cycle is usually incorrect.
- property optimal_false_edge¶
optimal false edge
- property optimal_true_edge¶
optimal true edge or edge otherwise
- class NonClockedEdge(unique_id: str, *args, child: Element | None = None, **kwargs)[source]¶
Bases:
Edge
Represents a non-clocked edge, i.e. no clock cycle has to pass for the next node to be executed
- create_cytoscape_elements(node: Element)[source]¶
Creates adjacency list from a node
Assumes names are unique
- create_networkx_adjacency_list(node: Element)[source]¶
Creates adjacency list from a node
Assumes names are unique
- get_variables(exp: Expression) Iterator[Var] [source]¶
Gets variables from expression
python2verilog.ir.instance module¶
An instance of a generator
Can be created from a context
- class Instance(module_name: str, var: Var, inputs: list[Var], outputs: list[Var], signals: ProtocolSignals)[source]¶
Bases:
object
- Parameters:
module_name – generator function name
var – variable name assigned to generator instance
- module_name: str¶
- signals: ProtocolSignals¶
python2verilog.ir.signals module¶
Protocol signals used by the converter
- class InstanceSignals(prefix: str = '')[source]¶
Bases:
object
Signals that are often named differently for each instance
- class ProtocolSignals(prefix: str = '')[source]¶
Bases:
InstanceSignals
Protocol signals
Includes ready, valid, clock, reset, done, etc.
Module contents¶
Intermediate Representation
A Control Flow Graph represented as a Directed Graph