taste-deployment_view.ads 9.12 KB
Newer Older
1
2
3
--  *************************** taste/kazoo ***********************  --
--  (c) 2019 Maxime Perrotin / European Space Agency
--  contact: maxime.perrotin@esa.int
4
5
6
7
--  LGPL license, see LICENSE file

--  Deployment View parser

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

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

28
package TASTE.Deployment_View is
29

30
   use String_Vectors,
31
       String_Sets;
32
33
34

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

Maxime Perrotin's avatar
Maxime Perrotin committed
38
   --  List of Ocarina AADL models needed to parse the deployment view
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
   AADL_Lib : String_Vectors.Vector :=
     Empty_Vector
     & "TASTE_DV_Properties.aadl"
     & "TASTE_IV_Properties.aadl"
     & "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);

Maxime Perrotin's avatar
Maxime Perrotin committed
119
120
121
122
123
124
125
   --  Memory component specified at node level
   type Taste_Memory is
      record
         Name             : Unbounded_String;
         Bound_Partitions : String_Sets.Set;
      end record;

126
127
128
129
130
   --  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
131
132
      record
         Name            : Unbounded_String;
133
         Coverage        : Boolean := False;
134
         Package_Name    : Unbounded_String;
135
136
137
         CPU_Name        : Unbounded_String; --  AADL Identifier
         CPU_Family      : Unbounded_String; --  e.g. leon3
         CPU_Instance    : Unbounded_String; --  e.g. rtems_posix
138
139
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
Maxime Perrotin's avatar
Maxime Perrotin committed
140
         CPU_Total_Time  : Unbounded_String := US ("");  -- TSP major frame
141
142
143
144
         VP_Package_Name : Unbounded_String := US ("");  -- Virtual Processor
         VP_Name         : Unbounded_String := US ("");
         VP_Platform     : Supported_Execution_Platform := Platform_None;
         VP_Classifier   : Unbounded_String := US ("");
Maxime Perrotin's avatar
Maxime Perrotin committed
145
         VP_Duration     : Unbounded_String := US ("");  --  TSP frame duration
Maxime Perrotin's avatar
Maxime Perrotin committed
146
         Memory_Region   : Unbounded_String := US ("");  --  TSP only
147
         Ada_Runtime     : Unbounded_String; --  if CPU_Platform = GNAT_Runtime
148
         Bound_Functions : String_Sets.Set;
149
150
      end record;

151
152
153
154
155
156
   --  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)
157
158
       & Assoc ("CPU_Family",      P.CPU_Family)
       & Assoc ("CPU_Instance",    P.CPU_Instance)
159
160
       & Assoc ("CPU_Platform",    P.CPU_Platform'Img)
       & Assoc ("CPU_Classifier",  P.CPU_Classifier)
161
162
163
164
       & AssoC ("VP_Package_Name", P.VP_Package_Name)
       & Assoc ("VP_Name",         P.VP_Name)
       & Assoc ("VP_Platform",     P.VP_Platform'Img)
       & Assoc ("VP_Classifier",   P.VP_Classifier)
Maxime Perrotin's avatar
Maxime Perrotin committed
165
       & Assoc ("VP_Duration",     P.VP_Duration)
Maxime Perrotin's avatar
Maxime Perrotin committed
166
       & Assoc ("Memory_Region",   P.Memory_Region)
167
       & Assoc ("Ada_Runtime",     P.Ada_Runtime)
168
169
       & Assoc ("Bound_Functions", To_Template_Tag (P.Bound_Functions)));

170
171
   package Option_Partition is new Option_Type (Taste_Partition);

172
   package Taste_Partitions is
Maxime Perrotin's avatar
Maxime Perrotin committed
173
174
175
176
177
178
179
180
181
182
183
184
185
     new Indefinite_Ordered_Maps (String, Taste_Partition);

   --  Virtual processors are used in TSP systems to represent partitions
   type Virtual_Processor is tagged
      record
         Name,
         Package_Name,
         Platform,
         Classifier : Unbounded_String;
      end record;

   package Virtual_Processors is
      new Indefinite_Ordered_Maps (String, Virtual_Processor);
186

Maxime Perrotin's avatar
Maxime Perrotin committed
187
   type Taste_Node is tagged
188
      record
189
190
191
         Name            : Unbounded_String;
         Drivers         : Taste_Drivers.Vector;
         Partitions      : Taste_Partitions.Map;
Maxime Perrotin's avatar
Maxime Perrotin committed
192
         Memory          : Taste_Memory;
Maxime Perrotin's avatar
Maxime Perrotin committed
193
194
         Virtual_CPUs    : Virtual_Processors.Map;
         Package_Name    : Unbounded_String;
195
196
197
         CPU_Name        : Unbounded_String;   --  AADL Identifier
         CPU_Family      : Unbounded_String;   --  e.g. leon3
         CPU_Instance    : Unbounded_String;   --  e.g. rtems_posix
198
199
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
Maxime Perrotin's avatar
Maxime Perrotin committed
200
         CPU_Duration    : Unbounded_String := US ("");  -- TSP Major frame
201
         Ada_Runtime     : Unbounded_String;  --  when Platform = GNAT_Runtime
202
203
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
204
205
206
207
208
   --  Helper function: find the partition where a function is bounded
   function Find_Partition (Node          : Taste_Node;
                            Function_Name : String)
                            return Option_Partition.Option;

209
210
   package Node_Maps is new Indefinite_Ordered_Maps (String, Taste_Node);

211
212
   type Complete_Deployment_View is tagged
      record
213
214
215
         Nodes       : Node_Maps.Map;
         Connections : Bus_Connections.Vector;
         Busses      : Taste_Busses.Vector;
216
217
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
218
219
220
221
222
   --  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;

223
   --  Function to build up the Ada AST by transforming the one from Ocarina
Maxime Perrotin's avatar
Maxime Perrotin committed
224
225
226
   function Parse_Deployment_View (System : Node_Id)
                                   return Complete_Deployment_View
   with Pre => System /= No_Node;
227
228
229
230
231
232
233
234
   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);
235

236
end TASTE.Deployment_View;