Example usage for org.objectweb.asm Opcodes IF_ICMPNE

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

Introduction

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

Prototype

int IF_ICMPNE

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

Click Source Link

Usage

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.JumpInstruction2.java

License:Open Source License

@Override
public String toString() {
    String condition;/*  ww  w.  ja va 2s . c  om*/
    switch (getOpcode()) {
    case Opcodes.IFEQ:
        condition = "IFEQ";
        break;
    case Opcodes.IFNE:
        condition = "IFNE";
        break;
    case Opcodes.IFLT:
        condition = "IFLT";
        break;
    case Opcodes.IFGE:
        condition = "IFGE";
        break;
    case Opcodes.IFGT:
        condition = "IFGT";
        break;
    case Opcodes.IFLE:
        condition = "IFLE";
        break;
    case Opcodes.IF_ICMPEQ:
        condition = "IF_ICMPEQ";
        break;
    case Opcodes.IF_ICMPNE:
        condition = "IF_ICMPNE";
        break;
    case Opcodes.IF_ICMPLT:
        condition = "IF_ICMPLT";
        break;
    case Opcodes.IF_ICMPGE:
        condition = "IF_ICMPGE";
        break;
    case Opcodes.IF_ICMPGT:
        condition = "IF_ICMPGT";
        break;
    case Opcodes.IF_ICMPLE:
        condition = "IF_ICMPLE";
        break;
    case Opcodes.IF_ACMPEQ:
        condition = "IF_ACMPEQ";
        break;
    case Opcodes.IF_ACMPNE:
        condition = "IF_ACMPNE";
        break;
    case Opcodes.GOTO:
        condition = "GOTO";
        break;
    case Opcodes.JSR:
        condition = "JSR";
        break;
    case Opcodes.IFNULL:
        condition = "IFNULL";
        break;
    case Opcodes.IFNONNULL:
        condition = "IFNONNULL";
        break;
    default:
        assert false;
        condition = "--ERROR--";
        break;
    }

    return condition + " " + this.target;
}

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

License:BSD License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    mv.visitJumpInsn(opcode, label);/*from  ww  w . j ava  2 s .c om*/
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        this.stackFrame.pop();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.JSR:
        this.stackFrame.push(OTHER);
        break;
    }
    addBranch(label);
}

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

License:Open Source License

private void interpret(JumpInsnNode insn, FrameState frame, BBInfo block) {
    //All JumpInsnNodes have a target.  Find it.
    BBInfo target = blockByInsn(insn.label);
    assert target != null;

    if (insn.getOpcode() == Opcodes.GOTO) {
        block.block.instructions().add(new JumpInst(target.block));
        return;/* w  ww.  ja v  a  2 s .com*/
    } else if (insn.getOpcode() == Opcodes.JSR)
        throw new UnsupportedOperationException("jsr not supported; upgrade to Java 6-era class files");

    //Remaining opcodes are branches.
    BBInfo fallthrough = blocks.get(blocks.indexOf(block) + 1);
    BranchInst.Sense sense = OPCODE_TO_SENSE.get(insn.getOpcode());
    //The second operand may come from the stack or may be a constant 0 or null.
    Value right;
    switch (insn.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        right = module.constants().getConstant(0);
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        right = module.constants().getNullConstant();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        right = frame.stack.pop();
        break;
    default:
        throw new AssertionError("Can't happen! Branch opcode missing? " + insn.getOpcode());
    }
    //First operand always comes from the stack.
    Value left = frame.stack.pop();
    block.block.instructions().add(new BranchInst(left, sense, right, target.block, fallthrough.block));
}

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

License:Open Source License

