Skip to content

Commit

Permalink
refactor[venom]: update translator for deploy instruction (#4318)
Browse files Browse the repository at this point in the history
this commit updates `ir_node_to_venom.py` for the `deploy` instruction
to properly emit the `exit` instruction. it also removes places in the
translator where the `exit` instruction was improperly emitted.

misc:
- update style to continue early in the loop rather than nest.
  • Loading branch information
charles-cooper authored Oct 29, 2024
1 parent 063f190 commit 3fba8c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 12 additions & 10 deletions vyper/venom/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,19 @@ def chain_basic_blocks(self) -> None:
"""
bbs = list(self.get_basic_blocks())
for i, bb in enumerate(bbs):
if not bb.is_terminated:
if i < len(bbs) - 1:
# TODO: revisit this. When contructor calls internal functions they
# are linked to the last ctor block. Should separate them before this
# so we don't have to handle this here
if bbs[i + 1].label.value.startswith("internal"):
bb.append_instruction("stop")
else:
bb.append_instruction("jmp", bbs[i + 1].label)
if bb.is_terminated:
continue

if i < len(bbs) - 1:
# TODO: revisit this. When contructor calls internal functions
# they are linked to the last ctor block. Should separate them
# before this so we don't have to handle this here
if bbs[i + 1].label.value.startswith("internal"):
bb.append_instruction("stop")
else:
bb.append_instruction("exit")
bb.append_instruction("jmp", bbs[i + 1].label)
else:
bb.append_instruction("stop")

def copy(self):
new = IRFunction(self.name)
Expand Down
6 changes: 2 additions & 4 deletions vyper/venom/ir_node_to_venom.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def _convert_ir_bb(fn, ir, symbols):
elif ir.value == "deploy":
ctx.ctor_mem_size = ir.args[0].value
ctx.immutables_len = ir.args[2].value
fn.get_basic_block().append_instruction("exit")
return None
elif ir.value == "seq":
if len(ir.args) == 0:
Expand Down Expand Up @@ -398,10 +399,7 @@ def _convert_ir_bb(fn, ir, symbols):
bb = IRBasicBlock(label, fn)
fn.append_basic_block(bb)
code = ir.args[2]
if code.value == "pass":
bb.append_instruction("exit")
else:
_convert_ir_bb(fn, code, symbols)
_convert_ir_bb(fn, code, symbols)
elif ir.value == "exit_to":
args = _convert_ir_bb_list(fn, ir.args[1:], symbols)
var_list = args
Expand Down

0 comments on commit 3fba8c7

Please sign in to comment.