示例#1
0
  public void removePhiFuncVariable(String origName, String varName) {
    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (0 == phiFunc.getVariable().getName().compareTo(origName)) {
        __debugPrintln("Removing Phi Func ref: " + origName + " to " + varName);

        phiFunc.deleteVariable(varName);
      }
    }
  }
示例#2
0
  public boolean isConstPhiFunc(String strName) {
    boolean bRet = false;

    for (int i = 0; !bRet && i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (0 == phiFunc.getName().compareTo(strName)) {
        if (phiFunc.isConst()) bRet = true;
      }
    }

    return bRet;
  }
示例#3
0
  // Updates this block's Phi Function
  public void updatePhiFunction(Argument arg, Symbol sym) {
    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (0 == phiFunc.getVariable().getName().compareTo(arg.getOrigName())) {
        __debugPrintln("Updating Phi Func: " + arg.getOrigName() + " to " + sym.getIntegerValue());

        phiFunc.updateVariable(arg.getName(), new Symbol(sym));

        break;
      }
    }
  }
示例#4
0
  public int getPhiFunctionConstValue(String strName) {
    int nRet = 0;

    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (0 == phiFunc.getVariable().getName().compareTo(strName)) {
        if (phiFunc.isConst()) {
          nRet = phiFunc.getConstValue();
          break;
        }
      }
    }

    return nRet;
  }
示例#5
0
  public void updatePhiFunctionCurName(String strCurName, Symbol sym) {
    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (phiFunc.varInMergeList(strCurName)) {
        __debugPrintln(
            "Updating Phi Func: "
                + phiFunc.getVariable().getName()
                + " to "
                + sym.getIntegerValue());

        phiFunc.updateVariable(strCurName, new Symbol(sym));

        break;
      }
    }
  }
示例#6
0
  private void search(BasicBlock X) {

    for (Statement stmt : X.getStatements()) {
      Expression rhs = stmt.getRHS();
      if (!(rhs instanceof PhiFunction)) {
        for (Variable V : rhs.variables()) {
          int i = Top(V);
          rhs = rhs.replaceVariable(V, new SsaVariable(V, i));
        }
        stmt = X.replaceStatement(stmt, stmt.withRHS(rhs));
      }

      if (stmt instanceof Assignment) {
        Assignment assignment = (Assignment) stmt;
        if (assignment.getLHS() instanceof Variable) {
          Variable V = (Variable) assignment.getLHS();
          int i = C.get(V);
          X.replaceStatement(assignment, assignment.withLHS(new SsaVariable(V, i)));
          S.get(V).push(i);
          C.put(V, i + 1);
        }
      }
    }

    for (BasicBlock Y : cfg.getSuccessors(X)) {
      int j = whichPred(Y, X);
      for (Assignment A : Lists.newArrayList(Y.phiAssignments())) {
        PhiFunction rhs = (PhiFunction) A.getRHS();
        Variable V = rhs.getArgument(j);
        int i = Top(V);
        rhs = rhs.replaceVariable(j, i);
        Y.replaceStatement(A, new Assignment(A.getLHS(), rhs));
        // replace the j-th operand V in RHS(F) by V_i where i = Top(S(V))
      }
    }
    for (BasicBlock Y : dtree.getChildren(X)) {
      search(Y);
    }
    for (Assignment A : X.assignments()) {
      if (A.getLHS() instanceof SsaVariable) {
        SsaVariable lhs = (SsaVariable) A.getLHS();
        S.get(lhs.getInner()).pop();
      }
    }
  }
示例#7
0
  public Symbol getPhiFunctionSymbol(String strName) {
    Symbol symRet = null;

    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (0 == phiFunc.getVariable().getName().compareTo(strName)) {
        __debugPrintln("Found Symbol for " + strName);
        symRet =
            new Symbol(
                "" + phiFunc.getConstValue(), Symbol.SymbolType.CONSTANT, Symbol.DataType.INTEGER);
        symRet.setIntegerValue(phiFunc.getConstValue());
        break;
      }
    }

    return symRet;
  }
示例#8
0
  public PhiFunction getPhiFunctionMatchingCurName(String strCurName) {
    PhiFunction ret = null;

    for (int i = 0; i < getPhiFunctions().size(); i++) {
      PhiFunction phiFunc = getPhiFunctions().get(i);

      if (phiFunc.varInMergeList(strCurName)) {
        __debugPrintln(
            "Found Phi Func : " + phiFunc.getVariable().getName() + " matching " + strCurName);

        ret = phiFunc;

        break;
      }
    }

    return ret;
  }