List of usage examples for org.objectweb.asm Opcodes ICONST_M1
int ICONST_M1
To view the source code for org.objectweb.asm Opcodes ICONST_M1.
Click Source Link
From source file:com.codename1.tools.translator.Util.java
License:Open Source License
public static char[] getStackOutputTypes(Instruction instr) { char[] out = instr.getStackOutputTypes(); if (out != null) { return out; }// ww w. j a v a 2s.c o m switch (instr.getOpcode()) { case Opcodes.NOP: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.POP: case Opcodes.POP2: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.ATHROW: return new char[0]; case Opcodes.ACONST_NULL: case Opcodes.AALOAD: case Opcodes.NEWARRAY: return new char[] { 'o' }; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.IALOAD: case Opcodes.SALOAD: case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.INEG: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.IUSHR: case Opcodes.IAND: case Opcodes.IOR: case Opcodes.IXOR: case Opcodes.F2I: case Opcodes.D2I: case Opcodes.L2I: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.LCMP: case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.DCMPL: case Opcodes.DCMPG: case Opcodes.ARRAYLENGTH: case Opcodes.SIPUSH: case Opcodes.BIPUSH: return new char[] { 'i' }; case Opcodes.LCONST_0: case Opcodes.LCONST_1: case Opcodes.LALOAD: case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.LNEG: case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: case Opcodes.LAND: case Opcodes.LOR: case Opcodes.LXOR: case Opcodes.I2L: case Opcodes.F2L: case Opcodes.D2L: return new char[] { 'l' }; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: case Opcodes.FALOAD: case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: case Opcodes.FNEG: case Opcodes.I2F: case Opcodes.D2F: case Opcodes.L2F: return new char[] { 'f' }; case Opcodes.DCONST_0: case Opcodes.DCONST_1: case Opcodes.DALOAD: case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: case Opcodes.DDIV: case Opcodes.DREM: case Opcodes.DNEG: case Opcodes.I2D: case Opcodes.F2D: case Opcodes.L2D: return new char[] { 'd' }; case Opcodes.DUP: return new char[] { '0', '0' }; case Opcodes.DUP2: case Opcodes.DUP_X2: case Opcodes.DUP2_X2: return null; case Opcodes.DUP_X1: case Opcodes.DUP2_X1: return new char[] { '0', '1', '0' }; case Opcodes.SWAP: return new char[] { '1', '0' }; default: return null; } }
From source file:com.dank.asm.InsnNodeUtils.java
License:Open Source License
/** * Creates a numeric push instruction./*from ww w . j a v a 2s. c om*/ * * @param num * The number to push. * @return The instruction node. */ public static AbstractInsnNode createNumericPushInsn(Number num) { long value = num.longValue(); if (value == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (value == 0) { return new InsnNode(Opcodes.ICONST_0); } else if (value == 1) { return new InsnNode(Opcodes.ICONST_1); } else if (value == 2) { return new InsnNode(Opcodes.ICONST_2); } else if (value == 3) { return new InsnNode(Opcodes.ICONST_3); } else if (value == 4) { return new InsnNode(Opcodes.ICONST_4); } else if (value == 5) { return new InsnNode(Opcodes.ICONST_5); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return new IntInsnNode(Opcodes.BIPUSH, (int) value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { return new IntInsnNode(Opcodes.SIPUSH, (int) value); } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) { return new LdcInsnNode((int) value); } else { return new LdcInsnNode(/* (long) */value); } }
From source file:com.dank.asm.InsnNodeUtils.java
License:Open Source License
/** * Reads the value of a numeric push instruction (which can be an * {@code ICONST_*} instruction, an {@code BIPUSH} instruction, an * {@code SIPUSH} instruction or a {@code LDC_*} instruction. * // ww w . j av a 2s. co m * @param push * The instruction node. * @return The numeric value. */ public static long getNumericPushValue(AbstractInsnNode push) { if (push instanceof InsnNode) { switch (push.opcode()) { case Opcodes.ICONST_M1: return -1; case Opcodes.ICONST_0: return 0; case Opcodes.ICONST_1: return 1; case Opcodes.ICONST_2: return 2; case Opcodes.ICONST_3: return 3; case Opcodes.ICONST_4: return 4; case Opcodes.ICONST_5: return 5; default: throw new AssertionError(); } } else if (push instanceof IntInsnNode) { return ((IntInsnNode) push).operand; } else { return ((Number) ((LdcInsnNode) push).cst).longValue(); } }
From source file:com.geeksaga.light.profiler.util.ASMUtil.java
License:Apache License
public static AbstractInsnNode createPushNode(int value) { if (value == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (value == 0) { return new InsnNode(Opcodes.ICONST_0); } else if (value == 1) { return new InsnNode(Opcodes.ICONST_1); } else if (value == 2) { return new InsnNode(Opcodes.ICONST_2); } else if (value == 3) { return new InsnNode(Opcodes.ICONST_3); } else if (value == 4) { return new InsnNode(Opcodes.ICONST_4); } else if (value == 5) { return new InsnNode(Opcodes.ICONST_5); } else if ((value >= -128) && (value <= 127)) { return new IntInsnNode(Opcodes.BIPUSH, value); } else if ((value >= -32768) && (value <= 32767)) { return new IntInsnNode(Opcodes.SIPUSH, value); } else {// w w w .java 2 s . co m return new LdcInsnNode(value); } }
From source file:com.github.fge.grappa.transform.CodeBlock.java
License:Apache License
public CodeBlock iconst_m1() { instructionList.add(new InsnNode(Opcodes.ICONST_M1)); return this; }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.NOP: case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.RETURN: break;/*from w w w. j av a 2s . c om*/ case Opcodes.ACONST_NULL: push(InferredType.NULL); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(InferredType.INT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(InferredType.FLOAT); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.IALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: pop(2); push(InferredType.INT); break; case Opcodes.LALOAD: case Opcodes.D2L: pop(2); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.DALOAD: case Opcodes.L2D: pop(2); push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.AALOAD: InferredType arrayType = pop(2); InferredType elementType = arrayType.getElementTypeIfArrayOrThrow(); push(elementType); break; case Opcodes.IASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.FASTORE: case Opcodes.AASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); break; case Opcodes.POP: case Opcodes.IRETURN: case Opcodes.FRETURN: case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: pop(); break; case Opcodes.POP2: case Opcodes.LRETURN: case Opcodes.DRETURN: pop(2); break; case Opcodes.DUP: push(top()); break; case Opcodes.DUP_X1: { InferredType top = pop(); InferredType next = pop(); push(top); push(next); push(top); break; } case Opcodes.DUP_X2: { InferredType top = pop(); InferredType next = pop(); InferredType bottom = pop(); push(top); push(bottom); push(next); push(top); break; } case Opcodes.DUP2: { InferredType top = pop(); InferredType next = pop(); push(next); push(top); push(next); push(top); break; } case Opcodes.DUP2_X1: { InferredType top = pop(); InferredType next = pop(); InferredType bottom = pop(); push(next); push(top); push(bottom); push(next); push(top); break; } case Opcodes.DUP2_X2: { InferredType t1 = pop(); InferredType t2 = pop(); InferredType t3 = pop(); InferredType t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; } case Opcodes.SWAP: { InferredType top = pop(); InferredType next = pop(); push(top); push(next); break; } case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.IUSHR: case Opcodes.IAND: case Opcodes.IOR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.D2I: case Opcodes.FCMPL: case Opcodes.FCMPG: pop(2); push(InferredType.INT); break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.LAND: case Opcodes.LOR: case Opcodes.LXOR: pop(4); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.I2L: case Opcodes.F2L: pop(); push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.I2F: pop(); push(InferredType.FLOAT); break; case Opcodes.LCMP: case Opcodes.DCMPG: case Opcodes.DCMPL: pop(4); push(InferredType.INT); break; case Opcodes.I2D: case Opcodes.F2D: pop(); push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.F2I: case Opcodes.ARRAYLENGTH: pop(); push(InferredType.INT); break; case Opcodes.FALOAD: case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: case Opcodes.L2F: case Opcodes.D2F: pop(2); push(InferredType.FLOAT); break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: case Opcodes.DDIV: case Opcodes.DREM: pop(4); push(InferredType.DOUBLE); push(InferredType.TOP); break; default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitInsn(opcode); }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitInsn(final int opcode) { switch (opcode) { case Opcodes.ACONST_NULL: recorder.add(new Runnable() { public void run() { block.addOp(new Load(lineNumber, new Constant(null, JavaType.OBJECT))); }/*from ww w .j a v a 2 s.com*/ }); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: loadConstant(opcode - Opcodes.ICONST_M1 - 1, JavaType.INT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: loadConstant(opcode - Opcodes.LCONST_0, JavaType.LONG); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: loadConstant(opcode - Opcodes.FCONST_0, JavaType.FLOAT); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: loadConstant(opcode - Opcodes.DCONST_0, JavaType.DOUBLE); break; case Opcodes.IALOAD: recordArrayLoad(JavaType.INT); break; case Opcodes.LALOAD: recordArrayLoad(JavaType.LONG); break; case Opcodes.FALOAD: recordArrayLoad(JavaType.FLOAT); break; case Opcodes.DALOAD: recordArrayLoad(JavaType.DOUBLE); break; case Opcodes.AALOAD: recordArrayLoad(JavaType.OBJECT); break; case Opcodes.BALOAD: recordArrayLoad(JavaType.BYTE); break; case Opcodes.CALOAD: recordArrayLoad(JavaType.CHAR); break; case Opcodes.SALOAD: recordArrayLoad(JavaType.SHORT); break; case Opcodes.IASTORE: recordArrayStore(JavaType.INT); break; case Opcodes.LASTORE: recordArrayStore(JavaType.LONG); break; case Opcodes.FASTORE: recordArrayStore(JavaType.FLOAT); break; case Opcodes.DASTORE: recordArrayStore(JavaType.DOUBLE); break; case Opcodes.AASTORE: recordArrayStore(JavaType.OBJECT); break; case Opcodes.BASTORE: recordArrayStore(JavaType.BYTE); break; case Opcodes.CASTORE: recordArrayStore(JavaType.CHAR); break; case Opcodes.SASTORE: recordArrayStore(JavaType.SHORT); break; case Opcodes.POP: case Opcodes.POP2: recorder.add(new Runnable() { public void run() { block.addOp(new Pop(lineNumber, opcode - Opcodes.POP + 1)); } }); break; case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: recorder.add(new Runnable() { public void run() { int offset = opcode - Opcodes.DUP; block.addOp(new Duplicate(lineNumber, offset)); } }); break; case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: recorder.add(new Runnable() { public void run() { block.addOp(new Duplicate2(lineNumber, opcode - Opcodes.DUP2)); } }); break; case Opcodes.SWAP: recorder.add(new Runnable() { public void run() { block.addOp(new Swap(lineNumber)); } }); break; case Opcodes.IRETURN: _return(JavaType.INT); break; case Opcodes.FRETURN: _return(JavaType.FLOAT); break; case Opcodes.ARETURN: _return(JavaType.OBJECT); break; case Opcodes.LRETURN: _return(JavaType.LONG); break; case Opcodes.DRETURN: _return(JavaType.DOUBLE); break; case Opcodes.ATHROW: recorder.add(new Runnable() { public void run() { block.addOp(new Throw(lineNumber)); } }); break; case Opcodes.RETURN: _return(JavaType.VOID); break; case Opcodes.LCMP: operation("cmp", JavaType.LONG, JavaType.LONG, JavaType.INT); break; case Opcodes.FCMPL: operation("cmpl", JavaType.FLOAT, JavaType.FLOAT, JavaType.INT); break; case Opcodes.FCMPG: operation("cmpg", JavaType.FLOAT, JavaType.FLOAT, JavaType.INT); break; case Opcodes.DCMPL: operation("cmpl", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.INT); break; case Opcodes.DCMPG: operation("cmpg", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.INT); break; case Opcodes.LSHL: operation("shl", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LSHR: operation("shr", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LUSHR: operation("ushr", JavaType.LONG, JavaType.INT, JavaType.LONG); break; case Opcodes.LADD: operation("add", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LSUB: operation("sub", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LDIV: operation("div", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LREM: operation("rem", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LAND: operation("and", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LOR: operation("or", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LXOR: operation("xor", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.LMUL: operation("mul", JavaType.LONG, JavaType.LONG, JavaType.LONG); break; case Opcodes.FADD: operation("add", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FSUB: operation("sub", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FMUL: operation("mul", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FREM: operation("rem", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.FDIV: operation("div", JavaType.FLOAT, JavaType.FLOAT, JavaType.FLOAT); break; case Opcodes.ISHL: operation("shl", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.ISHR: operation("shr", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IUSHR: operation("ushr", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IADD: operation("add", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.ISUB: operation("sub", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IMUL: operation("mul", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IDIV: operation("div", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IREM: operation("rem", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IAND: operation("and", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IOR: operation("or", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.IXOR: operation("xor", JavaType.INT, JavaType.INT, JavaType.INT); break; case Opcodes.DSUB: operation("sub", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DADD: operation("add", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DMUL: operation("mul", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DDIV: operation("div", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.DREM: operation("rem", JavaType.DOUBLE, JavaType.DOUBLE, JavaType.DOUBLE); break; case Opcodes.L2I: convert(JavaType.LONG, JavaType.INT); break; case Opcodes.L2F: convert(JavaType.LONG, JavaType.FLOAT); break; case Opcodes.L2D: convert(JavaType.LONG, JavaType.DOUBLE); break; case Opcodes.LNEG: operation("neg", JavaType.LONG, null, JavaType.LONG); break; case Opcodes.F2I: convert(JavaType.FLOAT, JavaType.INT); break; case Opcodes.F2L: convert(JavaType.FLOAT, JavaType.LONG); break; case Opcodes.FNEG: operation("neg", JavaType.FLOAT, null, JavaType.FLOAT); break; case Opcodes.F2D: convert(JavaType.FLOAT, JavaType.DOUBLE); break; case Opcodes.D2I: convert(JavaType.DOUBLE, JavaType.INT); break; case Opcodes.D2L: convert(JavaType.DOUBLE, JavaType.LONG); break; case Opcodes.D2F: convert(JavaType.DOUBLE, JavaType.FLOAT); break; case Opcodes.DNEG: operation("neg", JavaType.DOUBLE, null, JavaType.DOUBLE); break; case Opcodes.I2L: convert(JavaType.INT, JavaType.LONG); break; case Opcodes.I2F: convert(JavaType.INT, JavaType.FLOAT); break; case Opcodes.I2D: convert(JavaType.INT, JavaType.DOUBLE); break; case Opcodes.I2B: convert(JavaType.INT, JavaType.BYTE); break; case Opcodes.I2C: convert(JavaType.INT, JavaType.CHAR); break; case Opcodes.I2S: convert(JavaType.INT, JavaType.SHORT); break; case Opcodes.INEG: operation("neg", JavaType.INT, null, JavaType.INT); break; case Opcodes.ARRAYLENGTH: operation("arraylength", JavaType.OBJECT.toArray(), null, JavaType.INT); break; case Opcodes.MONITORENTER: recorder.add(new Runnable() { public void run() { block.addOp(new MonitorEnter(lineNumber)); } }); break; case Opcodes.MONITOREXIT: recorder.add(new Runnable() { public void run() { block.addOp(new MonitorExit(lineNumber)); } }); break; case Opcodes.NOP: recorder.add(new Runnable() { public void run() { block.addOp(new Transform(lineNumber, "NOP", null, null, null)); } }); } }
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;/*from ww w.j ava2 s . com*/ case Opcodes.ACONST_NULL: { Operand op = new Operand(); op.setNull(true); push(op); } break; case Opcodes.ICONST_M1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(-1)); push(op); } break; case Opcodes.ICONST_0: { Operand op = new Operand(); op.setConstant(Integer.valueOf(0)); push(op); } break; case Opcodes.ICONST_1: { Operand op = new Operand(); op.setConstant(Integer.valueOf(1)); push(op); } break; case Opcodes.ICONST_2: { Operand op = new Operand(); op.setConstant(Integer.valueOf(2)); push(op); } break; case Opcodes.ICONST_3: { Operand op = new Operand(); op.setConstant(Integer.valueOf(3)); push(op); } break; case Opcodes.ICONST_4: { Operand op = new Operand(); op.setConstant(Integer.valueOf(4)); push(op); } break; case Opcodes.ICONST_5: { Operand op = new Operand(); op.setConstant(Integer.valueOf(5)); push(op); } break; case Opcodes.LCONST_0: { Operand op = new Operand(); op.setConstant(Long.valueOf(0)); push(op); } break; case Opcodes.LCONST_1: { Operand op = new Operand(); op.setConstant(Long.valueOf(1)); push(op); } break; case Opcodes.FCONST_0: { Operand op = new Operand(); op.setConstant(Float.valueOf(0)); push(op); } break; case Opcodes.FCONST_1: { Operand op = new Operand(); op.setConstant(Float.valueOf(1)); push(op); } break; case Opcodes.FCONST_2: { Operand op = new Operand(); op.setConstant(Float.valueOf(2)); push(op); } break; case Opcodes.DCONST_0: { Operand op = new Operand(); op.setConstant(Double.valueOf(0)); push(op); } break; case Opcodes.DCONST_1: { Operand op = new Operand(); op.setConstant(Double.valueOf(1)); push(op); } break; case Opcodes.IALOAD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LALOAD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FALOAD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DALOAD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.AALOAD: { pop2(); Operand op = new Operand(); op.setSignature("Ljava/lang/Object;"); push(op); } break; case Opcodes.BALOAD: { pop2(); Operand op = new Operand(); op.setSignature("B"); push(op); } break; case Opcodes.CALOAD: { pop2(); Operand op = new Operand(); op.setSignature("C"); push(op); } break; case Opcodes.SALOAD: { pop2(); Operand op = new Operand(); op.setSignature("S"); push(op); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: if (stack.size() < 2) { stack.clear(); } else { Operand value = stack.remove(stack.size() - 1); Operand reg = stack.remove(stack.size() - 1); registers.put(Integer.valueOf(reg.getRegister()), value); } break; case Opcodes.POP: pop(); break; case Opcodes.POP2: pop2(); break; case Opcodes.DUP: if (!stack.isEmpty()) { Operand op = stack.get(stack.size() - 1); push(op); } break; case Opcodes.DUP_X1: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } break; case Opcodes.DUP_X2: if (stack.size() >= 2) { Operand op = stack.get(stack.size() - 2); String sig = op.getSignature(); op = stack.get(stack.size() - 1); if ("J".equals(sig) || "D".equals(sig)) { stack.add(stack.size() - 2, op); } else if (stack.size() >= 3) { stack.add(stack.size() - 3, op); } } break; case Opcodes.DUP2: if (stack.size() >= 2) { stack.add(stack.get(stack.size() - 2)); stack.add(stack.get(stack.size() - 2)); } break; case Opcodes.DUP2_X1: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 3) { stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); } } else { if (stack.size() >= 2) { stack.add(stack.size() - 2, op); } } } break; case Opcodes.DUP2_X2: if (stack.size() >= 1) { Operand op = stack.get(stack.size() - 1); String sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { if (stack.size() >= 2) { op = stack.get(stack.size() - 2); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 2, op); } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } } } } else { if (stack.size() >= 3) { op = stack.get(stack.size() - 3); sig = op.getSignature(); if ("J".equals(sig) || "D".equals(sig)) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 3, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 3, op); } else { if (stack.size() >= 4) { op = stack.get(stack.size() - 2); stack.add(stack.size() - 4, op); op = stack.get(stack.size() - 1); stack.add(stack.size() - 4, op); } } } } } break; case Opcodes.SWAP: if (stack.size() >= 2) { Operand op = stack.remove(stack.size() - 1); stack.add(stack.size() - 1, op); } break; case Opcodes.IADD: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LADD: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FADD: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DADD: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISUB: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSUB: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FSUB: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DSUB: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IMUL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LMUL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FMUL: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DMUL: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IDIV: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LDIV: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FDIV: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DDIV: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.IREM: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LREM: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FREM: { pop2(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DREM: { pop2(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.INEG: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LNEG: { pop(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.FNEG: { pop(); Operand op = new Operand(); op.setSignature("F"); push(op); } break; case Opcodes.DNEG: { pop(); Operand op = new Operand(); op.setSignature("D"); push(op); } break; case Opcodes.ISHL: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHL: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.ISHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IUSHR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LUSHR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IAND: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LAND: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.IXOR: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.LXOR: { pop2(); Operand op = new Operand(); op.setSignature("J"); push(op); } break; case Opcodes.I2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Integer) o).longValue())); } } push(lop); } break; case Opcodes.I2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Integer) o).floatValue())); } } push(fop); } break; case Opcodes.I2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Integer) o).doubleValue())); } } push(dop); } break; case Opcodes.L2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Long) o).intValue())); } } push(iop); } break; case Opcodes.L2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Long) o).floatValue())); } } push(fop); } break; case Opcodes.L2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Long) o).doubleValue())); } } push(dop); } break; case Opcodes.F2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Float) o).intValue())); } } push(iop); } break; case Opcodes.F2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Float) o).longValue())); } } push(lop); } break; case Opcodes.F2D: { Operand dop = new Operand(); dop.setSignature("D"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { dop.setConstant(Double.valueOf(((Float) o).doubleValue())); } } push(dop); } break; case Opcodes.D2I: { Operand iop = new Operand(); iop.setSignature("I"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { iop.setConstant(Integer.valueOf(((Double) o).intValue())); } } push(iop); } break; case Opcodes.D2L: { Operand lop = new Operand(); lop.setSignature("J"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { lop.setConstant(Long.valueOf(((Double) o).longValue())); } } push(lop); } break; case Opcodes.D2F: { Operand fop = new Operand(); fop.setSignature("F"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { fop.setConstant(Float.valueOf(((Double) o).floatValue())); } } push(fop); } break; case Opcodes.I2B: { Operand bop = new Operand(); bop.setSignature("B"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { bop.setConstant(Byte.valueOf(((Integer) o).byteValue())); } } push(bop); } break; case Opcodes.I2C: { Operand cop = new Operand(); cop.setSignature("C"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { cop.setConstant(Character.valueOf((char) ((Integer) o).intValue())); } } push(cop); } break; case Opcodes.I2S: { Operand sop = new Operand(); sop.setSignature("S"); if (!stack.isEmpty()) { Operand op = stack.remove(stack.size() - 1); Object o = op.getConstant(); if (o != null) { sop.setConstant(Short.valueOf((short) ((Integer) o).intValue())); } } push(sop); } break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.FCMPG: case Opcodes.DCMPL: case Opcodes.DCMPG: { pop2(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: pop(); break; case Opcodes.RETURN: //nop break; case Opcodes.ARRAYLENGTH: { pop(); Operand op = new Operand(); op.setSignature("I"); push(op); } break; case Opcodes.ATHROW: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: pop(); break; } }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Gets an instruction that pushes a integer onto the stack. The * instruction uses the smallest push possible (ICONST_*, BIPUSH, SIPUSH or * Integer constant)./*from ww w . jav a 2 s .c om*/ * * @param c the integer to push onto the stack * @return insn node to insert */ public static AbstractInsnNode pushIntConstant(int c) { if (c == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (c >= 0 && c <= 5) { return new InsnNode(ASMHelper.CONSTANTS_INT[c + 1]); } else if (c >= Byte.MIN_VALUE && c <= Byte.MAX_VALUE) { return new IntInsnNode(Opcodes.BIPUSH, c); } else if (c >= Short.MIN_VALUE && c <= Short.MAX_VALUE) { return new IntInsnNode(Opcodes.SIPUSH, c); } else { return new LdcInsnNode(c); } }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitInsn(int opcode) { Expression e;/* w w w . j a va 2 s . c o m*/ Expression first; Expression second; switch (opcode) { case Opcodes.ARRAYLENGTH: e = Expression.arrayLength(_exprStack.pop()); break; case Opcodes.ACONST_NULL: e = Expression.constant(null, Object.class); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.arrayIndex(second, first); break; case Opcodes.DCONST_0: e = Expression.constant(0d, Double.TYPE); break; case Opcodes.DCONST_1: e = Expression.constant(1d, Double.TYPE); break; case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.FCONST_0: e = Expression.constant(0f, Float.TYPE); break; case Opcodes.FCONST_1: e = Expression.constant(1f, Float.TYPE); break; case Opcodes.FCONST_2: e = Expression.constant(2f, Float.TYPE); break; case Opcodes.ICONST_M1: e = Expression.constant(-1, Integer.TYPE); break; case Opcodes.ICONST_0: e = Expression.constant(0, Integer.TYPE); break; case Opcodes.ICONST_1: e = Expression.constant(1, Integer.TYPE); break; case Opcodes.ICONST_2: e = Expression.constant(2, Integer.TYPE); break; case Opcodes.ICONST_3: e = Expression.constant(3, Integer.TYPE); break; case Opcodes.ICONST_4: e = Expression.constant(4, Integer.TYPE); break; case Opcodes.ICONST_5: e = Expression.constant(5, Integer.TYPE); break; case Opcodes.LCONST_0: e = Expression.constant(0l, Long.TYPE); break; case Opcodes.LCONST_1: e = Expression.constant(1l, Long.TYPE); break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.add(second, first); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.multiply(second, first); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.divide(second, first); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.modulo(second, first); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: first = _exprStack.pop(); e = Expression.negate(first); break; case Opcodes.ISHL: case Opcodes.LSHL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.leftShift(second, first); break; case Opcodes.ISHR: case Opcodes.LSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IUSHR: case Opcodes.LUSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IAND: case Opcodes.LAND: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseAnd(second, first); break; case Opcodes.IOR: case Opcodes.LOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseOr(second, first); break; case Opcodes.IXOR: case Opcodes.LXOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.exclusiveOr(second, first); break; case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup2[opcode - Opcodes.I2B]); break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.I2L + 1]); break; case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: int l2l = opcode > Opcodes.L2I ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.L2I + l2l]); break; case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: int f2f = opcode == Opcodes.F2D ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.F2I + f2f]); break; case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.D2I]); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: go(null); return; case Opcodes.SWAP: first = _exprStack.pop(); second = _exprStack.pop(); _exprStack.push(first); _exprStack.push(second); case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: // our stack is not divided to words int base = (opcode - Opcodes.DUP) % 3; base++; dup(_exprStack, base, base - 1); return; case Opcodes.NOP: return; case Opcodes.RETURN: default: throw notLambda(opcode); } _exprStack.push(e); }