Objective of casting in UVM "do_<methods>" (do_copy, do_compare etc)

Hi,

The following are the standard boiler plate codes of do_copy() and do_compare() methods:

function void do_copy(uvm_object rhs);
trans1 tr;
if(!$cast(tr, rhs)) `uvm_fatal("trans1", "ILLEGAL do_copy() cast")
a = tr.a;
… (copy remaining variables)
endfunction
function bit do_compare(uvm_object rhs, uvm_comparer comparer);
trans1 tr;
bit
eq;
if(!$cast(tr, rhs)) `uvm_fatal("trans1", "ILLEGAL do_compare() cast")
eq = super.do_compare(rhs, comparer);
eq &= (a == tr.a);
… (compare remaining variables)
return(eq);
endfunction

I observed the following points during such function calls:

  1. Whenever the user-defined do_* functions are called, the extended class handle is passed as an argument to the do_* function, such as tr1.do_copy(tr2) or tr1.do_compare(tr2) wherein it is converted into base class “uvm_object” handle “rhs”, as evident from the function definition header above.
  2. Once the conversion is done, the extended class handle is declared once again inside the function and the base handle is casted back to extended class handle.

I am not clear as to what purpose is served by this repetitive casting. Wouldn’t it be simpler to just call the do_* methods with the extended class handle and implement the copy/compare functionality without any casting?

Also, is overriding the do_* function a recommended approach for implementing the transaction-specific methods or can we just make do with using the functionality provided with the field automation macros?

Any feedback in this regard would be highly appreciated.

Thanks and Regards,

Hi Kautilya,

As the handle received in the do_copy method is uvm_object type it should be casted back to original transaction type to use the transaction variables, since uvm_object will not have the visibility of original transaction variables.

Regards
Kranthi

I think overriding the do_functions is recommended way as i have more control over my function. for example in AXI depends on my transaction type i can print the required variables. if i dont use the default do_print method i will get prints of all variables which may be unnecessary sometimes.