taste-deployment_view.ads 7.23 KB
Newer Older
1
2
3
4
5
6
--  *************************** taste aadl parser ***********************  --
--  (c) 2017 European Space Agency - maxime.perrotin@esa.int
--  LGPL license, see LICENSE file

--  Deployment View parser

7
with Ada.Containers.Indefinite_Ordered_Maps,
8
9
     Ada.Containers.Indefinite_Vectors,
     Ada.Strings.Unbounded,
10
     Text_IO,
11
     Templates_Parser,
12
13
     Ocarina,
     Ocarina.Types,
14
     Ocarina.Backends.Properties,
15
     Option_Type,
16
     TASTE.Parser_Utils;
17

18
19
20
use Ada.Containers,
    Ada.Strings.Unbounded,
    Text_IO,
21
    Templates_Parser,
22
    Ocarina,
23
    Ocarina.Types,
24
    Ocarina.Backends.Properties,
25
    TASTE.Parser_Utils;
26

27
package TASTE.Deployment_View is
28

29
   use String_Vectors,
30
       String_Sets;
31
32
33

   --  Exceptions specific to the deployment view
   Deployment_View_Error       : exception;
34
   Device_Driver_Error         : exception;
35
36
   Empty_Deployment_View_Error : exception;

Maxime Perrotin's avatar
Maxime Perrotin committed
37
   --  List of Ocarina AADL models needed to parse the deployment view
38
39
40
41
   AADL_Lib : String_Vectors.Vector :=
     Empty_Vector
     & "TASTE_DV_Properties.aadl"
     & "TASTE_IV_Properties.aadl"
42
     & "ocarina_components.aadl"
43
44
45
46
47
48
49
50
51
52
53
54
55
56
     & "aadl_project.aadl"
     & "taste_properties.aadl"
     & "Cheddar_Properties.aadl"
     & "communication_properties.aadl"
     & "deployment_properties.aadl"
     & "thread_properties.aadl"
     & "timing_properties.aadl"
     & "programming_properties.aadl"
     & "memory_properties.aadl"
     & "modeling_properties.aadl"
     & "arinc653.aadl"
     & "base_types.aadl"
     & "data_model.aadl"
     & "deployment.aadl";
Maxime Perrotin's avatar
Maxime Perrotin committed
57

58
59
   --  Initialize Ocarina and instantiate the deployment view, return root.
   function Initialize (Root : Node_Id) return Node_Id
60
     with Pre => Root /= No_Node;
61
62
63

   type Taste_Bus is
      record
Maxime Perrotin's avatar
Maxime Perrotin committed
64
65
66
67
         Name         : Unbounded_String;
         AADL_Package : Unbounded_String;
         Classifier   : Unbounded_String;
         Properties   : Property_Maps.Map;
68
69
70
71
      end record;

   package Taste_Busses is new Indefinite_Vectors (Natural, Taste_Bus);

72
   type Bus_Connection is tagged
73
74
75
76
77
78
79
80
      record
         Source_Node : Unbounded_String;
         Source_Port : Unbounded_String;
         Bus_Name    : Unbounded_String;
         Dest_Node   : Unbounded_String;
         Dest_Port   : Unbounded_String;
      end record;

81
82
83
84
85
86
87
   function To_Template (B : Bus_Connection) return Translate_Set is
     (+Assoc ("Source_Node",  B.Source_Node)
      & Assoc ("Source_Port", B.Source_Port)
      & Assoc ("Bus_Name",    B.Bus_Name)
      & Assoc ("Dest_Node",   B.Dest_Node)
      & Assoc ("Dest_Port",   B.Dest_Port));

88
89
   package Bus_Connections is new Indefinite_Vectors (Natural, Bus_Connection);

90
   type Taste_Device_Driver is tagged
91
92
      record
         Name                      : Unbounded_String;
93
         Package_Name              : Unbounded_String;
94
95
96
97
98
99
100
101
102
103
         Device_Classifier         : Unbounded_String;
         Associated_Processor_Name : Unbounded_String;
         Device_Configuration      : Unbounded_String;
         Accessed_Bus_Name         : Unbounded_String;
         Accessed_Port_Name        : Unbounded_String;
         ASN1_Filename             : Unbounded_String;
         ASN1_Typename             : Unbounded_String;
         ASN1_Module               : Unbounded_String;
      end record;

