Quartus® Prime Pro Edition User Guide: Design Compilation

ID 683236
Date 4/01/2024
Public
Document Table of Contents

1.6.2.2. Traversing the Design Netlist Using Tcl Commands

In this topic, you can see examples of Tcl commands that you can use to extract basic netlist objects or selective objects of your design using filters, pattern, and other techniques.

Traversing Basic Design Objects

The following table lists Tcl command examples for extracting hierarchical instances, instance ports, nets, and ports from your design netlist:

Note: When using dni:: Tcl commands in an SDC file, you can skip adding dni:: as read_sdc adds the namespace correctly.
Table 6.  Tcl Commands for Traversing Design Objects
Task Tcl Command Example
Get all instances directly under the top module. foreach_in_collection obj [dni::get_cells] { puts $obj; }
Get all design instances at all hierarchies. foreach_in_collection obj [dni::get_cells -hierarchical] { puts $obj; }
Get all instances directly under a hierarchical instance using a pattern with the hierarchy separator (|). foreach_in_collection obj [dni::get_cells auto|*] { puts $obj; }
Get all direct child instances of a specific hierarchical instance (for example, the instance auto).

# Use dni::current_instance to move the browsing scope to the auto hierarchical instance.

dni::current_instance auto

# Get all direct child instances of the hierarchical instance auto.

foreach_in_collection obj [dni::get_cells] { puts $obj; }

# Set the scope back to top design

dni::current_instance

Get all nets directly under the top module. foreach_in_collection obj [dni::get_nets] { puts $obj; }
Get all nets of the design at all hierarchies. foreach_in_collection obj [dni::get_nets -hierarchical] { puts $obj; }
Get all nets directly under a hierarchical instance using a pattern with the hierarchy separator (|). foreach_in_collection obj [dni::get_nets tick|*] { puts $obj; }
Get all nets directly under a specific hierarchical instance (for example, the instance tick).

# Use dni::current_instance to move the browsing scope to the tickhierarchical instance.

dni::current_instance tick

# Get all nets directly under tick

foreach_in_collection obj [dni::get_nets] { puts $obj; }

# Set the scope back to top design

dni::current_instance

Get all ports of the design. foreach_in_collection obj [dni::get_ports] { puts $obj; }
Get all instance ports of direct child instances under the design top module. foreach_in_collection obj [dni::get_pins] { puts $obj; }
Get all instance ports of all child instances under a specific hierarchical instance (for example, tick).

# Use dni::current_instance to move the browsing scope to the tick hierarchical instance.

dni::current_instance tick

# Get all instance ports under tick

foreach_in_collection obj [dni::get_pins] { puts $obj; }

# Set the scope back to the top design

dni::current_instance

Get all instance ports on all child instances using the object ID format to specify a hierarchical instance.

set inst [get_cells tick]

foreach_in_collection obj [dni::get_pins -of_objects $inst] { puts $obj; }

foreach_in_collection obj [dni::get_pins -of_objects tick|ticket[1]] { puts $obj; }

foreach_in_collection obj [dni::get_pins -of_objects instance::chiptrip::tick|ticket[1]] { puts $obj; }

Getting Selective Design Objects

You can use the following techniques to refine your search criteria and extract select design objects from your netlist:

  • <patterns> : It extracts objects by matching patterns in dni::get_cells, dni::get_nets, and dni::get_pins commands. Patterns can include wildcard characters * or ?. Wildcard characters do not match with the hierarchical separator.

    For objects in the design hierarchy:

    • The hierarchical path name of the object is matched against the pattern.
    • The hierarchical separator | splits the pattern into individual subpatterns, each of which is matched against one level of hierarchy. This means that a * does not match the hierarchy.
    • The name being matched is relative to the current search root (design top module). You can change the current search root using the dni::current_instance command.
