mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
Merge pull request #3723 from povik/pygen-const
Fix the python generator for a bunch of const cases
This commit is contained in:
commit
bac4c55ed6
|
@ -178,6 +178,8 @@ class WType:
|
||||||
t.cont = None
|
t.cont = None
|
||||||
t.attr_type = attr_types.default
|
t.attr_type = attr_types.default
|
||||||
if str_def.find("<") != -1:# and str_def.find("<") < str_def.find(" "):
|
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)
|
candidate = WContainer.from_string(str_def, containing_file, line_number)
|
||||||
if candidate == None:
|
if candidate == None:
|
||||||
return None
|
return None
|
||||||
|
@ -203,8 +205,12 @@ class WType:
|
||||||
|
|
||||||
prefix = ""
|
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 "):
|
if str.startswith(str_def, "unsigned "):
|
||||||
prefix = "unsigned "
|
prefix = "unsigned " + prefix
|
||||||
str_def = str_def[9:]
|
str_def = str_def[9:]
|
||||||
while str.startswith(str_def, "long "):
|
while str.startswith(str_def, "long "):
|
||||||
prefix= "long " + prefix
|
prefix= "long " + prefix
|
||||||
|
@ -1285,7 +1291,7 @@ class WFunction:
|
||||||
prefix = ""
|
prefix = ""
|
||||||
i = 0
|
i = 0
|
||||||
for part in parts:
|
for part in parts:
|
||||||
if part in ["unsigned", "long", "short"]:
|
if part in ["unsigned", "long", "short", "const"]:
|
||||||
prefix += part + " "
|
prefix += part + " "
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
|
@ -1361,10 +1367,17 @@ class WFunction:
|
||||||
func.args.append(parsed)
|
func.args.append(parsed)
|
||||||
return func
|
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):
|
def gen_alias(self):
|
||||||
self.alias = self.name
|
self.alias = self.mangled_name
|
||||||
for arg in self.args:
|
|
||||||
self.alias += "__" + arg.wtype.gen_text_cpp().replace("::", "_").replace("<","_").replace(">","_").replace(" ","").replace("*","").replace(",","")
|
|
||||||
|
|
||||||
def gen_decl(self):
|
def gen_decl(self):
|
||||||
if self.duplicate:
|
if self.duplicate:
|
||||||
|
@ -2190,12 +2203,15 @@ def clean_duplicates():
|
||||||
for fun in class_.found_funs:
|
for fun in class_.found_funs:
|
||||||
if fun.gen_decl_hash_py() in known_decls:
|
if fun.gen_decl_hash_py() in known_decls:
|
||||||
debug("Multiple declarations of " + fun.gen_decl_hash_py(),3)
|
debug("Multiple declarations of " + fun.gen_decl_hash_py(),3)
|
||||||
|
|
||||||
other = known_decls[fun.gen_decl_hash_py()]
|
other = known_decls[fun.gen_decl_hash_py()]
|
||||||
other.gen_alias()
|
if fun.mangled_name == other.mangled_name:
|
||||||
fun.gen_alias()
|
|
||||||
if fun.gen_decl_hash_py() == other.gen_decl_hash_py():
|
|
||||||
fun.duplicate = True
|
fun.duplicate = True
|
||||||
debug("Disabled \"" + fun.gen_decl_hash_py() + "\"", 3)
|
debug("Disabled \"" + fun.gen_decl_hash_py() + "\"", 3)
|
||||||
|
continue
|
||||||
|
|
||||||
|
other.gen_alias()
|
||||||
|
fun.gen_alias()
|
||||||
else:
|
else:
|
||||||
known_decls[fun.gen_decl_hash_py()] = fun
|
known_decls[fun.gen_decl_hash_py()] = fun
|
||||||
known_decls = []
|
known_decls = []
|
||||||
|
|
Loading…
Reference in a new issue