1
|
(********************************************************************)
|
2
|
(* *)
|
3
|
(* The LustreC compiler toolset / The LustreC Development Team *)
|
4
|
(* Copyright 2012 - -- ONERA - CNRS - INPT - ISAE-SUPAERO *)
|
5
|
(* *)
|
6
|
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *)
|
7
|
(* under the terms of the GNU Lesser General Public License *)
|
8
|
(* version 2.1. *)
|
9
|
(* *)
|
10
|
(********************************************************************)
|
11
|
|
12
|
open Format
|
13
|
|
14
|
open Machine_code_types
|
15
|
open Lustre_types
|
16
|
open Corelang
|
17
|
open Machine_code_common
|
18
|
|
19
|
open Ada_backend_common
|
20
|
|
21
|
(** Functions printing the .ads file **)
|
22
|
module Main =
|
23
|
struct
|
24
|
|
25
|
(** Print name of a node associated to an instance.
|
26
|
@param fmt the formater to print on
|
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)
|
55
|
(Utils.fprintf_list ~sep:";@;" (pp_machine_var_decl NoMode)) var_list
|
56
|
(Utils.pp_final_char_if_non_empty ";" var_list)
|
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
|
|
65
|
(** Print the package declaration(ads) of a machine.
|
66
|
@param fmt the formater to print on
|
67
|
@param machine the machine
|
68
|
**)
|
69
|
let print fmt machine =
|
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)
|
85
|
(pp_begin_package false) machine (*Begin the package*)
|
86
|
pp_private_type_decl pp_state_type (*Declare the state type*)
|
87
|
pp_init_prototype machine (*Declare the init procedure*)
|
88
|
pp_step_prototype machine (*Declare the step procedure*)
|
89
|
pp_reset_prototype machine (*Declare the reset procedure*)
|
90
|
pp_clear_prototype machine (*Declare the clear procedure*)
|
91
|
pp_type_decl (pp_state_type, pp_record) (*Define the state type*)
|
92
|
pp_end_package machine (*End the package*)
|
93
|
|
94
|
end
|