Example usage for org.objectweb.asm Opcodes IALOAD

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

Introduction

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

Prototype

int IALOAD

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

Click Source Link

Usage

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

License:BSD License

private void visitArrayLoadInsn(final int opcode) {
    super.visitInsn(Opcodes.DUP2);

    super.visitInsn(opcode);

    if (opcode == Opcodes.LALOAD || opcode == Opcodes.DALOAD)
        super.visitInsn(Opcodes.DUP2_X2);
    else//from w ww .  j  a v  a 2 s .  c  om
        super.visitInsn(Opcodes.DUP_X2);

    switch (opcode) {
    case Opcodes.AALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.getObjectType("java/lang/Object"));
        break;
    case Opcodes.BALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.BYTE_TYPE);
        break;
    case Opcodes.CALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.CHAR_TYPE);
        break;
    case Opcodes.FALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.FLOAT_TYPE);
        break;
    case Opcodes.IALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.INT_TYPE);
        break;
    case Opcodes.SALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.SHORT_TYPE);
        break;
    case Opcodes.DALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.DOUBLE_TYPE);
        break;
    case Opcodes.LALOAD:
        LoggingHelper.emitConvertToString(this.mv, Type.LONG_TYPE);
        break;
    }

    LoggingHelper.emitLogArray(this.mv, Logger.ArrayAction.GETA);
}

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

License:Open Source License

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

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

License:Open Source License

private void emit(ArrayLoadInst i, InsnList insns) {
    load(i.getArray(), insns);//w w w . j  av a 2s.c o  m
    load(i.getIndex(), insns);
    if (i.getType() instanceof ReferenceType)
        insns.add(new InsnNode(Opcodes.AALOAD));
    else if (i.getType().equals(booleanType) || i.getType().equals(byteType))
        insns.add(new InsnNode(Opcodes.BALOAD));
    else if (i.getType().equals(charType))
        insns.add(new InsnNode(Opcodes.CALOAD));
    else if (i.getType().equals(shortType))
        insns.add(new InsnNode(Opcodes.SALOAD));
    else if (i.getType().equals(intType))
        insns.add(new InsnNode(Opcodes.IALOAD));
    else if (i.getType().equals(longType))
        insns.add(new InsnNode(Opcodes.LALOAD));
    else if (i.getType().equals(floatType))
        insns.add(new InsnNode(Opcodes.FALOAD));
    else if (i.getType().equals(doubleType))
        insns.add(new InsnNode(Opcodes.DALOAD));
    else
        throw new AssertionError(i);
    store(i, insns);
}

