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:br.ufpr.gres.core.operators.method_level.AOR2.java

License:Apache License

private String getOp(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        return "+";
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        return "-";
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        return "*";
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        return "/";
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        return "%";
    }/*from   w  w  w.  ja v  a  2s.co  m*/
    throw new RuntimeException("Unknown opcode: " + opcode);
}

From source file:bytecode.InstructionExporter.java

License:Apache License

/**
 * Outputs all arithmetic instructions, selecting the correct opcode for the
 * required type etc.//w  w  w.  j  a  v a2s. c  o  m
 *
 * @param instruction Arithmetic instruction.
 * @return            <code>null</code>
 */
@Override
public Void visit(Arithmetic instruction) {
    switch (instruction.getOperator()) {
    case ADD:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IADD);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LADD);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FADD);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DADD);
            break;
        }
        break;
    case SUB:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.ISUB);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LSUB);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FSUB);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DSUB);
            break;
        }
        break;
    case MUL:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IMUL);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LMUL);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FMUL);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DMUL);
            break;
        }
        break;
    case DIV:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IDIV);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LDIV);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FDIV);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DDIV);
            break;
        }
        break;
    case REM:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IREM);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LREM);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FREM);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DREM);
            break;
        }
        break;
    case AND:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IAND);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LAND);
            break;
        }
        break;
    case OR:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IOR);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LOR);
            break;
        }
        break;
    case XOR:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IXOR);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LXOR);
            break;
        }
        break;
    case SHL:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.ISHL);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LSHL);
            break;
        }
        break;
    case SHR:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.ISHR);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LSHR);
            break;
        }
        break;
    case USHR:
        switch (instruction.getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IUSHR);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LUSHR);
            break;
        }
        break;
    }

    return null;
}

From source file:bytecode.MethodImporter.java

License:Apache License

/**
 * Imports instructions with no immediate operands.
 *
 * @param opcode Opcode./*from  w w w . java2  s .c o  m*/
 */
