Tcl_1_2015.00_SG

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

Tcl Tool Command Language

For additional reading, refer to SolvNet “Using Tcl with Synopsys Tools”,
v2014.09.
Tcl Tool Command Language
TNV Total Number of Violations
TNV Total Number of Violations
TNV Total Number of Violations
The redirect command will redirect all output, meaning intermediate output (eg. error, warning
or informational messages and the report itself) as well as the result of the command.
When there are errors during a redirect, a summary message will be printed to the screen.

pt_shell> redirect -help


redirect # Redirect output of a command to a file
[-append] (Append output to the file)
[-tee] (Tee output to the current output stream)
[-file] (Output to a file (default))
[-variable] (Output to a variable)
target (Name of file/variable target for redirect)
command_string (Command to redirect. Should be in braces {}.)
The characters \<newline> are replaced with a single space and is used for line continuation.

pt_shell> report_constraint –help


. . .
[-all_violators] (Show all constraint violators)
[-max_delay] (Only max_delay & setup)
TNV Total Number of Violations

pt_shell> man exec


NAME
exec - Invoke subprocess(es)
SYNOPSIS
exec ?switches? arg ?arg ...?
DESCRIPTION
This command treats its arguments as the specification of one or more
subprocesses to execute. The arguments take the form of a standard
shell pipeline where each arg becomes one word of a command, and each
distinct command becomes a subprocess.
TNV Total Number of Violations

pt_shell> man file


NAME
file - Manipulate file names and attributes
SYNOPSIS
file option name ?arg arg ...?
DESCRIPTION
This command provides several operations on a file's name or attributes.
Name is the name of a file; if it starts with a tilde, then tilde
substitution is done before executing the command (see the manual entry
for filename for details). Option indicates what to do with the file name.
Any unique abbreviation for option is acceptable. . .
Tcl has a comprehensive set of system commands that allow you to write you scripts 100% in Tcl!
# Lists the contents of a directory
ls
# Returns total CPU time in seconds
cputime
# Returns peak memory usage in kbytes
mem
# Manipulate file names and attributes
file
# Manipulate strings
regexp/string/regsub
# File I/O
open/close/read/puts
Variable substitution causes the $ and the variable name to be replaced by the value of the
variable.

pt_shell> man regexp


NAME
regexp - Match a regular expression against a string
DESCRIPTION
. . .
-all
Causes the regular expression to be matched as many times as possible in the
string, returning the total number of matches found. If this is specified
with match variables, they will continue information for the last match
only.
TNV Total Number of Violations
The square brackets [ ] cause command substitution. Everything inside the square brackets and
the square brackets themselves are replaced with the return value of the embedded command
execution.
The characters \n and \t are substituted with a newline and tab respectively.
The { } characters are used for grouping – to identify a single argument for the redirect
command in the example above.
The [ ] delimit an embedded command – report_constraint is executed and replaced with its
result.
pt_shell> man if
NAME
if - Execute scripts conditionally
SYNOPSIS
if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ...
?else? ?bodyN?
DESCRIPTION
The if command evaluates expr1 as an expression (in the same way that expr
evaluates its argument). The value of the expression must be a boolean (a
numeric value, where 0 is false and anything is true, or a string value
such as true or yes for true and false or no for false); if it is true
then body1 is executed by passing it to the Tcl interpreter. Otherwise expr2
is evaluated as an expression and if it is true then body2 is
executed, and so on. If none of the expressions evaluates to true then
bodyN is executed. The then and else arguments are optional ``noise
words'' to make the command easier to read. There may be any number of
elseif clauses, including zero. BodyN may also be omitted as long as else
is omitted too. The return value from the command is the result of the
body script that was executed, or an empty string if none of the expressions
was non-zero and there was no bodyN.
Numeric operands refers to either integers or floating point.

To do string comparison and matching, it is preferable to use the string command.


This command is taught later in this unit.

