예제 #1
0
  def regenerate_ir(self):
    """Regenerate Intermediate Representation by inserting phi instructions.
    """
    Instruction.reset_counter()

    new_ssa = []
    nodes_phi_ed = {}
    # Creates new instruction for every phi instruction and the old instruction.
    # Also creates a new CFG for the old CFG
    for instruction in self.ssa:
      node = self.label_nodes[instruction.label]


      # Generate phi instructions.
      if node not in nodes_phi_ed:
        for phi in node.phi_functions.values():
          new_instruction = Instruction('phi', phi['LHS'], *phi['RHS'])
          new_ssa.append(new_instruction)

        nodes_phi_ed[node] = True

      # Just regenerate the old instructions.
      new_instruction = Instruction(
          instruction.instruction, instruction.operand1, instruction.operand2)
      new_ssa.append(new_instruction)

      self.labels_ir_to_ssa[instruction.label] = new_instruction.label

    # FIXME: This may be a possible source of error, since this instruction
    # may be referring to the result of some 10 instructions before and
    # "phi" functions may have been inserted in between. First checkpoint
    # if bug appears.
    # Post processing to adjust all the instructions whose operands are
    # other instruction labels. We are doing a scan again because, we do
    # not know how branch instructions behave in the previous processing,
    # i.e. if "phi" instruction gets inserted anywhere in the future before
    # we regenerate the instruction to which this branch statement targets.
    for instruction in new_ssa:
      operand1 = instruction.operand1
      operand2 = instruction.operand2
      if isinstance(instruction.operand1, int):
        if operand1 in self.labels_ir_to_ssa:
          operand1 = self.labels_ir_to_ssa[operand1]
      if isinstance(instruction.operand2, int):
        if operand2 in self.labels_ir_to_ssa:
          operand2 = self.labels_ir_to_ssa[operand2]

      instruction.update(operand1=operand1, operand2=operand2)

    # Throw away old ssa copy, we don't want it anymore!
    self.ssa = new_ssa
예제 #2
0
 def __init__(self,node=None):
     Instruction.__init__(self)