From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    Type arrayElementType = null;
    boolean isArrayLoad = (Opcodes.IALOAD <= opcode && opcode < Opcodes.IALOAD + 8);
    boolean isArrayStore = (Opcodes.IASTORE <= opcode && opcode < Opcodes.IASTORE + 8);
    if (isArrayLoad || isArrayStore) {
        switch (opcode) {
        case Opcodes.IALOAD:
            arrayElementType = Type.INT_TYPE;
            break;
        case Opcodes.LALOAD:
            arrayElementType = Type.LONG_TYPE;
            break;
        case Opcodes.FALOAD:
            arrayElementType = Type.FLOAT_TYPE;
            break;
        case Opcodes.DALOAD:
            arrayElementType = Type.DOUBLE_TYPE;
            break;
        case Opcodes.AALOAD:
            arrayElementType = hologramType;
            break;
        case Opcodes.BALOAD:
            arrayElementType = Type.BYTE_TYPE;
            break;
        case Opcodes.CALOAD:
            arrayElementType = Type.CHAR_TYPE;
            break;
        case Opcodes.SALOAD:
            arrayElementType = Type.SHORT_TYPE;
            break;
        case Opcodes.IASTORE:
            arrayElementType = Type.INT_TYPE;
            break;
        case Opcodes.LASTORE:
            arrayElementType = Type.LONG_TYPE;
            break;
        case Opcodes.FASTORE:
            arrayElementType = Type.FLOAT_TYPE;
            break;
        case Opcodes.DASTORE:
            arrayElementType = Type.DOUBLE_TYPE;
            break;
        case Opcodes.AASTORE:
            arrayElementType = hologramType;
            break;
        case Opcodes.BASTORE:
            arrayElementType = Type.BYTE_TYPE;
            break;
        case Opcodes.CASTORE:
            arrayElementType = Type.CHAR_TYPE;
            break;
        case Opcodes.SASTORE:
            arrayElementType = Type.SHORT_TYPE;
            break;
        }//from  w w w.  j  av  a 2  s. c  om

        Type mirrorType = HologramClassGenerator.objectArrayMirrorType;
        if (arrayElementType.getSort() != Type.OBJECT && arrayElementType.getSort() != Type.ARRAY) {
            mirrorType = getPrimitiveArrayMirrorType(arrayElementType);
        }

        // Use the analyzer to figure out the expected array element type
        Type arrayElementTypeForMirrorCall = arrayElementType;
        Type hologramArrayType = Type
                .getObjectType((String) stackType(isArrayStore ? 1 + arrayElementType.getSize() : 1));
        if (hologramArrayType == null) {
            hologramArrayType = Type.getType(ObjectArrayHologram.class);
        }
        if (arrayElementType.equals(hologramType)) {
            Type originalType = Type
                    .getObjectType(getOriginalInternalClassName(hologramArrayType.getInternalName()));
            arrayElementType = getHologramType(
                    Reflection.makeArrayType(originalType.getDimensions() - 1, originalType.getElementType()));
            hologramArrayType = Type.getType(ObjectArrayHologram.class);
        }

        // Call the appropriate getter/setter method on the hologram
        String methodDesc;
        if (isArrayStore) {
            methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, mirrorType, Type.INT_TYPE,
                    arrayElementTypeForMirrorCall);
        } else {
            methodDesc = Type.getMethodDescriptor(arrayElementTypeForMirrorCall, mirrorType, Type.INT_TYPE);
        }
        invokestatic(hologramArrayType.getInternalName(), (isArrayStore ? "setHologram" : "getHologram"),
                methodDesc);
        if (!isArrayStore && arrayElementTypeForMirrorCall.equals(hologramType)) {
            checkcast(arrayElementType);
        }

        return;
    }

    if (opcode == Opcodes.ARRAYLENGTH) {
        invokeinterface(arrayMirrorType.getInternalName(), "length", Type.getMethodDescriptor(Type.INT_TYPE));
        return;
    }

    if (opcode == Opcodes.ARETURN) {
        if (isToString) {
            invokestatic(objectHologramType.getInternalName(), "getRealStringForHologram",
                    Type.getMethodDescriptor(Type.getType(String.class), Type.getType(ObjectHologram.class)));
        } else if (isGetStackTrace) {
            invokestatic(objectHologramType.getInternalName(), "getRealStackTraceForHologram",
                    Type.getMethodDescriptor(Type.getType(StackTraceElement[].class),
                            Type.getType(Hologram.class)));
        }
    }

    if (opcode == Opcodes.RETURN && owner.equals(hologramThrowableType) && name.equals("<init>")) {
        load(0, owner);
        new MethodHandle() {
            protected void methodCall() throws Throwable {
                ObjectHologram.register(null);
                ;
            }
        }.invoke(this);
    }

    super.visitInsn(opcode);
}

From source file:jerl.bcm.inj.impl.InjectCollection.java

License:Apache License

public void injectMemberFieldArraySystemOut(MethodVisitor mv, String clazz, String field, String type,
        String printType, String prefix, boolean isStatic, int index) {
    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn(prefix);/*from  ww  w.jav  a2 s. c o m*/
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V");

    mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    if (isStatic) {
        mv.visitFieldInsn(Opcodes.GETSTATIC, clazz, field, type);
    } else {
        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitFieldInsn(Opcodes.GETFIELD, clazz, field, type);
    }
    mv.visitLdcInsn(new Integer(index));

    if (type.endsWith("[Z") || type.endsWith("[B")) {
        mv.visitInsn(Opcodes.BALOAD);
    } else if (type.endsWith("[C")) {
        mv.visitInsn(Opcodes.CALOAD);
    } else if (type.endsWith("[D")) {
        mv.visitInsn(Opcodes.DALOAD);
    } else if (type.endsWith("[F")) {
        mv.visitInsn(Opcodes.FALOAD);
    } else if (type.endsWith("[I")) {
        mv.visitInsn(Opcodes.IALOAD);
    } else if (type.endsWith("[J")) {
        mv.visitInsn(Opcodes.LALOAD);
    } else if (type.endsWith("[S")) {
        mv.visitInsn(Opcodes.SALOAD);
    } else {
        mv.visitInsn(Opcodes.AALOAD);
    }
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(" + printType + ")V");
}

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

License:Open Source License

private void loadVRegister(int m, int c, int r, boolean isFloat) {
    int index = VfpuState.getVprIndex(m, c, r);
    if (isFloat) {
        loadVprFloat();//from   ww  w .j  ava2s .c o  m
        loadImm(index);
        mv.visitInsn(Opcodes.FALOAD);
    } else {
        loadVprInt();
        loadImm(index);
        mv.visitInsn(Opcodes.IALOAD);
    }
}

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

License:Open Source License

@Override
public void memRead32(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();/*w ww  .j  ava 2 s . c  om*/
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    prepareMemIndex(registerIndex, offset, true, 32);

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I");
    } else {
        mv.visitInsn(Opcodes.IALOAD);
    }
}

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

License:Open Source License

@Override
public void memRead16(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();/*from   w  ww.  j  a va2 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.  jav a 2s  .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 a  v  a2s. 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, "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;
}