In reply to dave_59:
Quote:
In reply to NiLu:
The OVM and UVM mechanisms are the same. The OVM added the virtual do_copy() methods as a hook to the non-virtual copy() methods. This might be to get their field automation macros to work.
In reply to swethasundararaj:
class base;
int p1;
function void copy(base orig);
this.p1 = orig.p1;
endfunction
virtual function base clone(base orig);
base h;
h = new;
h.copy(orig);
return h;
endfunction
endclass
[b]class ex_base;
int p2;
function void copy(base orig);
super.copy(b);
this.p2 = orig.p2;
endfunction
virtual function base clone(base orig);
ex_base h, h_orig
h = new;
$cast(h_orig, orig)
h.copy(h_orig);
return h;
endfunction
endclass[/b]
base b1,b2;
ex_base eb1, eb2;
initial begin
eb1 = new; eb2 = new();
eb2.p2 = 5;
b1 = eb1; b2 = eb2;
b1.copy(b2); // p2 is not copied
eb1.copy(eb2); // p2 is copied
end
Hi dave,
I am trying to copy an extended class object, randomized multiple times having single handle.
It is to be copied to the same type of class object based on certain conditions, thus using cloning method.
I am trying to implement it like this:
class mcs_data_packet extends mcs_inst_packet;
rand logic w1r0;
int mcs_core=0;
int count =0;
function new ();
endfunction:new
function void copy(mcs_data_packet ext);
super.copy(ext);
this.w1r0 = ext.w1r0;
endfunction
virtual function mcs_data_packet clone(mcs_data_packet ext);
mcs_data_packet h;
h=new();
h.copy(ext);
return h;
endfunction
But getting error as below:
virtual function mcs_data_packet clone(mcs_data_packet ext);
|
ncvlog: *E,CVMNMM (mcs_data_packet.svh,23|59): Virtual method 'mcs_data_packet::clone' formal argument name does not match base class 'mcs_inst_packet'.
virtual function mcs_data_packet clone(mcs_data_packet ext);
|
ncvlog: *E,CVMTMM (mcs_data_packet.svh,23|59): Virtual method 'mcs_data_packet::clone' formal argument type does not match base class 'mcs_inst_packet'.
Total errors/warnings found outside modules and primitives:
errors: 2, warnings: 0
But modifying the code:
class mcs_data_packet extends mcs_inst_packet;
rand logic w1r0;
int mcs_core=0;
int count =0;
function new ();
endfunction:new
function void copy(mcs_data_packet ext);
super.copy(ext);
this.w1r0 = ext.w1r0;
endfunction
virtual function mcs_inst_packet clone(mcs_inst_packet ext);
mcs_data_packet h,h_orig;
h=new();
$cast(h_orig,ext);
h.copy(h_orig);
return h;
endfunction
Getting error as while cloning I am passing the extended class type to clone function while it is expecting base class type.
mcs_data_rec[0]=mcs_data.clone(mcs_data);
|
ncvlog: *E,TYCMPAT (tb.sv,1131|30): assignment operator type check failed (expecting datatype compatible with 'class $unit::mcs_data_packet' but found 'class $unit::mcs_inst_packet' instead).
Can you please explain how to clone an extended class.