Example usage for org.objectweb.asm Opcodes DADD

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

Introduction

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

Prototype

int DADD

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

Click Source Link

Usage

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 v  a  2s  .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);
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.CodeEmitterTest.java

@Test
public void requireFloatAdd() throws Exception {
    UnitGenerator unit = new UnitGenerator("foo", source);
    unit.addInterface(Callable.class);
    MethodGenerator gen = unit.createMethod("call");
    gen.setReturnType(AnyTypeWidget.getInstance());
    final BytecodeExpression leftExpr = source.constant(1);
    final BytecodeExpression rightExpr = source.constant(1.0f);

    gen.add(new BytecodeSequence() {
        @Override/*from ww w .j  av a 2 s  . c  om*/
        public void generate(CodeEmitter code) {
            Label hasNull = new Label();
            CodeEmitter.Unification unify = code.unifiedEmit(leftExpr, rightExpr, hasNull);
            code.getMethodVisitor().visitInsn(Opcodes.DADD);
            code.box(BaseTypeAdapter.FLOAT64);
            code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            if (unify.nullPossible) {
                code.getMethodVisitor().visitLabel(hasNull);
                code.getMethodVisitor().visitInsn(Opcodes.ACONST_NULL);
                code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            }
        }
    });

    source.build();
    Class<? extends Callable> clazz = (Class<? extends Callable>) source.getGeneratedClass(unit);
    Callable c = clazz.newInstance();
    Assert.assertEquals(2.0, c.call());
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.CodeEmitterTest.java

@Test
public void requireBoxedAdd() throws Exception {
    UnitGenerator unit = new UnitGenerator("foo", source);
    unit.addInterface(Callable.class);
    MethodGenerator gen = unit.createMethod("call");
    gen.setReturnType(AnyTypeWidget.getInstance());
    final BytecodeExpression leftExpr = source.constant(BaseTypeAdapter.INT32.boxed(), 1);
    final BytecodeExpression rightExpr = source.constant(1.0f);

    gen.add(new BytecodeSequence() {
        @Override//from  www. j ava2 s  . c o m
        public void generate(CodeEmitter code) {
            Label hasNull = new Label();
            CodeEmitter.Unification unify = code.unifiedEmit(leftExpr, rightExpr, hasNull);
            code.getMethodVisitor().visitInsn(Opcodes.DADD);
            code.box(BaseTypeAdapter.FLOAT64);
            code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            if (unify.nullPossible) {
                code.getMethodVisitor().visitLabel(hasNull);
                code.getMethodVisitor().visitInsn(Opcodes.ACONST_NULL);
                code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            }
        }
    });

    source.build();
    Class<? extends Callable> clazz = (Class<? extends Callable>) source.getGeneratedClass(unit);
    Callable c = clazz.newInstance();
    Assert.assertEquals(2.0, c.call());
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.CodeEmitterTest.java

@Test
public void requireBoxedNull() throws Exception {
    UnitGenerator unit = new UnitGenerator("foo", source);
    unit.addInterface(Callable.class);
    MethodGenerator gen = unit.createMethod("call");
    gen.setReturnType(AnyTypeWidget.getInstance());
    final BytecodeExpression rightExpr = source.constant(1.0f);

    gen.add(new BytecodeSequence() {
        @Override//from w w  w .  j  a  v a 2s . co  m
        public void generate(CodeEmitter code) {
            Label hasNull = new Label();
            CodeEmitter.Unification unify = code.unifiedEmit(new NullExpr(BaseTypeAdapter.INT32.boxed()),
                    rightExpr, hasNull);
            code.getMethodVisitor().visitInsn(Opcodes.DADD);
            code.box(BaseTypeAdapter.FLOAT64);
            code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            if (unify.nullPossible) {
                code.getMethodVisitor().visitLabel(hasNull);
                code.getMethodVisitor().visitInsn(Opcodes.ACONST_NULL);
                code.getMethodVisitor().visitInsn(Opcodes.ARETURN);
            }
        }
    });

    source.build();
    Class<? extends Callable> clazz = (Class<? extends Callable>) source.getGeneratedClass(unit);
    Callable c = clazz.newInstance();
    Assert.assertNull(c.call());
}

From source file:de.sanandrew.core.manpack.transformer.TransformEntityThrowable.java

License:Creative Commons License

private static byte[] transformLqThrowable(byte[] bytes) {
    ClassNode classNode = ASMHelper.createClassNode(bytes);

    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PUBLIC, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID);

    method.visitCode();//from   w  w w.  ja v a  2s.  c om
    Label label1 = new Label();
    method.visitLabel(label1);
    method.visitInsn(Opcodes.ICONST_0);
    method.visitInsn(Opcodes.IRETURN);
    Label label2 = new Label();
    method.visitLabel(label2);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_THROWABLE, null, label1, label2, 0);
    method.visitMaxs(0, 0);
    method.visitEnd();
    classNode.methods.add(method);

    method = ASMHelper.findMethod(classNode, ASMNames.MD_THROWABLE_ON_UPDATE);

    InsnList needle = new InsnList();
    needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_MOTION_Z));
    needle.add(new InsnNode(Opcodes.DADD));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_VEC3_CREATE_VECTOR_HELPER, false));
    needle.add(new VarInsnNode(Opcodes.ASTORE, 2));
    needle.add(new LabelNode());
    needle.add(new LineNumberNode(-1, new LabelNode()));
    needle.add(new VarInsnNode(Opcodes.ALOAD, 0));
    needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ));
    needle.add(new VarInsnNode(Opcodes.ALOAD, 1));
    needle.add(new VarInsnNode(Opcodes.ALOAD, 2));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS, false));
    needle.add(new VarInsnNode(Opcodes.ASTORE, -1));

    VarInsnNode insertPoint = (VarInsnNode) ASMHelper.findLastNodeFromNeedle(method.instructions, needle);

    InsnList injectList = new InsnList();
    injectList.add(new LabelNode());
    injectList.add(new VarInsnNode(Opcodes.ALOAD, 0));
    injectList.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ));
    injectList.add(new VarInsnNode(Opcodes.ALOAD, 1));
    injectList.add(new VarInsnNode(Opcodes.ALOAD, 2));
    injectList.add(new VarInsnNode(Opcodes.ALOAD, 0));
    injectList.add(
            ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID, false));
    injectList.add(
            ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS_Z, false));
    injectList.add(new VarInsnNode(Opcodes.ASTORE, insertPoint.var));

    method.instructions.insert(insertPoint, injectList);

    return ASMHelper.createBytes(classNode, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS);
}

