Java Code Examples for soot.jimple.FloatConstant#v()

The following examples show how to use soot.jimple.FloatConstant#v() . 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: BaseEntryPointCreator.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected Value getSimpleDefaultValue(String t) {
	if (t.equals("java.lang.String"))
		return StringConstant.v("");
	if (t.equals("char"))
		return DIntConstant.v(0, CharType.v());
	if (t.equals("byte"))
		return DIntConstant.v(0, ByteType.v());
	if (t.equals("short"))
		return DIntConstant.v(0, ShortType.v());
	if (t.equals("int"))
		return IntConstant.v(0);
	if (t.equals("float"))
		return FloatConstant.v(0);
	if (t.equals("long"))
		return LongConstant.v(0);
	if (t.equals("double"))
		return DoubleConstant.v(0);
	if (t.equals("boolean"))
		return DIntConstant.v(0, BooleanType.v());

	//also for arrays etc.
	return G.v().soot_jimple_NullConstant();
}
 
Example 2
Source File: CPHelper.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public static Value createConstant(Object toConvert){
	if(toConvert instanceof Long){
		return LongConstant.v( ((Long)toConvert).longValue() );
	}
	else if(toConvert instanceof Double){
		return DoubleConstant.v( ((Double)toConvert).doubleValue());
	}
	else if(toConvert instanceof Boolean){
		boolean val = ((Boolean)toConvert).booleanValue();
		if(val)
			return DIntConstant.v(1,BooleanType.v());
		else
			return DIntConstant.v(0,BooleanType.v());
	}	
	else if(toConvert instanceof Float){
		return FloatConstant.v( ((Float)toConvert).floatValue());
	}
	else if(toConvert instanceof Integer){
		return IntConstant.v( ((Integer)toConvert).intValue());
	}
	else
		return null;
}
 
Example 3
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private Value toSootValue(Object val) throws AssertionError {
	Value v;
	if (val instanceof Integer)
		v = IntConstant.v((Integer) val);
	else if (val instanceof Float)
		v = FloatConstant.v((Float) val);
	else if (val instanceof Long)
		v = LongConstant.v((Long) val);
	else if (val instanceof Double)
		v = DoubleConstant.v((Double) val);
	else if (val instanceof String)
		v = StringConstant.v(val.toString());
	else if (val instanceof org.objectweb.asm.Type)
		v = ClassConstant.v(((org.objectweb.asm.Type) val).getInternalName());
	else if (val instanceof Handle)
		v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle)val).getTag());
	else
		throw new AssertionError("Unknown constant type: " + val.getClass());
	return v;
}
 
Example 4
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertConstInsn(InsnNode insn) {
	int op = insn.getOpcode();
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Value v;
		if (op == ACONST_NULL)
			v = NullConstant.v();
		else if (op >= ICONST_M1 && op <= ICONST_5)
			v = IntConstant.v(op - ICONST_0);
		else if (op == LCONST_0 || op == LCONST_1)
			v = LongConstant.v(op - LCONST_0);
		else if (op >= FCONST_0 && op <= FCONST_2)
			v = FloatConstant.v(op - FCONST_0);
		else if (op == DCONST_0 || op == DCONST_1)
			v = DoubleConstant.v(op - DCONST_0);
		else
			throw new AssertionError("Unknown constant opcode: " + op);
		opr = new Operand(insn, v);
		frame.out(opr);
	} else {
		opr = out[0];
	}
	if (op == LCONST_0 || op == LCONST_1 ||
			op == DCONST_0 || op == DCONST_1) {
		pushDual(opr);
	} else {
		push(opr);
	}
}
 
