How to get library containing nested module

From Verific Design Automation FAQ
Revision as of 10:52, 19 April 2021 by Hoa (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;
 3 
 4   bot b (t, i1, i2);
 5 
 6   module bot (output o, input i1, i2);
 7     assign o = i1 ^ i2;
 8   endmodule
 9 
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 ;

Sample code how to find nested modules:

    1	#include <iostream>
    2	#include "veri_file.h"
    3	#include "VeriModule.h"
    4	#include "VeriId.h"
    5
    6	#ifdef VERIFIC_NAMESPACE
    7	using namespace Verific ;
    8	#endif
    9
   10	int main(int argc, char **argv)
   11	{
   12	    if (!veri_file::Analyze("test.v", veri_file::SYSTEM_VERILOG_2012)) return 1 ;
   13	    VeriModule *mod = veri_file::GetModule("top") ;
   14	    if (!mod) return 2 ;
   15	    Array *moduleitems = mod->GetModuleItems() ;
   16	    unsigned i ;
   17	    VeriModuleItem *item ;
   18	    FOREACH_ARRAY_ITEM(moduleitems, i, item) {
   19	        if (item->IsModule()) {
   20	            VeriModule *nestedmodule = static_cast<VeriModule *>(item) ;
   21	            std::cout << ">> Found nested module: " << nestedmodule->Name() << "\n" ;
   22	        }
   23	    }
   24	    return 0 ;
   25	}

Run:

   $ test-linux
   -- Analyzing Verilog file 'test.v' (VERI-1482)
   >> Found nested module: bot
   $