@Override
public void visitInsn(final int opcode) {
    Producer a, b, c, d;
    Type top;

    switch (opcode) {
    // Constants
    case Opcodes.ACONST_NULL:
        createConstant(null);
        break;
    case Opcodes.ICONST_M1:
        createConstant(new Integer(-1));
        break;
    case Opcodes.ICONST_0:
        createConstant(new Integer(0));
        break;
    case Opcodes.ICONST_1:
        createConstant(new Integer(1));
        break;
    case Opcodes.ICONST_2:
        createConstant(new Integer(2));
        break;
    case Opcodes.ICONST_3:
        createConstant(new Integer(3));
        break;
    case Opcodes.ICONST_4:
        createConstant(new Integer(4));
        break;
    case Opcodes.ICONST_5:
        createConstant(new Integer(5));
        break;
    case Opcodes.LCONST_0:
        createConstant(new Long(0));
        break;
    case Opcodes.LCONST_1:
        createConstant(new Long(1));
        break;
    case Opcodes.FCONST_0:
        createConstant(new Float(0.0f));
        break;
    case Opcodes.FCONST_1:
        createConstant(new Float(1.0f));
        break;
    case Opcodes.FCONST_2:
        createConstant(new Float(2.0f));
        break;
    case Opcodes.DCONST_0:
        createConstant(new Double(0.0f));
        break;
    case Opcodes.DCONST_1:
        createConstant(new Double(1.0f));
        break;

    // Binary Operations
    case Opcodes.IADD:
        createArithmetic(Arithmetic.Operator.ADD, Type.INT);
        break;
    case Opcodes.LADD:
        createArithmetic(Arithmetic.Operator.ADD, Type.LONG);
        break;
    case Opcodes.FADD:
        createArithmetic(Arithmetic.Operator.ADD, Type.FLOAT);
        break;
    case Opcodes.DADD:
        createArithmetic(Arithmetic.Operator.ADD, Type.DOUBLE);
        break;
    case Opcodes.ISUB:
        createArithmetic(Arithmetic.Operator.SUB, Type.INT);
        break;
    case Opcodes.LSUB:
        createArithmetic(Arithmetic.Operator.SUB, Type.LONG);
        break;
    case Opcodes.FSUB:
        createArithmetic(Arithmetic.Operator.SUB, Type.FLOAT);
        break;
    case Opcodes.DSUB:
        createArithmetic(Arithmetic.Operator.SUB, Type.DOUBLE);
        break;
    case Opcodes.IMUL:
        createArithmetic(Arithmetic.Operator.MUL, Type.INT);
        break;
    case Opcodes.LMUL:
        createArithmetic(Arithmetic.Operator.MUL, Type.LONG);
        break;
    case Opcodes.FMUL:
        createArithmetic(Arithmetic.Operator.MUL, Type.FLOAT);
        break;
    case Opcodes.DMUL:
        createArithmetic(Arithmetic.Operator.MUL, Type.DOUBLE);
        break;
    case Opcodes.IDIV:
        createArithmetic(Arithmetic.Operator.DIV, Type.INT);
        break;
    case Opcodes.LDIV:
        createArithmetic(Arithmetic.Operator.DIV, Type.LONG);
        break;
    case Opcodes.FDIV:
        createArithmetic(Arithmetic.Operator.DIV, Type.FLOAT);
        break;
    case Opcodes.DDIV:
        createArithmetic(Arithmetic.Operator.DIV, Type.DOUBLE);
        break;
    case Opcodes.IREM:
        createArithmetic(Arithmetic.Operator.REM, Type.INT);
        break;
    case Opcodes.LREM:
        createArithmetic(Arithmetic.Operator.REM, Type.LONG);
        break;
    case Opcodes.FREM:
        createArithmetic(Arithmetic.Operator.REM, Type.FLOAT);
        break;
    case Opcodes.DREM:
        createArithmetic(Arithmetic.Operator.REM, Type.DOUBLE);
        break;
    case Opcodes.IAND:
        createArithmetic(Arithmetic.Operator.AND, Type.INT);
        break;
    case Opcodes.LAND:
        createArithmetic(Arithmetic.Operator.AND, Type.LONG);
        break;
    case Opcodes.IOR:
        createArithmetic(Arithmetic.Operator.OR, Type.INT);
        break;
    case Opcodes.LOR:
        createArithmetic(Arithmetic.Operator.OR, Type.LONG);
        break;
    case Opcodes.IXOR:
        createArithmetic(Arithmetic.Operator.XOR, Type.INT);
        break;
    case Opcodes.LXOR:
        createArithmetic(Arithmetic.Operator.XOR, Type.LONG);
        break;
    case Opcodes.ISHL:
        createArithmetic(Arithmetic.Operator.SHL, Type.INT);
        break;
    case Opcodes.LSHL:
        createArithmetic(Arithmetic.Operator.SHL, Type.LONG);
        break;
    case Opcodes.ISHR:
        createArithmetic(Arithmetic.Operator.SHR, Type.INT);
        break;
    case Opcodes.LSHR:
        createArithmetic(Arithmetic.Operator.SHR, Type.LONG);
        break;
    case Opcodes.IUSHR:
        createArithmetic(Arithmetic.Operator.USHR, Type.INT);
        break;
    case Opcodes.LUSHR:
        createArithmetic(Arithmetic.Operator.USHR, Type.LONG);
        break;

    case Opcodes.LCMP:
        createCompare(false, Type.LONG);
        break;
    case Opcodes.FCMPL:
        createCompare(false, Type.FLOAT);
        break;
    case Opcodes.FCMPG:
        createCompare(true, Type.FLOAT);
        break;
    case Opcodes.DCMPL:
        createCompare(false, Type.DOUBLE);
        break;
    case Opcodes.DCMPG:
        createCompare(true, Type.DOUBLE);
        break;
    case Opcodes.INEG:
        createNegate();
        break;
    case Opcodes.LNEG:
        createNegate();
        break;
    case Opcodes.FNEG:
        createNegate();
        break;
    case Opcodes.DNEG:
        createNegate();
        break;
    case Opcodes.I2L:
        createConvert(Type.LONG);
        break;
    case Opcodes.I2F:
        createConvert(Type.FLOAT);
        break;
    case Opcodes.I2D:
        createConvert(Type.DOUBLE);
        break;
    case Opcodes.I2B:
        createConvert(Type.BYTE);
        break;
    case Opcodes.I2C:
        createConvert(Type.CHAR);
        break;
    case Opcodes.I2S:
        createConvert(Type.SHORT);
        break;
    case Opcodes.L2I:
        createConvert(Type.INT);
        break;
    case Opcodes.L2F:
        createConvert(Type.FLOAT);
        break;
    case Opcodes.L2D:
        createConvert(Type.DOUBLE);
        break;
    case Opcodes.F2I:
        createConvert(Type.INT);
        break;
    case Opcodes.F2L:
        createConvert(Type.LONG);
        break;
    case Opcodes.F2D:
        createConvert(Type.DOUBLE);
        break;
    case Opcodes.D2I:
        createConvert(Type.INT);
        break;
    case Opcodes.D2F:
        createConvert(Type.FLOAT);
        break;
    case Opcodes.D2L:
        createConvert(Type.LONG);
        break;
    case Opcodes.IALOAD:
        createArrayRead(Type.INT);
        break;
    case Opcodes.LALOAD:
        createArrayRead(Type.LONG);
        break;
    case Opcodes.FALOAD:
        createArrayRead(Type.FLOAT);
        break;
    case Opcodes.DALOAD:
        createArrayRead(Type.DOUBLE);
        break;
    case Opcodes.AALOAD:
        createArrayRead(Type.getFreshRef());
        break;
    case Opcodes.BALOAD:
        createArrayRead(Type.BYTE);
        break;
    case Opcodes.CALOAD:
        createArrayRead(Type.CHAR);
        break;
    case Opcodes.SALOAD:
        createArrayRead(Type.SHORT);
        break;
    case Opcodes.IASTORE:
        createArrayWrite(Type.INT);
        break;
    case Opcodes.LASTORE:
        createArrayWrite(Type.LONG);
        break;
    case Opcodes.FASTORE:
        createArrayWrite(Type.FLOAT);
        break;
    case Opcodes.DASTORE:
        createArrayWrite(Type.DOUBLE);
        break;
    case Opcodes.AASTORE:
        createArrayWrite(Type.getFreshRef());
        break;
    case Opcodes.BASTORE:
        createArrayWrite(Type.BYTE);
        break;
    case Opcodes.CASTORE:
        createArrayWrite(Type.CHAR);
        break;
    case Opcodes.SASTORE:
        createArrayWrite(Type.SHORT);
        break;
    case Opcodes.IRETURN:
        createReturn(Type.INT);
        break;
    case Opcodes.LRETURN:
        createReturn(Type.LONG);
        break;
    case Opcodes.FRETURN:
        createReturn(Type.FLOAT);
        break;
    case Opcodes.DRETURN:
        createReturn(Type.DOUBLE);
        break;
    case Opcodes.ARETURN:
        createReturn(Type.REF);
        break;
    case Opcodes.RETURN:
        createReturn(null);
        break;
    case Opcodes.ATHROW:
        createThrow();
        break;

    // Array Length
    case Opcodes.ARRAYLENGTH:
        ordered.add(stack.push(new ArrayLength(stack.pop())));
        break;

    // Swap
    case Opcodes.SWAP:
        a = stack.pop();
        b = stack.pop();

        stack.push(a);
        stack.push(b);

        ordered.add(new StackOperation(StackOperation.Sort.SWAP));

        break;

    // Duplicates
    case Opcodes.DUP:
        stack.push(stack.peek());
        ordered.add(new StackOperation(StackOperation.Sort.DUP));
        break;
    case Opcodes.DUP2:
        top = stack.peek().getType();

        // Type 2 Values
        if (top.getSize() == 2) {
            stack.push(stack.peek());
            // Type 1 Values
        } else {
            b = stack.pop();
            a = stack.pop();

            stack.push(a);
            stack.push(b);
            stack.push(a);
            stack.push(b);
        }

        ordered.add(new StackOperation(StackOperation.Sort.DUP2));

        break;
    case Opcodes.DUP_X1:
        b = stack.pop();
        a = stack.pop();

        stack.push(b);
        stack.push(a);
        stack.push(b);

        ordered.add(new StackOperation(StackOperation.Sort.DUP_X1));

        break;
    case Opcodes.DUP_X2:
        top = stack.peek().getType();

        // Type 2 Values
        if (top.getSize() == 2) {
            b = stack.pop();
            a = stack.pop();

            stack.push(b);
            stack.push(a);
            stack.push(b);
            // Type 1 Values
        } else {
            c = stack.pop();
            b = stack.pop();
            a = stack.pop();

            stack.push(c);
            stack.push(a);
            stack.push(b);
            stack.push(c);
        }

        ordered.add(new StackOperation(StackOperation.Sort.DUP_X2));

        break;

    // Pops
    case Opcodes.POP:
        stack.pop();
        ordered.add(new StackOperation(StackOperation.Sort.POP));
        break;
    case Opcodes.POP2:
        top = stack.peek().getType();

        // Type 2 Values
        if (top.getSize() == 2) {
            stack.pop();
            // Type 1 Values
        } else {
            stack.pop();
            stack.pop();
        }

        ordered.add(new StackOperation(StackOperation.Sort.POP2));

        break;

    // TODO: DUP2_X1, DUP2_X2, MONITORENTER, MONITOREXIT
    case Opcodes.MONITORENTER:
        throw new RuntimeException("visitInsn: MONITORENTER");
    case Opcodes.MONITOREXIT:
        throw new RuntimeException("visitInsn: MONITOREXIT");
    case Opcodes.DUP2_X1:
        throw new RuntimeException("visitInsn: DUP2_X1");
    case Opcodes.DUP2_X2:
        throw new RuntimeException("visitInsn: DUP2_X2");
    default:
        throw new RuntimeException("visitInsn: " + opcode);
    }
}

From source file:Client.JClassPatcher.java

License:Open Source License

