buildsupport_utils.adb 14.3 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
--  *************************** buildsupport ****************************  --
Maxime Perrotin's avatar
Maxime Perrotin committed
2
--  (c) 2008-2017 European Space Agency - maxime.perrotin@esa.int
Maxime Perrotin's avatar
Maxime Perrotin committed
3
4
5
6
7
--  LGPL license, see LICENSE file

with Ada.Text_IO;
with GNAT.OS_Lib;

Maxime Perrotin's avatar
Maxime Perrotin committed
8
with Buildsupport_Version;
9
--  with Ocarina.Namet;
Maxime Perrotin's avatar
Maxime Perrotin committed
10
with Ocarina.Configuration;
Maxime Perrotin's avatar
Maxime Perrotin committed
11
with Ocarina.AADL_Values;
Maxime Perrotin's avatar
Maxime Perrotin committed
12
with Ocarina.Instances.Queries;
Maxime Perrotin's avatar
Maxime Perrotin committed
13
14
--  with Ocarina.ME_AADL.AADL_Tree.Nodes;
--  with Ocarina.ME_AADL.AADL_Instances.Nodes;
Maxime Perrotin's avatar
Maxime Perrotin committed
15
16
17
18
19
20
21
22
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ada.Characters.Latin_1;

package body Buildsupport_Utils is

   use Ada.Text_IO;
   use GNAT.OS_Lib;

23
--   use Ocarina.Namet;
Maxime Perrotin's avatar
Maxime Perrotin committed
24
   use Ocarina.Instances.Queries;
Maxime Perrotin's avatar
Maxime Perrotin committed
25
--   use Ocarina.ME_AADL.AADL_Instances.Nodes;
Maxime Perrotin's avatar
Maxime Perrotin committed
26
27
   use Ocarina.ME_AADL.AADL_Instances.Nutils;
   use Ada.Characters.Latin_1;
Maxime Perrotin's avatar
Maxime Perrotin committed
28
29
30
--  package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
--  package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
--   use type ATN.Node_Kind;
Maxime Perrotin's avatar
Maxime Perrotin committed
31
32
33
34
35
36
37

   ------------
   -- Banner --
   ------------

   procedure Banner is
      The_Banner : constant String :=
Maxime Perrotin's avatar
Maxime Perrotin committed
38
39
40
41
        "TASTE Buildsupport (Version "
        & Buildsupport_Version.Buildsupport_Release & ") "
        & ASCII.LF & ASCII.CR
        & "Contact: Maxime.Perrotin@esa.int or Thanassis.Tsiodras@esa.int"
Maxime Perrotin's avatar
Maxime Perrotin committed
42
        & ASCII.LF & ASCII.CR
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
43
        & "Based on Ocarina: " & Ocarina.Configuration.Ocarina_Version;
Maxime Perrotin's avatar
Maxime Perrotin committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
   begin
      Put_Line (The_Banner);
   end Banner;

   -----------
   -- Usage --
   -----------

   procedure Usage is
   begin
      Put_Line
        ("Usage: buildsupport <options> otherfiles");
      Put_Line
        ("Where <options> are:");
      New_Line;
      Put ("-l, --glue" & HT & HT & HT & HT);
      Put_Line ("Generate glue code");
      Put ("-w, --gw" & HT & HT & HT & HT);
      Put_Line ("Generate code skeletons");
      Put ("-j, --keep-case" & HT & HT & HT & HT);
      Put_Line ("Respect the case for interface names");
      Put ("-o, --output <outputDir>" & HT & HT);
      Put_Line ("Root directory for the output files");
      Put ("-i, --interfaceview <i_view.aadl>" & HT);
      Put_Line ("The interface view in AADL");
      Put ("-c, --deploymentview <d_view.aadl>" & HT);
      Put_Line ("The deployment view in AADL");
      Put ("-d, --dataview <dataview.aadl>" & HT & HT);
      Put_Line ("The data view in AADL");
      Put ("-t, --test" & HT & HT & HT & HT);
      Put_Line ("Dump model information");
      Put ("-g, --debug" & HT & HT & HT & HT);
      Put_Line ("Generate runtime debug output");
      Put ("-s, --stack <stack-value>" & HT & HT);
78
79
80
      Put_Line ("Set the size of the stack per thread in kbytes (default 50)");
      Put ("-x, --timer <timer-resolution in ms>" & HT);
      Put_Line ("Set the timer resolution (default 100 ms)");
