如何通过 uvm 工厂填充动态数组

How do I populate a dynamic array via uvm factory

你好,假设我有这样的代码,参数 NUM_MASTERS 和 NUM_SLAVES 在配置对象中定义:

class abc extends uvm_scoreboard;
configuration cfg;
wrapper_class master[]; //i am instantiating a dynamic array of class objects, one each for all masters and another for slaves 
wrapper_class slave[];
extern function new(string name = "abc", uvm_component parent = null);
extern function void build_phase(uvm_phase phase);
endclass


function abc::new(string name = "abc", uvm_component parent = null);
super.new(name, parent);
end
function void abc::build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(config_type)::get)this."*","configuration", cfg);
//this is where the error is happening
for(int i = 0; i < cfg.NUM_MASTERS : i++) 
  masters[i] = wrapper_class::type_id::create($sformatf("masters[%0d]",i),this);
for(int i = 0;i < cfg.NUM_SLAVES; i++) 
  slaves[i] =wrapper_class::type_id::create($sformatf("slaves[%0d]",i),this);
endfunction

谁能告诉我如何填充这些动态数组?我必须从构建阶段开始执行它们,因为只有这样我才能从 cfg 对象访问 NUM_MASTERS 和 NUM_SLAVES。 any help/advice 非常感谢。谢谢。

您需要 new 动态数组才能访问它们。

function void abc::build_phase(uvm_phase phase);
  super.build_phase(phase);
  uvm_config_db#(config_type)::get)this."*","configuration", cfg);
  masters = new[cfg.NUM_MASTERS];
  foreach( masters[i] ) 
    masters[i] = wrapper_class::type_id::create($sformatf("masters[%0d]",i),this);
  slaves = new[cfg.NUM_SLAVES];
  foreach( slaves[i] )
    slaves[i] =wrapper_class::type_id::create($sformatf("slaves[%0d]",i),this);
endfunction