I want to make a function that can determine if a given object is an instance of a given type, where both the type and the object are dynamic. I am hoping that uvm_object_wrapper can help me (if only as a proxy to create a type to be able to use virtual functions).
For example, if uvm_object defined something like
// Note: this could be an object util macro
virtual function bit is_an_instance_of_my_type(uvm_object o);
MY_TYPENAME t;
return $cast(t, o);
endfunction
Then I could do something like
function am_i_an_instance_of(uvm_object_wraper sometype);
uvm_object other_obj = some_type.create(“other_pbj”);
return other_obj.is_an_instance_of_my_type(this);
endfunction
As far as I know, this specific functionality is not present, but I am wondering if there is anything similar. Unfortunately, I would like my solution to generalize to third-party uvm_object subtypes, so I can’t just extend the macros myself or generate such a function.
I recently learned about uvm_callbacks, which seems to handle using subtypes as the type parameter, and somehow searches through the supertypes/subtypes as needed for a matching callback when requested to get or delete callbacks for example. The code for that has been hard for me to parse or figure out if I could apply it here.
For now, I have worked around this by creating a helper class with a type parameter and using $cast()
there, but I am hoping I can work this into the base class I’m using.