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.spongepowered.asm.mixin.injection.points.BeforeReturn.java

License:MIT License

@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
    boolean found = false;

    // RETURN opcode varies based on return type, thus we calculate what opcode we're actually looking for by inspecting the target method
    int returnOpcode = Type.getReturnType(desc).getOpcode(Opcodes.IRETURN);
    int ordinal = 0;

    ListIterator<AbstractInsnNode> iter = insns.iterator();
    while (iter.hasNext()) {
        AbstractInsnNode insn = iter.next();

        if (insn instanceof InsnNode && insn.getOpcode() == returnOpcode) {
            if (this.ordinal == -1 || this.ordinal == ordinal) {
                nodes.add(insn);//from  ww w.  j  a  va2  s. co  m
                found = true;
            }

            ordinal++;
        }
    }

    return found;
}

From source file:org.spongepowered.despector.emitter.bytecode.statement.BytecodeReturnEmitter.java

License:Open Source License

@Override
public void emit(BytecodeEmitterContext ctx, Return stmt, boolean semicolon) {
    MethodVisitor mv = ctx.getMethodVisitor();
    if (!stmt.getValue().isPresent()) {
        mv.visitInsn(Opcodes.RETURN);/*from   w ww  . j  ava  2  s .co  m*/
    } else {
        ctx.updateStack(-1);
        Instruction insn = stmt.getValue().get();
        ctx.emitInstruction(insn, ctx.getMethod().getReturnType());
        TypeSignature ret = ctx.getMethod().getReturnType();
        if (ret == ClassTypeSignature.INT || ret == ClassTypeSignature.BOOLEAN || ret == ClassTypeSignature.BYTE
                || ret == ClassTypeSignature.SHORT || ret == ClassTypeSignature.CHAR) {
            mv.visitInsn(Opcodes.IRETURN);
        } else if (ret == ClassTypeSignature.LONG) {
            mv.visitInsn(Opcodes.LRETURN);
        } else if (ret == ClassTypeSignature.FLOAT) {
            mv.visitInsn(Opcodes.FRETURN);
        } else if (ret == ClassTypeSignature.DOUBLE) {
            mv.visitInsn(Opcodes.DRETURN);
        } else {
            mv.visitInsn(Opcodes.ARETURN);
        }
    }
}

From source file:org.spongepowered.mod.asm.transformers.EventTransformer.java

License:MIT License

protected static MethodNode createIsCancellableMethod() {
    MethodNode methodNode = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, "isCancellable", "()Z", null,
            null);//www . j av a  2  s.  c  om
    methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
            "net/minecraftforge/fml/common/eventhandler/Event", "isCancelable", "()Z", false));
    methodNode.instructions.add(new InsnNode(Opcodes.IRETURN));
    methodNode.maxLocals = 1;
    methodNode.maxStack = 1;
    return methodNode;
}

From source file:org.spongepowered.mod.asm.transformers.EventTransformer.java

License:MIT License

protected static MethodNode createIsCancelledMethod() {
    MethodNode methodNode = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, "isCancelled", "()Z", null, null);
    methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
            "net/minecraftforge/fml/common/eventhandler/Event", "isCanceled", "()Z", false));
    methodNode.instructions.add(new InsnNode(Opcodes.IRETURN));
    methodNode.maxLocals = 1;/*from  w  ww  . j  a  v a2 s  . com*/
    methodNode.maxStack = 1;
    return methodNode;
}

From source file:org.spongepowered.mod.asm.util.ASMHelper.java

License:MIT License

/**
 * Generate a new method "boolean name()", which returns a constant value.
 *
 * @param clazz Class to add method to/*from  ww  w .  j  a  v a2 s .  com*/
 * @param name Name of method
 * @param retval Return value of method
 */
public static void generateBooleanMethodConst(ClassNode clazz, String name, boolean retval) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()Z",
            null, null);
    InsnList code = method.instructions;

    code.add(new InsnNode(retval ? Opcodes.ICONST_1 : Opcodes.ICONST_0));
    code.add(new InsnNode(Opcodes.IRETURN));

    clazz.methods.add(method);
}

From source file:org.spongepowered.mod.asm.util.ASMHelper.java

License:MIT License

/**
 * Generate a new method "int name()", which returns a constant value.
 *
 * @param clazz Class to add method to/*ww  w  .  j  a  v a  2  s.  c  o m*/
 * @param name Name of method
 * @param retval Return value of method
 */
public static void generateIntegerMethodConst(ClassNode clazz, String name, short retval) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I",
            null, null);
    InsnList code = method.instructions;

    // Probably doesn't make a huge difference, but use BIPUSH if the value is small enough.
    if (retval >= Byte.MIN_VALUE && retval <= Byte.MAX_VALUE) {
        code.add(new IntInsnNode(Opcodes.BIPUSH, retval));
    } else {
        code.add(new IntInsnNode(Opcodes.SIPUSH, retval));
    }
    code.add(new InsnNode(Opcodes.IRETURN));

    clazz.methods.add(method);
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildValidMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "isValid", "()Z", null, null);
    mv.visitCode();/*from w w  w.  j a  va  2 s  . c o m*/

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    Label trueLabel = new Label();
    mv.visitJumpInsn(Opcodes.IFGE, trueLabel);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(trueLabel);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);

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

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildDomainMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "getDomain", "()I", null, null);
    mv.visitCode();/*from  w  w  w.  j  a  v a2 s  .c  om*/

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "domain", "I");
    mv.visitInsn(Opcodes.IRETURN);

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

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildIndexMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "index", "()I", null, null);
    mv.visitCode();//from w w w  . j a  va2  s  .  co  m

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "index", "I");
    mv.visitInsn(Opcodes.IRETURN);

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

From source file:org.testeoa.estatica.AdapterDUG.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    addInstrucao(getInstrucao(opcode));//from   ww w. j  a  v a  2s.  com
    if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) {
        adjacente = false;
        saida = true;
        inserirVerticeAtual();
    } else if (opcode == Opcodes.ATHROW) {
        adjacente = false;
        saida = true;
        inserirVerticeAtual();
    }
    super.visitInsn(opcode);
}