private void emit(BranchInst i, InsnList insns) {
    //TODO: accessor methods on BranchInst
    Value left = i.getOperand(0), right = i.getOperand(1);
    BasicBlock target = (BasicBlock) i.getOperand(2), fallthrough = (BasicBlock) i.getOperand(3);
    if (!method.basicBlocks().contains(target))
        throw new IllegalArgumentException("Branch targets block not in method: " + i);
    if (!method.basicBlocks().contains(fallthrough))
        throw new IllegalArgumentException("Branch falls through to block not in method: " + i);
    load(i.getOperand(0), insns);//  w w  w .  j  a  v a 2 s  .  c om
    load(i.getOperand(1), insns);
    //TODO: long, float, doubles need to go through CMP inst first
    int opcode;
    if (left.getType() instanceof ReferenceType || left.getType() instanceof VoidType) {
        switch (i.getSense()) {
        case EQ:
            opcode = Opcodes.IF_ACMPEQ;
            break;
        case NE:
            opcode = Opcodes.IF_ACMPNE;
            break;
        default:
            throw new AssertionError(i);
        }
    } else if (left.getType().isSubtypeOf(intType)) {
        switch (i.getSense()) {
        case EQ:
            opcode = Opcodes.IF_ICMPEQ;
            break;
        case NE:
            opcode = Opcodes.IF_ICMPNE;
            break;
        case LT:
            opcode = Opcodes.IF_ICMPLT;
            break;
        case GT:
            opcode = Opcodes.IF_ICMPGT;
            break;
        case LE:
            opcode = Opcodes.IF_ICMPLE;
            break;
        case GE:
            opcode = Opcodes.IF_ICMPGE;
            break;
        default:
            throw new AssertionError(i);
        }
    } else
        throw new AssertionError(i);
    insns.add(new JumpInsnNode(opcode, labels.get(target)));
    insns.add(new JumpInsnNode(Opcodes.GOTO, labels.get(fallthrough)));
}

From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDBVisitor.java

License:Open Source License

@Override
public void visitJumpInsn(int opcode, Label label) {
    currentMethod.setEmpty(false);/*from   w  ww  .  j a v a 2 s .co m*/
    currentMethod.setEmpty(false);
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        //      case Opcodes.GOTO:
        //      case Opcodes.JSR:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        // add all label reads/writes as condition reads/writes
        currentMethod.getConditionReads().addAll(labelReads);
        currentMethod.getConditionWrites().addAll(labelWrites);
        break;
    }
}

From source file:erjang.ETuple.java

License:Apache License

