コード例 #1
0
ファイル: push-pop.cpp プロジェクト: stp/stp
TEST(push_pop, two)
{
  VC vc = vc_createValidityChecker();
  //vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');
  //vc_setFlags(vc, 'p');
  //vc_setFlags(vc, 'v');
  //vc_setFlags(vc, 's');
  vc_setFlags(vc, 'c');
  vc_push(vc);

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  vc_assertFormula(vc, a_eq_0);
  vc_printAsserts(vc);
  vc_push(vc);

  Expr queryexp = vc_eqExpr(vc, a, vc_bvConstExprFromInt(vc, 8, 0));
  //vc_printExpr(vc, queryexp);

  int query;
  query = vc_query(vc, queryexp);
  vc_printCounterExample(vc);
  vc_pop(vc);
  vc_pop(vc);

  ASSERT_TRUE(query);
}
コード例 #2
0
ファイル: stp-div-001.c プロジェクト: REMath/implementations
int main() {  
  VC vc = vc_createValidityChecker();
  vc_setFlags('n');
  vc_setFlags('d');
  //vc_setFlags('p');
  
  Type bv8 = vc_bvType(vc, 8);

  Expr a =  vc_bvCreateMemoryArray(vc, "a");  
 
  Expr index_3 = vc_bvConstExprFromInt(vc, 32, 3);

  Expr a_of_0 = vc_readExpr(vc, a, index_3);
  int i;
  for (i = 2; i >= 0; i--)
    a_of_0 = vc_bvConcatExpr(vc,
			     a_of_0,
			     vc_readExpr(vc, a, 
					 vc_bvConstExprFromInt(vc, 32, i)));
  
 
  Expr ct_5 = vc_bvConstExprFromInt(vc, 32, 5);
  Expr a_of_0_div_5 = vc_bvDivExpr(vc, 32, a_of_0, ct_5);
  
  Expr a_of_0_div_5_eq_5 = vc_eqExpr(vc, a_of_0_div_5, ct_5);
  vc_printExpr(vc, a_of_0_div_5_eq_5); printf("\n");
  
  /* Query 1 */
  vc_push(vc);
  int query = vc_query(vc, a_of_0_div_5_eq_5);
  vc_pop(vc);
  printf("query = %d\n", query);

  vc_assertFormula(vc, a_of_0_div_5_eq_5);
  vc_printExpr(vc, a_of_0_div_5_eq_5);
  
  /* query(false) */
  vc_push(vc);
  query = vc_query(vc, vc_falseExpr(vc));
  vc_pop(vc);
  printf("query = %d\n", query);
  assert(!query);
  
  assert(vc_counterexample_size(vc));
  
  int* a_val = (int*) malloc(sizeof *a_val);
  char *p = (char*) a_val;
  //a_of_1 = vc_simplify(vc, a_of_1);  // BUG here
  for (i=0; i<=3; i++) {
    Expr elem = vc_readExpr(vc, a, vc_bvConstExprFromInt(vc, 32, i));
    Expr ce = vc_getCounterExample(vc, elem);
    unsigned long long v = getBVUnsigned(ce);
    fprintf(stderr, "a[%d] = %ld\n", i, v);
    *p = v; p++;
  }
  printf("a = %d\n", *a_val);
  assert((*a_val)/5  == 5);

  vc_Destroy(vc);
}
コード例 #3
0
ファイル: getbv.cpp プロジェクト: cambridgehackers/stp
TEST(getbv, INT32)
{
  ASSERT_EQ(32, sizeof(int32_t) * 8);

  for (uint32_t j = 1; j < UINT32_MAX; j |= (j << 1))
  {
    VC vc = vc_createValidityChecker();
    ASSERT_NE(vc, (void*)0);
    vc_setFlags(vc, 'n');
    vc_setFlags(vc, 'd');
    vc_setFlags(vc, 'p');
    vc_setFlags(vc, 'x');

    Type bv8 = vc_bvType(vc, 8);
    ASSERT_NE(bv8, (void*)0);

    Expr a = vc_bvCreateMemoryArray(vc, "a"); // Why do we need this?
    ASSERT_NE(a, (void*)0);

    Expr index_3 = vc_bvConstExprFromInt(vc, 32, j);
    ASSERT_NE(index_3, (void*)0);

    uint32_t print_index = getBVUnsignedLongLong(index_3);
    ASSERT_EQ(print_index, j);
    vc_DeleteExpr(a);
    // vc_DeleteExpr(index_3); - Urgh... STP's C API is inconsistent regarding
    // what we should delete ourselves and what vc_Destroy() will do for us.
    vc_Destroy(vc);
  }
}
コード例 #4
0
ファイル: push-pop.cpp プロジェクト: stp/stp
TEST(push_pop, one)
{
  VC vc = vc_createValidityChecker();
  //vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');
  //vc_setFlags(vc, 'p');
  // vc_setFlags(vc,'v');
  // vc_setFlags(vc,'s');

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  int query = vc_query(vc, a_eq_0);
  ASSERT_FALSE(query);

  vc_push(vc);
  query = vc_query(vc, a_eq_0);
  ASSERT_FALSE(query);
  vc_pop(vc);

  vc_DeleteExpr(a_eq_0);
  vc_DeleteExpr(a);

  vc_Destroy(vc);
}
コード例 #5
0
ファイル: simplify1.c プロジェクト: 0bliv10n/s2e
int main() {
  for(int j=0;j < 3; j++) {
    VC vc = vc_createValidityChecker();
    vc_setFlags(vc,'n');
    vc_setFlags(vc,'d');
    vc_setFlags(vc,'p');
    vc_setFlags(vc,'x');
    
    Type bv8 = vc_bvType(vc, 8);
    Expr a =  vc_bvCreateMemoryArray(vc, "a");
    Expr index_3 = vc_bvConstExprFromLL(vc, 32, 3);

    Expr a_of_0 = vc_readExpr(vc, a, index_3);
    int i;
    for (i = 2; i >= 0; i--)
      a_of_0 = vc_bvConcatExpr(vc,
			       a_of_0,
			       vc_readExpr(vc, a,
					   vc_bvConstExprFromInt(vc, 32, i)));
    Expr cast_32_to_8 = vc_bvExtract(vc, a_of_0, 7, 0);
    Expr cast_8_to_32 = vc_bvSignExtend(vc, cast_32_to_8, 32);
    vc_printExpr(vc, cast_8_to_32);
    cast_8_to_32 = vc_simplify(vc, cast_8_to_32);
    vc_Destroy(vc);
  }
}
コード例 #6
0
ファイル: multiple-queries.c プロジェクト: Sjlver/stp
int main() {
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc,'n');
  vc_setFlags(vc,'c');
  vc_setFlags(vc,'d');
  vc_setFlags(vc,'p');

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  /* Query 1 */
  vc_push(vc);
  int query = vc_query(vc, a_eq_0);
  vc_pop(vc);
  printf("query = %d\n", query);

  /* Query 2 */
  Expr a_neq_0 = vc_notExpr(vc, a_eq_0);
  vc_push(vc);
  query = vc_query(vc, a_neq_0);
  vc_pop(vc);
  printf("query = %d\n", query);

  vc_Destroy(vc);
  return 0;
}
コード例 #7
0
ファイル: multiple-queries.cpp プロジェクト: edmcman/stp
TEST(multiple_queries,one) {
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc,'n');
  vc_setFlags(vc,'c');
  vc_setFlags(vc,'d');
  vc_setFlags(vc,'p');

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  /* Query 1 */
  vc_push(vc);
  int query = vc_query(vc, a_eq_0);
  vc_pop(vc);
  printf("query = %d\n", query);

  /* Query 2 */
  Expr a_neq_0 = vc_notExpr(vc, a_eq_0);
  vc_push(vc);
  query = vc_query(vc, a_neq_0);
  vc_pop(vc);
  printf("query = %d\n", query);

  vc_Destroy(vc);
  ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #8
