Search in sources :

Example 71 with InstructionHandle

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

the class MethodCode method removeLineNumbers.

/**
     * Remove all line numbers.
     */
public void removeLineNumbers() {
    methodGen.removeLineNumbers();
    // TODO should we do something about the CFG?
    for (InstructionHandle ih : methodGen.getInstructionList().getInstructionHandles()) {
        ih.removeAttribute(KEY_SOURCECLASS);
        ih.removeAttribute(KEY_LINENUMBER);
    }
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 72 with InstructionHandle

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

the class KeyManager method clearAllValues.

public void clearAllValues(CustomKey key, ClassInfo classInfo) {
    boolean fromStruct = key.getType().isStruct();
    boolean fromCode = key.getType().isCode();
    if (fromStruct) {
        classInfo.removeCustomValue(key);
        for (FieldInfo field : classInfo.getFields()) {
            field.removeCustomValue(key);
        }
    }
    for (MethodInfo method : classInfo.getMethods()) {
        if (fromStruct) {
            method.removeCustomValue(key);
        }
        if (fromCode && method.hasCode()) {
            MethodCode code = method.getCode();
            InstructionList il = code.getInstructionList();
            for (InstructionHandle ih : il.getInstructionHandles()) {
                code.clearCustomKey(ih, key);
            }
        }
    }
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 73 with InstructionHandle

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

the class MethodCode method getNumberOfBytes.

/**
     * @see ProcessorModel#getNumberOfBytes(MethodInfo, Instruction) 
     * @param il the instruction list to get the size for
     * @return the number of bytes for a given instruction list on the target.
     */
public int getNumberOfBytes(InstructionList il) {
    int sum = 0;
    ProcessorModel pm = getAppInfo().getProcessorModel();
    for (InstructionHandle ih : il.getInstructionHandles()) {
        sum += pm.getNumberOfBytes(methodInfo, ih.getInstruction());
    }
    return sum;
}
Also used : ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 74 with InstructionHandle

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

the class ReplaceIinc method replace.

private void replace(MethodInfo method) {
    MethodCode mc = method.getCode();
    InstructionList il = mc.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    for (Iterator i = f.search("IINC"); i.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) i.next();
        InstructionHandle ih = match[0];
        IINC ii = (IINC) ih.getInstruction();
        int idx = ii.getIndex();
        int inc = ii.getIncrement();
        //  	    IINC rep = new IINC(idx, inc);
        ih.setInstruction(new ILOAD(idx));
        if (inc >= -1 && inc <= 5) {
            ih = il.append(ih, new ICONST(inc));
        } else if (inc >= -128 && inc < 127) {
            ih = il.append(ih, new BIPUSH((byte) inc));
        } else if (inc >= -32768 && inc < 32767) {
            ih = il.append(ih, new SIPUSH((short) inc));
        } else {
            System.out.println("IINC constant too big");
            System.exit(-1);
        }
        ih = il.append(ih, new IADD());
        ih = il.append(ih, new ISTORE(idx));
    }
    method.compile();
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionFinder(org.apache.bcel.util.InstructionFinder) BIPUSH(org.apache.bcel.generic.BIPUSH) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ISTORE(org.apache.bcel.generic.ISTORE) IINC(org.apache.bcel.generic.IINC) Iterator(java.util.Iterator) IADD(org.apache.bcel.generic.IADD) MethodCode(com.jopdesign.common.MethodCode) SIPUSH(org.apache.bcel.generic.SIPUSH) ICONST(org.apache.bcel.generic.ICONST)

Example 75 with InstructionHandle

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

the class DFATool method dumpDFA.

public String dumpDFA(MethodInfo method) {
    if (getLoopBounds() == null)
        return "n/a";
    if (method.isAbstract()) {
        return "n/a";
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream os = new PrintStream(baos);
    Map<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> results = getLoopBounds().getResult();
    if (results == null)
        return "n/a";
    AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>> printer = new AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>>();
    for (Entry<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> ihEntry : results.entrySet()) {
        for (Entry<CallString, Pair<ValueMapping, ValueMapping>> csEntry : ihEntry.getValue().entrySet()) {
            if (ihEntry.getValue().getContext().getMethodInfo().equals(method)) {
                printer.addResult(method, ihEntry.getKey().getPosition(), csEntry.getKey(), csEntry.getValue());
            }
        }
    }
    printer.dump(os);
    try {
        return baos.toString("UTF-8");
    } catch (UnsupportedEncodingException e) {
        return baos.toString();
    }
}
Also used : PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap) ValueMapping(com.jopdesign.dfa.analyses.ValueMapping) CallString(com.jopdesign.common.code.CallString) AnalysisResultSerialization(com.jopdesign.dfa.framework.AnalysisResultSerialization) Pair(com.jopdesign.common.graphutils.Pair)

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