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; }
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; }
// Boolean expressions value caml_vc_trueExpr(value vc) { CAMLparam1(vc); CAMLreturn(alloc_Expr(vc_trueExpr(VC_val(vc)))); }