Search code examples
uvm

classes inherited in UVM


I am trying to learn UVM, and I just wanted to know that does this diagram below represent inheritence eg does uvm_object get inherited from uvm_void? I am reading the UVM 1.1 Class reference. It mentions on page 17 that

The uvm_void class is the base class for all UVM classes. It is an abstract class with no data members or functions. It allows for generic containers of objects to be created, similar to a void pointer in the C programming language. User classes derived directly from uvm_void inherit none of the UVM functionality, but such classes may be placed in uvm_void-typed containers along with other UVM objects.

If uvm_object is derived from uvm_void, then how does it have UVM functionality since classes derived from uvm_void shouldn't have any UVM functionality, but uvm_object has methods like clone, print, pack, unpack, record, compare etc.

When we write class uvm_* extends uvm_* eg. class uvm_component extends uvm_object, does it infer inheritence? Somewhere it also mentions the word subtype. Is subtype same as derived class?

enter image description here


Solution

  • A 'derived class' is a form of 'subtype'. Subtypes vs Derived Types in C++

    If uvm_object is derived from uvm_void, then how does it have UVM functionality since classes derived from uvm_void shouldn't have any UVM functionality, but uvm_object has methods like clone, print, pack, unpack, record, compare etc.

    This notion is incorrect, a derived class can implement new functionality. The restriction, objects cannot be created from abstract classes. A parent class handle can point to any object so long as it is a subtype. A handle can only access the methods and members of its own type, plus virtual methods that been override. Therefore if a handle is pointing to a subtype object, it cannot access the methods or members that were added by that subtype.

    uvm_void is an empty abstract class. If you look into the UVM source code you will see it defiled as two lines:

    virtual class uvm_void;
    endclass
    

    The purpose of uvm_void is to have a common parent type, so later on a generic container can be created that can hold any UVM related object. Such a container can even hold user-defined classes that inherit from uvm_void without relations to uvm_object (in practice this should not be done).

    uvm_object implements the fundamental functionality used by UVM. The vast majority UVM classes inherit from uvm_object or one of its subtypes.