verific_import() changes to avoid ElaborateAll()
authorEddie Hung <eddie@fpgeh.com>
Wed, 13 Mar 2019 00:02:04 +0000 (00:02 +0000)
committerClifford Wolf <clifford@clifford.at>
Fri, 3 May 2019 18:53:25 +0000 (20:53 +0200)
frontends/verific/verific.cc

index ed9727b88e2bd4625caca6859d708ff461e8507e..b191c910d315738c9c04d70ca17ca4610ba8b69e 100644 (file)
@@ -46,6 +46,7 @@ USING_YOSYS_NAMESPACE
 #include "VeriModule.h"
 #include "VeriWrite.h"
 #include "VhdlUnits.h"
+#include "HierTreeNode.h"
 #include "Message.h"
 
 #ifdef __clang__
@@ -1758,26 +1759,48 @@ void verific_import(Design *design, std::string top)
 
        std::set<Netlist*> nl_todo, nl_done;
 
-       {
-               VhdlLibrary *vhdl_lib = vhdl_file::GetLibrary("work", 1);
-               VeriLibrary *veri_lib = veri_file::GetLibrary("work", 1);
-
-               Array veri_libs, vhdl_libs;
-               if (vhdl_lib) vhdl_libs.InsertLast(vhdl_lib);
-               if (veri_lib) veri_libs.InsertLast(veri_lib);
-
-               Array *netlists = hier_tree::ElaborateAll(&veri_libs, &vhdl_libs);
-               Netlist *nl;
-               int i;
+       VhdlLibrary *vhdl_lib = vhdl_file::GetLibrary("work", 1);
+       VeriLibrary *veri_lib = veri_file::GetLibrary("work", 1);
+       Array *netlists = NULL;
+       Array veri_libs, vhdl_libs;
+       if (vhdl_lib) vhdl_libs.InsertLast(vhdl_lib);
+       if (veri_lib) veri_libs.InsertLast(veri_lib);
+
+       if (top.empty()) {
+               netlists = hier_tree::ElaborateAll(&veri_libs, &vhdl_libs);
+       }
+       else {
+               const Map *tree_tops = hier_tree::CreateHierarchicalTreeAll(&veri_libs, &vhdl_libs);
+               HierTreeNode *node = tree_tops ? static_cast<HierTreeNode*>(tree_tops->GetValue(top.c_str())) : NULL;
+               if (node) {
+                       Map specific_tops(STRING_HASH);
+                       specific_tops.Insert(top.c_str(), node);
+
+                       if (node->HasBindChild()) {
+                               MapIter mi;
+                               const char *key;
+                               FOREACH_MAP_ITEM(tree_tops, mi, &key, &node) {
+                                       if (!node->IsPackage()) continue;
+                                       specific_tops.Insert(key, node);
+                               }
+                       }
 
-               FOREACH_ARRAY_ITEM(netlists, i, nl) {
-                       if (top.empty() || nl->Owner()->Name() == top)
-                               nl_todo.insert(nl);
+                       netlists = hier_tree::GenerateNetlists(&specific_tops);
                }
+               hier_tree::DeleteHierarchicalTree();
+               veri_file::DeleteInstantiatedClassValues();
+       }
 
-               delete netlists;
+       Netlist *nl;
+       int i;
+
+       FOREACH_ARRAY_ITEM(netlists, i, nl) {
+               if (top.empty() || nl->Owner()->Name() == top)
+                       nl_todo.insert(nl);
        }
 
+       delete netlists;
+
        if (!verific_error_msg.empty())
                log_error("%s\n", verific_error_msg.c_str());