OpenAADL / ocarina
1
------------------------------------------------------------------------------
2
--                                                                          --
3
--                           OCARINA COMPONENTS                             --
4
--                                                                          --
5
--                 OCARINA.BACKENDS.VXWORKS653_CONF.NAMING                  --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--         Copyright (C) 2015-2019 ESA & ISAE, 2019-2020 OpenAADL           --
10
--                                                                          --
11
-- Ocarina  is free software; you can redistribute it and/or modify under   --
12
-- terms of the  GNU General Public License as published  by the Free Soft- --
13
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
15
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
16
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
17
--                                                                          --
18
-- As a special exception under Section 7 of GPL version 3, you are granted --
19
-- additional permissions described in the GCC Runtime Library Exception,   --
20
-- version 3.1, as published by the Free Software Foundation.               --
21
--                                                                          --
22
-- You should have received a copy of the GNU General Public License and    --
23
-- a copy of the GCC Runtime Library Exception along with this program;     --
24
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
27
--                    Ocarina is maintained by OpenAADL team                --
28
--                              (info@openaadl.org)                         --
29
--                                                                          --
30
------------------------------------------------------------------------------
31

32
with Ada.Strings;       use Ada.Strings;
33
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34

35
with Locations;
36
with Ocarina.ME_AADL;
37
with Ocarina.ME_AADL.AADL_Instances.Nodes;
38
with Ocarina.ME_AADL.AADL_Instances.Nutils;
39
with Ocarina.ME_AADL.AADL_Instances.Entities;
40

41
with Ocarina.Backends.C_Common.Mapping;
42
with Ocarina.Backends.Properties;
43
with Ocarina.Backends.Utils;
44
with Ocarina.Backends.XML_Tree.Nodes;
45
with Ocarina.Backends.XML_Tree.Nutils;
46
with Ocarina.Backends.Vxworks653_Conf.Mapping;
47
with Ocarina.Backends.XML_Values;
48
with Ocarina.Namet; use Ocarina.Namet;
49

50
package body Ocarina.Backends.Vxworks653_Conf.Naming is
51

52
   use Locations;
53
   use Ocarina.ME_AADL;
54
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
55
   use Ocarina.ME_AADL.AADL_Instances.Entities;
56
   use Ocarina.Backends.XML_Tree.Nutils;
57
   use Ocarina.Backends.Properties;
58
   use Ocarina.Backends.Utils;
59
   use Ocarina.Backends.Vxworks653_Conf.Mapping;
60

61
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
62
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
63
   package XTN renames Ocarina.Backends.XML_Tree.Nodes;
64
   package XTU renames Ocarina.Backends.XML_Tree.Nutils;
65
   package XV renames Ocarina.Backends.XML_Values;
66

67
   procedure Visit_Component (E : Node_Id);
68
   procedure Visit_System (E : Node_Id);
69
   procedure Visit_Process (E : Node_Id);
70
   procedure Visit_Processor (E : Node_Id);
71
   procedure Visit_Virtual_Processor (E : Node_Id);
72
   procedure Visit_Subcomponents_Of is new Visit_Subcomponents_Of_G (Visit);
73

74
   procedure Add_Applications (AADL_Processor : Node_Id; XML_Node : Node_Id);
75
   procedure Add_Shared_Data_Regions
76
     (AADL_Processor : Node_Id;
77
      XML_Node       : Node_Id);
78
   procedure Add_Shared_Library_Regions
79
     (AADL_Processor : Node_Id;
80
      XML_Node       : Node_Id);
81
   procedure Add_Application
82
     (AADL_Virtual_Processor : Node_Id;
83
      XML_Node               : Node_Id);
84

85
   -----------
86
   -- Visit --
87
   -----------
88

89 1
   procedure Visit (E : Node_Id) is
90
   begin
91 1
      case Kind (E) is
92 1
         when K_Architecture_Instance =>
93 1
            Visit (Root_System (E));
94

95 1
         when K_Component_Instance =>
96 1
            Visit_Component (E);
97

98 0
         when others =>
99 0
            null;
100 1
      end case;
101 1
   end Visit;
102

103
   ---------------------
104
   -- Visit_Component --
