void fun_scan(const char *str, fun *fun) { unsigned k, ar; sscanf(str, "fun%u_%u_", &k, &ar); str += 7; assert(k == K); fun_init(fun, ar); for(int64_t tuple = int_pow(K, fun->arity) - 1; tuple >= 0; --tuple) { fun_set_val(fun, tuple, *str-'0'); ++str; } }
int main(int argc,char *argv[]) { node node1 ; node node2 ; fun_init(1,"acb",&node1); printf("a is %d,buf is %s,buf addr is %x\n",node1.a,node1.buf,node1.buf); fun_copy(&node1,&node2); printf("a is %d,buf is %s,buf addr is %x\n",node2.a,node2.buf,node2.buf); fun_free(&node1); fun_free(&node2); return 0; }
void get_function(z3_wrapper *z3, Z3_func_decl fun, uint32_t fun_arity, struct fun *kfun) { Z3_model m = Z3_solver_get_model(z3->ctx, z3->solver); assert(m); /* printf("------\n%s\n------\n", Z3_model_to_string(z3->ctx, m)); */ Z3_model_inc_ref(z3->ctx, m); fun_init(kfun, fun_arity); for(size_t xs = 0; xs < int_pow(K, fun_arity); ++xs) { /* represent `xs` in the K-ary form, * with digits[0] being the highest digit. */ uint32_t digits[fun_arity]; get_K_digits(digits, fun_arity, xs); Z3_ast args[fun_arity]; for(size_t i = 0; i < fun_arity; ++i) { args[i] = z3->Ek_consts[digits[i]]; } /* eval func on given args */ Z3_ast t = Z3_mk_app(z3->ctx, fun, fun_arity, args); Z3_ast res; assert(Z3_model_eval(z3->ctx, m, t, 1, &res) == Z3_TRUE); /* printf("%s == %s\n", Z3_ast_to_string(z3->ctx, t), Z3_ast_to_string(z3->ctx, res)); */ /* interpret the result of function application */ uint64_t y; sscanf(Z3_ast_to_string(z3->ctx, res), "V%lu", &y); fun_set_val(kfun, xs, y); } Z3_model_dec_ref(z3->ctx, m); }