topic Re: Use of quotes inside a TCL script in Vivado TCL Communityhttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067187#M8732
<P><LI-USER uid="33837"></LI-USER>&nbsp;</P>
<P>&nbsp;<FONT color="#339966"> &nbsp; &nbsp;So when { } are used the special character $ isn't evaluated as such ? It's simply another character ?</FONT><BR />Yes.&nbsp; Curly braces, { }, cause everything inside to be treated as “simply another character”.</P>
<P>By the way, use of square braces, [ ], in Tcl requires some explanation.&nbsp; They are special characters for Tcl but not always for “Vivado Tcl” (see pg7 of UG894).&nbsp; The following examples explain further:</P>
<PRE>set_false_path -from [get_cells DAT1_reg]
set_false_path -from [get_cells {DAT_reg[*]}]
set_false_path -from [get_cells DAT_reg[*]]</PRE>
<P><BR />In the 1<SUP>st</SUP> line, the [ ] are special characters indicating that get_cells is a nested part of the set_false_path command.</P>
<P>In the 2<SUP>nd</SUP> line, the [ ] in DAT_reg[*] are not treated as special characters because DAT_reg[*] is enclosed by { }.&nbsp; However, the wildcard, *, will operate as you expect and is therefore a kind of special character.</P>
<P>In the 3<SUP>rd</SUP> line, the [ ] in DAT_reg[*] are not treated as special characters because of special Vivado rules for Tcl (pg7, UG894).&nbsp; So, the 3<SUP>rd</SUP> line does the same thing as the 2<SUP>nd</SUP> line.</P>
<P>For Vivado netlist names, I tend to follow the 2<SUP>nd</SUP> line example. That is, I enclose the netlist name with { } to ensure that nothing is treated as a special character (except the wildcard character).</P>Wed, 22 Jan 2020 13:53:47 GMTmarkg@prosensing.com2020-01-22T13:53:47ZUse of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1066913#M8725
<P>Hello,</P><P>When is it required to use quotes (" ") inside a TCL command.</P><P>For example:</P><P>both:</P><PRE>get_files *top*</PRE><P>and</P><PRE>get_files "*top*"</PRE><P>Return the same result.</P><P>When will the result be different is we use " " ?</P><P>&nbsp;</P>Tue, 21 Jan 2020 19:39:06 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1066913#M8725shaikon2020-01-21T19:39:06ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1066955#M8726
<P>Hi,&nbsp;<LI-USER uid="33837"></LI-USER>&nbsp;,</P>
<P>In the senario you mentioned, the result is same.</P>
<P>Please consider the below situation:</P>
<P>Ex: puts "tt&nbsp; t"</P>
<P>Without "", the space&nbsp;character cannot be included into the string.</P>Wed, 22 Jan 2020 01:27:36 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1066955#M8726hongh2020-01-22T01:27:36ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067061#M8729
<P><LI-USER uid="33837"></LI-USER>&nbsp;</P>
<P>In Tcl, <STRONG>double quotes</STRONG> and <STRONG>curly braces</STRONG> allow you to group <STRONG>multiple words</STRONG> into a single argument.&nbsp; Double quotes do this with <STRONG>substitution</STRONG> and curly braces do this without substitution.&nbsp; 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.</P>
<P>So, I agree with hongh that the double quotes make no difference in your example because you have a single word, <STRONG>*top*</STRONG>,&nbsp; that is not a Tcl variable.</P>
<P>The following examples explain further:</P>
<PRE>set var1 happy
set var2 $var1
set var3 $var1 birthday
set var4 “$var1 birthday”
set var5 {$var1 birthday}</PRE>
<P>The 1st line sets variable, var1, equal to <STRONG>happy</STRONG>.</P>
<P>The 2nd line sets variable, var2, equal to the value, <STRONG>happy</STRONG>, of var1.</P>
<P>The 3<SUP>rd</SUP> line is a syntax error because the two words, <STRONG>$var1</STRONG> and <STRONG>birthday</STRONG>, appear to be two arguments (and the set command can take only one argument).</P>
<P>The 4<SUP>th</SUP> line combines the two words, <STRONG>$var1</STRONG> and <STRONG>birthday</STRONG>, into a single argument and sets var4 equal to <STRONG>happy birthday.&nbsp; </STRONG>Note that the substitution, $var1=<STRONG>happy,</STRONG> has been used.</P>
<P>The 5<SUP>th</SUP> line combines the two words, <STRONG>$var1</STRONG> and <STRONG>birthday</STRONG>, into a single argument and sets var5 equal to <STRONG>$var1 birthday</STRONG>.&nbsp;Note that the substitution, $var1=<STRONG>happy,</STRONG> has not been used.</P>
<P>Mark</P>Wed, 22 Jan 2020 09:23:37 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067061#M8729markg@prosensing.com2020-01-22T09:23:37ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067085#M8730
Thanks for the example.<BR />So when { } are used the special character $ isn't evaluated as such ? It's simply another character ?Wed, 22 Jan 2020 10:02:24 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067085#M8730shaikon2020-01-22T10:02:24ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067187#M8732
<P><LI-USER uid="33837"></LI-USER>&nbsp;</P>
<P>&nbsp;<FONT color="#339966"> &nbsp; &nbsp;So when { } are used the special character $ isn't evaluated as such ? It's simply another character ?</FONT><BR />Yes.&nbsp; Curly braces, { }, cause everything inside to be treated as “simply another character”.</P>
<P>By the way, use of square braces, [ ], in Tcl requires some explanation.&nbsp; They are special characters for Tcl but not always for “Vivado Tcl” (see pg7 of UG894).&nbsp; The following examples explain further:</P>
<PRE>set_false_path -from [get_cells DAT1_reg]
set_false_path -from [get_cells {DAT_reg[*]}]
set_false_path -from [get_cells DAT_reg[*]]</PRE>
<P><BR />In the 1<SUP>st</SUP> line, the [ ] are special characters indicating that get_cells is a nested part of the set_false_path command.</P>
<P>In the 2<SUP>nd</SUP> line, the [ ] in DAT_reg[*] are not treated as special characters because DAT_reg[*] is enclosed by { }.&nbsp; However, the wildcard, *, will operate as you expect and is therefore a kind of special character.</P>
<P>In the 3<SUP>rd</SUP> line, the [ ] in DAT_reg[*] are not treated as special characters because of special Vivado rules for Tcl (pg7, UG894).&nbsp; So, the 3<SUP>rd</SUP> line does the same thing as the 2<SUP>nd</SUP> line.</P>
<P>For Vivado netlist names, I tend to follow the 2<SUP>nd</SUP> line example. That is, I enclose the netlist name with { } to ensure that nothing is treated as a special character (except the wildcard character).</P>Wed, 22 Jan 2020 13:53:47 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067187#M8732markg@prosensing.com2020-01-22T13:53:47ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067374#M8733
<P>So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?</P>Wed, 22 Jan 2020 21:58:46 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067374#M8733shaikon2020-01-22T21:58:46ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067425#M8734
<P><LI-USER uid="33837"></LI-USER>&nbsp;</P>
<P><SPAN><FONT color="#339966">So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?</FONT><BR />Yes - good summary!</SPAN></P>
<P><SPAN>Tcl is powerful and fun to fiddle with.&nbsp; You can learn lots about Tcl&nbsp; by opening a Vivado implemented design and typing Tcl commands into the Vivado Tcl Console.&nbsp; The Tcl Console has an auto-complete feature that helps you type commands quickly and helps you remember Tcl syntax.&nbsp; The Tcl Console also has great "help".&nbsp; &nbsp;For example, to learn about the <STRONG>get_cells</STRONG> command, type <STRONG>help get_cells</STRONG> into the Tcl Console.</SPAN></P>
<P><SPAN>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.&nbsp; You should say NO - otherwise your Tcl-fiddling can all be written into the Vivado project .xdc-file (at the end of the file).</SPAN></P>Thu, 23 Jan 2020 01:08:03 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067425#M8734markg@prosensing.com2020-01-23T01:08:03ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067465#M8736
<P><SPAN><FONT color="#339966">So the curly brackets { } deactivate the square brackets [ ] from being treated as a special character but not powerful enough to deactivate the asterisk * inside [ ] ?</FONT></SPAN></P>
<P><SPAN>Its actually a fair bit more complicated than that...</SPAN></P>
<P><SPAN>First, Tcl is an interpreted language - each command is interpreted separately. The interpretation is done in two passes:</SPAN></P>
<UL>
<LI><SPAN>Elaboration</SPAN>
<UL>
<LI><SPAN>The parsing of the command and expanding any special characters in them</SPAN>
<UL>
<LI><SPAN>This includes variable (and array) dereferencing (for $var) and command identification (finding the stuff in the square brakets)</SPAN>
<UL>
<LI><SPAN>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</SPAN></LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
<LI><SPAN>Execution</SPAN>
<UL>
<LI><SPAN>The command is actually performed</SPAN></LI>
</UL>
</LI>
</UL>
<P><SPAN>In the elaboration phase, the * character is not special in any way it is simply a character.</SPAN></P>
<P><SPAN>Thus in the command</SPAN></P>
<PRE>set_false_path -from [get_cells DAT_reg[*]]</PRE>
<P><SPAN>the string "DAT_reg[*]" becomes the argument to the get_cells command.&nbsp;</SPAN></P>
<P><SPAN>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.</SPAN></P>
<P><SPAN>Avrum</SPAN></P>Thu, 23 Jan 2020 04:31:33 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1067465#M8736avrumw2020-01-23T04:31:33ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068209#M8739
<P>Can you post an example (expanding Mark's example)</P><PRE>set_false_path -from [get_cells {DAT_reg[*]}]</PRE><P>showing how we can make the asterisk * also a non-special character ? (Disabling its wildcarding capability as if * was part of the name...</P>Sat, 25 Jan 2020 12:16:25 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068209#M8739shaikon2020-01-25T12:16:25ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068238#M8740
<P><LI-USER uid="33837"></LI-USER>&nbsp;</P>
<P><FONT color="#339966">&nbsp; &nbsp; &nbsp;…how we can make the asterisk * also a non-special character ?</FONT></P>
<P>In both VHDL and Verilog, the asterisk cannot be used in an identifier/name.&nbsp; Further, (I think) Vivado will not create netlist names that have the asterisk character.&nbsp; So, in the set_false_path example, I don’t think you will ever want to escape the wildcard meaning of the asterisk.</P>
<P>As Avrum has explained, Tcl commands undergo <STRONG>elaboration</STRONG> and <STRONG>execution</STRONG>.&nbsp; Mostly we encounter Tcl characters (eg. $ [ ] ) that are special during elaboration but not during execution.&nbsp; However, the asterisk is special during Tcl execution and not during Tcl elaboration.&nbsp;</P>
<P>I have not found a way to escape/disable the meaning of characters like the asterisk that are special only during <STRONG>execution</STRONG>.</P>
<P>Of course, you can escape the meaning of characters that are special only during <STRONG>elaboration</STRONG> by surrounding them with { }. &nbsp;</P>
<P>Sometimes, when using “ “, we want to escape the meaning of characters that are special only during <STRONG>elaboration</STRONG>.&nbsp; This can be done with the backslash, \.&nbsp; Whatever follows \ up to the closing “ is escaped.</P>
<P>The following examples explain further.</P>
<PRE>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[*]}<BR />get_cells "$var3\$var4"</PRE>
<P>In line-1, <STRONG>var1</STRONG> is assigned the value,&nbsp;<STRONG>DAT_reg[*], </STRONG>without error because "Vivado Tcl" recognizes <STRONG>[*]</STRONG> as not-special characters.</P>
<P>Line-2 is a syntax error, 'missing close-bracket', because <STRONG>[</STRONG>&nbsp; alone is recognized as a special character.</P>
<P>In line-3, the backslash is used to escape <STRONG>[</STRONG>&nbsp;.&nbsp; Also,&nbsp;<STRONG>var3</STRONG> is assigned the value, <STRONG>DAT_reg[</STRONG></P>
<P>In line-4, <STRONG>var4 </STRONG>is assigned the value,<STRONG> *]</STRONG></P>
<P>Lines 5, 6, 7 are all valid Tcl commands and are all equivalent to each other.</P>
<P>Line 8 looks for cells having the characters,&nbsp;<STRONG>DAT_reg[$var4</STRONG>.&nbsp; Note how the backslash has escaped all of<STRONG> $var4&nbsp; </STRONG>(ie. up to the closing " ).</P>Sat, 25 Jan 2020 19:00:10 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068238#M8740markg@prosensing.com2020-01-25T19:00:10ZRe: Use of quotes inside a TCL scripthttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068240#M8741
<P class="lia-indent-padding-left-30px"><FONT color="#339966">showing how we can make the asterisk * also a non-special character ? (Disabling its wildcarding capability as if * was part of the name...</FONT></P>
<P>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...)</P>
<P>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).</P>
<P>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</P>
<P>get_cells \*</P>
<P>seems to behave exactly as</P>
<P>get_cells *</P>
<P>(regardless of what kind of quotes you use).</P>
<P>Next, I would have thought that</P>
<P>get_cells -regexp \*</P>
<P>would have worked&nbsp; - 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).</P>
<P>So, my suspicion is that it isn't possible (and there is no real reason that anyone should care).</P>
<P>Avrum</P>Sat, 25 Jan 2020 19:14:31 GMThttps://forums.xilinx.com/t5/Vivado-TCL-Community/Use-of-quotes-inside-a-TCL-script/m-p/1068240#M8741avrumw2020-01-25T19:14:31Z