Java Code Examples for org.objectweb.asm.Opcodes#FRETURN

The following examples show how to use org.objectweb.asm.Opcodes#FRETURN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FontRendererTransformer.java    From SkyblockAddons with MIT License 6 votes vote down vote up
@Override
public void transform(ClassNode classNode, String name) {
    for (MethodNode methodNode : classNode.methods) {

        // Objective:
        // Find:
        //   return (float value)
        // Change to:
        //   float f4 = (float value)
        //   FontRendererHook.changeTextColor(); <- insert the call right before the return
        //   return f4;

        if (TransformerMethod.renderChar.matches(methodNode) || methodNode.name.equals("renderChar")) {
            Iterator<AbstractInsnNode> iterator = methodNode.instructions.iterator();
            while (iterator.hasNext()) {
                AbstractInsnNode abstractNode = iterator.next();

                if (abstractNode.getOpcode() == Opcodes.FRETURN) {
                    methodNode.instructions.insertBefore(abstractNode, insertChangeTextColor());
                }
            }
        }
    }
}
 
Example 2
Source File: GenerationPass.java    From maple-ir with GNU General Public License v3.0 6 votes vote down vote up
static boolean isExitOpcode(int opcode) {
	switch(opcode) {
		case Opcodes.RET:
		case Opcodes.ATHROW:
		case Opcodes.RETURN:
		case Opcodes.IRETURN:
		case Opcodes.LRETURN:
		case Opcodes.FRETURN:
		case Opcodes.DRETURN:
		case Opcodes.ARETURN: {
			return true;
		}
		default: {
			return false;
		}
	}
}
 
Example 3
Source File: Java7Compatibility.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  switch (opcode) {
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:
    case Opcodes.RETURN:
      checkState(mv != null, "Encountered a second return it would seem: %s", opcode);
      mv = null; // Done: we don't expect anything to follow
      return;
    default:
      super.visitInsn(opcode);
  }
}
 
Example 4
Source File: StateImplementationVisitor.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitInsn(int opcode)
{
	if(opcode == Opcodes.FRETURN)
	{
		System.out.println(
			"StateImplementationVisitor.GetAmbientOcclusionLightValueVisitor.visitInsn()");
		
		mv.visitVarInsn(Opcodes.ALOAD, 0);
		mv.visitMethodInsn(Opcodes.INVOKESTATIC,
			"net/wurstclient/forge/compatibility/WEventFactory",
			"getAmbientOcclusionLightValue",
			"(FLnet/minecraft/block/state/IBlockState;)F", false);
	}
	
	super.visitInsn(opcode);
}
 
Example 5
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 6 votes vote down vote up
public static int getReturnOpcode(Type type) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            return Opcodes.IRETURN;
        case Type.FLOAT:
            return Opcodes.FRETURN;
        case Type.LONG:
            return Opcodes.LRETURN;
        case Type.DOUBLE:
            return Opcodes.DRETURN;
        case Type.ARRAY:
        case Type.OBJECT:
            return Opcodes.ARETURN;
        case Type.VOID:
            return Opcodes.RETURN;
        default:
            throw new AssertionError("Unknown type sort: " + type.getClassName());
    }
}
 
Example 6
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a return bytecode instruction suitable for the given return type descriptor. This will return
 * specialised return instructions <tt>IRETURN, LRETURN, FRETURN, DRETURN, RETURN</tt> for primitives/void,
 * and <tt>ARETURN</tt> otherwise;
 * 
 * @param typeDescriptor the return type descriptor.
 * @return the correct bytecode return instruction for that return type descriptor.
 */
public static int getReturnInstruction(String typeDescriptor) {
    switch (typeDescriptor) {
        case "Z":
        case "B":
        case "C":
        case "S":
        case "I":
            return Opcodes.IRETURN;
        case "J":
            return Opcodes.LRETURN;
        case "F":
            return Opcodes.FRETURN;
        case "D":
            return Opcodes.DRETURN;
        case "V":
            return Opcodes.RETURN;
        default:
            return Opcodes.ARETURN;
    }
}
 
