class 对象的嵌套列表的数组方法
Array methods for nested list of class objects
我最近从 Specman/e 过渡到 SystemVerilog,我正在为 SystemVerilog 中数组方法的限制而苦苦挣扎。
我有一个 class 对象数组,每个对象内部都有一个 class 对象数组。
我想检查数组是否有一个项目,其子数组是否有一个具有特定值的项目。
在 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'。但是同样,我找不到基于嵌套的 class 对象。
您想使用数组缩减方法,而不是 find
方法。
find
方法return是一个与所选元素集类型相同的数组——它不能嵌套。如果你只是想得到一个真或假的结果,数组缩减方法return单个值并且可以嵌套。
initial begin
// populate list not shown here
if (axi_trans_list.or() with (item.beat_list.or() with (item.addr==0)))
$display("Found item with addr 0");
else
$display("Did not find item with addr 0");
end
我最近从 Specman/e 过渡到 SystemVerilog,我正在为 SystemVerilog 中数组方法的限制而苦苦挣扎。 我有一个 class 对象数组,每个对象内部都有一个 class 对象数组。 我想检查数组是否有一个项目,其子数组是否有一个具有特定值的项目。 在 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'。但是同样,我找不到基于嵌套的 class 对象。
您想使用数组缩减方法,而不是 find
方法。
find
方法return是一个与所选元素集类型相同的数组——它不能嵌套。如果你只是想得到一个真或假的结果,数组缩减方法return单个值并且可以嵌套。
initial begin
// populate list not shown here
if (axi_trans_list.or() with (item.beat_list.or() with (item.addr==0)))
$display("Found item with addr 0");
else
$display("Did not find item with addr 0");
end