Example usage for org.objectweb.asm Opcodes IAND

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

Introduction

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

Prototype

int IAND

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

Click Source Link

Usage

From source file:jpcsp.Allegrex.compiler.CodeInstruction.java

License:Open Source License

private void compileJalr(CompilerContext context, MethodVisitor mv) {
    // Retrieve the call address from the Rs register before executing
    // the delay slot instruction, as it might theoretically modify the
    // content of the Rs register.
    context.loadRs();/* ww  w .  ja  v a  2  s . co m*/

    // It seems the PSP ignores the lowest 2 bits of the address.
    // These bits are used and set by interruptman.prx
    // but never cleared explicitly before executing a jalr instruction.
    context.loadImm(0xFFFFFFFC);
    mv.visitInsn(Opcodes.IAND);

    compileDelaySlot(context, mv);
    context.visitCall(getAddress() + 8, context.getRdRegisterIndex());
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

private void applyPfxSrcPostfix(VfpuPfxSrcState pfxSrcState, int n, boolean isFloat) {
    if (pfxSrcState == null || pfxSrcState.isUnknown() || !pfxSrcState.pfxSrc.enabled) {
        return;//from   w  w w.j  a  v a 2 s  .  c  o  m
    }

    if (pfxSrcState.pfxSrc.abs[n]) {
        if (log.isTraceEnabled() && pfxSrcState.isKnown() && pfxSrcState.pfxSrc.enabled) {
            log.trace(String.format("PFX    %08X - applyPfxSrcPostfix abs(%d)",
                    getCodeInstruction().getAddress(), n));
        }

        if (isFloat) {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), "abs", "(F)F");
        } else {
            loadImm(0x7FFFFFFF);
            mv.visitInsn(Opcodes.IAND);
        }
    }
    if (pfxSrcState.pfxSrc.neg[n]) {
        if (log.isTraceEnabled() && pfxSrcState.isKnown() && pfxSrcState.pfxSrc.enabled) {
            log.trace(String.format("PFX    %08X - applyPfxSrcPostfix neg(%d)",
                    getCodeInstruction().getAddress(), n));
        }

        if (isFloat) {
            mv.visitInsn(Opcodes.FNEG);
        } else {
            loadImm(0x80000000);
            mv.visitInsn(Opcodes.IXOR);
        }
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memRead16(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();//from ww w.ja va 2 s.  c o m
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.debugMemoryRead) {
        mv.visitInsn(Opcodes.DUP);
        loadImm(0);
        loadImm(codeInstruction.getAddress());
        loadImm(1);
        loadImm(16);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                "(IIIZI)V");
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I");
    } else {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryRead16", "(II)I");
            loadImm(1);
            mv.visitInsn(Opcodes.IUSHR);
        } else {
            // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(4);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP);
        loadImm(1);
        mv.visitInsn(Opcodes.IAND);
        loadImm(4);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        loadImm(1);
        mv.visitInsn(Opcodes.IUSHR);
        mv.visitInsn(Opcodes.IALOAD);
        loadTmp1();
        mv.visitInsn(Opcodes.IUSHR);
        loadImm(0xFFFF);
        mv.visitInsn(Opcodes.IAND);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memRead8(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();//from w w  w  .j  ava 2 s .c o m
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.debugMemoryRead) {
        mv.visitInsn(Opcodes.DUP);
        loadImm(0);
        loadImm(codeInstruction.getAddress());
        loadImm(1);
        loadImm(8);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                "(IIIZI)V");
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read8", "(I)I");
    } else {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryRead8", "(II)I");
        } else {
            // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(3);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP);
        loadImm(3);
        mv.visitInsn(Opcodes.IAND);
        loadImm(3);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        loadImm(2);
        mv.visitInsn(Opcodes.IUSHR);
        mv.visitInsn(Opcodes.IALOAD);
        loadTmp1();
        mv.visitInsn(Opcodes.IUSHR);
        loadImm(0xFF);
        mv.visitInsn(Opcodes.IAND);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memWrite16(int registerIndex, int offset) {
    if (!memWritePrepared) {
        if (useMMIO()) {
            loadMMIO();//from   w ww. j  ava 2 s .co m
        } else if (!RuntimeContext.hasMemoryInt()) {
            loadMemory();
        } else {
            loadMemoryInt();
        }
        mv.visitInsn(Opcodes.SWAP);

        loadRegister(registerIndex);
        if (offset != 0) {
            loadImm(offset);
            mv.visitInsn(Opcodes.IADD);
        }

        if (RuntimeContext.hasMemoryInt()) {
            if (checkMemoryAccess()) {
                loadImm(codeInstruction.getAddress());
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite16",
                        "(II)I");
            }
        }
        mv.visitInsn(Opcodes.SWAP);
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write16", "(IS)V");
    } else {
        // tmp2 = value & 0xFFFF;
        // tmp1 = (address & 2) << 3;
        // memoryInt[address >> 2] = (memoryInt[address >> 2] & ((0xFFFF << tmp1) ^ 0xFFFFFFFF)) | (tmp2 << tmp1);
        loadImm(0xFFFF);
        mv.visitInsn(Opcodes.IAND);
        storeTmp2();
        mv.visitInsn(Opcodes.DUP);
        loadImm(2);
        mv.visitInsn(Opcodes.IAND);
        loadImm(3);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        if (checkMemoryAccess()) {
            loadImm(2);
            mv.visitInsn(Opcodes.ISHR);
        } else {
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(5);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP2);
        mv.visitInsn(Opcodes.IALOAD);
        loadImm(0xFFFF);
        loadTmp1();
        mv.visitInsn(Opcodes.ISHL);
        loadImm(-1);
        mv.visitInsn(Opcodes.IXOR);
        mv.visitInsn(Opcodes.IAND);
        loadTmp2();
        loadTmp1();
        mv.visitInsn(Opcodes.ISHL);
        mv.visitInsn(Opcodes.IOR);
        mv.visitInsn(Opcodes.IASTORE);
    }

    memWritePrepared = false;
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memWrite8(int registerIndex, int offset) {
    if (!memWritePrepared) {
        if (useMMIO()) {
            loadMMIO();/* w  ww  .  jav  a 2s.  c  om*/
        } else if (!RuntimeContext.hasMemoryInt()) {
            loadMemory();
        } else {
            loadMemoryInt();
        }
        mv.visitInsn(Opcodes.SWAP);

        loadRegister(registerIndex);
        if (offset != 0) {
            loadImm(offset);
            mv.visitInsn(Opcodes.IADD);
        }

        if (RuntimeContext.hasMemoryInt()) {
            if (checkMemoryAccess()) {
                loadImm(codeInstruction.getAddress());
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite8",
                        "(II)I");
            }
        }
        mv.visitInsn(Opcodes.SWAP);
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write8", "(IB)V");
    } else {
        // tmp2 = value & 0xFF;
        // tmp1 = (address & 3) << 3;
        // memoryInt[address >> 2] = (memoryInt[address >> 2] & ((0xFF << tmp1) ^ 0xFFFFFFFF)) | (tmp2 << tmp1);
        loadImm(0xFF);
        mv.visitInsn(Opcodes.IAND);
        storeTmp2();
        mv.visitInsn(Opcodes.DUP);
        loadImm(3);
        mv.visitInsn(Opcodes.IAND);
        loadImm(3);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        if (checkMemoryAccess()) {
            loadImm(2);
            mv.visitInsn(Opcodes.ISHR);
        } else {
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(5);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP2);
        mv.visitInsn(Opcodes.IALOAD);
        loadImm(0xFF);
        loadTmp1();
        mv.visitInsn(Opcodes.ISHL);
        loadImm(-1);
        mv.visitInsn(Opcodes.IXOR);
        mv.visitInsn(Opcodes.IAND);
        loadTmp2();
        loadTmp1();
        mv.visitInsn(Opcodes.ISHL);
        mv.visitInsn(Opcodes.IOR);
        mv.visitInsn(Opcodes.IASTORE);
    }

    memWritePrepared = false;
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memWriteZero8(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();/*from  w ww  . ja va2s  . co  m*/
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.hasMemoryInt()) {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite8", "(II)I");
        }
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        loadImm(0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write8", "(IB)V");
    } else {
        // tmp1 = (address & 3) << 3;
        // memoryInt[address >> 2] = (memoryInt[address >> 2] & ((0xFF << tmp1) ^ 0xFFFFFFFF));
        mv.visitInsn(Opcodes.DUP);
        loadImm(3);
        mv.visitInsn(Opcodes.IAND);
        loadImm(3);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        if (checkMemoryAccess()) {
            loadImm(2);
            mv.visitInsn(Opcodes.ISHR);
        } else {
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(5);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP2);
        mv.visitInsn(Opcodes.IALOAD);
        loadImm(0xFF);
        loadTmp1();
        mv.visitInsn(Opcodes.ISHL);
        loadImm(-1);
        mv.visitInsn(Opcodes.IXOR);
        mv.visitInsn(Opcodes.IAND);
        mv.visitInsn(Opcodes.IASTORE);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void compileVFPUInstr(Object cstBefore, int opcode, String mathFunction) {
    int vsize = getVsize();
    boolean useVt = getCodeInstruction().hasFlags(Instruction.FLAG_USES_VFPU_PFXT);

    if (mathFunction == null && opcode == Opcodes.NOP && !useVt && cstBefore == null && canUseVFPUInt(vsize)) {
        // VMOV should use int instead of float
        startPfxCompiled(false);/* w w w .  ja  v  a  2 s.  c  om*/

        for (int n = 0; n < vsize; n++) {
            prepareVdForStoreInt(n);
            loadVsInt(n);
            storeVdInt(n);
        }

        endPfxCompiled(vsize, false);
    } else {
        startPfxCompiled(true);

        for (int n = 0; n < vsize; n++) {
            prepareVdForStore(n);
            if (cstBefore != null) {
                mv.visitLdcInsn(cstBefore);
            }

            loadVs(n);
            if (useVt) {
                loadVt(n);
            }
            if (mathFunction != null) {
                if ("abs".equals(mathFunction)) {
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction,
                            "(F)F");
                } else if ("max".equals(mathFunction) || "min".equals(mathFunction)) {
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction,
                            "(FF)F");
                } else {
                    mv.visitInsn(Opcodes.F2D);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction,
                            "(D)D");
                    mv.visitInsn(Opcodes.D2F);
                }
            }

            Label doneStore = null;
            if (opcode != Opcodes.NOP) {
                Label doneOpcode = null;

                if (opcode == Opcodes.FDIV && cstBefore == null) {
                    // if (value1 == 0f && value2 == 0f) {
                    //     result = PSP-NaN | (sign(value1) ^ sign(value2));
                    // } else {
                    //     result = value1 / value2;
                    // }
                    doneOpcode = new Label();
                    doneStore = new Label();
                    Label notZeroByZero = new Label();
                    Label notZeroByZeroPop = new Label();
                    mv.visitInsn(Opcodes.DUP2);
                    mv.visitInsn(Opcodes.FCONST_0);
                    mv.visitInsn(Opcodes.FCMPG);
                    mv.visitJumpInsn(Opcodes.IFNE, notZeroByZeroPop);
                    mv.visitInsn(Opcodes.FCONST_0);
                    mv.visitInsn(Opcodes.FCMPG);
                    mv.visitJumpInsn(Opcodes.IFNE, notZeroByZero);
                    convertVFloatToInt();
                    loadImm(0x80000000);
                    mv.visitInsn(Opcodes.IAND);
                    mv.visitInsn(Opcodes.SWAP);
                    convertVFloatToInt();
                    loadImm(0x80000000);
                    mv.visitInsn(Opcodes.IAND);
                    mv.visitInsn(Opcodes.IXOR);
                    storeTmp1();
                    // Store the NaN value as an "int" to not loose any bit.
                    // Storing as float results in 0x7FC00001 instead of 0x7F800001.
                    mv.visitInsn(Opcodes.DUP2_X2);
                    mv.visitInsn(Opcodes.POP2);
                    loadPspNaNInt();
                    loadTmp1();
                    mv.visitInsn(Opcodes.IOR);
                    int preparedRegister = preparedRegisterForStore;
                    storeVdInt(n);
                    preparedRegisterForStore = preparedRegister;
                    mv.visitJumpInsn(Opcodes.GOTO, doneStore);

                    mv.visitLabel(notZeroByZeroPop);
                    mv.visitInsn(Opcodes.POP);
                    mv.visitLabel(notZeroByZero);
                }

                mv.visitInsn(opcode);

                if (doneOpcode != null) {
                    mv.visitLabel(doneOpcode);
                }
            }

            storeVd(n);

            if (doneStore != null) {
                mv.visitLabel(doneStore);
            }
        }

        endPfxCompiled(vsize, true);
    }
}

