GH-135379: Remove types from stack items in code generator. (GH-135384)

* Make casts explicit in the instruction definitions
This commit is contained in:
Mark Shannon 2025-06-11 15:52:25 +01:00 committed by GitHub
parent 49d72365cd
commit c87b5b2cb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 257 additions and 255 deletions

View file

@ -168,7 +168,7 @@ def from_memory(defn: StackItem, offset: PointerOffset) -> "Local":
@staticmethod
def register(name: str) -> "Local":
item = StackItem(name, None, "", False, True)
item = StackItem(name, "", False, True)
return Local(item, None, True)
def kill(self) -> None:
@ -216,13 +216,11 @@ def array_or_scalar(var: StackItem | Local) -> str:
return "array" if var.is_array() else "scalar"
class Stack:
def __init__(self, extract_bits: bool=True, cast_type: str = "uintptr_t") -> None:
def __init__(self) -> None:
self.base_offset = PointerOffset.zero()
self.physical_sp = PointerOffset.zero()
self.logical_sp = PointerOffset.zero()
self.variables: list[Local] = []
self.extract_bits = extract_bits
self.cast_type = cast_type
def drop(self, var: StackItem, check_liveness: bool) -> None:
self.logical_sp = self.logical_sp.pop(var)
@ -268,10 +266,8 @@ def pop(self, var: StackItem, out: CWriter) -> Local:
self.base_offset = self.logical_sp
if var.name in UNUSED or not var.used:
return Local.unused(var, self.base_offset)
cast = f"({var.type})" if (not indirect and var.type) else ""
bits = ".bits" if cast and self.extract_bits else ""
c_offset = (self.base_offset - self.physical_sp).to_c()
assign = f"{var.name} = {cast}{indirect}stack_pointer[{c_offset}]{bits};\n"
assign = f"{var.name} = {indirect}stack_pointer[{c_offset}];\n"
out.emit(assign)
self._print(out)
return Local.from_memory(var, self.base_offset)
@ -292,12 +288,8 @@ def _do_emit(
out: CWriter,
var: StackItem,
stack_offset: PointerOffset,
cast_type: str,
extract_bits: bool,
) -> None:
cast = f"({cast_type})" if var.type else ""
bits = ".bits" if cast and extract_bits else ""
out.emit(f"stack_pointer[{stack_offset.to_c()}]{bits} = {cast}{var.name};\n")
out.emit(f"stack_pointer[{stack_offset.to_c()}] = {var.name};\n")
def _save_physical_sp(self, out: CWriter) -> None:
if self.physical_sp != self.logical_sp:
@ -320,7 +312,7 @@ def save_variables(self, out: CWriter) -> None:
self._print(out)
var.memory_offset = var_offset
stack_offset = var_offset - self.physical_sp
Stack._do_emit(out, var.item, stack_offset, self.cast_type, self.extract_bits)
Stack._do_emit(out, var.item, stack_offset)
self._print(out)
var_offset = var_offset.push(var.item)
@ -350,7 +342,7 @@ def _print(self, out: CWriter) -> None:
out.emit(self.as_comment() + "\n")
def copy(self) -> "Stack":
other = Stack(self.extract_bits, self.cast_type)
other = Stack()
other.base_offset = self.base_offset
other.physical_sp = self.physical_sp
other.logical_sp = self.logical_sp