private void patchClient(ClassNode node) {
    Logger.Info("Patching client (" + node.name + ".class)");

    Iterator<MethodNode> methodNodeList = node.methods.iterator();
    while (methodNodeList.hasNext()) {
        MethodNode methodNode = methodNodeList.next();

        // I (I)V is where most of the interface is processed
        if (methodNode.name.equals("I") && methodNode.desc.equals("(I)V")) {
            // Show combat menu
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                if (insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode bipush = (IntInsnNode) insnNode;

                    if (bipush.operand == -9) {
                        AbstractInsnNode findNode = insnNode;
                        while (findNode.getOpcode() != Opcodes.IF_ICMPEQ)
                            findNode = findNode.getNext();

                        LabelNode label = ((JumpInsnNode) findNode).label;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_MENU", "Z"));
                        methodNode.instructions.insertBefore(insnNode, new JumpInsnNode(Opcodes.IFGT, label));
                        break;
                    }/*from   w  w w .j  a v  a  2s .  c om*/
                }
            }
        } else if (methodNode.name.equals("J") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Chat command patch
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 627) {
                        AbstractInsnNode jmpNode = insnNode;
                        while (jmpNode.getOpcode() != Opcodes.IFEQ)
                            jmpNode = jmpNode.getNext();

                        AbstractInsnNode insertNode = insnNode;
                        while (insertNode.getOpcode() != Opcodes.INVOKEVIRTUAL)
                            insertNode = insertNode.getPrevious();

                        JumpInsnNode jmp = (JumpInsnNode) jmpNode;
                        methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ASTORE, 2));
                        methodNode.instructions.insert(insertNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                                "Game/Client", "processChatCommand", "(Ljava/lang/String;)Ljava/lang/String;"));
                        methodNode.instructions.insert(insertNode, new VarInsnNode(Opcodes.ALOAD, 2));
                    }
                }
            }
        } else if (methodNode.name.equals("h") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Private chat command patch
                if (insnNode.getOpcode() == Opcodes.GETFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;
                    if (field.owner.equals("client") && field.name.equals("Ob")
                            && insnNode.getPrevious().getPrevious().getOpcode() != Opcodes.INVOKEVIRTUAL) {
                        insnNode = insnNode.getPrevious().getPrevious();
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ob", "Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode,
                                new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "processPrivateCommand",
                                        "(Ljava/lang/String;)Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.GETFIELD, "client", "Ob", "Ljava/lang/String;"));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                        break;
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIIIIIII)V")) {
            // Draw NPC hook
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4));

            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "e", "Mb", "[Ljava/lang/String;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Tb", "[Lta;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode, new FieldInsnNode(Opcodes.GETFIELD, "ta", "t", "I"));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                    "Game/Client", "drawNPC", "(IIIILjava/lang/String;)V"));
        } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIIII)V")) {
            // Draw Player hook
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 6));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 2));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "rg", "[Lta;"));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 8));
            methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.AALOAD));
            methodNode.instructions.insertBefore(insnNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "ta", "C", "Ljava/lang/String;"));
            methodNode.instructions.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                    "Game/Client", "drawPlayer", "(IIIILjava/lang/String;)V"));
        } else if (methodNode.name.equals("b") && methodNode.desc.equals("(IIIIIII)V")) {
            // Draw Item hook
            // ILOAD 4 is item id
            AbstractInsnNode insnNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 3));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 7));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 1));
            methodNode.instructions.insertBefore(insnNode, new VarInsnNode(Opcodes.ILOAD, 4));
            methodNode.instructions.insertBefore(insnNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "drawItem", "(IIIII)V"));
        } else if (methodNode.name.equals("L") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Right click bounds fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    AbstractInsnNode nextNode = insnNode.getNext();

                    if (call.operand == 510) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    } else if (call.operand == 315) {
                        call.operand = 334 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    } else if (call.operand == -316) {
                        call.operand = 334 - (call.operand * -1);
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height_client", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(ZZ)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Friends chat mouse fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 489 || call.operand == 429) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                    if (call.operand == -430) {
                        call.operand = 512 - (call.operand * -1);
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("i") && methodNode.desc.equals("(I)V")) {
            AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious();

            // Send combat style option
            LabelNode label = new LabelNode();

            methodNode.instructions.insert(lastNode, label);

            // Format
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Write byte
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, -80));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;"));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Create Packet
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 29));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Skip combat packet if style is already controlled
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPLE, label));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));

            // Client init_game
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_game", "()V", false));
        } else if (methodNode.name.equals("o") && methodNode.desc.equals("(I)V")) {
            // Client.init_login patch
            AbstractInsnNode findNode = methodNode.instructions.getLast();
            methodNode.instructions.insertBefore(findNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init_login", "()V", false));
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Camera view distance crash fix
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 15000) {
                        call.operand = 32767;
                    }
                }
            }

            // Client.init patch
            AbstractInsnNode findNode = methodNode.instructions.getFirst();
            methodNode.instructions.insertBefore(findNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insertBefore(findNode,
                    new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "instance", "Ljava/lang/Object;"));
            methodNode.instructions.insertBefore(findNode,
                    new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client", "init", "()V", false));
        } else if (methodNode.name.equals("G") && methodNode.desc.equals("(I)V")) {
            // TODO: This can be shortened, I'll fix it another time

            // NPC Dialogue keyboard
            AbstractInsnNode lastNode = methodNode.instructions.getLast().getPrevious();

            LabelNode label = new LabelNode();

            methodNode.instructions.insert(lastNode, label);

            // Hide dialogue
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.PUTFIELD, "client", "Ph", "Z"));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Format
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(I)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.SIPUSH, 21294));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Write byte
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ja", "c", "(II)V", false));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 115));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "da", "f", "Lja;"));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Create Packet
            methodNode.instructions.insert(lastNode,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "da", "b", "(II)V", false));
            methodNode.instructions.insert(lastNode, new InsnNode(Opcodes.ICONST_0));
            methodNode.instructions.insert(lastNode, new IntInsnNode(Opcodes.BIPUSH, 116));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETFIELD, "client", "Jh", "Lda;"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));

            // Check if dialogue option is pressed
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IF_ICMPGE, label));
            // Menu option count
            methodNode.instructions.insert(lastNode, new FieldInsnNode(Opcodes.GETFIELD, "client", "Id", "I"));
            methodNode.instructions.insert(lastNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
            methodNode.instructions.insert(lastNode, new JumpInsnNode(Opcodes.IFLT, label));
            methodNode.instructions.insert(lastNode,
                    new FieldInsnNode(Opcodes.GETSTATIC, "Game/KeyboardHandler", "dialogue_option", "I"));
        } else if (methodNode.name.equals("f") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Hide Roof option
                if (insnNode.getOpcode() == Opcodes.GETFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;

                    if (field.owner.equals("client") && field.name.equals("yj")) {
                        AbstractInsnNode nextNode = insnNode.getNext();
                        if (nextNode.getOpcode() == Opcodes.IFNE) {
                            LabelNode label = ((JumpInsnNode) nextNode).label;
                            methodNode.instructions.insert(nextNode, new JumpInsnNode(Opcodes.IFGT, label));
                            methodNode.instructions.insert(nextNode,
                                    new FieldInsnNode(Opcodes.GETSTATIC, "Client/Settings", "HIDE_ROOFS", "Z"));
                        }
                    }
                }

                // Move wilderness skull
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 465 || call.operand == 453) {
                        call.operand = 512 - call.operand;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IIZ)Z")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Move the load screen text dialogue
                if (insnNode.getOpcode() == Opcodes.SIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 192) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 19));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("d") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Center logout dialogue
                if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 173) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 126) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 130));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 137) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 36));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("j") && methodNode.desc.equals("(I)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Center welcome box
                if (insnNode.getOpcode() == Opcodes.SIPUSH || insnNode.getOpcode() == Opcodes.BIPUSH) {
                    IntInsnNode call = (IntInsnNode) insnNode;
                    if (call.operand == 256) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 167) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "height", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 6));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 56) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 200));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == -87) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.INEG));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 169));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 426) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 170));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 106) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.ISUB));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    } else if (call.operand == 406) {
                        call.operand = 2;
                        methodNode.instructions.insertBefore(insnNode,
                                new FieldInsnNode(Opcodes.GETSTATIC, "Game/Renderer", "width", "I"));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IADD));
                        methodNode.instructions.insert(insnNode, new IntInsnNode(Opcodes.SIPUSH, 150));
                        methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.IDIV));
                    }
                }
            }
        } else if (methodNode.name.equals("k") && methodNode.desc.equals("(B)V")) {
            Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
            while (insnNodeList.hasNext()) {
                AbstractInsnNode insnNode = insnNodeList.next();

                // Save settings from combat menu
                if (insnNode.getOpcode() == Opcodes.PUTFIELD) {
                    FieldInsnNode field = (FieldInsnNode) insnNode;

                    if (field.owner.equals("client") && field.name.equals("Fg")) {
                        methodNode.instructions.insert(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC,
                                "Client/Settings", "save", "()V", false));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.PUTSTATIC, "Client/Settings", "COMBAT_STYLE", "I"));
                        methodNode.instructions.insert(insnNode,
                                new FieldInsnNode(Opcodes.GETFIELD, "client", "Fg", "I"));
                        methodNode.instructions.insert(insnNode, new VarInsnNode(Opcodes.ALOAD, 0));
                    }
                }
            }
        } else if (methodNode.name.equals("a") && methodNode.desc
                .equals("(ZLjava/lang/String;ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)V")) {
            AbstractInsnNode first = methodNode.instructions.getFirst();
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 7));
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 4));
            methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 5));
            methodNode.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Client",
                    "messageHook", "(Ljava/lang/String;Ljava/lang/String;I)V"));
        }
    }
}

