Working with Strings - 2022.2 English

Vivado Design Suite User Guide: Using Tcl Scripting (UG894)

Document ID
UG894
Release Date
2022-10-19
Version
2022.2 English

The -return_string argument directs the output of a report_* command to a Tcl string rather than to stdout. The string can be assigned to a Tcl variable, and parsed or otherwise processed.

set rpt [report_timing -return_string]

After the string has been assigned to a variable, Tcl provides many useful commands for processing the string in a number of ways:

append string [arg1 arg2 ... argN]
Appends the specified args to the end of string.
format formatString [arg1 arg2 ... argN]
Returns a formatted string generated to match the format specified by the formatString template. The template must be specified using % conversion specifiers as used in sprintf. The additional arguments, args, provide values to be substituted into the formatted string.
reg exp [switches] exp string
Returns 1 if the regular expression, exp, matches all or part of string, 0 otherwise. The -nocase switch can be specified to ignore character case when matching.
string match pattern string
Returns 1 if the glob pattern matches string, 0 otherwise.
scan string formatString [ varName1 varName2 ...]
Extracts values from the specified string into variables, varName, applying the formatString using % conversion specifiers as in sscanf behavior. If no varNames are specified, scan returns the list of values to stdout
string range string first last
Returns the range of characters from string specified by character indices first through last inclusive.
string compare string1 string2
Performs a lexicographical comparison of two strings, and returns -1 if string1 comes before string2, 0 if they are the same, and 1 if string1 comes after string2.
string last string1 string2
Return the character index in string2 of the last occurrence of string1. Returns -1 if string1 is not found in string2.
string length string
Returns the number of characters in string.

The following example assigns the results of the report_timing command to the $report Tcl variable, using -return_string. The string is processed to extract the start point, end point, path group and path type of each path. After the path information is extracted, a summary of that path is printed to the Tcl console.

# Capture return string of timing report, and assign variables
set report [report_timing -return_string -max_paths 10]
set startPoint {}
set endPoint {}
set pathGroup {}
set pathType {}
# Write the header for string output
puts [format " %-12s %-12s %-20s -> %-20s" "Path Type" "Path Group" "Start Point" "End Point"]
puts [format " %-12s %-12s %-20s -> %-20s" "---------" "----------" "-----------" "---------"]
# Split the return string into multiple lines to allow line by line processing
foreach line [split $report \n] {
if {[regexp -nocase -- {^\s*Source:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - startPoint]} {
} elseif {[regexp -nocase -- {^\s*Destination:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - endPoint]} {
} elseif {[regexp -nocase -- {^\s*Path Group:\s*([^[:blank:]]+)\s*$} $line - pathGroup]} {
} elseif {[regexp -nocase -- {^\s*Path Type:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - pathType]} {
puts [format " %-12s %-12s %-20s -> %-20s" $pathType $pathGroup $startPoint $endPoint]
}
}

An example output from the code is:

Path Type Path Group Start Point -> End Point
--------- ---------- ----------- -> ---------
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[0]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[10]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[11]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[12]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[13]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[14]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[15]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[16]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[17]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[18]