Search code examples
tclfpgaxilinxvivado

Vivado/TCL get_cells with dynamic regexp


I've written a small example of what I want to do and what output I recieve.

set a 0
set tmp [get_cells -hier -regexp [ format .*latch\[%d\].* $a ] ]
puts [ llength $tmp ]

set tmp [get_cells -hier -regexp {.*latch\[0\].*}]
puts [ llength $tmp ]

Output:

WARNING: [Vivado 12-180] No cells matched '.*latch[0].*'. [C:/dev/jesd204b_clock_gen/logic/proj/xilinx/2017.4/Test1/Test1.srcs/sources_1/tdc/TDCConstraints.tcl:24]
0
16

As you can see, the first get_cells call returns a warning and 0 elements, even though it has the same regex expression as the second call, which succeeds
What did I do wrong, and how can I fix this behaviour?
Many thanks for answer.


Solution

  • They are not really the same however:

    % format .*latch\[%d\].* $a
    .*latch[0].*
    % puts {.*latch\[0\].*}
    .*latch\[0\].*
    

    You will have to use braces in format, or double escape the string, i.e. use:

    format {.*latch\[%d\].*} $a
    

    Or

    format .*latch\\\[%d\\\].* $a