elasticai.creator.ir2verilog.templates#

Module Contents#

Classes#

TemplateDirector

Director for building verilog templates.

VerilogTemplate

API#

class elasticai.creator.ir2verilog.templates.TemplateDirector[source]#

Director for building verilog templates.

Most methods correspond to verilog language constructs. Building the final template can be expensive! Typically you only want to do this once. E.g.:

from string import Template
from elasticai.creator.ir2verilog import type_handler, Code, TemplateDirector, Implementation

class _ExplodingTemplate:
    def substitute(self, params):
        raise RuntimeError("Template not initialized!")

_template = None

@type_handler
def fir_filter(impl: Implementation) -> Code:
    global _template
    if _template is None:
        _template = (
            TemplateDirector()
            .define_scoped_switch("USE_EXT_WEIGHTS", False)
            .define_scoped_switch("USE_EXT_MAC", False)
            .parameter("BITWIDTH")
            .parameter("LENGTH")
            .localparam("FILT_COEFFS")
            .localparam("NUM_MULT_UNIT")
            .add_module_name()
            .set_prototype(res.read_text(package_path, "verilog/filter_fir_full.v"))
            .build()
        )
    return _template.substitute(impl.attributes)

Initialization

reset() Self[source]#
set_prototype(prototype: str) Self[source]#
parameter(name: str) Self[source]#
localparam(name: str) Self[source]#
replace_module_of_instance(module_name: str, new_name: str) Self[source]#
replace_instance_name(module_name: str, new_name: str) Self[source]#
define_scoped_switch(name: str, default: bool) Self[source]#

Add a switch for a define that is scoped to the module name.

The switch will be prefixed with the value that users provide as module_name to the render call.

Parameters:
  • name – String with name of the switch/define name

  • default – Setting switch for defining output state (True=set, False=undefine)

add_module_name() Self[source]#
build() elasticai.creator.ir2verilog.templates.VerilogTemplate[source]#
class elasticai.creator.ir2verilog.templates.VerilogTemplate(template: string.Template, defines: dict[str, bool], module_name: dict[str, str])[source]#

Initialization

substitute(params: Mapping[str, str | bool]) str[source]#