cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Voyager
Voyager
849 Views
Registered: ‎04-12-2012

Use of quotes inside a TCL script

Hello,

When is it required to use quotes (" ") inside a TCL command.

For example:

both:

get_files *top*

and

get_files "*top*"

Return the same result.

When will the result be different is we use " " ?

 

0 Kudos
10 Replies
Highlighted
Moderator
Moderator
809 Views
Registered: ‎11-04-2010

Re: Use of quotes inside a TCL script

Hi, @shaikon ,

In the senario you mentioned, the result is same.

Please consider the below situation:

Ex: puts "tt  t"

Without "", the space character cannot be included into the string.

-------------------------------------------------------------------------
Don't forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
765 Views
Registered: ‎01-22-2015

Re: Use of quotes inside a TCL script

@shaikon 

In Tcl, double quotes and curly braces allow you to group multiple words into a single argument.  Double quotes do this with substitution and curly braces do this without substitution.  Here, substitution means that if one of the words is a Tcl variable then the value of the variable is used instead of the variable name.

So, I agree with hongh that the double quotes make no difference in your example because you have a single word, *top*,  that is not a Tcl variable.

The following examples explain further:

set var1 happy
set var2 $var1
set var3 $var1 birthday
set var4 “$var1 birthday”
set var5 {$var1 birthday}

The 1st line sets variable, var1, equal to happy.

The 2nd line sets variable, var2, equal to the value, happy, of var1.

The 3rd line is a syntax error because the two words, $var1 and birthday, appear to be two arguments (and the set command can take only one argument).

The 4th line combines the two words, $var1 and birthday, into a single argument and sets var4 equal to happy birthday.  Note that the substitution, $var1=happy, has been used.

The 5th line combines the two words, $var1 and birthday, into a single argument and sets var5 equal to $var1 birthday. Note that the substitution, $var1=happy, has not been used.

Mark

Tags (2)
Highlighted
Voyager
Voyager
754 Views
Registered: ‎04-12-2012

Re: Use of quotes inside a TCL script

Thanks for the example.
So when { } are used the special character $ isn't evaluated as such ? It's simply another character ?
0 Kudos
Highlighted
721 Views
Registered: ‎01-22-2015

Re: Use of quotes inside a TCL script

@shaikon 

     So when { } are used the special character $ isn't evaluated as such ? It's simply another character ?
Yes.  Curly braces, { }, cause everything inside to be treated as “simply another character”.

By the way, use of square braces, [ ], in Tcl requires some explanation.  They are special characters for Tcl but not always for “Vivado Tcl” (see pg7 of UG894).  The following examples explain further:

set_false_path -from [get_cells DAT1_reg]
set_false_path -from [get_cells {DAT_reg[*]}]
set_false_path -from [get_cells DAT_reg[*]]


In the 1st line, the [ ] are special characters indicating that get_cells is a nested part of the set_false_path command.

In the 2nd line, the [ ] in DAT_reg[*] are not treated as special characters because DAT_reg[*] is enclosed by { }.  However, the wildcard, *, will operate as you expect and is therefore a kind of special character.

In the 3rd line, the [ ] in DAT_reg[*] are not treated as special characters because of special Vivado rules for Tcl (pg7, UG894).  So, the 3rd line does the same thing as the 2nd line.

For Vivado netlist names, I tend to follow the 2nd line example. That is, I enclose the netlist name with { } to ensure that nothing is treated as a special character (except the wildcard character).

Highlighted
Voyager
Voyager
691 Views
Registered: ‎04-12-2012

Re: Use of quotes inside a TCL script

So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?

0 Kudos
Highlighted
679 Views
Registered: ‎01-22-2015

Re: Use of quotes inside a TCL script

@shaikon 

So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?
Yes - good summary!

Tcl is powerful and fun to fiddle with.  You can learn lots about Tcl  by opening a Vivado implemented design and typing Tcl commands into the Vivado Tcl Console.  The Tcl Console has an auto-complete feature that helps you type commands quickly and helps you remember Tcl syntax.  The Tcl Console also has great "help".   For example, to learn about the get_cells command, type help get_cells into the Tcl Console.

After you are done Tcl-fiddling in an open implemented design, Vivado may ask if you want to save things when you close the implemented design.  You should say NO - otherwise your Tcl-fiddling can all be written into the Vivado project .xdc-file (at the end of the file).

Highlighted
Guide
Guide
657 Views
Registered: ‎01-23-2009

Re: Use of quotes inside a TCL script

So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?

Its actually a fair bit more complicated than that...