From source file:com.codename1.tools.translator.bytecodes.ArithmeticExpression.java

public static boolean isBinaryOp(Instruction instr) {
    switch (instr.getOpcode()) {
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.LCMP:
    case Opcodes.IOR:
    case Opcodes.LOR:
    case Opcodes.IXOR:
    case Opcodes.LXOR:
    case Opcodes.IAND:
    case Opcodes.LAND:
    case Opcodes.FADD:
    case Opcodes.DADD:
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
    case Opcodes.LDIV:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
    case Opcodes.LREM:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
    case Opcodes.IMUL:
    case Opcodes.LMUL:
        return true;
    }/* w w w  .  jav  a 2 s . com*/
    return false;
}

From source file:com.codename1.tools.translator.bytecodes.ArithmeticExpression.java

public static boolean isArithmeticOp(Instruction instr) {

    switch (instr.getOpcode()) {
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:

    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.LCMP:
    case Opcodes.FNEG:
    case Opcodes.DNEG:
    case Opcodes.INEG:
    case Opcodes.D2F:
    case Opcodes.D2I:
    case Opcodes.D2L:
    case Opcodes.F2D:
    case Opcodes.F2I:
    case Opcodes.F2L:
    case Opcodes.L2D:
    case Opcodes.L2F:
    case Opcodes.L2I:
    case Opcodes.I2L:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2D:
    case Opcodes.I2F:
    case Opcodes.I2S:
    case Opcodes.IOR:
    case Opcodes.LOR:
    case Opcodes.IXOR:
    case Opcodes.LXOR:
    case Opcodes.IAND:
    case Opcodes.LAND:
    case Opcodes.FADD:
    case Opcodes.DADD:
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
    case Opcodes.LDIV:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
    case Opcodes.LREM:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
    case Opcodes.IMUL:
    case Opcodes.LMUL:
        return true;
    }/*from   www . ja v a 2  s.  co m*/
    return false;
}

From source file:com.codename1.tools.translator.bytecodes.ArithmeticExpression.java

