Tclug 2007 TCL Command
Tclug 2007 TCL Command
Tclug 2007 TCL Command
file dirname fname Returns the directory name part of a file name.
file tail fname Returns the file name from a file path string.
You use the glob command to generate a list of file names that match one or more patterns. The
glob command has the following form: glob pattern1 pattern2 pattern3 ...
The following example generates a list of .em and .volt files located in the current directory:
set flist [glob *.em *.volt]
You use the open, close, and flush commands to set up file access.
set f [open VDD.em w+]
close $f
You use the flush command to force buffered output to be written to a file.
flush $fid
You use the gets command to read a single line from a file and the puts commands to write
a single line to a file.
# Write out a line of text, then read it back and print
it set fname "mytext.txt"
# Open file, then write to it
set fid [open $fname w+]
puts $fid "This is my line of text."
close $fid
# Open file, then read from it
set fid [open $fname r]
set data_in [gets $fid]
close $fid
# Print out data read
echo $data_in
You can use the seek, tell, and eof commands to manage nonsequential file access.
The simplest form of the seek command is seek $fid offset
The $fid argument is the file ID of the file that was obtained from an open command; the
offset argument is the number of bytes to move the access position.
You use the tell command to obtain the current access position of a file. The basic form of
the command is tell $fid
You use the eof command to test whether the access position of a file is at the end of the file.
The command returns 1 if true, 0 otherwise.
The following is a procedure example:
# procedure max returns the greater of two values
proc max {a b} {
if {$a > $b} {
return $a
}
return $b
}
You invoke this procedure as follows:
dc_shell> max 10 5
In this example, you can invoke max with two or fewer arguments. If an argument is missing,
its value is set to the specified default, 0 in this case.
#procedure max returns the greater of two values
proc max {{a 0} {b 0}} {
if {$a > $b} {
return $a
}
return $b
}
Additional arguments are placed into args as a list. The following example shows how
to use a varying number of arguments:
# print the square of at least one
proc squares {num args} {
set nlist $num
append nlist " "
append nlist $args
foreach n $nlist {
echo "Square of $n is [expr $n*$n]"
}
}
A collection is a set of design objects such as libraries, ports, and cells. You create collections
with the Synopsys get_* and all_* commands. The following example creates a collection
of all ports in a design:
dc_shell> get_ports
dc_shell> set myports [get_ports]
dc_shell> query_objects [get_ports in*] {in0 in1 in2}
dc_shell> set hc [get_cells -filter is_hierarchical==true]
The result of filter_collection is a new collection, or if no objects match the criteria, an
empty string. For example,
dc_shell> filter_collection [get_cells] is_hierarchical==true
dc_shell> add_to_collection $reports [get_ports CLOCK]
dc_shell> set cPorts [remove_from_collection [all_inputs] CLOCK] {in1}
compare_collections command to compare the contents of two collections. If the two
collections are the same, the compare_collections command returns zero.
dc_shell> compare_collection [get_cells *] [get_cells *]
To iterate over a collection, use the foreach_in_collection command
dc_shell> foreach_in_collection itr [get_cells*] \
{if {[get_attribute $itr is_hierarchical] == “true”}\
{remove_wire_load_model $itr}}
copy_collection command duplicates a collection, resulting in a new collection.
index_collection command creates a collection of one object that is the nth object in
another collection. The objects in a collection are numbers 0 through n-1.
dc_shell> query_objects [index_collection $c1 0] {u1}
The DC_rpt_cell procedure lists all cells in a design and reports if a cell has the following
properties: Is a black box (unknown), Has a don’t touch attribute, Has a DesignWare attribute,
Is hierarchical, Is combinational, Is a test cell
proc DC_rpt_cell args {
suppress_message UID-101
echo " "
echo [format "%-32s %-14s %5s %11s" "Cell" "Reference" "Area" "Attributes"] echo
"-----------------------------------------------------------------"
} elseif {[string match -t* $option]} {
set option "-total_only"
echo ""
set cd [current_design]
echo "Performing cell count on [get_object $cd] . .
." echo " "
} elseif {[string match -h* $option]} {
set option "h"; # hierarchical only
echo ""
set cd [current_design]
echo "Performing hierarchical cell report on [get_object $cd] . . ."
echo " "
echo [format "%-36s %-14s %11s" "Cell" "Reference" "Attributes"]
echo "-----------------------------------------------------------------"
} else { echo
" "
echo " Message: Option Required (Version - December 2002)"
echo " Usage: DC_rpt_cell \[-all_cells\] \[-hier_only\] \[-total_only\]"
echo " "
return
}
# create a collection of all cell
objects set all_cells [get_cells -h *]