main: refactor IR printing
This commit is contained in:
parent
c29d4cd9ec
commit
5ed4c55522
1 changed files with 18 additions and 12 deletions
|
|
@ -53,21 +53,15 @@ def main():
|
||||||
context.check()
|
context.check()
|
||||||
|
|
||||||
intermediate_representation = ast.intermediate_representation()
|
intermediate_representation = ast.intermediate_representation()
|
||||||
|
pseudo_asm = [x.codegen() for x in intermediate_representation]
|
||||||
|
for i, action in enumerate(intermediate_representation):
|
||||||
|
|
||||||
messages = []
|
action.location.source = data
|
||||||
for ir_item in intermediate_representation:
|
|
||||||
ir_item.location.source = data
|
|
||||||
prefix = f"{str(ir_item.location) + ':':<30}"
|
|
||||||
source_info = ir_item.location.source_substring.splitlines(keepends=False)
|
|
||||||
messages += [f"# {prefix} {source_info.pop(0)}"]
|
|
||||||
while len(source_info) > 0:
|
|
||||||
messages += [f"# {' ' * len(prefix)} {source_info.pop(0)}"]
|
|
||||||
|
|
||||||
messages += [f"{repr(ir_item)}\n"]
|
|
||||||
|
|
||||||
print("\n".join(messages))
|
|
||||||
|
|
||||||
print("\n---\n", repr(context))
|
print("\n---\n", repr(context))
|
||||||
|
|
||||||
|
print_ir(intermediate_representation)
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -76,6 +70,18 @@ def main():
|
||||||
raise e.__cause__
|
raise e.__cause__
|
||||||
print(f"Caused by:\n{e.__cause__.__class__.__name__}: {e.__cause__}", file=sys.stderr)
|
print(f"Caused by:\n{e.__cause__.__class__.__name__}: {e.__cause__}", file=sys.stderr)
|
||||||
|
|
||||||
|
def print_ir(intermediate_representation: list[ir.IRAction]):
|
||||||
|
messages = []
|
||||||
|
for i, ir_item in enumerate(intermediate_representation):
|
||||||
|
prefix = f"{str(ir_item.location) + ':':<30}"
|
||||||
|
source_info = ir_item.location.source_substring.splitlines(keepends=False)
|
||||||
|
messages += [f"# {prefix} {source_info.pop(0)}"]
|
||||||
|
while len(source_info) > 0:
|
||||||
|
messages += [f"# {' ' * len(prefix)} {source_info.pop(0)}"]
|
||||||
|
|
||||||
|
messages += [f"{repr(ir_item)}\n"]
|
||||||
|
print("\n".join(messages))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue