【问题标题】:SystemVerilog - go over all the child member from the parent classSystemVerilog - 遍历父类的所有子成员
【发布时间】:2016-12-08 07:28:16
【问题描述】:

我有以下基类:

class base_transaction extends uvm_sequence_item();

   bit [] rand_bit_list;


   function int my_randomize(int seed);
   ....
   endfunction: my_randomize()

endclass: base_transaction

有几个类扩展了 base_transaction 类。

是否有任何 systemVrilog/UVM 选项可以从 base_transaction 类的 my_randomize() 函数中遍历所有子成员(扩展类之一)?

【问题讨论】:

  • 我不确定您的确切意思。您是说存在许多 child_class 类的对象,并且您希望通过一次调用 my_randomize 将它们全部随机化?
  • @Matthew Taylor - 是的。
  • 我认为你必须自己实现这个。也许您可以实现一个静态成员,它是类本身的一个队列,然后每次调用new 时将每个引用推送到该队列中。也许你可以有一个静态函数来遍历队列并在每个队列中调用my_randomize 方法?我怀疑可能有一个 设计模式 可以做到这一点。你可能想用 design pattern 标签来问这个问题。 (如果你有勇气的话。你知道 Stack Overflow 是什么样的。你可能会犯一些失礼并被击落。)

标签: system-verilog uvm


【解决方案1】:

我认为 Systemveilog/UVM 中没有任何选项可以满足您的需求。但是我们可以用下面的代码来做类似的事情。

// Add this queue in parent class - base_transaction
static base_transaction child_list[$];

// Add this function in parent class - base_transaction
function register_child (base_transaction child);
  base_transaction::child_list.push_back (child);
endfunction

// Your extended class
class new_transaction extends base_transaction;
  function new ();
    super.register_child (this);
  endfunction

  // Other stuff related to your new class
endclass

所以现在您可以使用base_transaction::child_list queue 访问您的所有子成员。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2015-07-12
    • 2013-10-11
    • 1970-01-01
    相关资源
    最近更新 更多