main+ir: do register allocation + show updated register names
This commit is contained in:
parent
3e59cc84a7
commit
dfa24f2d67
2 changed files with 13 additions and 0 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue