Examples of AbstractIntermediate


Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

    }
    NewConstantArrayInstance ncai = (NewConstantArrayInstance)declaration.getAssignment().getRightHandSide();
    Expression countExpression = ncai.getCount();
   
   
    AbstractIntermediate current = line;
    Map<Integer, Expression> values = new HashMap<Integer, Expression>();
    collectConstantAssignments(current, values);
   
    //create a new array...
    Integer count = toInteger(countExpression);
    List<Expression> expressions = new ArrayList<Expression>(count);
    for(int i=0, j=count; i<j; i++) {
      Expression exp = null;
      if(values.containsKey(i)) {
        exp = values.get(i);
      }
      else {
        exp = new Resolved(ncai.getInstructionHandle(), Type.NULL, "null");
      }
      expressions.add(i, exp);
    }
   
   
    //ok, we have the stack... now we need to just create a new expression.

    //create the contant...
    ConstantArray constantArray = new ConstantArray(declaration.getAssignment().getRightHandSide().getInstructionHandle(), expressions);
    declaration.getAssignment().setRightHandSide(constantArray);
   
   
    //excellent.  we have reordered the statements into the appropriate ContantArray assignment.  Now, we need to remove the dead nodes and heal the graph.
    AbstractIntermediate next = Graphs.successorListOf(igc.getGraph(), line).get(0);
   
    //loop through the dead elements...
    //we know the number of dead items is equal to the number of values we found.
    healGraph(line, next, values.size());
  }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

      if(i+1 == j) {
        igc.redirectPredecessors(current, next);
      }
     
     
      AbstractIntermediate temp = null;
      //move back..
      List<AbstractIntermediate> predecessor = Graphs.predecessorListOf(igc.getGraph(), current);
      if(predecessor.size() > 0) {
        temp = predecessor.get(0);
      }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

  @Override
  public Map<String, String> getComponentAttributes(IntermediateEdge edge) {
    Map<String, String> attributes = new HashMap<String, String>();
   
    AbstractIntermediate source = (AbstractIntermediate)edge.getSource();
    AbstractIntermediate target = (AbstractIntermediate)edge.getTarget();
   
    if(source instanceof TryIntermediate && (target instanceof CatchIntermediate || target instanceof FinallyIntermediate)) {
      attributes.put("style", "dashed");
    }
   
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

    visitIfIntermediate(line);
  }
 
  @Override
  public void visitIfIntermediate(IfIntermediate line) {
    AbstractIntermediate l = igc.getTrueTarget(line);
    InstructionHandle lower = l.getInstruction();
    line.getBlockRange().setStart(lower);
   
    //upper range...
    AbstractIntermediate u = igc.getFalseTarget(line);
    NullIntermediate nullIntermediate = new NullIntermediate(u.getInstruction().getPrev());
    AbstractIntermediate ai = igc.getOrderedIntermediate().floor(nullIntermediate);

    if(ai != null) {
      line.getBlockRange().setEnd(ai.getInstruction());
    }
   
  }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

   
    //now, add the edge between end of FINALLY and the next statement.
    InstructionHandle finallyEnd = line.getBlockRange().getEnd();
    //get the next.. then search for next node in graph.
   
    AbstractIntermediate finallyLast = igc.findNextNode(finallyEnd);
    AbstractIntermediate afterFinally = igc.findNextNode(finallyEnd.getNext());
   
    igc.redirectPredecessors(finallyLast, afterFinally);
    igc.getGraph().removeVertex(finallyLast);
  }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

 
  protected void processTry(TryIntermediate tryIntermediate, FinallyIntermediate finallyIntermediate, Set<Integer> offsets) {
    //ok, now let's handle the try...
    InstructionHandle end = tryIntermediate.getBlockRange().getEnd();
    //next should be GOTO.
    AbstractIntermediate tryEndNode = igc.findNextNode(end);
   
    AbstractIntermediate gotoIntermediate = null;
    //check to see if this is loop...
    if(tryEndNode instanceof StatementIntermediate) {
      LOG.debug("Position: "+tryEndNode.getInstruction().getPosition()+" Value: "+tryEndNode);
      gotoIntermediate = igc.getSingleSuccessor(tryEndNode);
    }
    else if(tryEndNode instanceof BooleanBranchIntermediate) {
      BooleanBranchIntermediate bbi = (BooleanBranchIntermediate)tryEndNode;
     
      //find higher target...
      AbstractIntermediate trueTarget = igc.getTrueTarget(bbi);
      AbstractIntermediate falseTarget = igc.getFalseTarget(bbi);
     
      int trueTargetPosition = trueTarget.getInstruction().getPosition();
      int falseTargetPosition = falseTarget.getInstruction().getPosition();
     
      gotoIntermediate = (trueTargetPosition > falseTargetPosition) ? trueTarget : falseTarget;
    }
   
    //validate it is a GOTO.
    if(!(gotoIntermediate instanceof GoToIntermediate)) {
      LOG.warn("Expected GOTO.  But this isn't: "+gotoIntermediate);
    }
    else {
      AbstractIntermediate tryFinallyFirst = igc.getSingleSuccessor(gotoIntermediate);
      eliminateNode(tryFinallyFirst, offsets);
     
      //now, eliminate the GOTO.
      igc.getGraph().removeVertex(gotoIntermediate);
      igc.getGraph().addEdge(tryIntermediate, finallyIntermediate);
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

      int position = ceg.getEndPC().getPosition();
      if(catchIntermediate.getBlockRange().containsNumber(position))  {
        LOG.debug("Relevant: "+position);
       
        //we found the relevant position, now we need to find the next...
        AbstractIntermediate lastNode = igc.findNextNode(ceg.getEndPC());
       
        AbstractIntermediate finallyStart = igc.getSingleSuccessor(lastNode);
        LOG.debug("Finally start: "+finallyStart);
       
        //start eliminating nodes from this point.
        eliminateNode(finallyStart, offsets);
      }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

   
  }
 
  protected Set<Integer> collectOffsets(AbstractIntermediate line) {
    //this is the finally template.
    AbstractIntermediate first = igc.getSingleSuccessor(line);
    //now, store the instruction position.
    int position = first.getInstruction().getPosition();
   
    BreadthFirstIterator<AbstractIntermediate, IntermediateEdge> bfi = new BreadthFirstIterator<AbstractIntermediate, IntermediateEdge>(igc.getGraph(), first);
   
    Set<Integer> offsets = new TreeSet<Integer>();
    while(bfi.hasNext()) {
      AbstractIntermediate next = bfi.next();
      int nextPosition = next.getInstruction().getPosition();
     
      int offset = nextPosition - position;
      LOG.debug("Offset: "+offset);
      offsets.add(offset);
    }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

        LOG.warn("Not found expected InstructionHandle: "+(position+offset));
        continue;
      }
     
      //loop through...
      AbstractIntermediate ai = igc.findNextNode(ih);
      if(ai.getInstruction().getPosition() == target) {
        igc.getGraph().removeVertex(ai);
      }
      else {
        LOG.warn("Did not find vertex: "+target);
      }
View Full Code Here

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate

  }

  @Override
  public void visitForIntermediate(ForIntermediate line) {
    //we need to look at the previous 2 statements and the first statement child.
    AbstractIntermediate arrayLenthCandidate = getForExteriorPredecessor(line);
   
    //check that the array length candidate's declared length variable is used in the for's condition.
   
    AbstractIntermediate tempArrayCandidate = null;
    AbstractIntermediate firstChild = igc.getTrueTarget(line);
   
    if(arrayLenthCandidate != null) {
      tempArrayCandidate = getSinglePredecessor(arrayLenthCandidate);
    }

    //if either of these are null, then this doesn't match.
    if(arrayLenthCandidate == null || tempArrayCandidate == null) {
      return;
    }
   
    GeneratedVariable generatedArrayLength = extractGeneratedVariableDeclaration(arrayLenthCandidate);
    GeneratedVariable generatedArrayReference = extractGeneratedVariableDeclaration(tempArrayCandidate);
    GeneratedVariable arrayIteratorValue = extractGeneratedVariableDeclaration(line.getInit());
   
    if(generatedArrayLength == null || generatedArrayReference == null || arrayIteratorValue == null) {
      return;
    }
   
    //now validate the types.  array length should be an integer.  the array reference, well, should be an array ;)
    //the iterator should be an integer.

    if(generatedArrayLength.getType() != Type.INT) {
     
      if(!(generatedArrayReference.getType() instanceof ArrayType)) {
        return;
      }
     
      if(arrayIteratorValue.getType() != Type.INT) {
        return;
      }
    }
   
    //great; at this point we know the pattern matches.  check the next statement to see if the transformation is possible.
    //format should be: 40 : GENERATED_ARRAY_REFERENCE_TYPE i = GENERATED_ARRAY_REFERENCE[ARRAY_ITERATOR_VALUE] |
    StatementIntermediate childDeclarationStatement = ((StatementIntermediate)firstChild);
    Declaration childDeclaration = (Declaration)childDeclarationStatement.getExpression();
   
    if(firstMatchesGeneratedVariables(childDeclarationStatement, generatedArrayReference, arrayIteratorValue)) {
     
      LOG.debug("Likely a enhanced for loop for array: "+generatedArrayLength + " , "+ generatedArrayReference);
     
      //we are good to go here.  Now we just need to reorganize the graph.  Start by creating the new enhanced for loop.
      EnhancedForIntermediate efl = new EnhancedForIntermediate(line.getInstruction(), line.getConditionalIntermediate(), childDeclaration.getVariable(), extractExpressionFromGeneratedArrayAssignment(tempArrayCandidate));
      //efl.setTrueBranch(line.getTrueBranch());
      //efl.setFalseBranch(line.getFalseBranch());
      //add the new node...
      this.igc.getGraph().addVertex(efl);
     
      //now, we just need to redirect.
      igc.redirectPredecessors(tempArrayCandidate, efl);
      igc.redirectPredecessors(line, efl);
      igc.redirectSuccessors(line, efl);
     
      AbstractIntermediate nextChild = getSingleSuccessor(firstChild);
      igc.redirectPredecessors(firstChild, nextChild);
     
      //remove line.
      igc.getGraph().removeVertex(line);
      igc.getGraph().removeVertex(tempArrayCandidate);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.