use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.
the class HeapVM method IALOAD.
/**
* Load an int value from an array and push it on the stack
*
* ..., arrayref, index ==> ..., value
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#iaload
*/
@Override
public void IALOAD(Object conc_array, int conc_index) {
// pop symbolic arguments
IntegerValue symb_index = env.topFrame().operandStack.popBv32();
ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
/* check reference initialization */
env.heap.initializeReference(conc_array, array_ref);
/* null-check */
if (nullReferenceViolation(array_ref, conc_array)) {
return;
}
/* negative index */
if (negativeIndexViolation(conc_index, symb_index)) {
return;
}
/* out of bound index */
ReferenceExpression symb_array = (ReferenceExpression) array_ref;
int conc_array_length = Array.getLength(conc_array);
IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
return;
int bv32 = Array.getInt(conc_array, conc_index);
IntegerValue c = env.heap.array_load(symb_array, conc_index, (long) bv32);
env.topFrame().operandStack.pushBv32(c);
}
use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.
the class JumpVM method IF_ICMPEQ.
/**
* (left == right). (left != right) is just (not (left == right)).
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#if_icmpcond
*/
@Override
public void IF_ICMPEQ(String className, String methName, int branchIndex, int left, int right) {
IntegerValue rightOp = env.topFrame().operandStack.popBv32();
IntegerValue leftOp = env.topFrame().operandStack.popBv32();
IntegerConstraint cnstr;
if (left == right)
// "True" branch
cnstr = ConstraintFactory.eq(leftOp, rightOp);
else
// "False" branch
cnstr = ConstraintFactory.neq(leftOp, rightOp);
// add branch condition iif local constraint is concrete
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable())
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.
the class JumpVM method IF_ICMPGT.
/**
* (left > right) is just (right < left). (left <= right) is just (not (left
* > right)).
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#if_icmpcond
*/
@Override
public void IF_ICMPGT(String className, String methName, int branchIndex, int left, int right) {
// FIXME: Replace following five instructions with SWAP
IntegerValue rightBv = env.topFrame().operandStack.popBv32();
IntegerValue leftBv = env.topFrame().operandStack.popBv32();
env.topFrame().operandStack.pushBv32(rightBv);
env.topFrame().operandStack.pushBv32(leftBv);
IF_ICMPLT(className, methName, branchIndex, right, left);
}
use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.
the class JumpVM method LOOKUPSWITCH.
/**
* <b>switch</b> statement whose cases may not be numbered consecutively.
* I.e., there may be holes (missing targets) between the lowest and highest
* target.
*
* <p>
* Very similar to {@link #TABLESWITCH}. The main difference is that here we
* are given a list of explicit goals. Tableswitch defines its goals
* implicitly, between min and max.
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc8.html#lookupswitch
*/
@Override
public void LOOKUPSWITCH(String className, String methName, int branchIndex, int goalConcrete, int[] targetsConcrete) {
// TODO: target array remains constant. Do we really need to create and
// pass
// this array every time as a paremeter?
final IntegerValue goal = env.topFrame().operandStack.popBv32();
Vector<IntegerConstraint> constraints = new Vector<IntegerConstraint>();
for (int targetConcrete : targetsConcrete) {
IntegerConstant integerConstant = ExpressionFactory.buildNewIntegerConstant(targetConcrete);
IntegerConstraint constraint;
if (goalConcrete == targetConcrete) {
constraint = ConstraintFactory.eq(goal, integerConstant);
constraints.add(constraint);
break;
} else {
constraint = ConstraintFactory.neq(goal, integerConstant);
constraints.add(constraint);
}
}
for (int i = 0; i < constraints.size() - 1; i++) {
IntegerConstraint cnstrnt = constraints.get(i);
if (cnstrnt.getLeftOperand().containsSymbolicVariable() || cnstrnt.getRightOperand().containsSymbolicVariable())
pc.addSupportingConstraint(cnstrnt);
}
// add branch condition iif local constraint is concrete
IntegerConstraint cnstr = constraints.get(constraints.size() - 1);
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable()) {
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
}
use of org.evosuite.symbolic.expr.bv.IntegerValue in project evosuite by EvoSuite.
the class JumpVM method IF_ICMPLT.
/**
* (left < right). (left >= right) is just (not (left < right)).
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc6.html#if_icmpcond
*/
@Override
public void IF_ICMPLT(String className, String methName, int branchIndex, int left, int right) {
IntegerValue rightBv = env.topFrame().operandStack.popBv32();
IntegerValue leftBv = env.topFrame().operandStack.popBv32();
IntegerConstraint cnstr;
if (left < right)
// True Branch
cnstr = ConstraintFactory.lt(leftBv, rightBv);
else
// False branch
cnstr = ConstraintFactory.gte(leftBv, rightBv);
// add branch condition iif local constraint is concrete
if (cnstr.getLeftOperand().containsSymbolicVariable() || cnstr.getRightOperand().containsSymbolicVariable())
pc.addBranchCondition(className, methName, branchIndex, cnstr);
}
Aggregations