예제 #1
0
Expr vc_bvWriteToMemoryArray(VC vc, 
			     Expr array, Expr byteIndex, 
			     Expr element, int numOfBytes) {
  if(!(numOfBytes > 0))
    BEEV::FatalError("numOfBytes must be greater than 0");
	    
  int newBitsPerElem = numOfBytes*8;
  if(numOfBytes == 1)
    return vc_writeExpr(vc, array, byteIndex, element);
  else {
    int count = 1;
    int hi = newBitsPerElem - 1;
    int low = newBitsPerElem - 8;
    int low_elem = 0;
    int hi_elem = low_elem + 7;
    Expr c = vc_bvExtract(vc, element, hi_elem, low_elem);
    Expr newarray = vc_writeExpr(vc, array, byteIndex, c);
    while(--numOfBytes > 0) {
      hi = low-1;
      low = low-8;      

      low_elem = low_elem + 8;
      hi_elem = low_elem + 7;

      c = vc_bvExtract(vc, element, hi_elem, low_elem);
      newarray = 
	vc_writeExpr(vc, newarray,
		     vc_bvPlusExpr(vc, 32, byteIndex, vc_bvConstExprFromInt(vc,32,count)),
		     c);
      count++;
    }
    return newarray;
  }    
}
예제 #2
0
파일: example.c 프로젝트: Sjlver/stp
int main(int argc, char** argv)
{
    int width=8;
    VC handle = vc_createValidityChecker();

    // Create variable "x"
    Expr x = vc_varExpr(handle, "x", vc_bvType(handle, width));

    // Create bitvector x + x
    Expr xPlusx = vc_bvPlusExpr(handle, width, x, x);

    // Create bitvector constant 2
    Expr two = vc_bvConstExprFromInt(handle, width, 2);
    
    // Create bitvector 2*x
    Expr xTimes2 = vc_bvMultExpr(handle, width, two, x);

    // Create bool expression x + x = 2*x
    Expr equality = vc_eqExpr(handle, xPlusx , xTimes2);

    vc_assertFormula(handle, vc_trueExpr(handle) );

    // We are asking STP: ∀ x. true → ( x + x = 2*x )
    // This should be VALID.
    printf("######First Query\n");
    handleQuery(handle, equality);

    // We are asking STP: ∀ x. true → ( x + x = 2 )
    // This should be INVALID.
    printf("######Second Query\n");
    // Create bool expression x + x = 2
    Expr badEquality = vc_eqExpr(handle, xPlusx , two);
    handleQuery(handle, badEquality);

    // Clean up
    vc_Destroy(handle);

    return 0;
}
예제 #3
0
Expr vc_bvReadMemoryArray(VC vc, 
			  Expr array, 
			  Expr byteIndex, int numOfBytes) {
  if(!(numOfBytes > 0))
    BEEV::FatalError("numOfBytes must be greater than 0");

  if(numOfBytes == 1)
    return vc_readExpr(vc,array,byteIndex);
  else {
    int count = 1;
    Expr a = vc_readExpr(vc,array,byteIndex);
    while(--numOfBytes > 0) {
      Expr b = vc_readExpr(vc,array,
			   /*vc_simplify(vc, */
				       vc_bvPlusExpr(vc, 32, 
						     byteIndex,
						     vc_bvConstExprFromInt(vc,32,count)))/*)*/;
      a = vc_bvConcatExpr(vc,b,a);
      count++;
    }
    return a;
  }    
}
예제 #4
0
TEST(extend_adder_notexpr, one)
{

  VC vc = vc_createValidityChecker();
  vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');

  // 8-bit variable 'x'
  Expr x = vc_varExpr(vc, "x", vc_bvType(vc, 8));

  // 32 bit constant value 1
  Expr one = vc_bvConstExprFromInt(vc, 32, 1);

  // 24 bit constant value 0
  Expr bit24_zero = vc_bvConstExprFromInt(vc, 24, 0);
  // 32 bit constant value 0
  Expr bit32_zero = vc_bvConstExprFromInt(vc, 32, 0);

  // Extending 8-bit variable to 32-bit value
  Expr zero_concat_x = vc_bvConcatExpr(vc, bit24_zero, x);
  Expr xp1 = vc_bvPlusExpr(vc, 32, zero_concat_x, one);

  // Insteading of concat operation, I also tried with SignExtend
  // Expr signextend_x=vc_bvSignExtend(vc,x,32);
  // Expr xp1=vc_bvPlusExpr(vc,32,signextend_x,one);

  // x+1=0
  Expr eq = vc_eqExpr(vc, xp1, bit32_zero);

  // x+1!=0
  eq = vc_notExpr(vc, eq);

  vc_query(vc, eq);
  vc_printCounterExample(vc);
  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
예제 #5
0
Expr vc_bv32PlusExpr(VC vc, Expr left, Expr right) {
  return vc_bvPlusExpr(vc, 32, left, right);
}
예제 #6
0
파일: reported_error.cpp 프로젝트: stp/stp
TEST(reported_issue_120, one)
{
  VC vc = vc_createValidityChecker();

  // Numbers will be non-negatives integers bounded at 2^32
  Type bv32 = vc_bvType(vc, 32);

  // Determine whether the following equations are satisfiable:
  //   v + 4 = n
  //   4 = n

  // Construct variable n
  Expr n = vc_varExpr(vc, "n", bv32);

  // Construct v + 4
  Expr v = vc_varExpr(vc, "v", bv32);
  Expr ct_4 = vc_bvConstExprFromInt(vc, 32, 4);
  Expr add_v_4 = vc_bvPlusExpr(vc, 32, v, ct_4);

  // Because numbers are represented as bit vectors,
  // addition can roll over.  So construct a constraint
  // expresses that v+4 does not overflow the bounds:
  //   v + 4 >= v
  //
  Expr ge = vc_bvGeExpr(vc, add_v_4, v);

  // Push a new context
  printf("Push\n");
  vc_push(vc);

  // Assert v + 4 = n
  printf("Assert v + 4 = n\n");
  Expr f_add = vc_eqExpr(vc, add_v_4, n);
  vc_assertFormula(vc, f_add);
  vc_printExpr(vc, f_add);
  printf("\n------\n");

  // Assert the bounds constraint
  printf("Assert v + 4 >= v\n");
  vc_assertFormula(vc, ge);
  vc_printExpr(vc, ge);
  printf("\n------\n");

  // Assert 4 = n
  printf("Assert 4 = n\n");
  Expr f_numeq = vc_eqExpr(vc, ct_4, n);
  vc_assertFormula(vc, f_numeq);
  vc_printExpr(vc, f_numeq);
  printf("\n------\n");

  // Check for satisfiability
  printf("Check\n");
  vc_printAsserts(vc);
  printf("\n------\n");
  int query = vc_query(vc, vc_falseExpr(vc));
  ASSERT_EQ(query, 0);

  // Pop context
  printf("Pop\n");
  vc_pop(vc);

  printf("query = %d\n", query);
}
예제 #7
0
value caml_vc_bvPlusExpr(value vc, value bits, value e1, value e2)
{
  CAMLparam4(vc,bits,e1,e2);
  CAMLreturn(alloc_Expr(vc_bvPlusExpr(VC_val(vc),Int_val(bits),
				      Expr_val(e1),Expr_val(e2))));
}