105
   ---------------------
106

107 1
   procedure Visit_Component (E : Node_Id) is
108 1
      Category : constant Component_Category := Get_Category_Of_Component (E);
109
   begin
110 1
      case Category is
111 1
         when CC_System =>
112 1
            Visit_System (E);
113

114 0
         when CC_Process =>
115 0
            Visit_Process (E);
116

117 0
         when CC_Device =>
118 0
            Visit_Process (E);
119

120 0
         when CC_Processor =>
121 0
            Visit_Processor (E);
122

123 1
         when CC_Virtual_Processor =>
124 1
            Visit_Virtual_Processor (E);
125

126 0
         when others =>
127 0
            null;
128 1
      end case;
129 1
   end Visit_Component;
130

131
   -------------------
132
   -- Visit_Process --
133
   -------------------
134

135 1
   procedure Visit_Process (E : Node_Id) is
136 1
      N              : Node_Id;
137 1
      Processes_List : List_Id;
138
   begin
139
      Processes_List :=
140 1
        XTN.Processes (Backend_Node (Identifier (Get_Bound_Processor (E))));
141

142 1
      N := XTU.Make_Container (E);
143

144 1
      XTU.Append_Node_To_List (N, Processes_List);
145 1
   end Visit_Process;
146

147
   --------------------------------------
148
   -- Visit_Virtual_Processor_Instance --
149
   --------------------------------------
150

151 1
   procedure Visit_Virtual_Processor (E : Node_Id) is
152 1
      Processes : List_Id;
153 1
      N         : Node_Id;
154
   begin
155 1
      N := New_Node (XTN.K_HI_Tree_Bindings);
156

157 1
      AIN.Set_Backend_Node (Identifier (E), N);
158

159 1
      Processes := XTU.New_List (XTN.K_List_Id);
160

161 1
      XTN.Set_Processes (N, Processes);
162

163 1
   end Visit_Virtual_Processor;
164

165
   ---------------------
166
   -- Visit_Processor --
167
   ---------------------
168

169 1
   procedure Visit_Processor (E : Node_Id) is
170 1
      P         : Node_Id;
171 1
      U         : Node_Id;
172 1
      N         : Node_Id;
173 1
      Processes : List_Id;
174
   begin
175 1
      P := Map_HI_Node (E);
176 1
      Push_Entity (P);
177

178 1
      U := Map_HI_Unit (E);
179 1
      Push_Entity (U);
180

181 1
      Visit_Subcomponents_Of (E);
182

183 1
      N := New_Node (XTN.K_HI_Tree_Bindings);
184

185 1
      Processes := AINU.New_List (K_Node_Id, No_Location);
186

187 1
      XTN.Set_Processes (N, Processes);
188

189 1
      XTN.Set_Unit (N, U);
190 1
      XTN.Set_Node (N, P);
191

192 1
      AIN.Set_Backend_Node (Identifier (E), N);
193

194 1
      Add_Applications (E, XTN.Root_Node (XTN.XML_File (U)));
195 1
      Add_Shared_Data_Regions (E, XTN.Root_Node (XTN.XML_File (U)));
196 1
      Add_Shared_Library_Regions (E, XTN.Root_Node (XTN.XML_File (U)));
197

198 1
      Pop_Entity;
199 1
      Pop_Entity;
200 1
   end Visit_Processor;
201

202
   ------------------
203
   -- Visit_System --
204
   ------------------
205

206 1
   procedure Visit_System (E : Node_Id) is
207 1
      S                  : Node_Id;
208 1
      Component_Instance : Node_Id;
209
   begin
210 1
      if not AINU.Is_Empty (Subcomponents (E)) then
211 1
         S := First_Node (Subcomponents (E));
212 1
         while Present (S) loop
213 1
            Component_Instance := Corresponding_Instance (S);
214 1
            if Get_Category_Of_Component (Component_Instance) =
215
              CC_Processor
216
            then
217 1
               Visit_Processor (Component_Instance);
218
            end if;
219 1
            S := Next_Node (S);
220 1
         end loop;
221
      end if;
222

223 1
      if not AINU.Is_Empty (Subcomponents (E)) then
