在没有名称的情况下在 verilog 中向上引用?
Upwards referencing in verilog without name?
如 中所述,verilog 支持“向上名称引用”。我的问题是是否可以使用模块名称以外的其他名称来执行此分层引用:
- 可以使用parent的实例名(
d1
,d2
)吗?
- 是否有一些内置的
$parent
或类似的?
模块名称 DUT
用于向上引用的示例:
module DUT(input clk);
wire a;
function void hello;
$display("Hello from %m");
endfunction
printer p(clk);
endmodule
module printer(input clk);
always @(posedge clk)
$display("a is %d", DUT.a); // Can this "DUT" here be replaced with something else?
initial DUT.hello;
endmodule
module TB;
reg clock;
DUT d1(clock);
DUT d2(clock);
endmodule
是的,您可以使用实例名称。在那种情况下,它会一直走到 TB 范围并找到 d1
和 d2
。所有搜索规则在 23.8 向上引用 部分中的 IEEE 1800-2017 SystemVerilog LRM.
部分进行了解释
基本上,对于 scope_name 的第一部分,规则首先在本地范围内查找。然后查看当前模块中的封闭范围,然后查找实例树。一旦找到 scope_name(在您的情况下为 d1
),则 d1.a
必须存在。它不会继续搜索另一个 d1
范围。 (顺便说一句,这些规则与 Verilog 保持不变)
匿名向上参考没有$parent
。 SystemVerilog中有$root
作为绝对引用
如
- 可以使用parent的实例名(
d1
,d2
)吗? - 是否有一些内置的
$parent
或类似的?
模块名称 DUT
用于向上引用的示例:
module DUT(input clk);
wire a;
function void hello;
$display("Hello from %m");
endfunction
printer p(clk);
endmodule
module printer(input clk);
always @(posedge clk)
$display("a is %d", DUT.a); // Can this "DUT" here be replaced with something else?
initial DUT.hello;
endmodule
module TB;
reg clock;
DUT d1(clock);
DUT d2(clock);
endmodule
是的,您可以使用实例名称。在那种情况下,它会一直走到 TB 范围并找到 d1
和 d2
。所有搜索规则在 23.8 向上引用 部分中的 IEEE 1800-2017 SystemVerilog LRM.
基本上,对于 scope_name 的第一部分,规则首先在本地范围内查找。然后查看当前模块中的封闭范围,然后查找实例树。一旦找到 scope_name(在您的情况下为 d1
),则 d1.a
必须存在。它不会继续搜索另一个 d1
范围。 (顺便说一句,这些规则与 Verilog 保持不变)
匿名向上参考没有$parent
。 SystemVerilog中有$root
作为绝对引用