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

The following examples show how to use org.objectweb.asm.Opcodes#FCONST_0 . 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: AsmUtil.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if the given opcode is a load of a constant (xCONST_y).
 *
 * @param opcode the opcode
 * @return true if the opcode is one of the constant loading ones, false otherwise
 */
public static boolean isXconst(final int opcode) {
  switch(opcode) {
  case Opcodes.ICONST_0:
  case Opcodes.ICONST_1:
  case Opcodes.ICONST_2:
  case Opcodes.ICONST_3:
  case Opcodes.ICONST_4:
  case Opcodes.ICONST_5:
  case Opcodes.ICONST_M1:
  case Opcodes.DCONST_0:
  case Opcodes.DCONST_1:
  case Opcodes.FCONST_0:
  case Opcodes.FCONST_1:
  case Opcodes.LCONST_0:
  case Opcodes.LCONST_1:
    return true;
  }

  return false;
}
 
Example 2
Source File: BasicInstruction.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isConstant() {
    switch (opcode) {
        case Opcodes.ACONST_NULL:
        case Opcodes.ICONST_0:
        case Opcodes.ICONST_1:
        case Opcodes.ICONST_2:
        case Opcodes.ICONST_3:
        case Opcodes.ICONST_4:
        case Opcodes.ICONST_5:
        case Opcodes.ICONST_M1:
        case Opcodes.FCONST_0:
        case Opcodes.FCONST_1:
        case Opcodes.FCONST_2:
        case Opcodes.DCONST_0:
        case Opcodes.DCONST_1:
        case Opcodes.LCONST_0:
        case Opcodes.LCONST_1:
        case Opcodes.LDC:
            return true;
    }
    return super.isConstant();
}
 
Example 3
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 4
Source File: InsnValue.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static InsnValue floatValue(int opcode) {
	switch (opcode) {
	case Opcodes.FCONST_0:
		return new InsnValue(Type.FLOAT_TYPE, 0.0f);
	case Opcodes.FCONST_1:
		return new InsnValue(Type.FLOAT_TYPE, 1.0f);
	case Opcodes.FCONST_2:
		return new InsnValue(Type.FLOAT_TYPE, 2.0f);
	}
	return InsnValue.FLOAT_VALUE;
}
 
Example 5
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 5 votes vote down vote up
public static float getFloatFromInsn(AbstractInsnNode insn) {
    int opcode = insn.getOpcode();

    if (opcode >= Opcodes.FCONST_0 && opcode <= Opcodes.FCONST_2) {
        return opcode - 11;
    } else if (insn instanceof LdcInsnNode
            && ((LdcInsnNode) insn).cst instanceof Float) {
        return (Float) ((LdcInsnNode) insn).cst;
    }

    throw new RadonException("Unexpected instruction");
}
 
Example 6
Source File: NullExpr.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(CodeEmitter code) {
    // VOID, BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE, ARRAY, OBJECT or METHOD.
    int opcode;
    switch (getType().getJVMType().getSort()) {
        case Type.VOID:
        case Type.METHOD:
            throw new UnsupportedOperationException("Unsupported NullExpr type: " + getType());
        case Type.BOOLEAN:
        case Type.SHORT:
        case Type.INT:
        case Type.CHAR:
            opcode = Opcodes.ICONST_0;
            break;
        case Type.FLOAT:
            opcode = Opcodes.FCONST_0;
            break;
        case Type.LONG:
            opcode = Opcodes.LCONST_0;
            break;
        case Type.DOUBLE:
            opcode = Opcodes.DCONST_0;
            break;
        case Type.ARRAY:
        case Type.OBJECT:
            opcode = Opcodes.ACONST_NULL;
            break;
        default:
            throw new UnsupportedOperationException("Unknown NullExpr type: " + getType());
    }
    code.getMethodVisitor().visitInsn(opcode);
    if (opcode == Opcodes.ACONST_NULL) {
        code.cast(getType(), AnyTypeWidget.getInstance());
    }
}
 