From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java

License:Apache License

public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.NOP:
        break;//from   w ww .  j  a  v a 2 s  .c om
    case Opcodes.ACONST_NULL:
        push("null", Object.class);
        break;
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
        push(Integer.toString(opcode - Opcodes.ICONST_0), Type.INT_TYPE);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        push(Integer.toString(opcode - Opcodes.LCONST_0), Type.LONG_TYPE);
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        push(Integer.toString(opcode - Opcodes.FCONST_0), Type.FLOAT_TYPE);
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        push(Integer.toString(opcode - Opcodes.DCONST_0), Type.DOUBLE_TYPE);
        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: {
        Type opType = getType(Opcodes.IALOAD, opcode);
        StackValue idx = pop(Type.INT_TYPE);
        StackValue arr = popArray(opType);
        push(arr.description + "[" + idx.description + "]", opType);
    }
        break;
    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE: {
        Type opType = getType(Opcodes.IASTORE, opcode);
        pop(opType);
        pop(Type.INT_TYPE);
        popArray(opType);
    }
        break;
    case Opcodes.POP:
        pop();
        break;
    case Opcodes.POP2:
        pop(2);
        break;
    case Opcodes.DUP:
        push(peek());
        break;
    case Opcodes.DUP2:
        push(peek(2));
        push(peek(1));
        break;
    case Opcodes.DUP_X1: {
        StackValue a = pop();
        StackValue b = pop();
        push(a);
        push(b);
        push(a);
    }
        break;
    case Opcodes.DUP_X2: {
        StackValue a = pop();
        StackValue b = pop();
        StackValue c = pop();
        push(a);
        push(c);
        push(b);
        push(a);
    }
        break;
    case Opcodes.DUP2_X1: {
        StackValue a = popValue(false);
        StackValue b = pop();
        StackValue c = pop();
        push(b);
        push(a);
        push(c);
        push(b);
        push(a);
    }
    case Opcodes.DUP2_X2: {
        StackValue a = popValue(false);
        StackValue b = pop();
        StackValue c = popValue(false);
        StackValue d = pop();
        push(b);
        push(a);
        push(d);
        push(c);
        push(b);
        push(a);
    }
        break;
    case Opcodes.SWAP: {
        StackValue a = pop();
        StackValue b = pop();
        push(a);
        push(b);
    }
        break;
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        math(Opcodes.IADD, opcode, "+");
        break;
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        math(Opcodes.ISUB, opcode, "-");
        break;
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        math(Opcodes.IMUL, opcode, "*");
        break;
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        math(Opcodes.IDIV, opcode, "/");
        break;
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        math(Opcodes.IREM, opcode, "%");
        break;
    case Opcodes.IAND:
    case Opcodes.LAND:
        math(Opcodes.IAND, opcode, "&");
        break;
    case Opcodes.IOR:
    case Opcodes.LOR:
        math(Opcodes.IOR, opcode, "|");
        break;
    case Opcodes.IXOR:
    case Opcodes.LXOR:
        math(Opcodes.IXOR, opcode, "^");
        break;
    case Opcodes.INEG:
    case Opcodes.LNEG:
    case Opcodes.FNEG:
    case Opcodes.DNEG: {
        Type type = getType(Opcodes.INEG, opcode);
        StackValue a = pop(type);
        push("-" + a.description, type);
    }
        break;
    case Opcodes.ISHL:
    case Opcodes.LSHL: {
        Type type = getType(Opcodes.ISHL, opcode);
        StackValue n = pop(Type.INT_TYPE);
        StackValue a = pop(type);
        push(a.description + "<<" + n.description, type);
    }
        break;
    case Opcodes.ISHR:
    case Opcodes.LSHR: {
        Type type = getType(Opcodes.ISHR, opcode);
        StackValue n = pop(Type.INT_TYPE);
        StackValue a = pop(type);
        push(a.description + ">>" + n.description, type);
    }
        break;
    case Opcodes.IUSHR:
    case Opcodes.LUSHR: {
        Type type = getType(Opcodes.IUSHR, opcode);
        StackValue n = pop(Type.INT_TYPE);
        StackValue a = pop(type);
        push(a.description + ">>>" + n.description, type);
    }
    case Opcodes.LCMP: {
        StackValue a = pop(Type.LONG_TYPE);
        StackValue b = pop(Type.LONG_TYPE);
        push(a.description + " cmp " + b.description + " {-1|0|1}", Type.LONG_TYPE);
    }
        break;
    case Opcodes.I2L:
    case Opcodes.I2F:
    case Opcodes.I2D:
    case Opcodes.L2I:
    case Opcodes.L2F:
    case Opcodes.L2D:
    case Opcodes.F2I:
    case Opcodes.F2L:
    case Opcodes.F2D:
    case Opcodes.D2I:
    case Opcodes.D2L:
    case Opcodes.D2F:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
        cast(opcode);
        break;
    case Opcodes.ARETURN:
    case Opcodes.ATHROW:
        popObject();
        break;
    case Opcodes.RETURN:
        break;
    default:
        throw new IllegalArgumentException("Unsupported opcode " + opcode + " - " + OPCODES[opcode]);
    }
    print(opcode, "");
    /* 
        *        FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
        *        FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
        *        MONITORENTER, or MONITOREXIT
      */

}

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

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    T t = null;// w  w  w.j  a v  a2 s.  c o  m
    int iValue = Integer.MIN_VALUE;
    Object oValue = null;

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