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); } }
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); }
// 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"); }
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); }
value caml_vc_bvSignExtend(value vc, value e, value nb) { CAMLparam3(vc,e,nb); CAMLreturn(alloc_Expr(vc_bvSignExtend(VC_val(vc),Expr_val(e),Int_val(nb)))); }