/* * Test * - create values of type tau * - n: max number of fresh values to try (assumed positive) */ static void test_type(type_t tau, uint32_t n) { value_t v; uint32_t i; printf("==== Test fresh values of type "); print_type(stdout, &types, tau); printf(" ====\n"); printf("cardinality: %"PRIu32"\n\n", type_card(&types, tau)); i = 0; do { v = make_fresh_value(&maker, tau); if (v == null_value) break; i ++; printf("val[%"PRIu32"] = ", i); vtbl_print_object(stdout, &vtbl, v); printf("\n"); if (vtbl_queue_is_nonempty(&vtbl)) { vtbl_print_queued_functions(stdout, &vtbl, true); printf("\n"); } } while (i <n); printf("\n---> got %"PRIu32" fresh values\n\n", i); }
/* * Print the terms of uninterpreted type in array a * - n = size of the array */ static void eval_print_constant_assignments(FILE *f, evaluator_t *eval, term_t *a, uint32_t n) { model_t *model; term_table_t *terms; char *name; value_unint_t *d; uint32_t i; term_t t; value_t c; type_kind_t tau; model = eval->model; terms = model->terms; for (i=0; i<n; i++) { t = a[i]; tau = term_type_kind(terms, t); if (tau == UNINTERPRETED_TYPE || tau == SCALAR_TYPE) { c = eval_in_model(eval, t); d = vtbl_unint(&model->vtbl, c); name = term_name(terms, t); assert(name != NULL); if (d->name == NULL || strcmp(name, d->name) != 0) { fprintf(f, "(= %s ", name); vtbl_print_object(f, &model->vtbl, c); fputs(")\n", f); } } } }
/* * Print the function terms in array a * - n = size of the array */ static void eval_print_function_assignments(FILE *f, evaluator_t *eval, term_t *a, uint32_t n) { model_t *model; term_table_t *terms; value_fun_t *fun; char *name; term_t t; value_t c; uint32_t i; model = eval->model; terms = model->terms; // first pass: function objects for (i=0; i<n; i++) { t = a[i]; if (is_function_term(terms, t)) { /* * t is mapped to a function object fun * if t and fun have different names, we print * (= <t's name> <fun 's name>) otherwise we print nothing * and store fun in the vtbl's internal queue */ c = eval_in_model(eval, t); name = term_name(terms, t); assert(name != NULL); if (object_is_function(&model->vtbl, c)) { fun = vtbl_function(&model->vtbl, c); if (fun->name == NULL || strcmp(name, fun->name) != 0) { fprintf(f, "(= %s ", name); vtbl_print_object(f, &model->vtbl, c); fputs(")\n", f); } else { vtbl_push_object(&model->vtbl, c); } } } } /* * second pass: deal with update objects */ for (i=0; i<n; i++) { t = a[i]; if (is_function_term(terms, t)) { c = eval_in_model(eval, t); name = term_name(terms, t); assert(name != NULL); if (object_is_update(&model->vtbl, c)) { vtbl_normalize_and_print_update(f, &model->vtbl, name, c, true); } } } }
/* * Print the function terms in array a * - n = size of the array */ static void model_print_function_assignments(FILE *f, model_t *model, term_t *a, uint32_t n) { term_table_t *terms; value_fun_t *fun; char *name; term_t t; value_t c; uint32_t i; terms = model->terms; for (i=0; i<n; i++) { t = a[i]; if (is_function_term(terms, t)) { /* * t is mapped to a function object fun * if t and fun have different names, we print * (= <t's name> <fun 's name>) otherwise we print nothing * and push fun in value_table's queue */ c = model_find_term_value(model, t); name = term_name(terms, t); assert(name != NULL); if (object_is_function(&model->vtbl, c)) { fun = vtbl_function(&model->vtbl, c); if (fun->name == NULL || strcmp(name, fun->name) != 0) { fprintf(f, "(= %s ", name); vtbl_print_object(f, &model->vtbl, c); fputs(")\n", f); } else { vtbl_push_object(&model->vtbl, c); } } } } /* * Second pass: print the update objects */ for (i=0; i<n; i++) { t = a[i]; if (is_function_term(terms, t)) { c = model_find_term_value(model, t); name = term_name(terms, t); assert(name != NULL); if (object_is_update(&model->vtbl, c)) { vtbl_normalize_and_print_update(f, &model->vtbl, name, c, true); } } } }
/* * Print the assignment for t as computed by the evaluator * - t must be a valid, uninterpreted term */ static void eval_print_term_value(FILE *f, evaluator_t *eval, term_t t) { model_t *model; char *name; value_t v; assert(term_kind(eval->model->terms, t) == UNINTERPRETED_TERM); model = eval->model; v = eval_in_model(eval, t); if (v >= 0) { // v = good value for t name = term_name(model->terms, t); if (name == NULL) { fprintf(f, "(= t!%"PRId32" ", t); } else { fprintf(f, "(= %s ", name); } vtbl_print_object(f, &model->vtbl, v); fputc(')', f); } }
static void test_enum_type(type_t tau) { uint32_t i, n; value_t x; assert(is_finite_type(&types, tau) && type_card_is_exact(&types, tau)); n = type_card(&types, tau); printf("==== Enumerating elements of type "); print_type(stdout, &types, tau); printf(" ====\n"); printf("cardinality: %"PRIu32"\n", n); for (i=0; i<n; i++) { x = vtbl_gen_object(&vtbl, tau, i); printf("elem[%"PRIu32"] = ", i); vtbl_print_object(stdout, &vtbl, x); printf("\n"); if (vtbl_queue_is_nonempty(&vtbl)) { vtbl_print_queued_functions(stdout, &vtbl, true); printf("\n"); } } printf("\n"); }
/* * Print the assignment for t in model * - the format is (= <t's name> <value>) */ void model_print_term_value(FILE *f, model_t *model, term_t t) { char *name; value_t v; assert(term_kind(model->terms, t) == UNINTERPRETED_TERM); name = term_name(model->terms, t); if (name == NULL) { fprintf(f, "(= t!%"PRId32" ", t); } else { fprintf(f, "(= %s ", name); } v = model_find_term_value(model, t); if (v == null_value) { /* * ??) is a C trigraph so "???)" can't be written as is. */ fputs("???"")", f); } else { vtbl_print_object(f, &model->vtbl, v); fputc(')', f); } }