working on generating output assembly
[bigint-presentation-code.git] / src / bigint_presentation_code / register_allocator.py
index b44c32dd76023c948ff9be447d34eb16e02a77bf..a22299f842badfdb4d48439907f7ec373b31ed52 100644 (file)
@@ -342,6 +342,13 @@ class AllocationFailed:
         self.interference_graph = interference_graph
 
 
+class AllocationFailedError(Exception):
+    def __init__(self, msg, allocation_failed):
+        # type: (str, AllocationFailed) -> None
+        super().__init__(msg, allocation_failed)
+        self.allocation_failed = allocation_failed
+
+
 def try_allocate_registers_without_spilling(ops):
     # type: (list[Op]) -> dict[SSAVal, RegLoc] | AllocationFailed
 
@@ -422,5 +429,10 @@ def try_allocate_registers_without_spilling(ops):
 
 
 def allocate_registers(ops):
-    # type: (list[Op]) -> None
-    raise NotImplementedError
+    # type: (list[Op]) -> dict[SSAVal, RegLoc]
+    retval = try_allocate_registers_without_spilling(ops)
+    if isinstance(retval, AllocationFailed):
+        # TODO: implement spilling
+        raise AllocationFailedError(
+            "spilling required but not yet implemented", retval)
+    return retval