First, Tcl is an interpreted language - each command is interpreted separately. The interpretation is done in two passes:

  • Elaboration
    • The parsing of the command and expanding any special characters in them
      • This includes variable (and array) dereferencing (for $var) and command identification (finding the stuff in the square brakets)
        • This is recursive - when a command is found in square brakets (not protected by hard quotes) the text inside the square brakets goes through its own elaboration and execution phase, and the result is substituted in place of the command
  • Execution
    • The command is actually performed

In the elaboration phase, the * character is not special in any way it is simply a character.

Thus in the command

set_false_path -from [get_cells DAT_reg[*]]

the string "DAT_reg[*]" becomes the argument to the get_cells command. 

The get_cells command is a command that searches the Vivado Design Suite Database for a cell that matches the name "DAT_reg[*]" - it is specifically the get_cells command (and other similar commands) that uses wildcards in this search - you can see this by doing "help get_cells" - it describes the wildcarding capability of the get_cells command. In fact, you can even change the nature of this wildcarding by adding the -regexp option to the get_cells command, which changes the wildcard mechanism from simple "glob" style wild carding to regular expression wildcarding.

Avrum

Highlighted
Voyager
Voyager
583 Views
Registered: ‎04-12-2012

Re: Use of quotes inside a TCL script

Can you post an example (expanding Mark's example)

set_false_path -from [get_cells {DAT_reg[*]}]

showing how we can make the asterisk * also a non-special character ? (Disabling its wildcarding capability as if * was part of the name...

0 Kudos
Highlighted
535 Views
Registered: ‎01-22-2015

Re: Use of quotes inside a TCL script

@shaikon 

     …how we can make the asterisk * also a non-special character ?

In both VHDL and Verilog, the asterisk cannot be used in an identifier/name.  Further, (I think) Vivado will not create netlist names that have the asterisk character.  So, in the set_false_path example, I don’t think you will ever want to escape the wildcard meaning of the asterisk.

As Avrum has explained, Tcl commands undergo elaboration and execution.  Mostly we encounter Tcl characters (eg. $ [ ] ) that are special during elaboration but not during execution.  However, the asterisk is special during Tcl execution and not during Tcl elaboration. 

I have not found a way to escape/disable the meaning of characters like the asterisk that are special only during execution.

Of course, you can escape the meaning of characters that are special only during elaboration by surrounding them with { }.  

Sometimes, when using “ “, we want to escape the meaning of characters that are special only during elaboration.  This can be done with the backslash, \.  Whatever follows \ up to the closing “ is escaped.

The following examples explain further.

set var1 “DAT_reg[*]”   
set var2 “DAT_reg[“   
set var3 “DAT_reg\[“  
set var4 “*\]”    
get_cells “$var3$var4”
get_cells “$var1”
get_cells {DAT_reg[*]}
get_cells "$var3\$var4"

In line-1, var1 is assigned the value, DAT_reg[*], without error because "Vivado Tcl" recognizes [*] as not-special characters.

Line-2 is a syntax error, 'missing close-bracket', because [  alone is recognized as a special character.

In line-3, the backslash is used to escape [ .  Also, var3 is assigned the value, DAT_reg[

In line-4, var4 is assigned the value, *]

Lines 5, 6, 7 are all valid Tcl commands and are all equivalent to each other.

Line 8 looks for cells having the characters, DAT_reg[$var4.  Note how the backslash has escaped all of $var4  (ie. up to the closing " ).

0 Kudos
Highlighted
Guide
Guide
533 Views
Registered: ‎01-23-2009

Re: Use of quotes inside a TCL script

showing how we can make the asterisk * also a non-special character ? (Disabling its wildcarding capability as if * was part of the name...

First, I don't think this is useful - I am pretty sure that no identifier in the Vivado design suite database can include a * (so matching the character * wouldn't be anything you would ever use...)

There also isn't much documentation on the wildcarding capabilities of Vivado, it mentions * for any number of characters and ? for a single character (and nothing else really).

If we look to other "glob" style wildcarding systems, the way to disable a special character is with a backslash in front of it, so \* might have been the way to do it, but trying

get_cells \*

seems to behave exactly as

get_cells *

(regardless of what kind of quotes you use).

Next, I would have thought that

get_cells -regexp \*

would have worked  - if this were a real regexp then that should match only the * character, but I tried a couple of things and it doesn't seem to. In fact, the way it treats the * character even with the -regexp seems "odd" (aka. incorrect).

So, my suspicion is that it isn't possible (and there is no real reason that anyone should care).

Avrum