【问题标题】:Array methods for nested list of class objects嵌套类对象列表的数组方法
【发布时间】: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


    【解决方案1】:

    您想使用数组缩减方法,而不是 find 方法。

    find 方法返回一个与所选元素集类型相同的数组——它不能嵌套。如果你只是想得到一个真假结果,数组归约方法返回单个值并且可以嵌套。

    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 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2021-12-06
      • 2021-04-21
      • 2021-11-12
      • 2022-01-16
      • 1970-01-01
      • 2021-04-10
      相关资源
      最近更新 更多