You get real hierarchy with VMM1.2
Posted by Wei-Hua Han on February 9th, 2010
If you look at VMM1.2 classes, you may find that almost all new() functions have an argument, vmm_object parent. The purpose of this argument is to build a parent-child hierarchy within a VMM1.2 based environment, so that VMM1.2 can provide an infrastructure where users can access the components inside the environment through hierarchical path and name. And this parent-child hierarchy also contributes to the implicit phasing implementation.
Here is a small example to illustrate how a hierarchy can be built with VMM1.2:
- class mike_c extends vmm_object;
- function new(vmm_object parent=null, string name="");
- super.new(parent,name);
- endfunction
- endclass
- class ben_c extends vmm_object;
- function new(vmm_object parent=null, string name="");
- super.new(parent,name);
- endfunction
- endclass
- class jason_c extends vmm_object;
- mike_c Mike;
- ben_c Ben;
- int weight;
- function new(vmm_object parent=null, string name="");
- bit is_set;
- super.new(parent,name);
- weight=vmm_opts::get_object_int(is_set,this, "weight",0, "set weight");
- endfunction
- function void build();
- Mike = new(this,"Mike");
- Ben = new(this,"Ben");
- endfunction
- endclass
- program p1;
- jason_c Jason;
- initial begin
- vmm_opts::set_int("Jason:weight",10);
- Jason=new(null,"Jason");
- Jason.build();
- vmm_object::print_hierarchy(Jason);
- $display("Jason has %0d children",Jason.get_num_children());
- $display(Jason.Mike.get_object_name());
- $display(Jason.Ben.get_object_hiername());
- $display(Jason.weight);
- end
-
endprogram
In this small example, line 30 creates an object (Jason) for jason_c and its parent is "null", so Jason is a root component in the hierarchy. When Jason.build() is called in line 31, object Mike and Ben are created and their parent is set to Jason. So in this small system we build the following hierarchy:
[Jason]
|–[Mike]
|–[Ben]
Jason has 2 children
Mike
Jason:Ben
This hierarchy can be printed by vmm_object method print_hierarchy().
Please note that unlike Verilog modules and instances where the hierarchy is defined as per the Verilog LRM, the VMM1.2 parent-child hierarchy is really user defined. It depends on how "parent" argument is specified when the object is created, and not on where the object variable is declared or created.
As for the component name, although you may choose to specify a different name as the variable name, it is a good practice to keep it consistent, which makes the code more readable and avoids confusion.
From the above example, you can find that the hierarchical name for object Jason.Ben is "Jason:Ben". VMM1.2 uses ":" as the hierarchical separator instead of ".". The reason is that this hierarchical name is actually a made-up name, and we want to differentiate it from the semantic hierarchical reference name specified in Verilog/SystemVerilog which uses "." as the separator.
There are many methods provided in VMM1.2 which help users to work with the parent-child hierarchy. Some of these methods are:
- find_child_by_name(): finds the named object relative to this object
- get_num_children(): gets the total number of children for this object
- get_nth_child(): returns the nth child of this object
- get_object_hiername(): gets the complete hierarchical name of this object
- get_parent_object():returns the parent of this object
- get_root_object(): gets the root parent of this object
- get_typename(): returns the name of the actual type of this object
- is_parent_of(): returns true, if the specified object is a parent of this object
- print_hierarchy(): prints the object hierarchy
- Set_parent_object(): sets or replaces the parent of this object
Dr. Ambar Sarkar has explained how users can traverse the hierarchy in his blog post.
This parent-child hierarchical infrastructure is one of the most important mechanisms in VMM1.2. Many other VMM1.2 features rely on this infrastructure:
1. Implicit phasing
Implicit phasing is new in VMM1.2. In implicit phasing, structural components (transactors) are aligned with each other automatically. The phase specific methods are called automatically throughout the whole hierarchy in a top-down (for functions) or forked (for tasks) mode. Thus implicit phasing makes integration of Verification IPs into the simulation environment or other structural components a lot easier. Other VMM1.2 users also benefit from implicit phasing when building complicated verification environments.
2. Factory replacement
Factory is an important feature that enables flexibility and reuse inside a verification environment. Because of the parent-child hierarchy, users can replace components, generated transactions or scenarios with their extension type or other objects by specifying hierarchy path and names. Support for regular expression for specifying hierarchies and names make this utility very powerful.
For example, in the following code segment, we override the type mike_c for Mike with mike_ext :
mike_c::override_with_new("@%Jason:Mike",mike_ext::this_type,log);
3. Hierarchical configuration
In addition to supporting runtime configuration through command-line options or files, using the parent-child hierarchy VMM1.2 also supports configuration of components by specifying their hierarchical path and name. All these configuration utilities are provided through vmm_opts.
For example, in the following code segment, we set the property weight of object Jason to 10 using hierarchical configuration:
vmm_opts::set_int("Jason:weight",10);
Like factory, users can also use regular expression with hierarchical configuration.
If you have watched "Growing Pains", you know that I am not quite accurate when I say
Jason has 2 children
He indeed has three…
Have fun with VMM1.2. J
Posted in Tutorial, VMM 1.2 | No Comments »







