main+ir: do register allocation + show updated register names

This commit is contained in:
Antoine Viallon 2024-01-05 23:37:56 +01:00
parent 3e59cc84a7
commit dfa24f2d67
Signed by: aviallon
GPG key ID: 186FC35EDEB25716
2 changed files with 13 additions and 0 deletions

View file

@ -63,8 +63,13 @@ def main():
print("\n---\n", repr(context)) print("\n---\n", repr(context))
register_alloc = optimizations.RegisterAllocation(intermediate_representation)
register_alloc.analyze()
print_ir(intermediate_representation) print_ir(intermediate_representation)
print(ir.IRRegister.get_registers())
except CompilationError as e: except CompilationError as e:
e.location.source = data e.location.source = data
print(f"{e}\n{e.location.show_in_source()}", file=sys.stderr) print(f"{e}\n{e.location.show_in_source()}", file=sys.stderr)

View file

@ -167,6 +167,14 @@ class IRRegister(IRAssignable):
return f"%r{self.real}" return f"%r{self.real}"
return f"%r{self.id}" return f"%r{self.id}"
@classmethod
def get_registers(cls) -> str:
messages = []
for register in cls.registers.values():
messages += [f"%r{register.id} -> {register.codegen()}"]
return "\n".join(messages)
class IRVariable(IRAssignable): class IRVariable(IRAssignable):
def __init__(self, location: SourceLocation, fq_identifier: str): def __init__(self, location: SourceLocation, fq_identifier: str):