计算系统Verilog中模块的实例
我正在尝试使用SystemVerilog设计简单的CPU,并且我会使用SystemVerilog设计和模型来模拟设计。我正在尝试设置一些代码来计算特定模块的实例数。我目前正在使用静态变量来实现这一目标,但是它不起作用。我的代码如下。
module testbench;
logic a0, b0, y0;
logic a1, b1, y1;
logic a2, b2, y2;
AND and0(.a(a0), .b(b0), .y(y0));
AND and1(.a(a1), .b(b1), .y(y1));
AND or0(.a(a2), .b(b2), .y(y2));
initial
begin
$display("AND Gates : ", and0.instance_count);
$display("OR Gates : ", or0.instance_count);
end
endmodule
module AND(input logic a, b, output logic y);
static int instance_count = 0;
initial
instance_count++;
and(y, a, b);
endmodule
module OR(input logic a, b, output logic y);
static int instance_count = 0;
initial
instance_count++;
or(y, a, b);
endmodule
这给出的输出是不正确的门和门的1个实例。我该如何更改代码来解决此问题?除此之外,如果可能的话,可以通过modelsim确定的解决方案可以通过modelsim确定,而我不需要我将任何代码添加到我的模型中,这是理想的解决方案。
I am attempting to design a simple CPU and I ma using SystemVerilog to design and ModelSim to simulate the design. I am trying to set up some code to count the number of instances of a specific module. I am currently using static variables to try to achieve this however it is not working. My code is as follows.
module testbench;
logic a0, b0, y0;
logic a1, b1, y1;
logic a2, b2, y2;
AND and0(.a(a0), .b(b0), .y(y0));
AND and1(.a(a1), .b(b1), .y(y1));
AND or0(.a(a2), .b(b2), .y(y2));
initial
begin
$display("AND Gates : ", and0.instance_count);
$display("OR Gates : ", or0.instance_count);
end
endmodule
module AND(input logic a, b, output logic y);
static int instance_count = 0;
initial
instance_count++;
and(y, a, b);
endmodule
module OR(input logic a, b, output logic y);
static int instance_count = 0;
initial
instance_count++;
or(y, a, b);
endmodule
The output this gives is 1 instance for both the AND gates and OR gates, which is incorrect. How could I change my code to fix this issue? In addition to this, a solution to this problem which can be determined through modelsim and not require me to add any code to my model would be an ideal solution, if that is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模块级别上的所有声明已经
static
,每个模块实例都有单独的变量实例分配。您可以使用关联阵列创建一个全局软件包。
SystemVerilog没有内置的内省,但是是将其构建到您的流程的方式您真的想深入了解VPI细节。
但是,包括Modelsim在内的许多工具具有类似的TCL命令
,很容易编写单个实例的计数脚本。
All declarations at the module level are already
static
, and each module instance has a separate allocation of variable instances.You could create a global package with an associative array.
SystemVerilog has no built-in introspection, but there are ways of building it in to your flow if you really want to dive into the VPI details.
But many tools including ModelSim have Tcl commands like
that would be easy to write a counting script of individual instances.