mirror of https://github.com/YosysHQ/yosys.git
Merge pull request #4174 from YosysHQ/claire/overwrite
Add API to overwrite existing pass from plugin
This commit is contained in:
commit
1b73b5beb7
|
@ -108,9 +108,8 @@ Pass::Pass(std::string name, std::string short_help) : pass_name(name), short_he
|
|||
|
||||
void Pass::run_register()
|
||||
{
|
||||
if (pass_register.count(pass_name))
|
||||
if (pass_register.count(pass_name) && !replace_existing_pass())
|
||||
log_error("Unable to register pass '%s', pass already exists!\n", pass_name.c_str());
|
||||
|
||||
pass_register[pass_name] = this;
|
||||
}
|
||||
|
||||
|
@ -447,13 +446,12 @@ Frontend::Frontend(std::string name, std::string short_help) :
|
|||
|
||||
void Frontend::run_register()
|
||||
{
|
||||
if (pass_register.count(pass_name))
|
||||
if (pass_register.count(pass_name) && !replace_existing_pass())
|
||||
log_error("Unable to register pass '%s', pass already exists!\n", pass_name.c_str());
|
||||
pass_register[pass_name] = this;
|
||||
|
||||
if (frontend_register.count(frontend_name))
|
||||
if (frontend_register.count(frontend_name) && !replace_existing_pass())
|
||||
log_error("Unable to register frontend '%s', frontend already exists!\n", frontend_name.c_str());
|
||||
|
||||
frontend_register[frontend_name] = this;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ struct Pass
|
|||
|
||||
virtual void on_register();
|
||||
virtual void on_shutdown();
|
||||
virtual bool replace_existing_pass() const { return false; }
|
||||
};
|
||||
|
||||
struct ScriptPass : Pass
|
||||
|
|
|
@ -1257,6 +1257,7 @@ class WFunction:
|
|||
func.is_static = False
|
||||
func.is_inline = False
|
||||
func.is_virtual = False
|
||||
func.is_const = False
|
||||
func.ret_attr_type = attr_types.default
|
||||
func.is_operator = False
|
||||
func.member_of = None
|
||||
|
@ -1334,6 +1335,11 @@ class WFunction:
|
|||
found = find_closing(str_def, "(", ")")
|
||||
if found == -1:
|
||||
return None
|
||||
|
||||
post_qualifiers = str_def[found + 1:].lstrip().replace("{", " {") + " "
|
||||
if post_qualifiers.startswith("const "):
|
||||
func.is_const = True
|
||||
|
||||
str_def = str_def[0:found]
|
||||
if func.name in blacklist_methods:
|
||||
return None
|
||||
|
@ -1379,6 +1385,12 @@ class WFunction:
|
|||
def gen_alias(self):
|
||||
self.alias = self.mangled_name
|
||||
|
||||
def gen_post_qualifiers(self, derived=False):
|
||||
if self.member_of != None and self.member_of.link_type == link_types.derive and self.is_virtual and derived:
|
||||
# we drop the qualifiers when deriving callbacks to be implemented in Python
|
||||
return ''
|
||||
return ' const' if self.is_const else ''
|
||||
|
||||
def gen_decl(self):
|
||||
if self.duplicate:
|
||||
return ""
|
||||
|
@ -1392,7 +1404,7 @@ class WFunction:
|
|||
text += ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text += ");\n"
|
||||
text += f"){self.gen_post_qualifiers()};\n"
|
||||
return text
|
||||
|
||||
def gen_decl_virtual(self):
|
||||
|
@ -1411,12 +1423,18 @@ class WFunction:
|
|||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text += ")"
|
||||
if len(self.args) == 0:
|
||||
if len(self.args) == 0 and self.ret_type.name == "void":
|
||||
text += "{}"
|
||||
else:
|
||||
text += "\n\t\t{"
|
||||
for arg in self.args:
|
||||
text += "\n\t\t\t(void)" + arg.gen_varname() + ";"
|
||||
if self.ret_type.name == "void":
|
||||
pass
|
||||
elif self.ret_type.name == "bool":
|
||||
text += "\n\t\t\treturn false;"
|
||||
else:
|
||||
raise NotImplementedError(self.ret_type.name)
|
||||
text += "\n\t\t}\n"
|
||||
text += "\n\t\tvirtual "
|
||||
if self.is_static:
|
||||
|
@ -1427,7 +1445,7 @@ class WFunction:
|
|||
text += ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text += ") override;\n"
|
||||
text += f"){self.gen_post_qualifiers()} override;\n"
|
||||
return text
|
||||
|
||||
def gen_decl_hash_py(self):
|
||||
|
@ -1452,7 +1470,7 @@ class WFunction:
|
|||
text += ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text +=")\n\t{"
|
||||
text += f"){self.gen_post_qualifiers()}\n\t{{"
|
||||
for arg in self.args:
|
||||
text += arg.gen_translation()
|
||||
text += "\n\t\t"
|
||||
|
@ -1507,16 +1525,17 @@ class WFunction:
|
|||
text += ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text += ")\n\t{"
|
||||
text += f"){self.gen_post_qualifiers()}\n\t{{"
|
||||
for arg in self.args:
|
||||
text += arg.gen_translation_cpp()
|
||||
text += "\n\t\t"
|
||||
return_stmt = "return " if self.ret_type.name != "void" else ""
|
||||
text += f"\n\t\t{return_stmt}"
|
||||
if self.member_of == None:
|
||||
text += "::" + self.namespace + "::" + self.alias + "("
|
||||
elif self.is_static:
|
||||
text += self.member_of.namespace + "::" + self.member_of.name + "::" + self.name + "("
|
||||
else:
|
||||
text += "py_" + self.alias + "("
|
||||
text += f"const_cast<{self.member_of.name}*>(this)->py_" + self.alias + "("
|
||||
for arg in self.args:
|
||||
text += arg.gen_call_cpp() + ", "
|
||||
if len(self.args) > 0:
|
||||
|
@ -1547,11 +1566,13 @@ class WFunction:
|
|||
call_string = call_string[0:-2]
|
||||
call_string += ");"
|
||||
|
||||
return_stmt = "return " if self.ret_type.name != "void" else ""
|
||||
|
||||
text += ")\n\t\t{"
|
||||
text += "\n\t\t\tif(boost::python::override py_" + self.alias + " = this->get_override(\"py_" + self.alias + "\"))"
|
||||
text += "\n\t\t\t\t" + call_string
|
||||
text += "\n\t\t\tif (boost::python::override py_" + self.alias + " = this->get_override(\"py_" + self.alias + "\"))"
|
||||
text += f"\n\t\t\t\t{return_stmt}" + call_string
|
||||
text += "\n\t\t\telse"
|
||||
text += "\n\t\t\t\t" + self.member_of.name + "::" + call_string
|
||||
text += f"\n\t\t\t\t{return_stmt}" + self.member_of.name + "::" + call_string
|
||||
text += "\n\t\t}"
|
||||
|
||||
text += "\n\n\t\t" + self.ret_type.gen_text() + " default_py_" + self.alias + "("
|
||||
|
@ -1559,8 +1580,8 @@ class WFunction:
|
|||
text += arg.gen_listitem() + ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[:-2]
|
||||
text += ")\n\t\t{"
|
||||
text += "\n\t\t\tthis->" + self.member_of.name + "::" + call_string
|
||||
text += f")\n\t\t{{"
|
||||
text += f"\n\t\t\t{return_stmt}this->" + self.member_of.name + "::" + call_string
|
||||
text += "\n\t\t}"
|
||||
return text
|
||||
|
||||
|
@ -1584,9 +1605,9 @@ class WFunction:
|
|||
for a in self.args:
|
||||
text += a.gen_listitem_hash() + ", "
|
||||
if len(self.args) > 0:
|
||||
text = text[0:-2] + ")>"
|
||||
text = text[0:-2] + f"){self.gen_post_qualifiers(True)}>"
|
||||
else:
|
||||
text += "void)>"
|
||||
text += f"void){self.gen_post_qualifiers(True)}>"
|
||||
|
||||
if self.is_operator:
|
||||
text += "(\"" + wrappable_operators[self.name.replace("operator","")] + "\""
|
||||
|
|
|
@ -103,7 +103,6 @@ void load_plugin(std::string filename, std::vector<std::string> aliases)
|
|||
|
||||
loaded_plugins[orig_filename] = hdl;
|
||||
Pass::init_register();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue