Revision 1b57e111
Added by Teme Kahsai almost 8 years ago
autom4te.cache/requests | ||
---|---|---|
14 | 14 |
'configure.ac' |
15 | 15 |
], |
16 | 16 |
{ |
17 |
'AM_PROG_MOC' => 1, |
|
18 |
'AM_XGETTEXT_OPTION' => 1, |
|
19 |
'AC_CANONICAL_BUILD' => 1, |
|
20 |
'm4_sinclude' => 1, |
|
21 |
'AM_PROG_CC_C_O' => 1, |
|
17 |
'AM_AUTOMAKE_VERSION' => 1, |
|
22 | 18 |
'_AM_MAKEFILE_INCLUDE' => 1, |
19 |
'm4_pattern_forbid' => 1, |
|
20 |
'AC_LIBSOURCE' => 1, |
|
23 | 21 |
'AM_PROG_F77_C_O' => 1, |
24 |
'm4_include' => 1, |
|
22 |
'AC_CANONICAL_HOST' => 1, |
|
23 |
'AC_CONFIG_HEADERS' => 1, |
|
24 |
'AC_FC_PP_DEFINE' => 1, |
|
25 |
'AC_SUBST' => 1, |
|
26 |
'_AM_COND_ELSE' => 1, |
|
25 | 27 |
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, |
26 |
'_AM_COND_IF' => 1, |
|
27 |
'_LT_AC_TAGCONFIG' => 1, |
|
28 |
'AM_PROG_AR' => 1, |
|
29 |
'AM_CONDITIONAL' => 1, |
|
30 |
'AM_MAINTAINER_MODE' => 1, |
|
31 | 28 |
'LT_INIT' => 1, |
32 |
'_AM_COND_ELSE' => 1, |
|
33 |
'AC_CONFIG_LIBOBJ_DIR' => 1, |
|
34 |
'_AM_COND_ENDIF' => 1, |
|
35 |
'AM_SILENT_RULES' => 1, |
|
36 |
'AM_PROG_CXX_C_O' => 1, |
|
37 |
'AC_INIT' => 1, |
|
29 |
'AC_PROG_LIBTOOL' => 1, |
|
30 |
'm4_include' => 1, |
|
31 |
'AM_PROG_CC_C_O' => 1, |
|
32 |
'_LT_AC_TAGCONFIG' => 1, |
|
38 | 33 |
'AC_CONFIG_FILES' => 1, |
39 |
'AM_NLS' => 1, |
|
40 |
'AC_CANONICAL_TARGET' => 1, |
|
41 |
'AC_CANONICAL_HOST' => 1, |
|
42 |
'm4_pattern_allow' => 1, |
|
43 |
'AM_GNU_GETTEXT' => 1, |
|
44 |
'AC_FC_PP_SRCEXT' => 1, |
|
34 |
'AC_CANONICAL_BUILD' => 1, |
|
35 |
'AM_MAINTAINER_MODE' => 1, |
|
45 | 36 |
'AC_FC_FREEFORM' => 1, |
46 |
'AC_FC_PP_DEFINE' => 1, |
|
47 |
'LT_SUPPORTED_TAG' => 1, |
|
48 |
'AM_PATH_GUILE' => 1, |
|
49 |
'AM_ENABLE_MULTILIB' => 1, |
|
50 |
'AM_POT_TOOLS' => 1, |
|
51 |
'sinclude' => 1, |
|
52 |
'AC_DEFINE_TRACE_LITERAL' => 1, |
|
53 |
'm4_pattern_forbid' => 1, |
|
54 |
'AC_CONFIG_HEADERS' => 1, |
|
55 |
'AC_REQUIRE_AUX_FILE' => 1, |
|
37 |
'm4_pattern_allow' => 1, |
|
38 |
'AM_PROG_MOC' => 1, |
|
56 | 39 |
'AC_CONFIG_LINKS' => 1, |
57 |
'AC_SUBST_TRACE' => 1,
|
|
58 |
'AC_LIBSOURCE' => 1,
|
|
59 |
'AC_PROG_LIBTOOL' => 1,
|
|
40 |
'_AM_COND_IF' => 1,
|
|
41 |
'AM_NLS' => 1,
|
|
42 |
'AC_INIT' => 1,
|
|
60 | 43 |
'AC_FC_SRCEXT' => 1, |
61 |
'AM_AUTOMAKE_VERSION' => 1, |
|
62 |
'LT_CONFIG_LTDL_DIR' => 1, |
|
44 |
'_m4_warn' => 1, |
|
45 |
'AM_PATH_GUILE' => 1, |
|
46 |
'AC_DEFINE_TRACE_LITERAL' => 1, |
|
63 | 47 |
'AM_MAKEFILE_INCLUDE' => 1, |
64 |
'include' => 1, |
|
48 |
'sinclude' => 1, |
|
49 |
'LT_CONFIG_LTDL_DIR' => 1, |
|
65 | 50 |
'AM_INIT_AUTOMAKE' => 1, |
51 |
'AM_GNU_GETTEXT' => 1, |
|
52 |
'AC_REQUIRE_AUX_FILE' => 1, |
|
66 | 53 |
'AC_CANONICAL_SYSTEM' => 1, |
67 |
'_AM_SUBST_NOTMAKE' => 1, |
|
68 |
'AC_SUBST' => 1, |
|
69 |
'AC_CONFIG_SUBDIRS' => 1, |
|
54 |
'AM_PROG_CXX_C_O' => 1, |
|
70 | 55 |
'AH_OUTPUT' => 1, |
56 |
'include' => 1, |
|
57 |
'AM_ENABLE_MULTILIB' => 1, |
|
58 |
'm4_sinclude' => 1, |
|
59 |
'AM_XGETTEXT_OPTION' => 1, |
|
60 |
'_AM_COND_ENDIF' => 1, |
|
61 |
'AM_PROG_FC_C_O' => 1, |
|
71 | 62 |
'AC_CONFIG_AUX_DIR' => 1, |
72 |
'_m4_warn' => 1, |
|
73 |
'AM_PROG_FC_C_O' => 1 |
|
63 |
'AM_POT_TOOLS' => 1, |
|
64 |
'AC_CONFIG_LIBOBJ_DIR' => 1, |
|
65 |
'AC_SUBST_TRACE' => 1, |
|
66 |
'AC_CANONICAL_TARGET' => 1, |
|
67 |
'AC_CONFIG_SUBDIRS' => 1, |
|
68 |
'AM_PROG_AR' => 1, |
|
69 |
'LT_SUPPORTED_TAG' => 1, |
|
70 |
'AM_CONDITIONAL' => 1, |
|
71 |
'_AM_SUBST_NOTMAKE' => 1, |
|
72 |
'AM_SILENT_RULES' => 1, |
|
73 |
'AC_FC_PP_SRCEXT' => 1 |
|
74 | 74 |
} |
75 | 75 |
], 'Autom4te::Request' ) |
76 | 76 |
); |
src/backends/Horn/horn_backend.ml | ||
---|---|---|
93 | 93 |
) |
94 | 94 |
dependencies |
95 | 95 |
|
96 |
let check_sfunction mannot = |
|
97 |
(*Check if its an sfunction*) |
|
98 |
match mannot with |
|
99 |
[] -> false |
|
100 |
| [x] -> match x.annots with |
|
101 |
[] -> false |
|
102 |
|[(key,va)] -> match key with |
|
103 |
[] -> false |
|
104 |
| ["c_code"] -> true |
|
105 |
| ["matlab"] -> true |
|
106 |
| _ -> false |
|
107 |
| _ -> false |
|
108 |
|
|
96 | 109 |
let translate fmt basename prog machines= |
97 | 110 |
(* We print typedef *) |
98 |
print_dep fmt prog; |
|
111 |
print_dep fmt prog; (*print static library e.g. math*)
|
|
99 | 112 |
print_type_definitions fmt; |
100 |
List.iter (print_machine machines fmt) (List.rev machines); |
|
113 |
(*List.iter (print_machine machines fmt) (List.rev machines);*) |
|
114 |
List.iter(fun m -> |
|
115 |
let is_sfunction = check_sfunction m.mannot in |
|
116 |
if is_sfunction then( |
|
117 |
Log.report ~level:1 (fun fmt -> fprintf fmt ".. detected sfunction: %s@," m.mname.node_id); |
|
118 |
print_sfunction machines fmt m |
|
119 |
) else ( |
|
120 |
print_machine machines fmt m) |
|
121 |
) |
|
122 |
(List.rev machines); |
|
101 | 123 |
main_print machines fmt |
102 | 124 |
|
103 | 125 |
(* Local Variables: *) |
src/backends/Horn/horn_backend_printers.ml | ||
---|---|---|
79 | 79 |
*) |
80 | 80 |
let pp_assign m pp_var fmt var_name value = |
81 | 81 |
let self = m.mname.node_id in |
82 |
fprintf fmt "(= %a %a)"
|
|
82 |
fprintf fmt "(= %a %a)" |
|
83 | 83 |
(pp_horn_val ~is_lhs:true self pp_var) var_name |
84 | 84 |
(pp_value_suffix self pp_var) value |
85 |
|
|
85 |
|
|
86 | 86 |
|
87 | 87 |
(* In case of no reset call, we define mid_mem = current_mem *) |
88 | 88 |
let pp_no_reset machines m fmt i = |
89 | 89 |
let (n,_) = List.assoc i m.minstances in |
90 | 90 |
let target_machine = List.find (fun m -> m.mname.node_id = (node_name n)) machines in |
91 | 91 |
|
92 |
let m_list =
|
|
92 |
let m_list = |
|
93 | 93 |
rename_machine_list |
94 | 94 |
(concat m.mname.node_id i) |
95 | 95 |
(rename_mid_list (full_memory_vars machines target_machine)) |
... | ... | |
104 | 104 |
fprintf fmt "(= %a %a)" |
105 | 105 |
(pp_horn_var m) mhd |
106 | 106 |
(pp_horn_var m) chd |
107 |
|
|
107 |
|
|
108 | 108 |
| _ -> ( |
109 | 109 |
fprintf fmt "@[<v 0>(and @[<v 0>"; |
110 |
List.iter2 (fun mhd chd ->
|
|
110 |
List.iter2 (fun mhd chd -> |
|
111 | 111 |
fprintf fmt "(= %a %a)@ " |
112 | 112 |
(pp_horn_var m) mhd |
113 | 113 |
(pp_horn_var m) chd |
... | ... | |
120 | 120 |
let pp_instance_reset machines m fmt i = |
121 | 121 |
let (n,_) = List.assoc i m.minstances in |
122 | 122 |
let target_machine = List.find (fun m -> m.mname.node_id = (node_name n)) machines in |
123 |
|
|
123 |
|
|
124 | 124 |
fprintf fmt "(%a @[<v 0>%a)@]" |
125 | 125 |
pp_machine_reset_name (node_name n) |
126 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m))
|
|
126 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) |
|
127 | 127 |
( |
128 | 128 |
(rename_machine_list |
129 | 129 |
(concat m.mname.node_id i) |
130 | 130 |
(rename_current_list (full_memory_vars machines target_machine)) |
131 |
)
|
|
131 |
) |
|
132 | 132 |
@ |
133 | 133 |
(rename_machine_list |
134 | 134 |
(concat m.mname.node_id i) |
... | ... | |
146 | 146 |
if not (List.mem i reset_instances) then |
147 | 147 |
(* If not, declare mem_m = mem_c *) |
148 | 148 |
pp_no_reset machines m fmt i; |
149 |
|
|
149 |
|
|
150 | 150 |
let mems = full_memory_vars machines target_machine in |
151 | 151 |
let rename_mems f = rename_machine_list (concat m.mname.node_id i) (f mems) in |
152 | 152 |
let mid_mems = rename_mems rename_mid_list in |
... | ... | |
157 | 157 |
fprintf fmt "@[<v 5>(and "; |
158 | 158 |
fprintf fmt "(= %a (ite %a %a %a))" |
159 | 159 |
(pp_horn_val ~is_lhs:true self (pp_horn_var m)) (mk_val (LocalVar o) o.var_type) (* output var *) |
160 |
(pp_horn_var m) mem_m
|
|
160 |
(pp_horn_var m) mem_m |
|
161 | 161 |
(pp_horn_val self (pp_horn_var m)) i1 |
162 | 162 |
(pp_horn_val self (pp_horn_var m)) i2 |
163 | 163 |
; |
... | ... | |
175 | 175 |
(List.map (fun v -> mk_val (LocalVar v) v.var_type) outputs) |
176 | 176 |
(Utils.pp_final_char_if_non_empty "@ " outputs) |
177 | 177 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) (mid_mems@next_mems) |
178 |
|
|
178 |
|
|
179 | 179 |
end |
180 | 180 |
end |
181 | 181 |
with Not_found -> ( (* stateless node instance *) |
... | ... | |
188 | 188 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_val self (pp_horn_var m))) |
189 | 189 |
(List.map (fun v -> mk_val (LocalVar v) v.var_type) outputs) |
190 | 190 |
) |
191 |
|
|
192 |
|
|
191 |
|
|
192 |
|
|
193 | 193 |
(* Print the instruction and update the set of reset instances *) |
194 | 194 |
let rec pp_machine_instr machines reset_instances (m: machine_t) fmt instr : ident list = |
195 | 195 |
match instr with |
... | ... | |
230 | 230 |
statement. *) |
231 | 231 |
let self = m.mname.node_id in |
232 | 232 |
let pp_branch fmt (tag, instrs) = |
233 |
fprintf fmt
|
|
234 |
"@[<v 3>(or (not (= %a %s))@ "
|
|
233 |
fprintf fmt |
|
234 |
"@[<v 3>(or (not (= %a %s))@ " |
|
235 | 235 |
(*"@[<v 3>(=> (= %a %s)@ "*) (* Issues with some versions of Z3. It |
236 | 236 |
seems that => within Horn predicate |
237 | 237 |
may cause trouble. I have hard time |
... | ... | |
244 | 244 |
() (* rs *) |
245 | 245 |
in |
246 | 246 |
pp_conj pp_branch fmt hl; |
247 |
reset_instances
|
|
247 |
reset_instances |
|
248 | 248 |
|
249 |
and pp_machine_instrs machines reset_instances m fmt instrs =
|
|
249 |
and pp_machine_instrs machines reset_instances m fmt instrs = |
|
250 | 250 |
let ppi rs fmt i = pp_machine_instr machines rs m fmt i in |
251 | 251 |
match instrs with |
252 |
| [x] -> ppi reset_instances fmt x
|
|
252 |
| [x] -> ppi reset_instances fmt x |
|
253 | 253 |
| _::_ -> |
254 | 254 |
fprintf fmt "(and @[<v 0>"; |
255 |
let rs = List.fold_left (fun rs i ->
|
|
255 |
let rs = List.fold_left (fun rs i -> |
|
256 | 256 |
let rs = ppi rs fmt i in |
257 | 257 |
fprintf fmt "@ "; |
258 | 258 |
rs |
259 | 259 |
) |
260 |
reset_instances instrs
|
|
260 |
reset_instances instrs |
|
261 | 261 |
in |
262 | 262 |
fprintf fmt "@])"; |
263 | 263 |
rs |
... | ... | |
269 | 269 |
fprintf fmt "@[<v 5>(and @ "; |
270 | 270 |
|
271 | 271 |
(* print "x_m = x_c" for each local memory *) |
272 |
(Utils.fprintf_list ~sep:"@ " (fun fmt v ->
|
|
272 |
(Utils.fprintf_list ~sep:"@ " (fun fmt v -> |
|
273 | 273 |
fprintf fmt "(= %a %a)" |
274 | 274 |
(pp_horn_var m) (rename_mid v) |
275 | 275 |
(pp_horn_var m) (rename_current v) |
... | ... | |
281 | 281 |
*) |
282 | 282 |
(Utils.fprintf_list ~sep:"@ " (fun fmt (id, (n, _)) -> |
283 | 283 |
let name = node_name n in |
284 |
if name = "_arrow" then (
|
|
284 |
if name = "_arrow" then ( |
|
285 | 285 |
fprintf fmt "(= %s._arrow._first_m true)" |
286 |
(concat m.mname.node_id id)
|
|
286 |
(concat m.mname.node_id id) |
|
287 | 287 |
) else ( |
288 |
let machine_n = get_machine machines name in
|
|
289 |
fprintf fmt "(%s_reset @[<hov 0>%a@])"
|
|
288 |
let machine_n = get_machine machines name in |
|
289 |
fprintf fmt "(%s_reset @[<hov 0>%a@])" |
|
290 | 290 |
name |
291 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m))
|
|
291 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) |
|
292 | 292 |
(rename_machine_list (concat m.mname.node_id id) (reset_vars machines machine_n)) |
293 | 293 |
) |
294 | 294 |
)) fmt m.minstances; |
... | ... | |
314 | 314 |
else |
315 | 315 |
begin |
316 | 316 |
fprintf fmt "; %s@." m.mname.node_id; |
317 |
|
|
317 |
|
|
318 | 318 |
(* Printing variables *) |
319 | 319 |
Utils.fprintf_list ~sep:"@." pp_decl_var fmt |
320 | 320 |
( |
... | ... | |
358 | 358 |
|
359 | 359 |
(* Rule for reset *) |
360 | 360 |
fprintf fmt "@[<v 2>(rule (=> @ %a@ (%a @[<v 0>%a)@]@]@.))@.@." |
361 |
(pp_machine_reset machines) m
|
|
361 |
(pp_machine_reset machines) m |
|
362 | 362 |
pp_machine_reset_name m.mname.node_id |
363 | 363 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) (reset_vars machines m); |
364 | 364 |
|
... | ... | |
373 | 373 |
pp_machine_step_name m.mname.node_id |
374 | 374 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) (step_vars machines m); |
375 | 375 |
end |
376 |
| assertsl ->
|
|
376 |
| assertsl -> |
|
377 | 377 |
begin |
378 | 378 |
let pp_val = pp_horn_val ~is_lhs:true m.mname.node_id (pp_horn_var m) in |
379 | 379 |
(* print_string pp_val; *) |
380 | 380 |
fprintf fmt "; with Assertions @."; |
381 |
|
|
381 |
|
|
382 | 382 |
(*Rule for step*) |
383 | 383 |
fprintf fmt "@[<v 2>(rule (=> @ (and @ "; |
384 | 384 |
ignore (pp_machine_instrs machines [] m fmt m.mstep.step_instrs); |
... | ... | |
386 | 386 |
pp_machine_step_name m.mname.node_id |
387 | 387 |
(Utils.fprintf_list ~sep:" " (pp_horn_var m)) (step_vars machines m); |
388 | 388 |
end |
389 |
|
|
390 |
|
|
389 |
|
|
390 |
|
|
391 | 391 |
end |
392 | 392 |
end |
393 | 393 |
|
394 | 394 |
|
395 |
let mk_flags arity = |
|
396 |
let b_range = |
|
397 |
let rec range i j = |
|
398 |
if i > arity then [] else i :: (range (i+1) j) in |
|
399 |
range 2 arity; |
|
400 |
in |
|
401 |
List.fold_left (fun acc x -> acc ^ " false") "true" b_range |
|
402 |
|
|
403 |
|
|
404 |
(*Get sfunction infos from command line*) |
|
405 |
let get_sf_info() = |
|
406 |
let splitted = Str.split (Str.regexp "@") !Options.sfunction in |
|
407 |
Log.report ~level:1 (fun fmt -> fprintf fmt ".. sfunction name: %s@," !Options.sfunction); |
|
408 |
let sf_name, flags, arity = match splitted with |
|
409 |
[h;flg;par] -> h, flg, par |
|
410 |
| _ -> failwith "Wrong Sfunction info" |
|
411 |
|
|
412 |
in |
|
413 |
Log.report ~level:1 (fun fmt -> fprintf fmt "... sf_name: %s@, .. flags: %s@ .. arity: %s@," sf_name flags arity); |
|
414 |
sf_name, flags, arity |
|
415 |
|
|
416 |
|
|
417 |
(*a function to print the rules in case we have an s-function*) |
|
418 |
let print_sfunction machines fmt m = |
|
419 |
if m.mname.node_id = arrow_id then |
|
420 |
(* We don't print arrow function *) |
|
421 |
() |
|
422 |
else |
|
423 |
begin |
|
424 |
Format.fprintf fmt "; SFUNCTION@."; |
|
425 |
Format.fprintf fmt "; %s@." m.mname.node_id; |
|
426 |
Format.fprintf fmt "; EndPoint Predicate %s." !Options.sfunction; |
|
427 |
|
|
428 |
(* Check if there is annotation for s-function *) |
|
429 |
if m.mannot != [] then( |
|
430 |
Format.fprintf fmt "; @[%a@]@]@\n" (Utils.fprintf_list ~sep:"@ " Printers.pp_s_function) m.mannot; |
|
431 |
); |
|
432 |
|
|
433 |
(* Printing variables *) |
|
434 |
Utils.fprintf_list ~sep:"@." pp_decl_var fmt |
|
435 |
((step_vars machines m)@ |
|
436 |
(rename_machine_list m.mname.node_id m.mstep.step_locals)); |
|
437 |
Format.pp_print_newline fmt (); |
|
438 |
let sf_name, flags, arity = get_sf_info() in |
|
439 |
|
|
440 |
if is_stateless m then |
|
441 |
begin |
|
442 |
(* Declaring single predicate *) |
|
443 |
Format.fprintf fmt "(declare-rel %a (%a))@." |
|
444 |
pp_machine_stateless_name m.mname.node_id |
|
445 |
(Utils.fprintf_list ~sep:" " pp_type) |
|
446 |
(List.map (fun v -> v.var_type) (reset_vars machines m)); |
|
447 |
Format.pp_print_newline fmt (); |
|
448 |
(* Rule for single predicate *) |
|
449 |
let str_flags = sf_name ^ " " ^ mk_flags (int_of_string flags) in |
|
450 |
Format.fprintf fmt "@[<v 2>(rule (=> @ (%s %a) (%a %a)@]@.))@.@." |
|
451 |
str_flags |
|
452 |
(Utils.fprintf_list ~sep:" " (pp_horn_var m)) (reset_vars machines m) |
|
453 |
pp_machine_stateless_name m.mname.node_id |
|
454 |
(Utils.fprintf_list ~sep:" " (pp_horn_var m)) (reset_vars machines m); |
|
455 |
end |
|
456 |
else |
|
457 |
begin |
|
458 |
(* Declaring predicate *) |
|
459 |
Format.fprintf fmt "(declare-rel %a (%a))@." |
|
460 |
pp_machine_reset_name m.mname.node_id |
|
461 |
(Utils.fprintf_list ~sep:" " pp_type) |
|
462 |
(List.map (fun v -> v.var_type) (inout_vars machines m)); |
|
463 |
|
|
464 |
Format.fprintf fmt "(declare-rel %a (%a))@." |
|
465 |
pp_machine_step_name m.mname.node_id |
|
466 |
(Utils.fprintf_list ~sep:" " pp_type) |
|
467 |
(List.map (fun v -> v.var_type) (step_vars machines m)); |
|
468 |
|
|
469 |
Format.pp_print_newline fmt (); |
|
470 |
(* Adding assertions *) |
|
471 |
match m.mstep.step_asserts with |
|
472 |
| [] -> |
|
473 |
begin |
|
474 |
|
|
475 |
(* Rule for step*) |
|
476 |
fprintf fmt "@[<v 2>(rule (=> @ "; |
|
477 |
ignore (pp_machine_instrs machines [] m fmt m.mstep.step_instrs); |
|
478 |
fprintf fmt "@ (%a @[<v 0>%a)@]@]@.))@.@." |
|
479 |
pp_machine_step_name m.mname.node_id |
|
480 |
(Utils.fprintf_list ~sep:"@ " (pp_horn_var m)) (step_vars machines m); |
|
481 |
end |
|
482 |
| assertsl -> |
|
483 |
begin |
|
484 |
let pp_val = pp_horn_val ~is_lhs:true m.mname.node_id (pp_horn_var m) in |
|
485 |
(* print_string pp_val; *) |
|
486 |
fprintf fmt "; with Assertions @."; |
|
487 |
|
|
488 |
(*Rule for step*) |
|
489 |
fprintf fmt "@[<v 2>(rule (=> @ (and @ "; |
|
490 |
ignore (pp_machine_instrs machines [] m fmt m.mstep.step_instrs); |
|
491 |
fprintf fmt "@. %a)(%a @[<v 0>%a)@]@]@.))@.@." (pp_conj pp_val) assertsl |
|
492 |
pp_machine_step_name m.mname.node_id |
|
493 |
(Utils.fprintf_list ~sep:" " (pp_horn_var m)) (step_vars machines m); |
|
494 |
end |
|
495 |
|
|
496 |
end |
|
497 |
|
|
498 |
end |
|
395 | 499 |
(* Local Variables: *) |
396 | 500 |
(* compile-command:"make -C ../../.." *) |
397 | 501 |
(* End: *) |
src/lexerLustreSpec.mll | ||
---|---|---|
66 | 66 |
"assumes", ASSUMES; |
67 | 67 |
"exists", EXISTS; |
68 | 68 |
"forall", FORALL; |
69 |
"c_code", CCODE; |
|
70 |
"matlab", MATLAB; |
|
69 | 71 |
] |
70 | 72 |
|
71 | 73 |
} |
src/lexer_lustre.mll | ||
---|---|---|
63 | 63 |
"assert", ASSERT; |
64 | 64 |
"lib", LIB; |
65 | 65 |
"prototype", PROTOTYPE; |
66 |
"c_code", CCODE; |
|
67 |
"matlab", MATLAB; |
|
66 | 68 |
] |
67 | 69 |
|
68 | 70 |
|
src/options.ml | ||
---|---|---|
15 | 15 |
let include_path = |
16 | 16 |
if (!include_dir != ".") then Version.prefix ^ !include_dir |
17 | 17 |
else Version.include_path |
18 |
|
|
18 |
|
|
19 | 19 |
|
20 | 20 |
|
21 | 21 |
|
... | ... | |
52 | 52 |
|
53 | 53 |
let salsa_enabled = ref true |
54 | 54 |
|
55 |
let sfunction = ref "" |
|
56 |
|
|
55 | 57 |
let set_mpfr prec = |
56 | 58 |
if prec > 0 then ( |
57 | 59 |
mpfr := true; |
... | ... | |
60 | 62 |
) |
61 | 63 |
else |
62 | 64 |
failwith "mpfr requires a positive integer" |
63 |
|
|
65 |
|
|
64 | 66 |
let options = |
65 | 67 |
[ "-d", Arg.Set_string dest_dir, |
66 | 68 |
"uses the specified directory \x1b[4mdir\x1b[0m as root for generated/imported object and C files <default: .>"; |
... | ... | |
87 | 89 |
"-print_clocks", Arg.Set print_clocks, "prints node clocks"; |
88 | 90 |
"-O", Arg.Set_int optimization, "changes optimization \x1b[4mlevel\x1b[0m <default: 2>"; |
89 | 91 |
"-verbose", Arg.Set_int verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>"; |
92 |
"-horn-sfunction", Arg.Set_string sfunction, "Get the endpoint predicate of the sfunction"; |
|
90 | 93 |
"-version", Arg.Unit print_version, " displays the version";] |
91 | 94 |
|
92 | 95 |
|
93 | 96 |
let plugin_opt (name, activate, options) = |
94 | 97 |
( "-" ^ name , Arg.Unit activate, "activate plugin " ^ name ) :: |
95 | 98 |
(List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options) |
96 |
|
|
99 |
|
|
97 | 100 |
|
98 | 101 |
let get_witness_dir filename = |
99 | 102 |
(* Make sure the directory exists *) |
src/parserLustreSpec.mly | ||
---|---|---|
52 | 52 |
%token PRE ARROW |
53 | 53 |
%token EOF |
54 | 54 |
%token REQUIRES ENSURES OBSERVER |
55 |
%token INVARIANT BEHAVIOR ASSUMES |
|
55 |
%token INVARIANT BEHAVIOR ASSUMES CCODE MATLAB
|
|
56 | 56 |
%token EXISTS FORALL |
57 | 57 |
|
58 | 58 |
%nonassoc prec_exists prec_forall |
... | ... | |
295 | 295 |
| IDENT COL expr SCOL lustre_annot_list { ([$1],$3)::$5 } |
296 | 296 |
| INVARIANT COL expr SCOL lustre_annot_list{ (["invariant"],$3)::$5 } |
297 | 297 |
| OBSERVER COL expr SCOL lustre_annot_list { (["observer"],$3)::$5 } |
298 |
| CCODE COL const lustre_annot_list{ (["c_code"],$3)::$5 } |
|
299 |
| MATLAB COL const lustre_annot_list{ (["matlab"],$3)::$5 } |
|
298 | 300 |
|
299 | 301 |
kwd: |
300 | 302 |
DIV { [] } |
src/parser_lustre.mly | ||
---|---|---|
78 | 78 |
%token MINUS PLUS UMINUS |
79 | 79 |
%token PRE ARROW |
80 | 80 |
%token REQUIRES ENSURES OBSERVER |
81 |
%token INVARIANT BEHAVIOR ASSUMES |
|
81 |
%token INVARIANT BEHAVIOR ASSUMES CCODE MATLAB
|
|
82 | 82 |
%token EXISTS FORALL |
83 | 83 |
%token PROTOTYPE LIB |
84 | 84 |
%token EOF |
... | ... | |
638 | 638 |
| IDENT COL qexpr SCOL lustre_annot_list { ([$1],$3)::$5 } |
639 | 639 |
| INVARIANT COL qexpr SCOL lustre_annot_list{ (["invariant"],$3)::$5 } |
640 | 640 |
| OBSERVER COL qexpr SCOL lustre_annot_list { (["observer"],$3)::$5 } |
641 |
| CCODE COL qexpr SCOL lustre_annot_list{ (["c_code"],$3)::$5 } |
|
642 |
| MATLAB COL qexpr SCOL lustre_annot_list{ (["matlab"],$3)::$5 } |
|
643 |
|
|
641 | 644 |
|
642 | 645 |
kwd: |
643 | 646 |
DIV { [] } |
src/printers.ml | ||
---|---|---|
52 | 52 |
|
53 | 53 |
let pp_quantifiers fmt (q, vars) = |
54 | 54 |
match q with |
55 |
| Forall -> fprintf fmt "forall %a" (fprintf_list ~sep:"; " pp_var) vars
|
|
56 |
| Exists -> fprintf fmt "exists %a" (fprintf_list ~sep:"; " pp_var) vars
|
|
55 |
| Forall -> fprintf fmt "forall %a" (fprintf_list ~sep:"; " pp_var) vars |
|
56 |
| Exists -> fprintf fmt "exists %a" (fprintf_list ~sep:"; " pp_var) vars |
|
57 | 57 |
|
58 | 58 |
let rec pp_struct_const_field fmt (label, c) = |
59 | 59 |
fprintf fmt "%a = %a;" pp_print_string label pp_const c |
60 |
and pp_const fmt c =
|
|
60 |
and pp_const fmt c = |
|
61 | 61 |
match c with |
62 | 62 |
| Const_int i -> pp_print_int fmt i |
63 | 63 |
| Const_real (c, e, s) -> pp_print_string fmt s (*if e = 0 then pp_print_int fmt c else if e < 0 then Format.fprintf fmt "%ie%i" c (-e) else Format.fprintf fmt "%ie-%i" c e *) |
... | ... | |
69 | 69 |
|
70 | 70 |
|
71 | 71 |
let rec pp_expr fmt expr = |
72 |
(match expr.expr_annot with
|
|
73 |
| None -> fprintf fmt "%t"
|
|
72 |
(match expr.expr_annot with |
|
73 |
| None -> fprintf fmt "%t" |
|
74 | 74 |
| Some ann -> fprintf fmt "(%a %t)" pp_expr_annot ann) |
75 |
(fun fmt ->
|
|
75 |
(fun fmt -> |
|
76 | 76 |
match expr.expr_desc with |
77 | 77 |
| Expr_const c -> pp_const fmt c |
78 | 78 |
| Expr_ident id -> Format.fprintf fmt "%s" id |
... | ... | |
85 | 85 |
| Expr_fby (e1, e2) -> fprintf fmt "%a fby %a" pp_expr e1 pp_expr e2 |
86 | 86 |
| Expr_pre e -> fprintf fmt "pre %a" pp_expr e |
87 | 87 |
| Expr_when (e, id, l) -> fprintf fmt "%a when %s(%s)" pp_expr e l id |
88 |
| Expr_merge (id, hl) ->
|
|
88 |
| Expr_merge (id, hl) -> |
|
89 | 89 |
fprintf fmt "merge %s %a" id pp_handlers hl |
90 | 90 |
| Expr_appl (id, e, r) -> pp_app fmt id e r |
91 | 91 |
) |
... | ... | |
101 | 101 |
and pp_app fmt id e r = |
102 | 102 |
match r with |
103 | 103 |
| None -> pp_call fmt id e |
104 |
| Some c -> fprintf fmt "%t every (%a)" (fun fmt -> pp_call fmt id e) pp_expr c
|
|
104 |
| Some c -> fprintf fmt "%t every (%a)" (fun fmt -> pp_call fmt id e) pp_expr c |
|
105 | 105 |
|
106 | 106 |
and pp_call fmt id e = |
107 | 107 |
match id, e.expr_desc with |
... | ... | |
131 | 131 |
(fun fmt -> match e.eexpr_quantifiers with [] -> () | _ -> fprintf fmt ";") |
132 | 132 |
pp_expr e.eexpr_qfexpr |
133 | 133 |
|
134 |
and pp_sf_value fmt e = |
|
135 |
fprintf fmt "%a" |
|
136 |
(* (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers *) |
|
137 |
(* (fun fmt -> match e.eexpr_quantifiers *) |
|
138 |
(* with [] -> () *) |
|
139 |
(* | _ -> fprintf fmt ";") *) |
|
140 |
pp_expr e.eexpr_qfexpr |
|
141 |
|
|
142 |
and pp_s_function fmt expr_ann = |
|
143 |
let pp_annot fmt (kwds, ee) = |
|
144 |
Format.fprintf fmt " %t : %a" |
|
145 |
(fun fmt -> match kwds with |
|
146 |
| [] -> assert false |
|
147 |
| [x] -> Format.pp_print_string fmt x |
|
148 |
| _ -> Format.fprintf fmt "%a" (fprintf_list ~sep:"/" Format.pp_print_string) kwds) |
|
149 |
pp_sf_value ee |
|
150 |
in |
|
151 |
fprintf_list ~sep:"@ " pp_annot fmt expr_ann.annots |
|
134 | 152 |
|
135 | 153 |
and pp_expr_annot fmt expr_ann = |
136 | 154 |
let pp_annot fmt (kwds, ee) = |
... | ... | |
139 | 157 |
pp_eexpr ee |
140 | 158 |
in |
141 | 159 |
fprintf_list ~sep:"@ " pp_annot fmt expr_ann.annots |
142 |
|
|
160 |
|
|
143 | 161 |
(* |
144 | 162 |
let pp_node_var fmt id = fprintf fmt "%s%s: %a(%a)%a" (if id.var_dec_const then "const " else "") id.var_id print_dec_ty id.var_dec_type.ty_dec_desc Types.print_ty id.var_type Clocks.print_ck_suffix id.var_clock |
145 | 163 |
*) |
... | ... | |
147 | 165 |
begin |
148 | 166 |
fprintf fmt "%s%s: %a%a" (if id.var_dec_const then "const " else "") id.var_id Types.print_node_ty id.var_type Clocks.print_ck_suffix id.var_clock; |
149 | 167 |
match id.var_dec_value with |
150 |
| None -> ()
|
|
168 |
| None -> () |
|
151 | 169 |
| Some v -> fprintf fmt " = %a" pp_expr v |
152 |
end
|
|
170 |
end |
|
153 | 171 |
|
154 |
let pp_node_args = fprintf_list ~sep:"; " pp_node_var
|
|
172 |
let pp_node_args = fprintf_list ~sep:"; " pp_node_var |
|
155 | 173 |
|
156 |
let pp_node_eq fmt eq =
|
|
157 |
fprintf fmt "%a = %a;"
|
|
174 |
let pp_node_eq fmt eq = |
|
175 |
fprintf fmt "%a = %a;" |
|
158 | 176 |
pp_eq_lhs eq.eq_lhs |
159 | 177 |
pp_expr eq.eq_rhs |
160 | 178 |
|
... | ... | |
179 | 197 |
(Utils.fprintf_list ~sep:"@," pp_unless) handler.hand_unless |
180 | 198 |
(fun fmt locals -> |
181 | 199 |
match locals with [] -> () | _ -> |
182 |
Format.fprintf fmt "@[<v 4>var %a@]@ "
|
|
183 |
(Utils.fprintf_list ~sep:"@ "
|
|
200 |
Format.fprintf fmt "@[<v 4>var %a@]@ " |
|
201 |
(Utils.fprintf_list ~sep:"@ " |
|
184 | 202 |
(fun fmt v -> Format.fprintf fmt "%a;" pp_node_var v)) |
185 | 203 |
locals) |
186 | 204 |
handler.hand_locals |
... | ... | |
204 | 222 |
let rec pp_var_struct_type_field fmt (label, tdesc) = |
205 | 223 |
fprintf fmt "%a : %a;" pp_print_string label pp_var_type_dec_desc tdesc |
206 | 224 |
and pp_var_type_dec_desc fmt tdesc = |
207 |
match tdesc with
|
|
225 |
match tdesc with |
|
208 | 226 |
| Tydec_any -> fprintf fmt "<any>" |
209 | 227 |
| Tydec_int -> fprintf fmt "int" |
210 | 228 |
| Tydec_real -> fprintf fmt "real" |
... | ... | |
241 | 259 |
fprintf fmt "@[<hov 2>(*@@ "; |
242 | 260 |
fprintf_list ~sep:"@;@@ " (fun fmt r -> fprintf fmt "requires %a;" pp_eexpr r) fmt spec.requires; |
243 | 261 |
fprintf_list ~sep:"@;@@ " (fun fmt r -> fprintf fmt "ensures %a; " pp_eexpr r) fmt spec.ensures; |
244 |
fprintf_list ~sep:"@;" (fun fmt (name, assumes, ensures, _) ->
|
|
245 |
fprintf fmt "behavior %s:@[@ %a@ %a@]"
|
|
262 |
fprintf_list ~sep:"@;" (fun fmt (name, assumes, ensures, _) -> |
|
263 |
fprintf fmt "behavior %s:@[@ %a@ %a@]" |
|
246 | 264 |
name |
247 | 265 |
(fprintf_list ~sep:"@ " (fun fmt r -> fprintf fmt "assumes %a;" pp_eexpr r)) assumes |
248 | 266 |
(fprintf_list ~sep:"@ " (fun fmt r -> fprintf fmt "ensures %a;" pp_eexpr r)) ensures |
... | ... | |
252 | 270 |
|
253 | 271 |
|
254 | 272 |
let pp_asserts fmt asserts = |
255 |
match asserts with
|
|
273 |
match asserts with |
|
256 | 274 |
| _::_ -> ( |
257 | 275 |
fprintf fmt "(* Asserts definitions *)@ "; |
258 |
fprintf_list ~sep:"@ " (fun fmt assert_ ->
|
|
276 |
fprintf_list ~sep:"@ " (fun fmt assert_ -> |
|
259 | 277 |
let expr = assert_.assert_expr in |
260 |
fprintf fmt "assert %a;" pp_expr expr
|
|
261 |
) fmt asserts
|
|
278 |
fprintf fmt "assert %a;" pp_expr expr |
|
279 |
) fmt asserts |
|
262 | 280 |
) |
263 | 281 |
| _ -> () |
264 |
|
|
265 |
let pp_node fmt nd =
|
|
282 |
|
|
283 |
let pp_node fmt nd = |
|
266 | 284 |
fprintf fmt "@[<v 0>%a%t%s %s (%a) returns (%a)@.%a%alet@.@[<h 2> @ @[<v>%a@ %a@ %a@]@ @]@.tel@]@." |
267 | 285 |
(fun fmt s -> match s with Some s -> pp_spec fmt s | _ -> ()) nd.node_spec |
268 | 286 |
(fun fmt -> match nd.node_spec with None -> () | Some _ -> Format.fprintf fmt "@.") |
... | ... | |
272 | 290 |
pp_node_args nd.node_outputs |
273 | 291 |
(fun fmt locals -> |
274 | 292 |
match locals with [] -> () | _ -> |
275 |
fprintf fmt "@[<v 4>var %a@]@ "
|
|
276 |
(fprintf_list ~sep:"@ "
|
|
293 |
fprintf fmt "@[<v 4>var %a@]@ " |
|
294 |
(fprintf_list ~sep:"@ " |
|
277 | 295 |
(fun fmt v -> fprintf fmt "%a;" pp_node_var v)) |
278 | 296 |
locals |
279 | 297 |
) nd.node_locals |
280 | 298 |
(fun fmt checks -> |
281 | 299 |
match checks with [] -> () | _ -> |
282 |
fprintf fmt "@[<v 4>check@ %a@]@ "
|
|
283 |
(fprintf_list ~sep:"@ "
|
|
300 |
fprintf fmt "@[<v 4>check@ %a@]@ " |
|
301 |
(fprintf_list ~sep:"@ " |
|
284 | 302 |
(fun fmt d -> fprintf fmt "%a" Dimension.pp_dimension d)) |
285 | 303 |
checks |
286 | 304 |
) nd.node_checks |
... | ... | |
289 | 307 |
pp_asserts nd.node_asserts |
290 | 308 |
(*fprintf fmt "@ /* Scheduling: %a */ @ " (fprintf_list ~sep:", " pp_print_string) (Scheduling.schedule_node nd)*) |
291 | 309 |
|
292 |
let pp_imported_node fmt ind =
|
|
310 |
let pp_imported_node fmt ind = |
|
293 | 311 |
fprintf fmt "@[<v>%s %s (%a) returns (%a)@]" |
294 | 312 |
(if ind.nodei_stateless then "function" else "node") |
295 | 313 |
ind.nodei_id |
... | ... | |
299 | 317 |
let pp_const_decl fmt cdecl = |
300 | 318 |
fprintf fmt "%s = %a;" cdecl.const_id pp_const cdecl.const_value |
301 | 319 |
|
302 |
let pp_const_decl_list fmt clist =
|
|
320 |
let pp_const_decl_list fmt clist = |
|
303 | 321 |
fprintf_list ~sep:"@ " pp_const_decl fmt clist |
304 | 322 |
|
305 | 323 |
let pp_decl fmt decl = |
... | ... | |
311 | 329 |
| Open (local, s) -> if local then fprintf fmt "#open \"%s\"@ " s else fprintf fmt "#open <%s>@ " s |
312 | 330 |
| TypeDef tdef -> fprintf fmt "%a@ " pp_typedef tdef |
313 | 331 |
|
314 |
let pp_prog fmt prog =
|
|
332 |
let pp_prog fmt prog = |
|
315 | 333 |
fprintf_list ~sep:"@ " pp_decl fmt prog |
316 | 334 |
|
317 | 335 |
let pp_short_decl fmt decl = |
... | ... | |
322 | 340 |
| Open (local, s) -> if local then fprintf fmt "#open \"%s\"@ " s else fprintf fmt "#open <%s>@ " s |
323 | 341 |
| TypeDef tdef -> fprintf fmt "type %s;@ " tdef.tydef_id |
324 | 342 |
|
325 |
let pp_lusi fmt decl =
|
|
343 |
let pp_lusi fmt decl = |
|
326 | 344 |
match decl.top_decl_desc with |
327 | 345 |
| ImportedNode ind -> fprintf fmt "%a;@ " pp_imported_node ind |
328 | 346 |
| Const c -> fprintf fmt "const %a@ " pp_const_decl c |
... | ... | |
334 | 352 |
fprintf fmt "(* Generated Lustre Interface file from %s.lus *)@." basename; |
335 | 353 |
fprintf fmt "(* by Lustre-C compiler version %s, %a *)@." Version.number pp_date (Unix.gmtime (Unix.time ())); |
336 | 354 |
fprintf fmt "(* Feel free to mask some of the definitions by removing them from this file. *)@.@."; |
337 |
List.iter (fprintf fmt "%a@." pp_lusi) prog
|
|
355 |
List.iter (fprintf fmt "%a@." pp_lusi) prog |
|
338 | 356 |
|
339 | 357 |
let pp_offset fmt offset = |
340 | 358 |
match offset with |
Also available in: Unified diff
adding sfunction support