pt_shell> man expr; # The expression in if statements are evaluated using expr
. . .
Operands may be specified in any of the following ways:
1. As an numeric value, either integer or floating-point.
2. As a Tcl variable, using standard $ notation. The variable's value will be
used as the operand.
3. As a string enclosed in double-quotes. The expression parser will perform
backslash, variable, and command substitutions on the information between the
quotes, and use the resulting value as the operand
4. As a string enclosed in braces. The characters between the open brace and
matching close brace will be used as the operand without any substitutions.
5. As a Tcl command enclosed in brackets. The command will be executed and
its result will be used as the operand.
6. As a mathematical function whose arguments have any of the above forms for
operands, such as sin($x). See below for a list of defined functions.
pt_shell> man info
. . .
info exists varName
Returns 1 if the variable named varName exists in the current context
(either as a global or local variable) and has been defined by being given a
value, returns 0 otherwise.
The above script is NOT representative of a recommended compile strategy. It is a
simple example to illustrate the expr command.
Available operators and functions with the expr command. More details available in the man pages.

MATH OPERATORS
- + ~ ! Unary minus, unary plus, bit-wise NOT, logical NOT
* / % Multiply, divide, remainder
+ - Add and subtract
<< >> Left and right shift
< > <= >= Boolean less, greater, less than or equal, and greater than or equal
== != Boolean equal and not equal
& | Bit-wise AND and OR
^ Bit-wise exclusive OR
&& || Logical AND and OR
x?y:z If-then-else, as in C
MATH FUNCTIONS
abs cosh log sqrt
acos double log10 srand
asin exp pow tan
atan floor rand tanh
atan2 fmod round
ceil hypot sin
cos int sinh
Defaulted arguments, if any, must be the last arguments for the procedure. If a default
is not specified, the argument is required. The following example is provided for
clarification:

proc my_incr {value {increment 1}} {


expr $value + $increment
}
my_incr 42 3
 45
my_incr 42
 43
proc my_incr {{increment 1} value} {
expr $value + $increment
}
my_incr 3 42
 45
my_incr 42
 Error: no value given for parameter "value" to “my_incr"
-Procedure names are global
-Variables inside procedures are local
-Variables defined outside of any procedures are global
-Global variables not automatically visible inside procedures. They are accessed inside the
procedure, using the following command
>> global varname1 varname2 …
pt_shell> man return
NAME
return - Return from a procedure
SYNOPSIS
return ?-code code? ?-errorinfo info? ?-errorcode code? ?string?
DESCRIPTION
Return immediately from the current procedure (or top-level command or
source command), with string as the return value. If string is not
specified then an empty string will be returned as result.
The commands used to perform pattern matching for strings:
# Exact pattern matching
string exact pattern string
# Glob style pattern matching
string match pattern string
# Regular expression pattern matching and string extraction or counting
regexp
# Regular expression pattern matching and replacing
regsub
More information on the rules and the need for curly braces in the above examples
can be found in the next workshop The Power of Tcl 2: Creating high impact
procedures.
This example does NOT work exactly as shown above. Each timing report will have a
date stamp which will differ. This date stamp must be eliminated and then the
remainder of the timing report can be matched.
The command that allows you to manipulate strings based on indices is string.
pt_shell> man glob
NAME
glob - Return names of files that match patterns
SYNOPSIS
glob ?switches? pattern ?pattern ...?
DESCRIPTION
This command performs file name ``globbing'' in a fashion similar to
the csh shell. It returns a list of the files whose names match any of the
pattern arguments.
The file name and the design name are assumed to be equivalent for the above example.
Use caution when parsing tool reports. Synopsys does not guarantee format of reports
from tool version to version.
pt_shell> man incr
NAME
incr - Increment the value of a variable
SYNOPSIS
incr varName ?increment?
DESCRIPTION
Increments the value stored in the variable whose name is varName. The
value of the variable must be an integer. If increment is supplied then
its value (which must be an integer) is added to the value of variable
varName; otherwise 1 is added to varName. The new value is stored as a
decimal string in variable varName and also returned as result.

You might also like