forked from M-Labs/artiq
compiler.ir: print basic blocks in reverse postorder for readability.
This commit is contained in:
parent
c73b2c1a78
commit
d92b3434a0
|
@ -463,12 +463,23 @@ class Function:
|
||||||
yield from iter(basic_block.instructions)
|
yield from iter(basic_block.instructions)
|
||||||
|
|
||||||
def as_entity(self, type_printer):
|
def as_entity(self, type_printer):
|
||||||
|
postorder = []
|
||||||
|
visited = set()
|
||||||
|
def visit(block):
|
||||||
|
visited.add(block)
|
||||||
|
for next_block in block.successors():
|
||||||
|
if next_block not in visited:
|
||||||
|
visit(next_block)
|
||||||
|
postorder.append(block)
|
||||||
|
|
||||||
|
visit(self.entry())
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
lines.append("{} {}({}) {{ ; type: {}".format(
|
lines.append("{} {}({}) {{ ; type: {}".format(
|
||||||
type_printer.name(self.type.ret), self.name,
|
type_printer.name(self.type.ret), self.name,
|
||||||
", ".join([arg.as_operand(type_printer) for arg in self.arguments]),
|
", ".join([arg.as_operand(type_printer) for arg in self.arguments]),
|
||||||
type_printer.name(self.type)))
|
type_printer.name(self.type)))
|
||||||
for block in self.basic_blocks:
|
for block in reversed(postorder):
|
||||||
lines.append(block.as_entity(type_printer))
|
lines.append(block.as_entity(type_printer))
|
||||||
lines.append("}")
|
lines.append("}")
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
Loading…
Reference in New Issue