Table 7.  Getting Selective Design Objects Using <pattern>
Tasks Using <pattern> Tcl Command Example
Get all first-level hierarchical and leaf instances. foreach_in_collection obj [dni::get_cells *] { puts $obj; }
Get all second-level hierarchical and leaf instances. foreach_in_collection obj [dni::get_cells *|*] { puts $obj; }
Get all instances under the hierarchical instance, for example, auto. foreach_in_collection obj [dni::get_cells auto|*] { puts $obj; }
Get all nets under the top module. foreach_in_collection obj [dni::get_nets *] { puts $obj; }
Get all nets under the first level hierarchical and leaf instances. foreach_in_collection obj [dni::get_nets *|*] { puts $obj; }
Get all nets under the first-level hierarchical instance, for example, auto. foreach_in_collection obj [dni::get_nets auto|*] { puts $obj; }
Get all instance ports on first-level hierarchical and leaf instances. foreach_in_collection obj [dni::get_pins *|*] { puts $obj; }
Get all instance ports on the hierarchical instance, for example, auto. foreach_in_collection obj [dni::get_pins auto|*] { puts $obj; }
Get all instance ports on all the child instances of the hierarchical instance, for example, auto. foreach_in_collection obj [dni::get_pins auto|*|*] { puts $obj; }
  • <-of_objects> : It extracts related design objects of the input object collection for dni::get_cells, dni::get_nets, dni::get_pins, and dni::get_ports. The following object relationships are considered:
    • dni::get_cells -of_objects <inst_port|net>
    • dni::get_nets -of_objects <inst_port|port|instance>
    • dni::get_pins -of_objects <instance|net>
    • dni::get_ports -of_objects <net>
Table 8.  Getting Selective Design Objects Using <-of_objects>
Tasks Using <-of_objects> Tcl Command Example

Get the hierarchical or leaf instance on which the input instance port is.

foreach_in_collection obj [dni::get_cells -of_objects inst_port::chiptrip::auto|dir[0]] { puts $obj; }

foreach_in_collection obj [dni::get_cells -of_objects inst_port::chiptrip::auto|street_map[2]|q] { puts $obj; }

Get the hierarchical or leaf instances to which the input net is connected.

foreach_in_collection obj [dni::get_cells -of_objects net::chiptrip::wire_get_ticket1] { puts $obj; }

foreach_in_collection obj [dni::get_cells -of_objects net::chiptrip::auto|n5] { puts $obj; }

foreach_in_collection obj [dni::get_cells -of_objects [dni::get_nets *]] { puts $obj; }

foreach_in_collection obj [dni::get_cells -of_objects [dni::get_nets auto|*]] { puts $obj; }

Get the net connecting a leaf instance port. foreach_in_collection obj [dni::get_nets -of_objects inst_port::chiptrip::auto|street_map[0]|q] { puts $obj; }
Get the net connecting a hierarchical instance port. foreach_in_collection obj [dni::get_nets -of_objects inst_port::chiptrip::auto|get_ticket] { puts $obj; }
Get the nets connecting to all the instance ports of a leaf instance. foreach_in_collection obj [dni::get_nets -of_objects instance::chiptrip::auto|street_map[0]] { puts $obj; }
Get the nets connecting to all the instance ports of a hierarchical instance. foreach_in_collection obj [dni::get_nets -of_objects instance::chiptrip::auto] { puts $obj; }
Get the net connecting to a primary port of the design. foreach_in_collection obj [dni::get_nets -of_objects port::chiptrip::gt1] { puts $obj; }
Get instance ports on a leaf instance. foreach_in_collection obj [dni::get_pins -of_objects instance::chiptrip::tick|add_0] { puts $obj; }
Get instance ports on a hierarchical instance. foreach_in_collection obj [dni::get_pins -of_objects instance::chiptrip::tick] { puts $obj; }
Get the instance ports on the hierarchical instance, for example, instance::chiptrip::auto. foreach_in_collection obj [dni::get_pins -of_objects [dni::get_cells auto]] { puts $obj; }
Get instance ports connected by a hierarchical net. foreach_in_collection obj [dni::get_pins -of_objects net::chiptrip::wire_get_ticket1] { puts $obj; }
Get primary ports connected by a hierarchical net on the top level. foreach_in_collection obj [dni::get_ports -of_objects net::chiptrip::wire_get_ticket1] { puts $obj; }
  • <-filter> : It extracts objects by filtering objects returned from dni::get_cells, dni::get_nets, dni::get_pins, and dni::get_ports based on the filter expression. The filter expression verifies every object that satisfies the other search criteria. If the object does not satisfy the filter, it is not returned in the result.
    A filter expression comprises predicates combined using logical operators, such as &&, and/AND, ||, or/OR, and !. Parentheses () in the expression override precedence. Each predicate has the following form:
    prop_name relop value
    where,
    • prop_name is the name of the object property being evaluated.
    • value is a number or a string. You can provide simple strings without the surrounding double-quotes.
    • relop is one of the following comparison operators:
      • == (equal)
      • != (not equal)
      • =~ (matches, value is then a pattern)
      • !~ (does not match, value is then a pattern)
      • > (greater than)
      • < (less than)
      • >= (greater than or equal to)
      • <= (less than or equal to)

    For example: -filter {name=~"out[*]" && ! (master_name==mod_1 || parent_name != block_1)}