0
ファイル: c_interface.cpp プロジェクト: columbia/woodpecker
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;
  }    
}
コード例 #9
0
ファイル: push-pop.cpp プロジェクト: MartinNowack/stp
TEST(push_pop, one)
{
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');
  vc_setFlags(vc, 'p');
  // vc_setFlags(vc,'v');
  // vc_setFlags(vc,'s');

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  int query = vc_query(vc, a_eq_0);
  printf("query = %d\n", query);

  vc_push(vc);
  query = vc_query(vc, a_eq_0);
  vc_pop(vc);

  printf("query = %d\n", query);

  vc_DeleteExpr(a_eq_0);
  vc_DeleteExpr(a);

  vc_Destroy(vc);
  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #10
0
ファイル: array-cvcl-02.cpp プロジェクト: DidwardFrenkel/stp
// FIXME: Pick a sensible testname that actually means something!
TEST(array_cvcl02,one) {
  VC vc = vc_createValidityChecker();
  vc_setFlag(vc,'n');
  vc_setFlag(vc,'d');
  vc_setFlag(vc,'p');

  Expr cvcl_array = vc_varExpr1(vc, "a",32,32);
  Expr i = vc_varExpr1(vc, "i", 0, 8);   
  Expr i32 = vc_bvConcatExpr(vc,
 			     vc_bvConstExprFromStr(vc,
 						   "000000000000000000000000"),
 			     i); 
  Expr no_underflow = vc_bvLeExpr(vc,
				  vc_bvConstExprFromInt(vc, 32, 0),
				  i32);  
  Expr no_overflow = vc_bvLeExpr(vc,
				 i32,
				 vc_bvConstExprFromInt(vc, 32, 9));  
  Expr in_bounds = vc_andExpr(vc, no_underflow, no_overflow);  
  Expr a_of_i = vc_bvSignExtend(vc,
				vc_readExpr(vc,cvcl_array,i32),
				32);  
  Expr a_of_i_eq_11 = vc_eqExpr(vc, 
				vc_bvConcatExpr(vc,i32,a_of_i),
				vc_bvConstExprFromInt(vc, 64, 11));
 
  vc_assertFormula(vc, in_bounds);
  vc_assertFormula(vc, a_of_i_eq_11);  
  vc_query(vc, vc_falseExpr(vc));

  long long v; 
  Expr pre = vc_bvConstExprFromInt(vc,24,0);
  int j;
  for(j=0;j<10;j++) {
    Expr exprj = vc_bvConstExprFromInt(vc,8,j);
    Expr index = vc_bvConcatExpr(vc, pre, exprj);
    index = vc_simplify(vc,index);
    Expr a_of_j = vc_readExpr(vc, cvcl_array, index);
    Expr ce = vc_getCounterExample(vc,a_of_j);    
  }
  vc_Destroy(vc);
  //vc_printCounterExample(vc);
  
  // FIXME: Actually test something
  //ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #11
0
TEST(stp_array_model,one) {  
  VC vc = vc_createValidityChecker();

  Expr a = vc_bvCreateMemoryArray(vc, "a");

  Expr index_1 = vc_bvConstExprFromInt(vc, 32, 1);
  Expr a_of_1 = vc_readExpr(vc, a, index_1);

  Expr index_2 = vc_bvConstExprFromInt(vc, 32, 2);
  Expr a_of_2 = vc_readExpr(vc, a, index_2);

  Expr ct_42 = vc_bvConstExprFromInt(vc, 8, 42);
  Expr a_of_1_eq_42 = vc_eqExpr(vc, a_of_1, ct_42);

  Expr ct_77 = vc_bvConstExprFromInt(vc, 8, 77);
  Expr a_of_2_eq_77 = vc_eqExpr(vc, a_of_2, ct_77);

  vc_assertFormula(vc, a_of_1_eq_42);
  vc_assertFormula(vc, a_of_2_eq_77);

  /* query(false) */
  ASSERT_TRUE(vc_query(vc, vc_falseExpr(vc)) == 0); // Should be invalid

  ASSERT_FALSE(vc_counterexample_size(vc) == 0);

  Expr *indices;
  Expr *values;
  int size;
  vc_getCounterExampleArray(vc, a, &indices, &values, &size);

  ASSERT_FALSE(size == 0); // No array entries

  int j;
  for (j = 0; j < size; ++j) {
    Expr index = vc_getCounterExample(vc, indices[j]);
    Expr value = vc_getCounterExample(vc, values[j]);
    unsigned long long i = getBVUnsigned(index);
    unsigned long long v = getBVUnsigned(value);

    fprintf(stderr, "a[%llu] = %llu\n", i, v);
  }

  vc_Destroy(vc);

}
コード例 #12
0
int main() {  
  VC vc = vc_createValidityChecker();
  vc_setFlags('n');
  vc_setFlags('d');
  //vc_setFlags('p');
  
  Type bv8 = vc_bvType(vc, 8);

  Expr a =  vc_bvCreateMemoryArray(vc, "a");  
 
  Expr index_1 = vc_bvConstExprFromInt(vc, 32, 1);
  Expr a_of_1 = vc_readExpr(vc, a, index_1);  
 
  Expr ct_100 = vc_bvConstExprFromInt(vc, 8, 100);
  Expr a_of_1_eq_100 = vc_eqExpr(vc, a_of_1, ct_100);

  /* Query 1 */  
  vc_push(vc);
  int query = vc_query(vc, a_of_1_eq_100);
  vc_pop(vc);
  printf("query = %d\n", query);

  vc_assertFormula(vc, a_of_1_eq_100);
  
  /* query(false) */
  vc_push(vc);
  query = vc_query(vc, vc_falseExpr(vc));
  vc_pop(vc);
  printf("query = %d\n", query);
  
  if (vc_counterexample_size(vc) == 0) {
    printf("Counterexample size is 0\n");
    exit(1);
  }
      
  a_of_1 = vc_simplify(vc, a_of_1);  
  //vc_printExpr(vc, a_of_1);
  Expr ce = vc_getCounterExample(vc, a_of_1);
  unsigned long long v = getBVUnsigned(ce);
  
  fprintf(stderr, "a[1] = %ld\n", v);

  vc_Destroy(vc);
}
コード例 #13
0
ファイル: c_interface.cpp プロジェクト: columbia/woodpecker
Expr vc_bvVar32RightShiftExpr(VC vc, Expr sh_amt, Expr child) {
  Expr ifpart;
  Expr thenpart;
  Expr elsepart = vc_trueExpr(vc);
  Expr ite = vc_trueExpr(vc);

  for(int count=32; count >= 0; count--){
    if(count != 32) {
      ifpart = vc_eqExpr(vc, sh_amt, 
			 vc_bvConstExprFromInt(vc, 32, count));      
      thenpart = vc_bvRightShiftExpr(vc, count, child);      
      ite = vc_iteExpr(vc,ifpart,thenpart,elsepart);
      elsepart = ite;
    } else {
      elsepart = vc_bvConstExprFromInt(vc,32, 0);
    }    
  }  
  return ite;  
}
コード例 #14
0
ファイル: main.c プロジェクト: clconway/cvc3-debian
void test9 (void)
{
  VC vc = vc_createValidityChecker (((void *) 0));
  Type bv32 = vc_bvType (vc, 32);
  Expr zero = vc_bvConstExprFromInt (vc, 32, 0);
  Expr one = vc_bvConstExprFromInt (vc, 32, 1);
  Expr a = vc_varExpr (vc, "a", bv32);
  Expr three = vc_bvConstExprFromInt (vc, 32, 3);
  Expr three64 = vc_bvSignExtend (vc, three, 64);
  Expr a64 = vc_bvSignExtend (vc, a, 64);
  Expr prod64 = vc_bvMultExpr (vc, 64, a64, three64);
  Expr min = vc_bvConstExprFromInt (vc, 32, (-2147483647 - 1));
  Expr max = vc_bvConstExprFromInt (vc, 32, 2147483647);
  Expr prod64_sge_min = vc_bvSGeExpr (vc, prod64, min);
  Expr prod64_sle_max = vc_bvSLeExpr (vc, prod64, max);
  Expr prod64_sge_min_and_sle_max =
    vc_andExpr (vc, prod64_sge_min, prod64_sle_max);
  vc_assertFormula (vc, prod64_sge_min_and_sle_max);
  Expr D3 = vc_varExpr (vc, "D3", bv32);
  Expr prod = vc_bvMultExpr (vc, 32, a, three);
  Expr D3_eq_prod = vc_eqExpr (vc, D3, prod);
  vc_assertFormula (vc, D3_eq_prod);
  Expr D4 = vc_varExpr (vc, "D4", bv32);
  Expr D3_sle_a_cond = vc_bvSLeExpr (vc, D3, a);
  Expr D3_sle_a_expr = vc_iteExpr (vc, D3_sle_a_cond, one, zero);
  Expr D4_eq_D3_sle_a_expr = vc_eqExpr (vc, D4, D3_sle_a_expr);
  vc_assertFormula (vc, D4_eq_D3_sle_a_expr);
  Expr D6 = vc_varExpr (vc, "D6", bv32);
  Expr D3_slt_a_cond = vc_bvSLtExpr (vc, D3, a);
  Expr D3_slt_a_expr = vc_iteExpr (vc, D3_slt_a_cond, one, zero);
  Expr D6_eq_D3_slt_a_expr = vc_eqExpr (vc, D6, D3_slt_a_expr);
  vc_assertFormula (vc, D6_eq_D3_slt_a_expr);
  Expr zero_lt_a = vc_bvSLtExpr (vc, zero, a);
  vc_assertFormula (vc, zero_lt_a);
  Expr D4_eq_one = vc_eqExpr (vc, D4, one);
  Expr not_D4_eq_one = vc_notExpr (vc, D4_eq_one);
  vc_query (vc, not_D4_eq_one);
  Expr D6_eq_one = vc_eqExpr (vc, D6, one);
  Expr not_D6_eq_one = vc_notExpr (vc, D6_eq_one);
  vc_query (vc, not_D6_eq_one);
  vc_destroyValidityChecker(vc);
}
コード例 #15
0
ファイル: stp-counterex.cpp プロジェクト: AmesianX/stp
TEST(stp_counterex,one) {  
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc,'n');
  vc_setFlags(vc,'d');
  //vc_setFlags(vc,'p');
  
  Type bv8 = vc_bvType(vc, 8);

  Expr a =  vc_bvCreateMemoryArray(vc, "a");  
 
  Expr index_1 = vc_bvConstExprFromInt(vc, 32, 1);
  Expr a_of_1 = vc_readExpr(vc, a, index_1);  
 
  Expr ct_100 = vc_bvConstExprFromInt(vc, 8, 100);
  Expr a_of_1_eq_100 = vc_eqExpr(vc, a_of_1, ct_100);

  /* Query 1 */  
  vc_push(vc);
  int query = vc_query(vc, a_of_1_eq_100);
  vc_pop(vc);
  printf("query = %d\n", query);

  vc_assertFormula(vc, a_of_1_eq_100);
  
  /* query(false) */
  vc_push(vc);
  query = vc_query(vc, vc_falseExpr(vc));
  vc_pop(vc);
  printf("query = %d\n", query);
  
  ASSERT_FALSE(vc_counterexample_size(vc) == 0);
      
  a_of_1 = vc_simplify(vc, a_of_1);  
  //vc_printExpr(vc, a_of_1);
  Expr ce = vc_getCounterExample(vc, a_of_1);
  unsigned long long v = getBVUnsigned(ce);
  
  fprintf(stderr, "a[1] = %llu\n", v);

  vc_Destroy(vc);
  // FIXME: we should test more things!
}
コード例 #16
0
ファイル: push-pop.cpp プロジェクト: MartinNowack/stp
TEST(push_pop, two)
{
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');
  vc_setFlags(vc, 'p');
  vc_setFlags(vc, 'v');
  vc_setFlags(vc, 's');
  vc_setFlags(vc, 'c');
  vc_push(vc);

  Type bv8 = vc_bvType(vc, 8);

  Expr a = vc_varExpr(vc, "a", bv8);
  Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  int query;
  // query = vc_query(vc, a_eq_0);
  // printf("query = %d\n", query);

  Expr a_neq_0 = vc_notExpr(vc, a_eq_0);
  vc_assertFormula(vc, a_eq_0);
  vc_printAsserts(vc);
  vc_push(vc);

  Expr queryexp = vc_eqExpr(vc, a, vc_bvConstExprFromInt(vc, 8, 0));
  vc_printExpr(vc, queryexp);

  query = vc_query(vc, queryexp);
  vc_printCounterExample(vc);
  vc_pop(vc);
  vc_pop(vc);

  printf("query = %d\n", query);
  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #17
0
ファイル: stpcheck.cpp プロジェクト: MartinNowack/stp
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");
}
コード例 #18
0
ファイル: print.c プロジェクト: 0bliv10n/s2e
int main() {
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc,'n');
  vc_setFlags(vc,'d');
  vc_setFlags(vc,'p');

  Expr ct_3 = vc_bvConstExprFromStr(vc,
"00000000000000000000000000000011");
  vc_printExpr(vc, ct_3);  printf("\n");

  ct_3 = vc_bvConstExprFromInt(vc, 32, 5);
  vc_printExpr(vc, ct_3);  printf("\n");

  vc_Destroy(vc);
}
コード例 #19
0
ファイル: multi-print.cpp プロジェクト: stp/stp
TEST(multiprint, one)
{
  VC vc = vc_createValidityChecker();
  VC vc2 = vc_createValidityChecker();

  vc_setFlags(vc, 'n');
  vc_setFlags(vc, 'd');
  vc_setFlags(vc, 'p');

  Expr ct_3 = vc_bvConstExprFromStr(vc, "00000000000000000000000000000011");
  vc_printExpr(vc, ct_3);
  printf("\n");

  ct_3 = vc_bvConstExprFromInt(vc, 32, 5);
  vc_printExpr(vc, ct_3);
  printf("\n");

  vc_Destroy(vc);

  vc_setFlags(vc2, 'n');
  vc_setFlags(vc2, 'd');
  vc_setFlags(vc2, 'p');

  ct_3 = vc_bvConstExprFromStr(vc2, "00000000000000000000000000000011");
  vc_printExpr(vc2, ct_3);
  printf("\n");

  ct_3 = vc_bvConstExprFromInt(vc2, 32, 5);
  vc_printExpr(vc2, ct_3);
  printf("\n");

  vc_Destroy(vc2);

  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #20
0
ファイル: sbvdiv.cpp プロジェクト: MartinNowack/stp
TEST(sbdiv, one)
{
  VC vc = vc_createValidityChecker();
  vc_setFlags(vc, 'p');

  Type int_type = vc_bv32Type(vc);
  Expr zero = vc_bv32ConstExprFromInt(vc, 0);
  Expr int_max = vc_bvConstExprFromInt(vc, 32, 0x7fffffff);
  Expr a = vc_varExpr(vc, "a", int_type);
  Expr b = vc_varExpr(vc, "b", int_type);
  vc_assertFormula(vc, vc_sbvGtExpr(vc, b, zero));
  vc_assertFormula(vc, vc_sbvLeExpr(vc, a, vc_sbvDivExpr(vc, 32, int_max, b)));
  std::cout << vc_query(vc, vc_falseExpr(vc)) << std::endl;
  // FIXME: Actually test something
  // ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #21
0
ファイル: sbvdiv.cpp プロジェクト: stp/stp
TEST(sbdiv, one)
{
  VC vc = vc_createValidityChecker();
  //vc_setFlags(vc, 'p');
  vc_setFlags(vc, 'd');

  Type int_type = vc_bv32Type(vc);
  Expr zero = vc_bv32ConstExprFromInt(vc, 0);
  Expr int_max = vc_bvConstExprFromInt(vc, 32, 0x7fffffff);
  Expr a = vc_varExpr(vc, "a", int_type);
  Expr b = vc_varExpr(vc, "b", int_type);
  vc_assertFormula(vc, vc_sbvGtExpr(vc, b, zero));
  vc_assertFormula(vc, vc_sbvLeExpr(vc, a, vc_sbvDivExpr(vc, 32, int_max, b)));
  int query = vc_query(vc, vc_falseExpr(vc));
  ASSERT_FALSE(query);
}
コード例 #22
0
ファイル: stp-test3.cpp プロジェクト: edmcman/stp
void go (enum ifaceflag_t f)
{
	VC vc;
	

	vc = vc_createValidityChecker ();
	vc_setInterfaceFlags(vc, f, 0);
	//vc_setFlags(vc,'s',0);

    // CVC_FILE is a macro that expands to a file path
	vc_parseExpr(vc, CVC_FILE);

  	Expr a = vc_varExpr(vc, "a", vc_bvType(vc, 8));
	Expr ct_0 = vc_bvConstExprFromInt(vc, 8, 0);

  	Expr a_eq_0 = vc_eqExpr(vc, a, ct_0);

  	int query = vc_query(vc, a_eq_0);
	vc_Destroy (vc);
    ASSERT_TRUE(false && "FIXME: Actually test something");
}
コード例 #23
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;
}
コード例 #24
0
ファイル: c_interface.cpp プロジェクト: columbia/woodpecker
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;
  }    
}
コード例 #25
0
ファイル: c_interface.cpp プロジェクト: columbia/woodpecker
Expr vc_bv32ConstExprFromInt(VC vc, unsigned int value){
  return vc_bvConstExprFromInt(vc, 32, value);
}
コード例 #26
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);
}
コード例 #27
0
ファイル: main.c プロジェクト: clconway/cvc3-debian
void test8 (void)
{
  Flags flags = vc_createFlags();
/*   vc_setStrSeqFlag(flags, "trace", "pushpop", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertLit", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFactCore", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFormula", 1); */

  VC vc = vc_createValidityChecker (flags);
  Type bv32 = vc_bvType (vc, 32);
  Expr zero = vc_bvConstExprFromInt (vc, 32, 0);
  Expr one = vc_bvConstExprFromInt (vc, 32, 1);
  Expr a = vc_varExpr (vc, "a", bv32);
  Expr three = vc_bvConstExprFromInt (vc, 32, 3);
  Expr prod = vc_bvMultExpr (vc, 32, a, three);
  {
    Expr a64 = vc_bvSignExtend (vc, a, 64);
    Expr three64 = vc_bvSignExtend (vc, three, 64);
    Expr prod64 = vc_bvMultExpr (vc, 64, a64, three64);
    Expr max = vc_bvConstExprFromInt (vc, 32, 2147483647);
    Expr min = vc_bvConstExprFromInt (vc, 32, (-2147483647 - 1));
    Expr prod64_sge_min = vc_bvSGeExpr (vc, prod64, min);
    Expr prod64_sle_max = vc_bvSLeExpr (vc, prod64, max);
    Expr prod64_sge_min_and_sle_max =
      vc_andExpr (vc, prod64_sge_min, prod64_sle_max);
    vc_assertFormula (vc, prod64_sge_min_and_sle_max);
  }
  Expr D4 = vc_varExpr (vc, "D4", bv32);
  {
    Expr cond = vc_bvSLtExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D4_eq_test = vc_eqExpr (vc, D4, test);
    vc_assertFormula (vc, D4_eq_test);
  }
  Expr D6 = vc_varExpr (vc, "D6", bv32);
  {
    Expr cond = vc_bvSLeExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D6_eq_test = vc_eqExpr (vc, D6, test);
    vc_assertFormula (vc, D6_eq_test);
  }
  vc_push (vc);
  vc_pop (vc);
  vc_push (vc);
  {
    Expr cond = vc_bvSLtExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    {
      Expr D4_eq_one = vc_eqExpr (vc, D4, one);
      vc_query (vc, D4_eq_one);
    }
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
  }
  vc_pop (vc);
  {
    Expr cond = vc_eqExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    vc_pop (vc);
    {
      Expr zero_eq_one = vc_eqExpr (vc, zero, one);
      vc_query (vc, zero_eq_one);
    }
  }
  vc_destroyValidityChecker(vc);
}
コード例 #28
0
ファイル: cvcl_ocaml_wrappers.c プロジェクト: spl/ivy
value caml_vc_bvConstExprFromInt(value vc, value nbits,value i)
{
  CAMLparam3(vc,nbits,i);
  CAMLreturn(alloc_Expr(vc_bvConstExprFromInt(VC_val(vc),Int_val(nbits),
					      Int_val(i))));
}