How to get library containing nested module

From Verific Design Automation FAQ
Jump to: navigation, search

Q: How do I get the library that contains the module nested inside another module?

Take the following example:

 1 module top (output o, input i1, i2, i3);
 2   logic t;
 4   bot b (t, i1, i2);
 6   module bot (output o, input i1, i2);
 7     assign o = i1 ^ i2;
 8   endmodule
10   assign o = t && i3;
11 endmodule

Calling GetLibrary() on module "bot" returns NULL because a module nested inside another one is not attached to any library. To get the module ("top") containing the nested module ("bot"):

// Get the scope of nested module
VeriScope *nested_module_scope = nested_module_ptr->GetScope();
// Get the containing module
VeriScope *upper_scope = nested_module_scope ? nested_module_scope->Upper(): 0 ;
VerIdDef *containing_module_id = upper_scope ? upper_scope->GetContainingModule(): 0 ;