Search in sources :

Example 1 with CodeExceptionGen

use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.

the class InstructionInterpreter method interpret.

private void interpret(InstructionList il, Map<InstructionHandle, T> start, boolean initialize) {
    if (initialize) {
        InstructionHandle ih = il.getStart();
        // set initial value for all instructions
        while (ih != null) {
            results.put(ih, analysis.bottom());
            ih = ih.getNext();
        }
        results.putAll(start);
    } else {
        // Set initial values for new instructions
        for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
            if (results.containsKey(ih))
                continue;
            if (ih.getPrev() == null) {
                // entry instruction, must always be merged with the initial state once, even
                // if this has an ingoing edge
                results.put(ih, analysis.initial(ih));
            } else {
                results.put(ih, analysis.bottom());
                // check for exception handler entry
                if (ih.hasTargeters()) {
                    for (InstructionTargeter targeter : ih.getTargeters()) {
                        if (targeter instanceof CodeExceptionGen && ((CodeExceptionGen) targeter).getHandlerPC().equals(ih)) {
                            results.put(ih, analysis.initial((CodeExceptionGen) targeter));
                            break;
                        }
                    }
                }
            }
        }
    }
    LinkedList<Edge> worklist = new LinkedList<Edge>();
    // setup the worklist
    for (InstructionHandle ih : start.keySet()) {
        if (initialize) {
            // when initializing, we start from the initial values, not from ingoing edges
            worklist.addAll(getOutEdges(ih));
        } else {
            // we continue from existing results
            List<Edge> inEdges = getInEdges(il, ih);
            if (inEdges.isEmpty()) {
                // entry instruction without ingoing edges, nothing to continue from
                worklist.addAll(getOutEdges(ih));
            } else {
                worklist.addAll(inEdges);
            }
        }
    }
    while (!worklist.isEmpty()) {
        Edge edge = worklist.removeFirst();
        InstructionHandle tail = edge.getTail();
        InstructionHandle head = edge.getHead();
        T tailValue = results.get(tail);
        T headValue = results.get(head);
        T transferred = analysis.transfer(tailValue, edge);
        if (!analysis.compare(transferred, headValue)) {
            T newValue = analysis.join(transferred, headValue);
            results.put(head, newValue);
            if (edge.getType() == EdgeType.EXIT_EDGE) {
                continue;
            }
            List<Edge> outEdges = getOutEdges(head);
            for (Edge outEdge : outEdges) {
                if (worklist.contains(outEdge)) {
                    continue;
                }
                if (outEdges.size() > 1) {
                    worklist.addLast(outEdge);
                } else {
                    worklist.addFirst(outEdge);
                }
            }
        }
    }
}
Also used : RET(org.apache.bcel.generic.RET) InstructionTargeter(org.apache.bcel.generic.InstructionTargeter) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedList(java.util.LinkedList)

Example 2 with CodeExceptionGen

use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.

the class MethodCode method getEndingExceptionRanges.

public List<CodeExceptionGen> getEndingExceptionRanges(InstructionHandle ih) {
    List<CodeExceptionGen> list = new ArrayList<CodeExceptionGen>();
    InstructionTargeter[] targeters = ih.getTargeters();
    if (targeters == null)
        return list;
    for (InstructionTargeter t : targeters) {
        if (t instanceof CodeExceptionGen) {
            CodeExceptionGen ceg = (CodeExceptionGen) t;
            if (ceg.getEndPC().equals(ih)) {
                list.add(ceg);
            }
        }
    }
    return list;
}
Also used : InstructionTargeter(org.apache.bcel.generic.InstructionTargeter) ArrayList(java.util.ArrayList) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen)

Example 3 with CodeExceptionGen

use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.

the class RetractDuplicateFinally method processCatch.

protected void processCatch(CatchIntermediate catchIntermediate, FinallyIntermediate finallyIntermediate, Set<Integer> offsets) {
    for (CodeExceptionGen ceg : finallyIntermediate.getCodeExceptions()) {
        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);
        }
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen)

Example 4 with CodeExceptionGen

use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.

the class FinallyIntermediate method toString.

@Override
public String toString() {
    StringWriter sw = new StringWriter();
    sw.append("Finally");
    for (CodeExceptionGen ceg : codeExceptions) {
        sw.append(" | Handler[" + ceg.getStartPC().getPosition() + ", " + ceg.getEndPC().getPosition() + "]");
    }
    return sw.toString() + ";";
}
Also used : StringWriter(java.io.StringWriter) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen)

Example 5 with CodeExceptionGen

use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.

the class InstructionTryCatch method process.

public void process() {
    Map<InstructionRange, List<CodeExceptionGen>> tryRangeGen = new HashMap<InstructionRange, List<CodeExceptionGen>>();
    //create try statements...
    for (CodeExceptionGen ceg : exceptions) {
        InstructionHandle min = (ceg.getStartPC());
        InstructionHandle max = (ceg.getEndPC());
        InstructionRange tryRange = new InstructionRange();
        tryRange.setStart(min);
        tryRange.setEnd(max);
        //SKIP THE FINALLY
        if (ceg.getCatchType() == null) {
            continue;
        }
        if (!tryRangeGen.containsKey(tryRange)) {
            tryRangeGen.put(tryRange, new LinkedList<CodeExceptionGen>());
        }
        tryRangeGen.get(tryRange).add(ceg);
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) InstructionRange(org.candle.decompiler.instruction.InstructionRange)

Aggregations

CodeExceptionGen (org.apache.bcel.generic.CodeExceptionGen)12 InstructionHandle (org.apache.bcel.generic.InstructionHandle)6 HashMap (java.util.HashMap)4 InstructionTargeter (org.apache.bcel.generic.InstructionTargeter)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)2 InstructionList (org.apache.bcel.generic.InstructionList)2 RET (org.apache.bcel.generic.RET)2 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2 MethodCode (com.jopdesign.common.MethodCode)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 Constant (org.apache.bcel.classfile.Constant)1 CPInstruction (org.apache.bcel.generic.CPInstruction)1 LineNumberGen (org.apache.bcel.generic.LineNumberGen)1 LocalVariableGen (org.apache.bcel.generic.LocalVariableGen)1 MethodGen (org.apache.bcel.generic.MethodGen)1