Skip to content

Commit 3d44069

Browse files
committed
WIP
1 parent 7b2d001 commit 3d44069

File tree

7 files changed

+104
-12
lines changed

7 files changed

+104
-12
lines changed

bug.ae

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type house = H1 | H2 | H3 | H4
2+
3+
logic h1, h2 : house
4+
5+
predicate leftof(h1: house, h2: house) =
6+
(h2 = H2 -> h1 <> H2 and h1 <> H3 and h1 <> H4) (* h1 = H1 *)
7+
and
8+
(h2 = H3 -> h1 <> H1 and h1 <> H3 and h1 <> H4) (* h1 = H2 *)
9+
and
10+
(h2 = H4 -> h1 <> H1 and h1 <> H2 and h1 <> H4) (* h1 = H3 *)
11+
and
12+
(h2 = H1 -> h1 <> H1 and h1 <> H2 and h1 <> H3) (* h1 = H4 *)
13+
14+
axiom clue : leftof(h1, h2)
15+
goal g : false

src/languages/smtlib2/v2.6/script/print.ml

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ let symbol_aux fmt s =
5757
| Unprintable ->
5858
_cannot_print "symbol \"%s\" cannot be printed due to lexical constraints" s
5959

60+
let index fmt s =
61+
if Misc.lex_string Lexer.check_num s then
62+
Format.pp_print_string fmt s
63+
else
64+
symbol_aux fmt s
65+
66+
6067
let symbol fmt name =
6168
match (name : Dolmen_std.Name.t) with
6269
| Simple s ->
@@ -66,7 +73,7 @@ let symbol fmt name =
6673
| Indexed { basename; indexes; } ->
6774
let pp_sep fmt () = Format.fprintf fmt " " in
6875
Format.fprintf fmt "(_ %a %a)"
69-
symbol_aux basename (Format.pp_print_list ~pp_sep symbol_aux) indexes
76+
symbol_aux basename (Format.pp_print_list ~pp_sep index) indexes
7077
| Qualified _ ->
7178
_cannot_print "qualified identifier: %a" Dolmen_std.Name.print name
7279

@@ -410,6 +417,7 @@ module Make
410417
in
411418

412419
(* small shorthand *)
420+
let int = string_of_int in
413421
let p ?omit_to_real ns name =
414422
aux ?omit_to_real (Dolmen_std.Id.create ns name) args
415423
in
@@ -504,7 +512,7 @@ module Make
504512
end
505513

