From: Jacob Lifshay Date: Fri, 14 Oct 2022 06:26:09 +0000 (-0700) Subject: add FixedGPRRangeType X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b099feff4ad332108008a66b148caf38903c3d9;p=bigint-presentation-code.git add FixedGPRRangeType --- diff --git a/src/bigint_presentation_code/compiler_ir.py b/src/bigint_presentation_code/compiler_ir.py index 645ff0e..f4f09f7 100644 --- a/src/bigint_presentation_code/compiler_ir.py +++ b/src/bigint_presentation_code/compiler_ir.py @@ -248,6 +248,22 @@ class GPRType(GPRRangeType): super().__init__(length=1) +@plain_data(frozen=True, unsafe_hash=True) +@final +class FixedGPRRangeType(GPRRangeType): + __slots__ = "reg", + + def __init__(self, reg): + # type: (GPRRange) -> None + super().__init__(length=reg.length) + self.reg = reg + + @property + def reg_class(self): + # type: () -> RegClass + return RegClass([self.reg]) + + @plain_data(frozen=True, unsafe_hash=True) @final class CYType(RegType): @@ -460,9 +476,20 @@ class OpCopy(Op, Generic[_RegT_co]): # type: () -> dict[str, SSAVal] return {"dest": self.dest} - def __init__(self, src): - # type: (SSAVal[_RegT_co]) -> None - self.dest = SSAVal(self, "dest", src.ty) + def __init__(self, src, dest_ty=None): + # type: (SSAVal[_RegT_co], _RegT_co | None) -> None + if dest_ty is None: + dest_ty = src.ty + if isinstance(src.ty, GPRRangeType) \ + and isinstance(dest_ty, GPRRangeType): + if src.ty.length != dest_ty.length: + raise ValueError(f"incompatible source and destination " + f"types: {src.ty} and {dest_ty}") + elif src.ty != dest_ty: + raise ValueError(f"incompatible source and destination " + f"types: {src.ty} and {dest_ty}") + + self.dest = SSAVal(self, "dest", dest_ty) self.src = src @@ -724,7 +751,7 @@ class OpFuncArg(Op): return {"out": self.out} def __init__(self, ty): - # type: (RegType) -> None + # type: (FixedGPRRangeType) -> None self.out = SSAVal(self, "out", ty)