Search in sources :

Example 61 with InstructionHandle

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

the class InstructionInterpreter method interpret.

public void interpret(boolean initialize) {
    InstructionList il = methodInfo.getCode().getInstructionList(true, false);
    InstructionHandle entry = il.getStart();
    Map<InstructionHandle, T> start = new HashMap<InstructionHandle, T>();
    start.put(entry, initialize ? analysis.initial(entry) : analysis.bottom());
    // start at exception handler entries too?
    if (startAtExceptionHandlers) {
        for (CodeExceptionGen eg : methodInfo.getCode().getExceptionHandlers()) {
            InstructionHandle ih = eg.getHandlerPC();
            start.put(ih, initialize ? analysis.initial(eg) : analysis.bottom());
        }
    }
    interpret(il, start, initialize);
}
Also used : RET(org.apache.bcel.generic.RET) HashMap(java.util.HashMap) InstructionList(org.apache.bcel.generic.InstructionList) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 62 with InstructionHandle

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

the class InstructionInterpreter method interpret.

public void interpret(InstructionHandle entry, boolean initialize) {
    // TODO we could use the CFG instead if it exists ?
    InstructionList il = methodInfo.getCode().getInstructionList(true, false);
    Map<InstructionHandle, T> start = new HashMap<InstructionHandle, T>(1);
    start.put(entry, initialize ? analysis.initial(entry) : analysis.bottom());
    interpret(il, start, initialize);
}
Also used : RET(org.apache.bcel.generic.RET) HashMap(java.util.HashMap) InstructionList(org.apache.bcel.generic.InstructionList) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 63 with InstructionHandle

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

the class BasicBlock method getTheInvokeInstruction.

/**
     * Get the invoke instruction of the basic block (which must be
     * the only instruction in the basic block)
     *
     * @return the invoke instruction, or <code>null</code>, if the basic block doesn't
     *         contain an invoke instruction or if it is a special invoke.
     * @throws ControlFlowGraph.ControlFlowError
     *          if there is more than one invoke instruction in the block.
     * @see ProcessorModel#isSpecialInvoke(MethodInfo, Instruction)
     */
public InstructionHandle getTheInvokeInstruction() {
    InstructionHandle theInvInstr = null;
    for (InstructionHandle ih : this.instructions) {
        if (!(ih.getInstruction() instanceof InvokeInstruction))
            continue;
        InvokeInstruction inv = (InvokeInstruction) ih.getInstruction();
        if (this.getAppInfo().getProcessorModel().isSpecialInvoke(methodCode.getMethodInfo(), inv)) {
            continue;
        }
        if (theInvInstr != null) {
            throw new ControlFlowGraph.ControlFlowError("More than one invoke instruction in a basic block");
        }
        theInvInstr = ih;
    }
    return theInvInstr;
}
Also used : InvokeInstruction(org.apache.bcel.generic.InvokeInstruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 64 with InstructionHandle

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

the class BasicBlock method getStartLine.

/**
     * @return a human readable string representation of the location of the first instruction
     * in the basic block
     */
public String getStartLine() {
    ClassInfo cls = null;
    int line = -1;
    for (InstructionHandle ih : instructions) {
        cls = methodCode.getSourceClassInfo(ih);
        line = methodCode.getLineNumber(this.getFirstInstruction());
        if (line >= 0)
            break;
    }
    if (line >= 0) {
        return cls.getSourceFileName() + ":" + line;
    } else {
        return getMethodInfo().getClassInfo().getSourceFileName() + ":" + getMethodInfo().getFQMethodName();
    }
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle) ClassInfo(com.jopdesign.common.ClassInfo)

Example 65 with InstructionHandle

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

the class BasicBlock method getSourceLines.

/**
     * @return all source code lines this basic block maps to
     */
public Map<ClassInfo, TreeSet<Integer>> getSourceLines() {
    Map<ClassInfo, TreeSet<Integer>> map = new HashMap<ClassInfo, TreeSet<Integer>>(2);
    for (InstructionHandle ih : instructions) {
        ClassInfo cls = methodCode.getSourceClassInfo(ih);
        TreeSet<Integer> lines = map.get(cls);
        if (lines == null) {
            lines = new TreeSet<Integer>();
            map.put(cls, lines);
        }
        int line = methodCode.getLineNumber(ih);
        if (line >= 0)
            lines.add(line);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

InstructionHandle (org.apache.bcel.generic.InstructionHandle)103 InstructionList (org.apache.bcel.generic.InstructionList)26 MethodInfo (com.jopdesign.common.MethodInfo)20 CallString (com.jopdesign.common.code.CallString)20 Instruction (org.apache.bcel.generic.Instruction)13 MethodCode (com.jopdesign.common.MethodCode)12 ContextMap (com.jopdesign.dfa.framework.ContextMap)11 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)11 Context (com.jopdesign.dfa.framework.Context)10 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)10 Iterator (java.util.Iterator)9 BranchInstruction (org.apache.bcel.generic.BranchInstruction)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)9 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)9 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)8 InstructionFinder (org.apache.bcel.util.InstructionFinder)8 ClassInfo (com.jopdesign.common.ClassInfo)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7