Example 7
Source File: AsmUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a return bytecode instruction suitable for the given return Jandex Type. This will return
 * specialised return instructions <tt>IRETURN, LRETURN, FRETURN, DRETURN, RETURN</tt> for primitives/void,
 * and <tt>ARETURN</tt> otherwise;
 * 
 * @param typeDescriptor the return Jandex Type.
 * @return the correct bytecode return instruction for that return type descriptor.
 */
public static int getReturnInstruction(Type jandexType) {
    if (jandexType.kind() == Kind.PRIMITIVE) {
        switch (jandexType.asPrimitiveType().primitive()) {
            case BOOLEAN:
            case BYTE:
            case SHORT:
            case INT:
            case CHAR:
                return Opcodes.IRETURN;
            case DOUBLE:
                return Opcodes.DRETURN;
            case FLOAT:
                return Opcodes.FRETURN;
            case LONG:
                return Opcodes.LRETURN;
            default:
                throw new IllegalArgumentException("Unknown primitive type: " + jandexType);
        }
    } else if (jandexType.kind() == Kind.VOID) {
        return Opcodes.RETURN;
    }
    return Opcodes.ARETURN;
}
 
Example 8
Source File: ReturnValuesMutator.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
public void visitInsn(final int opcode) {

  switch (opcode) {
  case Opcodes.IRETURN:
    mutatePrimitiveIntegerReturn();
    break;
  case Opcodes.LRETURN:
    mutatePrimitiveLongReturn();
    break;
  case Opcodes.FRETURN:
    mutatePrimitiveFloatReturn();
    break;
  case Opcodes.DRETURN:
    mutatePrimitiveDoubleReturn();
    break;
  case Opcodes.ARETURN:
    mutateObjectReferenceReturn();
    break;
  default:
    super.visitInsn(opcode);
    break;
  }
}
 
Example 9
Source File: InstructionAssembler.java    From es6draft with MIT License 6 votes vote down vote up
/**
 * value → &#x2205;
 */
public void _return() {
    Type returnType = method.methodDescriptor.returnType();
    switch (returnType.getOpcode(Opcodes.IRETURN)) {
    case Opcodes.IRETURN:
        ireturn();
        return;
    case Opcodes.LRETURN:
        lreturn();
        return;
    case Opcodes.FRETURN:
        freturn();
        return;
    case Opcodes.DRETURN:
        dreturn();
        return;
    case Opcodes.ARETURN:
        areturn();
        return;
    case Opcodes.RETURN:
        voidreturn();
        return;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 10
Source File: ReturnValuesMutator.java    From pitest with Apache License 2.0 6 votes vote down vote up
/**
 * Mutates a primitive float return (<code>Opcode.FRETURN</code>). The
 * strategy used was translated from jumble BCEL code. The following is
 * complicated by the problem of <tt>NaN</tt>s. By default the new value is
 * <code>-(x + 1)</code>, but this doesn't work for <tt>NaN</tt>s. But for a
 * <tt>NaN</tt> <code>x != x</code> is true, and we use this to detect them.
 *
 * @see #mutatePrimitiveDoubleReturn()
 */
private void mutatePrimitiveFloatReturn() {
  if (shouldMutate("primitive float", "(x != NaN)? -(x + 1) : -1 ")) {
    final Label label = new Label();

    super.visitInsn(Opcodes.DUP);
    super.visitInsn(Opcodes.DUP);
    super.visitInsn(Opcodes.FCMPG);
    super.visitJumpInsn(Opcodes.IFEQ, label);

    super.visitInsn(Opcodes.POP);
    super.visitInsn(Opcodes.FCONST_0);

    // the following code is executed in NaN case, too
    super.visitLabel(label);
    super.visitInsn(Opcodes.FCONST_1);
    super.visitInsn(Opcodes.FADD);
    super.visitInsn(Opcodes.FNEG);
    super.visitInsn(Opcodes.FRETURN);
  }
}
 
Example 11
Source File: ConstructorTransformerMethodVisitor.java    From scott with MIT License 6 votes vote down vote up
@Override
public void visitInsn(int opcode) {
	if ((opcode == Opcodes.ARETURN) || (opcode == Opcodes.IRETURN)
			|| (opcode == Opcodes.LRETURN)
			|| (opcode == Opcodes.FRETURN)
			|| (opcode == Opcodes.DRETURN)) {
		throw new RuntimeException(new UnmodifiableClassException("Constructors are supposed to return void"));
	}
	if (opcode == Opcodes.RETURN) {
		super.visitVarInsn(Opcodes.ALOAD, 0);
		super.visitTypeInsn(Opcodes.NEW, Type.getInternalName(ScottReportingRule.class));
		super.visitInsn(Opcodes.DUP);
		super.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ScottReportingRule.class), "<init>", "()V", false);

		super.visitFieldInsn(Opcodes.PUTFIELD,
				className, "scottReportingRule",
				Type.getDescriptor(ScottReportingRule.class));
	}
	
	super.visitInsn(opcode);
}
 
