如何将参数从 cmd 传递到 ModelSim 的 tcl 脚本

How to pass arguments from cmd to tcl script of ModelSim

我在 python 程序的 cmd 中 运行 Modelsim。 我使用以下代码调用一个 tcl 脚本,其中 运行 modelsim:

os.system("vsim -c -do top_tb_simulate_reg.tcl " )

tcl 脚本包含以下内容:

vsim -voptargs="+acc" +UVM_TESTNAME=test_name +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl

我希望 +UVM_TESTNAME 的值是我在执行时从 cmd 传递的参数:

os.system("vsim -c -do top_tb_simulate_reg.tcl " )

我该怎么做?

我尝试了以下但没有成功:

Python 脚本:

os.system("vsim -c -do top_tb_simulate_reg.tcl axi_rd_only_test" )

仿真文件(tcl脚本)

vsim -voptargs="+acc" +UVM_TESTNAME=$argv +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl

我收到以下错误:

# ** Error: (vsim-3170) Could not find 'C:/raft/raftortwo/girobo2/ver/sim/work.axi_rd_only_test'.

问题是 vsim 二进制文件正在对参数进行自己的处理,这是干扰。虽然是的,但您可能可以通过阅读 vsim 文档找到解决此问题的方法,解决此问题的最简单方法是通过 环境变量 传递值。它们由进程从其父进程继承,并且适合传递大多数内容。 (安全令牌除外,它应该始终在具有正确设置权限的文件中传递,而不是环境变量 命令行参数。)

在您的 python 代码中:

# Store the value in the *inheritable* environment
os.environ["MY_TEST_CASE"] = "axi_rd_only_test"

# Do the call; the environment gets passed over behind the scenes
os.system("vsim -c -do top_tb_simulate_reg.tcl " )

在你的 tcl 代码中:

# Read out of the inherited environment
set name $env(MY_TEST_CASE)

# Use it! (Could do this as one line, but that's hard to read)
vsim -voptargs="+acc" +UVM_TESTNAME=$name +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl

聚会迟到了,但我找到了一个很好的解决方法来解决你的障碍。 Modelsim 的 TCL 实例中的 do 命令确实接受参数。参见 command reference

vsim -c -do filename.tcl不能带参数,但是可以用vsim -c -do "do filename.tcl params".

在您的情况下,这转换为 os.system('vsim -c -do "do top_tb_simulate_reg.tcl axi_rd_only_test"')。您的 .tcl 脚本将找到通过变量 .

传递的参数

希望能帮到大家!