Example 7
Source File: ArithmeticExpression.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isArg(Instruction instr) {
    if (instr instanceof ArithmeticExpression) {
        return true;
    }
    if (instr instanceof AssignableExpression) {
        StringBuilder dummy = new StringBuilder();
        
        if (((AssignableExpression)instr).assignTo(null, dummy)) {
            return true;
        }
    }
    int opcode = instr.getOpcode();
    switch (opcode) {
        
        case Opcodes.FLOAD:
        case Opcodes.DLOAD:
        case Opcodes.ILOAD:
        case Opcodes.LLOAD:
        case org.objectweb.asm.Opcodes.ICONST_0:
        case org.objectweb.asm.Opcodes.ICONST_1: 
        case org.objectweb.asm.Opcodes.ICONST_2:
        case org.objectweb.asm.Opcodes.ICONST_3: 
        case org.objectweb.asm.Opcodes.ICONST_4: 
        case org.objectweb.asm.Opcodes.ICONST_5:
        case org.objectweb.asm.Opcodes.ICONST_M1:
        case org.objectweb.asm.Opcodes.LCONST_0:
        case org.objectweb.asm.Opcodes.LCONST_1: 
        case Opcodes.DCONST_0:
        case Opcodes.DCONST_1:
        case Opcodes.FCONST_0:
        case Opcodes.FCONST_1:
        case Opcodes.FCONST_2:
        case org.objectweb.asm.Opcodes.BIPUSH:
        case org.objectweb.asm.Opcodes.SIPUSH:
        case Opcodes.LDC:
            return true;
    }
    return false;
}
 
Example 8
Source File: AbstractCRCRVisitor.java    From pitest with Apache License 2.0 5 votes vote down vote up
void translateToByteCode(final Float constant) {
    if (constant == 0.0F) {
        super.visitInsn(Opcodes.FCONST_0);
    } else if (constant == 1.0F) {
        super.visitInsn(Opcodes.FCONST_1);
    } else if (constant == 2.0F) {
        super.visitInsn(Opcodes.FCONST_2);
    } else {
        super.visitLdcInsn(constant);
    }
}
 
Example 9
Source File: AbstractCRCRVisitor.java    From pitest with Apache License 2.0 5 votes vote down vote up
Number translateToNumber(final int opcode) {
    switch (opcode) {
        case Opcodes.ICONST_M1:
            return Integer.valueOf(-1);
        case Opcodes.ICONST_0:
            return Integer.valueOf(0);
        case Opcodes.ICONST_1:
            return Integer.valueOf(1);
        case Opcodes.ICONST_2:
            return Integer.valueOf(2);
        case Opcodes.ICONST_3:
            return Integer.valueOf(3);
        case Opcodes.ICONST_4:
            return Integer.valueOf(4);
        case Opcodes.ICONST_5:
            return Integer.valueOf(5);
        case Opcodes.LCONST_0:
            return Long.valueOf(0L);
        case Opcodes.LCONST_1:
            return Long.valueOf(1L);
        case Opcodes.FCONST_0:
            return Float.valueOf(0F);
        case Opcodes.FCONST_1:
            return Float.valueOf(1F);
        case Opcodes.FCONST_2:
            return Float.valueOf(2F);
        case Opcodes.DCONST_0:
            return Double.valueOf(0D);
        case Opcodes.DCONST_1:
            return Double.valueOf(1D);
        default:
            return null;
    }
}
 
Example 10
Source File: InlineConstantMutator.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void translateToByteCode(final Float constant) {
  if (constant == 0.0F) {
    super.visitInsn(Opcodes.FCONST_0);
  } else if (constant == 1.0F) {
    super.visitInsn(Opcodes.FCONST_1);
  } else if (constant == 2.0F) {
    super.visitInsn(Opcodes.FCONST_2);
  } else {
    super.visitLdcInsn(constant);
  }
}
 
Example 11
Source File: InlineConstantMutator.java    From pitest with Apache License 2.0 5 votes vote down vote up
/**
 * Translates the opcode to a number (inline constant) if possible or
 * returns <code>null</code> if the opcode cannot be translated.
 *
 * @param opcode
 *          that might represent an inline constant.
 * @return the value of the inline constant represented by opcode or
 *         <code>null</code> if the opcode does not represent a
 *         number/constant.
 */
private Number translateToNumber(final int opcode) {
  switch (opcode) {
  case Opcodes.ICONST_M1:
    return Integer.valueOf(-1);
  case Opcodes.ICONST_0:
    return Integer.valueOf(0);
  case Opcodes.ICONST_1:
    return Integer.valueOf(1);
  case Opcodes.ICONST_2:
    return Integer.valueOf(2);
  case Opcodes.ICONST_3:
    return Integer.valueOf(3);
  case Opcodes.ICONST_4:
    return Integer.valueOf(4);
  case Opcodes.ICONST_5:
    return Integer.valueOf(5);
  case Opcodes.LCONST_0:
    return Long.valueOf(0L);
  case Opcodes.LCONST_1:
    return Long.valueOf(1L);
  case Opcodes.FCONST_0:
    return Float.valueOf(0F);
  case Opcodes.FCONST_1:
    return Float.valueOf(1F);
  case Opcodes.FCONST_2:
    return Float.valueOf(2F);
  case Opcodes.DCONST_0:
    return Double.valueOf(0D);
  case Opcodes.DCONST_1:
    return Double.valueOf(1D);
  default:
    return null;
  }
}
 
