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); }
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; }
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_iteExpr(value vc, value i, value t, value e) { CAMLparam4(vc,i,t,e); CAMLreturn(alloc_Expr(vc_iteExpr(VC_val(vc),Expr_val(i),Expr_val(t), Expr_val(e)))); }