From f94f544b502c9de88807dec8205417628fe38202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 5 Apr 2023 12:36:56 +0200 Subject: [PATCH 1/2] Fix the python generator for a bunch of const cases Makes the below show up in the binding. .def("c_str", &IdString::c_str) .def("chunks", &SigSpec::chunks) .def("bits", &SigSpec::bits) .def("at", &SigSpec::at) .def("getPort", &Cell::getPort) .def("connections", &Cell::connections) .def("getParam", &Cell::getParam) .def("connections", &Module::connections) def("log_signal", YOSYS_PYTHON::log_signal); def("log_signal", YOSYS_PYTHON::log_signal); def("log_const", YOSYS_PYTHON::log_const); def("log_const", YOSYS_PYTHON::log_const); def("log_id", YOSYS_PYTHON::log_id); --- misc/py_wrap_generator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index 4d9a60113..ecf02e601 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -178,6 +178,8 @@ class WType: t.cont = None t.attr_type = attr_types.default if str_def.find("<") != -1:# and str_def.find("<") < str_def.find(" "): + str_def = str_def.replace("const ", "") + candidate = WContainer.from_string(str_def, containing_file, line_number) if candidate == None: return None @@ -203,8 +205,12 @@ class WType: prefix = "" + if str.startswith(str_def, "const "): + if "char_p" in str_def: + prefix = "const " + str_def = str_def[6:] if str.startswith(str_def, "unsigned "): - prefix = "unsigned " + prefix = "unsigned " + prefix str_def = str_def[9:] while str.startswith(str_def, "long "): prefix= "long " + prefix @@ -1285,7 +1291,7 @@ class WFunction: prefix = "" i = 0 for part in parts: - if part in ["unsigned", "long", "short"]: + if part in ["unsigned", "long", "short", "const"]: prefix += part + " " i += 1 else: From bd063381727a182b5d9f155483d5707fb6ce7e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 5 Apr 2023 13:33:18 +0200 Subject: [PATCH 2/2] py_wrap_generator: Fix handling of method name collisions If two methods have the same signature but for qualifiers the Python binding doesn't care about ('const'), do not generate a mangled name for the method. Fixes .def("wire__YOSYS_NAMESPACE_RTLIL_IdString", &Module::wire__YOSYS_NAMESPACE_RTLIL_IdString) .def("cell__YOSYS_NAMESPACE_RTLIL_IdString", &Module::cell__YOSYS_NAMESPACE_RTLIL_IdString) in the output after the previous change. --- misc/py_wrap_generator.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index ecf02e601..7fe78e03a 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -1367,10 +1367,17 @@ class WFunction: func.args.append(parsed) return func + @property + def mangled_name(self): + mangled_typename = lambda code: code.replace("::", "_").replace("<","_").replace(">","_") \ + .replace(" ","").replace("*","").replace(",","") + + return self.name + "".join( + f"__{mangled_typename(arg.wtype.gen_text_cpp())}" for arg in self.args + ) + def gen_alias(self): - self.alias = self.name - for arg in self.args: - self.alias += "__" + arg.wtype.gen_text_cpp().replace("::", "_").replace("<","_").replace(">","_").replace(" ","").replace("*","").replace(",","") + self.alias = self.mangled_name def gen_decl(self): if self.duplicate: @@ -2196,12 +2203,15 @@ def clean_duplicates(): for fun in class_.found_funs: if fun.gen_decl_hash_py() in known_decls: debug("Multiple declarations of " + fun.gen_decl_hash_py(),3) + other = known_decls[fun.gen_decl_hash_py()] - other.gen_alias() - fun.gen_alias() - if fun.gen_decl_hash_py() == other.gen_decl_hash_py(): + if fun.mangled_name == other.mangled_name: fun.duplicate = True debug("Disabled \"" + fun.gen_decl_hash_py() + "\"", 3) + continue + + other.gen_alias() + fun.gen_alias() else: known_decls[fun.gen_decl_hash_py()] = fun known_decls = []