Replace -ignore_redef with -[no]overwrite
authorClifford Wolf <clifford@clifford.at>
Thu, 3 May 2018 13:25:59 +0000 (15:25 +0200)
committerClifford Wolf <clifford@clifford.at>
Thu, 3 May 2018 13:25:59 +0000 (15:25 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
frontends/ast/ast.cc
frontends/ast/ast.h
frontends/liberty/liberty.cc
frontends/verilog/verilog_frontend.cc
passes/techmap/techmap.cc

index 037a9f3eec6ed17c1a60c5346e20163ded43b345..999202b474eab2fb6164265940da980dab0ac51b 100644 (file)
@@ -1003,7 +1003,7 @@ static AstModule* process_module(AstNode *ast, bool defer)
 
 // create AstModule instances for all modules in the AST tree and add them to 'design'
 void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump_ast2, bool dump_vlog, bool dump_rtlil,
-               bool nolatches, bool nomeminit, bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool ignore_redef, bool defer, bool autowire)
+               bool nolatches, bool nomeminit, bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool nooverwrite, bool overwrite, bool defer, bool autowire)
 {
        current_ast = ast;
        flag_dump_ast1 = dump_ast1;
@@ -1042,12 +1042,20 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump
                                (*it)->str = "$abstract" + (*it)->str;
 
                        if (design->has((*it)->str)) {
-                               if (!ignore_redef)
+                               RTLIL::Module *existing_mod = design->module((*it)->str);
+                               if (!nooverwrite && !overwrite && !existing_mod->get_bool_attribute("\\blackbox")) {
                                        log_error("Re-definition of module `%s' at %s:%d!\n",
                                                        (*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
-                               log("Ignoring re-definition of module `%s' at %s:%d!\n",
-                                               (*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
-                               continue;
+                               } else if (nooverwrite) {
+                                       log("Ignoring re-definition of module `%s' at %s:%d.\n",
+                                                       (*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
+                                       continue;
+                               } else {
+                                       log("Replacing existing%s module `%s' at %s:%d.\n",
+                                                       existing_mod->get_bool_attribute("\\blackbox") ? " blackbox" : "",
+                                                       (*it)->str.c_str(), (*it)->filename.c_str(), (*it)->linenum);
+                                       design->remove(existing_mod);
+                               }
                        }
 
                        design->add(process_module(*it, defer));
index d1e2c78d1f306a60102a89b329dce577ef80985d..756629aca1efdd9946820f4fd8ff1e59ef6d6ec1 100644 (file)
@@ -275,7 +275,7 @@ namespace AST
 
        // process an AST tree (ast must point to an AST_DESIGN node) and generate RTLIL code
        void process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump_ast2, bool dump_vlog, bool dump_rtlil, bool nolatches, bool nomeminit,
-                       bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool ignore_redef, bool defer, bool autowire);
+                       bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool nooverwrite, bool overwrite, bool defer, bool autowire);
 
        // parametric modules are supported directly by the AST library
        // therefore we need our own derivate of RTLIL::Module with overloaded virtual functions
index af80c292197aab75d66f31513102643b6c6f5f5e..877b1883e3cb93c34c4907107488cf227727f1f5 100644 (file)
@@ -463,9 +463,13 @@ struct LibertyFrontend : public Frontend {
                log("    -lib\n");
                log("        only create empty blackbox modules\n");
                log("\n");
-               log("    -ignore_redef\n");
+               log("    -nooverwrite\n");
                log("        ignore re-definitions of modules. (the default behavior is to\n");
-               log("        create an error message.)\n");
+               log("        create an error message if the existing module is not a blackbox\n");
+               log("        module, and overwrite the existing module if it is  a blackbox module.)\n");
+               log("\n");
+               log("    -overwrite\n");
+               log("        overwrite existing modules with the same name\n");
                log("\n");
                log("    -ignore_miss_func\n");
                log("        ignore cells with missing function specification of outputs\n");
@@ -484,7 +488,8 @@ struct LibertyFrontend : public Frontend {
        virtual void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
        {
                bool flag_lib = false;
-               bool flag_ignore_redef = false;
+               bool flag_nooverwrite = false;
+               bool flag_overwrite = false;
                bool flag_ignore_miss_func = false;
                bool flag_ignore_miss_dir  = false;
                bool flag_ignore_miss_data_latch = false;
@@ -499,8 +504,14 @@ struct LibertyFrontend : public Frontend {
                                flag_lib = true;
                                continue;
                        }
-                       if (arg == "-ignore_redef") {
-                               flag_ignore_redef = true;
+                       if (arg == "-ignore_redef" || arg == "-nooverwrite") {
+                               flag_nooverwrite = true;
+                               flag_overwrite = false;
+                               continue;
+                       }
+                       if (arg == "-overwrite") {
+                               flag_nooverwrite = false;
+                               flag_overwrite = true;
                                continue;
                        }
                        if (arg == "-ignore_miss_func") {
@@ -537,9 +548,16 @@ struct LibertyFrontend : public Frontend {
                        std::string cell_name = RTLIL::escape_id(cell->args.at(0));
 
                        if (design->has(cell_name)) {
-                               if (flag_ignore_redef)
+                               Module *existing_mod = design->module(cell_name);
+                               if (!flag_nooverwrite && !flag_overwrite && !existing_mod->get_bool_attribute("\\blackbox")) {
+                                       log_error("Re-definition of of cell/module %s!\n", log_id(cell_name));
+                               } else if (flag_nooverwrite) {
+                                       log("Ignoring re-definition of module %s.\n", log_id(cell_name));
                                        continue;
-                               log_error("Duplicate definition of cell/module %s.\n", RTLIL::unescape_id(cell_name).c_str());
+                               } else {
+                                       log("Replacing existing%s module %s.\n", existing_mod->get_bool_attribute("\\blackbox") ? " blackbox" : "", log_id(cell_name));
+                                       design->remove(existing_mod);
+                               }
                        }
 
                        // log("Processing cell type %s.\n", RTLIL::unescape_id(cell_name).c_str());
index e5917b97eb84bf09415d99035f40cab5c32fec39..505c94619eb853fdc85c448d88a6201e0cd88207 100644 (file)
@@ -137,9 +137,13 @@ struct VerilogFrontend : public Frontend {
                log("    -icells\n");
                log("        interpret cell types starting with '$' as internal cell types\n");
                log("\n");
-               log("    -ignore_redef\n");
+               log("    -nooverwrite\n");
                log("        ignore re-definitions of modules. (the default behavior is to\n");
-               log("        create an error message.)\n");
+               log("        create an error message if the existing module is not a black box\n");
+               log("        module, and overwrite the existing module otherwise.)\n");
+               log("\n");
+               log("    -overwrite\n");
+               log("        overwrite existing modules with the same name\n");
                log("\n");
                log("    -defer\n");
                log("        only read the abstract syntax tree and defer actual compilation\n");
@@ -191,7 +195,8 @@ struct VerilogFrontend : public Frontend {
                bool flag_nodpi = false;
                bool flag_noopt = false;
                bool flag_icells = false;
-               bool flag_ignore_redef = false;
+               bool flag_nooverwrite = false;
+               bool flag_overwrite = false;
                bool flag_defer = false;
                std::map<std::string, std::string> defines_map;
                std::list<std::string> include_dirs;
@@ -289,8 +294,14 @@ struct VerilogFrontend : public Frontend {
                                flag_icells = true;
                                continue;
                        }
-                       if (arg == "-ignore_redef") {
-                               flag_ignore_redef = true;
+                       if (arg == "-ignore_redef" || arg == "-nooverwrite") {
+                               flag_nooverwrite = true;
+                               flag_overwrite = false;
+                               continue;
+                       }
+                       if (arg == "-overwrite") {
+                               flag_nooverwrite = false;
+                               flag_overwrite = true;
                                continue;
                        }
                        if (arg == "-defer") {
@@ -370,7 +381,7 @@ struct VerilogFrontend : public Frontend {
                if (flag_nodpi)
                        error_on_dpi_function(current_ast);
 
-               AST::process(design, current_ast, flag_dump_ast1, flag_dump_ast2, flag_dump_vlog, flag_dump_rtlil, flag_nolatches, flag_nomeminit, flag_nomem2reg, flag_mem2reg, lib_mode, flag_noopt, flag_icells, flag_ignore_redef, flag_defer, default_nettype_wire);
+               AST::process(design, current_ast, flag_dump_ast1, flag_dump_ast2, flag_dump_vlog, flag_dump_rtlil, flag_nolatches, flag_nomeminit, flag_nomem2reg, flag_mem2reg, lib_mode, flag_noopt, flag_icells, flag_nooverwrite, flag_overwrite, flag_defer, default_nettype_wire);
 
                if (!flag_nopp)
                        delete lexin;
index 02d0d47e85b561afd6f13c29d2ccff80b8c096d4..1908ae8b58a83379c3539144dc34ded6437b867a 100644 (file)
@@ -933,7 +933,7 @@ struct TechmapPass : public Pass {
                log("    -D <define>, -I <incdir>\n");
                log("        this options are passed as-is to the Verilog frontend for loading the\n");
                log("        map file. Note that the Verilog frontend is also called with the\n");
-               log("        '-ignore_redef' option set.\n");
+               log("        '-nooverwrite' option set.\n");
                log("\n");
                log("When a module in the map file has the 'techmap_celltype' attribute set, it will\n");
                log("match cells with a type that match the text value of this attribute. Otherwise\n");
@@ -1031,7 +1031,7 @@ struct TechmapPass : public Pass {
                simplemap_get_mappers(worker.simplemap_mappers);
 
                std::vector<std::string> map_files;
-               std::string verilog_frontend = "verilog -ignore_redef";
+               std::string verilog_frontend = "verilog -nooverwrite";
                int max_iter = -1;
 
                size_t argidx;