506514
(* Bitvectors *)
507-
| B.Bitvec s -> p (Value Binary) (N.simple s) (* TODO: see if we can recover hex form ? *)
515+
| B.Bitvec s -> p (Value Binary) (N.simple ("#b" ^ s)) (* TODO: see if we can recover hex form ? *)
508516
| B.Bitv_not _ -> simple "bvnot"
509517
| B.Bitv_and _ -> simple "bvand"
510518
| B.Bitv_or _ -> simple "bvor"
@@ -528,6 +536,66 @@ module Make
528536
| B.Bitv_ugt _ -> simple "bvugt"
529537
| B.Bitv_uge _ -> simple "bvuge"
530538
| B.Bitv_slt _ -> simple "bvslt"
539+
| B.Bitv_sle _ -> simple "bvsle"
540+
| B.Bitv_sgt _ -> simple "bvsgt"
541+
| B.Bitv_sge _ -> simple "bvsge"
542+
| B.Bitv_concat _ -> simple "concat"
543+
| B.Bitv_repeat { n = _; k; } -> p Term (N.indexed "repeat" [int k])
544+
| B.Bitv_zero_extend { n = _; k; } -> p Term (N.indexed "zero_extend" [int k])
545+
| B.Bitv_sign_extend { n = _; k; } -> p Term (N.indexed "sign_extend" [int k])
546+
| B.Bitv_rotate_right { n = _; i; } -> p Term (N.indexed "rotate_right" [int i])
547+
| B.Bitv_rotate_left { n = _; i; } -> p Term (N.indexed "rotate_left" [int i])
548+
| B.Bitv_extract { n = _; i; j; } -> p Term (N.indexed "extract" [int i; int j])
549+
550+
(* bvconv extension
551+
TODO: use a flag to enable extensions such as this one ? *)
552+
| B.Bitv_to_nat { n = _; } -> simple "bv2nat"
553+
| B.Bitv_of_int { n } -> p Term (N.indexed "int2bv" [int n])
554+
555+
(* Floats *)
556+
| B.Fp _ -> simple "fp"
557+
| B.RoundNearestTiesToEven -> simple "RNE"
558+
| B.RoundNearestTiesToAway -> simple "RNA"
559+
| B.RoundTowardPositive -> simple "RTP"
560+
| B.RoundTowardNegative -> simple "RTN"
561+
| B.RoundTowardZero -> simple "RTZ"
562+
| B.Fp_abs _ -> simple "fp.abs"
563+
| B.Fp_neg _ -> simple "fp.neg"
564+
| B.Fp_add _ -> simple "fp.add"
565+
| B.Fp_sub _ -> simple "fp.sub"
566+
| B.Fp_mul _ -> simple "fp.mul"
567+
| B.Fp_div _ -> simple "fp.div"
568+
| B.Fp_fma _ -> simple "fp.fma"
569+
| B.Fp_sqrt _ -> simple "fp.sqrt"
570+
| B.Fp_rem _ -> simple "fp.rem"
571+
| B.Fp_roundToIntegral _ -> simple "fp.roundToInegral"
572+
| B.Fp_min _ -> simple "fp.min"
573+
| B.Fp_max _ -> simple "fp.max"
574+
| B.Fp_leq _ -> simple "fp.leq"
575+
| B.Fp_lt _ -> simple "fp.lt"
576+
| B.Fp_geq _ -> simple "fp.geq"
577+
| B.Fp_gt _ -> simple "fp.gt"
578+
| B.Fp_eq _ -> simple "fp.eq"
579+
| B.Fp_isNormal _ -> simple "fp.isNormal"
580+
| B.Fp_isSubnormal _ -> simple "fp.isSubnormal"
581+
| B.Fp_isZero _ -> simple "fp.isZero"
582+
| B.Fp_isInfinite _ -> simple "fp.isInfinite"
583+
| B.Fp_isNaN _ -> simple "fp.isNan"
584+
| B.Fp_isNegative _ -> simple "fp.isNegative"
585+
| B.Fp_isPositive _ -> simple "fp.isPositive"
586+
| B.To_real _ -> simple "fp.to_real"
587+
| B.Plus_infinity (e, s) -> p Term (N.indexed "+oo" [int e; int s])
588+
| B.Minus_infinity (e, s) -> p Term (N.indexed "-oo" [int e; int s])
589+
| B.Plus_zero (e, s) -> p Term (N.indexed "+zero" [int e; int s])
590+
| B.Minus_zero (e, s) -> p Term (N.indexed "-zero" [int e; int s])
591+
| B.NaN (e, s) -> p Term (N.indexed "NaN" [int e; int s])
592+
| B.Ieee_format_to_fp (e, s) -> p Term (N.indexed "to_fp" [int e; int s])
593+
| B.Fp_to_fp (_, _, e, s) -> p Term (N.indexed "to_fp" [int e; int s])
594+
| B.Real_to_fp (e, s) -> p Term (N.indexed "to_fp" [int e; int s])
595+
| B.Sbv_to_fp (_, e, s) -> p Term (N.indexed "to_fp" [int e; int s])
596+
| B.Ubv_to_fp (_, e, s) -> p Term (N.indexed "to_fp_unsigned" [int e; int s])
597+
| B.To_ubv (_, _, m) -> p Term (N.indexed "fp.to_ubv" [int m])
598+
| B.To_sbv (_, _, m) -> p Term (N.indexed "fp.to_sbv" [int m])
531599

532600
(* fallback *)
533601
| _ -> _cannot_print "unknown term builtin"
@@ -624,7 +692,7 @@ module Make
624692
let datatype_dec env fmt (_, vars, cases) =
625693
match vars with
626694
| [] ->
627-
Format.fprintf fmt "@[<v 1>(%a)@]" (list constructor_dec env) cases
695+
Format.fprintf fmt "@[<hv 1>(%a)@]" (list constructor_dec env) cases
628696
| _ ->
629697
let env = List.fold_left Env.Ty_var.bind env vars in
630698
Format.fprintf fmt "(par (%a)@ @[<v 1>(%a))@]"
@@ -720,7 +788,7 @@ module Make
720788
Format.fprintf fmt "(declare-sort %a %d)" (symbol env) name n
721789

