Added call_on_selection() and call_on_module() API
authorClifford Wolf <clifford@clifford.at>
Sun, 20 Jul 2014 13:16:10 +0000 (15:16 +0200)
committerClifford Wolf <clifford@clifford.at>
Sun, 20 Jul 2014 13:33:06 +0000 (15:33 +0200)
kernel/register.cc
kernel/register.h
passes/hierarchy/submod.cc
passes/techmap/techmap.cc

index 8da5a725fe7caae5a2d3851c4346ed5f1f8292a7..84051948fa6270ea91e362ca7b12c37b4fe9c460 100644 (file)
@@ -198,11 +198,11 @@ void Pass::call(RTLIL::Design *design, std::vector<std::string> args)
        design->check();
 }
 
-void Pass::call_newsel(RTLIL::Design *design, std::string command)
+void Pass::call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::string command)
 {
        std::string backup_selected_active_module = design->selected_active_module;
        design->selected_active_module.clear();
-       design->selection_stack.push_back(RTLIL::Selection());
+       design->selection_stack.push_back(selection);
 
        Pass::call(design, command);
 
@@ -210,11 +210,37 @@ void Pass::call_newsel(RTLIL::Design *design, std::string command)
        design->selected_active_module = backup_selected_active_module;
 }
 
-void Pass::call_newsel(RTLIL::Design *design, std::vector<std::string> args)
+void Pass::call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::vector<std::string> args)
 {
        std::string backup_selected_active_module = design->selected_active_module;
        design->selected_active_module.clear();
-       design->selection_stack.push_back(RTLIL::Selection());
+       design->selection_stack.push_back(selection);
+
+       Pass::call(design, args);
+
+       design->selection_stack.pop_back();
+       design->selected_active_module = backup_selected_active_module;
+}
+
+void Pass::call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command)
+{
+       std::string backup_selected_active_module = design->selected_active_module;
+       design->selected_active_module = module->name;
+       design->selection_stack.push_back(RTLIL::Selection(false));
+       design->selection_stack.back().select(module);
+
+       Pass::call(design, command);
+
+       design->selection_stack.pop_back();
+       design->selected_active_module = backup_selected_active_module;
+}
+
+void Pass::call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::vector<std::string> args)
+{
+       std::string backup_selected_active_module = design->selected_active_module;
+       design->selected_active_module = module->name;
+       design->selection_stack.push_back(RTLIL::Selection(false));
+       design->selection_stack.back().select(module);
 
        Pass::call(design, args);
 
index f3d3f70aec869346f0886a43178a05a1bd14771c..b07c461778d04a61e6cd42e894e9717637d594c7 100644 (file)
@@ -60,8 +60,11 @@ struct Pass
        static void call(RTLIL::Design *design, std::string command);
        static void call(RTLIL::Design *design, std::vector<std::string> args);
 
-       static void call_newsel(RTLIL::Design *design, std::string command);
-       static void call_newsel(RTLIL::Design *design, std::vector<std::string> args);
+       static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::string command);
+       static void call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::vector<std::string> args);
+
+       static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command);
+       static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::vector<std::string> args);
 
        static void init_register();
        static void done_register();
index 7d081125482cc946f23a6750ff0d8630dcfcfe08..55f5f04853effc8607cb3c8e5a8c391473e92ac9 100644 (file)
@@ -338,7 +338,7 @@ struct SubmodPass : public Pass {
                        if (module == NULL)
                                log("Nothing selected -> do nothing.\n");
                        else {
-                               Pass::call_newsel(design, stringf("opt_clean %s", module->name.c_str()));
+                               Pass::call_on_module(design, module, "opt_clean");
                                log_header("Continuing SUBMOD pass.\n");
                                SubmodWorker worker(design, module, opt_name);
                        }
index cb36c9e1f2ab5dc84ffd138ba6d2e3d06d83843c..3ceff279bebd4eb6dd72e1ac2846863b96708754 100644 (file)
@@ -393,15 +393,7 @@ struct TechmapWorker
                                                        tpl->add(data.wire);
 
                                                        std::string cmd_string = data.value.as_const().decode_string();
-
-                                                       RTLIL::Selection tpl_mod_sel(false);
-                                                       std::string backup_active_module = map->selected_active_module;
-                                                       map->selected_active_module = tpl->name;
-                                                       tpl_mod_sel.select(tpl);
-                                                       map->selection_stack.push_back(tpl_mod_sel);
-                                                       Pass::call(map, cmd_string);
-                                                       map->selection_stack.pop_back();
-                                                       map->selected_active_module = backup_active_module;
+                                                       Pass::call_on_module(map, tpl, cmd_string);
 
                                                        keep_running = true;
                                                        break;