CHAPTER 5
Basic TCL with PrimeTime
What is Tcl?
Tcl = Tool Command Language
An open, Industry-standard language
Developed at [Link]. Berkeley
Offers many powerful C-shell style features
References:
Tcl and Tk Toolkit, John [Link]
Practical Programming in Tcl and Tk, Brent B. Welch
Tcl Comments
## Comments
Comments in
in Tcl
Tcl are
are line-oriented
line-oriented
## If
If you
you wish
wish to
to comment
comment on
on the
the same
same line,
line, be
be sure
sure to
to use
use
## aa semicolon
before
the
comment:
semicolon before the comment:
set
set header_str
header_str output
output Header;#
Header;# Same
Same line
line comment
comment
Embedded Comments:
this semicolon is required!
Nesting Tcl Commands
Tcl commands are nested using square brackets:
command3 [ command2 [command1 ...]]
Set_output_delay
Set_output_delay 55 -clock
-clock CLK
CLK [all_outputs]
[all_outputs]
Wildcards in Tcl
Tcl supports two wild card characters :
? will match exactly one character
* will match zero to n characters
Examples:
help
help create*
create*
set_input_delay
set_input_delay 55 -clock
-clock CLK
CLK [get_ports
[get_ports BUS?]
BUS?]
Variables in Tcl
Create and assign variables using the Tcl set command
set
set my_var
my_var 10
10
Variable substitution is performed with a $
set
set my_New_Var
my_New_Var $my_var
$my_var
To print variables
set
set myvar;
myvar; ## or
or
printvar
printvar myvar
myvar
To remove user defined variables
unset
unset my_var
my_var
Exercise on Using Variables
set
set clock_period
clock_period 10
10
echo
echo clock_period
clock_period
____________________
____________________
echo
echo clock_period
clock_period == $clock_period
$clock_period
____________________
____________________
Executing Arithmetic Expressions
To evaluate arithmetic expressions, use the Tcl expr command
set
set period
period 10.0
10.0
set
set freq
freq [expr
[expr (1
(1 // $period)]
$period)]
echo
echo Freq
Freq == [expr
[expr $freq
$freq ** 1000]
1000] MH
MHZZ
_________________________________________
_________________________________________
List Manipulation Commands
A list is one string, containing items separated by white space
set
set L1
L1 el1
el1 el2
el2 el3
el3
set
set Num_of_List_Elements
Num_of_List_Elements [1length
[1length $$ L1]
L1]
33
lappend
lappend
el1
el1 el2
el2
set
set
el1
el1
L1
L1 el4
el4 el5
el5
el3
el3 el4
el4 el5
el5
new_list
new_list [1minus
[1minus $L1
$L1 el2]
el2]
el3
el4
el5
el3 el4 el5
Rigid versus Weak String Quoting
Create a string using weak quoting
Use for weak quoting
Weak quoting allows variable and command substitution to
Create a string using rigid quoting
Use { } for rigid quoting
Rigid quoting allows NO variable or command substitution
set
set aa 5
5 44 33 22 1
1
set
set length_of_a
length_of_a temp
temp == [1length
[1length $a]
$a]
__________________________________________
__________________________________________
set
set length_of_a
length_of_a {temp
{temp == [1length
[1length $a]}
$a]}
__________________________________________
__________________________________________
occur
Control Flow Commands
If
If {[file
{[file exists
exists My_Design.db]
My_Design.db] ==1}
==1} {{
read_db
read_db My_Design.db
My_Design.db
}} else
{
else {
echo
echo Could
Could not
not read
read My_Design.db
My_Design.db
}}
must be on same line as else!
set
set vendor_library
vendor_library $target_library
$target_library
switch
$vendor_library
switch $vendor_library {{
xlib
xlib {set_max_delay
{set_max_delay 2.8
2.8 [all_outputs]}
[all_outputs]}
zlib
{set_max_delay
3.1
[all_outputs]}
zlib {set_max_delay 3.1 [all_outputs]}
default
default [set_max_delay
[set_max_delay 3.4
3.4 [all_outputs]}
[all_outputs]}
}}
Looping Structures in Tcl
## foreach
foreach loop
loop example
example -- iterates
iterates over
over list
list elements
elements
set
set Mylist
Mylist {Hello
{Hello World}
World}
foreach
foreach
echo
echo
}}
list_element
list_element $Mylist
$Mylist {{
$list_element
$list_element
## while
while loop
loop example
example
set
set
set
set
idx
idx 00
clk_per
clk_per 10.0
10.0
## Create
Create divided
divided clocks
clocks
while
{$idx
<
10}
while {$idx < 10} {{
create_clock
create_clock -period
-period
incr
idx
incr idx
set
set clk_per
clk_per [expr
[expr (2
(2
}}
on
on ports
ports CLK0
CLK0 -- CLK9
CLK9
$clk_per
$clk_per [get_ports
[get_ports CLK$idx]
CLK$idx]
** $clk_per)]
$clk_per)]
Additional Tcl Commands
Use the \ character for line continuation
Use the Tcl redirect command to capture the output
of a command and save it to a file
Use the Tcl source command to read a Tcl script
set
set my_long_list
my_long_list Input_Port_1
Input_Port_1 Input_Port_2
Input_Port_2 \\
Input_Port_3
Input_Port_3 Input_Port_4
Input_Port_4
redirect
redirect -append
-append my_log_file
my_log_file {1length
{1length $my_long_list}
$my_long_list}
source
source my_script_file.tcl
my_script_file.tcl
##
##
Use
Use the
the following
following for
for
source
-echo
-verbose
source -echo -verbose
debugging
debugging script
script files
files
my_script_file.tcl
my_script_file.tcl
Recall PrimeTime Collections
A collection is a set of design objects which are stored internally
and referred to by the collection handle.
pt_shell>
pt_shell> set
set myvar
myvar [all_inputs]
[all_inputs]
{IN1,
IN2,
IN3,
{IN1, IN2, IN3, IN4,
IN4, IN5}
IN5}
pt_shell>
printvar
myvar
pt_shell> printvar myvar
_sell21
_sell21
IN1
A collection of all input ports in
PrimeTime memory
IN2
IN3
IN4
IN5
Application Attributes
Each design object has application attributes
You can control your scripts or create your own timing
analysis reports using these attributes
pt_shell> list_attributes -application -class clock
Attribute Name
Object
Type
----------------------------------------------------------clock_latency_fall_max
clock
float
clock_latency_fall_min
clock
float
clock_latency_rise_max
clock
float
clock_latency_rise_min
clock
float
full_name
clock
string
hold_uncertainty
clock
float
is_generated
clock
boolean
object_class
clock
string
period
clock
float
propagated_clock
clock
boolean
setup_uncertainty
clock
float
sources
clock
waveform
Examples Using Application Attributes
set myvar [get_attribute [get_clock CLOCK] propagated_clock]
if {$myvar == true} {
read_sdf [Link]
} else {
set_clock_uncertainty 0.3 [get_clock CLOCK]
set_clock_latency 0.75 [get_clock CLOCK]
}
set myvar [get_port INSTRUCTION* -filter direction == in]
set_input_delay 3.2 -max -clock CLOCK $myvar
Iterating Over a Collection
The normal Tcl foreach cannot be used on collections!
Use PrimeTimes foreach_in_collection
foreach_in_collection variable collection(s) {body}
## Script
Script to
to loop
loop thru
thru all
all clocks
clocks and
and print
print their
their period
period
foreach_in_collection
foreach_in_collection clk_itr
clk_itr [all_clocks]
[all_clocks] {{
set
set clk_name
clk_name [get_attribute
[get_attribute $clk_itr
$clk_itr full_name]
full_name]
set
clk_per
[get_attribute
$clk_itr
period]
set clk_per [get_attribute $clk_itr period]
echo
echo Clock
Clock period
period for
for $clk_name
$clk_name is
is $clk_per
$clk_per
}}
Tcl Procedures
Allows the user to write reusable, shareable routines
Powerful capabilities of procedures:
Allow you to define your own commands
Allow any number of arguments (can define default values)
Can have variable number of arguments
Pass arguments by value or reference
Can have local variables
Can use any commands or other procedures
Supports recursion
Tcl Procedure Syntax
Exercise:
Exercise:
Label
Labelthe
thename,
name,argument
argumentlist,
list,and
andbody
bodyof
ofthe
theprocedure
procedure
[Link]
proc
proc multadd
multadd {abc}
{abc} {{
expr
expr $a*$b+$c
$a*$b+$c
}}
pt_shell>
pt_shell>
pt_shell>
pt_shell>
11
11
source
source [Link]
[Link]
multadd
multadd 22 44 33
Example of a Tcl Procedure
proc
proc report_path_slack
report_path_slack {path}
{path} {{
set
set path_slack
path_slack [get_attribute
[get_attribute $path
$path slack]
slack]
if
{[get_attribute
$path
endpoint_clock]
if {[get_attribute $path endpoint_clock] !=
!= }
} {{
echo
echo Slack
Slack == $path_slack
$path_slack
}} else
{
else {
echo
echo Slack
Slack == (unconstrained
(unconstrained path)
path)
}}
return
return $path_slack
$path_slack
}}
How
How do
doyou
youcall
callthis
thisprocedure?
procedure?
What
Whatdoes
doesthe
theprocedure
proceduregive
giveyou?
you?
Answer: Tcl Procedures Example
[Link]
proc
proc report_path_slack
report_path_slack {path}
{path} {{
set
set path_slack
path_slack [get_attribute
[get_attribute $path
$path slack]
slack]
if
{[get_attribute
$path
endpoint_clock]
if {[get_attribute $path endpoint_clock] !=
!= }
} {{
echo
echo Slack
Slack == $path_slack
$path_slack
}} else
else {{
echo
echo Slack
Slack == (unconstrained
(unconstrained path)
path)
}}
return
return $path_slack
$path_slack
}}
pt_shell> source [Link]
pt_shell> set path_coll [get_timing_paths -max 100 -from [all_clocks]]
pt_shell> foreach_in_collection path $path_coll {
? report_path_slack $path
?}
Information: Defining new variable path_slack (CMD-041)
Slack = -14.032
...
pt_shell>