Revision a7062da6
Added by LĂ©lio Brun over 3 years ago
src/annotations.mli | ||
---|---|---|
1 | 1 |
open Utils |
2 | 2 |
|
3 |
val expr_annotations: (string list, ident * tag) Hashtbl.t |
|
4 |
|
|
3 | 5 |
val add_node_ann: ident -> string list -> unit |
4 | 6 |
val add_expr_ann: ident -> tag -> string list -> unit |
5 | 7 |
val get_expr_annotations: ident list -> (ident * tag) list |
src/backends/Ada/ada_backend.ml | ||
---|---|---|
114 | 114 |
@param basename name of the lustre file @param prog list of machines to |
115 | 115 |
translate **) |
116 | 116 |
let translate_to_ada basename machines = |
117 |
let module Ads = Ada_backend_ads.Main in |
|
118 |
let module Adb = Ada_backend_adb.Main in |
|
119 |
let module Wrapper = Ada_backend_wrapper.Main in
|
|
117 |
(* let module Ads = Ada_backend_ads.Main in
|
|
118 |
* let module Adb = Ada_backend_adb.Main in
|
|
119 |
* let module Wrapper = Ada_backend_wrapper.Main in *)
|
|
120 | 120 |
let is_real_machine m = |
121 | 121 |
match m.mspec.mnode_spec with Some (Contract _) -> false | _ -> true |
122 | 122 |
in |
... | ... | |
145 | 145 |
| main_node -> ( |
146 | 146 |
match Machine_code_common.get_machine_opt filtered_machines main_node with |
147 | 147 |
| None -> |
148 |
Format.eprintf "Ada Code generation error: %a@." Error.pp_error_msg
|
|
148 |
Format.eprintf "Ada Code generation error: %a@." Error.pp |
|
149 | 149 |
Error.Main_not_found; |
150 |
raise (Error.Error (Location.dummy_loc, Error.Main_not_found))
|
|
150 |
raise (Error.Error (Location.dummy, Error.Main_not_found)) |
|
151 | 151 |
| Some m -> |
152 | 152 |
Some m) |
153 | 153 |
in |
... | ... | |
158 | 158 |
List.iter check machines; |
159 | 159 |
|
160 | 160 |
log_str_level_two 1 "Generating ads"; |
161 |
List.iter (write_file destname (_pp_filename "ads") Ads.pp_file) _machines; |
|
161 |
List.iter (write_file destname (_pp_filename "ads") Ada_backend_ads.pp_file) _machines;
|
|
162 | 162 |
|
163 | 163 |
log_str_level_two 1 "Generating adb"; |
164 |
List.iter (write_file destname (_pp_filename "adb") Adb.pp_file) _machines; |
|
164 |
List.iter (write_file destname (_pp_filename "adb") Ada_backend_adb.pp_file) _machines;
|
|
165 | 165 |
|
166 | 166 |
(* If a main node is given we generate a main adb file and a project file *) |
167 | 167 |
log_str_level_two 1 "Generating wrapper files"; |
... | ... | |
169 | 169 |
| None -> |
170 | 170 |
() |
171 | 171 |
| Some machine -> |
172 |
write_file destname pp_main_filename Wrapper.pp_main_adb
|
|
172 |
write_file destname pp_main_filename Ada_backend_wrapper.pp_main_adb
|
|
173 | 173 |
(*get_typed_submachines filtered_machines machine*) |
174 | 174 |
machine; |
175 | 175 |
write_file destname |
176 |
(fun fmt _ -> Wrapper.pp_project_name (basename ^ "_exe") fmt)
|
|
177 |
(Wrapper.pp_project_file filtered_machines basename)
|
|
176 |
(fun fmt _ -> Ada_backend_wrapper.pp_project_name (basename ^ "_exe") fmt)
|
|
177 |
(Ada_backend_wrapper.pp_project_file filtered_machines basename)
|
|
178 | 178 |
main_machine); |
179 |
write_file destname Wrapper.pp_project_configuration_name
|
|
180 |
(fun fmt _ -> Wrapper.pp_project_configuration_file fmt)
|
|
179 |
write_file destname Ada_backend_wrapper.pp_project_configuration_name
|
|
180 |
(fun fmt _ -> Ada_backend_wrapper.pp_project_configuration_file fmt)
|
|
181 | 181 |
basename; |
182 | 182 |
write_file destname |
183 |
(fun fmt _ -> Wrapper.pp_project_name (basename ^ "_lib") fmt)
|
|
184 |
(Wrapper.pp_project_file filtered_machines basename)
|
|
183 |
(fun fmt _ -> Ada_backend_wrapper.pp_project_name (basename ^ "_lib") fmt)
|
|
184 |
(Ada_backend_wrapper.pp_project_file filtered_machines basename)
|
|
185 | 185 |
None |
186 | 186 |
|
187 | 187 |
(* Local Variables: *) |
src/backends/Ada/ada_backend.mli | ||
---|---|---|
1 |
(** Main function of the Ada backend. It calls all the subfunction creating all |
|
2 |
the file and fill them with Ada code representing the machines list given. |
|
3 |
@param basename name of the lustre file @param prog list of machines to |
|
4 |
translate **) |
|
5 |
val translate_to_ada: string -> Machine_code_types.machine_t list -> unit |
src/backends/Ada/ada_backend_adb.ml | ||
---|---|---|
9 | 9 |
(* *) |
10 | 10 |
(********************************************************************) |
11 | 11 |
|
12 |
open Utils |
|
12 | 13 |
open Format |
13 | 14 |
open Machine_code_types |
14 | 15 |
open Lustre_types |
... | ... | |
20 | 21 |
open Ada_backend_common |
21 | 22 |
|
22 | 23 |
(** Main module for generating packages bodies **) |
23 |
module Main = struct |
|
24 |
(** Printing function for basic assignement [var := value]. |
|
25 | 24 |
|
26 |
@param fmt the formater to print on @param var_name the name of the |
|
27 |
variable @param value the value to be assigned **) |
|
28 |
let pp_assign env fmt var value = |
|
29 |
fprintf fmt "%a := %a" (pp_var env) var (pp_value env) value |
|
25 |
(** Printing function for basic assignement [var := value]. |
|
30 | 26 |
|
31 |
(** Printing function for instruction. See {!type:Machine_code_types.instr_t} |
|
32 |
for more details on machine types. |
|
27 |
@param fmt the formater to print on @param var_name the name of the |
|
28 |
variable @param value the value to be assigned **) |
|
29 |
let pp_assign env fmt var value = |
|
30 |
fprintf fmt "%a := %a" (pp_var env) var (pp_value env) value |
|
33 | 31 |
|
34 |
@param typed_submachines list of all typed machine instances of this |
|
35 |
machine @param machine the current machine @param fmt the formater to |
|
36 |
print on @param instr the instruction to print **) |
|
37 |
let rec pp_machine_instr typed_submachines env instr fmt = |
|
38 |
let pp_instr = pp_machine_instr typed_submachines env in |
|
39 |
(* Print args for a step call *) |
|
40 |
let pp_state i fmt = fprintf fmt "%t.%s" pp_state_name i in |
|
41 |
(* Print a when branch of a case *) |
|
42 |
let pp_when (cond, instrs) fmt = |
|
43 |
fprintf fmt "when %s =>@,%a" cond pp_block (List.map pp_instr instrs) |
|
44 |
in |
|
45 |
(* Print a case *) |
|
46 |
let pp_case fmt (g, hl) = |
|
47 |
fprintf fmt "case %a is@,%aend case" (pp_value env) g pp_block |
|
48 |
(List.map pp_when hl) |
|
49 |
in |
|
50 |
(* Print a if *) |
|
51 |
(* If neg is true the we must test for the negation of the condition. It |
|
52 |
first check that we don't have a negation and a else case, if so it |
|
53 |
inverses the two branch and remove the negation doing a recursive call. *) |
|
54 |
let pp_if fmt (neg, g, instrs1, instrs2) = |
|
55 |
let pp_cond = |
|
56 |
if neg then fun fmt x -> fprintf fmt "! (%a)" (pp_value env) x |
|
57 |
else pp_value env |
|
58 |
in |
|
59 |
let pp_else = |
|
60 |
match instrs2 with |
|
61 |
| None -> |
|
62 |
fun fmt -> fprintf fmt "" |
|
63 |
| Some i2 -> |
|
64 |
fun fmt -> fprintf fmt "else@,%a" pp_block (List.map pp_instr i2) |
|
65 |
in |
|
66 |
fprintf fmt "if %a then@,%a%tend if" pp_cond g pp_block |
|
67 |
(List.map pp_instr instrs1) |
|
68 |
pp_else |
|
69 |
in |
|
70 |
match get_instr_desc instr with |
|
71 |
(* no reset *) |
|
72 |
| MNoReset _ -> |
|
73 |
() |
|
74 |
(* TODO: handle clear_reset *) |
|
75 |
| MClearReset -> |
|
76 |
() |
|
77 |
(* reset *) |
|
78 |
| MSetReset i when List.mem_assoc i typed_submachines -> |
|
79 |
let substitution, submachine = get_instance i typed_submachines in |
|
80 |
let pp_package = |
|
81 |
pp_package_name_with_polymorphic substitution submachine |
|
82 |
in |
|
83 |
let args = |
|
84 |
if is_machine_statefull submachine then [ [ pp_state i ] ] else [] |
|
85 |
in |
|
86 |
pp_call fmt (pp_package_access (pp_package, pp_reset_procedure_name), args) |
|
87 |
| MLocalAssign (ident, value) -> |
|
88 |
pp_assign env fmt ident value |
|
89 |
| MStateAssign (ident, value) -> |
|
90 |
pp_assign env fmt ident value |
|
91 |
| MStep ([ i0 ], i, vl) when is_builtin_fun i -> |
|
92 |
let value = mk_val (Fun (i, vl)) i0.var_type in |
|
93 |
pp_assign env fmt i0 value |
|
94 |
| MStep (il, i, vl) when List.mem_assoc i typed_submachines -> |
|
95 |
let substitution, submachine = get_instance i typed_submachines in |
|
96 |
let pp_package = |
|
97 |
pp_package_name_with_polymorphic substitution submachine |
|
98 |
in |
|
99 |
let input = List.map (fun x fmt -> pp_value env fmt x) vl in |
|
100 |
let output = List.map pp_var_name il in |
|
101 |
let args = |
|
102 |
(if is_machine_statefull submachine then [ [ pp_state i ] ] else []) |
|
103 |
@ (if input != [] then [ input ] else []) |
|
104 |
@ if output != [] then [ output ] else [] |
|
105 |
in |
|
106 |
pp_call fmt (pp_package_access (pp_package, pp_step_procedure_name), args) |
|
107 |
| MBranch (_, []) -> |
|
108 |
assert false |
|
109 |
| MBranch (g, (c1, i1) :: tl) when c1 = tag_false || c1 = tag_true -> |
|
110 |
pp_if fmt (build_if g c1 i1 tl) |
|
111 |
| MBranch (g, hl) -> |
|
112 |
pp_case fmt (g, hl) |
|
113 |
| MComment s -> |
|
114 |
let lines = String.split_on_char '\n' s in |
|
115 |
fprintf fmt "%a" (Utils.fprintf_list ~sep:"" pp_oneline_comment) lines |
|
116 |
| _ -> |
|
117 |
assert false |
|
32 |
(** Printing function for instruction. See {!type:Machine_code_types.instr_t} |
|
33 |
for more details on machine types. |
|
118 | 34 |
|
119 |
(** Print the definition of the step procedure from a machine. |
|
120 |
|
|
121 |
@param typed_submachines list of all typed machine instances of this |
|
122 |
machine @param fmt the formater to print on @param machine the machine **) |
|
123 |
let pp_step_definition env typed_submachines fmt (m, m_spec_opt, guarantees) = |
|
124 |
let transform_local_to_state_assign instr = |
|
125 |
match instr.instr_desc with |
|
126 |
| MLocalAssign (ident, value) -> |
|
127 |
{ instr with instr_desc = MStateAssign (ident, value) } |
|
128 |
| _ -> |
|
129 |
instr |
|
35 |
@param typed_submachines list of all typed machine instances of this |
|
36 |
machine @param machine the current machine @param fmt the formater to |
|
37 |
print on @param instr the instruction to print **) |
|
38 |
let rec pp_machine_instr typed_submachines env instr fmt = |
|
39 |
let pp_instr = pp_machine_instr typed_submachines env in |
|
40 |
(* Print args for a step call *) |
|
41 |
let pp_state i fmt = fprintf fmt "%t.%s" pp_state_name i in |
|
42 |
(* Print a when branch of a case *) |
|
43 |
let pp_when (cond, instrs) fmt = |
|
44 |
fprintf fmt "when %s =>@,%a" cond pp_block (List.map pp_instr instrs) |
|
45 |
in |
|
46 |
(* Print a case *) |
|
47 |
let pp_case fmt (g, hl) = |
|
48 |
fprintf fmt "case %a is@,%aend case" (pp_value env) g pp_block |
|
49 |
(List.map pp_when hl) |
|
50 |
in |
|
51 |
(* Print a if *) |
|
52 |
(* If neg is true the we must test for the negation of the condition. It |
|
53 |
first check that we don't have a negation and a else case, if so it |
|
54 |
inverses the two branch and remove the negation doing a recursive call. *) |
|
55 |
let pp_if fmt (neg, g, instrs1, instrs2) = |
|
56 |
let pp_cond = |
|
57 |
if neg then fun fmt x -> fprintf fmt "! (%a)" (pp_value env) x |
|
58 |
else pp_value env |
|
130 | 59 |
in |
131 |
let pp_local_ghost_list, spec_instrs =
|
|
132 |
match m_spec_opt with
|
|
60 |
let pp_else =
|
|
61 |
match instrs2 with
|
|
133 | 62 |
| None -> |
134 |
[], [] |
|
135 |
| Some m_spec -> |
|
136 |
( List.map |
|
137 |
(build_pp_var_decl_local (Some (true, false, [], []))) |
|
138 |
(List.filter |
|
139 |
(fun x -> not (List.mem x.var_id guarantees)) |
|
140 |
m_spec.mstep.step_locals), |
|
141 |
List.map transform_local_to_state_assign m_spec.mstep.step_instrs ) |
|
63 |
fun fmt -> fprintf fmt "" |
|
64 |
| Some i2 -> |
|
65 |
fun fmt -> fprintf fmt "else@,%a" pp_block (List.map pp_instr i2) |
|
66 |
in |
|
67 |
fprintf fmt "if %a then@,%a%tend if" pp_cond g pp_block |
|
68 |
(List.map pp_instr instrs1) |
|
69 |
pp_else |
|
70 |
in |
|
71 |
match get_instr_desc instr with |
|
72 |
(* no reset *) |
|
73 |
| MNoReset _ -> |
|
74 |
() |
|
75 |
(* TODO: handle clear_reset *) |
|
76 |
| MClearReset -> |
|
77 |
() |
|
78 |
(* reset *) |
|
79 |
| MSetReset i when List.mem_assoc i typed_submachines -> |
|
80 |
let substitution, submachine = get_instance i typed_submachines in |
|
81 |
let pp_package = |
|
82 |
pp_package_name_with_polymorphic substitution submachine |
|
142 | 83 |
in |
143 |
let pp_local_list =
|
|
144 |
List.map (build_pp_var_decl_local None) m.mstep.step_locals
|
|
84 |
let args =
|
|
85 |
if is_machine_statefull submachine then [ [ pp_state i ] ] else []
|
|
145 | 86 |
in |
146 |
let pp_instr_list = |
|
147 |
List.map |
|
148 |
(pp_machine_instr typed_submachines env) |
|
149 |
(m.mstep.step_instrs @ spec_instrs) |
|
87 |
pp_call fmt (pp_package_access (pp_package, pp_reset_procedure_name), args) |
|
88 |
| MLocalAssign (ident, value) -> |
|
89 |
pp_assign env fmt ident value |
|
90 |
| MStateAssign (ident, value) -> |
|
91 |
pp_assign env fmt ident value |
|
92 |
| MStep ([ i0 ], i, vl) when is_builtin_fun i -> |
|
93 |
let value = mk_val (Fun (i, vl)) i0.var_type in |
|
94 |
pp_assign env fmt i0 value |
|
95 |
| MStep (il, i, vl) when List.mem_assoc i typed_submachines -> |
|
96 |
let substitution, submachine = get_instance i typed_submachines in |
|
97 |
let pp_package = |
|
98 |
pp_package_name_with_polymorphic substitution submachine |
|
150 | 99 |
in |
151 |
let content = |
|
152 |
AdaProcedureContent |
|
153 |
( ((if pp_local_ghost_list = [] then [] else [ pp_local_ghost_list ]) |
|
154 |
@ if pp_local_list = [] then [] else [ pp_local_list ]), |
|
155 |
pp_instr_list ) |
|
100 |
let input = List.map (fun x fmt -> pp_value env fmt x) vl in |
|
101 |
let output = List.map pp_var_name il in |
|
102 |
let args = |
|
103 |
(if is_machine_statefull submachine then [ [ pp_state i ] ] else []) |
|
104 |
@ (if input != [] then [ input ] else []) |
|
105 |
@ if output != [] then [ output ] else [] |
|
156 | 106 |
in |
157 |
pp_procedure pp_step_procedure_name (build_pp_arg_step m) None fmt content |
|
107 |
pp_call fmt (pp_package_access (pp_package, pp_step_procedure_name), args) |
|
108 |
| MBranch (_, []) -> |
|
109 |
assert false |
|
110 |
| MBranch (g, (c1, i1) :: tl) when c1 = tag_false || c1 = tag_true -> |
|
111 |
pp_if fmt (build_if g c1 i1 tl) |
|
112 |
| MBranch (g, hl) -> |
|
113 |
pp_case fmt (g, hl) |
|
114 |
| MComment s -> |
|
115 |
let lines = String.split_on_char '\n' s in |
|
116 |
fprintf fmt "%a" (pp_print_list ~pp_sep:pp_print_nothing pp_oneline_comment) lines |
|
117 |
| _ -> |
|
118 |
assert false |
|
158 | 119 |
|
159 |
(** Print the definition of the reset procedure from a machine.
|
|
120 |
(** Print the definition of the step procedure from a machine.
|
|
160 | 121 |
|
161 |
@param typed_submachines list of all typed machine instances of this |
|
162 |
machine @param fmt the formater to print on @param machine the machine **) |
|
163 |
let pp_reset_definition env typed_submachines fmt (m, m_spec_opt) = |
|
164 |
let build_assign = function |
|
165 |
| var -> |
|
166 |
mkinstr (MStateAssign (var, mk_default_value var.var_type)) |
|
167 |
in |
|
168 |
let env, memory = |
|
169 |
match m_spec_opt with None -> env, m.mmemory | Some _ -> env, m.mmemory |
|
170 |
in |
|
171 |
let assigns = List.map build_assign memory in |
|
172 |
let pp_instr_list = |
|
173 |
List.map (pp_machine_instr typed_submachines env) (assigns @ m.minit) |
|
174 |
in |
|
175 |
pp_procedure pp_reset_procedure_name (build_pp_arg_reset m) None fmt |
|
176 |
(AdaProcedureContent ([], pp_instr_list)) |
|
122 |
@param typed_submachines list of all typed machine instances of this |
|
123 |
machine @param fmt the formater to print on @param machine the machine **) |
|
124 |
let pp_step_definition env typed_submachines fmt (m, m_spec_opt, guarantees) = |
|
125 |
let transform_local_to_state_assign instr = |
|
126 |
match instr.instr_desc with |
|
127 |
| MLocalAssign (ident, value) -> |
|
128 |
{ instr with instr_desc = MStateAssign (ident, value) } |
|
129 |
| _ -> |
|
130 |
instr |
|
131 |
in |
|
132 |
let pp_local_ghost_list, spec_instrs = |
|
133 |
match m_spec_opt with |
|
134 |
| None -> |
|
135 |
[], [] |
|
136 |
| Some m_spec -> |
|
137 |
( List.map |
|
138 |
(build_pp_var_decl_local (Some (true, false, [], []))) |
|
139 |
(List.filter |
|
140 |
(fun x -> not (List.mem x.var_id guarantees)) |
|
141 |
m_spec.mstep.step_locals), |
|
142 |
List.map transform_local_to_state_assign m_spec.mstep.step_instrs ) |
|
143 |
in |
|
144 |
let pp_local_list = |
|
145 |
List.map (build_pp_var_decl_local None) m.mstep.step_locals |
|
146 |
in |
|
147 |
let pp_instr_list = |
|
148 |
List.map |
|
149 |
(pp_machine_instr typed_submachines env) |
|
150 |
(m.mstep.step_instrs @ spec_instrs) |
|
151 |
in |
|
152 |
let content = |
|
153 |
AdaProcedureContent |
|
154 |
( ((if pp_local_ghost_list = [] then [] else [ pp_local_ghost_list ]) |
|
155 |
@ if pp_local_list = [] then [] else [ pp_local_list ]), |
|
156 |
pp_instr_list ) |
|
157 |
in |
|
158 |
pp_procedure pp_step_procedure_name (build_pp_arg_step m) None fmt content |
|
177 | 159 |
|
178 |
(** Print the package definition(ads) of a machine. It requires the list of |
|
179 |
all typed instance. A typed submachine instance is (ident, type_machine) |
|
180 |
with ident the instance name and typed_machine is (substitution, machine) |
|
181 |
with machine the machine associated to the instance and substitution the |
|
182 |
instanciation of all its polymorphic types. @param fmt the formater to |
|
183 |
print on @param typed_submachines list of all typed machine instances of |
|
184 |
this machine @param m the machine **) |
|
185 |
let pp_file fmt (typed_submachines, ((opt_spec_machine, guarantees), machine)) |
|
186 |
= |
|
187 |
let env = List.map (fun x -> x.var_id, pp_state_name) machine.mmemory in |
|
188 |
let pp_reset fmt = |
|
189 |
if is_machine_statefull machine then |
|
190 |
fprintf fmt "%a;@,@," |
|
191 |
(pp_reset_definition env typed_submachines) |
|
192 |
(machine, opt_spec_machine) |
|
193 |
else fprintf fmt "" |
|
194 |
in |
|
195 |
let aux pkgs (id, _) = |
|
196 |
try |
|
197 |
let pkg, _ = List.assoc id ada_supported_funs in |
|
198 |
if List.mem pkg pkgs then pkgs else pkg :: pkgs |
|
199 |
with Not_found -> pkgs |
|
200 |
in |
|
201 |
let packages = List.map pp_str (List.fold_left aux [] machine.mcalls) in |
|
202 |
let pp_content fmt = |
|
203 |
fprintf fmt "%t%a" (*Define the reset procedure*) pp_reset |
|
204 |
(*Define the step procedure*) |
|
205 |
(pp_step_definition env typed_submachines) |
|
206 |
(machine, opt_spec_machine, guarantees) |
|
207 |
in |
|
208 |
fprintf fmt "%a%t%a;@." |
|
209 |
(* Include all the required packages*) |
|
210 |
(Utils.fprintf_list ~sep:";@," (pp_with AdaPrivate)) |
|
211 |
packages |
|
212 |
(Utils.pp_final_char_if_non_empty ";@,@," packages) |
|
213 |
(*Print package*) |
|
214 |
(pp_package (pp_package_name machine) [] true) |
|
215 |
pp_content |
|
216 |
end |
|
160 |
(** Print the definition of the reset procedure from a machine. |
|
161 |
|
|
162 |
@param typed_submachines list of all typed machine instances of this |
|
163 |
machine @param fmt the formater to print on @param machine the machine **) |
|
164 |
let pp_reset_definition env typed_submachines fmt (m, m_spec_opt) = |
|
165 |
let build_assign = function |
|
166 |
| var -> |
|
167 |
mkinstr (MStateAssign (var, mk_default_value var.var_type)) |
|
168 |
in |
|
169 |
let env, memory = |
|
170 |
match m_spec_opt with None -> env, m.mmemory | Some _ -> env, m.mmemory |
|
171 |
in |
|
172 |
let assigns = List.map build_assign memory in |
|
173 |
let pp_instr_list = |
|
174 |
List.map (pp_machine_instr typed_submachines env) (assigns @ m.minit) |
|
175 |
in |
|
176 |
pp_procedure pp_reset_procedure_name (build_pp_arg_reset m) None fmt |
|
177 |
(AdaProcedureContent ([], pp_instr_list)) |
|
178 |
|
|
179 |
(** Print the package definition(ads) of a machine. It requires the list of |
|
180 |
all typed instance. A typed submachine instance is (ident, type_machine) |
|
181 |
with ident the instance name and typed_machine is (substitution, machine) |
|
182 |
with machine the machine associated to the instance and substitution the |
|
183 |
instanciation of all its polymorphic types. @param fmt the formater to |
|
184 |
print on @param typed_submachines list of all typed machine instances of |
|
185 |
this machine @param m the machine **) |
|
186 |
let pp_file fmt (typed_submachines, ((opt_spec_machine, guarantees), machine)) |
|
187 |
= |
|
188 |
let env = List.map (fun x -> x.var_id, pp_state_name) machine.mmemory in |
|
189 |
let pp_reset fmt = |
|
190 |
if is_machine_statefull machine then |
|
191 |
fprintf fmt "%a;@,@," |
|
192 |
(pp_reset_definition env typed_submachines) |
|
193 |
(machine, opt_spec_machine) |
|
194 |
else fprintf fmt "" |
|
195 |
in |
|
196 |
let aux pkgs (id, _) = |
|
197 |
try |
|
198 |
let pkg, _ = List.assoc id ada_supported_funs in |
|
199 |
if List.mem pkg pkgs then pkgs else pkg :: pkgs |
|
200 |
with Not_found -> pkgs |
|
201 |
in |
|
202 |
let packages = List.map pp_str (List.fold_left aux [] machine.mcalls) in |
|
203 |
let pp_content fmt = |
|
204 |
fprintf fmt "%t%a" (*Define the reset procedure*) pp_reset |
|
205 |
(*Define the step procedure*) |
|
206 |
(pp_step_definition env typed_submachines) |
|
207 |
(machine, opt_spec_machine, guarantees) |
|
208 |
in |
|
209 |
fprintf fmt "%a%a;@." |
|
210 |
(* Include all the required packages*) |
|
211 |
(pp_print_list |
|
212 |
~pp_sep:pp_print_semicolon |
|
213 |
~pp_epilogue:(fun fmt () -> fprintf fmt ";@,@,") |
|
214 |
(pp_with AdaPrivate)) |
|
215 |
packages |
|
216 |
(*Print package*) |
|
217 |
(pp_package (pp_package_name machine) [] true) |
|
218 |
pp_content |
|
217 | 219 |
|
218 | 220 |
(* Local Variables: *) |
219 | 221 |
(* compile-command: "make -C ../../.." *) |
src/backends/Ada/ada_backend_adb.mli | ||
---|---|---|
1 |
open Utils |
|
2 |
open Machine_code_types |
|
3 |
|
|
4 |
(** Print the package definition(ads) of a machine. It requires the list of |
|
5 |
all typed instance. A typed submachine instance is (ident, type_machine) |
|
6 |
with ident the instance name and typed_machine is (substitution, machine) |
|
7 |
with machine the machine associated to the instance and substitution the |
|
8 |
instanciation of all its polymorphic types. @param fmt the formater to |
|
9 |
print on @param typed_submachines list of all typed machine instances of |
|
10 |
this machine @param m the machine **) |
|
11 |
val pp_file: Format.formatter -> (ident * ((tag * Types.t) list * machine_t)) list |
|
12 |
* ((machine_t option * ident list) * machine_t) -> unit |
src/backends/Ada/ada_backend_ads.ml | ||
---|---|---|
9 | 9 |
(* *) |
10 | 10 |
(********************************************************************) |
11 | 11 |
|
12 |
open Utils |
|
12 | 13 |
open Format |
13 | 14 |
open Machine_code_types |
14 | 15 |
open Lustre_types |
... | ... | |
17 | 18 |
open Ada_backend_common |
18 | 19 |
|
19 | 20 |
(** Functions printing the .ads file **) |
20 |
module Main = struct |
|
21 |
let rec init f = function i when i < 0 -> [] | i -> f i :: init f (i - 1) |
|
22 |
(*should be replaced by the init of list from ocaml std lib*) |
|
23 | 21 |
|
24 |
let suffixOld = "_old" |
|
22 |
let rec init f = function i when i < 0 -> [] | i -> f i :: init f (i - 1) |
|
23 |
(*should be replaced by the init of list from ocaml std lib*) |
|
25 | 24 |
|
26 |
let suffixNew = "_new"
|
|
25 |
let suffixOld = "_old"
|
|
27 | 26 |
|
28 |
let pp_invariant_name fmt = fprintf fmt "inv"
|
|
27 |
let suffixNew = "_new"
|
|
29 | 28 |
|
30 |
let pp_transition_name fmt = fprintf fmt "transition"
|
|
29 |
let pp_invariant_name fmt = fprintf fmt "inv"
|
|
31 | 30 |
|
32 |
let pp_init_name fmt = fprintf fmt "init"
|
|
31 |
let pp_transition_name fmt = fprintf fmt "transition"
|
|
33 | 32 |
|
34 |
let pp_state_name_predicate suffix fmt = |
|
35 |
fprintf fmt "%t%s" pp_state_name suffix |
|
33 |
let pp_init_name fmt = fprintf fmt "init" |
|
36 | 34 |
|
37 |
let pp_axiomatize_package_name fmt = fprintf fmt "axiomatize" |
|
35 |
let pp_state_name_predicate suffix fmt = |
|
36 |
fprintf fmt "%t%s" pp_state_name suffix |
|
38 | 37 |
|
39 |
(** Print the expression function representing the transition predicate. |
|
40 |
@param fmt the formater to print on **) |
|
41 |
let pp_init_predicate fmt () = |
|
42 |
let new_state = |
|
43 |
AdaIn, pp_state_name_predicate suffixNew, pp_state_type, None |
|
44 |
in |
|
45 |
pp_predicate pp_init_name [ [ new_state ] ] true fmt None |
|
38 |
let pp_axiomatize_package_name fmt = fprintf fmt "axiomatize" |
|
46 | 39 |
|
47 |
(** Print the expression function representing the transition predicate. |
|
48 |
@param fmt the formater to print on @param machine the machine **) |
|
49 |
let pp_transition_predicate fmt (_, m) = |
|
50 |
let old_state = |
|
51 |
AdaIn, pp_state_name_predicate suffixOld, pp_state_type, None |
|
52 |
in |
|
53 |
let new_state = |
|
54 |
AdaIn, pp_state_name_predicate suffixNew, pp_state_type, None |
|
55 |
in |
|
56 |
let inputs = build_pp_var_decl_step_input AdaIn None m in |
|
57 |
let outputs = build_pp_var_decl_step_output AdaIn None m in |
|
58 |
pp_predicate pp_transition_name |
|
59 |
([ [ old_state; new_state ] ] @ inputs @ outputs) |
|
60 |
true fmt None |
|
40 |
(** Print the expression function representing the transition predicate. |
|
41 |
@param fmt the formater to print on **) |
|
42 |
let pp_init_predicate fmt () = |
|
43 |
let new_state = |
|
44 |
AdaIn, pp_state_name_predicate suffixNew, pp_state_type, None |
|
45 |
in |
|
46 |
pp_predicate pp_init_name [ [ new_state ] ] true fmt None |
|
61 | 47 |
|
62 |
let pp_invariant_predicate fmt () = |
|
63 |
pp_predicate pp_invariant_name |
|
64 |
[ [ build_pp_state_decl AdaIn None ] ] |
|
65 |
true fmt None |
|
48 |
(** Print the expression function representing the transition predicate. |
|
49 |
@param fmt the formater to print on @param machine the machine **) |
|
50 |
let pp_transition_predicate fmt (_, m) = |
|
51 |
let old_state = |
|
52 |
AdaIn, pp_state_name_predicate suffixOld, pp_state_type, None |
|
53 |
in |
|
54 |
let new_state = |
|
55 |
AdaIn, pp_state_name_predicate suffixNew, pp_state_type, None |
|
56 |
in |
|
57 |
let inputs = build_pp_var_decl_step_input AdaIn None m in |
|
58 |
let outputs = build_pp_var_decl_step_output AdaIn None m in |
|
59 |
pp_predicate pp_transition_name |
|
60 |
([ [ old_state; new_state ] ] @ inputs @ outputs) |
|
61 |
true fmt None |
|
66 | 62 |
|
67 |
(** Print a new statement instantiating a generic package. @param fmt the |
|
68 |
formater to print on @param substitutions the instanciation substitution |
|
69 |
@param machine the machine to instanciate **) |
|
70 |
let pp_new_package fmt (substitutions, machine) = |
|
71 |
let pp_name = pp_package_name machine in |
|
72 |
let pp_new_name = pp_package_name_with_polymorphic substitutions machine in |
|
73 |
let instanciations = |
|
74 |
List.map |
|
75 |
(fun (id, typ) -> pp_polymorphic_type id, fun fmt -> pp_type fmt typ) |
|
76 |
substitutions |
|
77 |
in |
|
78 |
pp_package_instanciation pp_new_name pp_name fmt instanciations |
|
63 |
let pp_invariant_predicate fmt () = |
|
64 |
pp_predicate pp_invariant_name |
|
65 |
[ [ build_pp_state_decl AdaIn None ] ] |
|
66 |
true fmt None |
|
79 | 67 |
|
80 |
(** Remove duplicates from a list according to a given predicate. @param eq |
|
81 |
the predicate defining equality @param l the list to parse **) |
|
82 |
let remove_duplicates eq l = |
|
83 |
let aux l x = if List.exists (eq x) l then l else x :: l in |
|
84 |
List.fold_left aux [] l |
|
68 |
(** Print a new statement instantiating a generic package. @param fmt the |
|
69 |
formater to print on @param substitutions the instanciation substitution |
|
70 |
@param machine the machine to instanciate **) |
|
71 |
let pp_new_package fmt (substitutions, machine) = |
|
72 |
let pp_name = pp_package_name machine in |
|
73 |
let pp_new_name = pp_package_name_with_polymorphic substitutions machine in |
|
74 |
let instanciations = |
|
75 |
List.map |
|
76 |
(fun (id, typ) -> pp_polymorphic_type id, fun fmt -> pp_type fmt typ) |
|
77 |
substitutions |
|
78 |
in |
|
79 |
pp_package_instanciation pp_new_name pp_name fmt instanciations |
|
85 | 80 |
|
86 |
(** Compare two typed machines. **) |
|
87 |
let eq_typed_machine (subst1, machine1) (subst2, machine2) = |
|
88 |
String.equal machine1.mname.node_id machine2.mname.node_id |
|
89 |
&& List.for_all2 (fun a b -> pp_eq_type (snd a) (snd b)) subst1 subst2 |
|
81 |
(** Remove duplicates from a list according to a given predicate. @param eq |
|
82 |
the predicate defining equality @param l the list to parse **) |
|
83 |
let remove_duplicates eq l = |
|
84 |
let aux l x = if List.exists (eq x) l then l else x :: l in |
|
85 |
List.fold_left aux [] l |
|
90 | 86 |
|
91 |
(** Print the package declaration(ads) of a machine. It requires the list of |
|
92 |
all typed instance. A typed submachine is a (ident, typed_machine) with - |
|
93 |
ident: the name - typed_machine: a (substitution, machine) with - machine: |
|
94 |
the submachine struct - substitution the instanciation of all its |
|
95 |
polymorphic types. @param fmt the formater to print on @param |
|
96 |
typed_submachines list of all typed submachines of this machine @param m |
|
97 |
the machine **) |
|
98 |
let pp_file fmt (typed_submachines, ((m_spec_opt, guarantees), m)) = |
|
99 |
let typed_machines = snd (List.split typed_submachines) in |
|
100 |
let typed_machines_set = |
|
101 |
remove_duplicates eq_typed_machine typed_machines |
|
102 |
in |
|
87 |
(** Compare two typed machines. **) |
|
88 |
let eq_typed_machine (subst1, machine1) (subst2, machine2) = |
|
89 |
String.equal machine1.mname.node_id machine2.mname.node_id |
|
90 |
&& List.for_all2 (fun a b -> pp_eq_type (snd a) (snd b)) subst1 subst2 |
|
103 | 91 |
|
104 |
let machines_to_import = |
|
105 |
List.map pp_package_name (snd (List.split typed_machines_set)) |
|
106 |
in |
|
92 |
(** Print the package declaration(ads) of a machine. It requires the list of |
|
93 |
all typed instance. A typed submachine is a (ident, typed_machine) with - |
|
94 |
ident: the name - typed_machine: a (substitution, machine) with - machine: |
|
95 |
the submachine struct - substitution the instanciation of all its |
|
96 |
polymorphic types. @param fmt the formater to print on @param |
|
97 |
typed_submachines list of all typed submachines of this machine @param m |
|
98 |
the machine **) |
|
99 |
let pp_file fmt (typed_submachines, ((m_spec_opt, guarantees), m)) = |
|
100 |
let typed_machines = snd (List.split typed_submachines) in |
|
101 |
let typed_machines_set = |
|
102 |
remove_duplicates eq_typed_machine typed_machines |
|
103 |
in |
|
107 | 104 |
|
108 |
let polymorphic_types = find_all_polymorphic_type m in |
|
105 |
let machines_to_import = |
|
106 |
List.map pp_package_name (snd (List.split typed_machines_set)) |
|
107 |
in |
|
109 | 108 |
|
110 |
let typed_machines_to_instanciate = |
|
111 |
List.filter (fun (l, _) -> l != []) typed_machines_set |
|
112 |
in |
|
109 |
let polymorphic_types = find_all_polymorphic_type m in |
|
113 | 110 |
|
114 |
let typed_instances =
|
|
115 |
List.filter is_submachine_statefull typed_submachines
|
|
116 |
in
|
|
111 |
let typed_machines_to_instanciate =
|
|
112 |
List.filter (fun (l, _) -> l != []) typed_machines_set
|
|
113 |
in |
|
117 | 114 |
|
118 |
let memories = |
|
119 |
match m_spec_opt with |
|
120 |
| None -> |
|
121 |
[] |
|
122 |
| Some m -> |
|
123 |
List.map |
|
124 |
(fun x -> |
|
125 |
pp_var_decl |
|
126 |
(build_pp_var_decl AdaNoMode (Some (true, false, [], [])) x)) |
|
127 |
m.mmemory |
|
128 |
in |
|
129 |
let ghost_private = memories in |
|
130 |
(* Commented since not used. Could be reinjected in the code let vars_spec = |
|
131 |
match m_spec_opt with | None -> [] | Some m_spec -> List.map |
|
132 |
(build_pp_var_decl AdaNoMode (Some (true, false, [], []))) |
|
133 |
(m_spec.mmemory) in *) |
|
134 |
let vars = List.map (build_pp_var_decl AdaNoMode None) m.mmemory in |
|
135 |
let states = |
|
115 |
let typed_instances = |
|
116 |
List.filter is_submachine_statefull typed_submachines |
|
117 |
in |
|
118 |
|
|
119 |
let memories = |
|
120 |
match m_spec_opt with |
|
121 |
| None -> |
|
122 |
[] |
|
123 |
| Some m -> |
|
136 | 124 |
List.map |
137 |
(build_pp_state_decl_from_subinstance AdaNoMode None) |
|
138 |
typed_instances |
|
139 |
in |
|
140 |
let var_lists = |
|
141 |
(if states = [] then [] else [ states ]) |
|
142 |
@ if vars = [] then [] else [ vars ] |
|
143 |
in |
|
125 |
(fun x -> |
|
126 |
pp_var_decl |
|
127 |
(build_pp_var_decl AdaNoMode (Some (true, false, [], [])) x)) |
|
128 |
m.mmemory |
|
129 |
in |
|
130 |
let ghost_private = memories in |
|
131 |
(* Commented since not used. Could be reinjected in the code let vars_spec = |
|
132 |
match m_spec_opt with | None -> [] | Some m_spec -> List.map |
|
133 |
(build_pp_var_decl AdaNoMode (Some (true, false, [], []))) |
|
134 |
(m_spec.mmemory) in *) |
|
135 |
let vars = List.map (build_pp_var_decl AdaNoMode None) m.mmemory in |
|
136 |
let states = |
|
137 |
List.map |
|
138 |
(build_pp_state_decl_from_subinstance AdaNoMode None) |
|
139 |
typed_instances |
|
140 |
in |
|
141 |
let var_lists = |
|
142 |
(if states = [] then [] else [ states ]) |
|
143 |
@ if vars = [] then [] else [ vars ] |
|
144 |
in |
|
144 | 145 |
|
145 |
let pp_ifstatefull fmt pp =
|
|
146 |
if is_machine_statefull m then fprintf fmt "%t" pp else fprintf fmt ""
|
|
147 |
in
|
|
146 |
let pp_ifstatefull fmt pp = |
|
147 |
if is_machine_statefull m then fprintf fmt "%t" pp else fprintf fmt "" |
|
148 |
in |
|
148 | 149 |
|
149 |
let pp_state_decl_and_reset fmt = |
|
150 |
let init fmt = |
|
151 |
pp_call fmt |
|
152 |
( pp_access pp_axiomatize_package_name pp_init_name, |
|
153 |
[ [ pp_state_name ] ] ) |
|
154 |
in |
|
155 |
let contract = Some (false, false, [], [ init ]) in |
|
156 |
fprintf fmt "%t;@,@,%a;@,@," |
|
157 |
(*Declare the state type*) |
|
158 |
(pp_type_decl pp_state_type AdaPrivate) |
|
159 |
(*Declare the reset procedure*) |
|
160 |
(pp_procedure pp_reset_procedure_name (build_pp_arg_reset m) contract) |
|
161 |
AdaNoContent |
|
150 |
let pp_state_decl_and_reset fmt = |
|
151 |
let init fmt = |
|
152 |
pp_call fmt |
|
153 |
( pp_access pp_axiomatize_package_name pp_init_name, |
|
154 |
[ [ pp_state_name ] ] ) |
|
162 | 155 |
in |
156 |
let contract = Some (false, false, [], [ init ]) in |
|
157 |
fprintf fmt "%t;@,@,%a;@,@," |
|
158 |
(*Declare the state type*) |
|
159 |
(pp_type_decl pp_state_type AdaPrivate) |
|
160 |
(*Declare the reset procedure*) |
|
161 |
(pp_procedure pp_reset_procedure_name (build_pp_arg_reset m) contract) |
|
162 |
AdaNoContent |
|
163 |
in |
|
163 | 164 |
|
164 |
let pp_private_section fmt = |
|
165 |
fprintf fmt "@,private@,@,%a%t%a%t%a" |
|
166 |
(*Instantiate the polymorphic type that need to be instantiated*) |
|
167 |
(Utils.fprintf_list ~sep:";@," pp_new_package) |
|
168 |
typed_machines_to_instanciate |
|
169 |
(Utils.pp_final_char_if_non_empty ";@,@," typed_machines_to_instanciate) |
|
170 |
(*Define the state type*) |
|
171 |
pp_ifstatefull |
|
172 |
(fun fmt -> pp_record pp_state_type fmt var_lists) |
|
173 |
(Utils.pp_final_char_if_non_empty ";@,@," ghost_private) |
|
174 |
(Utils.fprintf_list ~sep:";@," (fun fmt pp -> pp fmt)) |
|
175 |
ghost_private |
|
176 |
in |
|
165 |
let pp_private_section fmt = |
|
166 |
fprintf fmt "@,private@,@,%a%a%a" |
|
167 |
(*Instantiate the polymorphic type that need to be instantiated*) |
|
168 |
(pp_print_list |
|
169 |
~pp_sep:pp_print_semicolon |
|
170 |
~pp_epilogue:(fun fmt () -> fprintf fmt ";@,@,") |
|
171 |
pp_new_package) |
|
172 |
typed_machines_to_instanciate |
|
173 |
(*Define the state type*) |
|
174 |
pp_ifstatefull |
|
175 |
(fun fmt -> pp_record pp_state_type fmt var_lists) |
|
176 |
(pp_print_list |
|
177 |
~pp_sep:pp_print_semicolon |
|
178 |
~pp_prologue:(fun fmt () -> fprintf fmt ";@,@,") |
|
179 |
(fun fmt pp -> pp fmt)) |
|
180 |
ghost_private |
|
181 |
in |
|
177 | 182 |
|
178 |
let pp_content fmt = |
|
179 |
let pp_contract_opt = |
|
180 |
let pp_var x fmt = pp_clean_ada_identifier fmt x in |
|
181 |
let guarantee_post_conditions = List.map pp_var guarantees in |
|
182 |
let state_pre_conditions, state_post_conditions = |
|
183 |
if is_machine_statefull m then |
|
184 |
let input = List.map pp_var_name m.mstep.step_inputs in |
|
185 |
let output = List.map pp_var_name m.mstep.step_outputs in |
|
186 |
let args = |
|
187 |
[ [ pp_old pp_state_name; pp_state_name ] ] |
|
188 |
@ (if input != [] then [ input ] else []) |
|
189 |
@ if output != [] then [ output ] else [] |
|
190 |
in |
|
191 |
let transition fmt = |
|
192 |
pp_call fmt |
|
193 |
(pp_access pp_axiomatize_package_name pp_transition_name, args) |
|
194 |
in |
|
195 |
let invariant fmt = |
|
196 |
pp_call fmt |
|
197 |
( pp_access pp_axiomatize_package_name pp_invariant_name, |
|
198 |
[ [ pp_state_name ] ] ) |
|
199 |
in |
|
200 |
[ invariant ], [ transition; invariant ] |
|
201 |
else [], [] |
|
202 |
in |
|
203 |
let post_conditions = |
|
204 |
state_post_conditions @ guarantee_post_conditions |
|
205 |
in |
|
206 |
let pre_conditions = state_pre_conditions in |
|
207 |
if post_conditions = [] && pre_conditions = [] then None |
|
208 |
else Some (false, false, pre_conditions, post_conditions) |
|
183 |
let pp_content fmt = |
|
184 |
let pp_contract_opt = |
|
185 |
let pp_var x fmt = pp_clean_ada_identifier fmt x in |
|
186 |
let guarantee_post_conditions = List.map pp_var guarantees in |
|
187 |
let state_pre_conditions, state_post_conditions = |
|
188 |
if is_machine_statefull m then |
|
189 |
let input = List.map pp_var_name m.mstep.step_inputs in |
|
190 |
let output = List.map pp_var_name m.mstep.step_outputs in |
|
191 |
let args = |
|
192 |
[ [ pp_old pp_state_name; pp_state_name ] ] |
|
193 |
@ (if input != [] then [ input ] else []) |
|
194 |
@ if output != [] then [ output ] else [] |
|
195 |
in |
|
196 |
let transition fmt = |
|
197 |
pp_call fmt |
|
198 |
(pp_access pp_axiomatize_package_name pp_transition_name, args) |
|
199 |
in |
|
200 |
let invariant fmt = |
|
201 |
pp_call fmt |
|
202 |
( pp_access pp_axiomatize_package_name pp_invariant_name, |
|
203 |
[ [ pp_state_name ] ] ) |
|
204 |
in |
|
205 |
[ invariant ], [ transition; invariant ] |
|
206 |
else [], [] |
|
209 | 207 |
in |
210 |
let pp_guarantee name = |
|
211 |
pp_var_decl |
|
212 |
( AdaNoMode, |
|
213 |
(fun fmt -> pp_clean_ada_identifier fmt name), |
|
214 |
pp_boolean_type, |
|
215 |
Some (true, false, [], []) ) |
|
208 |
let post_conditions = |
|
209 |
state_post_conditions @ guarantee_post_conditions |
|
216 | 210 |
in |
217 |
let ghost_public = List.map pp_guarantee guarantees in |
|
218 |
fprintf fmt "@,%a%t%a%a%a@,@,%a;@,@,%t" |
|
219 |
(Utils.fprintf_list ~sep:";@," (fun fmt pp -> pp fmt)) |
|
220 |
ghost_public |
|
221 |
(Utils.pp_final_char_if_non_empty ";@,@," ghost_public) |
|
222 |
pp_ifstatefull pp_state_decl_and_reset |
|
223 |
(*Declare the step procedure*) |
|
224 |
(pp_procedure pp_step_procedure_name (build_pp_arg_step m) |
|
225 |
pp_contract_opt) |
|
226 |
AdaNoContent pp_ifstatefull |
|
227 |
(fun fmt -> fprintf fmt ";@,") |
|
228 |
(pp_package pp_axiomatize_package_name [] false) |
|
229 |
(fun fmt -> |
|
230 |
fprintf fmt |
|
231 |
"pragma Annotate (GNATProve, External_Axiomatization);@,\ |
|
232 |
@,\ |
|
233 |
%a;@,\ |
|
234 |
%a;@,\ |
|
235 |
%a" |
|
236 |
(*Declare the init predicate*) |
|
237 |
pp_init_predicate () |
|
238 |
(*Declare the transition predicate*) |
|
239 |
pp_transition_predicate (m_spec_opt, m) |
|
240 |
(*Declare the invariant predicate*) |
|
241 |
pp_invariant_predicate ()) |
|
242 |
(*Print the private section*) |
|
243 |
pp_private_section |
|
211 |
let pre_conditions = state_pre_conditions in |
|
212 |
if post_conditions = [] && pre_conditions = [] then None |
|
213 |
else Some (false, false, pre_conditions, post_conditions) |
|
214 |
in |
|
215 |
let pp_guarantee name = |
|
216 |
pp_var_decl |
|
217 |
( AdaNoMode, |
|
218 |
(fun fmt -> pp_clean_ada_identifier fmt name), |
|
219 |
pp_boolean_type, |
|
220 |
Some (true, false, [], []) ) |
|
244 | 221 |
in |
222 |
let ghost_public = List.map pp_guarantee guarantees in |
|
223 |
fprintf fmt "@,%a%a%a%a@,@,%a;@,@,%t" |
|
224 |
(pp_print_list |
|
225 |
~pp_sep:pp_print_semicolon |
|
226 |
~pp_epilogue:(fun fmt () -> fprintf fmt ";@,@,") |
|
227 |
(fun fmt pp -> pp fmt)) |
|
228 |
ghost_public |
|
229 |
pp_ifstatefull pp_state_decl_and_reset |
|
230 |
(*Declare the step procedure*) |
|
231 |
(pp_procedure pp_step_procedure_name (build_pp_arg_step m) |
|
232 |
pp_contract_opt) |
|
233 |
AdaNoContent pp_ifstatefull |
|
234 |
(fun fmt -> fprintf fmt ";@,") |
|
235 |
(pp_package pp_axiomatize_package_name [] false) |
|
236 |
(fun fmt -> |
|
237 |
fprintf fmt |
|
238 |
"pragma Annotate (GNATProve, External_Axiomatization);@,\ |
|
239 |
@,\ |
|
240 |
%a;@,\ |
|
241 |
%a;@,\ |
|
242 |
%a" |
|
243 |
(*Declare the init predicate*) |
|
244 |
pp_init_predicate () |
|
245 |
(*Declare the transition predicate*) |
|
246 |
pp_transition_predicate (m_spec_opt, m) |
|
247 |
(*Declare the invariant predicate*) |
|
248 |
pp_invariant_predicate ()) |
|
249 |
(*Print the private section*) |
|
250 |
pp_private_section |
|
251 |
in |
|
245 | 252 |
|
246 |
let pp_poly_type id = pp_type_decl (pp_polymorphic_type id) AdaPrivate in
|
|
247 |
let pp_generics = List.map pp_poly_type polymorphic_types in
|
|
253 |
let pp_poly_type id = pp_type_decl (pp_polymorphic_type id) AdaPrivate in |
|
254 |
let pp_generics = List.map pp_poly_type polymorphic_types in |
|
248 | 255 |
|
249 |
fprintf fmt "@[<v>%a%t%a;@]@." |
|
250 |
(* Include all the subinstance package*) |
|
251 |
(Utils.fprintf_list ~sep:";@," (pp_with AdaNoVisibility)) |
|
252 |
machines_to_import |
|
253 |
(Utils.pp_final_char_if_non_empty ";@,@," machines_to_import) |
|
254 |
(*Begin the package*) |
|
255 |
(pp_package (pp_package_name m) pp_generics false) |
|
256 |
pp_content |
|
257 |
end |
|
256 |
fprintf fmt "@[<v>%a%a;@]@." |
|
257 |
(* Include all the subinstance package*) |
|
258 |
(pp_print_list |
|
259 |
~pp_sep:pp_print_semicolon |
|
260 |
~pp_epilogue:(fun fmt () -> fprintf fmt ";@,@,") |
|
261 |
(pp_with AdaNoVisibility)) |
|
262 |
machines_to_import |
|
263 |
(*Begin the package*) |
|
264 |
(pp_package (pp_package_name m) pp_generics false) |
|
265 |
pp_content |
src/backends/Ada/ada_backend_ads.mli | ||
---|---|---|
1 |
open Utils |
|
2 |
open Machine_code_types |
|
3 |
|
|
4 |
(** Print the package declaration(ads) of a machine. It requires the list of |
|
5 |
all typed instance. A typed submachine is a (ident, typed_machine) with - |
|
6 |
ident: the name - typed_machine: a (substitution, machine) with - machine: |
|
7 |
the submachine struct - substitution the instanciation of all its |
|
8 |
polymorphic types. @param fmt the formater to print on @param |
|
9 |
typed_submachines list of all typed submachines of this machine @param m |
|
10 |
the machine **) |
|
11 |
val pp_file: Format.formatter -> (ident * ((tag * Types.t) list * machine_t)) list |
|
12 |
* ((machine_t option * ident list) * machine_t) -> unit |
src/backends/Ada/ada_backend_common.ml | ||
---|---|---|
1 |
open Utils |
|
1 | 2 |
open Format |
2 | 3 |
open Machine_code_types |
3 | 4 |
open Lustre_types |
... | ... | |
73 | 74 |
|
74 | 75 |
(** Print a type. @param fmt the formater to print on @param type the type **) |
75 | 76 |
let pp_type fmt typ = |
76 |
match (Types.repr typ).Types.tdesc with |
|
77 |
| Types.Tbasic Types.Basic.Tint -> |
|
77 |
let open Types in |
|
78 |
let t = repr typ in |
|
79 |
if is_bool_type t then |
|
80 |
pp_boolean_type fmt |
|
81 |
else if is_int_type t then |
|
78 | 82 |
pp_integer_type fmt |
79 |
| Types.Tbasic Types.Basic.Treal ->
|
|
83 |
else if is_real_type t then
|
|
80 | 84 |
pp_float_type fmt |
81 |
| Types.Tbasic Types.Basic.Tbool -> |
|
82 |
pp_boolean_type fmt |
|
83 |
| Types.Tunivar -> |
|
84 |
pp_polymorphic_type typ.Types.tid fmt |
|
85 |
| Types.Tbasic _ -> |
|
86 |
eprintf "Tbasic@."; |
|
87 |
assert false (*TODO*) |
|
88 |
| Types.Tconst _ -> |
|
89 |
eprintf "Tconst@."; |
|
90 |
assert false (*TODO*) |
|
91 |
| Types.Tclock _ -> |
|
92 |
eprintf "Tclock@."; |
|
93 |
assert false (*TODO*) |
|
94 |
| Types.Tarrow _ -> |
|
95 |
eprintf "Tarrow@."; |
|
96 |
assert false (*TODO*) |
|
97 |
| Types.Ttuple l -> |
|
98 |
eprintf "Ttuple %a @." (Utils.fprintf_list ~sep:" " Types.print_ty) l; |
|
99 |
assert false (*TODO*) |
|
100 |
| Types.Tenum _ -> |
|
101 |
eprintf "Tenum@."; |
|
102 |
assert false (*TODO*) |
|
103 |
| Types.Tstruct _ -> |
|
104 |
eprintf "Tstruct@."; |
|
105 |
assert false (*TODO*) |
|
106 |
| Types.Tarray _ -> |
|
107 |
eprintf "Tarray@."; |
|
108 |
assert false (*TODO*) |
|
109 |
| Types.Tstatic _ -> |
|
110 |
eprintf "Tstatic@."; |
|
111 |
assert false (*TODO*) |
|
112 |
| Types.Tlink _ -> |
|
113 |
eprintf "Tlink@."; |
|
114 |
assert false (*TODO*) |
|
115 |
| Types.Tvar -> |
|
116 |
eprintf "Tvar@."; |
|
117 |
assert false |
|
85 |
else match t.tdesc with |
|
86 |
| Tunivar -> |
|
87 |
pp_polymorphic_type typ.tid fmt |
|
88 |
| Tbasic _ -> |
|
89 |
eprintf "Tbasic@."; |
|
90 |
assert false (*TODO*) |
|
91 |
| Tconst _ -> |
|
92 |
eprintf "Tconst@."; |
|
93 |
assert false (*TODO*) |
|
94 |
| Tclock _ -> |
|
95 |
eprintf "Tclock@."; |
|
96 |
assert false (*TODO*) |
|
97 |
| Tarrow _ -> |
|
98 |
eprintf "Tarrow@."; |
|
99 |
assert false (*TODO*) |
|
100 |
| Ttuple l -> |
|
101 |
eprintf "Ttuple %a @." (pp_print_list print_ty) l; |
|
102 |
assert false (*TODO*) |
|
103 |
| Tenum _ -> |
|
104 |
eprintf "Tenum@."; |
|
105 |
assert false (*TODO*) |
|
106 |
| Tstruct _ -> |
|
107 |
eprintf "Tstruct@."; |
|
108 |
assert false (*TODO*) |
|
109 |
| Tarray _ -> |
|
110 |
eprintf "Tarray@."; |
|
111 |
assert false (*TODO*) |
|
112 |
| Tstatic _ -> |
|
113 |
eprintf "Tstatic@."; |
|
114 |
assert false (*TODO*) |
|
115 |
| Tlink _ -> |
|
116 |
eprintf "Tlink@."; |
|
117 |
assert false (*TODO*) |
|
118 |
| Tvar -> |
|
119 |
eprintf "Tvar@."; |
|
120 |
assert false |
|
118 | 121 |
(*TODO*) |
119 | 122 |
(*| _ -> eprintf "Type error : %a@." Types.print_ty typ; assert false *) |
120 | 123 |
|
121 | 124 |
(** Return a default ada constant for a given type. @param cst_typ the constant |
122 | 125 |
type **) |
123 |
let default_ada_cst cst_typ = |
|
124 |
match cst_typ with |
|
125 |
| Types.Basic.Tint -> |
|
126 |
let default_ada_cst t = |
|
127 |
let open Types in |
|
128 |
if is_bool_type t then |
|
129 |
Const_tag tag_false |
|
130 |
else if is_int_type t then |
|
126 | 131 |
Const_int 0 |
127 |
| Types.Basic.Treal ->
|
|
132 |
else if is_real_type t then
|
|
128 | 133 |
Const_real Real.zero |
129 |
| Types.Basic.Tbool -> |
|
130 |
Const_tag tag_false |
|
131 |
| _ -> |
|
134 |
else |
|
132 | 135 |
assert false |
133 | 136 |
|
134 | 137 |
(** Make a default value from a given type. @param typ the type **) |
135 | 138 |
let mk_default_value typ = |
136 |
match (Types.repr typ).Types.tdesc with |
|
137 |
| Types.Tbasic t -> |
|
139 |
let t = Types.repr typ in |
|
140 |
match t.Types.tdesc with |
|
141 |
| Types.Tbasic _ -> |
|
138 | 142 |
mk_val (Cst (default_ada_cst t)) typ |
139 | 143 |
| _ -> |
140 | 144 |
assert false |
... | ... | |
156 | 160 |
(fun poly1 (poly2, _) -> poly1 = poly2) |
157 | 161 |
polymorphic_types substituion); |
158 | 162 |
let instantiated_types = snd (List.split substitution) in |
159 |
fprintf fmt "%t%t%a" (pp_package_name machine) |
|
160 |
(Utils.pp_final_char_if_non_empty "_" instantiated_types) |
|
161 |
(Utils.fprintf_list ~sep:"_" pp_type) |
|
163 |
fprintf fmt "%t%a" |
|
164 |
(pp_package_name machine) |
|
165 |
(pp_print_list |
|
166 |
~pp_prologue:(fun fmt () -> pp_print_string fmt "_") |
|
167 |
~pp_sep:(fun fmt () -> pp_print_string fmt "_") |
|
168 |
pp_type) |
|
162 | 169 |
instantiated_types |
163 | 170 |
|
164 | 171 |
(** Print the name of a variable. @param fmt the formater to print on @param id |
src/backends/Ada/ada_backend_common.mli | ||
---|---|---|
29 | 29 |
|
30 | 30 |
val pp_value : (string * printer) list -> formatter -> value_t -> unit |
31 | 31 |
|
32 |
val pp_type : formatter -> type_expr -> unit
|
|
32 |
val pp_type : formatter -> Types.t -> unit
|
|
33 | 33 |
|
34 | 34 |
val pp_var_type : formatter -> var_decl -> unit |
35 | 35 |
|
36 | 36 |
val pp_package_name : machine_t -> printer |
37 | 37 |
|
38 | 38 |
val pp_package_name_with_polymorphic : |
39 |
(int * Types.type_expr) list -> machine_t -> printer
|
|
39 |
(int * Types.t) list -> machine_t -> printer |
|
40 | 40 |
|
41 |
val mk_default_value : type_expr -> value_t
|
|
41 |
val mk_default_value : Types.t -> value_t
|
|
42 | 42 |
|
43 | 43 |
val build_pp_var_decl : parameter_mode -> ada_with -> var_decl -> ada_var_decl |
44 | 44 |
|
... | ... | |
57 | 57 |
val build_pp_state_decl_from_subinstance : |
58 | 58 |
parameter_mode -> |
59 | 59 |
ada_with -> |
60 |
string * ((int * Types.type_expr) list * Machine_code_types.machine_t) ->
|
|
60 |
string * ((int * Types.t) list * Machine_code_types.machine_t) -> |
|
61 | 61 |
ada_var_decl |
62 | 62 |
|
63 | 63 |
val build_pp_state_decl : parameter_mode -> ada_with -> ada_var_decl |
src/backends/Ada/ada_backend_wrapper.ml | ||
---|---|---|
9 | 9 |
(* *) |
10 | 10 |
(********************************************************************) |
11 | 11 |
|
12 |
open Utils |
|
12 | 13 |
open Format |
13 | 14 |
open Machine_code_types |
14 | 15 |
open Lustre_types |
... | ... | |
17 | 18 |
open Ada_printer |
18 | 19 |
open Ada_backend_common |
19 | 20 |
|
20 |
module Main = struct |
|
21 |
let build_text_io_package_local typ = |
|
22 |
AdaLocalPackage |
|
23 |
( (fun fmt -> fprintf fmt "%s_IO" typ), |
|
24 |
(fun fmt -> fprintf fmt "Ada.Text_IO.%s_IO" typ), |
|
25 |
[ ((fun fmt -> fprintf fmt "Num"), fun fmt -> fprintf fmt "%s" typ) ] ) |
|
21 |
let build_text_io_package_local typ = |
|
22 |
AdaLocalPackage |
|
23 |
( (fun fmt -> fprintf fmt "%s_IO" typ), |
|
24 |
(fun fmt -> fprintf fmt "Ada.Text_IO.%s_IO" typ), |
|
25 |
[ ((fun fmt -> fprintf fmt "Num"), fun fmt -> fprintf fmt "%s" typ) ] ) |
|
26 | 26 |
|
27 |
(** Print the main file calling in a loop the step function of the main
|
|
28 |
machine. @param fmt the formater to print on @param machine the main
|
|
29 |
machine **)
|
|
30 |
let pp_main_adb fmt machine =
|
|
31 |
let statefull = is_machine_statefull machine in
|
|
27 |
(** Print the main file calling in a loop the step function of the main |
|
28 |
machine. @param fmt the formater to print on @param machine the main |
|
29 |
machine **) |
|
30 |
let pp_main_adb fmt machine = |
|
31 |
let statefull = is_machine_statefull machine in |
|
32 | 32 |
|
33 |
let pp_package = pp_package_name_with_polymorphic [] machine in
|
|
33 |
let pp_package = pp_package_name_with_polymorphic [] machine in |
|
34 | 34 |
|
35 |
(* Dependances *)
|
|
36 |
let text_io = "Ada.Text_IO" in
|
|
35 |
(* Dependances *) |
|
36 |
let text_io = "Ada.Text_IO" in |
|
37 | 37 |
|
38 |
(* Locals *) |
|
39 |
let locals = |
|
38 |
(* Locals *) |
|
39 |
let locals = |
|
40 |
[ |
|
40 | 41 |
[ |
41 |
[ |
|
42 |
build_text_io_package_local "Integer"; |
|
43 |
build_text_io_package_local "Float"; |
|
44 |
]; |
|
45 |
] |
|
46 |
@ (if statefull then |
|
42 |
build_text_io_package_local "Integer"; |
|
43 |
build_text_io_package_local "Float"; |
|
44 |
]; |
|
45 |
] |
|
46 |
@ (if statefull then |
|
47 | 47 |
[ |
48 | 48 |
[ |
49 | 49 |
AdaLocalVar |
... | ... | |
51 | 51 |
(asprintf "%t" pp_state_name, ([], machine))); |
52 | 52 |
]; |
53 | 53 |
] |
54 |
else [])
|
|
55 |
@ (if machine.mstep.step_inputs != [] then
|
|
54 |
else []) |
|
55 |
@ (if machine.mstep.step_inputs != [] then |
|
56 | 56 |
[ List.map (build_pp_var_decl_local None) machine.mstep.step_inputs ] |
57 |
else []) |
|
58 |
@ |
|
59 |
if machine.mstep.step_outputs != [] then |
|
60 |
[ List.map (build_pp_var_decl_local None) machine.mstep.step_outputs ] |
|
61 |
else [] |
|
62 |
in |
|
63 |
|
|
64 |
(* Stream instructions *) |
|
65 |
let get_basic var = |
|
66 |
match (Types.repr var.var_type).Types.tdesc with |
|
67 |
| Types.Tbasic x -> |
|
68 |
x |
|
69 |
| _ -> |
|
70 |
assert false |
|
71 |
in |
|
72 |
let pp_read fmt var = |
|
73 |
match get_basic var with |
|
74 |
| Types.Basic.Tbool -> |
|
75 |
fprintf fmt "%t := Integer'Value(Ada.Text_IO.Get_Line) /= 0" |
|
76 |
(pp_var_name var) |
|
77 |
| _ -> |
|
78 |
fprintf fmt "%t := %a'Value(Ada.Text_IO.Get_Line)" (pp_var_name var) |
|
79 |
pp_var_type var |
|
80 |
in |
|
81 |
let pp_write fmt var = |
|
82 |
match get_basic var with |
|
83 |
| Types.Basic.Tbool -> |
|
84 |
fprintf fmt |
|
85 |
"Ada.Text_IO.Put_Line(\"'%t': '\" & (if %t then \"1\" else \"0\") & \ |
|
86 |
\"' \")" |
|
87 |
(pp_var_name var) (pp_var_name var) |
|
88 |
| Types.Basic.Tint -> |
|
89 |
fprintf fmt |
|
90 |
"Ada.Text_IO.Put(\"'%t': '\");@,\ |
|
91 |
Integer_IO.Put(%t);@,\ |
|
92 |
Ada.Text_IO.Put_Line(\"' \")" (pp_var_name var) (pp_var_name var) |
|
93 |
| Types.Basic.Treal -> |
|
94 |
fprintf fmt |
|
95 |
"Ada.Text_IO.Put(\"'%t': '\");@,\ |
|
96 |
Float_IO.Put(%t, Fore=>0, Aft=> 15, Exp => 0);@,\ |
|
97 |
Ada.Text_IO.Put_Line(\"' \")" (pp_var_name var) (pp_var_name var) |
|
98 |
| Types.Basic.Tstring | Types.Basic.Trat -> |
|
99 |
assert false |
|
100 |
(* Could not be the top level inputs *) |
|
101 |
in |
|
102 |
|
|
103 |
(* Loop instructions *) |
|
104 |
let pp_loop fmt = |
|
105 |
let args = |
|
106 |
pp_state_name |
|
107 |
:: |
|
108 |
List.map pp_var_name |
|
109 |
(machine.mstep.step_inputs @ machine.mstep.step_outputs) |
|
110 |
in |
|
57 |
else []) |
|
58 |
@ |
|
59 |
if machine.mstep.step_outputs != [] then |
|
60 |
[ List.map (build_pp_var_decl_local None) machine.mstep.step_outputs ] |
|
61 |
else [] |
|
62 |
in |
|
63 |
|
|
64 |
(* Stream instructions *) |
|
65 |
let get_type var = Types.repr var.var_type in |
|
66 |
let pp_read fmt var = |
|
67 |
if Types.is_bool_type (get_type var) then |
|
68 |
fprintf fmt "%t := Integer'Value(Ada.Text_IO.Get_Line) /= 0" |
|
69 |
(pp_var_name var) |
|
70 |
else |
|
71 |
fprintf fmt "%t := %a'Value(Ada.Text_IO.Get_Line)" (pp_var_name var) |
|
72 |
pp_var_type var |
|
73 |
in |
|
74 |
let pp_write fmt var = |
|
75 |
let t = get_type var in |
|
76 |
if Types.is_bool_type t then |
|
77 |
fprintf fmt |
|
78 |
"Ada.Text_IO.Put_Line(\"'%t': '\" & (if %t then \"1\" else \"0\") & \ |
|
79 |
\"' \")" |
|
80 |
(pp_var_name var) (pp_var_name var) |
|
81 |
else if Types.is_int_type t then |
|
111 | 82 |
fprintf fmt |
112 |
"while not Ada.Text_IO.End_Of_File loop@,\ |
|
113 |
\ @[<v>%a;@,\ |
|
114 |
%a;@,\ |
|
115 |
%a;@]@,\ |
|
116 |
end loop" |
|
117 |
(Utils.fprintf_list ~sep:";@," pp_read) |
|
118 |
machine.mstep.step_inputs pp_call |
|
119 |
(pp_package_access (pp_package, pp_step_procedure_name), [ args ]) |
|
120 |
(Utils.fprintf_list ~sep:";@," pp_write) |
|
121 |
machine.mstep.step_outputs |
|
83 |
"Ada.Text_IO.Put(\"'%t': '\");@,\ |
|
84 |
Integer_IO.Put(%t);@,\ |
|
85 |
Ada.Text_IO.Put_Line(\"' \")" (pp_var_name var) (pp_var_name var) |
|
86 |
else if Types.is_real_type t then |
|
87 |
fprintf fmt |
|
88 |
"Ada.Text_IO.Put(\"'%t': '\");@,\ |
|
89 |
Float_IO.Put(%t, Fore=>0, Aft=> 15, Exp => 0);@,\ |
|
90 |
Ada.Text_IO.Put_Line(\"' \")" (pp_var_name var) (pp_var_name var) |
|
91 |
else |
|
92 |
assert false |
|
93 |
(* Could not be the top level inputs *) |
|
94 |
in |
|
95 |
|
|
96 |
(* Loop instructions *) |
|
97 |
let pp_loop fmt = |
|
98 |
let args = |
|
99 |
pp_state_name |
|
100 |
:: |
|
101 |
List.map pp_var_name |
|
102 |
(machine.mstep.step_inputs @ machine.mstep.step_outputs) |
|
122 | 103 |
in |
123 |
|
|
124 |
(* Print the file *) |
|
125 |
let instrs = |
|
126 |
(if statefull then |
|
104 |
fprintf fmt |
|
105 |
"while not Ada.Text_IO.End_Of_File loop@,\ |
|
106 |
\ @[<v>%a;@,\ |
|
107 |
%a;@,\ |
|
108 |
%a;@]@,\ |
|
109 |
end loop" |
|
110 |
(pp_print_list ~pp_sep:pp_print_semicolon pp_read) |
|
111 |
machine.mstep.step_inputs pp_call |
|
112 |
(pp_package_access (pp_package, pp_step_procedure_name), [ args ]) |
|
113 |
(pp_print_list ~pp_sep:pp_print_semicolon pp_write) |
|
114 |
machine.mstep.step_outputs |
|
115 |
in |
|
116 |
|
|
117 |
(* Print the file *) |
|
118 |
let instrs = |
|
119 |
(if statefull then |
|
127 | 120 |
[ |
128 | 121 |
(fun fmt -> |
129 |
pp_call fmt |
|
130 |
( pp_package_access (pp_package, pp_reset_procedure_name), |
|
131 |
[ [ pp_state_name ] ] )); |
|
122 |
pp_call fmt
|
|
123 |
( pp_package_access (pp_package, pp_reset_procedure_name),
|
|
124 |
[ [ pp_state_name ] ] ));
|
|
132 | 125 |
] |
133 |
else []) |
|
134 |
@ [ pp_loop ] |
|
135 |
in |
|
136 |
fprintf fmt "@[<v>%a;@,%a;@,@,%a;@]" (pp_with AdaPrivate) (pp_str text_io) |
|
137 |
(pp_with AdaPrivate) (pp_package_name machine) |
|
138 |
(pp_procedure pp_main_procedure_name [] None) |
|
139 |
(AdaProcedureContent (locals, instrs)) |
|
140 |
|
|
141 |
(** Print the name of the ada project configuration file. @param fmt the |
|
142 |
formater to print on @param main_machine the machine associated to the |
|
143 |
main node **) |
|
144 |
let pp_project_configuration_name fmt basename = fprintf fmt "%s.adc" basename |
|
145 |
|
|
146 |
(** Print the project configuration file. @param fmt the formater to print on |
|
147 |
**) |
|
148 |
let pp_project_configuration_file fmt = fprintf fmt "pragma SPARK_Mode (On);" |
|
149 |
|
|
150 |
(** Print the name of the ada project file. @param base_name name of the |
|
151 |
lustre file @param fmt the formater to print on **) |
|
152 |
let pp_project_name basename fmt = fprintf fmt "%s.gpr" basename |
|
153 |
|
|
154 |
let pp_for_single name arg fmt = fprintf fmt "for %s use \"%s\"" name arg |
|
155 |
|
|
156 |
let pp_for name args fmt = |
|
157 |
fprintf fmt "for %s use (@[%a@])" name |
|
158 |
(Utils.fprintf_list ~sep:",@ " (fun fmt arg -> fprintf fmt "\"%s\"" arg)) |
|
159 |
args |
|
160 |
|
|
161 |
let pp_content fmt lines = |
|
162 |
fprintf fmt " @[<v>%a%t@]" |
|
163 |
(Utils.fprintf_list ~sep:";@," (fun fmt pp -> fprintf fmt "%t" pp)) |
|
164 |
lines |
|
165 |
(Utils.pp_final_char_if_non_empty ";" lines) |
|
166 |
|
|
167 |
let pp_package name lines fmt = |
|
168 |
fprintf fmt "package %s is@,%a@,end %s" name pp_content lines name |
|
169 |
|
|
170 |
(** Print the gpr project file, if there is a machine in machine_opt then an |
|
171 |
executable project is made else it is a library. @param fmt the formater |
|
172 |
to print on @param machine_opt the main machine option **) |
|
173 |
let pp_project_file machines basename fmt machine_opt = |
|
174 |
let adbs = |
|
175 |
List.map (asprintf "%a" (pp_machine_filename "adb")) machines |
|
176 |
@ |
|
177 |
match machine_opt with |
|
178 |
| None -> |
|
179 |
[] |
|
180 |
| Some m -> |
|
181 |
[ asprintf "%a" pp_main_filename m ] |
|
182 |
in |
|
183 |
let project_name = |
|
184 |
basename ^ if machine_opt = None then "_lib" else "_exe" |
|
185 |
in |
|
186 |
fprintf fmt "%sproject %s is@,%a@,end %s;" |
|
187 |
(if machine_opt = None then "library " else "") |
|
188 |
project_name pp_content |
|
189 |
((match machine_opt with |
|
190 |
| None -> |
|
126 |
else []) |
|
127 |
@ [ pp_loop ] |
|
128 |
in |
|
129 |
fprintf fmt "@[<v>%a;@,%a;@,@,%a;@]" (pp_with AdaPrivate) (pp_str text_io) |
|
130 |
(pp_with AdaPrivate) (pp_package_name machine) |
|
131 |
(pp_procedure pp_main_procedure_name [] None) |
|
132 |
(AdaProcedureContent (locals, instrs)) |
|
133 |
|
|
134 |
(** Print the name of the ada project configuration file. @param fmt the |
|
135 |
formater to print on @param main_machine the machine associated to the |
|
136 |
main node **) |
|
137 |
let pp_project_configuration_name fmt basename = fprintf fmt "%s.adc" basename |
|
138 |
|
|
139 |
(** Print the project configuration file. @param fmt the formater to print on |
|
140 |
**) |
|
141 |
let pp_project_configuration_file fmt = fprintf fmt "pragma SPARK_Mode (On);" |
|
142 |
|
|
143 |
(** Print the name of the ada project file. @param base_name name of the |
|
144 |
lustre file @param fmt the formater to print on **) |
|
145 |
let pp_project_name basename fmt = fprintf fmt "%s.gpr" basename |
|
146 |
|
|
147 |
let pp_for_single name arg fmt = fprintf fmt "for %s use \"%s\"" name arg |
|
148 |
|
|
149 |
let pp_for name args fmt = |
|
150 |
fprintf fmt "for %s use (@[%a@])" name |
|
151 |
(pp_comma_list (fun fmt arg -> fprintf fmt "\"%s\"" arg)) |
|
152 |
args |
|
153 |
|
|
154 |
let pp_content fmt lines = |
|
155 |
fprintf fmt " @[<v>%a%a@]" |
|
156 |
(pp_print_list ~pp_sep:pp_print_semicolon (fun fmt pp -> fprintf fmt "%t" pp)) |
|
157 |
lines |
|
158 |
(if lines = [] then pp_print_nothing else pp_print_semicolon) () |
|
159 |
|
|
160 |
let pp_package name lines fmt = |
|
161 |
fprintf fmt "package %s is@,%a@,end %s" name pp_content lines name |
|
162 |
|
|
163 |
(** Print the gpr project file, if there is a machine in machine_opt then an |
|
164 |
executable project is made else it is a library. @param fmt the formater |
|
165 |
to print on @param machine_opt the main machine option **) |
|
166 |
let pp_project_file machines basename fmt machine_opt = |
|
167 |
let adbs = |
|
168 |
List.map (asprintf "%a" (pp_machine_filename "adb")) machines |
|
169 |
@ |
|
170 |
match machine_opt with |
|
171 |
| None -> |
|
172 |
[] |
|
173 |
| Some m -> |
|
174 |
[ asprintf "%a" pp_main_filename m ] |
|
175 |
in |
|
176 |
let project_name = |
|
177 |
basename ^ if machine_opt = None then "_lib" else "_exe" |
|
178 |
in |
Also available in: Unified diff
another step towards refactoring