Skip to content

Commit 946b949

Browse files
bclement-ocpGbury
authored andcommitted
Support SMT-LIB v2.7 bit-vector operators in psmt2
The new bit-vector operators from v2.7 are not available in SMT-LIB 2.6 scripts, which makes sense since Dolmen is intended to be able to check adherence to the specification. On the other hand, there is no standard specification for the psmt2 format, and while it implements polymorphism differently from SMT-LIB 2.7, there is no reason for psmt2 operators to be restricted to those available in version 2.6 of the standard. Allow the new bit-vector operators from version 2.7 of the standard when parsing files with psmt2 syntax.
1 parent 3c77a22 commit 946b949

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/languages/smtlib2/print/print.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,20 @@ module Make(Config : Config)(Lexer : Lexer with type token := Config.token) = st
753753

754754
| To_int { n = _; signed = true; } ->
755755
begin match Config.version with
756-
| V2_7 -> simple "sbv_to_int"
757-
| V2_6 | Poly -> _cannot_print "sbv_to_int"
756+
| V2_7 | Poly -> simple "sbv_to_int"
757+
| V2_6 -> _cannot_print "sbv_to_int"
758758
end
759759
| To_int { n = _; signed = false; } ->
760760
begin match Config.version with
761-
| V2_7 -> simple "ubv_to_int"
761+
| V2_7 | Poly -> simple "ubv_to_int"
762762
(* bvconv extension
763763
TODO: use a flag to enable extensions such as this one ? *)
764-
| V2_6 | Poly -> simple "bv2nat" (* 2.7: "sbv_to_int" *)
764+
| V2_6 -> simple "bv2nat" (* 2.7: "sbv_to_int" *)
765765
end
766766
| Of_int { n } ->
767767
begin match Config.version with
768-
| V2_6 | Poly -> p Term (N.indexed "int2bv" [int n])
769-
| V2_7 -> p Term (N.indexed "int_to_bv" [int n])
768+
| V2_6 -> p Term (N.indexed "int2bv" [int n])
769+
| V2_7 | Poly -> p Term (N.indexed "int_to_bv" [int n])
770770
end
771771
end
772772

src/typecheck/bitv.ml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ module Smtlib2 = struct
232232
| _ -> T.extract i j bitv
233233

234234
let parse version env s =
235-
let atleast2_7 () =
235+
(* Whether to include bit-vector operators from smt-lib 2.7 *)
236+
let bitv2_7 () =
236237
match (version : Dolmen.Smtlib2.version) with
237-
| `Script (`Latest | `V2_7)
238+
| `Script (`Latest | `V2_7 | `Poly)
238239
| `Response (`Latest | `V2_7) -> true
239-
| `Script (`V2_6 | `Poly)
240+
| `Script (`V2_6)
240241
| `Response (`V2_6) -> false
241242
in
242243
match s with
@@ -325,34 +326,34 @@ module Smtlib2 = struct
325326
| Type.Id { ns = Term; name = Simple "concat"; } ->
326327
Type.builtin_term (Base.term_app2 (module Type) env s T.concat)
327328

328-
| Type.Id { ns = Term; name = Simple "bvnego"; } when atleast2_7 () ->
329+
| Type.Id { ns = Term; name = Simple "bvnego"; } when bitv2_7 () ->
329330
Type.builtin_term (Base.term_app1 (module Type) env s T.nego)
330-
| Type.Id { ns = Term; name = Simple "bvsaddo"; } when atleast2_7 () ->
331+
| Type.Id { ns = Term; name = Simple "bvsaddo"; } when bitv2_7 () ->
331332
Type.builtin_term (Base.term_app2 (module Type) env s (T.addo ~signed:true))
332-
| Type.Id { ns = Term; name = Simple "bvuaddo"; } when atleast2_7 () ->
333+
| Type.Id { ns = Term; name = Simple "bvuaddo"; } when bitv2_7 () ->
333334
Type.builtin_term (Base.term_app2 (module Type) env s (T.addo ~signed:false))
334-
| Type.Id { ns = Term; name = Simple "bvssubo"; } when atleast2_7 () ->
335+
| Type.Id { ns = Term; name = Simple "bvssubo"; } when bitv2_7 () ->
335336
Type.builtin_term (Base.term_app2 (module Type) env s (T.subo ~signed:true))
336-
| Type.Id { ns = Term; name = Simple "bvusubo"; } when atleast2_7 () ->
337+
| Type.Id { ns = Term; name = Simple "bvusubo"; } when bitv2_7 () ->
337338
Type.builtin_term (Base.term_app2 (module Type) env s (T.subo ~signed:false))
338-
| Type.Id { ns = Term; name = Simple "bvsmulo"; } when atleast2_7 () ->
339+
| Type.Id { ns = Term; name = Simple "bvsmulo"; } when bitv2_7 () ->
339340
Type.builtin_term (Base.term_app2 (module Type) env s (T.mulo ~signed:true))
340-
| Type.Id { ns = Term; name = Simple "bvumulo"; } when atleast2_7 () ->
341+
| Type.Id { ns = Term; name = Simple "bvumulo"; } when bitv2_7 () ->
341342
Type.builtin_term (Base.term_app2 (module Type) env s (T.mulo ~signed:false))
342-
| Type.Id { ns = Term; name = Simple "bvsdivo"; } when atleast2_7 () ->
343+
| Type.Id { ns = Term; name = Simple "bvsdivo"; } when bitv2_7 () ->
343344
Type.builtin_term (Base.term_app2 (module Type) env s T.divo)
344345

345-
| Type.Id { ns = Term; name = Simple "ubv_to_int"; } when atleast2_7 () ->
346+
| Type.Id { ns = Term; name = Simple "ubv_to_int"; } when bitv2_7 () ->
346347
Type.builtin_term (Base.term_app1 (module Type) env s (T.to_int ~signed:false))
347-
| Type.Id { ns = Term; name = Simple "sbv_to_int"; } when atleast2_7 () ->
348+
| Type.Id { ns = Term; name = Simple "sbv_to_int"; } when bitv2_7 () ->
348349
Type.builtin_term (Base.term_app1 (module Type) env s (T.to_int ~signed:true))
349350

350351
(* indexed terms *)
351352
| Type.Id { ns = Term; name = Indexed { basename; indexes; } } as symbol ->
352353
Base.parse_indexed basename indexes (function
353354
| s when (String.length s >= 2 && s.[0] = 'b' && s.[1] = 'v') ->
354355
`Unary (fun n -> Type.builtin_term (parse_extended_lit env symbol s n))
355-
| "int_to_bv" when atleast2_7 () -> `Unary (function i_s ->
356+
| "int_to_bv" when bitv2_7 () -> `Unary (function i_s ->
356357
Type.builtin_term (Base.term_app1_ast (module Type) env symbol
357358
(indexed_positive env T.of_int i_s)))
358359
| "repeat" -> `Unary (function i_s ->

0 commit comments

Comments
 (0)