Uvm_object data type

Hi,

I have a confusion. What is the purpose of using uvm_object data type. For example, I have seen in code like
uvm_object tmp_object;

and then we cast it into our required variable, by doing

assert($cast(m_seq_a[0][0], tmp_object));

Why can’t we directly create handle and the using “function new” create object? I didn’t understand the part of creating tmp_object of type uvm_object and later casting it to required handle.

Any help on this please?

Regards,

In reply to pankajpattel:

You cannot call new() except as the RHS of a procedural assignment; the BNF syntax does not allow it. You could use the UVM’s create method directly instead of using a temporary variable.

assert($cast(m_seq_a[0][0], my_obj::type_id::create());

In reply to dave_59:

Hi Dave,

Thank you for the reply.

But still,the solution mentioned by you is using $cast and uvm_object. We can do like below right?

abc_seq m_seq_c;

m_seq_c=abc_seq::type_id::create(m_seq, this);

Or is there any specific purpose of using uvm_object data type and then casting?

Regards,

In reply to pankajpattel:

Some functions are returning the type uvm_object. Then you have to do the Type casting using $cast. An example is

virtual function bit do_compare (uvm_object rhs, uvm_comparer comparer);

If abc_seq is of base class type uvm_object the construction using the factory create is like this:

abc_seq m_seq_c;
m_seq_c = abc_seq::type_id::create("m_seq");

Hi, i think if i understand your intention correctly then i can say,
uvm_object is at very fundamental level a common base type class where we can utilise the casting concept when we aren’t sure about the original data type of class.

In reply to tez:

The type casting using $cast is not limited to uvm_objects. You can use it also for uvm_components.
Type casting is used when functions are returning the type of the uvm base classess, like uvm_object or uvm_component.
A typical example is when you are searching for components in your envrionment using the function find.
The definition

function uvm_component find (string comp_match);

returns a component of type uvm_component and you can cast this to your real component.