Example usage for org.objectweb.asm Opcodes GOTO

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

Introduction

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

Prototype

int GOTO

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

Click Source Link

Usage

From source file:io.syncframework.optimizer.OControllerStaticMethodVisitor.java

License:Apache License

public void visitInsn(int opcode) {
    if (opcode != Opcodes.RETURN) {
        mv.visitInsn(opcode);/*from  ww  w  .ja va  2  s  .c  om*/
        return;
    }

    Label start = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    Label interceptorsLabel = new Label();

    mv.visitCode();
    mv.visitTryCatchBlock(start, l1, l2, "java/lang/Throwable");

    /*
     * _asActions = new HashMap<String,Boolean>();
     */
    {
        mv.visitLabel(start);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;");
    }
    /*
     * _asActions.put("main", true);
     * _asActions.put("action1", true);
     */
    for (String name : reflector.getActions().keySet()) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;",
                false);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /*
     * _asInterceptors = new HashMap<String,Class<?>[]>()
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asInterceptors",
                "Ljava/util/Map;");
    }

    /*
     * List<Class<?>> l = new ArrayList<Class<?>>();
     */
    mv.visitLabel(interceptorsLabel);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
    mv.visitVarInsn(Opcodes.ASTORE, 0);

    for (String name : reflector.getActions().keySet()) {
        Class<?> interceptors[] = reflector.getInterceptors().get(name);
        if (interceptors == null || interceptors.length == 0)
            continue;

        /*
         * l.clear();
         */
        Label l01 = new Label();
        mv.visitLabel(l01);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "clear", "()V", true);

        for (Class<?> interceptor : interceptors) {
            /*
             * l.add(LoginInterceptor.class);
             */
            Label l02 = new Label();
            mv.visitLabel(l02);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitLdcInsn(Type.getType(interceptor));
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        }

        /*
         * _asInterceptors.put("upload", l.toArray(new Class[0]));
         */
        Label l03 = new Label();
        mv.visitLabel(l03);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asInterceptors",
                "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Class");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "toArray",
                "([Ljava/lang/Object;)[Ljava/lang/Object;", true);
        mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /* 
     * _asParameters = new HashMap<String,Class<?>>() 
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
    }
    /*
     * _asParameters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitLdcInsn(Type.getType(reflector.getParameters().get(name)));
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /* 
     * _asConverters = new HashMap<String,Class<?>>() 
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asConverters",
                "Ljava/util/Map;");
    }
    /*
     * _asConverters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        if (reflector.getConverters().get(name) != null) {
            Class<?> converter = reflector.getConverters().get(name);
            Label l = new Label();
            mv.visitLabel(l);
            mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters",
                    "Ljava/util/Map;");
            mv.visitLdcInsn(name);
            mv.visitLdcInsn(Type.getType(converter));
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                    "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
            mv.visitInsn(Opcodes.POP);
        }
    }

    /*
     * }
     * catch(Throwable t) {
     *    throw t;
     * }
     */
    Label throwableStart = new Label();
    Label throwableEnd = new Label();

    mv.visitLabel(l1);
    mv.visitJumpInsn(Opcodes.GOTO, throwableEnd);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
    mv.visitVarInsn(Opcodes.ASTORE, 0);
    mv.visitLabel(throwableStart);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ATHROW);

    mv.visitLabel(throwableEnd);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitLocalVariable("l", "Ljava/util/List;", null, interceptorsLabel, l1, 0);
    mv.visitLocalVariable("t", "Ljava/lang/Throwable;", null, throwableStart, throwableEnd, 0);
}

From source file:io.syncframework.optimizer.OInterceptorStaticMethodVisitor.java

License:Apache License

