Example usage for org.objectweb.asm Opcodes SIPUSH

List of usage examples for org.objectweb.asm Opcodes SIPUSH

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes SIPUSH.

Prototype

int SIPUSH

To view the source code for org.objectweb.asm Opcodes SIPUSH.

Click Source Link

Usage

From source file:org.evosuite.graphs.cfg.ASMWrapper.java

License:Open Source License

/**
 * <p>//www.java2s  .  com
 * isConstant
 * </p>
 * 
 * @return a boolean.
 */
public boolean isConstant() {
    switch (asmNode.getOpcode()) {
    case Opcodes.LDC:
    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.ICONST_M1:
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.BIPUSH:
    case Opcodes.SIPUSH:
        return true;
    default:
        return false;
    }
}

From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java

License:Open Source License

/**
 * Determine how many bytes the current instruction occupies together with
 * its operands/*from ww w.j  a v a 2 s .  c o  m*/
 * 
 * @return
 */
private int getBytecodeIncrement(AbstractInsnNode instructionNode) {
    int opcode = instructionNode.getOpcode();
    switch (opcode) {
    case Opcodes.ALOAD: // index
    case Opcodes.ASTORE: // index
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
        VarInsnNode varNode = (VarInsnNode) instructionNode;
        if (varNode.var > 3)
            return 1;
        else
            return 0;
    case Opcodes.BIPUSH: // byte
    case Opcodes.NEWARRAY:
    case Opcodes.RET:
        return 1;
    case Opcodes.LDC:
        LdcInsnNode ldcNode = (LdcInsnNode) instructionNode;
        if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long)
            return 2; // LDC2_W
        else
            return 1;
    case 19: //LDC_W
    case 20: //LDC2_W
        return 2;
    case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2
    case Opcodes.CHECKCAST: // indexbyte1, indexbyte2
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
    case Opcodes.GOTO:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFNE:
    case Opcodes.IFEQ:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
    case Opcodes.IINC:
    case Opcodes.INSTANCEOF:
    case Opcodes.INVOKESPECIAL:
    case Opcodes.INVOKESTATIC:
    case Opcodes.INVOKEVIRTUAL:
    case Opcodes.JSR:
    case Opcodes.NEW:
    case Opcodes.PUTFIELD:
    case Opcodes.PUTSTATIC:
    case Opcodes.SIPUSH:
        // case Opcodes.LDC_W
        // case Opcodes.LDC2_W

        return 2;
    case Opcodes.MULTIANEWARRAY:
        return 3;
    case Opcodes.INVOKEDYNAMIC:
    case Opcodes.INVOKEINTERFACE:
        return 4;

    case Opcodes.LOOKUPSWITCH:
    case Opcodes.TABLESWITCH:
        // TODO: Could be more
        return 4;
    // case Opcodes.GOTO_W 
    // case Opcodes.JSR_W
    }
    return 0;
}

From source file:org.evosuite.instrumentation.mutation.ReplaceConstant.java

License:Open Source License

private Object getValue(AbstractInsnNode constant) {
    switch (constant.getOpcode()) {
    case Opcodes.LDC:
        return ((LdcInsnNode) constant).cst;
    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;
    case Opcodes.ICONST_M1:
        return -1;
    case Opcodes.LCONST_0:
        return 0L;
    case Opcodes.LCONST_1:
        return 1L;
    case Opcodes.DCONST_0:
        return 0.0;
    case Opcodes.DCONST_1:
        return 1.0;
    case Opcodes.FCONST_0:
        return 0.0F;
    case Opcodes.FCONST_1:
        return 1.0F;
    case Opcodes.FCONST_2:
        return 2.0F;
    case Opcodes.SIPUSH:
        return ((IntInsnNode) constant).operand;
    case Opcodes.BIPUSH:
        return ((IntInsnNode) constant).operand;
    default://from   w  w w. j  a v  a  2  s .c o  m
        throw new RuntimeException("Unknown constant: " + constant.getOpcode());
    }
}

From source file:org.evosuite.seeding.PrimitivePoolMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w  w  w.j  a va 2s . co  m
public void visitIntInsn(int opcode, int operand) {
    if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) {
        // constantPool.add(operand);
        if (DependencyAnalysis.isTargetClassName(className)) {
            poolManager.addSUTConstant(operand);
        } else {
            poolManager.addNonSUTConstant(operand);
        }
    }
    super.visitIntInsn(opcode, operand);
}

From source file:org.friz.bytecode.insn.InsnNodeUtility.java

License:Open Source License

