forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ml
138 lines (113 loc) · 4.48 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(**************************************************************************)
(* *)
(* Cubicle *)
(* *)
(* Copyright (C) 2011-2014 *)
(* *)
(* Sylvain Conchon and Alain Mebsout *)
(* Universite Paris-Sud 11 *)
(* *)
(* *)
(* This file is distributed under the terms of the Apache Software *)
(* License version 2.0 *)
(* *)
(**************************************************************************)
open Lexing
open Format
open Options
open Ast
(** Entry point of Cubicle *)
(** intercepts SIGINT [Ctrl-C] to display progress before exit *)
let () =
Sys.set_signal Sys.sigint
(Sys.Signal_handle
(fun _ ->
eprintf "@{<n>@}@."; (* Remove colors *)
Stats.print_report ~safe:false [] [];
eprintf "\n\n@{<b>@{<fg_red>ABORT !@}@} Received SIGINT@.";
exit 1))
let () =
Sys.set_signal Sys.sigterm
(Sys.Signal_handle
(fun _ ->
eprintf "@{<n>@}@."; (* Remove colors *)
Stats.print_report ~safe:false [] [];
eprintf "\n\n@{<b>@{<fg_red>ABORT !@}@} Received SIGTERM@.";
exit 1))
(** intercepts SIGUSR1 to display progress *)
let () =
try
Sys.set_signal Sys.sigusr1
(Sys.Signal_handle
(fun _ ->
eprintf "@{<n>@}@."; (* Remove colors *)
Stats.print_report ~safe:false [] []))
with Invalid_argument _ -> () (* doesn't exist on windows *)
(** Print backtrace even in native mode *)
let () =
if verbose > 0 then Printexc.record_backtrace true
let _ =
let lb = from_channel cin in
try
let s = Parser.system Lexer.token lb in
let system = Typing.system s in
if type_only then exit 0;
if refine_universal then
printf "@{<b>@{<fg_yellow>Warning@} !@}\nUniversal guards refinement \
is an experimental feature. Use at your own risks.\n@.";
let close_dot = Dot.open_dot () in
begin
match Brab.brab system with
| Bwd.Safe (visited, candidates) ->
if (not quiet || profiling) then
Stats.print_report ~safe:true visited candidates;
printf "\n\nThe system is @{<b>@{<fg_green>SAFE@}@}\n@.";
Trace.Selected.certificate system visited;
close_dot ();
exit 0
| Bwd.Unsafe (faulty, candidates) ->
if (not quiet || profiling) then
Stats.print_report ~safe:false [] candidates;
begin try
if not quiet then Stats.error_trace system faulty;
printf "\n\n@{<b>@{<bg_red>UNSAFE@} !@}\n@.";
with Exit -> ()
end;
close_dot ();
exit 1
end
with
| Lexer.Lexical_error s ->
Util.report_loc err_formatter (lexeme_start_p lb, lexeme_end_p lb);
eprintf "lexical error: %s@." s;
exit 2
| Parsing.Parse_error ->
let loc = (lexeme_start_p lb, lexeme_end_p lb) in
Util.report_loc err_formatter loc;
eprintf "syntax error@.";
exit 2
| Typing.Error (e,loc) ->
Util.report_loc err_formatter loc;
eprintf "typing error: %a@." Typing.report e;
exit 2
| Stats.ReachedLimit ->
if (not quiet || profiling) then Stats.print_report ~safe:false [] [];
eprintf "\n@{<b>@{<fg_yellow>Reached Limit@} !@}\n";
eprintf "It is likely that the search diverges, increase \
the limit to explore further.@.";
exit 1
| Failure str ->
let backtrace = Printexc.get_backtrace () in
eprintf "\n@{<u>Internal failure:@}%s@." str;
if verbose > 0 then eprintf "Backtrace:@\n%s@." backtrace;
exit 1
| Smt.Error e ->
let backtrace = Printexc.get_backtrace () in
eprintf "\n@{<u>Solver error:@}%a@." Smt.report e;
if verbose > 0 then eprintf "Backtrace:@\n%s@." backtrace;
exit 1
| e ->
let backtrace = Printexc.get_backtrace () in
eprintf "Fatal error: %s@." (Printexc.to_string e);
if verbose > 0 then eprintf "Backtrace:@\n%s@." backtrace;
exit 1