Skip to content

Commit

Permalink
change text format for invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Dec 18, 2024
1 parent 192d82c commit 86c6a60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,11 @@ def __repr__(self) -> str:
opcode = f"{self.opcode} " if self.opcode != "store" else ""
s += opcode
operands = self.operands
if self.opcode not in ("jmp", "jnz", "invoke", "phi"):
# TODO: for invoke, maybe reverse the non-label instructions
if self.opcode == "invoke":
operands = [operands[0]] + list(reversed(operands[1:]))
elif self.opcode not in ("jmp", "jnz", "phi"):
operands = reversed(operands) # type: ignore

s += ", ".join([(f"@{op}" if isinstance(op, IRLabel) else str(op)) for op in operands])

if self.annotation:
Expand Down
8 changes: 6 additions & 2 deletions vyper/venom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ def instruction(self, children) -> IRInstruction:

# reverse operands, venom internally represents top of stack
# as rightmost operand
if opcode not in ("jmp", "jnz", "invoke", "phi"):
# special cases: operands with labels look better un-reversed
if opcode == "invoke":
# reverse stack arguments but not label arg
# invoke <target> <stack arguments>
operands = [operands[0]] + list(reversed(operands[1:]))
# special cases: operands with labels look better un-reversed
elif opcode not in ("jmp", "jnz", "phi"):
operands.reverse()
return IRInstruction(opcode, operands)

Expand Down

0 comments on commit 86c6a60

Please sign in to comment.