Maxime Perrotin's avatar
Maxime Perrotin committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
      Put ("-v, --version" & HT & HT & HT & HT);
      Put_Line ("Display buildsupport version number");
      Put ("-p, --polyorb-hi-c" & HT & HT & HT);
      Put_Line ("Interface glue code with PolyORB-HI-C");
      Put ("otherfiles" & HT & HT & HT & HT);
      Put_Line ("Any other aadl file you want to parse");
      New_Line;
      New_Line;
      Put_Line ("For example, this command will generate your application"
       & " skeletons:");
      New_Line;
      Put_Line ("buildsupport -i InterfaceView.aadl -d DataView.aadl"
       & " -o code --gw --keep-case");
      New_Line;

   end Usage;

   -------------------
   -- Exit_On_Error --
   -------------------

   procedure Exit_On_Error (Error : Boolean; Reason : String) is
   begin
      if Error then
         Put_Line (Reason);
         --  Imported_Routines.C_End;
         OS_Exit (1);
      end if;
   end Exit_On_Error;

   ----------------------------
   -- Get_RCM_Operation_Kind --
   ----------------------------

   function Get_RCM_Operation_Kind
     (E : Node_Id) return Supported_RCM_Operation_Kind
   is
      RCM_Operation_Kind_N : Name_Id;
Maxime Perrotin's avatar
Maxime Perrotin committed
119
120
121
122
123
124
      RCM_Operation_Kind : constant Name_Id :=
          Get_String_Name ("taste::rcmoperationkind");
      Unprotected_Name   : constant Name_Id := Get_String_Name ("unprotected");
      Protected_Name     : constant Name_Id := Get_String_Name ("protected");
      Cyclic_Name        : constant Name_Id := Get_String_Name ("cyclic");
      Sporadic_Name      : constant Name_Id := Get_String_Name ("sporadic");
Maxime Perrotin's avatar
Maxime Perrotin committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
   begin
      if Is_Defined_Enumeration_Property (E, RCM_Operation_Kind) then
         RCM_Operation_Kind_N
           := Get_Enumeration_Property (E, RCM_Operation_Kind);

         if RCM_Operation_Kind_N = Unprotected_Name then
            return Unprotected_Operation;

         elsif RCM_Operation_Kind_N =  Protected_Name then
            return Protected_Operation;

         elsif RCM_Operation_Kind_N =  Cyclic_Name then
            return Cyclic_Operation;

         elsif RCM_Operation_Kind_N =  Sporadic_Name then
            return Sporadic_Operation;
         end if;
      end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
143
      Exit_On_Error (True, "Could not determine interface kind");
Maxime Perrotin's avatar
Maxime Perrotin committed
144
      return Sporadic_Operation;
Maxime Perrotin's avatar
Maxime Perrotin committed
145
146
147
148
149
150
151
   end Get_RCM_Operation_Kind;

   -----------------------
   -- Get_RCM_Operation --
   -----------------------

   function Get_RCM_Operation (E : Node_Id) return Node_Id is
Maxime Perrotin's avatar
Maxime Perrotin committed
152
153
      RCM_Operation : constant Name_Id :=
          Get_String_Name ("taste::rcmoperation");
Maxime Perrotin's avatar
Maxime Perrotin committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
   begin
      if Is_Subprogram_Access (E) then
         return Corresponding_Instance (E);
      else
         if Is_Defined_Property (E, RCM_Operation) then
            return Get_Classifier_Property (E, RCM_Operation);
         else
            return No_Node;
         end if;
      end if;
   end Get_RCM_Operation;

   -----------------------
   -- Get_APLC_Binding --
   -----------------------

   function Get_APLC_Binding (E : Node_Id) return List_Id is
Maxime Perrotin's avatar
Maxime Perrotin committed
171
172
      APLC_Binding : constant Name_Id :=
          Get_String_Name ("taste::aplc_binding");
Maxime Perrotin's avatar
Maxime Perrotin committed
173
174
175
176
177
178
179
180
181
182
183
184
185
   begin
      if Is_Defined_Property (E, APLC_Binding) then
         return Get_List_Property (E, APLC_Binding);
      else
         return No_List;
      end if;
   end Get_APLC_Binding;

   --------------------
   -- Get_RCM_Period --
   --------------------

   function Get_RCM_Period (D : Node_Id) return Unsigned_Long_Long is
