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:
- 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.
- 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,