public String getExpressionAsString() {

    Instruction instr = lastInstruction;
    int opcode = lastInstruction.getOpcode();
    if (subExpression == null) {
        // This is the root of it... probably an FLOAD
        if (lastInstruction instanceof AssignableExpression
                && !(lastInstruction instanceof ArithmeticExpression)) {
            StringBuilder out = new StringBuilder();
            if (((AssignableExpression) lastInstruction).assignTo(null, out)) {
                String strOut = out.toString();
                if (strOut.trim().isEmpty()) {
                    throw new RuntimeException("Instruction produces blank string output: " + lastInstruction);
                }//from www.j  a  va2s.  com
                if (strOut == null || "null".equals(strOut)) {
                    throw new RuntimeException(
                            "ArithmeticExpression produced null value.  This shouldn't happen: "
                                    + lastInstruction);
                }
                return strOut;
            }
        }

        if (lastInstruction instanceof VarOp) {
            VarOp var = (VarOp) lastInstruction;
            switch (opcode) {
            case Opcodes.FLOAD: {
                return "flocals_" + var.getIndex() + "_";

            }
            case Opcodes.DLOAD: {
                return "dlocals_" + var.getIndex() + "_";
            }

            case Opcodes.ILOAD: {
                return "ilocals_" + var.getIndex() + "_";
            }

            case Opcodes.LLOAD: {
                return "llocals_" + var.getIndex() + "_";
            }

            case org.objectweb.asm.Opcodes.ICONST_0: {
                return "0";

            }
            case org.objectweb.asm.Opcodes.ICONST_1: {
                return "1";

            }
            case org.objectweb.asm.Opcodes.ICONST_2: {
                return "2";

            }
            case org.objectweb.asm.Opcodes.ICONST_3: {
                return "3";

            }
            case org.objectweb.asm.Opcodes.ICONST_4: {
                return "4";

            }
            case org.objectweb.asm.Opcodes.ICONST_5: {
                return "5";

            }
            case org.objectweb.asm.Opcodes.ICONST_M1: {
                return "(-1)";

            }
            case org.objectweb.asm.Opcodes.LCONST_0: {
                return "((JAVA_LONG)0)";

            }
            case Opcodes.DCONST_0: {
                return "((JAVA_DOUBLE)0)";
            }
            case Opcodes.DCONST_1: {
                return "((JAVA_DOUBLE)1)";
            }
            case Opcodes.FCONST_0: {
                return "((JAVA_FLOAT)0)";
            }
            case Opcodes.FCONST_1: {
                return "((JAVA_FLOAT)1)";
            }
            case Opcodes.FCONST_2: {
                return "((JAVA_FLOAT)2";
            }

            case org.objectweb.asm.Opcodes.LCONST_1: {
                return "((JAVA_LONG)1)";

            }
            case org.objectweb.asm.Opcodes.BIPUSH:
            case org.objectweb.asm.Opcodes.SIPUSH: {
                return String.valueOf(var.getIndex());
            }
            default: {
                throw new RuntimeException("Unsupported Opcode in ArithmeticExpression: " + opcode + " " + var);
            }
            }
        } else {
            switch (instr.getOpcode()) {

            case org.objectweb.asm.Opcodes.ICONST_0: {
                return "0";

            }
            case org.objectweb.asm.Opcodes.ICONST_1: {
                return "1";

            }
            case org.objectweb.asm.Opcodes.ICONST_2: {
                return "2";

            }
            case org.objectweb.asm.Opcodes.ICONST_3: {
                return "3";

            }
            case org.objectweb.asm.Opcodes.ICONST_4: {
                return "4";

            }
            case org.objectweb.asm.Opcodes.ICONST_5: {
                return "5";

            }
            case org.objectweb.asm.Opcodes.ICONST_M1: {
                return "(-1)";

            }
            case org.objectweb.asm.Opcodes.LCONST_0: {
                return "((JAVA_LONG)0)";

            }
            case org.objectweb.asm.Opcodes.LCONST_1: {
                return "(JAVA_LONG)1";

            }
            case org.objectweb.asm.Opcodes.BIPUSH: {
                if (instr instanceof BasicInstruction) {
                    return String.valueOf(((BasicInstruction) instr).getValue());
                }
                break;
            }
            case org.objectweb.asm.Opcodes.LDC: {
                if (instr instanceof Ldc) {
                    Ldc ldc = (Ldc) instr;
                    return ldc.getValueAsString();

                }
                break;
            }
            default: {
                throw new RuntimeException(
                        "Unsupported Opcode in ArithmeticExpression: " + opcode + " " + instr);
            }

            }
        }

    } else {

        switch (opcode) {

        case Opcodes.ISHL: {
            return "BC_ISHL_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.ISHR: {
            return "BC_ISHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LSHL: {
            return "BC_LSHL_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LSHR: {
            return "BC_LSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IUSHR: {
            return "BC_IUSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.LUSHR: {
            return "BC_LUSHR_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
        case Opcodes.LCMP: {
            return "CN1_CMP_EXPR(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.F2D: {
            return subExpression.getExpressionAsString().trim();
        }
        case Opcodes.F2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.F2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.D2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2B: {
            return "((" + subExpression.getExpressionAsString() + " << 24) >> 24)";
        }
        case Opcodes.I2C: {
            return "(" + subExpression.getExpressionAsString().trim() + " & 0xffff)";
        }
        case Opcodes.I2D: {
            return "((JAVA_DOUBLE)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2L: {
            return "((JAVA_LONG)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.I2S: {
            return "((" + subExpression.getExpressionAsString().trim() + " << 16) >> 16)";
        }
        case Opcodes.L2D: {
            return "((JAVA_DOUBLE)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.L2F: {
            return "((JAVA_FLOAT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.L2I: {
            return "((JAVA_INT)" + subExpression.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IAND:
        case Opcodes.LAND: {
            return "(" + subExpression.getExpressionAsString().trim() + " & "
                    + subExpression2.getExpressionAsString().trim() + ")";

        }
        case Opcodes.IOR:
        case Opcodes.LOR: {
            return "(" + subExpression.getExpressionAsString().trim() + " | "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }
        case Opcodes.IXOR:
        case Opcodes.LXOR: {
            return "(" + subExpression.getExpressionAsString().trim() + " ^ "
                    + subExpression2.getExpressionAsString().trim() + ")";

        }
        case Opcodes.DADD:
        case Opcodes.IADD:
        case Opcodes.LADD:
        case Opcodes.FADD: {
            return "(" + subExpression.getExpressionAsString().trim() + " + "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DSUB:
        case Opcodes.ISUB:
        case Opcodes.LSUB:
        case Opcodes.FSUB: {
            return "(" + subExpression.getExpressionAsString().trim() + " - "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DMUL:
        case Opcodes.IMUL:
        case Opcodes.LMUL:
        case Opcodes.FMUL: {
            return "(" + subExpression.getExpressionAsString().trim() + " * "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.DDIV:
        case Opcodes.IDIV:
        case Opcodes.LDIV:
        case Opcodes.FDIV: {
            return "(" + subExpression.getExpressionAsString().trim() + " / "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.FREM:
        case Opcodes.DREM: {
            return "fmod(" + subExpression.getExpressionAsString().trim() + ", "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.LREM:
        case Opcodes.IREM: {
            if (subExpression2.getExpressionAsString() == null
                    || "null".equals(subExpression2.getExpressionAsString())) {
                throw new RuntimeException("2nd param of REM is null.  Should never happen.  Expression is "
                        + subExpression2 + " with last instruction " + subExpression2.lastInstruction);
            }
            return "(" + subExpression.getExpressionAsString().trim() + " % "
                    + subExpression2.getExpressionAsString().trim() + ")";
        }

        case Opcodes.FNEG:
        case Opcodes.INEG:
        case Opcodes.LNEG:
        case Opcodes.DNEG:
            return "(-(" + subExpression.getExpressionAsString().trim() + "))";

        default: {
            throw new RuntimeException("Unsupported Opcode in ArithmeticExpression: " + opcode + " " + instr);
        }

        }
    }
    throw new RuntimeException("Did not return a value in getExpressionAsString() with lastInstruction "
            + lastInstruction + " subExpression " + subExpression + " and subExpression2 " + subExpression2);
}

From source file:com.codename1.tools.translator.bytecodes.BasicInstruction.java

License:Open Source License

@Override
public void appendInstruction(StringBuilder b, List<Instruction> instructions) {
    switch (opcode) {
    case Opcodes.NOP:
        break;/*w  w w  . j  a  va  2 s.co m*/

    case Opcodes.ACONST_NULL:
        b.append("    PUSH_POINTER(JAVA_NULL); /* ACONST_NULL */\n");
        break;

    case Opcodes.ICONST_M1:
        b.append("    PUSH_INT(-1); /* ICONST_M1 */\n");
        break;

    case Opcodes.ICONST_0:
        b.append("    PUSH_INT(0); /* ICONST_0 */\n");
        break;

    case Opcodes.ICONST_1:
        b.append("    PUSH_INT(1); /* ICONST_1 */\n");
        break;

    case Opcodes.ICONST_2:
        b.append("    PUSH_INT(2); /* ICONST_2 */\n");
        break;

    case Opcodes.ICONST_3:
        b.append("    PUSH_INT(3); /* ICONST_3 */\n");
        break;

    case Opcodes.ICONST_4:
        b.append("    PUSH_INT(4); /* ICONST_4 */\n");
        break;

    case Opcodes.ICONST_5:
        b.append("    PUSH_INT(5); /* ICONST_5 */\n");
        break;

    case Opcodes.LCONST_0:
        b.append("    PUSH_LONG(0); /* LCONST_0 */\n");
        break;

    case Opcodes.LCONST_1:
        b.append("    PUSH_LONG(1); /* LCONST_1 */\n");
        break;

    case Opcodes.FCONST_0:
        b.append("    PUSH_FLOAT(0); /* FCONST_0 */\n");
        break;

    case Opcodes.FCONST_1:
        b.append("    PUSH_FLOAT(1); /* FCONST_1 */\n");
        break;

    case Opcodes.FCONST_2:
        b.append("    PUSH_FLOAT(2); /* FCONST_2 */\n");
        break;

    case Opcodes.DCONST_0:
        b.append("    PUSH_DOUBLE(0); /* DCONST_0 */\n");
        break;

    case Opcodes.DCONST_1:
        b.append("    PUSH_DOUBLE(1); /* DCONST_1 */\n");
        break;

    case Opcodes.BALOAD:
        b.append("    { CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* BALOAD */ \n"
                + "    SP--; SP[-1].type = CN1_TYPE_INT; \n"
                + "    SP[-1].data.i = ((JAVA_ARRAY_BYTE*) (*(JAVA_ARRAY)SP[-1].data.o).data)[(*SP).data.i]; \n"
                + "    }\n");
        break;

    case Opcodes.CALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* CALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_INT; \n"
                + "    SP[-1].data.i = ((JAVA_ARRAY_CHAR*) (*(JAVA_ARRAY)SP[-1].data.o).data)[(*SP).data.i];\n");
        break;

    case Opcodes.IALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* IALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_INT; \n"
                + "    SP[-1].data.i = ((JAVA_ARRAY_INT*) (*(JAVA_ARRAY)SP[-1].data.o).data)[(*SP).data.i];\n");
        break;

    case Opcodes.SALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); \n" + "    SP--; SP[-1].type = CN1_TYPE_INT; \n"
                + "    SP[-1].data.i = ((JAVA_ARRAY_SHORT*) (*(JAVA_ARRAY)SP[-1].data.o).data)[(*SP).data.i]; /* SALOAD */\n");
        break;

    case Opcodes.LALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* LALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_LONG; \n"
                + "    SP[-1].data.l = LONG_ARRAY_LOOKUP((JAVA_ARRAY)SP[-1].data.o, (*SP).data.i);\n");
        break;

    case Opcodes.FALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* FALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_FLOAT; \n"
                + "    SP[-1].data.f = FLOAT_ARRAY_LOOKUP((JAVA_ARRAY)SP[-1].data.o, (*SP).data.i);\n");
        break;

    case Opcodes.DALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* DALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_DOUBLE; \n"
                + "    SP[-1].data.d = DOUBLE_ARRAY_LOOKUP((JAVA_ARRAY)SP[-1].data.o, (*SP).data.i);\n");
        break;

    case Opcodes.AALOAD:
        b.append("    CHECK_ARRAY_ACCESS(2, SP[-1].data.i); /* AALOAD */\n"
                + "    SP--; SP[-1].type = CN1_TYPE_INVALID; \n"
                + "    SP[-1].data.o = ((JAVA_ARRAY_OBJECT*) (*(JAVA_ARRAY)SP[-1].data.o).data)[(*SP).data.i]; \n"
                + "    SP[-1].type = CN1_TYPE_OBJECT; \n");
        break;

    case Opcodes.BASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* BASTORE */\n"
                + "    ((JAVA_ARRAY_BYTE*) (*(JAVA_ARRAY)SP[-3].data.o).data)[SP[-2].data.i] = SP[-1].data.i; SP -= 3;\n");
        break;

    case Opcodes.CASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* CASTORE */\n"
                + "    ((JAVA_ARRAY_CHAR*) (*(JAVA_ARRAY)SP[-3].data.o).data)[SP[-2].data.i] = SP[-1].data.i; SP -= 3;\n\n");
        break;

    case Opcodes.SASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* SASTORE */\n"
                + "    ((JAVA_ARRAY_SHORT*) (*(JAVA_ARRAY)SP[-3].data.o).data)[SP[-2].data.i] = SP[-1].data.i; SP -= 3;\n");
        break;

    case Opcodes.IASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* IASTORE */\n"
                + "    ((JAVA_ARRAY_INT*) (*(JAVA_ARRAY)SP[-3].data.o).data)[SP[-2].data.i] = SP[-1].data.i; SP -= 3;\n");
        break;

    case Opcodes.LASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* LASTORE */\n"
                + "    LONG_ARRAY_LOOKUP((JAVA_ARRAY)SP[-3].data.o, SP[-2].data.i) = SP[-1].data.l; SP -= 3;\n");
        break;

    case Opcodes.FASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* FASTORE */\n"
                + "    FLOAT_ARRAY_LOOKUP((JAVA_ARRAY)SP[-3].data.o, SP[-2].data.i) = SP[-1].data.f; SP -= 3;\n");
        break;

    case Opcodes.DASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); /* DASTORE */\n"
                + "    DOUBLE_ARRAY_LOOKUP((JAVA_ARRAY)SP[-3].data.o, SP[-2].data.i) = SP[-1].data.d; SP -= 3;\n");
        break;

    case Opcodes.AASTORE:
        b.append("    CHECK_ARRAY_ACCESS(3, SP[-2].data.i); { /* BC_AASTORE */\n"
                + "    JAVA_OBJECT aastoreTmp = SP[-3].data.o; \n"
                + "    ((JAVA_ARRAY_OBJECT*) (*(JAVA_ARRAY)aastoreTmp).data)[SP[-2].data.i] = SP[-1].data.o; \n"
                + "    SP -= 3; }\n");
        break;

    case Opcodes.POP:
        b.append("    SP--; /* POP */\n");
        break;

    case Opcodes.POP2:
        b.append("    popMany(threadStateData, 2, &SP); /* POP2 */\n");
        break;

    /*case Opcodes.DUP:
        b.append("    PUSH_INT(PEEK_INT(1));\n");
        break;
            
    case Opcodes.DUP_X1:
        b.append("    DUP_X1();\n");
        break;
                
    case Opcodes.DUP_X2:
        b.append("    DUP_X2();\n");
        break;*/

    case Opcodes.DUP:
        b.append("    BC_DUP(); /* DUP */\n");
        break;

    case Opcodes.DUP2:
        b.append("    BC_DUP2(); /* DUP2 */\n");
        break;

    case Opcodes.DUP_X1:
        b.append("    BC_DUP2_X1(); /* DUP_X1 */\n");
        break;

    case Opcodes.DUP2_X1:
        b.append("    BC_DUP2_X1(); /* DUP2_X1 */\n");
        break;

    case Opcodes.DUP_X2:
        b.append("    BC_DUP2_X2(); /* DUP_X2 */\n");
        break;

    case Opcodes.DUP2_X2:
        b.append("    BC_DUP2_X2(); /* DUP2_X2 */\n");
        break;

    case Opcodes.SWAP:
        b.append("    swapStack(SP); /* SWAP */\n");
        break;

    case Opcodes.IADD:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i + (*SP).data.i; /* IADD */\n");
        break;

    case Opcodes.LADD:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l + (*SP).data.l; /* LADD */\n");
        break;

    case Opcodes.FADD:
        b.append("    SP--; SP[-1].data.f = SP[-1].data.f + (*SP).data.f; /* FADD */\n");
        break;

    case Opcodes.DADD:
        b.append("    SP--; SP[-1].data.d = SP[-1].data.d + (*SP).data.d; /* DADD */\n");
        break;

    case Opcodes.ISUB:
        b.append("    SP--; SP[-1].data.i = (SP[-1].data.i - (*SP).data.i); /* ISUB */\n");
        break;

    case Opcodes.LSUB:
        b.append("    SP--; SP[-1].data.l = (SP[-1].data.l - (*SP).data.l); /* LSUB */\n");
        break;

    case Opcodes.FSUB:
        b.append("    SP--; SP[-1].data.f = (SP[-1].data.f - (*SP).data.f); /* FSUB */\n");
        break;

    case Opcodes.DSUB:
        b.append("    SP--; SP[-1].data.d = (SP[-1].data.d - (*SP).data.d); /* DSUB */\n");
        break;

    case Opcodes.IMUL:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i * (*SP).data.i; /* IMUL */\n");
        break;

    case Opcodes.LMUL:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l * (*SP).data.l; /* LMUL */\n");
        break;

    case Opcodes.FMUL:
        b.append("    SP--; SP[-1].data.f = SP[-1].data.f * (*SP).data.f; /* FMUL */\n");
        break;

    case Opcodes.DMUL:
        b.append("    SP--; SP[-1].data.d = SP[-1].data.d * (*SP).data.d; /* DMUL */\n");
        break;

    case Opcodes.IDIV:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i / (*SP).data.i; /* IDIV */\n");
        break;

    case Opcodes.LDIV:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l / (*SP).data.l; /* LDIV */\n");
        break;

    case Opcodes.FDIV:
        b.append("    SP--; SP[-1].data.f = SP[-1].data.f / (*SP).data.f; /* FDIV */\n");
        break;

    case Opcodes.DDIV:
        b.append("    SP--; SP[-1].data.d = SP[-1].data.d / (*SP).data.d; /* DDIV */\n");
        break;

    case Opcodes.IREM:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i % (*SP).data.i; /* IREM */\n");
        break;

    case Opcodes.LREM:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l % (*SP).data.l; /* LREM */\n");
        break;

    case Opcodes.FREM:
        b.append("    SP--; SP[-1].data.f = fmod(SP[-1].data.f, (*SP).data.f); /* FREM */\n");
        break;

    case Opcodes.DREM:
        b.append("    SP--; SP[-1].data.d = fmod(SP[-1].data.d, (*SP).data.d); /* DREM */\n");
        break;

    case Opcodes.INEG:
        b.append("    SP[-1].data.i *= -1; /* INEG */\n");
        break;

    case Opcodes.LNEG:
        b.append("    SP[-1].data.l *= -1; /* LNEG */\n");
        break;

    case Opcodes.FNEG:
        b.append("    SP[-1].data.f *= -1; /* FNEG */\n");
        break;

    case Opcodes.DNEG:
        b.append("    SP[-1].data.d *= -1; /* DNEG */\n");
        break;

    case Opcodes.ISHL:
        b.append("    SP--; SP[-1].data.i = (SP[-1].data.i << (0x1f & (*SP).data.i)); /* ISHL */\n");
        break;

    case Opcodes.LSHL:
        b.append("    SP--; SP[-1].data.l = (SP[-1].data.l << (0x3f & (*SP).data.i)); /* LSHL */\n");
        break;

    case Opcodes.ISHR:
        b.append("    SP--; SP[-1].data.i = (SP[-1].data.i >> (0x1f & (*SP).data.i)); /* ISHR */\n");
        break;

    case Opcodes.LSHR:
        b.append("    SP--; SP[-1].data.l = (SP[-1].data.l >> (0x3f & (*SP).data.l)); /* LSHR */\n");
        break;

    case Opcodes.IUSHR:
        b.append(
                "    SP--; SP[-1].data.i = (((unsigned int)SP[-1].data.i) >> (0x1f & ((unsigned int)(*SP).data.i))); /* IUSHR */\n");
        break;

    case Opcodes.LUSHR:
        b.append(
                "    SP--; SP[-1].data.l = (((unsigned long long)SP[-1].data.l) >> (0x3f & ((unsigned long long)(*SP).data.i))); /* LUSHR */\n");
        break;

    case Opcodes.IAND:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i & (*SP).data.i; /* IAND */\n");
        break;

    case Opcodes.LAND:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l & (*SP).data.l; /* LAND */\n");
        break;

    case Opcodes.IOR:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i | (*SP).data.i; /* IOR */\n");
        break;

    case Opcodes.LOR:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l | (*SP).data.l; /* LOR */\n");
        break;

    case Opcodes.IXOR:
        b.append("    SP--; SP[-1].data.i = SP[-1].data.i ^ (*SP).data.i; /* IXOR */\n");
        break;

    case Opcodes.LXOR:
        b.append("    SP--; SP[-1].data.l = SP[-1].data.l ^ (*SP).data.l; /* LXOR */\n");
        break;

    case Opcodes.I2L:
        b.append("    SP[-1].data.l = SP[-1].data.i; /* I2L */\n");
        break;

    case Opcodes.I2F:
        b.append("    SP[-1].data.f = (JAVA_FLOAT)SP[-1].data.i; /* I2F */\n");
        break;

    case Opcodes.I2D:
        b.append("    SP[-1].data.d = SP[-1].data.i; /* I2D */;\n");
        break;

    case Opcodes.L2I:
        b.append("    SP[-1].data.i = (JAVA_INT)SP[-1].data.l; /* L2I */\n");
        break;

    case Opcodes.L2F:
        b.append("    SP[-1].data.f = (JAVA_FLOAT)SP[-1].data.l; /* L2F */\n");
        break;

    case Opcodes.L2D:
        b.append("    SP[-1].data.d = (JAVA_DOUBLE)SP[-1].data.l; /* L2D */\n");
        break;

    case Opcodes.F2I:
        b.append("    SP[-1].data.i = (JAVA_INT)SP[-1].data.f; /* F2I */\n");
        break;

    case Opcodes.F2L:
        b.append("    SP[-1].data.l = (JAVA_LONG)SP[-1].data.f; /* F2L */\n");
        break;

    case Opcodes.F2D:
        b.append("    SP[-1].data.d = SP[-1].data.f; /* F2D */\n");
        break;

    case Opcodes.D2I:
        b.append("    SP[-1].data.i = (JAVA_INT)SP[-1].data.d; /* D2I */\n");
        break;

    case Opcodes.D2L:
        b.append("    SP[-1].data.l = (JAVA_LONG)SP[-1].data.d; /* D2L */\n");
        break;

    case Opcodes.D2F:
        b.append("    SP[-1].data.f = (JAVA_FLOAT)SP[-1].data.d; /* D2F */\n");
        break;

    case Opcodes.I2B:
        b.append("    SP[-1].data.i = ((SP[-1].data.i << 24) >> 24); /* I2B */\n");
        break;

    case Opcodes.I2C:
        b.append("    SP[-1].data.i = (SP[-1].data.i & 0xffff); /* I2C */\n");
        break;

    case Opcodes.I2S:
        b.append("    SP[-1].data.i = ((SP[-1].data.i << 16) >> 16); /* I2S */\n");
        break;

    case Opcodes.LCMP:
        b.append("    BC_LCMP();\n");
        break;

    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
        b.append("    BC_FCMPL();\n");
        break;

    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        b.append("    BC_DCMPL();\n");
        break;

    case Opcodes.IRETURN:
        appendSynchronized(b);

        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); return SP[-1].data.i;\n");
            //                    b.append(maxLocals);
            //                    b.append(", stack, locals, methodBlockOffset); \n    return SP[-1].data.i;\n");
        } else {
            b.append("    releaseForReturn(threadStateData, cn1LocalsBeginInThread); return SP[-1].data.i;\n");
            //                    b.append(maxLocals);
            //                    b.append(", stack, locals); \n    return SP[-1].data.i;\n");
        }
        break;

    case Opcodes.LRETURN:
        appendSynchronized(b);

        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); \n    return POP_LONG();\n");
        } else {
            b.append(
                    "    releaseForReturn(threadStateData, cn1LocalsBeginInThread); \n    return POP_LONG();\n");
        }
        break;

    case Opcodes.FRETURN:
        appendSynchronized(b);

        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); \n    return POP_FLOAT();\n");
        } else {
            b.append(
                    "    releaseForReturn(threadStateData, cn1LocalsBeginInThread); \n    return POP_FLOAT();\n");
        }
        break;

    case Opcodes.DRETURN:
        appendSynchronized(b);

        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); \n    return POP_DOUBLE();\n");
        } else {
            b.append(
                    "    releaseForReturn(threadStateData, cn1LocalsBeginInThread); \n    return POP_DOUBLE();\n");
        }
        break;

    case Opcodes.ARETURN:
        appendSynchronized(b);

        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); \n    return POP_OBJ();\n");
        } else {
            b.append(
                    "    releaseForReturn(threadStateData, cn1LocalsBeginInThread); \n    return POP_OBJ();\n");
        }
        break;

    case Opcodes.RETURN:
        appendSynchronized(b);

        if (!hasInstructions) {
            b.append("    return;\n");
            break;
        }
        if (TryCatch.isTryCatchInMethod()) {
            b.append(
                    "    releaseForReturnInException(threadStateData, cn1LocalsBeginInThread, methodBlockOffset); \n    return;\n");
        } else {
            b.append("    releaseForReturn(threadStateData, cn1LocalsBeginInThread); \n    return;\n");
        }
        break;

    case Opcodes.ARRAYLENGTH:
        b.append("    { /* ARRAYLENGTH */\n" + "        if(SP[-1].data.o == JAVA_NULL) { \n"
                + "            throwException(threadStateData, __NEW_INSTANCE_java_lang_NullPointerException(threadStateData)); \n"
                + "        }; \n" + "        SP[-1].type = CN1_TYPE_INT; \n"
                + "        SP[-1].data.i = (*((JAVA_ARRAY)SP[-1].data.o)).length; \n" + "    }\n");
        break;

    case Opcodes.ATHROW:
        //b.append("    NSLog(@\"Exception thrown %s %d %s %s\\n\", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__);\n");
        b.append("    throwException(threadStateData, POP_OBJ());\n");
        break;

    case Opcodes.MONITORENTER:
        b.append("    monitorEnter(threadStateData, POP_OBJ());\n");
        break;

    case Opcodes.MONITOREXIT:
        b.append("    monitorExit(threadStateData, POP_OBJ());\n");
        break;

    // int instructions
    case Opcodes.SIPUSH:
    case Opcodes.BIPUSH:
        b.append("    PUSH_INT(");
        b.append(value);
        b.append(");\n");
        break;

    case Opcodes.NEWARRAY:
        switch (value) {
        case 4: // boolean
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_BOOLEAN, sizeof(JAVA_ARRAY_BOOLEAN), 1));\n");
            break;
        case 5: // char
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_CHAR, sizeof(JAVA_ARRAY_CHAR), 1));\n");
            break;
        case 6: // float
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_FLOAT, sizeof(JAVA_ARRAY_FLOAT), 1));\n");
            break;
        case 7: // double
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_DOUBLE, sizeof(JAVA_ARRAY_DOUBLE), 1));\n");
            break;
        case 8: // byte
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_BYTE, sizeof(JAVA_ARRAY_BYTE), 1));\n");
            break;
        case 9: // short
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_SHORT, sizeof(JAVA_ARRAY_SHORT), 1));\n");
            break;
        case 10: // int
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_INT, sizeof(JAVA_ARRAY_INT), 1));\n");
            break;
        case 11: // long 
            b.append(
                    "    SP--; PUSH_OBJ(allocArray(threadStateData, (*SP).data.i, &class_array1__JAVA_LONG, sizeof(JAVA_ARRAY_LONG), 1));\n");
            break;
        }
        break;
    }
}

