Questa fails this at runtime, calling it an illegal comparison. I wish I could use the type operator, but I also need to support VCS, and VCS does not support the type operator.
Also, T1 and T2 could be parameterized classes, specifically parameterized UVM components. Don’t know if that matters.
It’s illegal because get_type() returns a handle to a proxy object of type uvm_component_registry#(T1,“T1”) and uvm_component_registry#(T2,“T2”). You can’t compare handles of different types.
What you really want is
if (type(T1) != type(T2) ) <do something>.
Are you sure VCS does not support this? This has been in the LRM since 1800-2005
If you want to compare the types of two constructed UVM objects, you can use the virtual method get_object_type()
if ( t1_h.get_object_type() != t2_h.get_object_type() ) <do_something>;
Yes, that is what I really wanted, to use the type operator. VCS does not support it as recent as their 2014.12 release. I know it’s been in the standard for a long time, and that’s why it’s very annoying.
The conditional is used to determine if something of a certain type should be constructed in the build phase, so I can’t really use an instance-based method such as get_object_type().
I believe this will work. Please include a comment that explains the proper way to code this
uvm_object_wrapper wrapt1,wrapt2;
// because VCS does not support the constant expression: ( type(T1) != type(T2) )
wrapt1 = T1::type_id::get();
wrapt2 = T2::type_id::get();
if (wrapt1 != wrapt2) <do_something>;