List of usage examples for org.objectweb.asm Opcodes IFNE
int IFNE
To view the source code for org.objectweb.asm Opcodes IFNE.
Click Source Link
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleBooleanOperator(Expression node, Operator op, Type type) throws ASTVisitorException { List<JumpInsnNode> trueList = new ArrayList<JumpInsnNode>(); System.out.println("***** handle boolean " + op); if (type.equals(TypeUtils.STRING_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.SWAP)); JumpInsnNode jmp = null;//from w w w .j a v a 2 s .c o m mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); break; default: ASTUtils.error(node, "Operator not supported on strings"); break; } mn.instructions.add(jmp); trueList.add(jmp); } else if (type.equals(Type.DOUBLE_TYPE)) { // FIXME: add DCMPG instruction // FIXME: add a JumpInsnNode with null label based on the operation // IFEQ, IFNE, IFGT, IFGE, IFLT, IFLE // FIXME: add the jmp instruction into trueList mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null; switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; } trueList.add(jmp); } else { System.out.println("here"); JumpInsnNode jmp = null; switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPNE, null); mn.instructions.add(jmp); break; case GREATER: System.out.println("----- greater"); jmp = new JumpInsnNode(Opcodes.IF_ICMPGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IF_ICMPLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } trueList.add(jmp); } ASTUtils.setTrueList(node, trueList); List<JumpInsnNode> falseList = new ArrayList<JumpInsnNode>(); JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null); mn.instructions.add(jmp); falseList.add(jmp); ASTUtils.setFalseList(node, falseList); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { // FIXME: IADD or DADD, etc. // use type.getOpcode(Opcodes.IADD) to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD))); } else if (op.equals(Operator.MINUS)) { // FIXME: ISUB or DSUB, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB))); } else if (op.equals(Operator.MULTIPLY)) { // FIXME: IMUL or DMUL, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL))); } else if (op.equals(Operator.DIVISION)) { // FIXME: IDIV or DDIV, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV))); } else if (op.isRelational()) { if (type.equals(Type.DOUBLE_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null;//from ww w . java 2 s .c om switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); LabelNode trueLabelNode = new LabelNode(); jmp.label = trueLabelNode; mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else if (type.equals(Type.INT_TYPE)) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode)); break; case GREATER: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode)); break; case GREATER_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode)); break; case LESS: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode)); break; case LESS_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode)); break; default: break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Cannot compare such types."); } } else { ASTUtils.error(node, "Operator not recognized."); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
/** * Assumes top of stack contains two strings *///from w ww . j av a2 s .co m private void handleStringOperator(ASTNode node, Operator op) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder")); mn.instructions.add(new InsnNode(Opcodes.DUP)); mn.instructions.add( new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)); } else if (op.isRelational()) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFEQ, trueLabelNode)); break; default: ASTUtils.error(node, "Operator not supported on strings"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Operator not recognized"); } }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchEcjFilterTest.java
License:Open Source License
@Test public void should_filter() { final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>(); final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null); final Label case1 = new Label(); final Label case2 = new Label(); final Label case3 = new Label(); final Label caseDefault = new Label(); final Label h1 = new Label(); final Label h2 = new Label(); // filter should not remember this unrelated slot m.visitLdcInsn(""); m.visitVarInsn(Opcodes.ASTORE, 1);/*from ww w. j a va2 s . c o m*/ m.visitVarInsn(Opcodes.ALOAD, 1); // switch (...) m.visitInsn(Opcodes.DUP); m.visitVarInsn(Opcodes.ASTORE, 2); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); m.visitTableSwitchInsn(97, 98, caseDefault, h1, h2); final AbstractInsnNode switchNode = m.instructions.getLast(); m.visitLabel(h1); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "a", then goto its case m.visitJumpInsn(Opcodes.IFNE, case1); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("\0a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "\0a", then goto its case m.visitJumpInsn(Opcodes.IFNE, case2); // goto default case m.visitJumpInsn(Opcodes.GOTO, caseDefault); m.visitLabel(h2); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("b"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "b", then goto its case m.visitJumpInsn(Opcodes.IFNE, case3); // goto default case m.visitJumpInsn(Opcodes.GOTO, caseDefault); final AbstractInsnNode expectedToInclusive = m.instructions.getLast(); m.visitLabel(case1); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case2); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case3); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(caseDefault); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); filter.filter(m, context, output); assertReplacedBranches(switchNode, expectedNewTargets); assertIgnored(new Range(switchNode.getNext(), expectedToInclusive)); }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchEcjFilterTest.java
License:Open Source License
@Test public void should_filter_when_default_is_first() { final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>(); final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null); final Label case1 = new Label(); final Label caseDefault = new Label(); final Label h1 = new Label(); // filter should not remember this unrelated slot m.visitLdcInsn(""); m.visitVarInsn(Opcodes.ASTORE, 1);/* w ww . j av a 2s . c o m*/ m.visitVarInsn(Opcodes.ALOAD, 1); // switch (...) m.visitInsn(Opcodes.DUP); m.visitVarInsn(Opcodes.ASTORE, 2); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); m.visitLookupSwitchInsn(caseDefault, new int[] { 97 }, new Label[] { h1 }); final AbstractInsnNode switchNode = m.instructions.getLast(); m.visitLabel(h1); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "a", then goto its case m.visitJumpInsn(Opcodes.IFNE, case1); final AbstractInsnNode expectedToInclusive = m.instructions.getLast(); m.visitLabel(caseDefault); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case1); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); filter.filter(m, context, output); assertReplacedBranches(switchNode, expectedNewTargets); assertIgnored(new Range(switchNode.getNext(), expectedToInclusive)); }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchJavacFilterTest.java
License:Open Source License
@Test public void should_not_filter_code_generated_by_ECJ() { final Label h1 = new Label(); final Label h2 = new Label(); final Label cases = new Label(); m.visitVarInsn(Opcodes.ALOAD, 1);/*w w w. j a v a2s .com*/ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); m.visitTableSwitchInsn(0, 2, cases, h1, h2); m.visitLabel(h1); m.visitVarInsn(Opcodes.ALOAD, 1); m.visitLdcInsn("a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "a", then goto its case m.visitJumpInsn(Opcodes.IFNE, cases); m.visitVarInsn(Opcodes.ALOAD, 1); m.visitLdcInsn("\0a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "\0a", then goto its case m.visitJumpInsn(Opcodes.IFNE, cases); // goto default case m.visitJumpInsn(Opcodes.GOTO, cases); m.visitLabel(h2); m.visitVarInsn(Opcodes.ALOAD, 1); m.visitLdcInsn("b"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "b", then goto its case m.visitJumpInsn(Opcodes.IFNE, cases); // goto default case m.visitJumpInsn(Opcodes.GOTO, cases); m.visitLabel(cases); filter.filter(m, context, output); assertIgnored(); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitJumpInsn(final int opcode, final Label label) { switch (opcode) { case Opcodes.GOTO: break;/*from w w w . jav a 2s . c om*/ case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop(1); 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: pop(2); break; default: throw new IllegalArgumentException(); } mv.visitJumpInsn(opcode, label); }
From source file:org.jacoco.core.internal.instr.MethodInstrumenter.java
License:Open Source License
private int getInverted(final int opcode) { switch (opcode) { case Opcodes.IFEQ: return Opcodes.IFNE; case Opcodes.IFNE: return Opcodes.IFEQ; case Opcodes.IFLT: return Opcodes.IFGE; case Opcodes.IFGE: return Opcodes.IFLT; case Opcodes.IFGT: return Opcodes.IFLE; case Opcodes.IFLE: return Opcodes.IFGT; case Opcodes.IF_ICMPEQ: return Opcodes.IF_ICMPNE; case Opcodes.IF_ICMPNE: return Opcodes.IF_ICMPEQ; case Opcodes.IF_ICMPLT: return Opcodes.IF_ICMPGE; case Opcodes.IF_ICMPGE: return Opcodes.IF_ICMPLT; case Opcodes.IF_ICMPGT: return Opcodes.IF_ICMPLE; case Opcodes.IF_ICMPLE: return Opcodes.IF_ICMPGT; case Opcodes.IF_ACMPEQ: return Opcodes.IF_ACMPNE; case Opcodes.IF_ACMPNE: return Opcodes.IF_ACMPEQ; case Opcodes.IFNULL: return Opcodes.IFNONNULL; case Opcodes.IFNONNULL: return Opcodes.IFNULL; }/*from w ww. j a va 2 s. com*/ throw new IllegalArgumentException(); }
From source file:org.jacoco.core.internal.instr.MethodInstrumenterTest.java
License:Open Source License
@Test public void testVisitJumpInsnWithProbe_IFEQ() { testVisitJumpInsnWithProbe(Opcodes.IFEQ, Opcodes.IFNE); }
From source file:org.jacoco.core.internal.instr.MethodInstrumenterTest.java
License:Open Source License
@Test public void testVisitJumpInsnWithProbe_IFNE() { testVisitJumpInsnWithProbe(Opcodes.IFNE, Opcodes.IFEQ); }