From 00b7f77b4b51b862922e6d73137243215133efa5 Mon Sep 17 00:00:00 2001 From: Robert Muth Date: Thu, 17 Oct 2024 13:57:40 -0400 Subject: [PATCH] more standardization on span/union instead of slice/sum --- FrontEnd/canonicalize.py | 2 +- FrontEnd/canonicalize_union.py | 3 +-- FrontEnd/type_corpus.py | 10 +++++----- FrontEnd/typify.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/FrontEnd/canonicalize.py b/FrontEnd/canonicalize.py index be58f38c..b18f4f6b 100644 --- a/FrontEnd/canonicalize.py +++ b/FrontEnd/canonicalize.py @@ -632,7 +632,7 @@ def _IsSimpleInitializer(expr) -> bool: def FunRewriteComplexAssignments(fun: cwast.DefFun, id_gen: identifier.IdGen, tc: type_corpus.TypeCorpus): - """Rewrite assignments of recs (including unions and slices) and arrays + """Rewrite assignments of recs (including unions and spans) and arrays to ensure correctness. Consider: diff --git a/FrontEnd/canonicalize_union.py b/FrontEnd/canonicalize_union.py index 929fd002..69414bbc 100644 --- a/FrontEnd/canonicalize_union.py +++ b/FrontEnd/canonicalize_union.py @@ -55,7 +55,6 @@ def add_replacement(old_ct: cwast.CanonType, new_ct: cwast.CanonType): if ct.replacement_type is not None: continue if ct.is_tagged_union(): - # maybe add DefRec to mod for generated code rec = _MakeSumReplacementStruct(ct, tc) mod_gen.body_mod.append(rec) add_replacement(ct, rec.x_type) @@ -73,7 +72,7 @@ def add_replacement(old_ct: cwast.CanonType, new_ct: cwast.CanonType): add_replacement(ct, tc.insert_array_type( ct.array_dim(), replacement)) elif ct.is_span(): - # This is now run this after slices have been eliminated so + # This is now run this after spans have been eliminated so # we do not have to deal with this case anymore assert False replacement = ct.underlying_span_type().replacement_type diff --git a/FrontEnd/type_corpus.py b/FrontEnd/type_corpus.py index 1ba9d53d..373743db 100644 --- a/FrontEnd/type_corpus.py +++ b/FrontEnd/type_corpus.py @@ -223,7 +223,7 @@ def is_mutable_array_or_span(node) -> bool: } -def _get_size_and_offset_for_sum_type(ct: cwast.CanonType, tag_size, ptr_size): +def _get_size_and_offset_for_union_type(ct: cwast.CanonType, tag_size, ptr_size): assert ct.node is cwast.TypeUnion num_void = 0 num_pointer = 0 @@ -331,7 +331,7 @@ def get_uint_reg_type(self): def get_address_size(self): return self._target_arch_config.data_addr_bitwidth // 8 - def _get_register_type_for_sum_type(self, ct: cwast.CanonType) -> Optional[list[str]]: + def _get_register_type_for_union_type(self, ct: cwast.CanonType) -> Optional[list[str]]: assert ct.node is cwast.TypeUnion num_void = 0 scalars: list[cwast.CanonType] = [] @@ -385,7 +385,7 @@ def _get_register_type(self, ct: cwast.CanonType) -> Optional[list[str]]: elif ct.node is cwast.DefEnum: return _BASE_TYPE_MAP[ct.base_type_kind] elif ct.node is cwast.TypeUnion: - return self._get_register_type_for_sum_type(ct) + return self._get_register_type_for_union_type(ct) elif ct.node is cwast.DefType: return self._get_register_type(ct.children[0]) elif ct.node is cwast.TypeFun: @@ -431,7 +431,7 @@ def _get_size_and_alignment(self, ct: cwast.CanonType): elif ct.node is cwast.TypeVec: return ct.children[0].aligned_size() * ct.dim, ct.children[0].alignment elif ct.node is cwast.TypeUnion: - return _get_size_and_offset_for_sum_type( + return _get_size_and_offset_for_union_type( ct, self._target_arch_config.typeid_bitwidth // 8, self._target_arch_config.data_addr_bitwidth // 8) elif ct.node is cwast.DefEnum: @@ -545,7 +545,7 @@ def insert_wrapped_type(self, ct: cwast.CanonType) -> cwast.CanonType: assert name not in self.corpus return self._insert(cwast.CanonType(cwast.DefType, name, children=[ct])) - def insert_sum_complement(self, all: cwast.CanonType, part: cwast.CanonType) -> cwast.CanonType: + def insert_union_complement(self, all: cwast.CanonType, part: cwast.CanonType) -> cwast.CanonType: assert all.node is cwast.TypeUnion, f"expect sum type: {all.name}" if part.node is cwast.TypeUnion: part_children = part.children diff --git a/FrontEnd/typify.py b/FrontEnd/typify.py index fc51d788..806a33b8 100755 --- a/FrontEnd/typify.py +++ b/FrontEnd/typify.py @@ -329,7 +329,7 @@ def _TypifyUnevaluableNodeRecursively(node, tc: type_corpus.TypeCorpus, node.type, tc, cwast.NO_TYPE, ctx) subtrahend = _TypifyNodeRecursively( node.subtrahend, tc, cwast.NO_TYPE, ctx) - return AnnotateNodeType(node, tc.insert_sum_complement(minuend, subtrahend)) + return AnnotateNodeType(node, tc.insert_union_complement(minuend, subtrahend)) elif isinstance(node, cwast.TypeOf): ct = _TypifyNodeRecursively(node.expr, tc, cwast.NO_TYPE, ctx) return AnnotateNodeType(node, ct)