Process -f file and explore the Netlist Database (C++)

From Verific Design Automation FAQ
Revision as of 17:15, 1 March 2019 by Hoa (Talk | contribs) (Created page with " <nowiki> #include <iostream> #include <fstream> #include "veri_file.h" #include "VeriModule.h" #include "VeriId.h" #include "VeriScope.h" #include "Set.h" using namespace...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <iostream>
#include <fstream>

#include "veri_file.h"
#include "VeriModule.h"
#include "VeriId.h"
#include "VeriScope.h"

#include "Set.h"

using namespace std ;

#ifdef VERIFIC_NAMESPACE
using namespace Verific ;
#endif

int main(int argc, const char **argv)
{
    const char *file = (argc > 1) ? argv[1] : "test.v" ;

    // Analyze the files (AnalyzeMultipleFiles API is the recommended one):
    Array files(1) ;
    files.InsertLast(file) ;
    if (!veri_file::AnalyzeMultipleFiles(&files, veri_file::SYSTEM_VERILOG)) return 1 ;

    // Get the module by name:
    VeriModule *test = veri_file::GetModule ("test");
    if (!test) return 2 ;

    // Get the scope of the module:
    VeriScope *scope = test->GetScope() ;

    std::ofstream f("test_out.v", std::ios::out) ;

    // Get the scope that this module/scope is using:
    // This also includes the compilation unit in the list, if any/required:
    Set *using_scopes = (scope) ? scope->GetUsing() : 0 ;

    // Print all those scopes/modules before printing the module itself:
    SetIter si ;
    VeriScope *using_scope ;
    FOREACH_SET_ITEM(using_scopes, si, &using_scope) {
        VeriIdDef *mod_id = using_scope->GetContainingModule() ;
        VeriModule *mod = (mod_id) ? mod_id->GetModule() : 0 ;
        if (!mod) continue ;
        f << "// Printing module " << mod->Name() << endl ;
        mod->PrettyPrint(f, 0) ;
    }

    // Now  print the module:
    f << "// Printing module " << test->Name() << endl ;
    test->PrettyPrint(f, 0) ;
    f.close() ;

    return 0 ;
}