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

Getting Help Math Functions

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

© 2015 Synopsys, Inc. 3


Find Your Collection Commands Find Your Application Attributes
help get_*
help all_*
Tcl JOB AID list_attributes –application –class object_class
# In PrimeTime, refer to the
help *_collections Collections & # User Guide for Advanced Timing Analysis

4 Attributes
man collections # In Design Compiler, use man pages
man attributes
man cell_attributes
man pin_attributes; # etc

If you see a collection handle


query_objects # Displays a report to the screen of the object names in a collection
get_object_name # Returns the object name as a string of a single-object collection

Making Procedures Robust – Handle Ambiguous Arguments Quietly


get_* # Accepts lists and collections
add_to_collection [get_ports –quiet $endpoints] \
[list [get_pins –quiet $endpoints] [get_clocks –quiet $endpoints]]

Returns a modified collection Operators


add_to_collection # Add object(s) to a collection. Result is new collection
copy_collection # Make a copy of a collection. Result is new collection ==
filter_collection # Filter a collection, resulting in new collection
index_collection # Extract object from collection. Result is new collection !=
remove_from_collection # Remove object(s) from a collection. Result is new collection
>
sort_collection # Creates and returns a sorted copy of the collection
<
Modifies the original, base collection >=
append_to_collection # Adds objects to a collection, modifying the base collection
<=
=~
Loop on a collection
foreach_in_collection each_port [all_outputs] { Allow wildcards !~
lappend port_list [get_object_name $each_port]
} defined()
Use Attributes
sort_collection undefined()
Collections are not Tcl strings or lists get_attribute
sizeof_collection # Do not use llength! report_attribute
get_* -filter
set new_coll [filter_collection [get_ports *] \
© 2015 Synopsys, Inc. 4 "full_name =~ sd_DQ* and direction == inout"]
Tcl JOB AID Create Collections of Timing Paths
# Commonly used switches
Timing Paths get_timing_paths –help

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)

Commonly Used Timing Path Attributes


# In Design Compiler, use the man page for get_timing_path to list attributes
pt_shell> list_attributes –application –class timing_path

Attribute Name Object Type


--------------------------------------------
arrival timing_path float
endpoint timing_path collection
endpoint_clock timing_path collection
path_group timing_path collection
slack timing_path float
startpoint timing_path collection
startpoint_clock timing_path collection

Pass Command-Line Arguments Directly to the Body of the Procedure


proc my_rpt_timing {args} {
# For argument validation and to enable the use of –help option
parse_proc_arguments –args $args results
# The eval command concatenates its arguments and then evaluates
set paths [eval get_timing_paths $args]
}

© 2015 Synopsys, Inc. 5


Notes:
© 2015 Synopsys, Inc. 6

You might also like