Skip to content

Commit

Permalink
Missing function: yices_model_set_bv_from_array
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoDutertre committed Oct 9, 2021
1 parent fc0440e commit 3e61b88
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/api/yices_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -10070,11 +10070,47 @@ int32_t _o_yices_model_set_bv_mpz(model_t *model, term_t var, mpz_t val) {
}

yices_model_set_bvconstant(model, var, &bv0);

return 0;
}



/*
* Assign a bitvector variable using an array of bits.
* - var = bitvector variable
* - a = array of n bits
* - var must be an uninterpreted term of type (bitvector n)
* (and var must not have a value in model).
*
* Elements of a are interpreted as in yices_bvconst_from_array:
* - bit i is 0 if a[i] == 0 and bit i is 1 if a[i] != 0
* - a[0] is the low-order bit
* - a[n-1] is the high-order bit
*/
EXPORTED int32_t yices_model_set_bv_from_array(model_t *model, term_t var, uint32_t n, const int32_t a[]) {
MT_PROTECT(int32_t, __yices_globals.lock, _o_yices_model_set_bv_from_array(model, var, n, a));
}

int32_t _o_yices_model_set_bv_from_array(model_t *model, term_t var, uint32_t n, const int32_t a[]) {
uint32_t nbits;

nbits = check_var_and_get_bitsize(model, var);
if (nbits == 0) return -1;

if (n != nbits) {
// could also report EMPTY_BITVECTOR if n == 0
set_error_code(INCOMPATIBLE_BVSIZES);
return -1;
}

bvconstant_set_bitsize(&bv0, n);
bvconst_set_array(bv0.data, a, n);
yices_model_set_bvconstant(model, var, &bv0);

return 0;
}


/*
* Export the list of uninterpreted terms that have a value in mdl.
Expand Down
1 change: 1 addition & 0 deletions src/api/yices_api_lock_free.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ extern int32_t _o_yices_model_set_bv_uint64(model_t *model, term_t var, uint64_t

extern int32_t _o_yices_model_set_bv_mpz(model_t *model, term_t var, mpz_t val);

extern int32_t _o_yices_model_set_bv_from_array(model_t *model, term_t var, uint32_t n, const int32_t a[]);

/************************
* VALUES IN A MODEL *
Expand Down
4 changes: 2 additions & 2 deletions src/include/yices_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ typedef enum error_code {
* TYPE_MISMATCH term1, type1
* INCOMPATIBLE_TYPES term1, type1, term2, type2
* DUPLICATE_VARIABLE term1
* INCOMPATIBLE_BVSIZES term1, type1, term2, type2
* INCOMPATIBLE_BVSIZES none
* EMPTY_BITVECTOR none
* ARITHCONSTANT_REQUIRED term1
* ARITHCONSTANT_REQUIRED term1
* INVALID_MACRO badval
* TOO_MANY_MACRO_PARAMS badval
* TYPE_VAR_REQUIRED type1
Expand Down
1 change: 1 addition & 0 deletions src/terms/bv_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ extern void bvconstant_set_all_one(bvconstant_t *b, uint32_t n);
*/
extern void bvconstant_copy(bvconstant_t *b, uint32_t n, const uint32_t *a);


/*
* Variant: initialize with a 64bit constant a, and normalize.
* - n = number of bits
Expand Down

0 comments on commit 3e61b88

Please sign in to comment.