【发布时间】:2022-01-17 21:08:58
【问题描述】:
我最近从 Specman/e 过渡到 SystemVerilog,我正在努力解决 SystemVerilog 中数组方法的限制。 我有一个类对象数组,每个类对象本身都有一个类对象数组。 我想检查数组是否有一个项目,其子数组有一个具有特定值的项目。 在 Specman 中,这很简单:
struct axi_beat_s {
addr : int;
};
struct axi_trans_s {
beat_list : list of axi_beat_s;
};
var axi_trans_list : list of axi_trans_s;
//Populate axi_trans_list, not shown here
//Check if the axi trans list has a trans with a beat with address 0
if (axi_trans_list.has(it.beat_list.has(it.addr == 0))) { //This is the line I want to replicate
//do something
} else {
//do something else
};
在 SystemVerilog 中实现相同目标的最佳方法是什么? 这是我在下面的尝试,但它涉及创建 2 个临时数组和几行代码。有没有更简单的方法?
class axi_beat_s;
int addr;
endclass
class axi_trans_s;
axi_beat_s beat_list [$];
endclass
axi_trans_s axi_trans_list [$];
//Populate axi_trans_list, not shown here
axi_trans_s axi_trans_list_temp [$];
axi_beat_s axi_beat_list_temp [$];
foreach(axi_trans_list[idx]) begin
axi_beat_list_temp = axi_trans_list[idx].beat_list.find with (item.addr == 0);
if (axi_beat_list_temp.size() > 0)
axi_trans_list_temp.push_back(axi_trans_list[idx]);
if (axi_trans_list_temp.size() > 0)
$display("Found item with addr 0");
else
$display("Did not find item with addr 0");
end
这里的工作示例: https://www.edaplayground.com/x/RFEk
同样 Specman 有一个方法 'all' 可以用来收集所有匹配项,类似于 SystemVerilog 中的 'find'。但同样,我找不到基于嵌套类对象。
【问题讨论】:
标签: arrays list system-verilog