Project

General

Profile

Download (7.34 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
(*
3
TODO
4

    
5
A property/contract is attached to a node foo and could be analyzed
6
- while considering the exact semantics
7
- while substituting some callee by their definition (doing it incrementaly ?)
8
- the returned cex could be given at node level
9
- or while considering a main node and producing the output at the main node level
10

    
11
One can consider the following algorithm:
12
- main node foo, local node bar, with a target property/contract
13
- declare bar using only the contract of its subnodes (callee)
14
- if the property is valid, 
15
  - check the validity status of the subnode contracts used
16
    - if one is not proved, perform the analysis again (of bar contract) using
17
      the actual definition of the unproven contract
18
  - return the computed invariants with the dependencies (subcontracts assumed, subcontracts proved)
19
- if the property is invalid
20
  - check invalidity wrt to full definition of the node bar (with the actual definition of its subnodes)
21
  - return the cex
22
  - try to see if the cex (or a similar violation of the contract) is reachable from its parents 
23
    (up to main node foo)
24
    
25

    
26
Other features:
27
- check equivalence btw two nodes, provided an equivalence map on some callee
28
  (A equiv B) with map (A id equiv B id) 
29
  - substitute each callee appearing B nodes 
30

    
31
Analysis:
32
  - take a main definition, a boolean proposition, and build the collecting semantics
33
  - then check that the proposition remains valid
34

    
35
*)
36

    
37

    
38
open Zustre_common
39
open Zustre_data
40

    
41
let param_stat = ref false
42
let param_eldarica = ref false
43
let param_utvpi = ref false
44
let param_tosmt = ref false
45
let param_pp = ref false
46

    
47
let active = ref false
48

    
49
module Verifier =
50
  (struct
51
    include VerifierType.Default
52
    let name = "zustre"
53
    let options = [
54
        "-stat", Arg.Set param_stat, "print statistics";
55
        "-eldarica", Arg.Set param_eldarica, "deactivate fixedpoint extensions when printing rules";
56
        "-no_utvpi", Arg.Set param_utvpi, "Deactivate UTVPI strategy";
57
        "-tosmt", Arg.Set param_tosmt, "Print low-level (possibly unreadable) SMT2 statements";
58
        "-no-pp", Arg.Set param_pp, "No preprocessing (inlining and slicing)";
59
      ]
60
                
61
    let activate () = (
62
        active := true;
63
        Options.output := "horn";
64
      )
65
    let is_active () = !active
66

    
67
    let get_normalization_params () =
68
      (* make sure the output is "Horn" *)
69
      assert(!Options.output = "horn");
70
      Backends.get_normalization_params ()
71

    
72
    let setup_solver () =
73
      fp := Z3.Fixedpoint.mk_fixedpoint !ctx;
74
      (* let help = Z3.Fixedpoint.get_help fp in
75
       * Format.eprintf "Fp help : %s@." help;
76
       * 
77
       * let solver =Z3.Solver.mk_solver !ctx None in
78
       * let help = Z3.Solver.get_help solver in
79
       * Format.eprintf "Z3 help : %s@." help; *)
80
      
81
      let module P = Z3.Params in
82
      let module S = Z3.Symbol in
83
      let mks = S.mk_string !ctx in
84
      let params = P.mk_params !ctx in
85

    
86
      (* (\* self.fp.set (engine='spacer') *\) *)
87
      P.add_symbol params (mks "engine") (mks "spacer");
88
      (* P.add_symbol params (mks "engine") (mks "pdr");  *)
89
      
90
       (* #z3.set_option(rational_to_decimal=True) *)
91
       (* #self.fp.set('precision',30) *)
92
      if !param_stat then 
93
        (* self.fp.set('print_statistics',True) *)
94
        P.add_bool params (mks "print_statistics") true;
95

    
96
      (* Dont know where to find this parameter *)
97
      (* if !param_spacer_verbose then
98
         *   if self.args.spacer_verbose: 
99
         *        z3.set_option (verbose=1) *)
100

    
101
      (* The option is not recogined*)
102
      (* self.fp.set('use_heavy_mev',True) *)
103
      (* P.add_bool params (mks "use_heavy_mev") true; *)
104
      
105
      (* self.fp.set('pdr.flexible_trace',True) *)
106
      P.add_bool params (mks "pdr.flexible_trace") true;
107

    
108
      (* self.fp.set('reset_obligation_queue',False) *)
109
      P.add_bool params (mks "spacer.reset_obligation_queue") false;
110

    
111
      (* self.fp.set('spacer.elim_aux',False) *)
112
      P.add_bool params (mks "spacer.elim_aux") false;
113

    
114
      (* if self.args.eldarica:
115
        *     self.fp.set('print_fixedpoint_extensions', False) *)
116
      if !param_eldarica then
117
        P.add_bool params (mks "print_fixedpoint_extensions") false;
118
      
119
      (* if self.args.utvpi: self.fp.set('pdr.utvpi', False) *)
120
      if !param_utvpi then
121
        P.add_bool params (mks "pdr.utvpi") false;
122

    
123
      (* if self.args.tosmt:
124
       *        self.log.info("Setting low level printing")
125
       *        self.fp.set ('print.low_level_smt2',True) *)
126
      if !param_tosmt then
127
        P.add_bool params (mks "print.low_level_smt2") true;
128

    
129
      (* if not self.args.pp:
130
       *        self.log.info("No pre-processing")
131
       *        self.fp.set ('xform.slice', False)
132
       *        self.fp.set ('xform.inline_linear',False)
133
       *        self.fp.set ('xform.inline_eager',False) *\) *)
134
      if !param_pp then (
135
        P.add_bool params (mks "xform.slice") false;
136
        P.add_bool params (mks "xform.inline_linear") false;
137
        P.add_bool params (mks "xform.inline_eager") false
138
      );
139
      Z3.Fixedpoint.set_parameters !fp params
140
              
141
      
142
    let run basename prog machines =
143
      let machines = Machine_code_common.arrow_machine::machines in
144
      let machines = preprocess machines in
145
      setup_solver ();
146

    
147

    
148
      (* TODO
149
	 load deps: cf print_dep in horn_backend.ml
150

    
151
      *)
152
      if false then (
153
	
154
	let queries = Z3.Fixedpoint.parse_file !fp "mini.smt2" in
155

    
156
	(* Debug instructions *)
157
	
158

    
159
	
160
	let rules_expr = Z3.Fixedpoint.get_rules !fp in
161
	Format.eprintf "@[<v 2>Registered rules:@ %a@ @]@."
162
      	  (Utils.fprintf_list ~sep:"@ "
163
      	     (fun fmt e ->
164
	       (* let e2 = Z3.Quantifier.get_body eq in *)
165
	       (* let fd = Z3.Expr.get_func_decl e in *)
166
	       Format.fprintf fmt "Rule: %s@."
167
		 (Z3.Expr.to_string e);
168
	     )) rules_expr;
169
	
170
	let _ = List.map extract_expr_fds rules_expr in
171
	Format.eprintf "%t" pp_fdecls;
172
	
173
      	let res_status = Z3.Fixedpoint.query !fp (List.hd queries )in
174
	
175
	Format.eprintf "Status: %s@." (Z3.Solver.string_of_status res_status)
176
      )
177
      else if false then (
178

    
179
	(* No queries here *)
180
	let _ = Z3.Fixedpoint.parse_file !fp "mini_decl.smt2" in
181

    
182
	(* Debug instructions *)
183
	
184

    
185
	
186
	let rules_expr = Z3.Fixedpoint.get_rules !fp in
187
	Format.eprintf "@[<v 2>Registered rules:@ %a@ @]@."
188
      	  (Utils.fprintf_list ~sep:"@ "
189
      	     (fun fmt e ->
190
	       (* let e2 = Z3.Quantifier.get_body eq in *)
191
	       (* let fd = Z3.Expr.get_func_decl e in *)
192
	       Format.fprintf fmt "Rule: %s@."
193
		 (Z3.Expr.to_string e);
194
	     )) rules_expr;
195
	
196
	let _ = List.map extract_expr_fds rules_expr in
197
	Format.eprintf "%t" pp_fdecls;
198

    
199
	if !Options.main_node <> "" then
200
      	  begin
201
      	    Zustre_analyze.check machines !Options.main_node
202

    
203
      	  end
204
	else
205
      	  failwith "Require main node";
206

    
207
	()	
208
      )
209
      else (
210
	
211
	
212
	decl_sorts ();
213
	
214
	List.iter (decl_machine machines) (List.rev machines);
215

    
216

    
217
	(* (\* Debug instructions *\) *)
218
	(* let rules_expr = Z3.Fixedpoint.get_rules !fp in *)
219
	(* Format.eprintf "@[<v 2>Registered rules:@ %a@ @]@." *)
220
	(* 	(Utils.fprintf_list ~sep:"@ " *)
221
	(* 	   (fun fmt e -> Format.pp_print_string fmt (Z3.Expr.to_string e)) ) *)
222
	(* 	rules_expr; *)
223

    
224
	if !Options.main_node <> "" then
225
      	  begin
226
      	    Zustre_analyze.check machines !Options.main_node
227

    
228
      	  end
229
	else
230
      	  failwith "Require main node";
231
	
232
	()
233
      )
234
	
235

    
236
	    end: VerifierType.S)
237
    
238
(* Local Variables: *)
239
(* compile-command:"make -C ../.." *)
240
(* End: *)
(5-5/5)