224 1
         S := First_Node (Subcomponents (E));
225 1
         while Present (S) loop
226
            --  Visit process subcomponents
227

228 1
            if AINU.Is_Process_Or_Device (Corresponding_Instance (S)) then
229 1
               Visit_Process (Corresponding_Instance (S));
230
            end if;
231 1
            S := Next_Node (S);
232 1
         end loop;
233
      end if;
234

235 1
   end Visit_System;
236

237
   -----------------------
238
   --  Add_Application  --
239
   -----------------------
240

241 1
   procedure Add_Application
242
     (AADL_Virtual_Processor : Node_Id;
243
      XML_Node               : Node_Id)
244
   is
245 1
      Application_Node             : Node_Id;
246 1
      Application_Description_Node : Node_Id;
247 1
      Memory_Size_Node             : Node_Id;
248 1
      Ports_Node                   : Node_Id;
249 1
      Port_Node                    : Node_Id;
250 1
      Corresponding_Process        : Node_Id;
251 1
      Feature                      : Node_Id;
252 1
      Size                         : Unsigned_Long_Long;
253 1
      Queue_Size                   : Long_Long;
254 1
      Refresh_Period               : Time_Type;
255 1
      Refresh_Period_Second        : Long_Double;
256
   begin
257
      --  Application Node that is the child of Applications
258

259
      Corresponding_Process :=
260 1
        Find_Associated_Process (AADL_Virtual_Processor);
261

262 1
      Application_Node := Make_XML_Node ("Application");
263 1
      XTU.Add_Attribute
264
        ("Name",
265 1
         Get_Name_String (Map_Application_Name (AADL_Virtual_Processor, True)),
266
         Application_Node);
267 1
      Append_Node_To_List (Application_Node, XTN.Subitems (XML_Node));
268

269
      --  Application Description with MemorySize and Ports nodes
270

271 1
      Application_Description_Node := Make_XML_Node ("ApplicationDescription");
272 1
      Append_Node_To_List
273
        (Application_Description_Node,
274 1
         XTN.Subitems (Application_Node));
275

276 1
      Memory_Size_Node := Make_XML_Node ("MemorySize");
277 1
      Append_Node_To_List
278
        (Memory_Size_Node,
279 1
         XTN.Subitems (Application_Description_Node));
280 1
      XTU.Add_Attribute ("MemorySizeBss", "0x10000", Memory_Size_Node);
281 1
      XTU.Add_Attribute ("MemorySizeText", "0x10000", Memory_Size_Node);
282 1
      XTU.Add_Attribute ("MemorySizeData", "0x10000", Memory_Size_Node);
283 1
      XTU.Add_Attribute ("MemorySizeRoData", "0x10000", Memory_Size_Node);
284 1
      XTU.Add_Attribute
285
        ("MemorySizePersistentData",
286
         "0x10000",
287
         Memory_Size_Node);
288 1
      XTU.Add_Attribute
289
        ("MemorySizePersistentBss",
290
         "0x10000",
291
         Memory_Size_Node);
292

293 1
      Ports_Node := Make_XML_Node ("Ports");
294 1
      Append_Node_To_List
295
        (Ports_Node,
296 1
         XTN.Subitems (Application_Description_Node));
297

298 1
      Feature := First_Node (Features (Corresponding_Process));
299

300 1
      while Present (Feature) loop
301 1
         if Is_Event (Feature) and then Is_Data (Feature) then
302
            Size :=
303 1
              To_Bytes (Get_Data_Size (Corresponding_Instance (Feature)));
304 1
            Queue_Size := Get_Queue_Size (Feature);
305

306 1
            if Queue_Size = -1 then
307 1
               Queue_Size := 1;
308
            end if;
309

310 1
            Port_Node := Make_XML_Node ("QueuingPort");
311

312 1
            XTU.Add_Attribute
