share codepath for scratchpad argument handling with command arguments
authorN. Engelhardt <nak@symbioticeda.com>
Fri, 3 Jan 2020 13:11:41 +0000 (14:11 +0100)
committerN. Engelhardt <nak@symbioticeda.com>
Fri, 3 Jan 2020 13:11:41 +0000 (14:11 +0100)
passes/techmap/abc9.cc

index dd73d53a9cbc0c109ef039300551b1bf160490cd..913b299d2265db5f51992d13d0671f50ae532773 100644 (file)
@@ -332,10 +332,6 @@ void abc9_module(RTLIL::Design *design, RTLIL::Module *current_module, std::stri
                                        abc9_script += script_file[i];
                } else
                        abc9_script += stringf("source %s", script_file.c_str());
-       } else if (design->scratchpad.count("abc9.script")) {
-               abc9_script += design->scratchpad_get_string("abc9.script");
-       } else if (design->scratchpad.count("abc9.scriptfile")) {
-               abc9_script += stringf("source %s", design->scratchpad_get_string("abc9.scriptfile").c_str());
        } else if (!lut_costs.empty() || !lut_file.empty()) {
                //bool all_luts_cost_same = true;
                //for (int this_cost : lut_costs)
@@ -956,6 +952,42 @@ struct Abc9Pass : public Pass {
 #endif
 #endif
 
+               // get arguments from scratchpad first, then override by command arguments
+               std::string lut_arg, luts_arg;
+               if (design->scratchpad.count("abc9.script")) {
+                       script_file = design->scratchpad_get_string("abc9.script");
+               }
+               if (design->scratchpad.count("abc9.D")) {
+                       delay_target = "-D " + design->scratchpad_get_string("abc9.D");
+               }
+               if (design->scratchpad.count("abc9.lut")) {
+                       lut_arg = design->scratchpad_get_string("abc9.lut");
+               }
+               if (design->scratchpad.count("abc9.luts")) {
+                       luts_arg = design->scratchpad_get_string("abc9.luts");
+               }
+               if (design->scratchpad.count("abc9.fast")) {
+                       fast_mode = design->scratchpad_get_bool("abc9.fast", false /* default value if not bool-like */);
+               }
+               if (design->scratchpad.count("abc9.nocleanup")) {
+                       cleanup = !design->scratchpad_get_bool("abc9.nocleanup", false /* default value if not bool-like */);
+               }
+               if (design->scratchpad.count("abc9.showtmp")) {
+                       show_tempdir = design->scratchpad_get_bool("abc9.showtmp", false /* default value if not bool-like */);
+               }
+               if (design->scratchpad.count("abc9.markgroups")) {
+                       markgroups = design->scratchpad_get_bool("abc9.markgroups", false /* default value if not bool-like */);
+               }
+               if (design->scratchpad.count("abc9.box")) {
+                       box_file = design->scratchpad_get_string("abc9.box");
+               }
+               if (design->scratchpad.count("abc9.W")) {
+                       wire_delay = "-W " + design->scratchpad_get_string("abc9.W");
+               }
+               if (design->scratchpad.count("abc9.nomfs")) {
+                       nomfs = design->scratchpad_get_bool("abc9.nomfs", false /* default value if not bool-like */);
+               }
+
                size_t argidx;
                char pwd [PATH_MAX];
                if (!getcwd(pwd, sizeof(pwd))) {
@@ -984,45 +1016,11 @@ struct Abc9Pass : public Pass {
                        //      continue;
                        //}
                        if (arg == "-lut" && argidx+1 < args.size()) {
-                               string arg = args[++argidx];
-                               if (arg.find_first_not_of("0123456789:") == std::string::npos) {
-                                       size_t pos = arg.find_first_of(':');
-                                       int lut_mode = 0, lut_mode2 = 0;
-                                       if (pos != string::npos) {
-                                               lut_mode = atoi(arg.substr(0, pos).c_str());
-                                               lut_mode2 = atoi(arg.substr(pos+1).c_str());
-                                       } else {
-                                               lut_mode = atoi(arg.c_str());
-                                               lut_mode2 = lut_mode;
-                                       }
-                                       lut_costs.clear();
-                                       for (int i = 0; i < lut_mode; i++)
-                                               lut_costs.push_back(1);
-                                       for (int i = lut_mode; i < lut_mode2; i++)
-                                               lut_costs.push_back(2 << (i - lut_mode));
-                               }
-                               else {
-                                       lut_file = arg;
-                                       rewrite_filename(lut_file);
-                                       if (!lut_file.empty() && !is_absolute_path(lut_file) && lut_file[0] != '+')
-                                               lut_file = std::string(pwd) + "/" + lut_file;
-                               }
+                               lut_arg = args[++argidx];
                                continue;
                        }
                        if (arg == "-luts" && argidx+1 < args.size()) {
-                               lut_costs.clear();
-                               for (auto &tok : split_tokens(args[++argidx], ",")) {
-                                       auto parts = split_tokens(tok, ":");
-                                       if (GetSize(parts) == 0 && !lut_costs.empty())
-                                               lut_costs.push_back(lut_costs.back());
-                                       else if (GetSize(parts) == 1)
-                                               lut_costs.push_back(atoi(parts.at(0).c_str()));
-                                       else if (GetSize(parts) == 2)
-                                               while (GetSize(lut_costs) < atoi(parts.at(0).c_str()))
-                                                       lut_costs.push_back(atoi(parts.at(1).c_str()));
-                                       else
-                                               log_cmd_error("Invalid -luts syntax.\n");
-                               }
+                               luts_arg = args[++argidx];
                                continue;
                        }
                        if (arg == "-fast") {
@@ -1070,6 +1068,52 @@ struct Abc9Pass : public Pass {
                }
                extra_args(args, argidx, design);
 
+               rewrite_filename(script_file);
+               if (!script_file.empty() && !is_absolute_path(script_file) && script_file[0] != '+')
+                       script_file = std::string(pwd) + "/" + script_file;
+
+               // handle -lut / -luts args
+               if (!lut_arg.empty()) {
+                       string arg = lut_arg;
+                       if (arg.find_first_not_of("0123456789:") == std::string::npos) {
+                               size_t pos = arg.find_first_of(':');
+                               int lut_mode = 0, lut_mode2 = 0;
+                               if (pos != string::npos) {
+                                       lut_mode = atoi(arg.substr(0, pos).c_str());
+                                       lut_mode2 = atoi(arg.substr(pos+1).c_str());
+                               } else {
+                                       lut_mode = atoi(arg.c_str());
+                                       lut_mode2 = lut_mode;
+                               }
+                               lut_costs.clear();
+                               for (int i = 0; i < lut_mode; i++)
+                                       lut_costs.push_back(1);
+                               for (int i = lut_mode; i < lut_mode2; i++)
+                                       lut_costs.push_back(2 << (i - lut_mode));
+                       }
+                       else {
+                               lut_file = arg;
+                               rewrite_filename(lut_file);
+                               if (!lut_file.empty() && !is_absolute_path(lut_file) && lut_file[0] != '+')
+                                       lut_file = std::string(pwd) + "/" + lut_file;
+                       }
+               }
+               if (!luts_arg.empty()) {
+                       lut_costs.clear();
+                       for (auto &tok : split_tokens(luts_arg, ",")) {
+                               auto parts = split_tokens(tok, ":");
+                               if (GetSize(parts) == 0 && !lut_costs.empty())
+                                       lut_costs.push_back(lut_costs.back());
+                               else if (GetSize(parts) == 1)
+                                       lut_costs.push_back(atoi(parts.at(0).c_str()));
+                               else if (GetSize(parts) == 2)
+                                       while (GetSize(lut_costs) < atoi(parts.at(0).c_str()))
+                                               lut_costs.push_back(atoi(parts.at(1).c_str()));
+                               else
+                                       log_cmd_error("Invalid -luts syntax.\n");
+                       }
+               }
+
                // ABC expects a box file for XAIG
                if (box_file.empty())
                    box_file = "+/dummy.box";