public void visitInsn(int opcode) {
    if (opcode != Opcodes.RETURN) {
        mv.visitInsn(opcode);//from w  ww .  ja  va  2 s .  c  om
        return;
    }

    Label start = new Label();
    Label l1 = new Label();
    Label l2 = new Label();

    mv.visitCode();
    mv.visitTryCatchBlock(start, l1, l2, "java/lang/Throwable");

    /* 
     * _asParameters = new HashMap<String,Class<?>>() 
     */
    {
        mv.visitLabel(start);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
    }
    /*
     * _asParameters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitLdcInsn(Type.getType(reflector.getParameters().get(name)));
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /* 
     * _asConverters = new HashMap<String,Class<?>>() 
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asConverters",
                "Ljava/util/Map;");
    }
    /*
     * _asConverters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        if (reflector.getConverters().get(name) != null) {
            Class<?> converter = reflector.getConverters().get(name);
            Label l = new Label();
            mv.visitLabel(l);
            mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters",
                    "Ljava/util/Map;");
            mv.visitLdcInsn(name);
            mv.visitLdcInsn(Type.getType(converter));
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                    "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
            mv.visitInsn(Opcodes.POP);
        }
    }

    /*
     * }
     * catch(Throwable t) {
     *    throw t;
     * }
     */
    Label throwableStart = new Label();
    Label throwableEnd = new Label();

    mv.visitLabel(l1);
    mv.visitJumpInsn(Opcodes.GOTO, throwableEnd);

    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
    mv.visitVarInsn(Opcodes.ASTORE, 0);

    mv.visitLabel(throwableStart);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ATHROW);

    mv.visitLabel(throwableEnd);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitLocalVariable("t", "Ljava/lang/Throwable;", null, throwableStart, throwableEnd, 0);
}

From source file:jaspex.speculation.newspec.RemoveOverspeculation.java

License:Open Source License

/** Scan simples para tentar eliminar overspeculation.
  *//from  w  w w  .j a  va2  s.c  o  m
  * A ideia deste mtodo  determinar se entre uma operao de spawnSpeculation e o get do seu Future /
  * nonTransactionalActionAttempted existem instruces suficientes para valer o trabalho de fazer
  * especulao.
  *
  * Quando observamos um spawnSpeculation, comeamos a fazer tracking dele. Se virmos alguma
  * operao complexa (alguns saltos, outros mtodos, etc), paramos o tracking. Caso contrrio, se
  * ainda estivermos a fazer tracking quando encontramos o get / nonTransactionalActionAttempted, ento
  * colocamos o mtodo na lista de especulaes a rejeitar.
  **/
