python2verilog.backend.verilog package

Submodules

python2verilog.backend.verilog.ast module

Verilog Abstract Syntax Tree Components

class Always(trigger: Expression, *args, body: list[Statement] | None = None, **kwargs)[source]

Bases: Statement

always () begin

end

to_lines()[source]

To Verilog

class AtNegedge(condition: Expression)[source]

Bases: Expression

@(negedge <condition>)

class AtNegedgeStatement(condition: Expression, *args, **kwargs)[source]

Bases: Statement

@(negedge <condition>);

class AtPosedge(condition: Expression)[source]

Bases: Expression

@(posedge <condition>)

class AtPosedgeStatement(condition: Expression, *args, **kwargs)[source]

Bases: Statement

@(posedge <condition>);

class BlockingSub(lvalue: Var, rvalue: Expression, *args, **kwargs)[source]

Bases: Subsitution

<lvalue> = <rvalue>

class Case(expression: Expression, case_items: list[CaseItem], *args, **kwargs)[source]

Bases: Statement

Verilog case statement with various cases case (<expression>)

<items[0]> … <items[n]>

endcase

to_lines()[source]

To Verilog Lines

class CaseItem(condition: Expression, statements: list[Statement])[source]

Bases: ImplementsToLines

Verilog case item, i.e. <condition>: begin

<statements>

end

to_lines()[source]

To Verilog lines

class Declaration(name: str, *args, size: int = 32, reg: bool = False, signed: bool = False, **kwargs)[source]

Bases: Statement

<reg or wire> <modifiers> <[size-1:0]> <name>;

to_lines()[source]

To Verilog lines

class IfElse(condition: Expression, then_body: list[Statement], else_body: list[Statement] | None, *args, **kwargs)[source]

Bases: Statement

Verilog if else

to_lines()[source]

To Verilog

class Initial(*args, body: list[Statement] | None = None, **kwargs)[source]

Bases: Statement

initial begin

end

to_lines()[source]

To Verilog

class Instantiation(module_name: str, given_name: str, port_connections: dict[str, str], *args, **kwargs)[source]

Bases: Statement

Instantiationo f Verilog module. <module-name> <given-name> (…);

to_lines()[source]

To Verilog

class LocalParam(name: str, value: UInt, *args, **kwargs)[source]

Bases: Statement

localparam <name> = <value>;

class Module(name: str, body: list[Statement] | None = None, localparams: dict[str, UInt] | None = None, header: Lines | None = None)[source]

Bases: ImplementsToLines

module name(…); endmodule

to_lines()[source]

To Verilog

class NonBlockingSubsitution(lvalue: Var, rvalue: Expression, *args, **kwargs)[source]

Bases: Subsitution

<lvalue> <= <rvalue>

class PosedgeSyncAlways(clock: Expression, *args, **kwargs)[source]

Bases: Always

always @(posedge <clock>) begin

<valid> = 0;

end

class Statement(literal: str = '', comment: str = '')[source]

Bases: ImplementsToLines, GenericRepr

Represents a statement in verilog (i.e. a line or a block) If used directly, it is treated as a string literal

get_blocked_comment()[source]

// <comment> … // <comment> Separated by newlines

get_inline_comment()[source]

// <comment>

to_lines()[source]

To Verilog

class Subsitution(lvalue: Var, rvalue: Expression, oper: str, *args, **kwargs)[source]

Bases: Statement

Interface for <lvalue> <blocking or nonblocking> <rvalue>

to_lines()[source]

Converts to Verilog

class TypeDef(name: str, values: list[str])[source]

Bases: Statement

typedef enum {

<val0>, <val1>, …

} _state_t;

to_lines()[source]

To Verilog

class While(*args, condition: Expression, body: list[Statement] | None = None, **kwargs)[source]

Bases: Statement

Unsynthesizable While while (<condition>) begin

end

to_lines()[source]

To Verilog

python2verilog.backend.verilog.codegen module

Verilog Codegen

class CodeGen(root: Node, context: Context, config: CodegenConfig | None = None)[source]

Bases: object

Builds the Verilog ast from the context and IR

get_module()[source]

Get Verilog module

get_module_lines()[source]

Get Verilog module as Lines

get_module_str()[source]

Get Verilog module as string

get_testbench(config: TestbenchConfig)[source]

Creates testbench with multiple test cases

Each element of self.context.test_cases represents a single test case

Parameters:

random_ready – whether or not to have random ready signal in the while loop

get_testbench_lines(config: TestbenchConfig)[source]

New Testbench as lines

get_testbench_str(config: TestbenchConfig)[source]

New testbench as str

python2verilog.backend.verilog.config module

Configurations

class CodegenConfig(random_ready: bool = False, add_debug_comments: bool = <factory>)[source]

Bases: TestbenchConfig

Configurations for code generator

add_debug_comments: bool
class TestbenchConfig(random_ready: bool = False)[source]

Bases: object

Configurations for test bench code generator

random_ready: bool = False

python2verilog.backend.verilog.fsm module

Lowers IR Graph to FSM

class FsmBuilder(root: Node, context: Context, config: CodegenConfig | None = None)[source]

Bases: object

Creates a FSM using a case block from a IR Graph

static create_quick_done(context: Context) IfElse[source]
if ready:

done = 1 state = idle

else:

state = done

do_edge(edge: Edge)[source]

Processes a edge

do_vertex(vertex: Node)[source]

Processes a node

get_case() Case[source]

Gets case statement/block

new_caseitem(root: Node)[source]

Creates a new case item with the root’s unique id as identifier

python2verilog.backend.verilog.module module

Creates module from context and FSM

class Module(context: Context, root: Case)[source]

Bases: Module

A module that implements the python2verilog module interface

static make_start_ifelse(root: Case, context: Context) list[Statement][source]
if (_start) begin

end else begin

end

python2verilog.backend.verilog.testbench module

Creates testbench from context and FSM

class Testbench(context: Context, config: TestbenchConfig)[source]

Bases: Module

Module contents

Verilog Backend