Search in sources :

Example 6 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method LAND.

/**
 * @see http
 *      ://java.sun.com/docs/books/jvms/second_edition/html/Instructions2
 *      .doc8.html#land
 */
@Override
public void LAND() {
    IntegerValue right = env.topFrame().operandStack.popBv64();
    IntegerValue left = env.topFrame().operandStack.popBv64();
    long left_concrete_value = ((Long) left.getConcreteValue()).longValue();
    long right_concrete_value = ((Long) right.getConcreteValue()).longValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    long con = left_concrete_value & right_concrete_value;
    IntegerValue intExpr = new IntegerBinaryExpression(left, Operator.IAND, right, (long) con);
    env.topFrame().operandStack.pushBv64(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 7 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method ISHL.

/**
 * Stack=value1(int)|value2(int)
 *
 * Pops two ints off the stack. Shifts value2 left by the amount indicated
 * in the five low bits of value1. The int result is then pushed back onto
 * the stack.
 */
@Override
public void ISHL() {
    IntegerValue right_expr = (IntegerValue) env.topFrame().operandStack.popBv32();
    IntegerValue left_expr = (IntegerValue) env.topFrame().operandStack.popBv32();
    int left_concrete_value = ((Long) left_expr.getConcreteValue()).intValue();
    int right_concrete_value = ((Long) right_expr.getConcreteValue()).intValue();
    int concrete_value = left_concrete_value << (right_concrete_value & 0x001F);
    IntegerBinaryExpression intExpr = new IntegerBinaryExpression(left_expr, Operator.SHL, right_expr, (long) concrete_value);
    env.topFrame().operandStack.pushBv32(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 8 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method LSUB.

/**
 * @see http
 *      ://java.sun.com/docs/books/jvms/second_edition/html/Instructions2
 *      .doc8.html#lsub
 */
@Override
public void LSUB() {
    IntegerValue right = env.topFrame().operandStack.popBv64();
    IntegerValue left = env.topFrame().operandStack.popBv64();
    long left_concrete_value = ((Long) left.getConcreteValue()).longValue();
    long right_concrete_value = ((Long) right.getConcreteValue()).longValue();
    if (!left.containsSymbolicVariable()) {
        left = ExpressionFactory.buildNewIntegerConstant(left_concrete_value);
    }
    if (!right.containsSymbolicVariable()) {
        right = ExpressionFactory.buildNewIntegerConstant(right_concrete_value);
    }
    long con = left_concrete_value - right_concrete_value;
    IntegerValue intExpr = new IntegerBinaryExpression(left, Operator.MINUS, right, (long) con);
    env.topFrame().operandStack.pushBv64(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 9 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ArithmeticVM method ISHR.

/**
 * Stack=value1(int)|value2(int)
 *
 * Pops two ints off the stack. Shifts value2 left by the amount indicated
 * in the five low bits of value1. The int result is then pushed back onto
 * the stack.
 */
@Override
public void ISHR() {
    IntegerValue right_expr = (IntegerValue) env.topFrame().operandStack.popBv32();
    IntegerValue left_expr = (IntegerValue) env.topFrame().operandStack.popBv32();
    int left_concrete_value = ((Long) left_expr.getConcreteValue()).intValue();
    int right_concrete_value = ((Long) right_expr.getConcreteValue()).intValue();
    int concrete_value = left_concrete_value >> (right_concrete_value & 0x001F);
    IntegerBinaryExpression intExpr = new IntegerBinaryExpression(left_expr, Operator.SHR, right_expr, (long) concrete_value);
    env.topFrame().operandStack.pushBv32(intExpr);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 10 with IntegerBinaryExpression

use of org.evosuite.symbolic.expr.bv.IntegerBinaryExpression in project evosuite by EvoSuite.

the class ExpressionFactory method buildAddNormalized.

private static IntegerValue buildAddNormalized(IntegerValue left, IntegerValue right, long con) {
    // can only optimize if left is a literal
    if (!(left instanceof IntegerConstant))
        return new IntegerBinaryExpression(left, Operator.PLUS, right, con);
    /*
		 * (add 0 x) --> x
		 */
    if (((IntegerConstant) left).getConcreteValue() == 0) {
        return right;
    }
    /*
		 * (add a b) --> result of a+b
		 */
    if (right instanceof IntegerConstant) {
        long a = left.getConcreteValue();
        long b = right.getConcreteValue();
        return buildNewIntegerConstant(a + b);
    }
    /*
		 * (add a (add b x)) --> (add (a+b) x)
		 */
    if (right instanceof IntegerBinaryExpression && ((IntegerBinaryExpression) right).getOperator() == Operator.PLUS) {
        IntegerBinaryExpression add = (IntegerBinaryExpression) right;
        if (add.getLeftOperand() instanceof IntegerConstant) {
            long a = left.getConcreteValue();
            long b = add.getLeftOperand().getConcreteValue();
            IntegerConstant a_plus_b = buildNewIntegerConstant(a + b);
            return new IntegerBinaryExpression(a_plus_b, Operator.PLUS, add.getRightOperand(), con);
        }
    }
    return new IntegerBinaryExpression(left, Operator.PLUS, right, con);
}
Also used : IntegerBinaryExpression(org.evosuite.symbolic.expr.bv.IntegerBinaryExpression) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Aggregations

IntegerBinaryExpression (org.evosuite.symbolic.expr.bv.IntegerBinaryExpression)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)22 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)14 Constraint (org.evosuite.symbolic.expr.Constraint)12 ArrayList (java.util.ArrayList)8 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)8 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)8 Test (org.junit.Test)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)7 SolverResult (org.evosuite.symbolic.solver.SolverResult)7 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)1 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)1 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)1