Maxime Perrotin's avatar
Maxime Perrotin committed
186
      RCM_Period : constant Name_Id := Get_String_Name ("taste::rcmperiod");
Maxime Perrotin's avatar
Maxime Perrotin committed
187
188
189
190
191
192
193
194
195
196
197
198
199
   begin
      if Is_Defined_Integer_Property (D, RCM_Period) then
         return Get_Integer_Property (D, RCM_Period);
      else
         return 0;
      end if;
   end Get_RCM_Period;

   --------------------------
   -- Get_Ada_Package_Name --
   --------------------------

   function Get_Ada_Package_Name (D : Node_Id) return Name_Id is
Maxime Perrotin's avatar
Maxime Perrotin committed
200
201
      Ada_Package_Name : constant Name_id :=
         Get_String_Name ("taste::ada_package_name");
Maxime Perrotin's avatar
Maxime Perrotin committed
202
203
204
205
206
207
208
209
210
   begin
      return Get_String_Property (D, Ada_Package_Name);
   end Get_Ada_Package_Name;

   -------------------------------
   -- Get_Ellidiss_Tool_Version --
   -------------------------------

   function Get_Ellidiss_Tool_Version (D : Node_Id) return Name_Id is
Maxime Perrotin's avatar
Maxime Perrotin committed
211
212
      Ellidiss_Tool_Version : constant Name_id :=
         Get_String_Name ("taste::version");
Maxime Perrotin's avatar
Maxime Perrotin committed
213
214
215
216
217
218
219
220
221
   begin
      return Get_String_Property (D, Ellidiss_Tool_Version);
   end Get_Ellidiss_Tool_Version;

   ------------------------
   -- Get_Interface_Name --
   ------------------------

   function Get_Interface_Name (D : Node_Id) return Name_Id is
Maxime Perrotin's avatar
Maxime Perrotin committed
222
223
      Interface_Name : constant Name_id :=
         Get_String_Name ("taste::interfacename");
Maxime Perrotin's avatar
Maxime Perrotin committed
224
225
226
227
228
229
230
231
232
233
   begin
      return Get_String_Property (D, Interface_Name);
   end Get_Interface_Name;

   ---------------------------
   -- Get ASN.1 Module name --
   ---------------------------

   function Get_ASN1_Module_Name (D : Node_Id) return String is
      id : Name_Id := No_Name;
Maxime Perrotin's avatar
Maxime Perrotin committed
234
235
      ASN1_Module : constant Name_id :=
         Get_String_Name ("deployment::asn1_module_name");
Maxime Perrotin's avatar
Maxime Perrotin committed
236
237
238
239
240
241
242
243
244
   begin
      if Is_Defined_String_Property (D, ASN1_Module) then
         id := Get_String_Property (D, ASN1_Module);
         return Get_Name_String (id);
      else
         return Get_Name_String (Get_String_Name ("nomodule"));
      end if;
   end Get_ASN1_Module_Name;

Maxime Perrotin's avatar
Maxime Perrotin committed
245
246
247
248
249
   --------------------------------------------
   -- Get all properties as a Map Key/String --
   -- Input parameter is an AADL instance    --
   --------------------------------------------
   function Get_Properties_Map (D : Node_Id) return Property_Maps.Map is
Maxime Perrotin's avatar
Maxime Perrotin committed
250
      properties : constant List_Id  := AIN.Properties (D);
Maxime Perrotin's avatar
Maxime Perrotin committed
251
      result     : Property_Maps.Map := Empty_Map;
Maxime Perrotin's avatar
Maxime Perrotin committed
252
      property   : Node_Id           := AIN.First_Node (properties);
253
254
      prop_value : Node_Id;
      single_val : Node_Id;
Maxime Perrotin's avatar
Maxime Perrotin committed
255
256
   begin
      while Present (property) loop
257
258
259
260
         prop_value := AIN.Property_Association_Value (property);
         if Present (ATN.Single_Value (prop_value)) then
            --  Only support single-value properties for now
            single_val := ATN.Single_Value (prop_value);
