-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathsvcompSpec.ml
99 lines (90 loc) · 2.87 KB
/
svcompSpec.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(** SV-COMP specification strings and files. *)
open Batteries
type t =
| UnreachCall of string
| NoDataRace
| NoOverflow
| Termination
| ValidFree
| ValidDeref
| ValidMemtrack
| ValidMemcleanup
type multi = t list
let of_string s =
let s = String.strip s in
let regexp_single = Str.regexp "CHECK( init(main()), LTL(G \\(.*\\)) )" in
let regexp_negated = Str.regexp "CHECK( init(main()), LTL(G ! \\(.*\\)) )" in
let regexp_finally = Str.regexp "CHECK( init(main()), LTL(F \\(.*\\)) )" in
if Str.string_match regexp_negated s 0 then (
match Str.matched_group 1 s with
| "data-race" -> NoDataRace
| "overflow" -> NoOverflow
| global_not ->
let call_regex = Str.regexp "call(\\(.*\\)())" in
if Str.string_match call_regex global_not 0 then
let f = Str.matched_group 1 global_not in
UnreachCall f
else
failwith "Svcomp.Specification.of_string: unknown global not expression"
)
else if Str.string_match regexp_single s 0 then (
match Str.matched_group 1 s with
| "valid-free" -> ValidFree
| "valid-deref" -> ValidDeref
| "valid-memtrack" -> ValidMemtrack
| "valid-memcleanup" -> ValidMemcleanup
| _ -> failwith "Svcomp.Specification.of_string: unknown global expression"
)
else if Str.string_match regexp_finally s 0 then (
match Str.matched_group 1 s with
| "end" -> Termination
| _ -> failwith "Svcomp.Specification.of_string: unknown finally expression"
)
else
failwith "Svcomp.Specification.of_string: unknown expression"
let of_string s: multi =
List.filter_map (fun line ->
let line = String.strip line in
if line = "" then
None
else
Some (of_string line)
) (String.split_on_char '\n' s)
let of_file path =
let s = BatFile.with_file_in path BatIO.read_all in
of_string s
let of_option () =
let s = GobConfig.get_string "ana.specification" in
if Sys.file_exists s then
of_file s
else
of_string s
let to_string spec =
let module Prop = struct
type prop = F | G
let string_of_prop = function
| F -> "F"
| G -> "G"
end
in
let open Prop in
let print_output prop spec_str is_neg =
let prop = string_of_prop prop in
if is_neg then
Printf.sprintf "CHECK( init(main()), LTL(%s ! %s) )" prop spec_str
else
Printf.sprintf "CHECK( init(main()), LTL(%s %s) )" prop spec_str
in
let prop, spec_str, is_neg = match spec with
| UnreachCall f -> G, "call(" ^ f ^ "())", true
| NoDataRace -> G, "data-race", true
| NoOverflow -> G, "overflow", true
| ValidFree -> G, "valid-free", false
| ValidDeref -> G, "valid-deref", false
| ValidMemtrack -> G, "valid-memtrack", false
| ValidMemcleanup -> G, "valid-memcleanup", false
| Termination -> F, "end", false
in
print_output prop spec_str is_neg
let to_string spec =
String.concat "\n" (List.map to_string spec)