【问题标题】:Does Verilog `ifdef respond to environment variables?Verilog `ifdef 是否响应环境变量?
【发布时间】:2019-07-03 05:30:13
【问题描述】:

如果我有以下 Verilog 代码:

//test.v

`ifdef V1
{code block 1}
`else
{code block 2}
`endif

我可以使用标准环境变量定义语法从命令行“引导”条件吗? 例如,这会导致 {code block 1} 执行吗?:

$ V1=1 <simulator> test.v

【问题讨论】:

  • 不,verilog 模拟器不应该识别环境变量。根据模拟器的不同,您可能能够在命令行中定义 verilog 宏。确切的方式取决于模拟器的实现。请查阅模拟器文档。

标签: macros system-verilog conditional-compilation


【解决方案1】:

ifdef 语句是一个编译器指令,很像 C 或 C++ 中的预处理器指令,因此您可以使用 -D$var 标志以类似的方式通过命令行传递它们。

假设我们有以下模块:

// test.v

module hello;
  initial 
    begin
`ifdef V1
      $display("V1 defined!");
`else
      $display("V1 not defined!");
`endif
      $finish ;
    end
endmodule

然后以 IcarusVerilog 为例,您可以使用以下命令在命令行上定义 V1

terminal:~$ iverilog -DV1 -o test test.v
terminal:~$ vvp test
V1 defined!
terminal:~$ iverilog -o test test.v
terminal:~$ vvp test
V1 not defined!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-15
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多