From source file:com.codename1.tools.translator.Util.java

License:Open Source License

public static char[] getStackInputTypes(Instruction instr) {
    char[] out = instr.getStackInputTypes();
    if (out != null) {
        return out;
    }//w ww. j  a  v a2s.  c o  m

    switch (instr.getOpcode()) {

    case Opcodes.NOP:
    case Opcodes.ACONST_NULL:
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.SIPUSH:
    case Opcodes.BIPUSH:
        return new char[0];
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.IALOAD:
    case Opcodes.SALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.AALOAD:
        return new char[] { 'i', 'o' };

    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.IASTORE:
        return new char[] { 'i', 'i', 'o' };
    case Opcodes.LASTORE:
        return new char[] { 'l', 'i', 'o' };
    case Opcodes.FASTORE:
        return new char[] { 'f', 'i', 'o' };
    case Opcodes.DASTORE:
        return new char[] { 'd', 'i', 'o' };
    case Opcodes.AASTORE:
        return new char[] { 'o', 'i', 'o' };

    case Opcodes.POP:
        return new char[] { '*' };

    case Opcodes.POP2:
        return new char[] { '*', '*' };

    case Opcodes.DUP:
        return new char[] { '0' };

    case Opcodes.DUP2:
    case Opcodes.DUP_X2:
    case Opcodes.DUP2_X2:
        return null; // DUP2 depends on the types on the stack so we don't statically know the input types

    case Opcodes.DUP_X1:
    case Opcodes.DUP2_X1:
        return new char[] { '0', '1' };
    case Opcodes.SWAP:
        return new char[] { '0', '1' };
    case Opcodes.IADD:
    case Opcodes.ISUB:
    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:
        return new char[] { 'i', 'i' };

    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.LCMP:
        return new char[] { 'l', 'l' };
    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
        return new char[] { 'f', 'f' };
    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        return new char[] { 'd', 'd' };

    case Opcodes.INEG:
    case Opcodes.I2L:
    case Opcodes.I2F:
    case Opcodes.I2D:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.NEWARRAY:
        return new char[] { 'i' };
    case Opcodes.LNEG:
    case Opcodes.L2I:
    case Opcodes.L2F:
    case Opcodes.L2D:
        return new char[] { 'l' };

    case Opcodes.FNEG:
    case Opcodes.F2I:
    case Opcodes.F2L:
    case Opcodes.F2D:
        return new char[] { 'f' };
    case Opcodes.DNEG:
    case Opcodes.D2I:
    case Opcodes.D2L:
    case Opcodes.D2F:
        return new char[] { 'd' };
    case Opcodes.LUSHR:
        return new char[] { 'i', 'l' };

    case Opcodes.ARRAYLENGTH:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.ATHROW:
        return new char[] { 'o' };
    default:
        return null;

    }

}