Example 12
Source File: StackHelper.java    From zelixkiller with GNU General Public License v3.0 4 votes vote down vote up
public InsnValue createConstant(AbstractInsnNode insn) throws AnalyzerException {
	switch (insn.getOpcode()) {
	case Opcodes.ACONST_NULL:
		return InsnValue.NULL_REFERENCE_VALUE;
	case Opcodes.ICONST_M1:
	case Opcodes.ICONST_0:
	case Opcodes.ICONST_1:
	case Opcodes.ICONST_2:
	case Opcodes.ICONST_3:
	case Opcodes.ICONST_4:
	case Opcodes.ICONST_5:
	case Opcodes.BIPUSH:
	case Opcodes.SIPUSH:
		return InsnValue.intValue(insn);
	case Opcodes.LCONST_0:
	case Opcodes.LCONST_1:
		return InsnValue.longValue(insn.getOpcode());
	case Opcodes.FCONST_0:
	case Opcodes.FCONST_1:
	case Opcodes.FCONST_2:
		return InsnValue.floatValue(insn.getOpcode());
	case Opcodes.DCONST_0:
	case Opcodes.DCONST_1:
		return InsnValue.doubleValue(insn.getOpcode());
	case Opcodes.LDC:
		Object obj = ((LdcInsnNode) insn).cst;
		if (obj instanceof Type) {
			return new InsnValue((Type) obj);
		} else {
			Type t = Type.getType(obj.getClass());
			int sort = t.getSort();
			// Non-included types:
			// Type.ARRAY
			// Type.VOID
			// Type.METHOD
			switch (sort) {
			case Type.BOOLEAN:
				return InsnValue.intValue((int) obj);
			case Type.CHAR:
				return InsnValue.charValue((char) obj);
			case Type.BYTE:
				return InsnValue.byteValue((byte) obj);
			case Type.SHORT:
				return InsnValue.shortValue((short) obj);
			case Type.INT:
				return InsnValue.intValue((int) obj);
			case Type.FLOAT:
				return InsnValue.floatValue((float) obj);
			case Type.LONG:
				return InsnValue.longValue((long) obj);
			case Type.DOUBLE:
				return InsnValue.doubleValue((double) obj);
			case Type.OBJECT:
				return new InsnValue(t, obj);
			}
			return new InsnValue(t);
		}
	case Opcodes.NEW:
		return new InsnValue(Type.getType(((TypeInsnNode) insn).desc));
	case Opcodes.JSR:
		// TODO: IDK if this is right.
		return InsnValue.REFERENCE_VALUE;
	}

	return null;
}
 
Example 13
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isFloatInsn(AbstractInsnNode insn) {
    int opcode = insn.getOpcode();
    return (opcode >= Opcodes.FCONST_0 && opcode <= Opcodes.FCONST_2)
            || (insn instanceof LdcInsnNode && ((LdcInsnNode) insn).cst instanceof Float);
}
 
Example 14
Source File: LambdaDesugaring.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether a given instruction can be used to push argument of {@code type} on stack.
 */
private /* static */ boolean isPushForType(AbstractInsnNode insn, Type type) {
  int opcode = insn.getOpcode();
  if (opcode == type.getOpcode(Opcodes.ILOAD)) {
    return true;
  }
  // b/62060793: AsyncAwait rewrites bytecode to convert java methods into state machine with
  // support of lambdas. Constant zero values are pushed on stack for all yet uninitialized
  // local variables. And SIPUSH instruction is used to advance an internal state of a state
  // machine.
  switch (type.getSort()) {
    case Type.BOOLEAN:
      return opcode == Opcodes.ICONST_0 || opcode == Opcodes.ICONST_1;

    case Type.BYTE:
    case Type.CHAR:
    case Type.SHORT:
    case Type.INT:
      return opcode == Opcodes.SIPUSH
          || opcode == Opcodes.ICONST_0
          || opcode == Opcodes.ICONST_1
          || opcode == Opcodes.ICONST_2
          || opcode == Opcodes.ICONST_3
          || opcode == Opcodes.ICONST_4
          || opcode == Opcodes.ICONST_5
          || opcode == Opcodes.ICONST_M1;

    case Type.LONG:
      return opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1;

    case Type.FLOAT:
      return opcode == Opcodes.FCONST_0
          || opcode == Opcodes.FCONST_1
          || opcode == Opcodes.FCONST_2;

    case Type.DOUBLE:
      return opcode == Opcodes.DCONST_0 || opcode == Opcodes.DCONST_1;

    case Type.OBJECT:
    case Type.ARRAY:
      return opcode == Opcodes.ACONST_NULL;

    default:
      // Support for BIPUSH and LDC* opcodes is not implemented as there is no known use case.
      return false;
  }
}