private static void create_cast(ClassAdapter cw, int n) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "cast",
            "(L" + ETUPLE_NAME + ";)L" + ETUPLE_NAME + n + ";", null, null);
    mv.visitCode();//from   w  w w. ja v  a  2  s .co  m

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ETUPLE_NAME, "arity", "()I");

    if (n <= 5) {
        mv.visitInsn(Opcodes.ICONST_0 + n);
    } else {
        mv.visitLdcInsn(new Integer(n));
    }

    Label fail = new Label();

    mv.visitJumpInsn(Opcodes.IF_ICMPNE, fail);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitTypeInsn(Opcodes.CHECKCAST, ETUPLE_NAME + n);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitLabel(fail);
    mv.visitInsn(Opcodes.ACONST_NULL);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitMaxs(2, 2);
    mv.visitEnd();
}

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   w  ww.  jav a 2  s .  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 getBranchingOpcode(CompilerContext context, MethodVisitor mv) {
    int branchingOpcode = Opcodes.NOP;

    if (insn == Instructions.BEQ) {
        branchingOpcode = getBranchingOpcodeBranch2(context, mv, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE);
    } else if (insn == Instructions.BEQL) {
        branchingOpcode = getBranchingOpcodeBranch2L(context, mv, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE);
    } else if (insn == Instructions.BNE) {
        branchingOpcode = getBranchingOpcodeBranch2(context, mv, Opcodes.IF_ICMPNE, Opcodes.IF_ICMPEQ);
    } else if (insn == Instructions.BNEL) {
        branchingOpcode = getBranchingOpcodeBranch2L(context, mv, Opcodes.IF_ICMPNE, Opcodes.IF_ICMPEQ);
    } else if (insn == Instructions.BGEZ) {
        branchingOpcode = getBranchingOpcodeBranch1(context, mv, Opcodes.IFGE, Opcodes.IFLT);
    } else if (insn == Instructions.BGEZL) {
        branchingOpcode = getBranchingOpcodeBranch1L(context, mv, Opcodes.IFGE, Opcodes.IFLT);
    } else if (insn == Instructions.BGTZ) {
        branchingOpcode = getBranchingOpcodeBranch1(context, mv, Opcodes.IFGT, Opcodes.IFLE);
    } else if (insn == Instructions.BGTZL) {
        branchingOpcode = getBranchingOpcodeBranch1L(context, mv, Opcodes.IFGT, Opcodes.IFLE);
    } else if (insn == Instructions.BLEZ) {
        branchingOpcode = getBranchingOpcodeBranch1(context, mv, Opcodes.IFLE, Opcodes.IFGT);
    } else if (insn == Instructions.BLEZL) {
        branchingOpcode = getBranchingOpcodeBranch1L(context, mv, Opcodes.IFLE, Opcodes.IFGT);
    } else if (insn == Instructions.BLTZ) {
        branchingOpcode = getBranchingOpcodeBranch1(context, mv, Opcodes.IFLT, Opcodes.IFGE);
    } else if (insn == Instructions.BLTZL) {
        branchingOpcode = getBranchingOpcodeBranch1L(context, mv, Opcodes.IFLT, Opcodes.IFGE);
    } else if (insn == Instructions.J) {
        branchingOpcode = getBranchingOpcodeBranch0(context, mv);
    } else if (insn == Instructions.JAL) {
        branchingOpcode = getBranchingOpcodeCall0(context, mv);
    } else if (insn == Instructions.BLTZAL) {
        branchingOpcode = getBranchingOpcodeCall1(context, mv, Opcodes.IFLT, Opcodes.IFGE);
    } else if (insn == Instructions.BLTZALL) {
        branchingOpcode = getBranchingOpcodeCall1L(context, mv, Opcodes.IFLT, Opcodes.IFGE);
    } else if (insn == Instructions.BGEZAL) {
        branchingOpcode = getBranchingOpcodeCall1(context, mv, Opcodes.IFGE, Opcodes.IFLT);
    } else if (insn == Instructions.BGEZALL) {
        branchingOpcode = getBranchingOpcodeCall1L(context, mv, Opcodes.IFGE, Opcodes.IFLT);
    } else if (insn == Instructions.BC1F) {
        branchingOpcode = getBranchingOpcodeBC1(context, mv, Opcodes.IFEQ, Opcodes.IFNE);
    } else if (insn == Instructions.BC1FL) {
        branchingOpcode = getBranchingOpcodeBC1L(context, mv, Opcodes.IFEQ, Opcodes.IFNE);
    } else if (insn == Instructions.BC1T) {
        branchingOpcode = getBranchingOpcodeBC1(context, mv, Opcodes.IFNE, Opcodes.IFEQ);
    } else if (insn == Instructions.BC1TL) {
        branchingOpcode = getBranchingOpcodeBC1L(context, mv, Opcodes.IFNE, Opcodes.IFEQ);
    } else if (insn == Instructions.BVF) {
        branchingOpcode = getBranchingOpcodeBV(context, mv, Opcodes.IFEQ, Opcodes.IFNE);
    } else if (insn == Instructions.BVT) {
        branchingOpcode = getBranchingOpcodeBV(context, mv, Opcodes.IFNE, Opcodes.IFEQ);
    } else if (insn == Instructions.BVFL) {
        branchingOpcode = getBranchingOpcodeBVL(context, mv, Opcodes.IFEQ, Opcodes.IFNE);
    } else if (insn == Instructions.BVTL) {
        branchingOpcode = getBranchingOpcodeBVL(context, mv, Opcodes.IFNE, Opcodes.IFEQ);
    } else {/*from  w  w  w .  ja  va2  s  .  c  o m*/
        log.error("CodeInstruction.getBranchingOpcode: unknown instruction "
                + insn.disasm(getAddress(), getOpcode()));
    }

    return branchingOpcode;
}