313
              ("MessageSize",
314 1
               Trim (Unsigned_Long_Long'Image (Size), Left),
315
               Port_Node);
316

317 1
            XTU.Add_Attribute
318
              ("Name",
319 1
               Get_Name_String (C_Common.Mapping.Map_Port_Name (Feature)),
320
               Port_Node);
321

322 1
            XTU.Add_Attribute
323
              ("QueueLength",
324 1
               Trim (Long_Long'Image (Queue_Size), Left),
325
               Port_Node);
326

327 1
            if not Is_In (Feature) and then Is_Out (Feature) then
328 1
               XTU.Add_Attribute ("Direction", "SOURCE", Port_Node);
329

330 1
               XTU.Add_Attribute ("Protocol", "SENDER_BLOCK", Port_Node);
331
            end if;
332

333 1
            if Is_In (Feature) and then not Is_Out (Feature) then
334 1
               XTU.Add_Attribute ("Direction", "DESTINATION", Port_Node);
335 1
               XTU.Add_Attribute ("Protocol", "NOT_APPLICABLE", Port_Node);
336
            end if;
337

338 1
            Append_Node_To_List (Port_Node, XTN.Subitems (Ports_Node));
339
         end if;
340

341 1
         if not Is_Event (Feature) and then Is_Data (Feature) then
342
            Size :=
343 1
              To_Bytes (Get_Data_Size (Corresponding_Instance (Feature)));
344

345 1
            Port_Node := Make_XML_Node ("SamplingPort");
346 1
            XTU.Add_Attribute
347
              ("MessageSize",
348 1
               Trim (Unsigned_Long_Long'Image (Size), Left),
349
               Port_Node);
350

351 1
            XTU.Add_Attribute
352
              ("Name",
353 1
               Get_Name_String (C_Common.Mapping.Map_Port_Name (Feature)),
354
               Port_Node);
355

356 1
            if Is_In (Feature) and then not Is_Out (Feature) then
357 1
               Refresh_Period        := Get_POK_Refresh_Time (Feature);
358 1
               Refresh_Period_Second :=
359 1
                 (Long_Double (To_Milliseconds (Refresh_Period)) /
360
                  Long_Double (1000.0));
361

362 1
               XTU.Add_Attribute ("Direction", "DESTINATION", Port_Node);
363

364 1
               XTU.Add_Attribute
365
                 ("RefreshRate",
366 1
                  XV.New_Floating_Point_Value (Refresh_Period_Second),
367
                  Port_Node);
368
            end if;
369

370 1
            if not Is_In (Feature) and then Is_Out (Feature) then
371 1
               XTU.Add_Attribute ("Direction", "SOURCE", Port_Node);
372

373 1
               XTU.Add_Attribute ("RefreshRate", "INFINITE_TIME", Port_Node);
374
            end if;
375

376 1
            Append_Node_To_List (Port_Node, XTN.Subitems (Ports_Node));
377
         end if;
378

379 1
         Feature := Next_Node (Feature);
380 1
      end loop;
381 1
   end Add_Application;
382

383
   ------------------------
384
   --  Add_Applications  --
385
   ------------------------
386

387 1
   procedure Add_Applications (AADL_Processor : Node_Id; XML_Node : Node_Id) is
388 1
      Applications_Node : Node_Id;
389 1
      S                 : Node_Id;
390
   begin
391

392
      --  Applications Node first
393

394 1
      Applications_Node := Make_XML_Node ("Applications");
395 1
      Append_Node_To_List (Applications_Node, XTN.Subitems (XML_Node));
396

397 1
      if not AINU.Is_Empty (Subcomponents (AADL_Processor)) then
398 1
         S := First_Node (Subcomponents (AADL_Processor));
399 1
         while Present (S) loop
400
            --  Visit virtual processor subcomponents
401

402 1
            if AINU.Is_Virtual_Processor (Corresponding_Instance (S)) then
403 1
               Add_Application (Corresponding_Instance (S), Applications_Node);
404
            end if;
405 1
            S := Next_Node (S);
406 1
         end loop;
407
      end if;
408 1
   end Add_Applications;
409

410
   -------------------------------
411
   --  Add_Shared_Data_Regions  --
412
   -------------------------------
413

414 1
   procedure Add_Shared_Data_Regions
415
     (AADL_Processor : Node_Id;
416
      XML_Node       : Node_Id)
417
   is
418
      pragma Unreferenced (AADL_Processor);
419

420 1
      Shared_Data_Node : Node_Id;
421
   begin
422 1
      Shared_Data_Node := Make_XML_Node ("SharedDataRegions");
423 1
      Append_Node_To_List (Shared_Data_Node, XTN.Subitems (XML_Node));
424 1
   end Add_Shared_Data_Regions;
425

426
   ----------------------------------
427
   --  Add_Shared_Library_Regions  --
428
   ----------------------------------
429

430 1
   procedure Add_Shared_Library_Regions
431
     (AADL_Processor : Node_Id;
432
      XML_Node       : Node_Id)
433
   is
434
      pragma Unreferenced (AADL_Processor);
435

436 1
      Shared_Library_Node             : Node_Id;
437 1
      Shared_Library_Regions_Node     : Node_Id;
438 1
      Shared_Library_Description_Node : Node_Id;
439 1
      Shared_Memory_Size_Node         : Node_Id;
440
   begin
441
      --  look like the following.
442
      --
443
      --  <SharedLibraryRegions>
444
      --    <SharedLibrary Name="vxSysLib">
445
      --      <SharedLibraryDescription ...>
446
      --        <MemorySize
447
      --           MemorySizeText="0x40000"
448
      --           MemorySizeRoData="0x10000"
449
      --           MemorySizeData="0x10000"
450
      --           MemorySizeBss="0x10000"
451
      --           MemorySizePersistentData="0x10000"
452
      --           MemorySizePersistentBss="0x10000"/>
453
      --      </SharedLibraryDescription>
454
      --    </SharedLibrary>
455
      --  </SharedLibraryRegions>
456

457
      --  First, add a central node for all shared library regions.
458

459 1
      Shared_Library_Regions_Node := Make_XML_Node ("SharedLibraryRegions");
460 1
      Append_Node_To_List
461
        (Shared_Library_Regions_Node,
462 1
         XTN.Subitems (XML_Node));
463

464
      --  Take care of all sub shared libraries.
465

466 1
      Shared_Library_Node := Make_XML_Node ("SharedLibrary");
467 1
      XTU.Add_Attribute ("Name", "vxSysLib", Shared_Library_Node);
468 1
      Append_Node_To_List
469
        (Shared_Library_Node,
470 1
         XTN.Subitems (Shared_Library_Regions_Node));
471

472
      --  The SharedLibraryDescription node now.
473

474
      Shared_Library_Description_Node :=
475 1
        Make_XML_Node ("SharedLibraryDescription");
476 1
      XTU.Add_Attribute
477
        ("SystemSharedLibrary",
478
         "true",
479
         Shared_Library_Description_Node);
480 1
      XTU.Add_Attribute
481
        ("VirtualAddress",
482
         "0x50000000",
483
         Shared_Library_Description_Node);
484 1
      Append_Node_To_List
485
        (Shared_Library_Description_Node,
486 1
         XTN.Subitems (Shared_Library_Node));
487

488
      --  The MemorySize node now.
489

490 1
      Shared_Memory_Size_Node := Make_XML_Node ("MemorySize");
491 1
      XTU.Add_Attribute ("MemorySizeText", "0x40000", Shared_Memory_Size_Node);
492

493 1
      XTU.Add_Attribute
494
        ("MemorySizeRoData",
495
         "0x10000",
496
         Shared_Memory_Size_Node);
497

498 1
      XTU.Add_Attribute ("MemorySizeData", "0x10000", Shared_Memory_Size_Node);
499

500 1
      XTU.Add_Attribute ("MemorySizeBss", "0x10000", Shared_Memory_Size_Node);
501

502 1
      XTU.Add_Attribute
503
        ("MemorySizePersistentData",
504
         "0x10000",
505
         Shared_Memory_Size_Node);
506

507 1
      XTU.Add_Attribute
508
        ("MemorySizePersistentBss",
509
         "0x10000",
510
         Shared_Memory_Size_Node);
511

512 1
      Append_Node_To_List
513
        (Shared_Memory_Size_Node,
514 1
         XTN.Subitems (Shared_Library_Description_Node));
515 1
   end Add_Shared_Library_Regions;
516

517
end Ocarina.Backends.Vxworks653_Conf.Naming;

Read our documentation on viewing source code .

Loading