From 4b9c1350980f8e4b96f500d6c3a96fb2d88ba341 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 16 Oct 2024 22:46:23 +0200 Subject: [PATCH 1/6] py_wrap: refactor nesting_delta --- misc/py_wrap_generator.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index a65d24d92..049c67f19 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -1958,7 +1958,10 @@ def assure_length(text, length, left = False): if left: return text + " "*(length - len(text)) return " "*(length - len(text)) + text - + +def nesting_delta(s): + return s.count("{") - s.count("}") + def parse_header(source): debug("Parsing " + source.name + ".pyh",1) source_file = open(source.name + ".pyh", "r") @@ -1982,6 +1985,7 @@ def parse_header(source): while i < len(source_text): line = source_text[i].replace("YOSYS_NAMESPACE_BEGIN", " namespace YOSYS_NAMESPACE{").replace("YOSYS_NAMESPACE_END"," }") ugly_line = unpretty_string(line) + debug(f"READ:>> {line}", 2) # for anonymous unions, ignore union enclosure by skipping start line and replacing end line with new line if 'union {' in line: @@ -2004,15 +2008,15 @@ def parse_header(source): continue if len(namespaces) != 0: - namespaces[-1] = (namespaces[-1][0], namespaces[-1][1] + ugly_line.count("{") - ugly_line.count("}")) + namespaces[-1] = (namespaces[-1][0], namespaces[-1][1] + nesting_delta(ugly_line)) if namespaces[-1][1] == 0: debug("-----END NAMESPACE " + concat_namespace(namespaces) + "-----",3) - del namespaces[-1] + namespaces.pop() i += 1 continue if class_ == None and (str.startswith(ugly_line, "struct ") or str.startswith(ugly_line, "class")) and ugly_line.count(";") == 0: - + # Opening a record declaration which isn't a forward declaration struct_name = ugly_line.split(" ")[1].split("::")[-1] impl_namespaces = ugly_line.split(" ")[1].split("::")[:-1] complete_namespace = concat_namespace(namespaces) @@ -2031,6 +2035,7 @@ def parse_header(source): base_class = class_by_name(base_class_name) class_ = (class_by_name(struct_name), ugly_line.count("{"))#calc_ident(line)) + debug(f"switch to {struct_name} in namespace {namespaces}", 2) if struct_name in classnames: class_[0].namespace = complete_namespace class_[0].base_class = base_class @@ -2038,12 +2043,14 @@ def parse_header(source): continue if class_ != None: - class_ = (class_[0], class_[1] + ugly_line.count("{") - ugly_line.count("}")) + class_ = (class_[0], class_[1] + nesting_delta(ugly_line)) + debug(f"switch to uhh depth {class_[1]}", 2) if class_[1] == 0: if class_[0] == None: debug("\tExiting unknown class", 3) else: debug("\tExiting class " + class_[0].name, 3) + debug(f"nevermind!", 2) class_ = None private_segment = False i += 1 @@ -2156,12 +2163,12 @@ def parse_header(source): line = source_text[i].replace("YOSYS_NAMESPACE_BEGIN", " namespace YOSYS_NAMESPACE{").replace("YOSYS_NAMESPACE_END"," }") ugly_line = unpretty_string(line) if len(namespaces) != 0: - namespaces[-1] = (namespaces[-1][0], namespaces[-1][1] + ugly_line.count("{") - ugly_line.count("}")) + namespaces[-1] = (namespaces[-1][0], namespaces[-1][1] + nesting_delta(ugly_line)) if namespaces[-1][1] == 0: debug("-----END NAMESPACE " + concat_namespace(namespaces) + "-----",3) - del namespaces[-1] + namespaces.pop() if class_ != None: - class_ = (class_[0] , class_[1] + ugly_line.count("{") - ugly_line.count("}")) + class_ = (class_[0] , class_[1] + nesting_delta(ugly_line)) if class_[1] == 0: if class_[0] == None: debug("\tExiting unknown class", 3) From 86630bba0823b0a1046c3b55de33e0f362bbf21e Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 16 Oct 2024 22:55:17 +0200 Subject: [PATCH 2/6] py_wrap: nested classes --- misc/py_wrap_generator.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index 049c67f19..e95fc0e73 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -1979,7 +1979,7 @@ def parse_header(source): i = 0 namespaces = [] - class_ = None + classes = [] private_segment = False while i < len(source_text): @@ -2015,7 +2015,7 @@ def parse_header(source): i += 1 continue - if class_ == None and (str.startswith(ugly_line, "struct ") or str.startswith(ugly_line, "class")) and ugly_line.count(";") == 0: + if (str.startswith(ugly_line, "struct ") or str.startswith(ugly_line, "class")) and ugly_line.count(";") == 0: # Opening a record declaration which isn't a forward declaration struct_name = ugly_line.split(" ")[1].split("::")[-1] impl_namespaces = ugly_line.split(" ")[1].split("::")[:-1] @@ -2034,28 +2034,31 @@ def parse_header(source): 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)) + c = (class_by_name(struct_name), ugly_line.count("{"))#calc_ident(line)) debug(f"switch to {struct_name} in namespace {namespaces}", 2) if struct_name in classnames: - class_[0].namespace = complete_namespace - class_[0].base_class = base_class + c[0].namespace = complete_namespace + c[0].base_class = base_class + classes.append(c) i += 1 continue - if class_ != None: - class_ = (class_[0], class_[1] + nesting_delta(ugly_line)) - debug(f"switch to uhh depth {class_[1]}", 2) - if class_[1] == 0: - if class_[0] == None: + if len(classes): + c = (classes[-1][0], classes[-1][1] + nesting_delta(ugly_line)) + debug(f"switch to uhh depth {c[1]}", 2) + if c[1] == 0: + if c[0] == None: debug("\tExiting unknown class", 3) else: - debug("\tExiting class " + class_[0].name, 3) + debug("\tExiting class " + c[0].name, 3) debug(f"nevermind!", 2) - class_ = None + classes.pop() private_segment = False i += 1 continue + class_ = classes[-1] if classes else None + if class_ != None and (line.find("private:") != -1 or line.find("protected:") != -1): private_segment = True i += 1 @@ -2167,14 +2170,14 @@ def parse_header(source): if namespaces[-1][1] == 0: debug("-----END NAMESPACE " + concat_namespace(namespaces) + "-----",3) namespaces.pop() - if class_ != None: - class_ = (class_[0] , class_[1] + nesting_delta(ugly_line)) - if class_[1] == 0: - if class_[0] == None: + if len(classes): + c = (classes[-1][0] , classes[-1][1] + nesting_delta(ugly_line)) + if c[1] == 0: + if c[0] == None: debug("\tExiting unknown class", 3) else: - debug("\tExiting class " + class_[0].name, 3) - class_ = None + debug("\tExiting class " + c[0].name, 3) + classes.pop() private_segment = False i += 1 else: From f219bb357f338aa53e2d21d564e34d9013b93744 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 16 Oct 2024 23:12:41 +0200 Subject: [PATCH 3/6] py_wrap: kinda fixed --- misc/py_wrap_generator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index e95fc0e73..fe80c8c85 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -2045,6 +2045,7 @@ def parse_header(source): if len(classes): c = (classes[-1][0], classes[-1][1] + nesting_delta(ugly_line)) + classes[-1] = c debug(f"switch to uhh depth {c[1]}", 2) if c[1] == 0: if c[0] == None: @@ -2172,6 +2173,7 @@ def parse_header(source): namespaces.pop() if len(classes): c = (classes[-1][0] , classes[-1][1] + nesting_delta(ugly_line)) + classes[-1] = c if c[1] == 0: if c[0] == None: debug("\tExiting unknown class", 3) From e9e67f381cd47763efd50a9cb331b3d2e3619421 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 16 Oct 2024 23:15:06 +0200 Subject: [PATCH 4/6] rtlil: remove trailing comma as pyosys workaround --- kernel/rtlil.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index eaaae814d..136cf9a13 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -53,15 +53,9 @@ namespace RTLIL CONST_FLAG_NONE = 0, CONST_FLAG_STRING = 1, CONST_FLAG_SIGNED = 2, // only used for parameters - CONST_FLAG_REAL = 4, // only used for parameters + CONST_FLAG_REAL = 4 // only used for parameters }; - // // Union discriminator. Values are exclusive - // enum ConstRepr : unsigned char { - // CONST_REPR_BITS = 1, - // CONST_REPR_STRING = 2, - // }; - struct Const; struct AttrObject; struct Selection; From d5aadeae3ba2a4a377455e03d1b3c39f1d48a9d0 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 18 Oct 2024 11:18:34 +0200 Subject: [PATCH 5/6] py_wrap: remove some debug statements --- misc/py_wrap_generator.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/misc/py_wrap_generator.py b/misc/py_wrap_generator.py index fe80c8c85..91a82081a 100644 --- a/misc/py_wrap_generator.py +++ b/misc/py_wrap_generator.py @@ -2046,13 +2046,11 @@ def parse_header(source): if len(classes): c = (classes[-1][0], classes[-1][1] + nesting_delta(ugly_line)) classes[-1] = c - debug(f"switch to uhh depth {c[1]}", 2) if c[1] == 0: if c[0] == None: debug("\tExiting unknown class", 3) else: debug("\tExiting class " + c[0].name, 3) - debug(f"nevermind!", 2) classes.pop() private_segment = False i += 1 From 49d8a35c2ec4a3e8364591ad11210417d123b65a Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 18 Oct 2024 11:31:20 +0200 Subject: [PATCH 6/6] rtlil: appease py_wrap --- kernel/rtlil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 136cf9a13..0f3984ab8 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -660,7 +660,7 @@ namespace RTLIL struct RTLIL::Const { - short flags; + short int flags; private: friend class KernelRtlilTest; FRIEND_TEST(KernelRtlilTest, ConstStr);