From source file:com.codename1.tools.translator.Util.java

License:Open Source License

public static char[] getStackOutputTypes(Instruction instr) {
    char[] out = instr.getStackOutputTypes();
    if (out != null) {
        return out;
    }//from  ww w  . j ava 2  s  .c o  m

    switch (instr.getOpcode()) {
    case Opcodes.NOP:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.POP:
    case Opcodes.POP2:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.ATHROW:
        return new char[0];

    case Opcodes.ACONST_NULL:
    case Opcodes.AALOAD:
    case Opcodes.NEWARRAY:
        return new char[] { 'o' };

    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.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.IALOAD:
    case Opcodes.SALOAD:
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.INEG:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
    case Opcodes.IAND:
    case Opcodes.IOR:
    case Opcodes.IXOR:
    case Opcodes.F2I:
    case Opcodes.D2I:
    case Opcodes.L2I:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.LCMP:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
    case Opcodes.ARRAYLENGTH:
    case Opcodes.SIPUSH:
    case Opcodes.BIPUSH:
        return new char[] { 'i' };
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.LALOAD:
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LNEG:
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.I2L:
    case Opcodes.F2L:
    case Opcodes.D2L:
        return new char[] { 'l' };
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.FALOAD:
    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FNEG:
    case Opcodes.I2F:
    case Opcodes.D2F:
    case Opcodes.L2F:
        return new char[] { 'f' };
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.DALOAD:
    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
    case Opcodes.DNEG:
    case Opcodes.I2D:
    case Opcodes.F2D:
    case Opcodes.L2D:
        return new char[] { 'd' };
    case Opcodes.DUP:
        return new char[] { '0', '0' };

    case Opcodes.DUP2:
    case Opcodes.DUP_X2:
    case Opcodes.DUP2_X2:
        return null;

    case Opcodes.DUP_X1:
    case Opcodes.DUP2_X1:
        return new char[] { '0', '1', '0' };
    case Opcodes.SWAP:
        return new char[] { '1', '0' };

    default:
        return null;
    }

}