Example 12
Source File: ConstructorInstrumenter.java    From allocation-instrumenter with Apache License 2.0 6 votes vote down vote up
/** Inserts the appropriate INVOKESTATIC call */
@Override
public void visitInsn(int opcode) {
  if ((opcode == Opcodes.ARETURN)
      || (opcode == Opcodes.IRETURN)
      || (opcode == Opcodes.LRETURN)
      || (opcode == Opcodes.FRETURN)
      || (opcode == Opcodes.DRETURN)) {
    throw new RuntimeException(
        new UnmodifiableClassException("Constructors are supposed to return void"));
  }
  if (opcode == Opcodes.RETURN) {
    super.visitVarInsn(Opcodes.ALOAD, 0);
    super.visitMethodInsn(
        Opcodes.INVOKESTATIC,
        "com/google/monitoring/runtime/instrumentation/ConstructorInstrumenter",
        "invokeSamplers",
        "(Ljava/lang/Object;)V",
        false);
  }
  super.visitInsn(opcode);
}
 
Example 13
Source File: Instrumentator.java    From instrumentation with Apache License 2.0 6 votes vote down vote up
private void addTraceReturn() {

        InsnList il = this.mn.instructions;

        Iterator<AbstractInsnNode> it = il.iterator();
        while (it.hasNext()) {
            AbstractInsnNode abstractInsnNode = it.next();

            switch (abstractInsnNode.getOpcode()) {
                case Opcodes.RETURN:
                    il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions());
                    break;
                case Opcodes.IRETURN:
                case Opcodes.LRETURN:
                case Opcodes.FRETURN:
                case Opcodes.ARETURN:
                case Opcodes.DRETURN:
                    il.insertBefore(abstractInsnNode, getReturnTraceInstructions());
            }
        }
    }
 
Example 14
Source File: Utils.java    From Concurnas with MIT License 5 votes vote down vote up
public static int returnTypeToOpcode(Type ret)
{
	if(ret == null)
	{
		return Opcodes.RETURN;//void
	}
	else if(ret instanceof PrimativeType && !ret.hasArrayLevels())
	{
		PrimativeTypeEnum pte = ((PrimativeType)ret).type;
		switch(pte)
		{
			case VOID: return Opcodes.RETURN;
			case BOOLEAN:
			case BYTE:
			case SHORT:
			case CHAR:
			case INT: return Opcodes.IRETURN;
			case LONG: return Opcodes.LRETURN;
			case FLOAT: return Opcodes.FRETURN;
			case DOUBLE: return Opcodes.DRETURN;
			
			default: return Opcodes.ARETURN;//PrimativeTypeEnum.LAMBDA
		}
	}
	return Opcodes.ARETURN; //object
	
}
 
Example 15
Source File: JvmType.java    From turin-programming-language with Apache License 2.0 5 votes vote down vote up
public int returnOpcode() {
    if (signature.equals("J")){
        return Opcodes.LRETURN;
    } else if (signature.equals("V")) {
        return Opcodes.RETURN;
    } else if (signature.equals("F")) {
        return Opcodes.FRETURN;
    } else if (signature.equals("D")) {
        return Opcodes.DRETURN;
    } else if (signature.equals("B")||signature.equals("S")||signature.equals("C")||signature.equals("I")||signature.equals("Z")) {
        return Opcodes.IRETURN;
    } else {
        return Opcodes.ARETURN;
    }
}
 
