3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-11 13:40:53 +00:00

Merge pull request #5269 from georgerennie/george/pyosys_source_location

pyosys: support trailing defaulted source_location arguments
This commit is contained in:
KrystalDelusion 2025-08-07 11:50:06 +12:00 committed by GitHub
commit 4230c2712f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 16 deletions

View file

@ -116,7 +116,7 @@ struct ScriptPass : Pass
RTLIL::Design *active_design; RTLIL::Design *active_design;
std::string active_run_from, active_run_to; std::string active_run_from, active_run_to;
ScriptPass(std::string name, std::string short_help = "** document me **", source_location location = source_location::current()) : ScriptPass(std::string name, std::string short_help = "** document me **", source_location location = source_location::current()) :
Pass(name, short_help, location) { } Pass(name, short_help, location) { }
virtual void script() = 0; virtual void script() = 0;

View file

@ -71,7 +71,7 @@ keyword_aliases = {
#These can be used without any explicit conversion #These can be used without any explicit conversion
primitive_types = ["void", "bool", "int", "double", "size_t", "std::string", primitive_types = ["void", "bool", "int", "double", "size_t", "std::string",
"string", "State", "char_p"] "string", "State", "char_p", "std::source_location", "source_location"]
from enum import Enum from enum import Enum
@ -200,7 +200,7 @@ class WType:
t.cont = candidate t.cont = candidate
if(t.name not in known_containers): if(t.name not in known_containers):
return None return None
return t return t
prefix = "" prefix = ""
@ -447,7 +447,7 @@ class PythonDictTranslator(Translator):
if types[0].attr_type != attr_types.star: if types[0].attr_type != attr_types.star:
text += "*" text += "*"
text += key_tmp_name + "->get_cpp_obj()" text += key_tmp_name + "->get_cpp_obj()"
text += ", " text += ", "
if types[1].name not in classnames: if types[1].name not in classnames:
text += val_tmp_name text += val_tmp_name
@ -457,7 +457,7 @@ class PythonDictTranslator(Translator):
text += val_tmp_name + "->get_cpp_obj()" text += val_tmp_name + "->get_cpp_obj()"
text += "));\n" + prefix + "}" text += "));\n" + prefix + "}"
return text return text
#Generate c++ code to translate to a boost::python::dict #Generate c++ code to translate to a boost::python::dict
@classmethod @classmethod
def translate_cpp(c, varname, types, prefix, ref): def translate_cpp(c, varname, types, prefix, ref):
@ -498,7 +498,7 @@ class DictTranslator(PythonDictTranslator):
#Sub_type for std::map #Sub_type for std::map
class MapTranslator(PythonDictTranslator): class MapTranslator(PythonDictTranslator):
insert_name = "insert" insert_name = "insert"
orig_name = "std::map" orig_name = "std::map"
#Translator for std::pair. Derived from PythonDictTranslator because the #Translator for std::pair. Derived from PythonDictTranslator because the
#gen_type function is the same (because both have two template parameters) #gen_type function is the same (because both have two template parameters)
@ -684,7 +684,7 @@ class Attribute:
if self.wtype.name in known_containers: if self.wtype.name in known_containers:
return known_containers[self.wtype.name].typename return known_containers[self.wtype.name].typename
return prefix + self.wtype.name return prefix + self.wtype.name
#Generate Translation code for the attribute #Generate Translation code for the attribute
def gen_translation(self): def gen_translation(self):
if self.wtype.name in known_containers: if self.wtype.name in known_containers:
@ -948,7 +948,7 @@ class WClass:
text = "\n\t\tclass_<" + self.name + base_info + ">(\"" + self.name + "\"" text = "\n\t\tclass_<" + self.name + base_info + ">(\"" + self.name + "\""
text += body text += body
return text return text
def contains_default_constr(self): def contains_default_constr(self):
for c in self.found_constrs: for c in self.found_constrs:
@ -1137,10 +1137,18 @@ class WConstructor:
str_def = str_def[0:found].strip() str_def = str_def[0:found].strip()
if len(str_def) == 0: if len(str_def) == 0:
return con return con
for arg in split_list(str_def, ","): args = split_list(str_def, ",")
for i, arg in enumerate(args):
parsed = Attribute.from_string(arg.strip(), containing_file, line_number) parsed = Attribute.from_string(arg.strip(), containing_file, line_number)
if parsed == None: if parsed == None:
return None return None
# Only allow std::source_location as defaulted last argument, and
# don't append so it takes default value
if parsed.wtype.name in ["std::source_location", "source_location"]:
if parsed.default_value is None or i != len(args) - 1:
debug("std::source_location not defaulted last arg of " + class_.name + " is unsupported", 2)
return None
continue
con.args.append(parsed) con.args.append(parsed)
return con return con
@ -1379,12 +1387,20 @@ class WFunction:
str_def = str_def[:found].strip() str_def = str_def[:found].strip()
if(len(str_def) == 0): if(len(str_def) == 0):
return func return func
for arg in split_list(str_def, ","): args = split_list(str_def, ",")
for i, arg in enumerate(args):
if arg.strip() == "...": if arg.strip() == "...":
continue continue
parsed = Attribute.from_string(arg.strip(), containing_file, line_number) parsed = Attribute.from_string(arg.strip(), containing_file, line_number)
if parsed == None: if parsed == None:
return None return None
# Only allow std::source_location as defaulted last argument, and
# don't append so it takes default value
if parsed.wtype.name in ["std::source_location", "source_location"]:
if parsed.default_value is None or i != len(args) - 1:
debug("std::source_location not defaulted last arg of " + func.name + " is unsupported", 2)
return None
continue
func.args.append(parsed) func.args.append(parsed)
return func return func
@ -1773,7 +1789,7 @@ class WMember:
if self.wtype.name in classnames: if self.wtype.name in classnames:
text += ")" text += ")"
text += ";" text += ";"
if self.wtype.name in classnames: if self.wtype.name in classnames:
text += "\n\t\treturn *ret_;" text += "\n\t\treturn *ret_;"
elif self.wtype.name in known_containers: elif self.wtype.name in known_containers:
@ -1795,12 +1811,12 @@ class WMember:
text += "\n\t{" text += "\n\t{"
text += ret.gen_translation() text += ret.gen_translation()
text += "\n\t\tthis->get_cpp_obj()->" + self.name + " = " + ret.gen_call() + ";" text += "\n\t\tthis->get_cpp_obj()->" + self.name + " = " + ret.gen_call() + ";"
text += "\n\t}\n" text += "\n\t}\n"
return text; return text;
def gen_boost_py(self): def gen_boost_py(self):
text = "\n\t\t\t.add_property(\"" + self.name + "\", &" + self.member_of.name + "::get_var_py_" + self.name text = "\n\t\t\t.add_property(\"" + self.name + "\", &" + self.member_of.name + "::get_var_py_" + self.name
if not self.is_const: if not self.is_const:
text += ", &" + self.member_of.name + "::set_var_py_" + self.name text += ", &" + self.member_of.name + "::set_var_py_" + self.name
text += ")" text += ")"
@ -1926,7 +1942,7 @@ class WGlobal:
if self.wtype.name in classnames: if self.wtype.name in classnames:
text += ")" text += ")"
text += ";" text += ";"
if self.wtype.name in classnames: if self.wtype.name in classnames:
text += "\n\t\treturn *ret_;" text += "\n\t\treturn *ret_;"
elif self.wtype.name in known_containers: elif self.wtype.name in known_containers:
@ -1948,12 +1964,12 @@ class WGlobal:
text += "\n\t{" text += "\n\t{"
text += ret.gen_translation() text += ret.gen_translation()
text += "\n\t\t" + self.namespace + "::" + self.name + " = " + ret.gen_call() + ";" text += "\n\t\t" + self.namespace + "::" + self.name + " = " + ret.gen_call() + ";"
text += "\n\t}\n" text += "\n\t}\n"
return text; return text;
def gen_boost_py(self): def gen_boost_py(self):
text = "\n\t\t\t.add_static_property(\"" + self.name + "\", &" + "YOSYS_PYTHON::get_var_py_" + self.name text = "\n\t\t\t.add_static_property(\"" + self.name + "\", &" + "YOSYS_PYTHON::get_var_py_" + self.name
if not self.is_const: if not self.is_const:
text += ", &YOSYS_PYTHON::set_var_py_" + self.name text += ", &YOSYS_PYTHON::set_var_py_" + self.name
text += ")" text += ")"