Table 9.  Getting Selective Design Objects Using <-filter>
Tasks Using <-filter> Tcl Command Example
Get all child instances under the top-level. foreach_in_collection obj [dni::get_cells *] { puts $obj; }
Get properties of the instance object type. dni::list_properties -type instance
Get objects that are not a leaf instance foreach_in_collection obj [dni::get_cells * -filter {is_leaf==1}] { puts $obj; }
Get all objects that are hierarchical instances. foreach_in_collection obj [dni::get_cells * -filter {is_leaf==0}] { puts $obj; }
Return hierarchical instances matching the name pattern (for example, t*) under the design top-level module. foreach_in_collection obj [dni::get_cells * -filter {is_leaf==0 && name=~"t*"}] { puts $obj; }
Get all instances under the hierarchical instance, for example, auto that matches the module name in the filter.

foreach_in_collection obj [dni::get_cells auto|*] { puts $obj; }

dni::get_property -name module_name -object instance::chiptrip::auto|Mux_0

foreach_in_collection obj [dni::get_cells auto|* -filter {module_name=="primitive_lib_WORKING_LIBRARY_INTERNAL/OPER_(MUX)"}] { puts $obj; }

Get properties that you can use to filter net objects. Then, get nets with three connected instance ports and primary ports under the top-level design.

dni::list_properties -type net

foreach_in_collection obj [dni::get_nets -filter {number_of_ports==3}] { puts $obj; }

Get all nets in the full design hierarchies that are under the parent module, for example, auto_max. foreach_in_collection obj [dni::get_nets -hierarchical -filter {parent_name=="auto_max"}] { puts $obj; }
Get all nets in the full design hierarchies that are associated with the net_bus, for example, street_map. foreach_in_collection obj [dni::get_nets -hierarchical -filter {net_bus_name=="street_map"} ] { puts $obj; }
Get properties that you can use to filter instance port objects and get the value of the direction property. Then, get all output inst_ports under the top-level design.

dni::list_properties -type inst_port

dni::get_property -name direction -object inst_port::chiptrip::auto|get_ticket

foreach_in_collection obj [dni::get_pins -filter {direction==output}] { puts $obj; }

Get all primary input ports in the design. foreach_in_collection obj [dni::get_ports -filter {direction==input}] { puts $obj; }
  • Combined use of <pattern>, -of_objects <obj_col>, -hierarchical, and -filter <filter_expr> :
Table 10.  Combined Search Criteria
Tasks Using Combined Search Criteria  
Get all instance ports under the design top-module that match the combined search criteria of -of_objects and -filter. foreach_in_collection obj [dni::get_pins -of_objects [dni::get_cells *] -filter {direction==input}] { puts $obj; }
Get all nets under the design top module that match the pattern and -hierarchical. foreach_in_collection obj [dni::get_nets time* -hierarchical] { puts $obj; }
The following example shows the limitation of the combined search criteria:
tcl> foreach_in_collection obj [dni::get_pins clk -hierarchical]  { puts $obj; }
inst_port::chiptrip::auto|clk
inst_port::chiptrip::speed|clk
inst_port::chiptrip::tick|clk
inst_port::chiptrip::time_c|clk

 
tcl> foreach_in_collection obj [dni::get_nets time* -of_objects instance::chiptrip::time_c] { puts $obj; }
Arguments '-of_objects' and 'patterns' are mutually exclusive

 
tcl> foreach_in_collection obj [dni::get_pins -hierarchical -of_objects instance::chiptrip::time_c]  { puts $obj; }

Arguments '-of_objects' and '-hierarchical' are mutually exclusive