104
105
106
107
108
109
110
111
112
113
114
115
   function To_Template (D : Taste_Device_Driver) return Translate_Set is
     (+Assoc ("Name",                       D.Name)
      & Assoc ("Package_Name",              D.Package_Name)
      & Assoc ("Device_Classifier",         D.Device_Classifier)
      & Assoc ("Associated_Processor_Name", D.Associated_Processor_Name)
      & Assoc ("Device_Configuration",      D.Device_Configuration)
      & Assoc ("Accessed_Bus_Name",         D.Accessed_Bus_Name)
      & Assoc ("Accessed_Port_Name",        D.Accessed_Port_Name)
      & Assoc ("ASN1_Filename",             D.ASN1_Filename)
      & Assoc ("ASN1_Typename",             D.ASN1_Typename)
      & Assoc ("ASN1_Module",               D.ASN1_Module));

116
117
118
   package Taste_Drivers is
     new Indefinite_Vectors (Natural, Taste_Device_Driver);

119
120
121
122
123
   --  Partition in the deployment view
   --  Supported_Execution_Platform is defined in:
   --  ocarina/src/backends/ocarina-backends-properties.ads
   --  Values are Plaform_Native, Platform_Leon_Rtems, etc.
   type Taste_Partition is tagged
124
125
      record
         Name            : Unbounded_String;
126
         Coverage        : Boolean := False;
127
128
129
130
         Package_Name    : Unbounded_String;
         CPU_Name        : Unbounded_String;
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
131
         Ada_Runtime     : Unbounded_String;  --  when Platform = GNAT_Runtime
132
         Bound_Functions : String_Sets.Set;
133
134
      end record;

135
136
137
138
139
140
141
142
   --  Make a Templates Parser translate set, to generate code
   function To_Template (P : Taste_Partition) return Translate_Set is
      (+Assoc  ("Name",            P.Name)
       & Assoc ("Coverage",        P.Coverage)
       & Assoc ("Package_Name",    P.Package_Name)
       & Assoc ("CPU_Name",        P.CPU_Name)
       & Assoc ("CPU_Platform",    P.CPU_Platform'Img)
       & Assoc ("CPU_Classifier",  P.CPU_Classifier)
143
       & Assoc ("Ada_Runtime",     P.Ada_Runtime)
144
145
       & Assoc ("Bound_Functions", To_Template_Tag (P.Bound_Functions)));

146
147
   package Option_Partition is new Option_Type (Taste_Partition);

148
149
150
   package Taste_Partitions is
      new Indefinite_Ordered_Maps (String, Taste_Partition);

Maxime Perrotin's avatar
Maxime Perrotin committed
151
   type Taste_Node is tagged
152
      record
153
154
155
156
157
158
         Name            : Unbounded_String;
         Drivers         : Taste_Drivers.Vector;
         Partitions      : Taste_Partitions.Map;
         CPU_Name        : Unbounded_String;
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
159
         Ada_Runtime     : Unbounded_String;  --  when Platform = GNAT_Runtime
160
161
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
162
163
164
165
166
   --  Helper function: find the partition where a function is bounded
   function Find_Partition (Node          : Taste_Node;
                            Function_Name : String)
                            return Option_Partition.Option;

167
168
   package Node_Maps is new Indefinite_Ordered_Maps (String, Taste_Node);

169
170
   type Complete_Deployment_View is tagged
      record
171
172
173
         Nodes       : Node_Maps.Map;
         Connections : Bus_Connections.Vector;
         Busses      : Taste_Busses.Vector;
174
175
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
176
177
178
179
180
   --  Helper function: find the node of a given function
   package Option_Node is new Option_Type (Taste_Node);
   function Find_Node (Deployment    : Complete_Deployment_View;
                       Function_Name : String) return Option_Node.Option;

181
   --  Function to build up the Ada AST by transforming the one from Ocarina
Maxime Perrotin's avatar
Maxime Perrotin committed
182
183
184
   function Parse_Deployment_View (System : Node_Id)
                                   return Complete_Deployment_View
   with Pre => System /= No_Node;
185
186
187
188
189
190
191
192
   procedure Dump_Nodes       (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Dump_Connections (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Dump_Busses      (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Debug_Dump       (DV     : Complete_Deployment_View;
                               Output : File_Type);
193

194
end TASTE.Deployment_View;