Beispiel #1
0
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;
}
Beispiel #2
0
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");
}
Beispiel #3
0
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);
}
Beispiel #4
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_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);
}
Beispiel #5
0
/** returns 0 if the constraint is unsatisfiable
    else returns the id of the new path condition
    obtained by appending cstr to the pc represented by id
*/
int isSatisfiable(char* cstr, int id)
{
  // case 1:
  // if id is equal to current ID
  // then query the constraint in the current context

  // case 2:
  // if id is less than the current ID then "pop to the depth".

  //printf("%d %s\n", ++count, cstr);
  //printf("%d %d\n", id, currentID); fflush(stdout);
  if(id > currentID)
    throwRuntimeException("id > currentID. ...Not expected!");

  if(id < currentID){
    //printf( "Popping to %d\n", id);
    int pcid;
    do{
      pcid = (int) stack_pop(&pcids);
      vc_pop(vc);
    }while (pcid != id);
    currentID = id;
  }

  //fflush(stdout);

  vc_push(vc);  

  constraint = cstr; //printf("%s", constraint);
  marker = 0;

  Expr query = parse();

  jboolean result = check(vc, query);

  if(result){
    // satisfiable. Also means negation is invalid.
    // meaning current context changed.
    // So Restore the current context.
    vc_pop(vc);
    vc_push(vc);
    vc_assertFormula(vc,query);
    stack_push(&pcids, (void*) currentID);
    currentID++;
    return currentID;
  }
  else{
    // unsatifiable. Also means negation is valid.
    // context must be unchanged.
    vc_pop(vc);
    return 0;
  }
}
Beispiel #6
0
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");
}
Beispiel #7
0
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);
}
Beispiel #8
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);
}
Beispiel #9
0
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!
}
Beispiel #10
0
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");
}
Beispiel #11
0
bool STPSolverImpl::computeInitialValues(
    const Query &query, const std::vector<const Array *> &objects,
    std::vector<std::vector<unsigned char> > &values, bool &hasSolution) {
  runStatusCode = SOLVER_RUN_STATUS_FAILURE;

  TimerStatIncrementer t(stats::queryTime);

  vc_push(vc);

  for (ConstraintManager::const_iterator it = query.constraints.begin(),
                                         ie = query.constraints.end();
       it != ie; ++it)
    vc_assertFormula(vc, builder->construct(*it));

  ++stats::queries;
  ++stats::queryCounterexamples;

  ExprHandle stp_e = builder->construct(query.expr);

  if (DebugDumpSTPQueries) {
    char *buf;
    unsigned long len;
    vc_printQueryStateToBuffer(vc, stp_e, &buf, &len, false);
    klee_warning("STP query:\n%.*s\n", (unsigned)len, buf);
  }

  bool success;
  if (useForkedSTP) {
    runStatusCode = runAndGetCexForked(vc, builder, stp_e, objects, values,
                                       hasSolution, timeout);
    success = ((SOLVER_RUN_STATUS_SUCCESS_SOLVABLE == runStatusCode) ||
               (SOLVER_RUN_STATUS_SUCCESS_UNSOLVABLE == runStatusCode));
  } else {
    runStatusCode =
        runAndGetCex(vc, builder, stp_e, objects, values, hasSolution);
    success = true;
  }

  if (success) {
    if (hasSolution)
      ++stats::queriesInvalid;
    else
      ++stats::queriesValid;
  }

  vc_pop(vc);

  return success;
}
Beispiel #12
0
char *STPSolverImpl::getConstraintLog(const Query &query) {
  vc_push(vc);
  for (std::vector<ref<Expr> >::const_iterator it = query.constraints.begin(),
                                               ie = query.constraints.end();
       it != ie; ++it)
    vc_assertFormula(vc, builder->construct(*it));
  assert(query.expr == ConstantExpr::alloc(0, Expr::Bool) &&
         "Unexpected expression in query!");

  char *buffer;
  unsigned long length;
  vc_printQueryStateToBuffer(vc, builder->getFalse(), &buffer, &length, false);
  vc_pop(vc);

  return buffer;
}
Beispiel #13
0
JNIEXPORT jboolean JNICALL Java_gov_nasa_jpf_symbolic_dp_NativeInterface_isSatisfiable
  (JNIEnv *env, jclass cls, jstring constraintString )
{
  constraint = (char*) (*env)->GetStringUTFChars(env,constraintString, NULL);
  if( constraint == NULL ){
    throwRuntimeException( "out of memory?" );
  }

  //printf( "query: %s\n", constraint);
  //fflush(stdout);
  if (constraint[0] == '\0')
    return TRUE;

  vc_push(vc);
  marker = 0;
  int constraintCount = 1;
  char c;
  int i = 0;
  do{
    c = constraint[i++];
    if (c == ',')
      constraintCount++;
  }while(c != '\0');

  Expr* constraintArray = (Expr*) malloc(sizeof(Expr)*constraintCount);
  i = 0;
  char token[2]; // it must be just a comma and '\0'
  do{
    constraintArray[i++] = parse();
  }while(readToken(token));

  Expr andExpr = vc_andExprN(vc, constraintArray, constraintCount);
  linkedlist_add(&exprPool, andExpr);
  
  jboolean result = check(vc, andExpr);

  //fflush(stdout);

  //clean up
  (*env)->ReleaseStringUTFChars(env,constraintString, constraint);
  free(constraintArray);
  freeStuff();
  vc_pop(vc);

  return result;
}
Beispiel #14
0
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);
}
Beispiel #15
0
// Checkpoint the current context and increase the scope level
value caml_vc_push(value vc)
{
  CAMLparam1(vc);
  vc_push(VC_val(vc));
  CAMLreturn(Val_unit);
}
Beispiel #16
0
void test1()
{
  Flags flags = vc_createFlags();
  VC vc;
  Type b;
  Expr p, np, e;
  Type r, real2real;
  Expr x, y, fx, fy, xeqy, fxeqfy, w, z, weqx, yeqz, one, two, xeqone, xeqtwo,
    simp, simp2;
  Op f;
  Expr* assertions;
  int i, size, res;
  Kind k;

  vc_setStringFlag(flags, "dump-log", ".testc1.cvc");
  vc_setStrSeqFlag(flags, "trace", "pushpop", 1);

  vc = vc_createValidityChecker(flags);

  // Check p OR ~p

  b = vc_boolType(vc);
  p = vc_varExpr(vc, "p", vc_boolType(vc));
  np = vc_notExpr(vc, p);
  e = vc_orExpr(vc, p, np);

  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  FatalAssert(vc_getKind(e) == OR, "Expected TRUE for kind check");
  FatalAssert(vc_getKind(vc_getType(vc, e)) == BOOLEAN, "Expected TRUE for type kind check");

  vc_deleteType(b);
  vc_deleteExpr(p);
  vc_deleteExpr(np);
  vc_deleteExpr(e);

  /* Check x = y -> f(x) = f(y) */

  r = vc_realType(vc);

  x = vc_varExpr(vc, "x", r);
  y = vc_varExpr(vc, "y", r);

  real2real = vc_funType1(vc, r, r);
  f = vc_createOp(vc, "f", real2real);

  fx = vc_funExpr1(vc, f, x);
  fy = vc_funExpr1(vc, f, y);
  
  xeqy = vc_eqExpr(vc, x, y);
  fxeqfy = vc_eqExpr(vc, fx, fy);

  e = vc_impliesExpr(vc, xeqy, fxeqfy);
  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  vc_deleteType(real2real);
  vc_deleteExpr(e);

  // Check f(x) = f(y) -> x = y

  e = vc_impliesExpr(vc, fxeqfy, xeqy);
  vc_push(vc);
  res = check(vc, e);
  FatalAssert(res == 0, "Expected Invalid");
  vc_deleteExpr(e);

  // Get counter-example

  printf("Stack level: %d\n", vc_stackLevel(vc));
  printf("Counter-example:\n");
  assertions = vc_getCounterExample(vc, &size);
  
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);
  printf("End of counter-example\n\n");

  printf("Concrete model:\n");
  assertions = vc_getConcreteModel(vc, &size);
  
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);
  printf("End of concrete model\n\n");

  // Reset to initial scope
  printf("Resetting\n");
  vc_pop(vc);
  printf("Stack level: %d\n\n", vc_stackLevel(vc));

  // Check w = x & x = y & y = z & f(x) = f(y) & x = 1 & z = 2

  w = vc_varExpr(vc, "w", r);
  z = vc_varExpr(vc, "z", r);

  printf("Push Scope\n\n");
  vc_push(vc);

  weqx = vc_eqExpr(vc, w, x);
  yeqz = vc_eqExpr(vc, y, z);
  
  one = vc_ratExpr(vc, 1, 1);
  two = vc_ratExpr(vc, 2, 1);
  xeqone = vc_eqExpr(vc, x, one);
  xeqtwo = vc_eqExpr(vc, x, two);

  newAssertion(vc, weqx);
  newAssertion(vc, xeqy);
  newAssertion(vc, yeqz);
  newAssertion(vc, fxeqfy);
  newAssertion(vc, xeqone);
  newAssertion(vc, xeqtwo);

  printf("\nsimplify(w) = ");

  simp = vc_simplify(vc, w);

  char* str = vc_printExprString(vc, simp);
  printf("%s\n", str);
  vc_deleteString(str);

  printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size));
  check_error("Error occured during inconsistency check");

  printf("Assumptions Used:\n");
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);

  printf("\nPop Scope\n\n");
  vc_pop(vc);

  printf("simplify(w) = ");

  simp2 = vc_simplify(vc, w);
  vc_printExpr(vc, simp2);
  printf("\n");

  printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size));
  vc_deleteVector(assertions);

  vc_deleteType(r);
  vc_deleteExpr(x);
  vc_deleteExpr(y);
  vc_deleteOp(f);
  vc_deleteExpr(fx);
  vc_deleteExpr(fy);
  vc_deleteExpr(xeqy);
  vc_deleteExpr(fxeqfy);
  vc_deleteExpr(w);
  vc_deleteExpr(z);
  vc_deleteExpr(weqx);
  vc_deleteExpr(yeqz);
  vc_deleteExpr(one);
  vc_deleteExpr(two);
  vc_deleteExpr(xeqone);
  vc_deleteExpr(xeqtwo);
  vc_deleteExpr(simp);
  vc_deleteExpr(simp2);

  vc_destroyValidityChecker(vc);
  vc_deleteFlags(flags);
}
Beispiel #17
0
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);
}
Beispiel #18
0
void test7()
{
  VC vc = vc_createValidityChecker(NULL);

  Type r = vc_realType(vc);
  Type b = vc_boolType(vc);

  Expr x = vc_varExpr(vc, "x", r);
  Expr y = vc_varExpr(vc, "y", r);
  Expr z = vc_varExpr(vc, "z", r);

  Type real2real = vc_funType1(vc, r, r);
  Type real2bool = vc_funType1(vc, r, b);

  Op f = vc_createOp(vc, "f", real2real);
  Op p = vc_createOp(vc, "p", real2bool);

  Expr fx = vc_funExpr1(vc, f, x);
  Expr fy = vc_funExpr1(vc, f, y);
  Expr fxeqfy = vc_eqExpr(vc, fx, fy);

  Expr px = vc_funExpr1(vc, p, x);
  Expr py = vc_funExpr1(vc, p, y);

  Expr xeqy = vc_eqExpr(vc, x, y);
  Expr yeqx = vc_eqExpr(vc, y, x);
  Expr xeqz = vc_eqExpr(vc, x, z);
  Expr zeqx = vc_eqExpr(vc, z, x);
  Expr yeqz = vc_eqExpr(vc, y, z);
  Expr zeqy = vc_eqExpr(vc, z, y);

  Expr notxeqz = vc_notExpr(vc, xeqz);

  int c;

  vc_registerAtom(vc, xeqy);
  vc_registerAtom(vc, yeqx);
  vc_registerAtom(vc, xeqz);
  vc_registerAtom(vc, zeqx);
  vc_registerAtom(vc, yeqz);
  vc_registerAtom(vc, zeqy);
  vc_registerAtom(vc, px);
  vc_registerAtom(vc, py);
  vc_registerAtom(vc, fxeqfy);

  printf("Push\n");
  vc_push(vc);

  printf("Assert x = y\n");
  vc_assertFormula(vc, xeqy);
  c = printImpliedLiterals(vc);
  FatalAssert(c==3,"Implied literal error 0");

  printf("Push\n");
  vc_push(vc);
  printf("Assert x /= z\n");
  vc_assertFormula(vc, notxeqz);
  c = printImpliedLiterals(vc);
  FatalAssert(c==4,"Implied literal error 1");
  printf("Pop\n");
  vc_pop(vc);
  printf("Pop\n");
  vc_pop(vc);

  vc_deleteExpr(notxeqz);
  vc_deleteExpr(zeqy);
  vc_deleteExpr(yeqz);
  vc_deleteExpr(zeqx);
  vc_deleteExpr(xeqz);
  vc_deleteExpr(yeqx);
  vc_deleteExpr(xeqy);
  vc_deleteExpr(py);
  vc_deleteExpr(px);
  vc_deleteExpr(fxeqfy);
  vc_deleteExpr(fy);
  vc_deleteExpr(fx);
  vc_deleteOp(p);
  vc_deleteOp(f);
  vc_deleteType(real2bool);
  vc_deleteType(real2real);
  vc_deleteExpr(z);
  vc_deleteExpr(y);
  vc_deleteExpr(x);
  vc_deleteType(b);
  vc_deleteType(r);

  vc_destroyValidityChecker(vc);
}
Beispiel #19
0
int main(int argc, char** argv)
{
  if(argc < 2)
    throwRuntimeException( "must specify the file name that contains the query" );

  printf( "argc: %d\n", argc);

  printf("%s\n",argv[1]);


  // initialize stuff
  hashmap_init(&vars, 0, hash_str, cmp_str, NULL, NULL);
  linkedlist_init(&exprPool, 0, NULL);
  
  //flags = vc_createFlags();
  //vc_setStringFlag(flags, "dump-log", "test1.cvc");
  //vc = vc_createValidityChecker(flags);
  vc = vc_createValidityChecker(NULL);
  intType = vc_intType(vc);
  realType = vc_realType(vc);

  constraint = (char*) malloc(sizeof(char)*10000);

  int k = 0;
  FILE* fpt = fopen(argv[1],"r");

  while(1){
    char c = fgetc(fpt);
    if (c == EOF) break;
    constraint[k++]=c;
  }
  constraint[k]='\0';


  if (constraint[0] == '\0')
    return TRUE;

  vc_push(vc);
  marker = 0;
  int constraintCount = 1;
  char c;
  int i = 0;
  do{
    c = constraint[i++];
    if (c == ',')
      constraintCount++;
  }while(c != '\0');
  
  Expr* constraintArray = (Expr*) malloc(sizeof(Expr)*constraintCount);
  i = 0;
  char token[2]; // it must be just a comma and '\0'
  do{
    constraintArray[i++] = parse();
  }while(readToken(token));

  Expr andExpr = vc_andExprN(vc, constraintArray, constraintCount);
  linkedlist_add(&exprPool, andExpr);

  jboolean result = check(vc, andExpr);

  //clean up
  free(constraintArray);
  freeStuff();
  vc_pop(vc);

  if(result)
    printf("satisfiable");
  else
    printf("unsatisfiable");

  return EXIT_SUCCESS;
}