Skip to content

Commit

Permalink
more standardization on span/union instead of slice/sum
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Oct 17, 2024
1 parent 10af4d1 commit 00b7f77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion FrontEnd/canonicalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions FrontEnd/canonicalize_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions FrontEnd/type_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/typify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 00b7f77

Please sign in to comment.