PDA

View Full Version : query in example



ankit1
01-23-2008, 01:21 AM
Hi All,

can anybody tell me in below program why it is required to create object of ovm_object?
why it is assigned with packet object ? and what is use of $cast in below program?

location of this function given below:
ovm/ovm-1.0/examples/factory/gen_pkg.sv

--------------------------------------------------------------------------------------------------
virtual function packet get_packet();
packet p;
ovm_object obj;

//use the factory to generate a package
obj = create_object("packet", "p");

//make sure it is a packet
$cast(p, obj);

//randomize it
void'(p.randomize());

return p;
endfunction
--------------------------------------------------------------------------------------------------
regards,
Ankit

dlong
01-23-2008, 02:08 AM
Hi Ankit,

The ovm_factory ALWAYS returns an object handle of type ovm_object, regardless of the type of the object actually being created. The packet class in the example is derived from the ovm_object class - SystemVerilog (like other object-oriented languages) allows a handle (or "pointer") to a base class to point to an object of any derived class, which is what is happening with the variable "obj" in the example.

To access the object as a packet, the ovm_object handle must be "cast" to a packet handle ("p"). Member functions of packet can then be called using "p".

If you are not familiar with these concepts, I would suggest taking a look at an object oriented programming textbook, or if you would prefer to stick to SystemVerilog, you might find the introduction to OO Chris Spear's book "SystemVerilog for Verification" easier to understand.

Regards,
Dave