Example 5
Source File: InstrumentationUtils.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Value toDefaultSootTypeValue(Type sootType)
{
	String type = sootType.toString();
	
	if ("boolean".equals(type))
	{
		IntConstant.v(0);
	}
	else if ("byte".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("char".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("short".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("int".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("long".equals(type))
	{
		return LongConstant.v(0);
	}
	else if ("float".equals(type))
	{
		return FloatConstant.v(0);
	}
	else if ("double".equals(type))
	{
		return DoubleConstant.v(0);
	}

	return NullConstant.v();
}
 
Example 6
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void outAFloatConstant(AFloatConstant node)
   {
String s = (String) mProductions.removeLast();

       boolean isDouble = true;
       float value = 0;
       double dvalue = 0;

       if(s.endsWith("f") || s.endsWith("F")) 
         isDouble = false;
         
       if(s.charAt(0) == '#') {
         if(s.charAt(1) == '-') {
           if(isDouble)
             dvalue = Double.NEGATIVE_INFINITY;
           else
             value = Float.NEGATIVE_INFINITY;
         }
         else if(s.charAt(1) == 'I') {
           if(isDouble)
             dvalue = Double.POSITIVE_INFINITY;
           else
             value = Float.POSITIVE_INFINITY;
         }
         else {
           if(isDouble)
             dvalue = Double.NaN;
           else
             value = Float.NaN;
         }
       }
       else {
         StringBuffer buf = new StringBuffer();          
         if(node.getMinus() != null)
           buf.append('-');
         buf.append(s);
         s = buf.toString();
       
         if(isDouble)
           dvalue = Double.parseDouble(s);
         else
           value =Float.parseFloat(s);        
       }

       Object res;
       if(isDouble)
         res = DoubleConstant.v(dvalue);
       else
         res = FloatConstant.v(value);

mProductions.addLast(res);
   }
 
Example 7
Source File: UntypedIntOrFloatConstant.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public FloatConstant toFloatConstant() {
    return  FloatConstant.v(Float.intBitsToFloat((int) value));
}
 
Example 8
Source File: CONSTANT_Float_info.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Value createJimpleConstantValue(cp_info[] constant_pool) {
	return FloatConstant.v(convert());
}
 
Example 9
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() {
    unitAnalysis = new UnitThrowAnalysis();
    immaculateAnalysis = new ImmaculateInvokeUnitThrowAnalysis();

    // Ensure the Exception classes we need are represented in Soot:
    utility = new ExceptionTestUtility(System.getProperty("sun.boot.class.path"));

    List voidList = new ArrayList();
    SootClass bogusClass = new SootClass("BogusClass");
    bogusClass.addMethod(new SootMethod("floatFunction",voidList,FloatType.v()));
    bogusClass.addMethod(new SootMethod("floatFunction",Arrays.asList(new Type[] {
        FloatType.v(), FloatType.v(),}),
                FloatType.v(),Modifier.STATIC));
    SootFieldRef nanFieldRef = Scene.v().makeFieldRef(Scene.v().getSootClass("java.lang.Float"),
            "NaN", FloatType.v(),
            true);
    floatStaticFieldRef = Grimp.v().newStaticFieldRef(nanFieldRef);
    floatLocal = Grimp.v().newLocal("local", FloatType.v());
    floatConstant = FloatConstant.v(33.42f);
    floatConstantLocal = Grimp.v().newLocal("local", RefType.v("soot.jimple.FloatConstant"));
    SootFieldRef valueFieldRef 
        = Scene.v().makeFieldRef(bogusClass, "value", FloatType.v(), false);
    floatInstanceFieldRef = Grimp.v().newInstanceFieldRef(floatConstantLocal,
            valueFieldRef);
    floatArrayRef = Grimp.v().newArrayRef(
            Jimple.v().newLocal("local1", FloatType.v()), 
            IntConstant.v(0));
    floatVirtualInvoke = Grimp.v().newVirtualInvokeExpr(
            floatConstantLocal, 
            Scene.v().makeMethodRef(bogusClass, "floatFunction", voidList, 
                FloatType.v(), false), 
            voidList);
    floatStaticInvoke = Grimp.v().newStaticInvokeExpr(
            Scene.v().makeMethodRef(bogusClass, "floatFunction", 
                Arrays.asList(new Type[] {
                    FloatType.v(), FloatType.v(),}),
                FloatType.v(), true),
            Arrays.asList(new Value[] {
                floatStaticFieldRef, floatArrayRef,})
            );
}