ir: IRRegister: track registers (statefully)
This commit is contained in:
parent
fb62c3b34a
commit
6bbe2b195e
1 changed files with 9 additions and 1 deletions
|
|
@ -125,12 +125,20 @@ class IRAssignable(IRValue, metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
|
|
||||||
class IRRegister(IRAssignable):
|
class IRRegister(IRAssignable):
|
||||||
register_id = 0
|
register_id: int = 0
|
||||||
|
registers: dict[int, IRRegister] = {}
|
||||||
|
|
||||||
def __init__(self, location: SourceLocation):
|
def __init__(self, location: SourceLocation):
|
||||||
super().__init__(location)
|
super().__init__(location)
|
||||||
self.id = IRRegister.register_id
|
self.id = IRRegister.register_id
|
||||||
IRRegister.register_id += 1
|
IRRegister.register_id += 1
|
||||||
|
IRRegister.registers[self.id] = self
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return self.id
|
||||||
|
|
||||||
|
def remove(self):
|
||||||
|
del IRRegister.registers[self.id]
|
||||||
|
|
||||||
def codegen(self):
|
def codegen(self):
|
||||||
return f"%r{self.id}"
|
return f"%r{self.id}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue