Search code examples
arraysdynamicsystem-veriloguvm

How do I populate a dynamic array via uvm factory


Hello lets say I have a code like this, the parameters NUM_MASTERS and NUM_SLAVES are defined in configuration object:

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

Can someone tell me how to populate these dynamic arrays? I have to do them from the build phase because only then can I access the NUM_MASTERS and NUM_SLAVES from the cfg object. any help/advice is very much apprecieated. Thank you.


Solution

  • You need to new dynamic arrays before accessing them.

    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