mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-18 03:46:18 +00:00
Merge pull request #1669 from thasti/pyosys-attrs
Make RTLIL attributes accessible via pyosys
This commit is contained in:
commit
224dc033aa
1 changed files with 38 additions and 2 deletions
|
@ -721,6 +721,7 @@ class WClass:
|
||||||
name = None
|
name = None
|
||||||
namespace = None
|
namespace = None
|
||||||
link_type = None
|
link_type = None
|
||||||
|
base_class = None
|
||||||
id_ = None
|
id_ = None
|
||||||
string_id = None
|
string_id = None
|
||||||
hash_id = None
|
hash_id = None
|
||||||
|
@ -732,6 +733,7 @@ class WClass:
|
||||||
def __init__(self, name, link_type, id_, string_id = None, hash_id = None, needs_clone = False):
|
def __init__(self, name, link_type, id_, string_id = None, hash_id = None, needs_clone = False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.namespace = None
|
self.namespace = None
|
||||||
|
self.base_class = None
|
||||||
self.link_type = link_type
|
self.link_type = link_type
|
||||||
self.id_ = id_
|
self.id_ = id_
|
||||||
self.string_id = string_id
|
self.string_id = string_id
|
||||||
|
@ -804,6 +806,8 @@ class WClass:
|
||||||
|
|
||||||
for con in self.found_constrs:
|
for con in self.found_constrs:
|
||||||
text += con.gen_decl()
|
text += con.gen_decl()
|
||||||
|
if self.base_class is not None:
|
||||||
|
text += "\n\t\tvirtual ~" + self.name + "() { };"
|
||||||
for var in self.found_vars:
|
for var in self.found_vars:
|
||||||
text += var.gen_decl()
|
text += var.gen_decl()
|
||||||
for fun in self.found_funs:
|
for fun in self.found_funs:
|
||||||
|
@ -908,15 +912,19 @@ class WClass:
|
||||||
|
|
||||||
def gen_boost_py(self):
|
def gen_boost_py(self):
|
||||||
body = self.gen_boost_py_body()
|
body = self.gen_boost_py_body()
|
||||||
|
base_info = ""
|
||||||
|
if self.base_class is not None:
|
||||||
|
base_info = ", bases<" + (self.base_class.name) + ">"
|
||||||
|
|
||||||
if self.link_type == link_types.derive:
|
if self.link_type == link_types.derive:
|
||||||
text = "\n\t\tclass_<" + self.name + ">(\"Cpp" + self.name + "\""
|
text = "\n\t\tclass_<" + self.name + base_info + ">(\"Cpp" + self.name + "\""
|
||||||
text += body
|
text += body
|
||||||
text += "\n\t\tclass_<" + self.name
|
text += "\n\t\tclass_<" + self.name
|
||||||
text += "Wrap, boost::noncopyable"
|
text += "Wrap, boost::noncopyable"
|
||||||
text += ">(\"" + self.name + "\""
|
text += ">(\"" + self.name + "\""
|
||||||
text += body
|
text += body
|
||||||
else:
|
else:
|
||||||
text = "\n\t\tclass_<" + self.name + ">(\"" + self.name + "\""
|
text = "\n\t\tclass_<" + self.name + base_info + ">(\"" + self.name + "\""
|
||||||
text += body
|
text += body
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
@ -1971,9 +1979,21 @@ def parse_header(source):
|
||||||
for namespace in impl_namespaces:
|
for namespace in impl_namespaces:
|
||||||
complete_namespace += "::" + namespace
|
complete_namespace += "::" + namespace
|
||||||
debug("\tFound " + struct_name + " in " + complete_namespace,2)
|
debug("\tFound " + struct_name + " in " + complete_namespace,2)
|
||||||
|
|
||||||
|
base_class_name = None
|
||||||
|
if len(ugly_line.split(" : ")) > 1: # class is derived
|
||||||
|
deriv_str = ugly_line.split(" : ")[1]
|
||||||
|
if len(deriv_str.split("::")) > 1: # namespace of base class is given
|
||||||
|
base_class_name = deriv_str.split("::", 1)[1]
|
||||||
|
else:
|
||||||
|
base_class_name = deriv_str.split(" ")[0]
|
||||||
|
debug("\t " + struct_name + " is derived from " + base_class_name,2)
|
||||||
|
base_class = class_by_name(base_class_name)
|
||||||
|
|
||||||
class_ = (class_by_name(struct_name), ugly_line.count("{"))#calc_ident(line))
|
class_ = (class_by_name(struct_name), ugly_line.count("{"))#calc_ident(line))
|
||||||
if struct_name in classnames:
|
if struct_name in classnames:
|
||||||
class_[0].namespace = complete_namespace
|
class_[0].namespace = complete_namespace
|
||||||
|
class_[0].base_class = base_class
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -2142,6 +2162,21 @@ def expand_functions():
|
||||||
new_funs.extend(expand_function(fun))
|
new_funs.extend(expand_function(fun))
|
||||||
class_.found_funs = new_funs
|
class_.found_funs = new_funs
|
||||||
|
|
||||||
|
def inherit_members():
|
||||||
|
for source in sources:
|
||||||
|
for class_ in source.classes:
|
||||||
|
if class_.base_class:
|
||||||
|
base_funs = copy.deepcopy(class_.base_class.found_funs)
|
||||||
|
for fun in base_funs:
|
||||||
|
fun.member_of = class_
|
||||||
|
fun.namespace = class_.namespace
|
||||||
|
base_vars = copy.deepcopy(class_.base_class.found_vars)
|
||||||
|
for var in base_vars:
|
||||||
|
var.member_of = class_
|
||||||
|
var.namespace = class_.namespace
|
||||||
|
class_.found_funs.extend(base_funs)
|
||||||
|
class_.found_vars.extend(base_vars)
|
||||||
|
|
||||||
def clean_duplicates():
|
def clean_duplicates():
|
||||||
for source in sources:
|
for source in sources:
|
||||||
for class_ in source.classes:
|
for class_ in source.classes:
|
||||||
|
@ -2178,6 +2213,7 @@ def gen_wrappers(filename, debug_level_ = 0):
|
||||||
parse_header(source)
|
parse_header(source)
|
||||||
|
|
||||||
expand_functions()
|
expand_functions()
|
||||||
|
inherit_members()
|
||||||
clean_duplicates()
|
clean_duplicates()
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue