Search in sources :

Example 1 with ISTORE

use of org.apache.bcel.generic.ISTORE 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)

Aggregations

MethodCode (com.jopdesign.common.MethodCode)1 Iterator (java.util.Iterator)1 BIPUSH (org.apache.bcel.generic.BIPUSH)1 IADD (org.apache.bcel.generic.IADD)1 ICONST (org.apache.bcel.generic.ICONST)1 IINC (org.apache.bcel.generic.IINC)1 ILOAD (org.apache.bcel.generic.ILOAD)1 ISTORE (org.apache.bcel.generic.ISTORE)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 InstructionList (org.apache.bcel.generic.InstructionList)1 SIPUSH (org.apache.bcel.generic.SIPUSH)1 InstructionFinder (org.apache.bcel.util.InstructionFinder)1