Example usage for org.objectweb.asm Opcodes ISUB

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

Introduction

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

Prototype

int ISUB

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

Click Source Link

Usage

From source file:com.nginious.http.xsp.ForEachTagPart.java

License:Apache License

/**
 * Creates bytecode in a separate method for evaluating this for each tag part.
 * /*from w  w  w .j ava2s  .  c om*/
 * @param intClassName the binary class name of the class being created
 * @param writer the class writer
 * @throws XspException if unable to create bytecode
 */
void compileMethod(String intClassName, ClassWriter writer) throws XspException {
    String[] exceptions = { "com/nginious/http/xsp/XspException" };
    MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PRIVATE, this.methodName,
            "(Lcom/nginious/http/HttpRequest;Lcom/nginious/http/HttpResponse;Ljava/lang/StringBuffer;)V", null,
            exceptions);
    visitor.visitCode();

    Label tryLabel = new Label();
    Label startCatchLabel = new Label();

    // Start try block
    visitor.visitTryCatchBlock(tryLabel, startCatchLabel, startCatchLabel, "java/lang/Exception");
    visitor.visitLabel(tryLabel);

    try {
        String expression = setValue.getExpressionContent();
        ExpressionParser parser = new ExpressionParser();
        TreeExpression expr = parser.parse(expression);

        if (expr.getType() != Type.ANY) {
            throw new XspException("Expression in attribute set in tag " + getName()
                    + " is not an attribute or bean property " + " at line " + getLocationDescriptor());
        }

        expr.compile(visitor, Type.ANY);
        visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Collection");
        visitor.visitVarInsn(Opcodes.ASTORE, 4);
    } catch (ExpressionException e) {
        throw new XspException("Invalid expression in attribute set in tag " + getName() + " at line "
                + getLocationDescriptor(), e);
    }

    Label labelOut = new Label();
    visitor.visitVarInsn(Opcodes.ALOAD, 4);
    visitor.visitJumpInsn(Opcodes.IFNULL, labelOut);

    // Start
    if (this.start != null) {
        start.compile(visitor, Type.INT);
    } else {
        visitor.visitLdcInsn((int) 0);
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 5);

    // End
    if (this.end != null) {
        end.compile(visitor, Type.INT);
    } else {
        visitor.visitVarInsn(Opcodes.ALOAD, 4);
        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I");
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 6);

    // Step
    if (this.step != null) {
        step.compile(visitor, Type.INT);
    } else {
        visitor.visitLdcInsn((int) 1);
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 7);

    // Current pos
    visitor.visitLdcInsn(0);
    visitor.visitVarInsn(Opcodes.ISTORE, 8);

    visitor.visitVarInsn(Opcodes.ALOAD, 4);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "iterator",
            "()Ljava/util/Iterator;");
    visitor.visitVarInsn(Opcodes.ASTORE, 9);

    Label labelStart = new Label();

    // Start of loop
    visitor.visitLabel(labelStart);

    // iterator.hasNext();
    visitor.visitVarInsn(Opcodes.ALOAD, 9);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z");
    visitor.visitJumpInsn(Opcodes.IFEQ, labelOut);

    // iterator.next();
    visitor.visitVarInsn(Opcodes.ALOAD, 9);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;");
    visitor.visitVarInsn(Opcodes.ASTORE, 10);

    // pos >= start && pos <= end && (pos - start) % step == 0
    Label labelIncr = new Label();

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 5);
    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, labelIncr);

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 6);
    visitor.visitJumpInsn(Opcodes.IF_ICMPGT, labelIncr);

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 5);
    visitor.visitInsn(Opcodes.ISUB);
    visitor.visitVarInsn(Opcodes.ILOAD, 7);
    visitor.visitInsn(Opcodes.IREM);
    visitor.visitJumpInsn(Opcodes.IFNE, labelIncr);

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    varName.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ALOAD, 10);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpRequest", "setAttribute",
            "(Ljava/lang/String;Ljava/lang/Object;)V");

    // Call sub parts
    for (XspPart part : this.contentParts) {
        part.compile(intClassName, writer, visitor);
    }

    // pos++
    visitor.visitLabel(labelIncr);
    visitor.visitIincInsn(8, 1);
    visitor.visitJumpInsn(Opcodes.GOTO, labelStart);

    visitor.visitLabel(labelOut);
    visitor.visitInsn(Opcodes.RETURN);

    visitor.visitLabel(startCatchLabel);

    visitor.visitVarInsn(Opcodes.ASTORE, 3);
    visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/XspException");
    visitor.visitInsn(Opcodes.DUP);
    visitor.visitLdcInsn("Attribute set contains an invalid collection for tag " + getName() + " at "
            + getLocationDescriptor());
    visitor.visitVarInsn(Opcodes.ALOAD, 3);
    visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/XspException", "<init>",
            "(Ljava/lang/String;Ljava/lang/Throwable;)V");
    visitor.visitInsn(Opcodes.ATHROW);

    visitor.visitMaxs(11, 11);
    visitor.visitEnd();
}

From source file:com.retroduction.carma.transformer.asm.aor.IADD_2_ISUB_Transition.java

License:Open Source License

public IADD_2_ISUB_Transition() {
    super();
    this.sourceInstruction = Opcodes.IADD;
    this.targetInstruction = Opcodes.ISUB;
}

From source file:com.retroduction.carma.transformer.asm.aor.ISUB_2_IADD_Transition.java

License:Open Source License

public ISUB_2_IADD_Transition() {
    super();
    this.sourceInstruction = Opcodes.ISUB;
    this.targetInstruction = Opcodes.IADD;
}

From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    Expression e;// w  w w.ja v  a  2 s .  co  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.compiler.BytecodeArithmeticExpression.java

@Override
public void generate(CodeEmitter code) {
    MethodVisitor mv = code.getMethodVisitor();
    Label isNull = new Label();
    TypeWidget mathType = getType().unboxed();

    if (!mathType.isPrimitive() || op == ArithmeticOperation.POW) {
        mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(Maths.class), "INSTANCE",
                Type.getDescriptor(Maths.class));
        mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(ArithmeticOperation.class), op.name(),
                Type.getDescriptor(ArithmeticOperation.class));
    }// w  w w .ja  v a  2 s  .  co  m

    CodeEmitter.Unification out = code.unifyAs(mathType, leftExpr, rightExpr, isNull, isNull, isNull);
    // now we have both sides unified as (if possible) a primitive type

    // compute the result
    if (mathType.isPrimitive()) {
        switch (op) {
        case ADD:
            mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IADD));
            break;
        case SUB:
            mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.ISUB));
            break;
        case MULT:
            mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IMUL));
            break;
        case DIV:
            mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IDIV));
            break;
        case MOD:
            mv.visitInsn(mathType.getJVMType().getOpcode(Opcodes.IREM));
            break;
        case POW:
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Maths.class), "binaryMath",
                    Type.getMethodDescriptor(mathType.getJVMType(), Type.getType(ArithmeticOperation.class),
                            mathType.getJVMType(), mathType.getJVMType()),
                    false);
            break;
        default:
            throw new ProgramCompileException(loc, "Unknown BinaryMath operation: " + op);

        }
    } else if (mathType.getValueCoreType() == YQLCoreType.ANY) {
        String desc = Type.getMethodDescriptor(getType().getJVMType(), Type.getType(Maths.class),
                Type.getType(ArithmeticOperation.class), leftExpr.getType().boxed().getJVMType(),
                rightExpr.getType().boxed().getJVMType());
        mv.visitInvokeDynamicInsn("dyn:callMethod:binaryMath", desc, Dynamic.H_DYNALIB_BOOTSTRAP);
    } else {
        throw new ProgramCompileException(loc, "Math operation %s is not defined for type %s", op,
                mathType.getJVMType());
    }

    if (!getType().isPrimitive() && mathType.isPrimitive()) {
        code.box(mathType);
    }

    if (out.nullPossible) {
        Label done = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(isNull);
        if (!mathType.isPrimitive() || op == ArithmeticOperation.POW) {
            mv.visitInsn(Opcodes.POP2);
        }
        mv.visitInsn(Opcodes.ACONST_NULL);
        mv.visitLabel(done);
    }
}

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:// w  w  w .j  ava 2 s. c om
        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;//w w w . ja va 2 s.c o m
    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.illinois.nondex.instr.PriorityBlockingQueueShufflingAdder.java

License:Open Source License

public void addToString() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();/*  www  . ja v a  2 s  .co m*/
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    Label l4 = new Label();
    mv.visitTryCatchBlock(l3, l4, l2, null);
    Label l5 = new Label();
    mv.visitTryCatchBlock(l2, l5, l2, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "lock",
            "Ljava/util/concurrent/locks/ReentrantLock;");
    mv.visitVarInsn(Opcodes.ASTORE, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lock", "()V", false);
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "size", "I");
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitJumpInsn(Opcodes.IFNE, l3);
    mv.visitLdcInsn("[]");
    mv.visitVarInsn(Opcodes.ASTORE, 3);
    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_APPEND, 2,
            new Object[] { "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER }, 0, null);
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
    mv.visitVarInsn(Opcodes.ASTORE, 3);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 91);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "queue",
            "[Ljava/lang/Object;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "[Ljava/lang/Object;", "clone", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
    mv.visitVarInsn(Opcodes.ASTORE, 4);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
    mv.visitVarInsn(Opcodes.ASTORE, 4);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitVarInsn(Opcodes.ISTORE, 5);
    Label l6 = new Label();
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_APPEND, 3,
            new Object[] { "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    Label l7 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l7);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitVarInsn(Opcodes.ASTORE, 6);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitVarInsn(Opcodes.ALOAD, 6);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    Label l8 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ACMPNE, l8);
    mv.visitLdcInsn("(this Collection)");
    Label l9 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l9);
    mv.visitLabel(l8);
    mv.visitFrame(Opcodes.F_FULL, 7,
            new Object[] { "java/util/concurrent/PriorityBlockingQueue",
                    "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder",
                    "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" },
            1, new Object[] { "java/lang/StringBuilder" });
    mv.visitVarInsn(Opcodes.ALOAD, 6);
    mv.visitLabel(l9);
    mv.visitFrame(Opcodes.F_FULL, 7,
            new Object[] { "java/util/concurrent/PriorityBlockingQueue",
                    "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder",
                    "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" },
            2, new Object[] { "java/lang/StringBuilder", "java/lang/Object" });
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.ISUB);
    Label l10 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l10);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 44);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitIntInsn(Opcodes.BIPUSH, 32);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitLabel(l10);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitIincInsn(5, 1);
    mv.visitJumpInsn(Opcodes.GOTO, l6);
    mv.visitLabel(l7);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 93);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;",
            false);
    mv.visitVarInsn(Opcodes.ASTORE, 5);
    mv.visitLabel(l4);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 5);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { "java/util/concurrent/PriorityBlockingQueue",
            "java/util/concurrent/locks/ReentrantLock" }, 1, new Object[] { "java/lang/Throwable" });
    mv.visitVarInsn(Opcodes.ASTORE, 7);
    mv.visitLabel(l5);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 7);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitMaxs(3, 8);
    mv.visitEnd();
}

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;// www. j a v a 2 s . c o  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 w w.  ja  v  a  2 s. c om*/
    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);
}