private TrackingResult scanFuture(MethodInsnNode tracking, AbstractInsnNode start) {
    for (AbstractInsnNode node = start; node != null; node = node.getNext()) {
        if (node instanceof MethodInsnNode) {
            MethodInsnNode mInsn = (MethodInsnNode) node;

            if (mInsn.owner.equals(CommonTypes.CONTSPECULATIONCONTROL.asmName())
                    && mInsn.name.equals("spawnSpeculation")) {
                // do nothing
            } else if (mInsn.owner.startsWith(CommonTypes.FUTURE.asmName()) && mInsn.name.equals("get")) {
                int futureId = Integer.parseInt(mInsn.owner.substring(mInsn.owner.lastIndexOf('$') + 1));

                if (getFutureId(tracking) == futureId) {
                    return TrackingResult.NEEDVALUE;
                }
            } else if (mInsn.owner.equals(CommonTypes.SPECULATIONCONTROL.asmName())
                    && (mInsn.name.equals("nonTransactionalActionAttempted")
                            || mInsn.name.equals("blacklistedActionAttempted"))) {
                return TrackingResult.FORCEDSYNC;
            } else if (mInsn.owner.equals(CommonTypes.TRANSACTION.asmName())
                    || mInsn.owner.equals(CommonTypes.MARKER_BEFOREINLINEDSTORE)
                    || mInsn.owner.equals(CommonTypes.DEBUGCLASS.asmName())) {
                continue;
            } else if (mInsn.owner.equals(CommonTypes.REPLACEMENTS.asmName())) {
                // do nothing
            } else if (mInsn.owner.startsWith("jaspex")
                    && !CodegenHelper.isCodegenClass(Type.fromAsm(mInsn.owner))) {
                throw new AssertionError("Resetting tracking due to call to " + mInsn.owner + "." + mInsn.name);
            }

            return TrackingResult.OK;
        } else if (node instanceof JumpInsnNode) {
            JumpInsnNode jInsn = (JumpInsnNode) node;

            if (_mNode.instructions.indexOf(jInsn) > _mNode.instructions.indexOf(jInsn.label)) {
                // Salto para trs, no continuar tracking
                return TrackingResult.OK;
            }

            if (jInsn.getOpcode() == Opcodes.GOTO)
                return scanFuture(tracking, jInsn.label);
            if (jInsn.getOpcode() == Opcodes.JSR)
                throw new AssertionError();

            // Opcode  um de
            // IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT,
            // IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, IFNULL, IFNONNULL
            // Portanto vamos ter que analisar ambos os branches

            return TrackingResult.combine(scanFuture(tracking, jInsn.getNext()),
                    scanFuture(tracking, jInsn.label));
        } else if (node instanceof LookupSwitchInsnNode || node instanceof TableSwitchInsnNode) {
            List<LabelNode> targets = new UtilArrayList<LabelNode>();

            // Infelizmente o ASM no tem uma classe comum entre os dois tipos de switch
            if (node instanceof LookupSwitchInsnNode) {
                LookupSwitchInsnNode sInsn = (LookupSwitchInsnNode) node;
                if (sInsn.dflt != null)
                    targets.add(sInsn.dflt);
                targets.addAll(sInsn.labels);
            } else {
                TableSwitchInsnNode sInsn = (TableSwitchInsnNode) node;
                if (sInsn.dflt != null)
                    targets.add(sInsn.dflt);
                targets.addAll(sInsn.labels);
            }

            // Vamos analisar todos os targets do switch e fazer merge do resultado
            TrackingResult mergedResult = null;
            for (LabelNode l : targets) {
                TrackingResult res = scanFuture(tracking, l);

                if (mergedResult == null) {
                    mergedResult = res;
                } else {
                    mergedResult = TrackingResult.combine(mergedResult, res);
                }
            }

            return mergedResult;
        } else if (node instanceof InsnNode) {
            InsnNode insn = (InsnNode) node;

            // Encontrmos fim do mtodo
            if (insn.getOpcode() == Opcodes.ATHROW || returnOpcodes.contains(insn.getOpcode())) {
                if (new InvokedMethod(_mNode).returnType().equals(Type.PRIM_VOID)) {
                    // Caso especial: Todos os mtodos que retornam void so
                    // escolhidos para especulao -- Uma consequncia directa
                    // disso  que ter um futuro activo aquando do retorno do
                    // mtodo no serve para nada, j que a nica coisa que vai
                    // acontecer  a especulao acabada de criar vai tentar fazer
                    // commit imediatamente
                    return TrackingResult.FORCEDSYNC;
                }

                return TrackingResult.OK;
            }
        }
    }

    // FIXME: Alguma vez aqui chegamos?
    //return TrackingResult.OK;
    throw new AssertionError("FIXME");
}

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

License:Open Source License

