Do_copy method use?

hi,

do_copy will preforms deep_copy method. but I’m not getting how it is working in UVM.

In reply to Gangaraju M:

You do never explicitly call the do_copy method. It is called by the copy method of an object, like the uvm_seq_item

hello,
i want to know how exactly a do_copy method works? what is the need of $cast(rhs_, rhs)?
and also why to call the super.do_copy(rhs)??

function void write_xtn::do_copy (uvm_object rhs);

// handle for overriding the variable
write_xtn rhs_;
if(!$cast(rhs_,rhs)) begin
`uvm_fatal("do_copy","cast of the rhs object failed")
end
super.do_copy(rhs);

data= rhs_.data;
address= rhs_.address;
write= rhs_.write;
xtn_type= rhs_.xtn_type;
xtn_delay= rhs_.xtn_delay;

endfunction:do_copy

In reply to Gangaraju M:

You do the $cast because rhs is of type uvm_object and rhs_ is of type write_xtn.
You can call super.do_copy, but don’t have to do this. super.do_copy is in your case the do_copy of the base class.

In reply to chr_sue:

Hi chr_sue , what is the use of doing $cast(rhs_,rhs);??

thanks,

In reply to shireeshkumar:

This code fragment shows the important things:

function void write_xtn::do_copy (uvm_object rhs);
  write_xtn rhs_;
  if(!$cast(rhs_,rhs)) begin

the variable rhs is of type uvm_object and the variable rhs_ is of type write_xtn which is an extension of uvm_seq_item. And uvm_seq_item is an extension of uvm_object.
Because rhs_ and rhs have different types, but belonging to the same family we cannot make a direct assigment. But we can perform a type cast using $cast.

Hi chr_sue,

I have a basic question. Why is user not supposed to call do_copy() method directly and what is the need for having an extra layer of copy() function?

Thanks in advance.

In reply to MSB:
You should aks one of the architects of the UVM library. That’s not me.
But having a function wrapper copy(), allows to cal inside different do_copy functions, like the automatic genearted function when using the field macros and using also your individual function you have personally defined.

In a typical UVM hierarchical TB consisting of test, env, agents and sequence_items, typically where do we create the do_copy functions and where do we call the copy() function across the hierarchy?

In reply to sri205:

It’s rare to call copy() directly. Never on class derived from uvm_component.

Normally you call clone() which combines construction and copy.
https://verificationacademy.com/forums/ovm/importance-clone-method

Hi,

Using super.do_copy is needed if you have an extended class definition with some additional properties. So, in the do_copy definition of extended class, you can simply call super.do_copy to make sure that copying of base class properties is done and after this, you can write additional logic by which copying of the additional properties of the extended class can be done.

Hope this helps.
Putta Satish.

In reply to puttasatish:

do_copy() is a method defined inside the copy() method. So , can we override a nested method directly in the child class?