Skip to content

Commit

Permalink
Refactor basic block instruction appending names
Browse files Browse the repository at this point in the history
adopted a shorted name for frequently used methods
  • Loading branch information
harkal committed Dec 8, 2023
1 parent 3b093dd commit 73628df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ class IRBasicBlock:
%2 = mul %1, 2
is represented as:
bb = IRBasicBlock("bb", function)
r1 = bb.add_instruction("add", "%0", "1")
r2 = bb.add_instruction("mul", r1, "2")
r1 = bb.append_inst("add", "%0", "1")
r2 = bb.append_inst("mul", r1, "2")
The label of a basic block is used to refer to it from other basic blocks
in order to branch to it.
Expand Down Expand Up @@ -296,19 +296,16 @@ def remove_cfg_out(self, bb: "IRBasicBlock") -> None:
def is_reachable(self) -> bool:
return len(self.cfg_in) > 0

def _append_instruction(self, instruction: IRInstruction) -> None:
assert isinstance(instruction, IRInstruction), "instruction must be an IRInstruction"
instruction.parent = self
self.instructions.append(instruction)

def add_instruction_no_return(self, opcode: str, *args) -> None:
def append_inst_no_ret(self, opcode: str, *args) -> None:
inst = IRInstruction(opcode, list(args))
self._append_instruction(inst)
inst.parent = self
self.instructions.append(inst)

def add_instruction(self, opcode: str, *args) -> IRVariable:
def append_inst(self, opcode: str, *args) -> IRVariable:
ret = self.parent.get_next_variable()
inst = IRInstruction(opcode, list(args), ret)
self._append_instruction(inst)
inst.parent = self
self.instructions.append(inst)
return ret

def insert_instruction(self, instruction: IRInstruction, index: int) -> None:
Expand Down
2 changes: 1 addition & 1 deletion vyper/venom/passes/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _insert_split_basicblock(self, bb: IRBasicBlock, in_bb: IRBasicBlock) -> IRB
source = in_bb.label.value
target = bb.label.value
split_bb = IRBasicBlock(IRLabel(f"{target}_split_{source}"), self.ctx)
split_bb.add_instruction_no_return("jmp", bb.label)
split_bb.append_inst_no_ret("jmp", bb.label)
self.ctx.append_basic_block(split_bb)

# Rewire the CFG
Expand Down

0 comments on commit 73628df

Please sign in to comment.