From source file:lucee.transformer.bytecode.statement.tag.TagHelper.java

License:Open Source License

/**
 * writes out the tag/* w w  w  . j a  v  a2  s.  c o  m*/
 * @param tag
 * @param bc
 * @param doReuse
 * @throws BytecodeException
 */
public static void writeOut(Tag tag, BytecodeContext bc, boolean doReuse, final FlowControlFinal fcf)
        throws BytecodeException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final TagLibTag tlt = tag.getTagLibTag();
    final Type currType = getTagType(tag);

    final int currLocal = adapter.newLocal(currType);
    Label tagBegin = new Label();
    Label tagEnd = new Label();
    ExpressionUtil.visitLine(bc, tag.getStart());
    // TODO adapter.visitLocalVariable("tag", "L"+currType.getInternalName()+";", null, tagBegin, tagEnd, currLocal);

    adapter.visitLabel(tagBegin);

    // tag=pc.use(str);
    adapter.loadArg(0);
    adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    adapter.push(tlt.getTagClassName());
    adapter.push(tlt.getFullName());
    adapter.push(tlt.getAttributeType());
    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, USE3);
    adapter.checkCast(currType);
    adapter.storeLocal(currLocal);

    TryFinallyVisitor outerTcfv = new TryFinallyVisitor(new OnFinally() {
        public void _writeOut(BytecodeContext bc) {

            adapter.loadArg(0);
            adapter.loadLocal(currLocal);
            adapter.invokeVirtual(Types.PAGE_CONTEXT, RE_USE);
        }
    }, null);
    if (doReuse)
        outerTcfv.visitTryBegin(bc);

    // appendix
    if (tlt.hasAppendix()) {
        adapter.loadLocal(currLocal);
        adapter.push(tag.getAppendix());
        adapter.invokeVirtual(currType, SET_APPENDIX);
    }

    // hasBody
    boolean hasBody = tag.getBody() != null;
    if (tlt.isBodyFree() && tlt.hasBodyMethodExists()) {
        adapter.loadLocal(currLocal);
        adapter.push(hasBody);
        adapter.invokeVirtual(currType, HAS_BODY);
    }

    // default attributes (get overwritten by attributeCollection because of that set before)
    setAttributes(bc, tag, currLocal, currType, true);

    // attributeCollection
    Attribute attrColl = tag.getAttribute("attributecollection");
    if (attrColl != null) {
        int attrType = tag.getTagLibTag().getAttributeType();
        if (TagLibTag.ATTRIBUTE_TYPE_NONAME != attrType) {
            tag.removeAttribute("attributecollection");
            // TagUtil.setAttributeCollection(Tag, Struct)
            adapter.loadArg(0);
            adapter.loadLocal(currLocal);
            adapter.cast(currType, TAG);

            ///
            TagLibTagAttr[] missings = tag.getMissingAttributes();
            if (!ArrayUtil.isEmpty(missings)) {
                ArrayVisitor av = new ArrayVisitor();
                av.visitBegin(adapter, MISSING_ATTRIBUTE, missings.length);
                int count = 0;
                TagLibTagAttr miss;
                for (int i = 0; i < missings.length; i++) {
                    miss = missings[i];
                    av.visitBeginItem(adapter, count++);
                    Variable.registerKey(bc, LitString.toExprString(miss.getName()));
                    adapter.push(miss.getType());
                    if (ArrayUtil.isEmpty(miss.getAlias()))
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX2);
                    else {
                        new LiteralStringArray(miss.getAlias()).writeOut(bc, Expression.MODE_REF);
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX3);
                    }
                    av.visitEndItem(bc.getAdapter());
                }
                av.visitEnd();
            } else {
                ASMConstants.NULL(adapter);
            }
            ///
            attrColl.getValue().writeOut(bc, Expression.MODE_REF);

            adapter.push(attrType);
            adapter.invokeStatic(TAG_UTIL, SET_ATTRIBUTE_COLLECTION);
        }
    }

    // metadata
    Attribute attr;
    Map<String, Attribute> metadata = tag.getMetaData();
    if (metadata != null) {
        Iterator<Attribute> it = metadata.values().iterator();
        while (it.hasNext()) {
            attr = it.next();
            adapter.loadLocal(currLocal);
            adapter.push(attr.getName());
            attr.getValue().writeOut(bc, Expression.MODE_REF);
            adapter.invokeVirtual(currType, SET_META_DATA);
        }
    }

    // set attributes
    setAttributes(bc, tag, currLocal, currType, false);

    // Body
    if (hasBody) {
        final int state = adapter.newLocal(Types.INT_VALUE);

        // int state=tag.doStartTag();
        adapter.loadLocal(currLocal);
        adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.storeLocal(state);

        // if (state!=Tag.SKIP_BODY)
        Label endBody = new Label();
        adapter.loadLocal(state);
        adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_BODY);
        adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endBody);
        // pc.initBody(tag, state);
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.loadLocal(state);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, INIT_BODY);

        OnFinally onFinally = new OnFinally() {

            public void _writeOut(BytecodeContext bc) {
                Label endIf = new Label();
                /*if(tlt.handleException() && fcf!=null && fcf.getAfterFinalGOTOLabel()!=null){
                   ASMUtil.visitLabel(adapter, fcf.getFinalEntryLabel());
                }*/
                adapter.loadLocal(state);
                adapter.push(javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE);
                adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endIf);
                // ... pc.popBody();
                adapter.loadArg(0);
                adapter.invokeVirtual(Types.PAGE_CONTEXT, POP_BODY);
                adapter.pop();
                adapter.visitLabel(endIf);

                // tag.doFinally();
                if (tlt.handleException()) {
                    adapter.loadLocal(currLocal);
                    adapter.invokeVirtual(currType, DO_FINALLY);
                }
                // GOTO after execution body, used when a continue/break was called before
                /*if(fcf!=null) {
                   Label l = fcf.getAfterFinalGOTOLabel();
                   if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
                }*/

            }
        };

        if (tlt.handleException()) {
            TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(onFinally, fcf);
            tcfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType);
            int t = tcfv.visitTryEndCatchBeging(bc);
            // tag.doCatch(t);
            adapter.loadLocal(currLocal);
            adapter.loadLocal(t);
            //adapter.visitVarInsn(Opcodes.ALOAD,t);
            adapter.invokeVirtual(currType, DO_CATCH);
            tcfv.visitCatchEnd(bc);
        } else {
            TryFinallyVisitor tfv = new TryFinallyVisitor(onFinally, fcf);
            tfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType);
            tfv.visitTryEnd(bc);
        }

        adapter.visitLabel(endBody);

    } else {
        //tag.doStartTag();
        adapter.loadLocal(currLocal);
        adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.pop();
    }

    // if (tag.doEndTag()==Tag.SKIP_PAGE) throw new Abort(0<!-- SCOPE_PAGE -->);
    Label endDoEndTag = new Label();
    adapter.loadLocal(currLocal);
    adapter.invokeVirtual(currType, DO_END_TAG);
    adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_PAGE);
    adapter.visitJumpInsn(Opcodes.IF_ICMPNE, endDoEndTag);
    adapter.push(Abort.SCOPE_PAGE);
    adapter.invokeStatic(ABORT, NEW_INSTANCE);
    adapter.throwException();
    adapter.visitLabel(endDoEndTag);

    if (doReuse) {
        // } finally{pc.reuse(tag);}
        outerTcfv.visitTryEnd(bc);
    }

    adapter.visitLabel(tagEnd);
    ExpressionUtil.visitLine(bc, tag.getEnd());
}

