Verification in the trenches: Traversing object hierarchies using VMM1.2
Posted by Shankar Hemmady on November 25th, 2009
Dr. Ambar Sarkar, Chief Verification Technologist, Paradigm Works Inc.
Ever get stuck trying to configure an object deep inside a verification environment? More likely than not, someone else created the environment, changed it drastically over time, and did not leave a description of the object hierarchy. It is quite time-consuming to unravel the whole hierarchical path from the root to that object. The phrase “needle in a haystack” comes to mind.
I will share some tips on how the vmm_object class, recently added to VMM1.2, can help.
As you are most likely aware, a typical verification environment today contains hundreds of classes defined by the user. Many of these are related to each other in parent/child relationships, creating several hierarchies.
As you are most likely aware, a typical verification environment today contains hundreds of classes defined by the user. Many of these are related to each other in parent/child relationships, creating several hierarchies.
So how does the vmm_object class help in traversing these hierarchies? In a nutshell, it is the base class for all classes defined in the VMM library. This means that for every object derived from a class in the VMM library, you can use the same API for:
- Finding its type
- Finding its ancestors and children
- Avoiding name clashes ( a new feature called namespace and we will save this topic for another post)
- Displaying the hierarchy
- Iterate over the objects
- Find object by a regular expression search
The last two bullets above are what I feel help me most, because:
a. I do not have to write separate code for traversing the hierarchy of different types of objects.
b. I can locate an object easily without having to remember or figure out the exact path to it.
Here is an example. I wanted to access all the atomic generators in my environment and they were all named with the suffix GEN.
There are at least two ways to accomplish this:
1. Use the `foreach_vmm_object macro:
// Configuration phasefor test
virtual function void configure_ph();
string pattern = “@%*GEN”; // regular expression used to search for generator name
// Just iterate over all `VMM_ATOMIC_GEN objects that end with “GEN”
`foreach_vmm_object(`VMM_ATOMIC_GEN, pattern, env)
begin
// Do something with this generator
`vmm_note(log, $psprintf(“Found %s\n”, obj.get_object_name()));
end
When applicable, this approach seems like a quite concise way to get things done. Do note that the implementation of `foreach_vmm_object macro requires it to be the first statement following the declarations in a method or following a begin keyword due to the way it is implemented.
Of course, you can avoid the macro if you are so inclined as shown below. Sometimes I do this to get better visibility while debugging.
2. Use iteration class vmm_object_iter provided with this release:
|
Pretty much similar to what I expected as a use model for an iterator class.
Of course, your mileage/opinion may differ from mine. Please share how you plan on using the common vmm_object base class in your daily verification tasks.
This article is the 2nd in the Verification in the trenches series. Hope you found this article useful. If you would like to hear about any other related topic, please comment or drop me a line at ambar.sarkar@paradigm-works.com. Also, if you are starting out fresh, please check out the free VMM1.2 environment generator at http://resourceworks.paradigm-works.com/svftg/vmm .