add FixedGPRRangeType
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 14 Oct 2022 06:26:09 +0000 (23:26 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 14 Oct 2022 06:26:09 +0000 (23:26 -0700)
src/bigint_presentation_code/compiler_ir.py

index 645ff0eac0d8069fa7702a342760ac742449f573..f4f09f7cb613806c63e233b66c7bab0ecc252f5c 100644 (file)
@@ -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)