什么是在编译时抛出错误的 LINT/synthesis 安全语句?

What is a LINT/synthesis safe statement to throw an error at compile time?

我有一个模块,它传递了一个 parameter 然后实例化了另一个与定义的参数相对应的模块。

但是,如果没有为特定的参数组合定义 case,我希望在编译时抛出错误以突出显示问题,如下所示:

generate
if (PARAM1 == 1 && PARAM2 == 2) begin

   // instantiate module logic_A

end else if (PARAM1 == 2 && PARAM2 == 1) begin              

   // instantiate module logic_B

end else begin

   // throw an error at compile time if we haven't
   // defined a case for those parameters 

end
endgenerate

但是,尽管插入错误,此代码仍然需要可综合(在 Verilog 中,而不是 SystemVerilog 中)并通过 LINTing。

有人知道我在这种情况下可以使用什么吗?提前谢谢你。

没有。 verilog 中没有这方面的内容。你不能在编译时这样做。

但是您可以做一些事情来转储错误并在模拟中的时间“0”退出。

在系统verilog中你可以添加一个断言:

initial assert(0) else $fatal("--error--");

或者只是

initial $fatal("--error--");

否则类似:

 initial begin $display("--error--"); $finish; end

两者都会在模拟开始时提供一条消息。

它有点笨拙,我不知道你的 lint 工具在检查什么,但是这个怎么样:

generate
  if (PARAM1 == 1 && PARAM2 == 2) begin

    // instantiate module logic_A

  end else if (PARAM1 == 2 && PARAM2 == 1) begin              

    // instantiate module logic_B

  end else begin

    reg ILLEGAL_VALUES_ON_PARAM1_AND_PARAM2;
    reg DUMMYO, DUMMYI;
    always @(posedge ILLEGAL_VALUES_ON_PARAM1_AND_PARAM2 or negedge ILLEGAL_VALUES_ON_PARAM1_AND_PARAM2)
      DUMMYO <= DUMMYI;

  end
endgenerate

当我将 PARAM1 设置为 3 时,这会在 Quartus 上出现以下错误:

Error (10239): Verilog HDL Always Construct error at synth_assertion.v(18): event control cannot test for both positive and negative edges of variable "ILLEGAL_VALUES_ON_PARAM1_AND_PARAM2"

我在姊妹网站 Electronics StackExchange 上针对“a way of conditionally triggering a compile-time error in verilog”回答了非常相似的问题。解决方案是有条件地实例化一个不存在的模块。我建议不存在的模块有一个很长的名字和有意义的名字来解释错误。这也降低了不存在的模块意外地与现有模块同名的风险。

generate
if (PARAM1 == 1 && PARAM2 == 2) begin : use_logicA
   // instantiate module logic_A
end
else if (PARAM1 == 2 && PARAM2 == 1) begin : use_logicB
   // instantiate module logic_B
end
else begin : illegal
   illegal_parameter_condition_triggered_will_instantiate_an non_existing_module();
end
endgenerate

之所以可行,是因为在细化阶段评估参数值之后才会检查不存在的模块是否存在。


更好的解决方案是使用 SystemVerilog 方法;特别是带有符合 IEEE Std 1800-2009 标准或更新标准的模拟器。然后您可以使用 $error() 并提供更有意义的消息来处理错误(例如,打印触发错误条件的参数值)。您可以在 IEEE Std 1800-2012 20.11 精化系统任务

中阅读更多相关信息
generate
if (PARAM1 == 1 && PARAM2 == 2) begin : use_logicA
   // instantiate module logic_A
end
else if (PARAM1 == 2 && PARAM2 == 1) begin : use_logicB
   // instantiate module logic_B
end
else begin : illegal
   $error("Expected PRAM1/2 to be 1/2 or 2/1, but was %0d/%0d", PARAM1, PARAM2 );
end
endgenerate