Complete najaeda API Reference

class najaeda.netlist.Attribute(snlAttribute)[source]

Bases: object

get_name()[source]
Returns:

the name of the attribute.

Return type:

str

get_value()[source]
Returns:

the value of the attribute.

Return type:

str

has_value()[source]
Returns:

True if the attribute has a value.

Return type:

bool

class najaeda.netlist.Equipotential(term)[source]

Bases: object

Class that represents the term and wraps some of the snl occurrence API.

dump_dot(path: str)[source]

Dump the dot file of this equipotential.

get_inst_terms()[source]

Iterate over the instance terminals of this equipotential.

Returns:

an iterator over the instance terminals of this equipotential.

Return type:

Iterator[Term]

get_leaf_drivers(filter=None)[source]
get_leaf_readers(filter=None)[source]
get_top_drivers()[source]
get_top_readers()[source]
get_top_terms()[source]

Iterate over the top terminals of this equipotential.

Returns:

an iterator over the top terminals of this equipotential.

Return type:

Iterator[Term]

is_const() bool[source]

Check if this equipotential is a constant generator.

Returns:

True if this equipotential is a constant generator.

Return type:

bool

is_const0() bool[source]

Check if this equipotential is a constant 0 generator.

Returns:

True if this equipotential is a constant 0 generator.

Return type:

bool

is_const1() bool[source]

Check if this equipotential is a constant 1 generator.

Returns:

True if this equipotential is a constant 1 generator.

Return type:

bool

class najaeda.netlist.Instance(path=najaeda.naja.SNLPath)[source]

Bases: object

Class that represents an instance in the design hierarchy.

Add input terms that are related to the given clock term.

Parameters:
  • clock_term – the clock term to check for related inputs.

  • input_terms – a list of input terms to add.

Returns:

None

Add output terms that are related to the given clock term.

Parameters:
  • clock_term – the clock term to check for related outputs.

  • output_terms – a list of output terms to add.

Returns:

None

add_combinatorial_arcs(input_terms: List[Term], output_terms: List[Term])[source]

Add input terms that are combinatorial inputs for the given output term.

Parameters:
  • output_term – the output term to check for combinatorial inputs.

  • input_terms – a list of input terms to add.

Returns:

None

count_attributes() int[source]

Count the attributes of this Instance.

Returns:

the number of attributes of this Instance.

Return type:

int

count_bit_nets() int[source]

Count the number of scalar nets and bus net bits of this Instance.

Returns:

the number of bit nets of this Instance.

Return type:

int

count_bit_terms() int[source]

Count the number of scalar terms and bus term bits of this Instance.

Returns:

the number of bit terms of this Instance.

Return type:

int

count_child_instances() int[source]
Returns:

the number of child instances of this instance.

Return type:

int

count_input_bit_terms() int[source]

Count the number of scalar input terms and bus input term bits of this Instance.

Returns:

the number of bit input terms of this Instance.

Return type:

int

count_input_terms() int[source]

Count the number of scalar input terms and bus input terms of this Instance.

Returns:

the number of input terms of this Instance.

Return type:

int

count_nets() int[source]

Count the number of scalar nets and bus nets of this Instance.

Returns:

the number of nets of this Instance.

Return type:

int

count_output_bit_terms() int[source]

Count the number of scalar output terms and bus output term bits of this Instance.

Returns:

the number of bit output terms of this Instance.

Return type:

int

count_output_terms() int[source]

Count the number of scalar output terms and bus output terms of this Instance.

Returns:

the number of output terms of this Instance.

Return type:

int

count_terms() int[source]

Count the number of scalar terms and bus terms of this Instance.

Returns:

the number of terms of this Instance.

Return type:

int

create_bus_net(name: str, msb: int, lsb: int) Net[source]

Create a bus Net in this Instance with the given name, msb and lsb.

Parameters:
  • name (str) – the name of the Net to create.

  • msb (int) – the most significant bit of the Net to create.

  • lsb (int) – the least significant bit of the Net to create.

Returns:

the created Net.

Return type:

Net

create_bus_term(name: str, msb: int, lsb: int, direction: Direction) Term[source]

Create a bus Term in this Instance with the given name, msb, lsb and direction.

Parameters:
  • name (str) – the name of the Term to create.

  • msb (int) – the most significant bit of the Term to create.

  • lsb (int) – the least significant bit of the Term to create.

  • direction (Term.Direction) – the direction of the Term to create.

Returns:

the created Term.

create_child_instance(model: str, name: str) Instance[source]

Create a child instance with the given model and name.

Parameters:
  • model (str) – the name of the model of the instance to create.

  • name (str) – the name of the instance to create.

Returns:

the created Instance.

Return type:

Instance

create_inout_bus_term(name: str, msb: int, lsb: int) Term[source]

Create an inout bus Term in this Instance with the given name, msb and lsb.

Parameters:
  • name (str) – the name of the Term to create.

  • msb (int) – the most significant bit of the Term to create.

  • lsb (int) – the least significant bit of the Term to create.

Returns:

the created Term.

Return type:

Term

create_inout_term(name: str) Term[source]

Create an inout Term in this Instance with the given name.

Parameters:

name (str) – the name of the Term to create.

Returns:

the created Term.

Return type:

Term

create_input_bus_term(name: str, msb: int, lsb: int) Term[source]

Create an input bus Term in this Instance with the given name, msb and lsb.

Parameters:
  • name (str) – the name of the Term to create.

  • msb (int) – the most significant bit of the Term to create.

  • lsb (int) – the least significant bit of the Term to create.

Returns:

the created Term.

Return type:

Term

create_input_term(name: str) Term[source]

Create an input Term in this Instance with the given name.

Parameters:

name (str) – the name of the Term to create.

Returns:

the created Term.

Return type:

Term

create_net(name: str) Net[source]

Create a scalar Net in this Instance with the given name.

Parameters:

name (str) – the name of the Net to create.

Returns:

the created Net.

Return type:

Net

create_output_bus_term(name: str, msb: int, lsb: int) Term[source]

Create an output bus Term in this Instance with the given name, msb and lsb.

Parameters:
  • name (str) – the name of the Term to create.

  • msb (int) – the most significant bit of the Term to create.

  • lsb (int) – the least significant bit of the Term to create.

Returns:

the created Term.

Return type:

Term

create_output_term(name: str) Term[source]

Create an output Term in this Instance with the given name.

Parameters:

name (str) – the name of the Term to create.

Returns:

the created Term.

Return type:

Term

create_term(name: str, direction: Direction) Term[source]

Create a Term in this Instance with the given name and direction.

Parameters:
  • name (str) – the name of the Term to create.

  • direction (Term.Direction) – the direction of the Term to create.

Returns:

the created Term.

delete()[source]

Delete this instance.

dump_context_dot(path: str)[source]
dump_full_dot(path: str)[source]

Dump the full dot file of this instance.

dump_verilog(path: str, config: VerilogDumpConfig = None)[source]

Dump the verilog of this instance.

Parameters:
  • path (str) – the file path where to dump the verilog.

  • config – the configuration to use when dumping the verilog.

Return type:

None

Raises:
  • ValueError – if the path does not end with .v.

  • FileNotFoundError – if the directory of the path does not exist.

get_attributes() Iterator[Attribute][source]

Iterate over the attributes of this Instance.

Returns:

the attributes of this Instance.

Return type:

Iterator[Attribute]

get_bit_nets()[source]

Iterate over all scalar nets and bus net bits.

Returns:

an iterator over the nets at bit level of this Instance.

Return type:

Iterator[Net]

get_bit_terms()[source]

Iterate over all scalar terms and bus term bits.

Returns:

the bit terms of this Instance.

Return type:

Iterator[Term]

get_child_instance(names: str | list)[source]
Parameters:

names – the name of the child instance or the path to the child Instance as a list of names.

Returns:

the child Instance at the given path or None if it does not exist.

Return type:

Instance or None

get_child_instance_by_id(ids: int | list[int])[source]
Parameters:

ids – the ID of the child instance or the path to the child Instance as a list of IDs.

Returns:

the child Instance at the given path or None if it does not exist.

Return type:

Instance or None

get_child_instances()[source]

Iterate over the child instances of this instance. Equivalent to go down one level in hierarchy.

Returns:

an iterator over the child instances of this instance.

Return type:

Iterator[Instance]

get_design() Instance[source]
Returns:

the Instance containing this instance.

Return type:

Instance

get_input_bit_terms()[source]

Iterate over all scalar input terms and bus input term bits of this Instance.

Returns:

the bit input terms of this Instance.

Return type:

Iterator[Term]

get_input_terms()[source]

Iterate over all scalar input terms and bus input terms of this Instance.

Returns:

the input terms of this Instance.

Return type:

Iterator[Term]

get_leaf_children()[source]

Iterate over the leaf children of this Instance. Equivalent to the underlying leaves of the instanciation tree.

Returns:

an iterator over the leaf children Instance of this Instance.

Return type:

Iterator[Instance]

get_model_id() tuple[int, int, int][source]
Returns:

the ID of the model of this Instance or ID of the top if this is the top.

get_model_name() str[source]
Returns:

the name of the model of the instance or name of the top is this is the top.

Return type:

str

get_name() str[source]
Returns:

the name of the instance or name of the top is this is the top.

Return type:

str

get_net(name: str) Net[source]
Parameters:

name (str) – the name of the Net to get.

Returns:

the Net with the given name or None if it does not exist.

Return type:

Net or None

get_nets()[source]

Iterate over all scalar nets and bus nets.

Returns:

an iterator over the nets of this Instance.

Return type:

Iterator[Net]

get_output_bit_terms()[source]

Iterate over all scalar output terms and bus output term bits of this Instance.

Returns:

the bit output terms of this Instance.

Return type:

Iterator[Term]

get_output_terms()[source]

Iterate over all scalar output terms and bus output terms of this Instance.

Returns:

the output terms of this Instance.

Return type:

Iterator[Term]

get_term(name: str) Term[source]
Parameters:

name (str) – the name of the Term to get.

Returns:

the Term with the given name.

Return type:

Term or None

get_terms()[source]

Iterate over all scalar terms and bus terms of this Instance.

Returns:

the terms of this Instance.

Return type:

Iterator[Term]

get_truth_table()[source]
Returns:

the truth table of the instance.

Return type:

list[str]

has_modeling() bool[source]
Returns:

True if this instance has timing modeling.

Return type:

bool

is_assign() bool[source]

(assign a=b) will create an instance of assign connecting the wire a to the output of the assign and b to the input.

Returns:

True if this is an assign (represented by an unnamed assign instance).

Return type:

bool

is_blackbox() bool[source]
Returns:

True if this is a blackbox.

Return type:

bool

is_buf() bool[source]
Returns:

True if this is a buffer.

Return type:

bool

is_const() bool[source]
Returns:

True if this is a constant generator.

Return type:

bool

is_const0() bool[source]
Returns:

True if this is a constant 0 generator.

Return type:

bool

is_const1() bool[source]
Returns:

True if this is a constant 1 generator.

Return type:

bool

is_inv() bool[source]
Returns:

True if this is an inverter.

Return type:

bool

is_leaf() bool[source]
Returns:

True if this is a leaf.

Return type:

bool

is_primitive() bool[source]
Returns:

True if this is a primitive.

Return type:

bool

is_sequential() bool[source]
Returns:

True if this is a sequential element.

Return type:

bool

is_top() bool[source]
Returns:

True if this is the top design.

Return type:

bool

set_name(name: str)[source]

Set the name of this instance.

Parameters:

name (str) – the new name of the instance.

class najaeda.netlist.Net(path, net=None, net_concat=None)[source]

Bases: object

class Type(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

count_attributes() int[source]

Count the attributes of this Net.

Returns:

the number of attributes of this Net.

Return type:

int

count_design_terms() int[source]

Count the design terminals of this net.

Returns:

the number of design terminals of this net.

Return type:

int

count_inst_terms() int[source]

Count the instance terminals of this net.

Returns:

the number of instance terminals of this net.

Return type:

int

delete()[source]
get_attributes() Iterator[Attribute][source]

Iterate over the attributes of this Net.

Returns:

the attributes of this Net.

Return type:

Iterator[Attribute]

get_bit(index: int)[source]
Parameters:

index (int) – the index of the bit to get.

Returns:

the Net bit at the given index or None if it does not exist.

Return type:

Net

get_bits()[source]

Iterate over the bits of this Net. The iterator will return itself if the Net is scalar. :return: an iterator over the bits of this Net. :rtype: Iterator[Net]

get_design_terms()[source]

Return an iterator over the design terminals of the net. This includes only the terminals that are part of the current design. The iterator will yield Term objects bit per bit.

Returns:

an iterator over the design terminals of the net.

Return type:

Iterator[Term]

get_inst_terms()[source]
Returns:

an iterator over the instance terminals of the net.

Return type:

Iterator[Term]

get_lsb() int[source]
Returns:

the least significant bit of the net if it is a bus.

Return type:

int

get_msb() int[source]
Returns:

the most significant bit of the net if it is a bus.

Return type:

int

get_name() str[source]
Returns:

the name of this Net.

Return type:

str

get_terms()[source]

Return an iterator over the terminals of the net. This includes both design and instance terminals.

Returns:

an iterator over the terminals of the net.

Return type:

Iterator[Term]

get_width() int[source]
Returns:

the width of the net.

Return type:

int

is_bit() bool[source]
Returns:

True if the net is a bit.

Return type:

bool

is_bus() bool[source]
Returns:

True if the net is a bus.

Return type:

bool

is_bus_bit() bool[source]
Returns:

True if the net is a bit of a bus.

Return type:

bool

is_concat() bool[source]
Returns:

True if the net is a concatenation.

Return type:

bool

is_const() bool[source]
Returns:

True if the net is a constant generator.

Return type:

bool

is_const0() bool[source]
Returns:

True if the net is a constant 0 generator.

Return type:

bool

is_const1() bool[source]
Returns:

True if the net is a constant 1 generator.

Return type:

bool

is_scalar() bool[source]
Returns:

True if the net is a scalar.

Return type:

bool

key()[source]

Stable, hashable identity for Net.

set_lsb(lsb: int)[source]
Parameters:

lsb (int) – the lsb to set for this Net.

set_msb(msb: int)[source]
Parameters:

msb (int) – the msb to set for this Net.

set_name(name: str)[source]
Parameters:

name (str) – the name to set for this Net.

set_type(net_type: Type)[source]
Parameters:

net_type (Type) – the type of the net.

class najaeda.netlist.SystemVerilogConfig(keep_assigns: bool = True, elaborated_ast_json_path: str = None, diagnostics_report_path: str = None, pretty_print_elaborated_ast_json: bool = True, include_source_info_in_elaborated_ast_json: bool = True, flist: str = None, top: str = None, suppress_warnings: list = None)[source]

Bases: object

diagnostics_report_path: str = None
elaborated_ast_json_path: str = None
flist: str = None
include_source_info_in_elaborated_ast_json: bool = True
keep_assigns: bool = True
pretty_print_elaborated_ast_json: bool = True
suppress_warnings: list = None
top: str = None
class najaeda.netlist.Term(path, term)[source]

Bases: object

class Direction(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum for the direction of a term.

bit: int | None
connect_lower_net(net: Net)[source]

Connect this term to the given lower Net.

Parameters:

net (Net) – the lower Net to connect to.

connect_upper_net(net: Net)[source]

Connect this term to the given upper Net.

Parameters:

net (Net) – the upper Net to connect to.

count_attributes() int[source]

Count the attributes of this Term.

Returns:

the number of attributes of this Term.

Return type:

int

count_flat_fanout(filter=None)[source]
delete()[source]

Delete this Term.

disconnect_lower_net()[source]

Disconnect this term from its lower net.

disconnect_upper_net()[source]

Disconnect this term from its upper net.

get_attributes() Iterator[Attribute][source]

Iterate over the attributes of this Term.

Returns:

the attributes of this Term.

Return type:

Iterator[Attribute]

get_bit(index: int)[source]
Parameters:

index (int) – the index of the bit to get.

Returns:

the Term bit at the given index or None if it does not exist.

Return type:

Term or None

get_bit_number()[source]
Returns:

the bit index of the term if it is a bit.

Return type:

int or None

get_bits()[source]
Returns:

an iterator over the bits of the term. If the term is scalar, it will return an iterator over itself.

Return type:

Iterator[Term]

Get all input terms that are related to the given clock term.

Parameters:

clock_term – the clock term to check for related inputs.

Returns:

a list of input terms that are related to the clock term.

Return type:

List[Term]

Get all output terms that are related to the given clock term.

Parameters:

clock_term – the clock term to check for related outputs.

Returns:

a list of output terms that are related to the clock term.

Return type:

List[Term]

get_combinatorial_inputs()[source]

Get all combinatorial input terms of this instance.

Returns:

a list of combinatorial input terms.

Return type:

List[Term]

get_combinatorial_outputs()[source]

Get all combinatorial output terms of this instance.

Returns:

a list of combinatorial output terms.

Return type:

List[Term]

get_direction() Direction[source]
Returns:

the direction of the term.

Return type:

Term.Direction

get_equipotential() Equipotential[source]
Returns:

the Equipotential of this Term.

Return type:

Equipotential

get_flat_fanout(filter=None)[source]
get_instance()[source]
Returns:

the instance of this Term.

Return type:

Instance

get_lower_net() Net[source]
Returns:

the lower net of the term.

Return type:

Net

get_lsb() int[source]
Returns:

the least significant bit of the term if it is a bus.

Return type:

int or None

get_msb() int[source]
Returns:

the most significant bit of the term if it is a bus.

Return type:

int or None

get_name() str[source]
Returns:

the name of the term.

Return type:

str

get_snl_term()[source]
get_truth_table()[source]
get_upper_net() Net[source]
Returns:

the upper net of the term.

Return type:

Net

Remark:

If the term is a top level term, it will return None.

get_width() int[source]
Returns:

the width of the term. 1 if scalar.

Return type:

int

is_bit() bool[source]
Returns:

True if the term is a bit.

Return type:

bool

is_bus() bool[source]
Returns:

True if the term is a bus.

Return type:

bool

is_bus_bit() bool[source]
Returns:

True if the term is a bit of a bus.

Return type:

bool

is_input() bool[source]
Returns:

True if the term is an input.

Return type:

bool

is_output() bool[source]
Returns:

True if the term is an output.

Return type:

bool

is_scalar() bool[source]
Returns:

True if the term is a scalar.

Return type:

bool

is_sequential() bool[source]
Returns:

True if the term is a sequential term.

Return type:

bool

is_unnamed() bool[source]
Returns:

True if the term is unnamed.

Return type:

bool

key() tuple[source]

Unique, hashable identity of this Term. Stable within a design revision.

set_lsb(lsb: int)[source]
Parameters:

lsb (int) – the lsb to set for this Term.

set_msb(msb: int)[source]
Parameters:

msb (int) – the msb to set for this Term.

class najaeda.netlist.VerilogConfig(keep_assigns: bool = True, allow_unknown_designs: bool = False, preprocess_enabled: bool = False, conflicting_design_name_policy: str = 'forbid')[source]

Bases: object

allow_unknown_designs: bool = False
conflicting_design_name_policy: str = 'forbid'
keep_assigns: bool = True
preprocess_enabled: bool = False
class najaeda.netlist.VerilogDumpConfig(dumpRTLInfosAsAttributes: bool = False, dumpAssignsAsInstances: bool = False)[source]

Bases: object

dumpAssignsAsInstances: bool = False
dumpRTLInfosAsAttributes: bool = False
najaeda.netlist.apply_constant_propagation()[source]

Apply constant propagation to the top design. :rtype: None

najaeda.netlist.apply_dle()[source]

Apply the DLE (Dead Logic Elimination) to the top design. :rtype: None

najaeda.netlist.consistent_hash(obj)[source]
najaeda.netlist.create_top(name: str) Instance[source]

Create a top instance with the given name.

Parameters:

name (str) – the name of the top instance to create.

Returns:

the created top Instance.

Return type:

Instance

najaeda.netlist.dump_naja_if(path: str)[source]

Dump the Naja IF to the given path.

najaeda.netlist.get_instance_by_path(names: list)[source]
najaeda.netlist.get_max_fanout() list[source]

Get the maximum fanout of the top design.

Returns:

the maximum fanout of the top design.

Return type:

int

najaeda.netlist.get_max_logic_level() list[source]

Get the maximum logic level of the top design.

Returns:

the maximum logic level of the top design.

Return type:

int

najaeda.netlist.get_model_name(id: tuple[int, int, int]) str[source]
Parameters:

id (tuple[int, int, int]) – the id of the model.

Returns:

the name of the model given its id or None if it does not exist.

Return type:

str or None

najaeda.netlist.get_primitives_library() najaeda.naja.NLLibrary[source]
najaeda.netlist.get_snl_instance_from_id_list(id_list: list) najaeda.naja.SNLInstance[source]
najaeda.netlist.get_snl_path_from_id_list(id_list: list) najaeda.naja.SNLPath[source]
najaeda.netlist.get_snl_term_for_ids_with_path(path, termID, bit)[source]
najaeda.netlist.get_top()[source]
Returns:

the top Instance.

Return type:

Instance

najaeda.netlist.load_liberty(files: str | List[str])[source]

Load liberty files.

Parameters:

files – a list of liberty files to load or a single file.

Return type:

None

Raises:

Exception – if no liberty files are provided.

najaeda.netlist.load_naja_if(path: str)[source]

Load the Naja IF from the given path.

najaeda.netlist.load_primitives(name: str)[source]

Loads a primitive library embedded in najaeda.

Currently supported libraries are:

  • xilinx

  • yosys

Parameters:

name (str) – the name of the primitives library to load.

Raises:

ValueError – if the name is not recognized.

Return type:

None

najaeda.netlist.load_primitives_from_file(file: str)[source]

Loads a primitives library from a file.

Parameters:

file (str) – the path to the primitives library file.

The file must define a function load(db).

najaeda.netlist.load_system_verilog(files: str | List[str], config: SystemVerilogConfig = None) Instance[source]

Load SystemVerilog files into the top design.

Parameters:
  • files – a list of SystemVerilog files to load or a single file.

  • config – the configuration to use when loading the files.

Returns:

the top Instance.

Return type:

Instance

Raises:

Exception – if no files are provided.

najaeda.netlist.load_verilog(files: str | List[str], config: VerilogConfig = None) Instance[source]

Load verilog files into the top design.

Parameters:
  • files – a list of verilog files to load or a single file.

  • config – the configuration to use when loading the files.

Returns:

the top Instance.

Return type:

Instance

Raises:

Exception – if no files are provided.

najaeda.netlist.reset()[source]

Reset the environment by deleting everything. :rtype: None