private Class<IExecutable> compile(CompilerContext context) throws ClassFormatError {
    Class<IExecutable> compiledClass = null;

    context.setCodeBlock(this);
    String className = getInternalClassName();
    if (log.isDebugEnabled()) {
        String functionName = Utilities.getFunctionNameByAddress(getStartAddress());

        if (functionName != null) {
            log.debug(String.format("Compiling %s (%s)", className, functionName));
        } else {/*ww w  .j  a  v a  2s  .com*/
            log.debug(String.format("Compiling %s", className));
        }
    }

    prepare(context, context.getMethodMaxInstructions());

    currentSequence = null;
    int computeFlag = ClassWriter.COMPUTE_FRAMES;
    if (context.isAutomaticMaxLocals() || context.isAutomaticMaxStack()) {
        computeFlag |= ClassWriter.COMPUTE_MAXS;
    }
    ClassWriter cw = new ClassWriter(computeFlag);
    ClassVisitor cv = cw;
    if (log.isDebugEnabled()) {
        cv = new CheckClassAdapter(cv);
    }
    StringWriter debugOutput = null;
    if (log.isTraceEnabled()) {
        debugOutput = new StringWriter();
        PrintWriter debugPrintWriter = new PrintWriter(debugOutput);
        cv = new TraceClassVisitor(cv, debugPrintWriter);
    }
    cv.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, objectInternalName,
            interfacesForExecutable);
    context.startClass(cv);

    addConstructor(cv);
    addNonStaticMethods(context, cv);

    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
            context.getStaticExecMethodName(), context.getStaticExecMethodDesc(), null, exceptions);
    mv.visitCode();
    context.setMethodVisitor(mv);
    context.startMethod();

    // Jump to the block start if other instructions have been inserted in front
    if (!codeInstructions.isEmpty() && codeInstructions.getFirst().getAddress() != getStartAddress()) {
        mv.visitJumpInsn(Opcodes.GOTO, getCodeInstruction(getStartAddress()).getLabel());
    }

    compile(context, mv, codeInstructions);
    mv.visitMaxs(context.getMaxStack(), context.getMaxLocals());
    mv.visitEnd();

    for (SequenceCodeInstruction sequenceCodeInstruction : sequenceCodeInstructions) {
        if (log.isDebugEnabled()) {
            log.debug("Compiling Sequence " + sequenceCodeInstruction.getMethodName(context));
        }
        currentSequence = sequenceCodeInstruction;
        mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
                sequenceCodeInstruction.getMethodName(context), "()V", null, exceptions);
        mv.visitCode();
        context.setMethodVisitor(mv);
        context.startSequenceMethod();

        compile(context, mv, sequenceCodeInstruction.getCodeSequence().getInstructions());

        context.endSequenceMethod();
        mv.visitMaxs(context.getMaxStack(), context.getMaxLocals());
        mv.visitEnd();
    }
    currentSequence = null;

    cv.visitEnd();

    if (debugOutput != null) {
        log.trace(debugOutput.toString());
    }

    try {
        compiledClass = loadExecutable(context, className, cw.toByteArray());
    } catch (NullPointerException e) {
        log.error("Error while compiling " + className + ": " + e);
    }

    return compiledClass;
}

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

License:Open Source License

private int getBranchingOpcodeBranch0(CompilerContext context, MethodVisitor mv) {
    compileDelaySlot(context, mv);//from   w w w. j ava2 s . c o m

    if (getBranchingTo() == getAddress()) {
        context.visitLogInfo(mv,
                String.format("Pausing emulator - jump to self (death loop) at 0x%08X", getAddress()));
        context.visitPauseEmuWithStatus(mv, Emulator.EMU_STATUS_JUMPSELF);
    }

    return Opcodes.GOTO;
}

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

License:Open Source License

private int getBranchingOpcodeBranch1L(CompilerContext context, MethodVisitor mv, int branchingOpcode,
        int notBranchingOpcode) {
    context.loadRs();/*from w  w w . jav  a  2s  . co  m*/
    CodeInstruction afterDelaySlotCodeInstruction = getAfterDelaySlotCodeInstruction(context);
    context.visitJump(notBranchingOpcode, afterDelaySlotCodeInstruction);
    compileDelaySlot(context, mv);

    return Opcodes.GOTO;
}

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

License:Open Source License

private int loadRegistersForBranchingOpcodeBranch2(CompilerContext context, MethodVisitor mv,
        int branchingOpcode) {
    boolean loadRs = true;
    boolean loadRt = true;

    if (context.getRsRegisterIndex() == context.getRtRegisterIndex()) {
        if (branchingOpcode == Opcodes.IF_ICMPEQ) {
            loadRs = false;//from  www. j  a  v a 2s .c  o m
            loadRt = false;
            branchingOpcode = Opcodes.GOTO;

            // The ASM library has problems with small frames having no
            // stack (NullPointerException). Generate a dummy stack requirement:
            //   ILOAD 0
            //   POP
            context.loadImm(0);
            context.getMethodVisitor().visitInsn(Opcodes.POP);
        } else if (branchingOpcode == Opcodes.IF_ICMPNE) {
            loadRs = false;
            loadRt = false;
            branchingOpcode = Opcodes.NOP;
        }
    } else if (context.isRsRegister0()) {
        if (branchingOpcode == Opcodes.IF_ICMPEQ) {
            loadRs = false;
            branchingOpcode = Opcodes.IFEQ;
        } else if (branchingOpcode == Opcodes.IF_ICMPNE) {
            loadRs = false;
            branchingOpcode = Opcodes.IFNE;
        }
    } else if (context.isRtRegister0()) {
        if (branchingOpcode == Opcodes.IF_ICMPEQ) {
            loadRt = false;
            branchingOpcode = Opcodes.IFEQ;
        } else if (branchingOpcode == Opcodes.IF_ICMPNE) {
            loadRt = false;
            branchingOpcode = Opcodes.IFNE;
        }
    }

    if (loadRs) {
        context.loadRs();
    }
    if (loadRt) {
        context.loadRt();
    }

    return branchingOpcode;
}

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

