use of org.apache.bcel.generic.SIPUSH 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();
}
Aggregations