Example 16
Source File: ClassParserUsingASM.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.MONITORENTER:
        mBuilder.setUsesConcurrency();
        break;
    case Opcodes.ARETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.DRETURN:
    case Opcodes.FRETURN:
        if (identityState == IdentityMethodState.LOADED_PARAMETER) {
            mBuilder.setIsIdentity();
        }
        sawReturn = true;
        break;
    case Opcodes.RETURN:
        sawReturn = true;
        break;
    case Opcodes.ATHROW:
        if (stubState == StubState.INITIALIZE_RUNTIME) {
            sawStubThrow = true;
        } else if (justSawInitializationOfUnsupportedOperationException) {
            sawUnsupportedThrow = true;
        } else {
            sawNormalThrow = true;
        }
        break;
    default:
        break;
    }

    resetState();
}
 
Example 17
Source File: RobustAsmUtils.java    From Robust with Apache License 2.0 5 votes vote down vote up
/**
 * 针对不同类型返回指令不一样
 *
 * @param typeS
 * @return
 */
private static int getReturnTypeCode(String typeS) {
    if ("Z".equals(typeS)) {
        return Opcodes.IRETURN;
    }
    if ("B".equals(typeS)) {
        return Opcodes.IRETURN;
    }
    if ("C".equals(typeS)) {
        return Opcodes.IRETURN;
    }
    if ("S".equals(typeS)) {
        return Opcodes.IRETURN;
    }
    if ("I".equals(typeS)) {
        return Opcodes.IRETURN;
    }
    if ("F".equals(typeS)) {
        return Opcodes.FRETURN;
    }
    if ("D".equals(typeS)) {
        return Opcodes.DRETURN;
    }
    if ("J".equals(typeS)) {
        return Opcodes.LRETURN;
    }
    return Opcodes.ARETURN;
}
 
Example 18
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getReturnOpcode(Type type) {
	if (type.getSort() >= Type.BOOLEAN && type.getSort() <= Type.INT) {
		return Opcodes.IRETURN;
	} else if (type == Type.LONG_TYPE) {
		return Opcodes.LRETURN;
	} else if (type == Type.FLOAT_TYPE) {
		return Opcodes.FRETURN;
	} else if (type == Type.DOUBLE_TYPE) {
		return Opcodes.DRETURN;
	} else if (type.getSort() >= Type.ARRAY && type.getSort() <= Type.OBJECT) {
		return Opcodes.ARETURN;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 19
Source File: SerianalyzerMethodVisitor.java    From serianalyzer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see org.objectweb.asm.MethodVisitor#visitInsn(int)
 */
@Override
public void visitInsn ( int opcode ) {

    switch ( opcode ) {
    case Opcodes.ARETURN:
        Object ret = this.stack.pop();
        Type sigType = Type.getReturnType(this.ref.getSignature());
        Type retType = null;
        Set<Type> altTypes = null;
        if ( ret != null ) {
            if ( ret instanceof SimpleType ) {
                retType = ( (SimpleType) ret ).getType();
                altTypes = ( (SimpleType) ret ).getAlternativeTypes();
            }
            else if ( ret instanceof MultiAlternatives ) {
                retType = ( (MultiAlternatives) ret ).getCommonType();
            }
        }

        if ( retType != null ) {
            this.returnTypes.add(retType);
            if ( altTypes != null ) {
                this.returnTypes.addAll(altTypes);
            }
        }
        else {
            this.returnTypes.add(sigType);
        }
        this.stack.clear();
        break;

    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if ( this.log.isTraceEnabled() ) {
            this.log.trace("Found return " + this.stack.pop()); //$NON-NLS-1$
        }
        this.stack.clear();
        break;

    case Opcodes.ATHROW:
        Object thrw = this.stack.pop();
        this.log.trace("Found throw " + thrw); //$NON-NLS-1$
        this.stack.clear();
        break;

    default:
        JVMImpl.handleJVMInsn(opcode, this.stack);
    }

    super.visitInsn(opcode);
}
 
Example 20
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
boolean isReturnCode(final int opcode) {
    return opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN;
}