vmm_class_factory_base

The factory class is the utility class to generate instances of any class through the factory mechanism.

Summary
vmm_class_factory_base
The factory class is the utility class to generate instances of any class through the factory mechanism.
Class Declaration
class vmm_class_factory_base#(
   type classname = vmm_object
)
Methods
create_instance()Creates an instance of the specified class type, for the specified name in the scope, created by the specified parent vmm_object.
override_with_new()Sets the specified class instance as the create-by-construction factory, when creating further instances of that class under the specified instance name.
override_with_copy()Sets the specified class instance as the create-by-copy factory, when creating further instances of that class under the specified instance name.

create_instance()

static function classname create_instance(vmm_object parent,  
string name,  
string fname =  "",
int lineno =  0)

Creates an instance of the specified class type, for the specified name in the scope, created by the specified parent vmm_object.  The new instance is created by calling allocate() or copy() on the corresponding factory instance, specified using the create_by_new() or create_by_copy() method, in this class, or any of its parent (base)* classes.

If you do not specify any factory instance, then it creates an instance of this class.

The newly created instance contains the specified name and the specified vmm_object as parent, if the newly created instance is extended from vmm_object.

The fname and lineno arguments are used to track the file name and the line number where the instance is created using create_instance.

class ahb_trans extends vmm_object;
  `vmm_class_factory(ahb_trans)
endclass

class ahb_gen extends vmm_group;
  ahb_trans tr;

  virtual function void_build_ph();
    tr = ahb_trans::create_instance(this, "Ahb_Tr0",
                                    `__FILE__, `__LINE__);
    ...
  endfunction
endclass

override_with_new()

static function void override_with_new(string name,  
classname factory,  
vmm_log log,  
string fname =  "",
int lineno =  0)

Sets the specified class instance as the create-by-construction factory, when creating further instances of that class under the specified instance name.  You can specify the instance name as a match pattern or regular expression.

Also, you can specify an instance name in a specific namespace by prefixing it with spacename::.  The classname::create_instance() method uses the allocate() method to create a new instance of this class.

You should call this method using the following pattern

master::override_with_new( “@*”, extended_master::this_type(), this.log);

If the specified name matches the hierarchical name of atomic, single-stream, or multi-stream scenario generators of the appropriate type, then the matching factory instances they contain are immediately replaced with newly allocated instances of the specified class.  If this method is called before the build phase, then this replacement is delayed until the completion of that phase.

The log argument is the message interface used by factory to report various messages.  The fname and lineno arguments are used to track the file name and the line number where the instance is created using create_instance.

class my_ahb_trans extends vmm_object;
`vmm_class_factory(my_ahb_trans)
endclass

initial begin
  ahb_trans::override_with_new("@%*", my_ahb_trans::this_type, log);
end

override_with_copy()

static function void override_with_copy(string name,  
classname factory,  
vmm_log log,  
string fname =  "",
int lineno =  0)

Sets the specified class instance as the create-by-copy factory, when creating further instances of that class under the specified instance name.

You can specify the instance name as a match pattern or regular expression.

Also, you can specify an instance name in a specific namespace by prefixing it with spacename::.

The classname::create_instance() method uses the copy() method to create new instance of this class.

If the specified name matches the hierarchical name of atomic, single-stream, or multi-stream scenario generators of the appropriate type, the matching factory instances they contain are immediately replaced with copies of the specified factory instance.  If you call this method before the build phase, this replacement is delayed until the completion of that phase.

The log argument is the message interface used by factory to report various messages.  The fname and lineno arguments are used to track the file name and the line number where the instance is created using create_instance.

class ahb_trans extends vmm_object;
  rand bit [7:0] addr;
  `vmm_class_factory(ahb_trans)
endclass

initial begin
  ahb_trans tr;
  tr = new("gen_trans");
  tr.addr = 5;
  ahb_trans::override_with_copy("@%*", tr, log, `__FILE__, `__LINE__);
end
class vmm_class_factory_base#(type classname = vmm_object)
The factory class is the utility class to generate instances of any class through the factory mechanism.
static function classname create_instance(vmm_object parent,  
string name,  
string fname =  "",
int lineno =  0)
Creates an instance of the specified class type, for the specified name in the scope, created by the specified parent vmm_object.
virtual class vmm_object
The vmm_object class is a virtual class that is used as the common base class for all VMM related classes.
static function void override_with_new(string name,  
classname factory,  
vmm_log log,  
string fname =  "",
int lineno =  0)
Sets the specified class instance as the create-by-construction factory, when creating further instances of that class under the specified instance name.
static function void override_with_copy(string name,  
classname factory,  
vmm_log log,  
string fname =  "",
int lineno =  0)
Sets the specified class instance as the create-by-copy factory, when creating further instances of that class under the specified instance name.