Exemplo n.º 1
0
  private void insertCopy(TryCatchJoint joint) {
    Set<Variable> variableSet = new HashSet<>(joint.getSourceVariables());

    BasicBlock block = joint.getSource();
    DefinitionExtractor defExtractor = new DefinitionExtractor();
    for (int i = block.getInstructions().size() - 1; i >= 0; --i) {
      Instruction insn = block.getInstructions().get(i);
      insn.acceptVisitor(defExtractor);
      for (Variable definedVar : defExtractor.getDefinedVariables()) {
        if (variableSet.remove(definedVar)) {
          AssignInstruction copyInsn = new AssignInstruction();
          copyInsn.setReceiver(joint.getReceiver());
          copyInsn.setAssignee(definedVar);
          block.getInstructions().add(i, copyInsn);
        }
      }
    }

    for (Variable enteringVar : variableSet) {
      AssignInstruction copyInsn = new AssignInstruction();
      copyInsn.setReceiver(joint.getReceiver());
      copyInsn.setAssignee(enteringVar);
      block.getInstructions().add(0, copyInsn);
    }
  }
 public static boolean[] findEscapingVariables(Program program) {
   boolean[] escaping = new boolean[program.variableCount()];
   InstructionAnalyzer analyzer = new InstructionAnalyzer(escaping);
   for (int i = 0; i < program.basicBlockCount(); ++i) {
     BasicBlock block = program.basicBlockAt(i);
     for (Instruction insn : block) {
       insn.acceptVisitor(analyzer);
     }
   }
   return escaping;
 }