Skip to content

Commit bd25696

Browse files
committed
Add API to overwrite existing pass from plugin
Signed-off-by: Claire Xenia Wolf <[email protected]>
1 parent 3537976 commit bd25696

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

kernel/register.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ Pass::Pass(std::string name, std::string short_help) : pass_name(name), short_he
108108

109109
void Pass::run_register()
110110
{
111-
if (pass_register.count(pass_name))
111+
if (pass_register.count(pass_name) && !overwrite_existing_pass())
112112
log_error("Unable to register pass '%s', pass already exists!\n", pass_name.c_str());
113-
114113
pass_register[pass_name] = this;
115114
}
116115

@@ -447,13 +446,12 @@ Frontend::Frontend(std::string name, std::string short_help) :
447446

448447
void Frontend::run_register()
449448
{
450-
if (pass_register.count(pass_name))
449+
if (pass_register.count(pass_name) && !overwrite_existing_pass())
451450
log_error("Unable to register pass '%s', pass already exists!\n", pass_name.c_str());
452451
pass_register[pass_name] = this;
453452

454-
if (frontend_register.count(frontend_name))
453+
if (frontend_register.count(frontend_name) && !overwrite_existing_pass())
455454
log_error("Unable to register frontend '%s', frontend already exists!\n", frontend_name.c_str());
456-
457455
frontend_register[frontend_name] = this;
458456
}
459457

kernel/register.h

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct Pass
7070

7171
virtual void on_register();
7272
virtual void on_shutdown();
73+
virtual bool overwrite_existing_pass() const { return false; }
7374
};
7475

7576
struct ScriptPass : Pass

passes/cmds/plugin.cc

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
103103

104104
loaded_plugins[orig_filename] = hdl;
105105
Pass::init_register();
106-
107106
}
108107
}
109108

0 commit comments

Comments
 (0)