722790
let declare_datatype env fmt ((c, _, _) as dec) =
723-
Format.fprintf fmt "@[<hov 2>(declare-datatype %a@ %a)@]"
791+
Format.fprintf fmt "@[<hv 2>(declare-datatype %a@ %a)@]"
724792
(ty_cst env) c
725793
(datatype_dec env) dec
726794

@@ -758,7 +826,7 @@ module Make
758826

759827
let define_fun_aux ~recursive env fmt (f, params, body) =
760828
let env = List.fold_left Env.Term_var.bind env params in
761-
Format.fprintf fmt "@[<hv 2>(@[<hov 1>%s %a@ (%a) %a@]@ %a)@]"
829+
Format.fprintf fmt "@[<hv 2>(@[<hov 1>%s %a@ (%a) %a@]@ @[<hov>%a@])@]"
762830
(if recursive then "define-fun-rec" else "define-fun")
763831
(term_cst env) f
764832
(list sorted_var env) params

src/loop/export.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,19 @@ module Smtlib2_6
290290
let simples, adts = List.partition_map map_decl l in
291291
let env =
292292
match simples, adts, recursive with
293-
| [], l, true ->
293+
| [], l, _ ->
294+
(* slight over-approximation: we always treat all adts as recursive *)
294295
let env = List.fold_left register_adt_decl env l in
295296
Format.fprintf fmt "%a@." (P.declare_datatypes env) l;
296297
env
297-
| l, [], false ->
298+
| l, [], _ ->
299+
(* declarations for smtlib cannot be recursive:
300+
- type declarations's bodies are just integers
301+
- term declarations's bodies are types (and thus the term
302+
constant begin declared cannot appear in them).
303+
Therefore, it should be fine to ignore the recursive flag.
304+
For the future, it might be better to adjust the flag to
305+
represent whether things are actually recursive. *)
298306
let env = List.fold_left register_simple_decl env l in
299307
List.iter (print_simple_decl env fmt) l;
300308
env

src/loop/headers.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ module Field = struct
118118
| { Id.ns = Attr; Id.name = Simple ":source"; } ->
119119
begin match args with
120120
| [ { Ast.term = Ast.Symbol {
121-
Id.ns = Attr; Id.name = Simple descr }; _ } ] ->
121+
Id.ns = (Attr | Term | Value String);
122+
Id.name = Simple descr }; _ } ] ->
122123
Ok (Problem_source, descr)
123124
| [] -> Error (loc, "empty value for :source")
124125
| { Ast.loc; _ } :: _ -> Error (loc, "Expected a single symbol as description")

src/standard/id.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let equal id id' =
2929
let print fmt { name; ns; } =
3030
match ns with
3131
| Value String -> Format.fprintf fmt {|"%a"|} Name.print name
32-
| Attr -> Format.fprintf fmt "a:%a" Name.print name
32+
| Attr -> Format.fprintf fmt "%a" Name.print name
3333
| _ -> Name.print fmt name
3434

3535

src/standard/statement.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ let rec print_descr fmt = function
329329

330330
and print_id_opt fmt = function
331331
| None -> ()
332-
| Some id -> Format.fprintf fmt "%a@," Id.print id
332+
| Some id -> Format.fprintf fmt "%a :@ " Id.print id
333333

334334
and print fmt = function { id; descr; attrs; _ } ->
335335
Format.fprintf fmt "@[<hv>%a%a%a@]" print_id_opt id print_attrs attrs print_descr descr

tests/qcheck/print.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let identifier
4949
let smtlib2_id =
5050
identifier
5151
~language:(Smtlib2 `V2_6)
52-
~print:Dolmen.Smtlib2.Script.V2_6.Print.id
52+
~print:Dolmen.Smtlib2.Script.V2_6.Print.symbol
5353
~gen:(Generators.name ~printable:false
5454
~simple:true ~indexed:true ~qualified:true)
5555
~template:{|(assert %a)|}
@@ -64,7 +64,7 @@ let smtlib2_id =
6464
let smtlib2_id_printable =
6565
identifier
6666
~language:(Smtlib2 `V2_6)
67-
~print:Dolmen.Smtlib2.Script.V2_6.Print.id
67+
~print:Dolmen.Smtlib2.Script.V2_6.Print.symbol
6868
~gen:(Generators.name ~printable:true
6969
~simple:true ~indexed:true ~qualified:false)
7070
~template:{|(assert %a)|}

0 commit comments

Comments
 (0)