Example usage for org.objectweb.asm Opcodes ICONST_M1

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

Introduction

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

Prototype

int ICONST_M1

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

Click Source Link

Usage

From source file:org.brutusin.instrumentation.utils.TreeInstructions.java

License:Apache License

public static AbstractInsnNode getPushInstruction(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 {//from   www.ja  v  a  2s .co m
        return new LdcInsnNode(value);
    }
}

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    T t = null;//from  w  w  w  .  j a va2s .c  om
    int iValue = Integer.MIN_VALUE;
    Object oValue = null;

    switch (opcode) {
    case Opcodes.NOP:
        // nothing to do, ignore
        break;
    /*******
     * ADD *
     *******/
    case Opcodes.DADD:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FADD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IADD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LADD:
        if (t == null) {
            t = T.LONG;
        }
        add(new ADD(this.ops.size(), opcode, this.line, t));
        break;
    /*********
     * ALOAD *
     *********/
    case Opcodes.AALOAD:
        t = T.REF;
        // fall through
    case Opcodes.BALOAD:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CALOAD:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DALOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FALOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IALOAD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LALOAD:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SALOAD:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ALOAD(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * AND *
     *******/
    case Opcodes.IAND:
        t = T.AINT;
        // fall through
    case Opcodes.LAND:
        if (t == null) {
            t = T.LONG;
        }
        add(new AND(this.ops.size(), opcode, this.line, t));
        break;
    /***************
     * ARRAYLENGTH *
     ***************/
    case Opcodes.ARRAYLENGTH:
        add(new ARRAYLENGTH(this.ops.size(), opcode, this.line));
        break;
    /**********
     * ASTORE *
     **********/
    case Opcodes.AASTORE:
        t = T.REF;
        // fall through
    case Opcodes.BASTORE:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CASTORE:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DASTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FASTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IASTORE:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LASTORE:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SASTORE:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ASTORE(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * CAST *
     ********/
    case Opcodes.D2F:
        t = T.DOUBLE;
        oValue = T.FLOAT;
        // fall through
    case Opcodes.D2I:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.D2L:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.F2D:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.F2I:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.F2L:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2B:
        if (t == null) {
            t = T.INT;
            oValue = T.BYTE;
        }
        // fall through
    case Opcodes.I2C:
        if (t == null) {
            t = T.INT;
            oValue = T.CHAR;
        }
        // fall through
    case Opcodes.I2D:
        if (t == null) {
            t = T.INT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.I2F:
        if (t == null) {
            t = T.INT;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.I2L:
        if (t == null) {
            t = T.INT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2S:
        if (t == null) {
            t = T.INT;
            oValue = T.SHORT;
        }
        // fall through
    case Opcodes.L2D:
        if (t == null) {
            t = T.LONG;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.L2F:
        if (t == null) {
            t = T.LONG;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.L2I:
        if (t == null) {
            t = T.LONG;
            oValue = T.INT;
        }
        assert oValue instanceof T;
        add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue));
        break;
    /*******
     * CMP *
     *******/
    case Opcodes.DCMPG:
        t = T.DOUBLE;
        iValue = CMP.T_G;
        // fall through
    case Opcodes.DCMPL:
        if (t == null) {
            t = T.DOUBLE;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.FCMPG:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_G;
        }
        // fall through
    case Opcodes.FCMPL:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.LCMP:
        if (t == null) {
            t = T.LONG;
            iValue = CMP.T_0;
        }
        add(new CMP(this.ops.size(), opcode, this.line, t, iValue));
        break;
    /*******
     * DIV *
     *******/
    case Opcodes.DDIV:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FDIV:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IDIV:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LDIV:
        if (t == null) {
            t = T.LONG;
        }
        add(new DIV(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * DUP *
     *******/
    case Opcodes.DUP:
        oValue = DUP.Kind.DUP;
        // fall through
    case Opcodes.DUP_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X1;
        }
        // fall through
    case Opcodes.DUP_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X2;
        }
        // fall through
    case Opcodes.DUP2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2;
        }
        // fall through
    case Opcodes.DUP2_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X1;
        }
        // fall through
    case Opcodes.DUP2_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X2;
        }
        add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue));
        break;
    /***********
     * MONITOR *
     ***********/
    case Opcodes.MONITORENTER:
        oValue = MONITOR.Kind.ENTER;
        // fall through
    case Opcodes.MONITOREXIT:
        if (oValue == null) {
            oValue = MONITOR.Kind.EXIT;
        }
        add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue));
        break;
    /*******
     * MUL *
     *******/
    case Opcodes.DMUL:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FMUL:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IMUL:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LMUL:
        if (t == null) {
            t = T.LONG;
        }
        add(new MUL(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * NEG *
     *******/
    case Opcodes.DNEG:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FNEG:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.INEG:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LNEG:
        if (t == null) {
            t = T.LONG;
        }
        add(new NEG(this.ops.size(), opcode, this.line, t));
        break;
    /******
     * OR *
     ******/
    case Opcodes.IOR:
        t = T.AINT;
        // fall through
    case Opcodes.LOR:
        if (t == null) {
            t = T.LONG;
        }
        add(new OR(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * POP *
     *******/
    case Opcodes.POP:
        oValue = POP.Kind.POP;
        // fall through
    case Opcodes.POP2:
        if (oValue == null) {
            oValue = POP.Kind.POP2;
        }
        add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue));
        break;
    /********
     * PUSH *
     ********/
    case Opcodes.ACONST_NULL:
        t = T.REF;
        // fall through
    case Opcodes.DCONST_0:
        if (t == null) {
            oValue = 0D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_0:
        if (t == null) {
            oValue = 0F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_0:
        if (t == null) {
            oValue = 0;
            t = T.getJvmIntT(0);
        }
        // fall through
    case Opcodes.LCONST_0:
        if (t == null) {
            oValue = 0L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.DCONST_1:
        if (t == null) {
            oValue = 1D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_1:
        if (t == null) {
            oValue = 1F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_1:
        if (t == null) {
            oValue = 1;
            t = T.getJvmIntT(1);
        }
        // fall through
    case Opcodes.LCONST_1:
        if (t == null) {
            oValue = 1L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.FCONST_2:
        if (t == null) {
            oValue = 2F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_2:
        if (t == null) {
            oValue = 2;
            t = T.getJvmIntT(2);
        }
        // fall through
    case Opcodes.ICONST_3:
        if (t == null) {
            oValue = 3;
            t = T.getJvmIntT(3);
        }
        // fall through
    case Opcodes.ICONST_4:
        if (t == null) {
            oValue = 4;
            t = T.getJvmIntT(4);
        }
        // fall through
    case Opcodes.ICONST_5:
        if (t == null) {
            oValue = 5;
            t = T.getJvmIntT(5);
        }
        // fall through
    case Opcodes.ICONST_M1:
        if (t == null) {
            oValue = -1;
            t = T.getJvmIntT(-1);
        }
        add(new PUSH(this.ops.size(), opcode, this.line, t, oValue));
        break;
    /*******
     * REM *
     *******/
    case Opcodes.DREM:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FREM:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IREM:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LREM:
        if (t == null) {
            t = T.LONG;
        }
        add(new REM(this.ops.size(), opcode, this.line, t));
        break;
    /**********
     * RETURN *
     **********/
    case Opcodes.ARETURN:
        t = T.REF;
        // fall through
    case Opcodes.DRETURN:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FRETURN:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IRETURN:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LRETURN:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.RETURN:
        if (t == null) {
            t = T.VOID;
        }
        add(new RETURN(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * SHL *
     *******/
    case Opcodes.ISHL:
        t = T.INT;
        // fall through
    case Opcodes.LSHL:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHL(this.ops.size(), opcode, this.line, t, T.INT));
        break;
    /*******
     * SHR *
     *******/
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
        t = T.INT;
        // fall through
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHR(this.ops.size(), opcode, this.line, t, T.INT,
                opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR));
        break;
    /*******
     * SUB *
     *******/
    case Opcodes.DSUB:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FSUB:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISUB:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LSUB:
        if (t == null) {
            t = T.LONG;
        }
        add(new SUB(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * SWAP *
     ********/
    case Opcodes.SWAP:
        add(new SWAP(this.ops.size(), opcode, this.line));
        break;
    /*********
     * THROW *
     *********/
    case Opcodes.ATHROW:
        add(new THROW(this.ops.size(), opcode, this.line));
        break;
    /*******
     * XOR *
     *******/
    case Opcodes.IXOR:
        t = T.AINT;
        // fall through
    case Opcodes.LXOR: {
        if (t == null) {
            t = T.LONG;
        }
        add(new XOR(this.ops.size(), opcode, this.line, t));
        break;
    }
    default:
        log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!");
    }
}

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

License:Open Source License

/**
 * <p>/* www. j a v a2 s . co  m*/
 * 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.instrumentation.mutation.InsertUnaryOperator.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w  ww .j a v  a2s. c  o  m
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction,
        Frame frame) {
    // TODO - need to keep InsnList in Mutation, not only Instruction?

    // Mutation: Insert an INEG _after_ an iload 
    List<Mutation> mutations = new LinkedList<Mutation>();
    List<InsnList> mutationCode = new LinkedList<InsnList>();
    List<String> descriptions = new LinkedList<String>();

    if (instruction.getASMNode() instanceof VarInsnNode) {
        try {
            InsnList mutation = new InsnList();
            VarInsnNode node = (VarInsnNode) instruction.getASMNode();

            // insert mutation into bytecode with conditional
            mutation.add(new VarInsnNode(node.getOpcode(), node.var));
            mutation.add(new InsnNode(getNegation(node.getOpcode())));
            mutationCode.add(mutation);

            if (!mn.localVariables.isEmpty())
                descriptions.add("Negation of " + getName(mn, node));
            else
                descriptions.add("Negation");

            if (node.getOpcode() == Opcodes.ILOAD) {
                if (frame.getStack(frame.getStackSize() - 1) != BooleanValueInterpreter.BOOLEAN_VALUE) {
                    mutation = new InsnList();
                    mutation.add(new IincInsnNode(node.var, 1));
                    mutation.add(new VarInsnNode(node.getOpcode(), node.var));
                    if (!mn.localVariables.isEmpty())
                        descriptions.add("IINC 1 " + getName(mn, node));
                    else
                        descriptions.add("IINC 1");
                    mutationCode.add(mutation);

                    mutation = new InsnList();
                    mutation.add(new IincInsnNode(node.var, -1));
                    mutation.add(new VarInsnNode(node.getOpcode(), node.var));
                    if (!mn.localVariables.isEmpty())
                        descriptions.add("IINC -1 " + getName(mn, node));
                    else
                        descriptions.add("IINC -1");
                    mutationCode.add(mutation);
                }
            }
        } catch (VariableNotFoundException e) {
            logger.info("Could not find variable: " + e);
            return new ArrayList<Mutation>();
        }
    } else {
        InsnList mutation = new InsnList();
        FieldInsnNode node = (FieldInsnNode) instruction.getASMNode();
        Type type = Type.getType(node.desc);
        mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
        mutation.add(new InsnNode(getNegation(type)));
        descriptions.add("Negation");
        mutationCode.add(mutation);

        if (type == Type.INT_TYPE) {
            mutation = new InsnList();
            mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
            mutation.add(new InsnNode(Opcodes.ICONST_1));
            mutation.add(new InsnNode(Opcodes.IADD));
            descriptions.add("+1");
            mutationCode.add(mutation);

            mutation = new InsnList();
            mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
            mutation.add(new InsnNode(Opcodes.ICONST_M1));
            mutation.add(new InsnNode(Opcodes.IADD));
            descriptions.add("-1");
            mutationCode.add(mutation);
        }
    }

    int i = 0;
    for (InsnList mutation : mutationCode) {
        // insert mutation into pool
        Mutation mutationObject = MutationPool.addMutation(className, methodName,
                NAME + " " + descriptions.get(i++), instruction, mutation,
                Mutation.getDefaultInfectionDistance());

        mutations.add(mutationObject);
    }
    return mutations;
}

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 ww  .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

@Override
public void visitInsn(int opcode) {
    Object constant = null;//from w ww  .  java 2  s . co  m
    switch (opcode) {
    case Opcodes.ICONST_0:
        constant = 0;
        break;
    case Opcodes.ICONST_1:
        constant = 1;
        break;
    case Opcodes.ICONST_2:
        constant = 2;
        break;
    case Opcodes.ICONST_3:
        constant = 3;
        break;
    case Opcodes.ICONST_4:
        constant = 4;
        break;
    case Opcodes.ICONST_5:
        constant = 5;
        break;
    case Opcodes.ICONST_M1:
        constant = -1;
        break;
    case Opcodes.LCONST_0:
        constant = 0L;
        break;
    case Opcodes.LCONST_1:
        constant = 1L;
        break;
    case Opcodes.DCONST_0:
        constant = 0.0;
        break;
    case Opcodes.DCONST_1:
        constant = 1.0;
        break;
    case Opcodes.FCONST_0:
        constant = 0f;
        break;
    case Opcodes.FCONST_1:
        constant = 1f;
        break;
    case Opcodes.FCONST_2:
        constant = 2f;
        break;
    }
    if (constant != null) {
        if (DependencyAnalysis.isTargetClassName(className)) {
            poolManager.addSUTConstant(constant);
        } else {
            poolManager.addNonSUTConstant(constant);
        }
    }
    super.visitInsn(opcode);
}

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

License:Open Source License

/**
 * Creates a numeric push instruction./*  w ww  .j  a  v a2s  .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.friz.bytecode.insn.InsnNodeUtility.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.
 * @param push The instruction node.//from   w  ww .ja  v a 2 s.co m
 * @return The numeric value.
 */
public static long getNumericPushValue(AbstractInsnNode push) {
    if (push instanceof InsnNode) {
        switch (push.getOpcode()) {
        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:org.jacoco.core.internal.analysis.filter.StringSwitchJavacFilterTest.java

License:Open Source License

private void createFirstSwitch() {
    final Label h1 = new Label();
    final Label h1_2 = new Label();
    final Label h2 = new Label();
    final Label secondSwitch = new Label();

    m.visitInsn(Opcodes.ICONST_M1);
    m.visitVarInsn(Opcodes.ISTORE, 2);/*from   w w  w .j  ava2  s .  c  om*/

    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    m.visitLookupSwitchInsn(secondSwitch, new int[] { 97, 98 }, new Label[] { h1, h2 });
    expectedFromInclusive = m.instructions.getLast();

    m.visitLabel(h1);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "a", then goto next comparison
    m.visitJumpInsn(Opcodes.IFEQ, h1_2);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h1_2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("\0a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "\0a", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_1);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("b");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "b", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_2);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    m.visitLabel(secondSwitch);
    expectedToInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ILOAD, 2);
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    final Object t1, t2, t3, t4;
    switch (opcode) {
    case Opcodes.NOP:
    case Opcodes.RETURN:
        break;//  w  w  w. j  av  a 2  s.  c  o  m
    case Opcodes.ARETURN:
    case Opcodes.ATHROW:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        pop(1);
        break;
    case Opcodes.DRETURN:
    case Opcodes.LRETURN:
    case Opcodes.POP2:
        pop(2);
        break;
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.FASTORE:
    case Opcodes.IASTORE:
    case Opcodes.SASTORE:
        pop(3);
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        pop(4);
        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(Opcodes.INTEGER);
        break;
    case Opcodes.ARRAYLENGTH:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.INEG:
        pop(1);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.D2I:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.IADD:
    case Opcodes.IALOAD:
    case Opcodes.IAND:
    case Opcodes.IDIV:
    case Opcodes.IMUL:
    case Opcodes.IOR:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.ISUB:
    case Opcodes.IUSHR:
    case Opcodes.IXOR:
    case Opcodes.L2I:
    case Opcodes.SALOAD:
        pop(2);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.LCMP:
        pop(4);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        push(Opcodes.FLOAT);
        break;
    case Opcodes.FNEG:
    case Opcodes.I2F:
        pop(1);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.D2F:
    case Opcodes.FADD:
    case Opcodes.FALOAD:
    case Opcodes.FDIV:
    case Opcodes.FMUL:
    case Opcodes.FREM:
    case Opcodes.FSUB:
    case Opcodes.L2F:
        pop(2);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2L:
    case Opcodes.I2L:
        pop(1);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.D2L:
    case Opcodes.LALOAD:
    case Opcodes.LNEG:
        pop(2);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        pop(3);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LDIV:
    case Opcodes.LMUL:
    case Opcodes.LOR:
    case Opcodes.LREM:
    case Opcodes.LSUB:
    case Opcodes.LXOR:
        pop(4);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2D:
    case Opcodes.I2D:
        pop(1);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DALOAD:
    case Opcodes.DNEG:
    case Opcodes.L2D:
        pop(2);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DADD:
    case Opcodes.DDIV:
    case Opcodes.DMUL:
    case Opcodes.DREM:
    case Opcodes.DSUB:
        pop(4);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.ACONST_NULL:
        push(Opcodes.NULL);
        break;
    case Opcodes.AALOAD:
        pop(1);
        t1 = pop();
        push(Type.getType(((String) t1).substring(1)));
        break;
    case Opcodes.DUP:
        t1 = pop();
        push(t1);
        push(t1);
        break;
    case Opcodes.DUP_X1:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2:
        t1 = pop();
        t2 = pop();
        push(t2);
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X1:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t2);
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        t4 = pop();
        push(t2);
        push(t1);
        push(t4);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.SWAP:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitInsn(opcode);
}