How to call Tcl command with conditional option

2019-08-25 07:41发布

问题:

I want to conditionally append options when calling a Tcl command. I'm using a Xilinx Tcl command synth_design as indicated in UG835 p.1042 using Tcl version 8.5.

For instance, I want to:

  1. build a data structure that will append 0 or more of -verilog_define MACRO where -verilog_define is not a string but an option, and
  2. pass that structure to the command in its expanded form.

Where this:

synth_design -top ${top}_top -part ${part} -verilog_define MACRO1 -verilog_define MACRO2
                                           ^-------------------------------------------^

Becomes this:

synth_design -top ${top}_top -part ${part} ???
                                           ^-^

回答1:

With {*}$makro (expansion)

E.g.:

set makro {-verilog_define MACRO1 -verilog_define MACRO2}
synth_design -top ${top}_top -part ${part} {*}$makro