"""
from itertools import combinations
-from typing import TYPE_CHECKING, Generic, Iterable, Mapping, TypeVar
+from typing import Generic, Iterable, Mapping, TypeVar
from nmutil.plain_data import plain_data
from bigint_presentation_code.compiler_ir import (GPRRangeType, Op, RegClass,
RegLoc, RegType, SSAVal)
-from bigint_presentation_code.ordered_set import OFSet, OSet
-
-if TYPE_CHECKING:
- from typing_extensions import final
-else:
- def final(v):
- return v
-
+from bigint_presentation_code.type_util import final
+from bigint_presentation_code.util import OFSet, OSet
_RegType = TypeVar("_RegType", bound=RegType)
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
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