Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bitv] Add support for the SMT-LIB2's BV primitives #669

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3a92a55
Full support of BV primitives, 1st version
hra687261 Jun 19, 2023
05f6349
Move bv smart constructors to expr.ml
hra687261 Jun 19, 2023
ebb6f1c
Fix `mk_add` in D_cnf
hra687261 Jun 20, 2023
c247259
Merge branch 'next' into bv-primitives
hra687261 Jun 20, 2023
ed5b711
Move dolmen-fe only tests to `tests/dolmen/...`
hra687261 Jun 20, 2023
376fd4b
Move the expansion of most BV ops to the theory
hra687261 Jun 20, 2023
94165c3
Merge branch 'next' into bv-primitives-wip
hra687261 Jun 25, 2023
4f40a6c
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jun 26, 2023
d6a1991
Add op comparison for `bv_rotate` & `bv_repeat`
hra687261 Jun 26, 2023
2524a69
Merge branch 'next' into bv-primitives
hra687261 Jun 26, 2023
5e48a02
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jun 26, 2023
533cefd
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jun 26, 2023
bfd9916
Update src/lib/structures/symbols.ml
hra687261 Jun 26, 2023
03660ac
Update src/lib/structures/expr.ml
hra687261 Jun 26, 2023
2d5877b
Update src/lib/structures/expr.ml
hra687261 Jun 26, 2023
818829e
Update src/lib/reasoners/bitv.ml
hra687261 Jun 26, 2023
3bc686c
Update src/lib/reasoners/bitv.ml
hra687261 Jun 26, 2023
0ff6b42
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jun 26, 2023
61cb00d
Applied some requested changes, fixed build
hra687261 Jun 26, 2023
3e2bdf9
More requested changes
hra687261 Jun 27, 2023
0cb9ef9
`Util.failwith` instead of `failwith`, `asprintf`
hra687261 Jun 27, 2023
52eb884
Remove unused `nctx`
hra687261 Jun 27, 2023
1ffcf50
revert changes to `mk_add` in d_cnf
hra687261 Jun 27, 2023
6d5c2a8
Merge branch 'next' into bv-primitives
hra687261 Jun 27, 2023
cc005ee
Fix defintions of `udiv` and `urem`
hra687261 Jun 28, 2023
ed084e6
Make Dolmen ignore the "shawoding" warning
hra687261 Jun 28, 2023
032e315
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jun 29, 2023
e634b55
[bitv] simply & rename `mk_bvor` -> `mk_bvbinop`
hra687261 Jul 2, 2023
e315e82
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jul 2, 2023
c6e9d83
Added failing tests
hra687261 Jul 4, 2023
f330337
Add failing tests
hra687261 Jul 4, 2023
46568f3
Fix type of mk_bvsign
bclement-ocp Jul 4, 2023
778e332
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jul 6, 2023
0405db3
Fail if `mk_bvule` or `mk_bvult` receive n < 0 (with n being the size…
hra687261 Jul 10, 2023
be74d71
Merge branch 'OCamlPro:next' into bv-primitives
hra687261 Jul 10, 2023
a0b2910
Type fix
bclement-ocp Jul 6, 2023
9c2758e
[bitv] Proper bvnot support
bclement-ocp Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 125 additions & 6 deletions src/lib/frontend/d_cnf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,7 @@ let rec mk_expr
E.mk_term (Sy.Op Sy.Minus) [e1; aux_mk_expr x] ty

| B.Bitv_extract { i; j; _ }, [x] ->
E.mk_term
(Sy.Op (Sy.Extract (j, i))) [aux_mk_expr x] (Ty.Tbitv (i - j + 1))
E.mk_bvextract j i (aux_mk_expr x)

| B.Destructor { case; field; adt; _ }, [x] ->
begin match DT.definition adt with
Expand Down Expand Up @@ -1020,11 +1019,132 @@ let rec mk_expr
in
semantic_trigger ~loc ?var trigger

| B.Bitv_repeat { n; k }, [t] ->
E.mk_term (Op (BV_repeat k)) [aux_mk_expr t] (Tbitv (n*k))

| B.Bitv_zero_extend { n; k }, [t] ->
E.mk_bvextend false n k (aux_mk_expr t)

| B.Bitv_sign_extend { n; k }, [t] ->
E.mk_bvextend true n k (aux_mk_expr t)

| B.Bitv_rotate_left { n; i }, [t] ->
let t' = aux_mk_expr t in
if n < 2 then t' else
E.mk_term (Op (BV_rotate (-i))) [t'] (Tbitv n)

| B.Bitv_rotate_right { n; i }, [t] ->
let t' = aux_mk_expr t in
if n < 2 then t' else
E.mk_term (Op (BV_rotate i)) [t'] (Tbitv n)

| B.Bitv_neg n, [t] ->
E.mk_term (Op BVneg) [aux_mk_expr t] (Tbitv n)

| B.Bitv_not n, [t] ->
E.mk_term (Op BVnot) [aux_mk_expr t] (Tbitv n)

(* Binary applications *)

| B.Bitv_concat { n; m; }, [ x; y ] ->
let rty = Ty.Tbitv (n+m) in
E.mk_term (Sy.Op Sy.Concat) [aux_mk_expr x; aux_mk_expr y] rty
E.mk_bvconcat (aux_mk_expr x) (aux_mk_expr y) (n + m)

| B.Bitv_or n, [ x; y ] ->
E.mk_term
(Op Sy.BVor) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_and n, [ x; y ] ->
E.mk_term
(Op Sy.BVand) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_nor n, [ x; y ] ->
E.mk_term
(Op Sy.BVnor) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_nand n, [ x; y ] ->
E.mk_term
(Op Sy.BVnand) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_xor n, [ x; y ] ->
E.mk_term
(Op Sy.BVxor) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_xnor n, [ x; y ] ->
E.mk_term
(Op Sy.BVxnor) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_comp n, [ x; y ] ->
E.mk_term
(Op Sy.BVcomp) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_add n, [ x; y ] ->
E.mk_term
(Op Sy.BVadd) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_sub n, [ x; y ] ->
E.mk_term
(Op Sy.BVsub) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_mul n, [ x; y ] ->
E.mk_term
(Op Sy.BVmul) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_shl n, [ x; y ] ->
E.mk_term
(Op Sy.BVshl) [aux_mk_expr x; aux_mk_expr y] (Tbitv n)

| B.Bitv_lshr n, [ x; y ] ->
E.mk_bvlshr n (aux_mk_expr x) (aux_mk_expr y)

(* BV operators that produce ITEs or booleans are partially expanded
here instead of in the theory. Currently it is not possible to
produce ITEs in the Bit-vector theory. *)

| B.Bitv_udiv n, [ x; y ] ->
E.mk_bvudiv n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_urem n, [ x; y ] ->
E.mk_bvurem n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_sdiv n, [ x; y ] ->
E.mk_bvsdiv n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_srem n, [ x; y ] ->
E.mk_bvsrem n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_smod n, [ x; y ] ->
E.mk_bvsmod n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_ashr n, [ x; y ] ->
E.mk_bvashr n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_ult n, [ x; y ] ->
E.mk_bvult n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_ule n, [ x; y ] ->
E.mk_bvule n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_ugt n, [ x; y ] ->
E.mk_bvult n (aux_mk_expr y) (aux_mk_expr x)

| B.Bitv_uge n, [ x; y ] ->
E.mk_bvule n (aux_mk_expr y) (aux_mk_expr x)

| B.Bitv_slt n, [ x; y ] ->
if n = 0 then E.faux else
E.mk_bvslt n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_sle n, [ x; y ] ->
if n = 0 then E.faux else
E.mk_bvsle n (aux_mk_expr x) (aux_mk_expr y)

| B.Bitv_sgt n, [ x; y ] ->
if n = 0 then E.faux else
E.mk_bvslt n (aux_mk_expr y) (aux_mk_expr x)

| B.Bitv_sge n, [ x; y ] ->
if n = 0 then E.faux else
E.mk_bvsle n (aux_mk_expr y) (aux_mk_expr x)

| B.Select, [ x; y ] ->
let rty = dty_to_ty term_ty in
Expand Down Expand Up @@ -1141,8 +1261,7 @@ let rec mk_expr

| B.Add ty, _ ->
let rty = if ty == `Int then Ty.Tint else Treal in
let sy = Sy.Op Sy.Plus in
mk_add aux_mk_expr sy rty args
mk_add aux_mk_expr (Sy.Op Sy.Plus) rty args

| B.Sub ty, h :: t ->
let rty = if ty == `Int then Ty.Tint else Treal in
Expand Down
12 changes: 9 additions & 3 deletions src/lib/reasoners/arith.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ module Shostak
| Sqrt_real_default | Sqrt_real_excess
| Real_of_int | Int_floor | Int_ceil
| Max_int | Max_real | Min_int | Min_real
| Pow | Integer_log2
| Integer_round) -> true
| Pow | Integer_log2 | Integer_round) -> true
| _ -> false

let empty_polynome ty = P.create [] Q.zero ty
Expand Down Expand Up @@ -721,7 +720,14 @@ module Shostak
| Sy.Op (Sy.Plus | Sy.Minus) -> true
| _ -> false

let term_extract _ = None, false
let term_extract r =
match P.extract r with
| None -> None, false
| Some pt ->
match P.is_const pt, P.type_info pt with
| Some q, Ty.Tint ->
Some (E.int (Q.to_string q)), false
| _ -> None, false (* TODO: extract for the other types? *)

let abstract_selectors p acc =
let p, acc = P.abstract_selectors p acc in
Expand Down
Loading
Loading