Professional Documents
Culture Documents
TCL Job Aid Synopsys
TCL Job Aid Synopsys
help -v command
man command Tcl JOB AID 1 expr expression
incr var_name
info body rpt_TNV
info args rpt_TNV Fundamentals
printvar var_name
# TNV.tcl
redirect –variable rptstring \
String Commands List Commands {report_constraint –all_violators}
string equal glob set TNV [regexp –all VIOLATED $rptstring]
string match llength echo "The TNV is $TNV"
string first lappend # To run a script in the Synopsys tool
string last lindex source TNV.tcl
string range lrange
string length lsearch
# Avoid exec if possible, potentially large memory footprint
string index linsert
redirect –file tmp1212 \
join lminus
{report_constraint –all_violators}
append split
exec grep –c VIOLATED tmp1212
regexp concat
file delete tmp1212
regsub list
format lreplace
scan lsort Control Flow
subst # The argument expr below is evaluated in the same
# way that the command expr evaluates its argument
if {expr} {body}
proc metrics {header} { if {expr} {body} else {body}
global metrics_cpu_time if {expr} {body} elseif {expr} {body} else {body}
echo $header while {expr} {body}
if {![info exists metrics_cpu_time]} { for {start} {expr} {next} {body}
foreach loop_var list {body}
echo "CPU time since beginning [cputime]" switch string {pattern {body}}
} else { break
set new_time [expr [cputime] - $metrics_cpu_time] continue
echo "CPU time since last metrics $new_time"
}
< > <=
echo "Peak memory usage [mem]" Boolean compare. Returns 0 if false, 1 if true
Operators for >= == !=
set metrics_cpu_time [cputime]
expr
return "" Logical OR. Returns 0 if both operands are
} ||
zero, 1 otherwise
# To remove user defined variables
unset metrics_cpu_time Logical NOT. Returns 1 if operand is zero, 0
!
otherwise
Logical AND. Returns 1 if both operands are
&&
© 2015 Synopsys, Inc. 1 non-zero, 0 otherwise
Getting Help
help -v command
help command_group Tcl JOB AID
man command
info body rpt_TNV
info args rpt_TNV
Non-Positional 2
printvar var_name Arguments
Arrays
array option arrayName
if {[info exists results(-boolean)]} {body}
set period [expr 100.0 / $clk(pci_clk)]
File I/O
set file_handle [open ./TNV.rpt w]
puts $file_handle “The TNV is $TNV”
close $file_handle
set rptstring [read $file_handle]
while {[gets $file_handle each_line] != -1} {body}
Tcl Procedures
create_command_group group_name
# For positional arguments
define_proc_attributes clean_log \
–info "Removes duplicate timing reports" \
–command_group My_procs \
-define_args {
{infile "Log file to be cleaned" infile}
{outfile "Cleaned log file" outfile}
}
# For non-positional arguments
# The argument for the procedure must be the key word args
# Inside the procedure, often the 1st line
parse_proc_arguments –args $args results
# After completion of procedure
define_proc_attributes clean_log \
-info "Removes duplicate timing reports" \
-command_group My_procs \
-define_args {
{-infile "Log file to be cleaned" file string required}
{-outfile "Cleaned log file" file string required}
{-verbose "Generates verbose output" "" boolean optional}
}
© 2015 Synopsys, Inc. 2
Tcl JOB AID
Rule #1: Command and Argument Parsing
• White space separates the command name and each argument The Rules 3
• Newlines or semicolons separate commands
Rule #2: Rigid Grouping with { }
• Groups a single argument while preventing all substitutions by the Tcl interpreter
• The braces group all characters, including newlines, semicolons and nested braces, until a matching brace is found
• The outermost braces themselves are stripped off before the argument is passed to the command
Rule #3: Weak Grouping with " "
• Groups a single argument while allowing substitutions by the Tcl interpreter
• The quotes group all characters, including newlines and semicolons, until another quote is found
• To nest quotes, you must use a backslash escaping
• The quotes themselves are stripped off before the argument is passed to the command
Rule #4: Backslash Substitution
• The backslash is used to quote special characters \<newline> Space
• The backslash and the next character are replaced with a new character \t Tab
Rule #5: Variable Substitution
\n Newline
• The $ causes variable substitution
Rule #6: Command Substitution \\ \{ \} \[ \] Literal c (special
• Square brackets delimit embedded commands and nesting is allowed \" \$ meaning removed
• Everything, including the square brackets, is replaced by the result of the command
Rule #7: Common Mistakes and Gotchas
• Look for mismatched or missing braces (use comments when closing braces }; # End if)
• Look for incorrect line continuations the newline must follow directly after the backslash
• Must include a space between the close and open curly brace when used to identify arguments
• Comments (#) are commands
• Ensure all braces are evenly matched, even if they occur on commented lines
• Each command determines how its arguments are interpreted
• Read man pages for more information (as a script, as an expression as interpreted by the expr command, as a switch etc)
• Tcl interpreter assumes variable or array names contain only letters, digits and underscores during variable substitution
• If the variable being substituted is terminated by a letter, digit, or underscore, use { } to identify the variable name
• Recommendation - use only letters, digits and underscores when defining variable or array names
• The Synopsys Preprocessor identifies bus notation (e.g. sd_DQ[2]) and will not invoke command substitution
4 Attributes
man collections # In Design Compiler, use man pages
man attributes
man cell_attributes
man pin_attributes; # etc
5 [-to to_list]
[-from from_list]
(To pins, ports, nets, or clocks)
(From pins, ports, nets, or clocks)
[-through through_list] (Through pins, ports, or nets)
[-delay_type delay_type] (Type of path delay:
Values: max, min, min_max, max_rise,
max_fall, min_rise, min_fall)
[-nworst paths_per_endpoint] (Get N worst paths to endpoint: Value >= 1)
[-max_paths max_path_count] (Maximum number of paths per path group:
Value >= 1)
[-group group_name] (Get paths only in this path group)