Example usage for org.objectweb.asm Opcodes IRETURN

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

Introduction

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

Prototype

int IRETURN

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

Click Source Link

Usage

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

public static void doReturn(MethodVisitor mv, ClassNode returnType) {
    if (returnType == double_TYPE) {
        mv.visitInsn(Opcodes.DRETURN);// w  w  w  . j a va  2 s.  c  o  m
    } else if (returnType == float_TYPE) {
        mv.visitInsn(Opcodes.FRETURN);
    } else if (returnType == long_TYPE) {
        mv.visitInsn(Opcodes.LRETURN);
    } else if (returnType == boolean_TYPE || returnType == char_TYPE || returnType == byte_TYPE
            || returnType == int_TYPE || returnType == short_TYPE) {
        //byte,short,boolean,int are all IRETURN
        mv.visitInsn(Opcodes.IRETURN);
    } else if (returnType == VOID_TYPE) {
        mv.visitInsn(Opcodes.RETURN);
    } else {
        mv.visitInsn(Opcodes.ARETURN);
    }

}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**    
 * @param type//  ww  w .j  a  v a  2 s .  com
 * @return the RETURN, IRETURN,... op code, depending on type.
 */
private static int getReturnOpCode(JavaTypeName type) {

    switch (type.getTag()) {
    case JavaTypeName.VOID_TAG:
        return Opcodes.RETURN;

    case JavaTypeName.BOOLEAN_TAG:
    case JavaTypeName.BYTE_TAG:
    case JavaTypeName.SHORT_TAG:
    case JavaTypeName.CHAR_TAG:
    case JavaTypeName.INT_TAG:
        return Opcodes.IRETURN;

    case JavaTypeName.LONG_TAG:
        return Opcodes.LRETURN;

    case JavaTypeName.DOUBLE_TAG:
        return Opcodes.DRETURN;

    case JavaTypeName.FLOAT_TAG:
        return Opcodes.FRETURN;

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
        return Opcodes.ARETURN;

    default: {
        throw new IllegalArgumentException("invalid type: " + type);
    }
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator.java

License:Apache License

private static ZeroOperandMutation ireturnMutation() {
    return new ZeroOperandMutation() {

        public void apply(final int opCode, final MethodVisitor mv) {
            final Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l1);
            mv.visitInsn(Opcodes.ICONST_0);
            mv.visitInsn(Opcodes.IRETURN);
            mv.visitLabel(l1);/*from   www  .ja  v  a2  s.  com*/
            mv.visitInsn(Opcodes.ICONST_1);
            mv.visitInsn(Opcodes.IRETURN);
        }

        public String decribe(final int opCode, final MethodInfo methodInfo) {
            return "replaced return of integer sized value with (x == 0 ? 1 : 0)";
        }

    };
}

From source file:org.pitest.mutationtest.UnviableClassMutator.java

License:Apache License

@Override
protected Map<Integer, ZeroOperandMutation> getMutations() {
    final Map<Integer, ZeroOperandMutation> map = new HashMap<Integer, ZeroOperandMutation>();
    // map.put(Opcodes.ALOAD, new InsnSubstitution(Opcodes.TABLESWITCH,
    // "Made unviable class"));
    map.put(Opcodes.IRETURN, new InsnSubstitution(Opcodes.FCMPG, "Made unviable class"));
    map.put(Opcodes.RETURN, new InsnSubstitution(Opcodes.FCMPG, "Made unviable class"));
    return map;/* w ww .  ja  va  2 s .c  om*/
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGBuilderTest.java

License:Open Source License

@Test
public void all_opcodes_should_be_visited() throws Exception {
    Instructions ins = new Instructions();
    Predicate<Integer> filterReturnAndThrow = opcode -> !((Opcodes.IRETURN <= opcode
            && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW);
    NO_OPERAND_INSN.stream().filter(filterReturnAndThrow).forEach(ins::visitInsn);
    INT_INSN.forEach(i -> ins.visitIntInsn(i, 0));
    VAR_INSN.forEach(i -> ins.visitVarInsn(i, 0));
    TYPE_INSN.forEach(i -> ins.visitTypeInsn(i, "java/lang/Object"));
    FIELD_INSN.forEach(i -> ins.visitFieldInsn(i, "java/lang/Object", "foo", "D(D)"));
    METHOD_INSN.forEach(i -> ins.visitMethodInsn(i, "java/lang/Object", "foo", "()V", i == INVOKEINTERFACE));

    JUMP_INSN.forEach(i -> {/*from www .j a v  a 2 s  . c o m*/
        Label jumpLabel = new Label();
        ins.visitJumpInsn(i, jumpLabel);
        ins.visitLabel(jumpLabel);
    });

    ins.visitLdcInsn("a");
    ins.visitIincInsn(0, 1);
    Handle handle = new Handle(H_INVOKESTATIC, "", "", "()V", false);
    ins.visitInvokeDynamicInsn("sleep", "()V", handle);
    ins.visitLookupSwitchInsn(new Label(), new int[] {}, new Label[] {});
    ins.visitMultiANewArrayInsn("B", 1);

    Label l0 = new Label();
    Label dflt = new Label();
    Label case0 = new Label();
    ins.visitTableSwitchInsn(0, 1, dflt, case0);
    ins.visitLabel(dflt);
    ins.visitInsn(NOP);
    ins.visitLabel(l0);
    ins.visitInsn(NOP);

    BytecodeCFG cfg = ins.cfg();
    Multiset<String> cfgOpcodes = cfgOpcodes(cfg);
    List<String> collect = Instructions.OPCODES.stream().filter(filterReturnAndThrow)
            .map(op -> Printer.OPCODES[op]).collect(Collectors.toList());
    assertThat(cfgOpcodes).containsAll(collect);
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGBuilderTest.java

License:Open Source License

@Test
public void visited_label_should_be_assigned_to_true_successor() throws Exception {
    Label label0 = new Label();
    Label label1 = new Label();
    BytecodeCFG cfg = new Instructions().visitVarInsn(Opcodes.ALOAD, 0).visitJumpInsn(Opcodes.IFNULL, label0)
            .visitJumpInsn(Opcodes.IFEQ, label0).visitInsn(Opcodes.ICONST_0).visitJumpInsn(Opcodes.GOTO, label1)
            .visitLabel(label0).visitInsn(Opcodes.ICONST_1).visitLabel(label1).visitInsn(Opcodes.IRETURN).cfg();

    BytecodeCFG.Block block3 = cfg.blocks.get(3);
    assertThat(block3.terminator.opcode).isEqualTo(Opcodes.IFEQ);
    assertThat(block3.falseSuccessor()).isNotNull().isSameAs(cfg.blocks.get(4));
    assertThat(block3.trueSuccessor()).isNotNull().isSameAs(cfg.blocks.get(2));
    assertThat(block3.successors).hasSize(2);
    assertThat(block3.successors()).hasSize(2);
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGBuilderTest.java

License:Open Source License

@Test
public void goto_successors() throws Exception {
    Label label0 = new Label();
    Label label1 = new Label();
    BytecodeCFG cfg = new Instructions().visitVarInsn(Opcodes.ALOAD, 0).visitJumpInsn(Opcodes.IFNULL, label0)
            .visitVarInsn(Opcodes.ALOAD, 0).visitJumpInsn(Opcodes.IFNULL, label1).visitVarInsn(Opcodes.ALOAD, 0)
            .visitVarInsn(Opcodes.ALOAD, 0).visitJumpInsn(Opcodes.IFEQ, label0).visitInsn(Opcodes.ICONST_0)
            .visitJumpInsn(Opcodes.GOTO, label1).visitLabel(label0).visitInsn(Opcodes.ICONST_1)
            .visitLabel(label1).visitInsn(Opcodes.IRETURN).cfg();
    assertThat(cfg.blocks.get(6).successors).containsExactly(cfg.blocks.get(4));
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    currentBlock.addInsn(opcode);//from w  w w.  j  a va2s. c om
    if ((Opcodes.IRETURN <= opcode && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
        currentBlock.successors.add(cfg.blocks.get(0));
        currentBlock = null;
    }
}

From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java

License:Open Source License

@Test
public void test_xReturn() throws Exception {
    SymbolicValue returnValue = new SymbolicValue();
    int[] opcodes = { Opcodes.IRETURN, Opcodes.LRETURN, Opcodes.FRETURN, Opcodes.DRETURN, Opcodes.ARETURN };
    for (int opcode : opcodes) {
        ProgramState programState = execute(new Instruction(opcode),
                ProgramState.EMPTY_STATE.stackValue(returnValue));
        assertThat(programState.peekValue()).isNull();
        assertThat(programState.exitValue()).isEqualTo(returnValue);
    }/*from w  ww  . ja va 2 s .  com*/
}

From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java

License:MIT License

/**
 * Inject the appropriate return code for the method type
 * /*from   ww  w.j a v a2 s  . c o  m*/
 * @param callback callback handle
 */
protected void injectReturnCode(final Callback callback) {
    if (callback.target.returnType.equals(Type.VOID_TYPE)) {
        // Void method, so just return void
        callback.add(new InsnNode(Opcodes.RETURN));
    } else {
        // Non-void method, so work out which accessor to call to get the
        // return value, and return it
        callback.add(new VarInsnNode(Opcodes.ALOAD, callback.marshallVar));
        String accessor = CallbackInfoReturnable.getReturnAccessor(callback.target.returnType);
        String descriptor = CallbackInfoReturnable.getReturnDescriptor(callback.target.returnType);
        callback.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, callback.target.callbackInfoClass, accessor,
                descriptor, false));
        if (callback.target.returnType.getSort() == Type.OBJECT) {
            callback.add(new TypeInsnNode(Opcodes.CHECKCAST, callback.target.returnType.getInternalName()));
        }
        callback.add(new InsnNode(callback.target.returnType.getOpcode(Opcodes.IRETURN)));
    }
}