I am converting system verilog class based testbench to UVM. I had to replace it’s constructor with UVM constructor and had to replace all new with create. I was deciding the array length dynamically when i create them by passing parameter with new. Ex : class_name object=new() and it’s is not possible now since UVM constructor does not support the my format. So I wrote a new function which I call after I instantiate the object in UVM using create method which does job for me but dynamic array length works well with new method but I could not find workaround to make it work with UVM.
Earlier code:
class child extends parent_class;
protected parent_class array [];
function new (int number_inst = 1);
begin
super.new(1);
// Create the arrays of pointers to the array
array = new[number_inst];
end
endfunction
endclass
Current code:
class child extends parent_class;
`uvm_component_utils(child)
function new(string name = "child", uvm_component parent = null);
super.new(name, parent);
endfunction
protected parent_class array [];
function initialize_setup (int number_inst = 1);
begin
super.initialize_setup(1);
for(int i=0;i< number_inst;i++)
begin
array[i] = parent_class::type_id::create($sformatf("array%0d",i), this);
array[i].initialize_setup(1);
end
end
endfunction
endclass
The current gives me following error:
Error-[NOA] Null object access at array[i].initialize_setup(1);
The object is being used before it was constructed/allocated.
Please make sure that the object is allocated before using it.
Problem gets solved when I hardcode the value array instance Ex: protected parent_class array [20];
What could be solution for this type of problem ?
Thanks,
Varun