License:Open Source License

private int getBranchingOpcodeBranch2(CompilerContext context, MethodVisitor mv, int branchingOpcode,
        int notBranchingOpcode) {
    // Retrieve the registers for the branching opcode before executing
    // the delay slot instruction, as it might theoretically modify the
    // content of these registers.
    branchingOpcode = loadRegistersForBranchingOpcodeBranch2(context, mv, branchingOpcode);

    CodeInstruction delaySlotCodeInstruction = getDelaySlotCodeInstruction(context);
    if (delaySlotCodeInstruction != null
            && delaySlotCodeInstruction.hasFlags(Instruction.FLAG_HAS_DELAY_SLOT)) {
        // We are compiling a sequence where the delay instruction has itself a delay slot:
        //    beq $reg1, $reg2, label
        //    jr  $ra
        //    nop
        // Handle the sequence by inserting one nop between the instructions:
        //    bne $reg1, $reg2, label
        //    nop
        //    jr  $ra
        //    nop
        String lineSeparator = System.getProperty("line.separator");
        log.warn(String.format("Instruction in a delay slot having a delay slot:%s%s%s%s", lineSeparator, this,
                lineSeparator, delaySlotCodeInstruction));
    } else {/*from   ww  w.  ja  v a  2  s. c  o m*/
        compileDelaySlot(context, mv, delaySlotCodeInstruction);
    }

    if (branchingOpcode == Opcodes.GOTO && getBranchingTo() == getAddress()
            && delaySlotCodeInstruction.getOpcode() == NOP()) {
        context.visitLogInfo(mv,
                String.format("Pausing emulator - branch to self (death loop) at 0x%08X", getAddress()));
        context.visitPauseEmuWithStatus(mv, Emulator.EMU_STATUS_JUMPSELF);
    }

    return branchingOpcode;
}

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

License:Open Source License

private int getBranchingOpcodeBranch2L(CompilerContext context, MethodVisitor mv, int branchingOpcode,
        int notBranchingOpcode) {
    // Retrieve the registers for the branching opcode before executing
    // the delay slot instruction, as it might theoretically modify the
    // content of these registers.
    notBranchingOpcode = loadRegistersForBranchingOpcodeBranch2(context, mv, notBranchingOpcode);
    if (notBranchingOpcode != Opcodes.NOP) {
        CodeInstruction afterDelaySlotCodeInstruction = getAfterDelaySlotCodeInstruction(context);
        context.visitJump(notBranchingOpcode, afterDelaySlotCodeInstruction);
    }//from  w  w  w . j  av  a 2s.  c o m
    compileDelaySlot(context, mv);

    return Opcodes.GOTO;
}

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

License:Open Source License

private int getBranchingOpcodeBC1L(CompilerContext context, MethodVisitor mv, int branchingOpcode,
        int notBranchingOpcode) {
    context.loadFcr31c();/*  w  w w.jav  a 2  s .  c  om*/
    CodeInstruction afterDelaySlotCodeInstruction = getAfterDelaySlotCodeInstruction(context);
    context.visitJump(notBranchingOpcode, afterDelaySlotCodeInstruction);
    compileDelaySlot(context, mv);

    return Opcodes.GOTO;
}