From source file:de.tuberlin.uebb.jbop.optimizer.array.FieldArrayValueInlinerTest.java

License:Open Source License

/**
 * Tests that FieldArrayValueInliner is working correctly.
 * //from w  ww  . j a va  2s. c  o m
 * @throws Exception
 *           the exception
 */
@Test
public void testFieldArrayValueInliner() throws Exception {
    // INIT
    final String owner = "de.tuberlin.uebb.jbop.optimizer.array.FieldArrayValueTestClass";
    final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).//
            addField("doubleArray1", "[D").withAnnotation(ImmutableArray.class).initArrayWith(1.0, 2.0, 3.0).//
            addField("doubleArray2", "[D").withAnnotation(ImmutableArray.class).initArrayWith(4.0, 5.0, 6.0).//
            addMethod("sumArrayValues", "()D").withAnnotation(Optimizable.class).//
            loadFieldArrayValue("doubleArray1", 0).// 4 -> 1
            loadFieldArrayValue("doubleArray2", 0).// 4 -> 1
            addInsn(new InsnNode(Opcodes.DADD)).// 1
            loadFieldArrayValue("doubleArray1", 1).// 4 -> 1
            loadFieldArrayValue("doubleArray2", 1).// 4 -> 1
            addInsn(new InsnNode(Opcodes.DADD)).// 1
            addInsn(new InsnNode(Opcodes.DADD)).// 1
            loadFieldArrayValue("doubleArray1", 2).// 4 -> 1
            loadFieldArrayValue("doubleArray2", 2).// 4 -> 1
            addInsn(new InsnNode(Opcodes.DADD)).// 1
            addInsn(new InsnNode(Opcodes.DADD)).// 1
            addInsn(new InsnNode(Opcodes.DRETURN));// 1
    //

    final FieldArrayValueInliner inliner = new FieldArrayValueInliner();
    inliner.setClassNode(builder.getClassNode());
    inliner.setInputObject(builder.instance());

    final MethodNode method = builder.getMethod("sumArrayValues");
    assertEquals(30, method.instructions.size());

    // RUN STEP 1
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT STEP 1

    assertEquals(12, optimized.size());

    // first value pair
    AbstractInsnNode currentNode = optimized.getFirst();
    assertEquals(1.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);
    currentNode = currentNode.getNext();
    assertEquals(4.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);
    currentNode = currentNode.getNext();

    // second value pair
    currentNode = currentNode.getNext();
    assertEquals(2.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);
    currentNode = currentNode.getNext();
    assertEquals(5.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);
    currentNode = currentNode.getNext();
    currentNode = currentNode.getNext();

    // third value pair
    currentNode = currentNode.getNext();
    assertEquals(3.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);
    currentNode = currentNode.getNext();
    assertEquals(6.0, NodeHelper.getNumberValue(currentNode).doubleValue(), .0001);

    // RUN STEP 3
    final InsnList optimized3 = inliner.optimize(method.instructions, method);

    // ASSERT STEP 3
    assertEquals(12, optimized3.size());
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.SimpleInstruction.java

