Z3_context mk_context_custom(Z3_config cfg, Z3_error_handler err){ Z3_context ctx; Z3_set_param_value(cfg, "MODEL", "true"); ctx = Z3_mk_context(cfg); #ifdef TRACING Z3_trace_to_stderr(ctx); #endif Z3_set_error_handler(ctx, err); return ctx; }
static void test_mk_distinct() { Z3_config cfg = Z3_mk_config(); Z3_context ctx = Z3_mk_context(cfg); Z3_set_error_handler(ctx, my_cb); Z3_sort bv8 = Z3_mk_bv_sort(ctx, 8); Z3_sort bv32 = Z3_mk_bv_sort(ctx, 32); Z3_ast args[] = { Z3_mk_int64(ctx, 0, bv8), Z3_mk_int64(ctx, 0, bv32) }; Z3_ast d = Z3_mk_distinct(ctx, 2, args); SASSERT(cb_called); }
JNIEXPORT jboolean JNICALL Java_org_joogie_prover_old_Z3ProverEx_createContext( JNIEnv * env, jclass clazz) { // create config and context Z3_config cfg = Z3_mk_config(); //Z3_set_param_value(cfg, "SOFT_TIMEOUT", "30000"); context = Z3_mk_context(cfg); Z3_del_config(cfg); // set error handler Z3_set_error_handler(context, myErrorHandler); return JNI_TRUE; }
void z3_wrapper_init(z3_wrapper *z3) { /* init ctx */ Z3_config cfg = Z3_mk_config(); Z3_set_param_value(cfg, "model", "true"); z3->ctx = Z3_mk_context(cfg); /* init error handling */ Z3_set_error_handler(z3->ctx, z3_error_handler); /* init solver */ z3->solver = Z3_mk_solver(z3->ctx); Z3_solver_inc_ref(z3->ctx, z3->solver); Z3_del_config(cfg); z3->Ek_consts = NULL; }
int main(int argc, const char **argv) { /* Create a Z3 context to contain formulas */ Z3_config cfg = Z3_mk_config(); Z3_context ctx = iz3_mk_context(cfg); Z3_set_error_handler(ctx, throw_z3_error); /* Make some constraints, by parsing an smtlib formatted file given as arg 1 */ try { Z3_parse_smtlib_file(ctx, argv[1], 0, 0, 0, 0, 0, 0); } catch(const z3_error &err){ std::cerr << "Z3 error: " << Z3_get_error_msg(err.c) << "\n"; std::cerr << Z3_get_smtlib_error(ctx) << "\n"; return(1); } /* Get the constraints from the parser. */ int num = Z3_get_smtlib_num_formulas(ctx); if(num == 0){ std::cerr << "iZ3 error: File contains no formulas.\n"; return 1; } Z3_ast *constraints = (Z3_ast *)malloc(num * sizeof(Z3_ast)); int i; for (i = 0; i < num; i++) constraints[i] = Z3_get_smtlib_formula(ctx, i); /* if we get only one formula, and it is a conjunction, split it into conjuncts. */ if(num == 1){ Z3_app app = Z3_to_app(ctx,constraints[0]); Z3_func_decl func = Z3_get_app_decl(ctx,app); Z3_decl_kind dk = Z3_get_decl_kind(ctx,func); if(dk == Z3_OP_AND){ int nconjs = Z3_get_app_num_args(ctx,app); if(nconjs > 1){ std::cout << "Splitting formula into " << nconjs << " conjuncts...\n"; num = nconjs; constraints = new Z3_ast[num]; for(int k = 0; k < num; k++) constraints[k] = Z3_get_app_arg(ctx,app,k); } } } /* print out the result for grins. */ // Z3_string smtout = Z3_benchmark_to_smtlib_string (ctx, "foo", "QFLIA", "sat", "", num, constraints, Z3_mk_true(ctx)); // Z3_string smtout = Z3_ast_to_string(ctx,constraints[0]); // Z3_string smtout = Z3_context_to_string(ctx); // puts(smtout); // iz3_print(ctx,num,constraints,"iZ3temp.smt"); /* Make room for interpolants. */ Z3_ast *interpolants = (Z3_ast *)malloc((num-1) * sizeof(Z3_ast)); /* Make room for the model. */ Z3_model model = 0; /* Call the prover */ Z3_lbool result = iz3_interpolate(ctx, num, constraints, interpolants, &model); switch (result) { /* If UNSAT, print the interpolants */ case Z3_L_FALSE: printf("unsat, interpolants:\n"); for(i = 0; i < num-1; i++) printf("%s\n", Z3_ast_to_string(ctx, interpolants[i])); std::cout << "Checking interpolants...\n"; const char *error; if(iZ3_check_interpolant(ctx, num, constraints, 0, interpolants, &error)) std::cout << "Interpolant is correct\n"; else { std::cout << "Interpolant is incorrect\n"; std::cout << error << "\n"; } break; case Z3_L_UNDEF: printf("fail\n"); break; case Z3_L_TRUE: printf("sat\n"); printf("model:\n%s\n", Z3_model_to_string(ctx, model)); break; } /* Delete the model if there is one */ if (model) Z3_del_model(ctx, model); /* Delete logical context (note, we call iz3_del_context, not Z3_del_context */ iz3_del_context(ctx); return 0; }