Revision 7cbb6d8a
Added by Guillaume DAVY over 5 years ago
src/backends/Ada/ada_backend_ads.ml | ||
---|---|---|
22 | 22 |
module Main = |
23 | 23 |
struct |
24 | 24 |
|
25 |
(** Print a record definition.
|
|
25 |
(** Print name of a node associated to an instance.
|
|
26 | 26 |
@param fmt the formater to print on |
27 |
@param var_list list of machine variable |
|
28 |
*) |
|
29 |
let pp_record_definition fmt var_list = |
|
30 |
fprintf fmt "@, @[<v>record@, @[<v>%a%t@]@,end record@]" |
|
27 |
@param instance the instance |
|
28 |
**) |
|
29 |
let pp_instance_node_name fmt instance = |
|
30 |
let (_, (node, _)) = instance in |
|
31 |
let node = match node.top_decl_desc with |
|
32 |
| Node nd -> nd |
|
33 |
| _ -> assert false (*TODO*) in |
|
34 |
pp_package_name fmt node |
|
35 |
|
|
36 |
(** Print the declaration of a state element of a subinstance of a machine. |
|
37 |
@param fmt the formater to print on |
|
38 |
@param instance the instance |
|
39 |
**) |
|
40 |
let pp_machine_subinstance_state_decl fmt instance = |
|
41 |
let (name, (node, static)) = instance in |
|
42 |
let pp_package fmt = pp_instance_node_name fmt instance in |
|
43 |
let pp_type fmt = pp_package_access fmt (pp_package, pp_state_type) in |
|
44 |
let pp_name fmt = print_clean_ada_identifier fmt name in |
|
45 |
pp_var_decl fmt (NoMode, pp_name, pp_type) |
|
46 |
|
|
47 |
(** Print the state record for a machine. |
|
48 |
@param fmt the formater to print on |
|
49 |
@param machine the machine |
|
50 |
**) |
|
51 |
let pp_state_record_definition fmt (var_list, instances) = |
|
52 |
fprintf fmt "@, @[<v>record@, @[<v>%a%t%a%t@]@,end record@]" |
|
53 |
(Utils.fprintf_list ~sep:";@;" pp_machine_subinstance_state_decl) instances |
|
54 |
(Utils.pp_final_char_if_non_empty ";@," instances) |
|
31 | 55 |
(Utils.fprintf_list ~sep:";@;" (pp_machine_var_decl NoMode)) var_list |
32 | 56 |
(Utils.pp_final_char_if_non_empty ";" var_list) |
33 | 57 |
|
58 |
(** Print a with statement to include an instance. |
|
59 |
@param fmt the formater to print on |
|
60 |
@param instance the instance |
|
61 |
**) |
|
62 |
let pp_with_subinstance fmt instance = |
|
63 |
fprintf fmt "private with %a" pp_instance_node_name instance |
|
64 |
|
|
34 | 65 |
(** Print the package declaration(ads) of a machine. |
35 | 66 |
@param fmt the formater to print on |
36 | 67 |
@param machine the machine |
37 |
*) |
|
68 |
**)
|
|
38 | 69 |
let print fmt machine = |
39 |
let pp_record fmt = pp_record_definition fmt machine.mmemory in |
|
40 |
fprintf fmt "%a@, @[<v>@,%a;@,@,%a;@,@,%a;@,@,%a;@,@,%a;@,@,private@,@,%a;@,@]@,%a;@." |
|
70 |
(* Take apart the arrow instance from the instance list and transform them |
|
71 |
into simple boolean variable *) |
|
72 |
let extract (instances, arrows) instance = |
|
73 |
let (name, (node, static)) = instance in |
|
74 |
if String.equal (node_name node) Arrow.arrow_id then |
|
75 |
(instances, (dummy_var_decl name Type_predef.type_bool)::arrows) |
|
76 |
else |
|
77 |
(instance::instances, arrows) in |
|
78 |
let instances, arrows = List.fold_left extract ([], []) machine.minstances in |
|
79 |
(* Add the boolean variable reated for arrow instance to the list of all variable *) |
|
80 |
let var_list = arrows@machine.mmemory in |
|
81 |
let pp_record fmt = pp_state_record_definition fmt (var_list, instances) in |
|
82 |
fprintf fmt "@[<v>%a%t@,%a@, @[<v>@,%a;@,@,%a;@,@,%a;@,@,%a;@,@,%a;@,@,private@,@,%a;@,@]@,%a;@.@]" |
|
83 |
(Utils.fprintf_list ~sep:";@," pp_with_subinstance) instances (* Include all the subinstance*) |
|
84 |
(Utils.pp_final_char_if_non_empty ";@," instances) |
|
41 | 85 |
(pp_begin_package false) machine (*Begin the package*) |
42 | 86 |
pp_private_type_decl pp_state_type (*Declare the state type*) |
43 | 87 |
pp_init_prototype machine (*Declare the init procedure*) |
Also available in: Unified diff
Ada: Add to the machine state all its subinstance states. Improve also identifier cleaning