License:Open Source License

@Override
public String toString() {
    switch (getOpcode()) {
    // the not interesting ones:
    case Opcodes.NOP:
        return "NOP";
    // constants:
    case Opcodes.ACONST_NULL:
        return "ACONST_NULL";
    case Opcodes.ICONST_M1:
        return "ICONST_M1";
    case Opcodes.ICONST_0:
        return "ICONST_0";
    case Opcodes.ICONST_1:
        return "ICONST_1";
    case Opcodes.ICONST_2:
        return "ICONST_2";
    case Opcodes.ICONST_3:
        return "ICONST_3";
    case Opcodes.ICONST_4:
        return "ICONST_4";
    case Opcodes.ICONST_5:
        return "ICONST_5";
    case Opcodes.LCONST_0:
        return "LCONST_0";
    case Opcodes.LCONST_1:
        return "LCONST_1";
    case Opcodes.FCONST_0:
        return "FCONST_0";
    case Opcodes.FCONST_1:
        return "FCONST_1";
    case Opcodes.FCONST_2:
        return "FCONST_2";
    case Opcodes.DCONST_0:
        return "DCONST_0";
    case Opcodes.DCONST_1:
        return "DCONST_1";

    // array load:
    case Opcodes.IALOAD:
        return "IALOAD";
    case Opcodes.LALOAD:
        return "LALOAD";
    case Opcodes.FALOAD:
        return "FALOAD";
    case Opcodes.DALOAD:
        return "DALOAD";
    case Opcodes.AALOAD:
        return "AALOAD";
    case Opcodes.BALOAD:
        return "BALOAD";
    case Opcodes.CALOAD:
        return "CALOAD";
    case Opcodes.SALOAD:
        return "SALOAD";

    // array store:
    case Opcodes.IASTORE:
        return "IASTORE";
    case Opcodes.LASTORE:
        return "LASTORE";
    case Opcodes.FASTORE:
        return "FASTORE";
    case Opcodes.DASTORE:
        return "DASTORE";
    case Opcodes.AASTORE:
        return "AASTORE";
    case Opcodes.BASTORE:
        return "BASTORE";
    case Opcodes.CASTORE:
        return "CASTORE";
    case Opcodes.SASTORE:
        return "SASTORE";

    // stack manipulation:
    case Opcodes.POP:
        return "POP";
    case Opcodes.POP2:
        return "POP2";
    case Opcodes.DUP:
        return "DUP";
    case Opcodes.DUP_X1:
        return "DUP_X1";
    case Opcodes.DUP_X2:
        return "DUP_X2";
    case Opcodes.DUP2:
        return "DUP2";
    case Opcodes.DUP2_X1:
        return "DUP2_X1";
    case Opcodes.DUP2_X2:
        return "DUP2_X2";
    case Opcodes.SWAP:
        return "SWAP";

    // arithmetic:
    case Opcodes.IADD:
        return "IADD";
    case Opcodes.LADD:
        return "LADD";
    case Opcodes.FADD:
        return "FADD";
    case Opcodes.DADD:
        return "DADD";
    case Opcodes.ISUB:
        return "ISUB";
    case Opcodes.LSUB:
        return "LSUB";
    case Opcodes.FSUB:
        return "FSUB";
    case Opcodes.DSUB:
        return "DSUB";
    case Opcodes.IMUL:
        return "IMUL";
    case Opcodes.LMUL:
        return "LMUL";
    case Opcodes.FMUL:
        return "FMUL";
    case Opcodes.DMUL:
        return "DMUL";
    case Opcodes.IDIV:
        return "IDIV";
    case Opcodes.LDIV:
        return "LDIV";
    case Opcodes.FDIV:
        return "FDIV";
    case Opcodes.DDIV:
        return "DDIV";
    case Opcodes.IREM:
        return "IREM";
    case Opcodes.LREM:
        return "LREM";
    case Opcodes.FREM:
        return "FREM";
    case Opcodes.DREM:
        return "DREM";
    case Opcodes.INEG:
        return "INEG";
    case Opcodes.LNEG:
        return "LNEG";
    case Opcodes.FNEG:
        return "FNEG";
    case Opcodes.DNEG:
        return "DNEG";
    case Opcodes.ISHL:
        return "ISHL";
    case Opcodes.LSHL:
        return "LSHL";
    case Opcodes.ISHR:
        return "ISHR";
    case Opcodes.LSHR:
        return "LSHR";
    case Opcodes.IUSHR:
        return "IUSHR";
    case Opcodes.LUSHR:
        return "LUSHR";
    case Opcodes.IAND:
        return "IAND";
    case Opcodes.LAND:
        return "LAND";
    case Opcodes.IOR:
        return "IOR";
    case Opcodes.LOR:
        return "LOR";
    case Opcodes.IXOR:
        return "IXOR";
    case Opcodes.LXOR:
        return "LXOR";

    // type conversions:
    case Opcodes.I2L:
        return "I2L";
    case Opcodes.I2F:
        return "I2F";
    case Opcodes.I2D:
        return "I2D";
    case Opcodes.L2I:
        return "L2I";
    case Opcodes.L2F:
        return "L2F";
    case Opcodes.L2D:
        return "L2D";
    case Opcodes.F2I:
        return "F2I";
    case Opcodes.F2L:
        return "F2L";
    case Opcodes.F2D:
        return "F2D";
    case Opcodes.D2I:
        return "D2I";
    case Opcodes.D2L:
        return "D2L";
    case Opcodes.D2F:
        return "D2F";
    case Opcodes.I2B:
        return "I2B";
    case Opcodes.I2C:
        return "I2C";
    case Opcodes.I2S:
        return "I2S";

    // comparison:
    case Opcodes.LCMP:
        return "LCMP";
    case Opcodes.FCMPL:
        return "FCMPL";
    case Opcodes.FCMPG:
        return "FCMPG";
    case Opcodes.DCMPL:
        return "DCMPL";
    case Opcodes.DCMPG:
        return "DCMPG";

    // control-flow statements:
    case Opcodes.IRETURN:
        return "IRETURN";
    case Opcodes.LRETURN:
        return "LRETURN";
    case Opcodes.FRETURN:
        return "FRETURN";
    case Opcodes.DRETURN:
        return "DRETURN";
    case Opcodes.ARETURN:
        return "ARETURN";
    case Opcodes.RETURN:
        return "RETURN";

    // special things
    case Opcodes.ARRAYLENGTH:
        return "ARRAYLENGTH";
    case Opcodes.ATHROW:
        return "ATHROW";
    case Opcodes.MONITORENTER:
        return "MONITORENTER";
    case Opcodes.MONITOREXIT:
        return "MONITOREXIT";

    default://from  w w  w  . j  a  va2s . c  o m
        assert false;
        return "--ERROR--";
    }
}

