Search in sources :

Example 1 with JSR

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

the class InstructionInterpreter method getOutEdges.

private List<Edge> getOutEdges(InstructionHandle ih) {
    List<Edge> edges = new LinkedList<Edge>();
    Instruction instr = ih.getInstruction();
    if (instr instanceof BranchInstruction) {
        if (instr instanceof Select) {
            Select s = (Select) instr;
            InstructionHandle[] target = s.getTargets();
            for (InstructionHandle aTarget : target) {
                edges.add(new Edge(ih, aTarget, EdgeType.TRUE_EDGE));
            }
            edges.add(new Edge(ih, s.getTarget(), EdgeType.FALSE_EDGE));
        } else {
            BranchInstruction b = (BranchInstruction) instr;
            edges.add(new Edge(ih, b.getTarget(), EdgeType.TRUE_EDGE));
        }
    }
    // Check if we can fall through to the next instruction
    if (ih.getNext() != null && !(instr instanceof UnconditionalBranch || instr instanceof Select || instr instanceof ReturnInstruction)) {
        if (instr instanceof BranchInstruction) {
            edges.add(new Edge(ih, ih.getNext(), EdgeType.FALSE_EDGE));
        } else {
            edges.add(new Edge(ih, ih.getNext(), EdgeType.NORMAL_EDGE));
        }
    }
    if (instr instanceof ReturnInstruction) {
        edges.add(new Edge(ih, getExitInstruction(), EdgeType.EXIT_EDGE));
    }
    if (instr instanceof ATHROW) {
    // TODO should we handle this somehow? Insert edges to the exception handlers or to an return-by-exception
    // exit instruction?
    // for now, just ignore them
    }
    // but for now, we just ignore them too.. in a safe way :)
    if (instr instanceof RET || instr instanceof JSR || instr instanceof JSR_W) {
        throw new JavaClassFormatError("Unsupported instruction " + instr + " in " + methodInfo);
    }
    return edges;
}
Also used : RET(org.apache.bcel.generic.RET) UnconditionalBranch(org.apache.bcel.generic.UnconditionalBranch) BranchInstruction(org.apache.bcel.generic.BranchInstruction) JSR(org.apache.bcel.generic.JSR) ATHROW(org.apache.bcel.generic.ATHROW) BranchInstruction(org.apache.bcel.generic.BranchInstruction) Instruction(org.apache.bcel.generic.Instruction) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) LinkedList(java.util.LinkedList) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) Select(org.apache.bcel.generic.Select) JSR_W(org.apache.bcel.generic.JSR_W)

Aggregations

JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)1 LinkedList (java.util.LinkedList)1 ATHROW (org.apache.bcel.generic.ATHROW)1 BranchInstruction (org.apache.bcel.generic.BranchInstruction)1 Instruction (org.apache.bcel.generic.Instruction)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 JSR (org.apache.bcel.generic.JSR)1 JSR_W (org.apache.bcel.generic.JSR_W)1 RET (org.apache.bcel.generic.RET)1 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)1 Select (org.apache.bcel.generic.Select)1 UnconditionalBranch (org.apache.bcel.generic.UnconditionalBranch)1