在 systemverilog 中勾选包内的头文件

Tick-including a header file inside package in systemverilog

您好,我遇到了以下情况,但它对我不起作用。

文件:a.svh

a.svh 定义了一些参数和函数——比方说函数 xyz(b)

文件b.sv

package b;
`include "a.svh"

typedef logic[(xyz(10)-1):0] h;

endpackage

现在的问题是,b.sv 在它的范围内找不到 xyz 函数,即使我在 b.sv 中勾选了 a.svh。如果我不使用 b.sv 文件中的包,一切正常。 (注释掉 package b 和 endpackage 行)。

//package b;
`include "a.svh"

typedef logic[(xyz(10)-1):0] h;

//endpackage

是否是systemverilog中的非法案例?

我在 EDAplayground 上重新创建了您的场景。我没有收到任何错误。

A function 旨在在模拟期间进行评估。一些模拟器支持在 compile/elaboration 期间评估函数,但这似乎不是必需的。

SystemVerilog 还有let,更适合编译时评估(它也支持仿真时)。参考IEEE Std 1800-2012 § 11.13 让构造:

let declarations can be used for customization and can replace the text macros in many cases. The let construct is safer because it has a local scope, while the scope of compiler directives is global within the compilation unit. Including let declarations in packages (see Clause 26) is a natural way to implement a well-structured customization for the design code.

a.svh

function int xyz_func(int b);
  return b;
endfunction
let xyz_let(b) = b;

design.sv(相当于你的b.sv,EDAplayground需要design.sv才能存在)

package b;
`include "a.svh"

typedef logic[(xyz_func(10)-1):0] hf;
typedef logic[xyz_let(10):1] hl;

endpackage

testbench.sv

module tb;
  import b::*;
  hf myhf;
  hl myhl;
  initial begin
    myhf = -1;
    myhl = -1;
    $display("hf:%b left:%0d right:%0d", myhf, $left(myhf), $right(myhf));
    $display("hl:%b left:%0d right:%0d", myhl, $left(myhl), $right(myhl));
  end
endmodule

输出:

hf:1111111111 left:9 right:0
hl:1111111111 left:10 right:1