From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java

License:BSD License

@Override
public void visitInsn(final int opcode) {
    super.visitInsn(opcode);
    switch (opcode) {
    case Opcodes.IRETURN: // 1 before n/a after
    case Opcodes.FRETURN: // 1 before n/a after
    case Opcodes.ARETURN: // 1 before n/a after
    case Opcodes.ATHROW: // 1 before n/a after
        this.stackFrame.pop();
        break;//from w  w  w .  j  a v  a  2 s. c  om
    case Opcodes.LRETURN: // 2 before n/a after
    case Opcodes.DRETURN: // 2 before n/a after
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.NOP:
    case Opcodes.LALOAD: // remove 2 add 2
    case Opcodes.DALOAD: // remove 2 add 2
    case Opcodes.LNEG:
    case Opcodes.DNEG:
    case Opcodes.FNEG:
    case Opcodes.INEG:
    case Opcodes.L2D:
    case Opcodes.D2L:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.I2F:
    case Opcodes.ARRAYLENGTH:
        break;
    case Opcodes.ACONST_NULL:
    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.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.F2L: // 1 before 2 after
    case Opcodes.F2D:
    case Opcodes.I2L:
    case Opcodes.I2D:
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        this.stackFrame.push(OTHER);
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.IALOAD: // remove 2 add 1
    case Opcodes.FALOAD: // remove 2 add 1
    case Opcodes.AALOAD: // remove 2 add 1
    case Opcodes.BALOAD: // remove 2 add 1
    case Opcodes.CALOAD: // remove 2 add 1
    case Opcodes.SALOAD: // remove 2 add 1
    case Opcodes.POP:
    case Opcodes.IADD:
    case Opcodes.FADD:
    case Opcodes.ISUB:
    case Opcodes.LSHL: // 3 before 2 after
    case Opcodes.LSHR: // 3 before 2 after
    case Opcodes.LUSHR: // 3 before 2 after
    case Opcodes.L2I: // 2 before 1 after
    case Opcodes.L2F: // 2 before 1 after
    case Opcodes.D2I: // 2 before 1 after
    case Opcodes.D2F: // 2 before 1 after
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FCMPL: // 2 before 1 after
    case Opcodes.FCMPG: // 2 before 1 after
    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.MONITORENTER:
    case Opcodes.MONITOREXIT:
        this.stackFrame.pop();
        break;
    case Opcodes.POP2:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.DADD:
    case Opcodes.DMUL:
    case Opcodes.DSUB:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.IASTORE:
    case Opcodes.FASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.LCMP: // 4 before 1 after
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.DUP:
        this.stackFrame.push(this.stackFrame.peek());
        break;
    case Opcodes.DUP_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.SWAP: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.remove(_s);
        break;
    }
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void interpret(InsnNode insn, FrameState frame, BBInfo block) {
    ReturnType returnType = block.block.getParent().getType().getReturnType();
    switch (insn.getOpcode()) {
    case Opcodes.NOP:
        break;/*from ww  w.  ja va2  s .  co  m*/
    //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)">
    case Opcodes.POP:
        assert frame.stack.peek().getType().getCategory() == 1;
        frame.stack.pop();
        break;
    case Opcodes.POP2:
        final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } };
        conditionallyPermute(frame, pop2Permutations);
        break;
    case Opcodes.DUP:
        final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } };
        conditionallyPermute(frame, dupPermutations);
        break;
    case Opcodes.DUP_X1:
        final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x1Permutations);
        break;
    case Opcodes.DUP_X2:
        final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x2Permutations);
        break;
    case Opcodes.DUP2:
        final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } };
        conditionallyPermute(frame, dup2Permutations);
        break;
    case Opcodes.DUP2_X1:
        final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x1Permutations);
        break;
    case Opcodes.DUP2_X2:
        final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } },
                { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } },
                { { 2, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x2Permutations);
        break;
    case Opcodes.SWAP:
        final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } };
        conditionallyPermute(frame, swapPermutations);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)">
    case Opcodes.ACONST_NULL:
        frame.stack.push(module.constants().getNullConstant());
        break;
    case Opcodes.ICONST_M1:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        break;
    case Opcodes.ICONST_0:
        frame.stack.push(module.constants().getSmallestIntConstant(0));
        break;
    case Opcodes.ICONST_1:
        frame.stack.push(module.constants().getSmallestIntConstant(1));
        break;
    case Opcodes.ICONST_2:
        frame.stack.push(module.constants().getSmallestIntConstant(2));
        break;
    case Opcodes.ICONST_3:
        frame.stack.push(module.constants().getSmallestIntConstant(3));
        break;
    case Opcodes.ICONST_4:
        frame.stack.push(module.constants().getSmallestIntConstant(4));
        break;
    case Opcodes.ICONST_5:
        frame.stack.push(module.constants().getSmallestIntConstant(5));
        break;
    case Opcodes.LCONST_0:
        frame.stack.push(module.constants().getConstant(0L));
        break;
    case Opcodes.LCONST_1:
        frame.stack.push(module.constants().getConstant(1L));
        break;
    case Opcodes.FCONST_0:
        frame.stack.push(module.constants().getConstant(0f));
        break;
    case Opcodes.FCONST_1:
        frame.stack.push(module.constants().getConstant(1f));
        break;
    case Opcodes.FCONST_2:
        frame.stack.push(module.constants().getConstant(2f));
        break;
    case Opcodes.DCONST_0:
        frame.stack.push(module.constants().getConstant(0d));
        break;
    case Opcodes.DCONST_1:
        frame.stack.push(module.constants().getConstant(1d));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Return opcodes">
    case Opcodes.IRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(int.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.LRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(long.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.FRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(float.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.DRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(double.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.ARETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(Object.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.RETURN:
        assert returnType instanceof VoidType || method.isConstructor();
        block.block.instructions().add(new ReturnInst(typeFactory.getVoidType()));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)">
    //Unary minus is rendered as a multiplication by -1.  (The obvious
    //other choice, subtraction from 0, is not equivalent for floats and
    //doubles due to negative zero.)
    case Opcodes.INEG:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.LNEG:
        frame.stack.push(module.constants().getConstant(-1L));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.FNEG:
        frame.stack.push(module.constants().getConstant(-1f));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.DNEG:
        frame.stack.push(module.constants().getConstant(-1d));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Binary math opcodes">
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        binary(BinaryInst.Operation.ADD, frame, block);
        break;
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        binary(BinaryInst.Operation.SUB, frame, block);
        break;
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        binary(BinaryInst.Operation.DIV, frame, block);
        break;
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        binary(BinaryInst.Operation.REM, frame, block);
        break;
    case Opcodes.ISHL:
    case Opcodes.LSHL:
        binary(BinaryInst.Operation.SHL, frame, block);
        break;
    case Opcodes.ISHR:
    case Opcodes.LSHR:
        binary(BinaryInst.Operation.SHR, frame, block);
        break;
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        binary(BinaryInst.Operation.USHR, frame, block);
        break;
    case Opcodes.IAND:
    case Opcodes.LAND:
        binary(BinaryInst.Operation.AND, frame, block);
        break;
    case Opcodes.IOR:
    case Opcodes.LOR:
        binary(BinaryInst.Operation.OR, frame, block);
        break;
    case Opcodes.IXOR:
    case Opcodes.LXOR:
        binary(BinaryInst.Operation.XOR, frame, block);
        break;
    case Opcodes.LCMP:
    case Opcodes.FCMPL:
    case Opcodes.DCMPL:
        binary(BinaryInst.Operation.CMP, frame, block);
        break;
    case Opcodes.FCMPG:
    case Opcodes.DCMPG:
        binary(BinaryInst.Operation.CMPG, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Primitive casts">
    case Opcodes.I2L:
        cast(int.class, long.class, frame, block);
        break;
    case Opcodes.I2F:
        cast(int.class, float.class, frame, block);
        break;
    case Opcodes.I2D:
        cast(int.class, double.class, frame, block);
        break;
    case Opcodes.L2I:
        cast(long.class, int.class, frame, block);
        break;
    case Opcodes.L2F:
        cast(long.class, float.class, frame, block);
        break;
    case Opcodes.L2D:
        cast(long.class, double.class, frame, block);
        break;
    case Opcodes.F2I:
        cast(float.class, int.class, frame, block);
        break;
    case Opcodes.F2L:
        cast(float.class, long.class, frame, block);
        break;
    case Opcodes.F2D:
        cast(float.class, double.class, frame, block);
        break;
    case Opcodes.D2I:
        cast(double.class, int.class, frame, block);
        break;
    case Opcodes.D2L:
        cast(double.class, long.class, frame, block);
        break;
    case Opcodes.D2F:
        cast(double.class, float.class, frame, block);
        break;
    case Opcodes.I2B:
        cast(int.class, byte.class, frame, block);
        break;
    case Opcodes.I2C:
        cast(int.class, char.class, frame, block);
        break;
    case Opcodes.I2S:
        cast(int.class, short.class, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array store opcodes">
    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
        Value data = frame.stack.pop();
        Value index = frame.stack.pop();
        Value array = frame.stack.pop();
        ArrayStoreInst asi = new ArrayStoreInst(array, index, data);
        block.block.instructions().add(asi);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array load opcodes">
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.AALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        Value index2 = frame.stack.pop();
        Value array2 = frame.stack.pop();
        ArrayLoadInst ali = new ArrayLoadInst(array2, index2);
        block.block.instructions().add(ali);
        frame.stack.push(ali);
        break;
    //</editor-fold>
    case Opcodes.ARRAYLENGTH:
        ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop());
        block.block.instructions().add(lengthInst);
        frame.stack.push(lengthInst);
        break;
    case Opcodes.ATHROW:
        block.block.instructions().add(new ThrowInst(frame.stack.pop()));
        break;
    default:
        throw new UnsupportedOperationException("" + insn.getOpcode());
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(BinaryInst i, InsnList insns) {
    load(i.getOperand(0), insns);/*  w  ww  .  ja  v  a  2s . c o m*/
    load(i.getOperand(1), insns);
    int opcode = 0;
    if (i.getOperand(0).getType().isSubtypeOf(intType)) {
        switch (i.getOperation()) {
        case ADD:
            opcode = Opcodes.IADD;
            break;
        case SUB:
            opcode = Opcodes.ISUB;
            break;
        case MUL:
            opcode = Opcodes.IMUL;
            break;
        case DIV:
            opcode = Opcodes.IDIV;
            break;
        case REM:
            opcode = Opcodes.IREM;
            break;
        case SHL:
            opcode = Opcodes.ISHL;
            break;
        case SHR:
            opcode = Opcodes.ISHR;
            break;
        case USHR:
            opcode = Opcodes.ISHR;
            break;
        case AND:
            opcode = Opcodes.IAND;
            break;
        case OR:
            opcode = Opcodes.IOR;
            break;
        case XOR:
            opcode = Opcodes.IXOR;
            break;
        default:
            throw new AssertionError(i);
        }
    } else if (i.getOperand(0).getType().equals(longType)) {
        switch (i.getOperation()) {
        case ADD:
            opcode = Opcodes.LADD;
            break;
        case SUB:
            opcode = Opcodes.LSUB;
            break;
        case MUL:
            opcode = Opcodes.LMUL;
            break;
        case DIV:
            opcode = Opcodes.LDIV;
            break;
        case REM:
            opcode = Opcodes.LREM;
            break;
        case SHL:
            opcode = Opcodes.LSHL;
            break;
        case SHR:
            opcode = Opcodes.LSHR;
            break;
        case USHR:
            opcode = Opcodes.LSHR;
            break;
        case AND:
            opcode = Opcodes.LAND;
            break;
        case OR:
            opcode = Opcodes.LOR;
            break;
        case XOR:
            opcode = Opcodes.LXOR;
            break;
        case CMP:
            opcode = Opcodes.LCMP;
            break;
        default:
            throw new AssertionError(i);
        }
    } else if (i.getOperand(0).getType().equals(floatType)) {
        switch (i.getOperation()) {
        case ADD:
            opcode = Opcodes.FADD;
            break;
        case SUB:
            opcode = Opcodes.FSUB;
            break;
        case MUL:
            opcode = Opcodes.FMUL;
            break;
        case DIV:
            opcode = Opcodes.FDIV;
            break;
        case REM:
            opcode = Opcodes.FREM;
            break;
        case CMP:
            opcode = Opcodes.FCMPL;
            break;
        case CMPG:
            opcode = Opcodes.FCMPG;
            break;
        default:
            throw new AssertionError(i);
        }
    } else if (i.getOperand(0).getType().equals(doubleType)) {
        switch (i.getOperation()) {
        case ADD:
            opcode = Opcodes.DADD;
            break;
        case SUB:
            opcode = Opcodes.DSUB;
            break;
        case MUL:
            opcode = Opcodes.DMUL;
            break;
        case DIV:
            opcode = Opcodes.DDIV;
            break;
        case REM:
            opcode = Opcodes.DREM;
            break;
        case CMP:
            opcode = Opcodes.DCMPL;
            break;
        case CMPG:
            opcode = Opcodes.DCMPG;
            break;
        default:
            throw new AssertionError(i);
        }
    } else
        throw new AssertionError(i);
    insns.add(new InsnNode(opcode));
    store(i, insns);
}