PrimeTime Suite Tool Commands - Foreach - in - Collection

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

10/14/22, 3:03 PM PrimeTime Suite Tool Commands - foreach_in_collection

You are here: PrimeTime Suite Man Pages > PrimeTime Suite Tool Commands > f >
foreach_in_collection

foreach_in_collection
NAME

SYNTAX

ARGUMENTS

DESCRIPTION

EXAMPLES

SEE ALSO

NAME
foreach_in_collection

Iterates over the elements of a collection.

SYNTAX
string foreach_in_collection

itr_var

collections

body

Data Types
itr_var string

collections list

body string

ARGUMENTS
itr_var

Specifies the name of the iterator variable.

collections

Specifies a list of collections over which to iterate.

body

Specifies a script to execute per iteration.

DESCRIPTION
The foreach_in_collection command is used
to iterate over each element in a collection.
You cannot
use the Tcl-supplied foreach command to iterate over collections because the foreach command
requires a list, and a collection is not a list. Also,
using the foreach command on a collection causes
the collection to be deleted.

The arguments for the foreach_in_collection command parallel those of the foreach command: an
iterator variable, the collections over which to iterate, and the script to apply at each iteration. All
arguments are required.

Note: The foreach_in_collection command does not


allow a list of iterator variables.

During each iteration, the itr_var option is set to a collection of exactly


one object. Any command that
accepts collections as an argument also accepts
itr_var because they are of the same data type
(collection).

https://spdocs.synopsys.com/dow_retrieve/qsc-t/dg/ptolh/T-2022.03/ptolh/Default.htm#manpages/pt2/foreach_in_collection.htm%3FTocPath%3D… 1/2
10/14/22, 3:03 PM PrimeTime Suite Tool Commands - foreach_in_collection

You can nest the foreach_in_collection command within other control


structures, including another
foreach_in_collection command.

Note that if the body of the iteration is modifying the netlist, it is


possible that all or part of the
collection involved in the iteration will be deleted. The foreach_in_collection command is safe for
such operations. If a
command in the body causes the collection to be removed, at the next
iteration,
the iteration ends with a message indicating that the
iteration ended prematurely.

An alternative to collection iteration is to use


complex filtering to create a collection that includes
only
the desired elements, then apply one or more commands to that
collection. If the order of operations
does
not matter, the following are equivalent. The first is an example
without iterators.
set s [get_cells {U1/*}]

command1 $s

command2 $s

unset s

The following is a similar approach using the foreach_in_collection command:


foreach_in_collection itr [get_cells {U1/*}] {

command1 $itr

command2 $itr

For collections with large numbers of objects, the non-iterator


version is more efficient, though both
produce the same results if the commands are order-independent.

EXAMPLES
The following example from PrimeTime removes the wire load model from all hierarchical cells in the
current instance.
pt_shell> foreach_in_collection itr [get_cells *] {

? if {[get_attribute $itr is_hierarchical] == "true"} {

? remove_wire_load_model $itr

? }

? }

Removing wire load model from cell 'i1'.

Removing wire load model from cell 'i2'.

SEE ALSO
collections(2)

https://spdocs.synopsys.com/dow_retrieve/qsc-t/dg/ptolh/T-2022.03/ptolh/Default.htm#manpages/pt2/foreach_in_collection.htm%3FTocPath%3D… 2/2

You might also like