From source file:name.martingeisse.minimal.compiler.Compiler.java

License:Open Source License

/**
 * Compiles a {@link MethodNode} to MCode.
 * //from  www . ja  v  a2 s  .c o  m
 * @param methodNode the method node to compile
 * @return the compiled code
 */
public ImmutableList<MCodeEntry> compile(final MethodNode methodNode) {
    for (int i = 0; i < methodNode.instructions.size(); i++) {
        final AbstractInsnNode instruction = methodNode.instructions.get(i);
        if (instruction instanceof LineNumberNode) {
            // ignored
        } else if (instruction instanceof FrameNode) {
            // this could be useful in the future
        } else if (instruction instanceof LabelNode) {
            label(((LabelNode) instruction).getLabel());
        } else if (instruction instanceof InsnNode) {
            switch (instruction.getOpcode()) {

            case Opcodes.ICONST_M1:
                iconst(-1);
                break;

            case Opcodes.ICONST_0:
                iconst(0);
                break;

            case Opcodes.ICONST_1:
                iconst(1);
                break;

            case Opcodes.ICONST_2:
                iconst(2);
                break;

            case Opcodes.ICONST_3:
                iconst(3);
                break;

            case Opcodes.ICONST_4:
                iconst(4);
                break;

            case Opcodes.ICONST_5:
                iconst(5);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof VarInsnNode) {
            final VarInsnNode varInsnNode = (VarInsnNode) instruction;
            switch (varInsnNode.getOpcode()) {

            case Opcodes.ILOAD:
                iload(varInsnNode.var);
                break;

            case Opcodes.ISTORE:
                istore(varInsnNode.var);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IincInsnNode) {
            final IincInsnNode iincInsnNode = (IincInsnNode) instruction;
            iinc(iincInsnNode.var, iincInsnNode.incr);
        } else if (instruction instanceof JumpInsnNode) {
            final JumpInsnNode jumpInsnNode = (JumpInsnNode) instruction;
            switch (jumpInsnNode.getOpcode()) {

            case Opcodes.IFEQ:
            case Opcodes.IFNE:
            case Opcodes.IFLT:
            case Opcodes.IFGE:
            case Opcodes.IFGT:
            case Opcodes.IFLE:
                branch1(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IF_ICMPEQ:
            case Opcodes.IF_ICMPNE:
            case Opcodes.IF_ICMPLT:
            case Opcodes.IF_ICMPGE:
            case Opcodes.IF_ICMPGT:
            case Opcodes.IF_ICMPLE:
                branch2(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IFNULL:
            case Opcodes.IFNONNULL:
                // unsupported: one-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.IF_ACMPEQ:
            case Opcodes.IF_ACMPNE:
                // unsupported: two-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.GOTO:
                jump(jumpInsnNode.label.getLabel());
                break;

            case Opcodes.JSR:
                jsr(jumpInsnNode.label.getLabel());
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IntInsnNode) {
            final IntInsnNode intInsnNode = (IntInsnNode) instruction;
            if (instruction.getOpcode() == Opcodes.BIPUSH || instruction.getOpcode() == Opcodes.SIPUSH) {
                iconst(intInsnNode.operand);
            } else {
                // NEWARRAY
                unsupported(instruction);
            }
        } else if (instruction instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
            if (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) {
                if (methodInsnNode.owner.replace('/', '.').equals(Native.class.getName())) {
                    nativeCall(methodInsnNode.name, methodInsnNode.desc);
                } else {
                    unsupported(instruction);
                }
            } else {
                unsupported(instruction);
            }
        } else {
            unsupported(instruction);
        }
    }
    return builder.build();
}