Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TAC function parameter names #171

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions clients/visualizeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def emit(s: str, out: TextIO, indent: int=0):
print(f'{indent*INDENT_BASE}{s}', file=out)


def emit_stmt(stmt: Statement, out: TextIO):
def render_var(var: str):
if var in tac_variable_value:
return f"v{var.replace('0x', '')}({tac_variable_value[var]})"
else:
return f"v{var.replace('0x', '')}"
def render_var(var: str):
if var in tac_variable_value:
return f"v{var.replace('0x', '')}({tac_variable_value[var]})"
else:
return f"v{var.replace('0x', '')}"


def emit_stmt(stmt: Statement, out: TextIO):
defs = [render_var(v) for v in stmt.defs]
uses = [render_var(v) for v in stmt.operands]

Expand Down Expand Up @@ -55,7 +56,8 @@ def pretty_print_block(block: Block, visited: Set[str], out: TextIO):
def pretty_print_tac(functions: Mapping[str, Function], out: TextIO):
for function in sorted(functions.values(), key=lambda x: x.ident):
visibility = 'public' if function.is_public else 'private'
emit(f"function {function.name}({', '.join(function.formals)}) {visibility} {{", out)
formals = [render_var(v) for v in function.formals]
emit(f"function {function.name}({', '.join(formals)}) {visibility} {{", out)
pretty_print_block(function.head_block, set(), out)

emit("}", out)
Expand Down
Loading