prga.netlist.module.util module

Unitility methods for accessing modules and instances.

class prga.netlist.module.util.ModuleUtils

Bases: prga.util.Object

A wrapper class for utility functions for modules and instances.

classmethod _ModuleUtils__add_edge_to_graph(g, u, v, path, edge_attrs, *key, prefix='', **reserved)
classmethod _ModuleUtils__add_node_to_graph(g, node, net, node_attrs, **reserved)
classmethod _analyze_sink(net)
classmethod _attach_hierarchy(net, hierarchy)
classmethod _dereference(module, ref, *, byname=False)

De-reference ref in module.

Parameters:
  • module (Module) – Top-level module
  • ref (Sequence [Hashable ] or str) –
Keyword Arguments:
 

byname (bool) – If set, ref is treated as a hierarchical name

Returns:

Return type:

AbstractInstance or AbstractNet

classmethod _iter_nets(obj, blackbox_instance=<function ModuleUtils.<lambda>>)
classmethod _reference(obj, *, byname=False)

Create a reference to obj.

Parameters:obj (AbstractInstance or AbstractNet) –
Keyword Arguments:
 byname (bool) – If set, this method returns a string instead of a sequence of keys
Returns:
Return type:Sequence [Hashable ] or str
classmethod create_port(module, name, width, direction, *, is_clock=False, key=None, **kwargs)

Create a port in module.

Parameters:
  • module (Module) –
  • name (str) – Name of the port
  • width (int) – Number of bits in the port
  • direction (PortDirection or str) – Direction of the port
Keyword Arguments:
 
  • is_clock (bool) – Mark this port as a clock
  • key (Hashable) – A hashable key used to index the port in the ports mapping the parent module. If not set (default argument: None), name is used by default
  • **kwargs – Custom key-value arguments. These attributes are added to __dict__ of the created port and accessible as dynamic attributes
Returns:

The created port

Return type:

Port

classmethod instantiate(module, model, name, *, key=None, **kwargs)

Instantiate model and add it as a sub-module in parent.

Parameters:
  • module (Module) –
  • model (Module) –
  • name (str) – Name of the instance
Keyword Arguments:
 
  • key (Hashable) – A hashable key used to index the instance in the instances mapping in the parent module. If not set (default argument: None), name is used by default
  • **kwargs – Custom key-value arguments. These attributes are added to __dict__ of the created port and accessible as dynamic attributes
Returns:

The created instance

Return type:

Instance

classmethod reduce_conn_graph(module, *, allow_multisource=False, coalesce_connections=False, blackbox_instance=<function ModuleUtils.<lambda>>, node_key=<function ModuleUtils.<lambda>>, node_attrs=<function ModuleUtils.<lambda>>, edge_attrs=<function ModuleUtils.<lambda>>)

Create a connection graph for module.

Parameters:

module (Module) –

Keyword Arguments:
 
  • allow_multisource (bool) – If set, multi-source connections are allowed in the reduced graph. It’s OK if some levels of hierarchy don’t allow so. Incompatible with coalesce_connections
  • coalesce_connections (bool) – If set, the reduced connection graph coalesce bus connections. This requires all levels of hierarchy do so. Incompatible with allow_multisource
  • blackbox_instance (Function [AbstractInstance ] -> bool) – A function testing if an instance should be blackboxed during elaboration. If True is returned, everything inside the instance is ignored.
  • node_key (Function [AbstractNet ] -> Hashable) – A function that returns a hasable key to be used as the node ID in the graph. If None is returned, the net and all paths starting from/ending at it are not added to the graph. Paths passing through the net may be added depending on the endpoints of the paths. This function might be called multiple times upon the same net and should be deterministic
  • node_attrs (Function [AbstractNet ] -> dict) – A function that returns additional attributes for a [hierarchical] net. This function is called only once when a node with a valid key is created. "net" is a reserved key whose value is the corresponding net object.
  • edge_attrs (Function [Sequence [AbstractNet ]] -> dict) – A function that returns additional attributes for a path. This function is called only once when an edge with valid endpoints is created. "path" is a reserved key whose corresponding value is a sequence of nets that this path includes, from the startpoint to the endpoint, inclusively. If None is returned, the edge is not added to the graph
Returns:

Return type:

networkx.DiGraph

classmethod reduce_timing_graph(module, *, blackbox_instance=<function ModuleUtils.<lambda>>, node_key=<function ModuleUtils.<lambda>>, node_attrs=<function ModuleUtils.<lambda>>, edge_attrs=<function ModuleUtils.<lambda>>)

Create a timing graph for module.

Parameters:

module (Module) –

Keyword Arguments:
 
  • blackbox_instance (Function [AbstractInstance ] -> bool) – A function testing if an instance should be blackboxed during elaboration. If True is returned, all connections or timing arcs inside the instance are ignored. Consequentially, all timing paths passing through the instance are ignored as well.
  • node_key (Function [AbstractNet ] -> Hashable) – A function that returns a hasable key to be used as the node ID in the graph. If None is returned, the net and all paths starting from/ending at it are not added to the graph. Paths passing through the net may be added depending on the endpoints of the paths. This function might be called multiple times upon the same net and should be deterministic
  • node_attrs (Function [AbstractNet ] -> dict) – A function that returns additional attributes for a [hierarchical] net. This function is called only once when a node with a valid key is created. "net" is a reserved key whose value is the corresponding net object; "clock_root" is a reserved key whose value is the node of the root net of the clock network that this net belongs to, or None if this net is not a clock.
  • edge_attrs (Function [TimingArcType, Sequence [AbstractNet ]] -> dict) – A function that returns additional attributes for a path. This function is called only once when an edge with valid endpoints is created. "path" is a reserved key whose corresponding value is a sequence of nets that this path includes, from the startpoint to the endpoint, inclusively; "type_" is a reserved key indicating the type of this timing arc. If None is returned, the edge is not added to the graph
Returns:

Return type:

networkx.MultiDiGraph

Notes

Clock networks are handled relatively naively in this method. Clock networks are detected using the is_clock attribute on nets and collected following connections. For each network, a clock “root” is identified (currently the root must be a clock input of module), and combinational timing arcs are created in the clock network. Reference clocks for all sequential timing arcs are updated to be the “root” clock.