Tcl uses the Linux file separator (/) convention regardless of which Operating System you are running.
The following subsections describe the general syntax guidelines for using Tcl in the Vivado Design Suite.
Using Tcl Eval
When executing Tcl commands, you can use variable
substitution to replace some of the command line arguments accepted or required by the Tcl
command. However, you must use the Tcl eval
command to evaluate the command
line with the Tcl variable as part of the command.
help
command can take the
-category argument, with one of a number of command
categories as options:
help -category ipflow
set cat "ipflow"
-
set
is the Tcl keyword that defines the variable. -
cat
is the name of the variable being defined. -
"ipflow"
is the value assigned to the variable.
eval help -category $cat
set cat "category ipflow" eval help $cat
set runblocksOptDesignOpts { -sweep -retarget -propconst -remap }
eval opt_design $runblocksOptDesignOpts
Typing
help eval
in the Tcl console will provide additional information
regarding the eval
command.
Using Special Characters
Some commands take arguments that contain characters that have special meaning to Tcl. Those arguments must be surrounded with curly braces {} to avoid unintended processing by Tcl. The most common cases are as follows.
[]
have
special meaning to Tcl, an indexed (bit- or part-selected) bus using the square bracket
notation must be surrounded with curly braces. For example, when adding index 4 of a bus to
the Vivado Common Waveform Viewer window using the square bracket notation, you must write
the command as:
add_wave {bus[4]}
add_wave bus(4)
add_wave {\my wire }
add_wave {\w }
add_wave w
add_wave \\my\ sig\\
General Syntax Structure
The general structure of Vivado Design Suite Tcl commands is:
command [optional_parameters] required_parameters
Command syntax is of the verb-noun and verb-adjective-noun structure separated by the underscore (“_”) character.
-
Commands that query things are generally prefixed with
get_
. -
Commands that set a value or a parameter are prefixed with
set_
. -
Commands that generate reports are prefixed with
report_
.
Example Syntax
get_cells -help
command:get_cells
Description:
Get a list of cells in the current design
Syntax:
get_cells [-hsc <arg>] [-hierarchical] [-regexp] [-nocase] [-filter <arg>]
[-of_objects <args>] [-match_style <arg>] [-quiet] [-verbose]
[<patterns>]
Returns:
list of cell objects
Usage:
Name Description
----------------------------
[-hsc] Hierarchy separator
Default: /
[-hierarchical] Search level-by-level in current instance
[-regexp] Patterns are full regular expressions
[-nocase] Perform case-insensitive matching (valid only when -regexp
specified)
[-filter] Filter list with expression
[-of_objects] Get cells of these pins, timing paths, nets, bels, sites
or drc violations
[-match_style] Style of pattern matching
Default: sdc
Values: ucf, sdc
[-quiet] Ignore command errors
[-verbose] Suspend message limits during command execution
[<patterns>] Match cell names against patterns
Default: *
Categories:
SDC, XDC, Object
Unknown Commands
Tcl contains a list of built-in commands that are generally supported by the language, Vivado tool specific commands which are exposed to the Tcl interpreter, and user-defined procedures.
Commands that do not match any of these
known commands are sent to the OS for execution in the shell from the exec
command. This lets users execute shell commands that might be OS-specific. If there is no
shell command, then an error message is issued to indicate that no command was
found.
Return Codes
Some Tcl commands are expected to provide a return value, such as a list or collection of objects on which to operate. Other commands perform an action but do not necessarily return a value that can be used directly by the user. Some tools that integrate Tcl interfaces return a 0 or a 1 to indicate success or error conditions when the command is run.
To properly handle errors in Tcl commands or
scripts, you should use the Tcl built-in command catch
. Generally, the
catch
command and the presence of numbered info, warning, or error
messages should be relied upon to assess issues in Tcl scripted flows.
Vivado tool Tcl commands return either TCL_OK or TCL_ERROR upon completion. In addition, the Vivado Design Suite sets the global variable $ERRORINFO through standard Tcl mechanisms.
To take advantage of the $ERRORINFO variable, use the following line to report the variable after an error occurs in the Tcl console:
puts $ERRORINFO
Line 1: Vivado % source procs.tcl
Line 2: Vivado% loads
Line 3: Found 180 driving FFs
Line 4: Processing pin a_reg_reg[1]/Q...
Line 5: ERROR: [HD-Tcl 53] Cannot specify '-patterns' with '-of_objects'.
Line 6: Vivado% puts $errorInfo
Line 7: ERROR: [HD-Tcl 53] Cannot specify '-patterns' with '-of_objects'.
While executing "get_ports -of objects $pin" (procedure "my_report" line 6)
invoked from within procs.tcl
You
can add puts $ERRORINFO
into catch clauses in your Tcl script files to
report the details of an error when it is caught, or use the command interactively in the
Tcl console immediately after an error is encountered to get the specific details of the
error.In the example code above, typing the puts $ERRORINFO
command
in line 6, reports detailed information about the command and its failure in line
7.