/**
 * Creates a numeric push instruction.//from  w w  w  .  j  ava 2s.  c o  m
 * @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:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitIntInsn(final int opcode, final int operand) {
    switch (opcode) {
    case Opcodes.BIPUSH:
    case Opcodes.SIPUSH:
        push(Opcodes.INTEGER);/*from  www . j a  v  a  2s.co m*/
        break;
    case Opcodes.NEWARRAY:
        pop(1);
        switch (operand) {
        case Opcodes.T_BOOLEAN:
            push("[Z");
            break;
        case Opcodes.T_CHAR:
            push("[C");
            break;
        case Opcodes.T_FLOAT:
            push("[F");
            break;
        case Opcodes.T_DOUBLE:
            push("[D");
            break;
        case Opcodes.T_BYTE:
            push("[B");
            break;
        case Opcodes.T_SHORT:
            push("[S");
            break;
        case Opcodes.T_INT:
            push("[I");
            break;
        case Opcodes.T_LONG:
            push("[J");
            break;
        default:
            throw new IllegalArgumentException();
        }
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitIntInsn(opcode, operand);
}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates the instruction to push the given value on the stack.
 *
 * @param value the value to be pushed on the stack.
 *///w  ww  .j  a v  a 2  s.  c  o  m
public void push(final int value) {
    if (value >= -1 && value <= 5) {
        visitInsn(Opcodes.ICONST_0 + value);
    } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
        visitIntInsn(Opcodes.BIPUSH, value);
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
        visitIntInsn(Opcodes.SIPUSH, value);
    } else {
        visitLdcInsn(new Integer(value));
    }
}

From source file:org.mbte.groovypp.compiler.asm.LdcImproverMethodAdapter.java

License:Apache License

public void visitLdcInsn(Object cst) {
    if (cst instanceof Integer) {
        Integer value = (Integer) cst;
        switch (value) {
        case -1://w w w. ja  v a  2 s  . com
            super.visitInsn(Opcodes.ICONST_M1);
            break;
        case 0:
            super.visitInsn(Opcodes.ICONST_0);
            break;
        case 1:
            super.visitInsn(Opcodes.ICONST_1);
            break;
        case 2:
            super.visitInsn(Opcodes.ICONST_2);
            break;
        case 3:
            super.visitInsn(Opcodes.ICONST_3);
            break;
        case 4:
            super.visitInsn(Opcodes.ICONST_4);
            break;
        case 5:
            super.visitInsn(Opcodes.ICONST_5);
            break;
        default:
            if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
                super.visitIntInsn(Opcodes.BIPUSH, value);
            } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
                super.visitIntInsn(Opcodes.SIPUSH, value);
            } else {
                super.visitLdcInsn(Integer.valueOf(value));
            }
        }
    } else if (cst instanceof BigDecimal) {
        super.visitTypeInsn(NEW, "java/math/BigDecimal");
        super.visitInsn(DUP);
        super.visitLdcInsn(cst.toString());
        super.visitMethodInsn(INVOKESPECIAL, "java/math/BigDecimal", "<init>", "(Ljava/lang/String;)V");
    } else if (cst instanceof BigInteger) {
        super.visitTypeInsn(NEW, "java/math/BigInteger");
        super.visitInsn(DUP);
        super.visitLdcInsn(cst.toString());
        super.visitMethodInsn(INVOKESPECIAL, "java/math/BigInteger", "<init>", "(Ljava/lang/String;)V");
    } else if (cst instanceof Double) {
        Double aDouble = (Double) cst;
        if (aDouble == 1.0d)
            super.visitInsn(DCONST_1);
        else
            super.visitLdcInsn(cst);
    } else if (cst instanceof Long) {
        Long aLong = (Long) cst;
        if (aLong == 0L)
            super.visitInsn(LCONST_0);
        else if (aLong == 1L)
            super.visitInsn(LCONST_1);
        else
            super.visitLdcInsn(cst);
    } else if (cst instanceof Float) {
        Float aFloat = (Float) cst;
        if (aFloat == 1.0f)
            super.visitInsn(FCONST_1);
        else if (aFloat == 2.0f)
            super.visitInsn(FCONST_2);
        else
            super.visitLdcInsn(cst);
    } else if (cst == null) {
        super.visitInsn(ACONST_NULL);
    } else
        super.visitLdcInsn(cst);
}

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

public void pushConstant(int value, MethodVisitor mv) {
    switch (value) {
    case 0://ww  w . j a  v a  2  s.  c om
        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  www .  ja  v  a  2 s .com*/
 * @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;
}