def pause_writing(self, args_gv): log('%s Builder.pause_writing' % self.block.label) assert self.asm is not None self.nextlabel = count.newlabel() # for the next block self.asm.append(' br label %%%s' % (self.nextlabel,)) self.asm = None return self
def jump_if_true(self, gv_condition, args_for_jump_gv): log('%s Builder.jump_if_true %s' % (self.block.label, gv_condition.operand())) targetbuilder = self._fork() self.nextlabel = count.newlabel() self.asm.append(' br %s,label %%%s,label %%%s' % ( gv_condition.operand(), targetbuilder.nextlabel, self.nextlabel)) self.start_writing() return targetbuilder
def add_incoming_link(self, sourceblock, sourcevars): # check the types for debugging sourcevartypes = [var.type for var in sourcevars] targetvartypes = [var.type for var in self.inputargs] if sourcevartypes != targetvartypes: logger.dump('assert fails on: sourcevartypes(%s) != targetvartypes(%s)' % ( sourcevartypes, targetvartypes)) self.rgenop._dump_partial_lines() assert sourcevartypes == targetvartypes # Check if the source block jumps to 'self' from multiple # positions: in this case we need an intermediate block... if sourceblock in self.phinodes: tmplabel = count.newlabel() tmpblock = BasicBlock(self.rgenop, tmplabel, targetvartypes) tmpblock.add_incoming_link(sourceblock, sourcevars) sourceblock = tmpblock sourcevars = tmpblock.inputargs # Add this source for the phi nodes self.phinodes[sourceblock] = list(sourcevars)
def enter_next_block(self, kinds, args_gv): assert self.nextlabel is None coming_from = self.block newlabel = count.newlabel() # we still need to properly terminate the current block # (with a br to go to the next block) # see: http://llvm.org/docs/LangRef.html#terminators self.asm.append(' br label %%%s' % (newlabel,)) # prepare the next block nextblock = BasicBlock(self.rgenop, newlabel, kinds) log('%s Builder enter block %s' % ( nextblock.label, [v.operand() for v in nextblock.inputargs])) self.block = nextblock self.asm = nextblock.asm # link the two blocks together and update args_gv nextblock.add_incoming_link(coming_from, args_gv) for i in range(len(args_gv)): args_gv[i] = nextblock.inputargs[i] return self.block
def __init__(self, rgenop, coming_from): self.rgenop = rgenop self.nextlabel = count.newlabel() # the label of the next block self.block = coming_from # the old block that jumped here