List of usage examples for org.objectweb.asm Opcodes BIPUSH
int BIPUSH
To view the source code for org.objectweb.asm Opcodes BIPUSH.
Click Source Link
From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java
License:Apache License
public void pushConstant(int value, MethodVisitor mv) { switch (value) { case 0:/* w ww. j a va 2 s .c o m*/ mv.visitInsn(Opcodes.ICONST_0); break; case 1: mv.visitInsn(Opcodes.ICONST_1); break; case 2: mv.visitInsn(Opcodes.ICONST_2); break; case 3: mv.visitInsn(Opcodes.ICONST_3); break; case 4: mv.visitInsn(Opcodes.ICONST_4); break; case 5: mv.visitInsn(Opcodes.ICONST_5); break; default: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, value); } else { mv.visitLdcInsn(Integer.valueOf(value)); } } }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * Encodes instructions to push an int value onto the operand stack. * Does not reallocate the wrapper argument 'value'. * @param value to be pushed /*from w ww . ja v a 2 s .co m*/ * @param context * @return JavaTypeName the type of the result on the operand stack. */ private static JavaTypeName encodePushIntegerValue(Integer value, GenerationContext context) { MethodVisitor mv = context.getMethodVisitor(); int v = value.intValue(); if (v >= -1 && v <= 5) { // Use ICONST_n mv.visitInsn(Opcodes.ICONST_0 + v); } else if (v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE) { // Use BIPUSH mv.visitIntInsn(Opcodes.BIPUSH, (byte) v); } else if (v >= Short.MIN_VALUE && v <= Short.MAX_VALUE) { // Use SIPUSH mv.visitIntInsn(Opcodes.SIPUSH, (short) v); } else { // If everything fails create a Constant pool entry mv.visitLdcInsn(value); } return JavaTypeName.INT; }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * Encodes instructions to push an int value onto the operand stack. * May need to box the argument 'value' if it is sufficiently large that * it needs to go into the constant pool. * @param value to be pushed /* w w w . j a v a 2 s. c om*/ * @param context * @return JavaTypeName the type of the result on the operand stack. */ private static JavaTypeName encodePushIntValue(int value, GenerationContext context) { MethodVisitor mv = context.getMethodVisitor(); if (value >= -1 && value <= 5) { // Use ICONST_n mv.visitInsn(Opcodes.ICONST_0 + value); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { // Use BIPUSH mv.visitIntInsn(Opcodes.BIPUSH, (byte) value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { // Use SIPUSH mv.visitIntInsn(Opcodes.SIPUSH, (short) value); } else { // If everything fails create a Constant pool entry mv.visitLdcInsn(Integer.valueOf(value)); } return JavaTypeName.INT; }
From source file:org.pitest.coverage.codeassist.CoverageMethodVisitor.java
License:Apache License
private void pushConstant(final int value) { switch (value) { case 0:/*from w ww. j ava 2s. co m*/ this.mv.visitInsn(ICONST_0); break; case 1: this.mv.visitInsn(ICONST_1); break; case 2: this.mv.visitInsn(ICONST_2); break; case 3: this.mv.visitInsn(ICONST_3); break; case 4: this.mv.visitInsn(ICONST_4); break; case 5: this.mv.visitInsn(ICONST_5); break; default: if (value <= Byte.MAX_VALUE) { this.mv.visitIntInsn(Opcodes.BIPUSH, value); } else if (value <= Short.MAX_VALUE) { this.mv.visitIntInsn(Opcodes.SIPUSH, value); } else { this.mv.visitLdcInsn(value); } } }
From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java
License:Open Source License
@Test public void test_bipush() throws Exception { ProgramState programState = execute(new Instruction(Opcodes.BIPUSH, 42)); assertStack(programState,//w w w . j av a 2s. com new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL } }); programState = execute(new Instruction(Opcodes.BIPUSH, 1)); assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL, BooleanConstraint.TRUE } }); programState = execute(new Instruction(Opcodes.BIPUSH, 0)); assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.ZERO, ObjectConstraint.NOT_NULL, BooleanConstraint.FALSE } }); }
From source file:org.spongepowered.asm.util.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 w w w . j a v a2 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(intConstants[c]); } 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:org.spongepowered.despector.emitter.bytecode.instruction.BytecodeIntConstantEmitter.java
License:Open Source License
@Override public void emit(BytecodeEmitterContext ctx, IntConstant arg, TypeSignature type) { MethodVisitor mv = ctx.getMethodVisitor(); int val = arg.getConstant(); if (val == -1) { mv.visitInsn(Opcodes.ICONST_M1); } else if (val == 0) { mv.visitInsn(Opcodes.ICONST_0);// ww w . ja v a2 s. c o m } else if (val == 1) { mv.visitInsn(Opcodes.ICONST_1); } else if (val == 2) { mv.visitInsn(Opcodes.ICONST_2); } else if (val == 3) { mv.visitInsn(Opcodes.ICONST_3); } else if (val == 4) { mv.visitInsn(Opcodes.ICONST_4); } else if (val == 5) { mv.visitInsn(Opcodes.ICONST_5); } else if (val <= Byte.MAX_VALUE && val >= Byte.MIN_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, val); } else if (val <= Short.MAX_VALUE && val >= Short.MIN_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, val); } else { mv.visitLdcInsn(val); } ctx.updateStack(1); }
From source file:org.spongepowered.mod.asm.util.ASMHelper.java
License:MIT License
/** * Generate a new method "int name()", which returns a constant value. * * @param clazz Class to add method to//from w w w . j a v a2 s. c o m * @param name Name of method * @param retval Return value of method */ public static void generateIntegerMethodConst(ClassNode clazz, String name, short retval) { MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I", null, null); InsnList code = method.instructions; // Probably doesn't make a huge difference, but use BIPUSH if the value is small enough. if (retval >= Byte.MIN_VALUE && retval <= Byte.MAX_VALUE) { code.add(new IntInsnNode(Opcodes.BIPUSH, retval)); } else { code.add(new IntInsnNode(Opcodes.SIPUSH, retval)); } code.add(new InsnNode(Opcodes.IRETURN)); clazz.methods.add(method); }
From source file:org.spongepowered.mod.asm.util.ASMUtils.java
License:MIT License
public static AbstractInsnNode getPushIntConstant(int c) { if (c == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (c >= 0 && c <= 5) { return new InsnNode(intConstants[c]); } 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 {//from w w w .j av a 2 s . c o m return new LdcInsnNode(c); } }
From source file:org.zoeey.ztpl.compiler.ByteCodeHelper.java
License:LGPL
/** * /*from w w w .j a va2 s .c o m*/ * @param num * @return */ private ByteCodeHelper visitInt(int num) { /** * * @param num */ int label = 0; switch (num) { case -1: mv.visitInsn(Opcodes.ICONST_M1); break; case 0: mv.visitInsn(Opcodes.ICONST_0); break; case 1: mv.visitInsn(Opcodes.ICONST_1); break; case 2: mv.visitInsn(Opcodes.ICONST_2); break; case 3: mv.visitInsn(Opcodes.ICONST_3); break; case 4: mv.visitInsn(Opcodes.ICONST_4); break; case 5: mv.visitInsn(Opcodes.ICONST_5); break; default: if (num <= Byte.MAX_VALUE && num >= Byte.MIN_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, num); } else if (num <= Short.MAX_VALUE && num >= Short.MIN_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, num); } else if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE) { mv.visitLdcInsn(num); /** * ?? */ } else if (num <= Long.MAX_VALUE && num >= Long.MIN_VALUE) { mv.visitLdcInsn(num); label = 1; } else { // todo throw something } } if (label == 1) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); } return this; }