Maxime Perrotin's avatar
Maxime Perrotin committed
261
            result.Insert (Key => AIN_Case (property),
Maxime Perrotin's avatar
Maxime Perrotin committed
262
                        New_Item =>
263
264
265
266
267
              (case ATN.Kind (single_val) is
                 when ATN.K_Signed_AADLNumber =>
                   Ocarina.AADL_Values.Image
                      (ATN.Value (ATN.Number_Value (single_val))) &
                      (if Present (ATN.Unit_Identifier (single_val)) then " " &
Maxime Perrotin's avatar
Maxime Perrotin committed
268
                      Get_Name_String
269
                          (ATN.Display_Name (ATN.Unit_Identifier (single_val)))
Maxime Perrotin's avatar
Maxime Perrotin committed
270
                      else ""),
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
                 when ATN.K_Literal =>
                    Ocarina.AADL_Values.Image (ATN.Value (single_val),
                                               Quoted => False),
                 when ATN.K_Reference_Term =>
                    Get_Name_String
                       (ATN.Display_Name (ATN.First_Node --  XXX must iterate
                          (ATN.List_Items (ATN.Reference_Term (single_val))))),
                 when ATN.K_Enumeration_Term =>
                    Get_Name_String
                       (ATN.Display_Name (ATN.Identifier (single_val))),
                 when ATN.K_Number_Range_Term =>
                    "RANGE NOT SUPPORTED!",
                 when others => "ERROR! Unsupported kind: "
                                & ATN.Kind (single_val)'Img));
         end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
286
         property := AIN.Next_Node (property);
Maxime Perrotin's avatar
Maxime Perrotin committed
287
288
289
290
      end loop;
      return result;
   end Get_Properties_Map;

Maxime Perrotin's avatar
Maxime Perrotin committed
291
292
293
294
295
296
   -----------------------
   -- Get_ASN1_Encoding --
   -----------------------

   function Get_ASN1_Encoding (E : Node_Id) return Supported_ASN1_Encoding is
      ASN1_Encoding_N : Name_Id;
Maxime Perrotin's avatar
Maxime Perrotin committed
297
298
299
300
      ASN1_Encoding : constant Name_Id := Get_String_Name ("taste::encoding");
      Native_Name   : constant Name_Id := Get_String_Name ("native");
      UPER_Name     : constant Name_Id := Get_String_Name ("uper");
      ACN_Name      : constant Name_Id := Get_String_Name ("acn");
Maxime Perrotin's avatar
Maxime Perrotin committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
   begin
      if Is_Defined_Enumeration_Property (E, ASN1_Encoding) then
         ASN1_Encoding_N := Get_Enumeration_Property (E, ASN1_Encoding);

         if ASN1_Encoding_N = Native_Name then
            return Native;

         elsif ASN1_Encoding_N = UPER_Name then
            return UPER;

         elsif ASN1_Encoding_N = ACN_Name then
            return ACN;
         end if;
      end if;
      Exit_On_Error (True, "ASN1 Encoding not set");
      return Default;
   end Get_ASN1_Encoding;

   -------------------------
   -- Get_ASN1_Basic_Type --
   -------------------------

Maxime Perrotin's avatar
Maxime Perrotin committed
323
   function Get_ASN1_Basic_Type (E : Node_Id) return Supported_ASN1_Basic_Type
Maxime Perrotin's avatar
Maxime Perrotin committed
324
   is
Maxime Perrotin's avatar
Maxime Perrotin committed
325
326
327
328
329
330
331
332
333
334
335
336
337
      ASN1_Basic_Type  : constant Name_Id :=
                               Get_String_Name ("taste::asn1_basic_type");
      Sequence_Name    : constant Name_Id := Get_String_Name ("asequence");
      SequenceOf_Name  : constant Name_Id := Get_String_Name ("asequenceof");
      Enumerated_Name  : constant Name_Id := Get_String_Name ("aenumerated");
      Set_Name         : constant Name_Id := Get_String_Name ("aset");
      SetOf_Name       : constant Name_Id := Get_String_Name ("asetof");
      Integer_Name     : constant Name_Id := Get_String_Name ("ainteger");
      Boolean_Name     : constant Name_Id := Get_String_Name ("aboolean");
      Real_Name        : constant Name_Id := Get_String_Name ("areal");
      OctetString_Name : constant Name_Id := Get_String_Name ("aoctetstring");
      Choice_Name      : constant Name_Id := Get_String_Name ("achoice");
      String_Name      : constant Name_Id := Get_String_Name ("astring");
Maxime Perrotin's avatar
Maxime Perrotin committed
338
339
340
341
342
      ASN1_Basic_Type_N : Name_Id;
   begin
      if Is_Defined_Enumeration_Property (E, ASN1_Basic_Type) then
         ASN1_Basic_Type_N := Get_Enumeration_Property (E, ASN1_Basic_Type);

Maxime Perrotin's avatar
Maxime Perrotin committed
343
344
         if ASN1_Basic_Type_N = Sequence_Name then
            return ASN1_Sequence;
Maxime Perrotin's avatar
Maxime Perrotin committed
345

Maxime Perrotin's avatar
Maxime Perrotin committed
346
347
         elsif ASN1_Basic_Type_N = SequenceOf_Name then
            return ASN1_SequenceOf;
Maxime Perrotin's avatar
Maxime Perrotin committed
348

Maxime Perrotin's avatar
Maxime Perrotin committed
349
350
         elsif ASN1_Basic_Type_N = Enumerated_Name then
            return ASN1_Enumerated;
Maxime Perrotin's avatar
Maxime Perrotin committed
351

Maxime Perrotin's avatar
Maxime Perrotin committed
352
353
         elsif ASN1_Basic_Type_N = Set_Name then
            return ASN1_Set;
Maxime Perrotin's avatar
Maxime Perrotin committed
354

Maxime Perrotin's avatar
Maxime Perrotin committed
355
356
         elsif ASN1_Basic_Type_N = SetOf_Name then
            return ASN1_SetOf;
Maxime Perrotin's avatar
Maxime Perrotin committed
357

Maxime Perrotin's avatar
Maxime Perrotin committed
358
359
         elsif ASN1_Basic_Type_N = Integer_Name then
            return ASN1_Integer;
Maxime Perrotin's avatar
Maxime Perrotin committed
360

Maxime Perrotin's avatar
Maxime Perrotin committed
361
362
         elsif ASN1_Basic_Type_N = Boolean_Name then
            return ASN1_Boolean;
Maxime Perrotin's avatar
Maxime Perrotin committed
363

Maxime Perrotin's avatar
Maxime Perrotin committed
364
365
         elsif ASN1_Basic_Type_N = Real_Name then
            return ASN1_Real;
Maxime Perrotin's avatar
Maxime Perrotin committed
366

Maxime Perrotin's avatar
Maxime Perrotin committed
367
368
         elsif ASN1_Basic_Type_N = OctetString_Name then
            return ASN1_OctetString;
Maxime Perrotin's avatar
Maxime Perrotin committed
369

Maxime Perrotin's avatar
Maxime Perrotin committed
370
371
         elsif ASN1_Basic_Type_N = Choice_Name then
            return ASN1_Choice;
Maxime Perrotin's avatar
Maxime Perrotin committed
372

Maxime Perrotin's avatar
Maxime Perrotin committed
373
374
         elsif ASN1_Basic_Type_N = String_Name then
            return ASN1_String;
Maxime Perrotin's avatar
Maxime Perrotin committed
375

Maxime Perrotin's avatar
Maxime Perrotin committed
376
377
378
379
         else
            raise Program_Error with "Undefined choice "
              & Get_Name_String (ASN1_Basic_Type_N);
         end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
380
381
382
383
384
      end if;
      Exit_On_Error (True, "Error: ASN.1 Basic type undefined!");
      return ASN1_Unknown;
   end Get_ASN1_Basic_Type;

Maxime Perrotin's avatar
Maxime Perrotin committed
385
   function AADL_to_Ada_IV (System : Node_Id) return Complete_Interface_View is
Maxime Perrotin's avatar
Maxime Perrotin committed
386
387
388
389
390
      Funcs             : Functions.Vector;
      Routes            : Channels.Vector;
      Current_Function  : Node_Id;
      CI                : Node_Id;
      pragma Unreferenced (CI);
Maxime Perrotin's avatar
Maxime Perrotin committed
391
   begin
Maxime Perrotin's avatar
Maxime Perrotin committed
392
393
394
395
396
397
398
399
400
      Exit_On_Error (No (System), "Missing or erroneous interface view");

      Current_Function := AIN.First_Node (AIN.Subcomponents (System));
      while Present (Current_Function) loop
         CI := Corresponding_Instance (Current_Function);
         Put_Line ("Function " & AIN_Case (Current_Function));
         Current_Function := AIN.Next_Node (Current_Function);
      end loop;

Maxime Perrotin's avatar
Maxime Perrotin committed
401
402
403
404
      return IV_AST : constant Complete_Interface_View :=
          (Flat_Functions => Funcs,
           Connections    => Routes);
   end AADL_to_Ada_IV;
Maxime Perrotin's avatar
Maxime Perrotin committed
405
406

end Buildsupport_Utils;