ir: better register shrinkage pretty printing
This commit is contained in:
parent
37bfd831f4
commit
a98f38d43f
2 changed files with 10 additions and 4 deletions
|
|
@ -77,7 +77,7 @@ def main():
|
||||||
|
|
||||||
intermediate_representation.pretty_print()
|
intermediate_representation.pretty_print()
|
||||||
|
|
||||||
print(ir.IRRegister.get_registers())
|
ir.IRRegister.pprint()
|
||||||
|
|
||||||
except CompilationError as e:
|
except CompilationError as e:
|
||||||
e.location.source = tokens.data
|
e.location.source = tokens.data
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
import collections
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from . import nodes
|
from . import nodes
|
||||||
|
|
@ -169,12 +170,17 @@ class IRRegister(IRAssignable):
|
||||||
return f"%r{self.id}"
|
return f"%r{self.id}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_registers(cls) -> str:
|
def pprint(cls):
|
||||||
messages = []
|
messages = []
|
||||||
|
by_codegen = collections.defaultdict(lambda: [])
|
||||||
for register in cls.registers.values():
|
for register in cls.registers.values():
|
||||||
messages += [f"%r{register.id} -> {register.codegen()}"]
|
by_codegen[register.codegen()] += [register.id]
|
||||||
|
|
||||||
return "\n".join(messages)
|
for remapped_name, registers in by_codegen.items():
|
||||||
|
register_names = (f"%r{register}" for register in registers)
|
||||||
|
messages += [f"Remapped {', '.join(register_names)} to {remapped_name}"]
|
||||||
|
|
||||||
|
print("\n".join(messages))
|
||||||
|
|
||||||
|
|
||||||
class IRVariable(IRAssignable):
|
class IRVariable(IRAssignable):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue