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

33
with Ocarina.Namet;
34
with Utils; use Utils;
35
with Ocarina.ME_AADL;
36
with Ocarina.ME_AADL.AADL_Instances.Nodes;
37
with Ocarina.ME_AADL.AADL_Instances.Nutils;
38
with Ocarina.ME_AADL.AADL_Instances.Entities;
39

40
with Ocarina.Backends.Utils;
41
with Ocarina.Backends.C_Values;
42
with Ocarina.Backends.C_Tree.Nutils;
43
with Ocarina.Backends.C_Tree.Nodes;
44
with Ocarina.Backends.C_Common.Mapping;
45
with Ocarina.Backends.PO_HI_C.Runtime;
46
with Ocarina.Backends.Properties;
47
with Ocarina.Backends.Messages;
48
with Ocarina.Backends.C_Common.BA;
49
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;
50
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
51

52
with Ocarina.Instances.Queries;
53

54
with Locations;
55

56 1
package body Ocarina.Backends.PO_HI_C.Deployment is
57

58
   use Ocarina.Namet;
59
   use Ocarina.ME_AADL;
60
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
61
   use Ocarina.ME_AADL.AADL_Instances.Entities;
62
   use Ocarina.Backends.Utils;
63
   use Ocarina.Backends.C_Values;
64
   use Ocarina.Backends.C_Tree.Nutils;
65
   use Ocarina.Backends.C_Common.Mapping;
66
   use Ocarina.Backends.PO_HI_C.Runtime;
67
   use Ocarina.Backends.Properties;
68
   use Ocarina.Backends.Messages;
69
   use Ocarina.Instances.Queries;
70
   use Ocarina.Backends.C_Common.BA;
71

72
   use Locations;
73

74
   package AAN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
75
   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
76
   package CV renames Ocarina.Backends.C_Values;
77
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
78
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
79
   package BATN renames Ocarina.ME_AADL_BA.BA_Tree.Nodes;
80
   package BANu renames Ocarina.ME_AADL_BA.BA_Tree.Nutils;
81

82 1
   Entity_Array           : Node_Id;
83 1
   Devices_Array          : Node_Id;
84 1
   Devices_Nb_Buses_Array : Node_Id;
85 1
   Devices_Confvars       : Node_Id;
86 1
   Protocols_Conf         : Node_Id;
87 1
   Devices_Buses_Array    : Node_Id;
88 1
   Port_To_Devices        : Node_Id;
89 1
   Devices_To_Nodes       : Node_Id;
90 1
   Global_Port_Kind       : Node_Id;
91 1
   Global_Port_Queue_Size : Node_Id;
92 1
   Global_Port_Data_Size  : Node_Id;
93 1
   Global_Ports           : List_Id;
94
   Protocol_Identifier    : Unsigned_Long_Long := 0;
95

96
   function Is_Added (P : Node_Id; E : Node_Id) return Boolean;
97
   function Added_Internal_Name (P : Node_Id; E : Node_Id) return Name_Id;
98

99
   --------------
100
   -- Is_Added --
101
   --------------
102

103 1
   function Is_Added (P : Node_Id; E : Node_Id) return Boolean is
104 1
      I_Name : constant Name_Id := Added_Internal_Name (P, E);
105
   begin
106 1
      return Get_Name_Table_Byte (I_Name) = 1;
107
   end Is_Added;
108

109
   -------------------------
110
   -- Added_Internal_Name --
111
   -------------------------
112

113 1
   function Added_Internal_Name (P : Node_Id; E : Node_Id) return Name_Id is
114
   begin
115 1
      Set_Str_To_Name_Buffer ("%add%enumerator%");
116 1
      Add_Nat_To_Name_Buffer (Nat (P));
117 1
      Add_Char_To_Name_Buffer ('%');
118 1
      Add_Nat_To_Name_Buffer (Nat (E));
119

120 1
      return Name_Find;
121
   end Added_Internal_Name;
122

123
   -----------------
124
   -- Header_File --
125
   -----------------
126

127
   package body Header_File is
128

129
      procedure Visit_Architecture_Instance (E : Node_Id);
130
      procedure Visit_Component_Instance (E : Node_Id);
131
      procedure Visit_System_Instance (E : Node_Id);
132
      procedure Visit_Process_Instance (E : Node_Id);
133
      procedure Visit_Thread_Instance (E : Node_Id);
134
      procedure Visit_Subprogram_Instance (E : Node_Id);
135
      procedure Visit_Device_Instance (E : Node_Id);
136
      procedure Visit_Bus_Instance (E : Node_Id);
137
      procedure Visit_Virtual_Bus_Instance (E : Node_Id);
138

139
      procedure Set_Added (P : Node_Id; E : Node_Id);
140

141
      procedure Append_Existing
142
        (S         :        Node_Id;
143
         L         :        List_Id;
144
         Id        : in out Unsigned_Long_Long;
145
         Is_Entity :        Boolean := False);
146

147
      --  Append a node in a List. If the node was node already processed,
148
      --  it assigns a value (using the Id) argument to the node and bind
149
      --  it to the Backend Node of S. Is a value was already assigned, it
150
      --  simply uses it and append the it in the list.
151
      --  This function is used to warrant that all entities will have
152
      --  the same values on each node.
153

154 1
      Nb_Ports_List           : List_Id;
155 1
      Node_Enumerator_List    : List_Id;
156 1
      Tasks_Enumerator_List   : List_Id;
157 1
      Devices_Enumerator_List : List_Id;
158 1
      Buses_Enumerator_List   : List_Id;
159 1
      Entity_Enumerator_List  : List_Id;
160 1
      Global_Port_List        : List_Id;
161 1
      Protocol_List           : List_Id;
162 1
      Global_Port_Names       : Node_Id;
163 1
      Global_Port_Model_Names : Node_Id;
164 1
      Local_Port_List         : List_Id;
165

166 1
      Nb_Nodes : Unsigned_Long_Long;
167

168
      Current_Process_Instance : Node_Id := No_Node;
169

170 1
      Global_Port_To_Entity : Node_Id;
171 1
      Global_Port_To_Local  : Node_Id;
172 1
      Local_Port_Values     : Node_Id;
173

174
      Invalid_Local_Port_Added  : Boolean := False;
175
      Invalid_Protocol_Added    : Boolean := False;
176
      Invalid_Global_Port_Added : Boolean := False;
177
      Invalid_Entity_Added      : Boolean := False;
178

179
      Current_Device : Node_Id := No_Node;
180
      --  Current_Process : Node_Id := No_Node;
181

182
      --  Point to the process currently visited. When we visit a process
183
      --  we look at all its ports and visit the called subprograms. So,
184
      --  we need to know if these subprograms are linked with the currrent
185
      --  process.
186

187
      Node_Identifier        : Unsigned_Long_Long := 0;
188
      Global_Port_Identifier : Unsigned_Long_Long := 0;
189
      Local_Port_Identifier  : Unsigned_Long_Long := 0;
190
      Entity_Identifier      : Unsigned_Long_Long := 0;
191
      Task_Identifier        : Unsigned_Long_Long := 0;
192
      Tasks_Stack            : Unsigned_Long_Long := 0;
193
      Nb_Protected           : Unsigned_Long_Long := 0;
194
      Device_Id              : Unsigned_Long_Long := 0;
195
      Bus_Id                 : Unsigned_Long_Long := 0;
196
      Nb_Ports_In_Process    : Unsigned_Long_Long := 0;
197
      Nb_Ports_Total         : Unsigned_Long_Long := 0;
198
      Total_Ports_Node       : Node_Id            := No_Node;
199
      Nb_Entities_Node       : Node_Id            := No_Node;
200
      Nb_Devices_Node        : Node_Id            := No_Node;
201
      Nb_Buses_Node          : Node_Id            := No_Node;
202
      Nb_Protocols_Node      : Node_Id            := No_Node;
203

204
      --  The information from Simulink can come
205
      --  from both data and subprograms. So, to avoid
206
      --  conflict, we add relevant informations from
207
      --  the first component that have them. And for other
208
      --  components, we add nothing.
209

210
      ---------------------
211
      -- Append_Existing --
212
      ---------------------
213

214 1
      procedure Append_Existing
215
        (S         :        Node_Id;
216
         L         :        List_Id;
217
         Id        : in out Unsigned_Long_Long;
218
         Is_Entity :        Boolean := False)
219
      is
220 1
         N : Node_Id;
221
      begin
222 1
         if No (Backend_Node (Identifier (S)))
223
           or else
224 1
           (Present (Backend_Node (Identifier (S)))
225 1
            and then No (CTN.Enumerator_Node (Backend_Node (Identifier (S)))))
226
         then
227

228
            N :=
229 1
              Make_Expression
230 1
                (Make_Defining_Identifier
231 1
                   (Map_C_Enumerator_Name
232
                      (S,
233
                       Custom_Parent => Current_Device,
234
                       Entity        => Is_Entity)),
235
                 Op_Equal,
236 1
                 Make_Literal (CV.New_Int_Value (Id, 0, 10)));
237 1
            Bind_AADL_To_Enumerator (Identifier (S), N);
238 1
            Append_Node_To_List (N, L);
239 1
            Id := Id + 1;
240
         end if;
241 1
      end Append_Existing;
242

243
      ---------------
244
      -- Set_Added --
245
      ---------------
246

247 1
      procedure Set_Added (P : Node_Id; E : Node_Id) is
248 1
         I_Name : constant Name_Id := Added_Internal_Name (P, E);
249
      begin
250 1
         Set_Name_Table_Byte (I_Name, 1);
251 1
      end Set_Added;
252

253
      -----------
254
      -- Visit --
255
      -----------
256

257 1
      procedure Visit (E : Node_Id) is
258
      begin
259 1
         case Kind (E) is
260 1
            when K_Architecture_Instance =>
261 1
               Visit_Architecture_Instance (E);
262

263 1
            when K_Component_Instance =>
264 1
               Visit_Component_Instance (E);
265

266 0
            when others =>
267 0
               null;
268 1
         end case;
269 1
      end Visit;
270

271
      ---------------------------------
272
      -- Visit_Architecture_Instance --
273
      ---------------------------------
274

275 1
      procedure Visit_Architecture_Instance (E : Node_Id) is
276
      begin
277 1
         Visit (Root_System (E));
278 1
      end Visit_Architecture_Instance;
279

280
      ------------------------------
281
      -- Visit_Component_Instance --
282
      ------------------------------
283

284 1
      procedure Visit_Component_Instance (E : Node_Id) is
285
         Category : constant Component_Category :=
286 1
           Get_Category_Of_Component (E);
287
      begin
288 1
         case Category is
289 1
            when CC_System =>
290 1
               Visit_System_Instance (E);
291

292 1
            when CC_Process =>
293 1
               Visit_Process_Instance (E);
294

295 1
            when CC_Thread =>
296 1
               Visit_Thread_Instance (E);
297

298 1
            when CC_Subprogram =>
299 1
               Visit_Subprogram_Instance (E);
300

301 1
            when CC_Device =>
302 1
               Visit_Device_Instance (E);
303

304 1
            when CC_Bus =>
305 1
               Visit_Bus_Instance (E);
306

307 0
            when CC_Virtual_Bus =>
308 0
               Visit_Virtual_Bus_Instance (E);
309

310 1
            when others =>
311 1
               null;
312 1
         end case;
313 1
      end Visit_Component_Instance;
314

315
      ------------------------
316
      -- Visit_Bus_Instance --
317
      ------------------------
318

319 1
      procedure Visit_Bus_Instance (E : Node_Id) is
320 1
         N : Node_Id;
321
      begin
322
         N :=
323 1
           Make_Expression
324 1
             (Make_Defining_Identifier
325 1
                (Map_C_Enumerator_Name (E, Entity => False)),
326
              Op_Equal,
327 1
              (Make_Literal (CV.New_Int_Value (Bus_Id, 0, 10))));
328 1
         Append_Node_To_List (N, Buses_Enumerator_List);
329

330 1
         Bus_Id := Bus_Id + 1;
331

332 1
         CTN.Set_Value (Nb_Buses_Node, New_Int_Value (Bus_Id, 1, 10));
333

334 1
      end Visit_Bus_Instance;
335

336
      --------------------------------
337
      -- Visit_Virtual_Bus_Instance --
338
      --------------------------------
339

340 0
      procedure Visit_Virtual_Bus_Instance (E : Node_Id) is
341 0
         N        : Node_Id;
342 0
         C        : Node_Id;
343 0
         S        : Node_Id;
344 0
         Impl     : Node_Id;
345 0
         Found    : Boolean;
346 0
         PName    : Name_Id;
347 0
         Bus_Conf : constant Node_Id := Make_Array_Values;
348
      begin
349
         --  A virtual bus describe a user-defined protocol.
350
         --  We are expecting that such a component defines some
351
         --  sub-components that model how it works.
352
         --  We are expecting at least one subprogram
353
         --  for marshalling (called marshaller in the subcomponent)
354
         --  and one for unmarshalling.
355

356
         --  Here, we retrieve the implementation of the protocol, as
357
         --  an abstract component. Then, we look for the marshaller
358
         --  and unmarshaller components that model protocol internals.
359

360 0
         Impl := Get_Implementation (E);
361

362
         --  If there is no abstract component associated with the virtual
363
         --  bus, this is useless to continue.
364

365 0
         if Impl = No_Node then
366 0
            return;
367
         end if;
368

369
         --  Make sure we include the header of subprograms
370
         --  in order to avoid any compilation issue (warning/errors).
371 0
         Set_Deployment_Source;
372 0
         Add_Include (RH (RH_Subprograms));
373 0
         Set_Deployment_Header;
374

375
         --  Add a maccro __PO_HI_USE_PROTOCOL_<NAME> so that we can
376
         --  make conditional compilation depending on the protocol
377
         --  that are used within the distributed system.
378 0
         Set_Str_To_Name_Buffer ("__PO_HI_USE_PROTOCOL_");
379 0
         Get_Name_String_And_Append (Name (Identifier (E)));
380

381 0
         PName := Name_Find;
382 0
         PName := To_Upper (To_C_Name (PName));
383

384 0
         Add_Define_Deployment
385 0
           (Make_Defining_Identifier (PName, C_Conversion => False));
386

387
         --  If there is a backend node and a naming node associated
388
         --  with it, it means that we already processed this protocol
389
         --  and correctly mapped it in the generated code.
390

391 0
         if Backend_Node (Identifier (E)) /= No_Node
392 0
           and then CTN.Naming_Node (Backend_Node (Identifier (E))) /= No_Node
393
         then
394 0
            return;
395
         end if;
396

397
         --  First, we are looking for the marshaller subcomponent.
398
         --  If not found, we raise an error.
399

400 0
         Found := False;
401

402 0
         if not AAU.Is_Empty (Subcomponents (Impl)) then
403 0
            S := First_Node (Subcomponents (Impl));
404 0
            while Present (S) loop
405 0
               C := Corresponding_Instance (S);
406 0
               if AAU.Is_Subprogram (C)
407 0
                 and then
408 0
                   Get_Name_String (Name (Identifier (S))) =
409
                   "marshaller"
410
               then
411 0
                  Append_Node_To_List
412 0
                    (Map_C_Defining_Identifier (C),
413 0
                     CTN.Values (Bus_Conf));
414 0
                  Found := True;
415
               end if;
416

417 0
               S := Next_Node (S);
418 0
            end loop;
419
         end if;
420

421 0
         if not Found then
422 0
            Display_Error
423
              ("User-defined protocol does define a marshaller",
424
               Fatal => True);
425
         end if;
426

427
         --  First, we are looking for the unmarshaller subcomponent.
428
         --  If not found, we display an error.
429

430 0
         Found := False;
431

432 0
         if not AAU.Is_Empty (Subcomponents (Impl)) then
433 0
            S := First_Node (Subcomponents (Impl));
434 0
            while Present (S) loop
435 0
               C := Corresponding_Instance (S);
436 0
               if AAU.Is_Subprogram (C)
437 0
                 and then
438 0
                   Get_Name_String (Name (Identifier (S))) =
439
                   "unmarshaller"
440
               then
441

442 0
                  Append_Node_To_List
443 0
                    (Map_C_Defining_Identifier (C),
444 0
                     CTN.Values (Bus_Conf));
445 0
                  Found := True;
446
               end if;
447

448 0
               S := Next_Node (S);
449 0
            end loop;
450
         end if;
451

452 0
         if not Found then
453 0
            Display_Error
454
              ("User-defined protocol does define a unmarshaller",
455
               Fatal => True);
456
         end if;
457

458
--         Found := False;
459
--
460
--         if not AAU.Is_Empty (Subcomponents (Impl)) then
461
--            S := First_Node (Subcomponents (Impl));
462
--            while Present (S) loop
463
--               C := Corresponding_Instance (S);
464
--               if AAU.Is_Data (C) and then
465
--                  Append_Node_To_List
466
--                     (Map_C_Defining_Identifier (C),
467
--                     CTN.Values (Bus_Conf));
468
--               end if;
469
--               S := Next_Node (S);
470
--            end loop;
471
--         end if;
472
--
473
--         if not Found then
474
--            Display_Error
475
--               ("User-defined protocol does define an associated type",
476
--                Fatal => True);
477
--         end if;
478

479
         --  Here, we add the array we just built and that describe
480
         --  the protocol configuration into the global array
481
         --  that contain all protocols configuration.
482

483 0
         Append_Node_To_List (Bus_Conf, CTN.Values (Protocols_Conf));
484

485
         --  Finally, we assigned a unique protocol identifier to the
486
         --  virtual bus, that will be mapped in the protocol_t enumeration
487
         --  in deployment.h.
488

489
         N :=
490 0
           Make_Expression
491 0
             (Make_Defining_Identifier (Map_C_Enumerator_Name (E)),
492
              Op_Equal,
493 0
              (Make_Literal (CV.New_Int_Value (Protocol_Identifier, 1, 10))));
494 0
         Append_Node_To_List (N, Protocol_List);
495 0
         Protocol_Identifier := Protocol_Identifier + 1;
496

497 0
         CTN.Set_Value
498
           (Nb_Protocols_Node,
499 0
            New_Int_Value (Protocol_Identifier, 1, 10));
500

501 0
         Bind_AADL_To_Naming
502 0
           (Identifier (E),
503 0
            Make_Defining_Identifier (Map_C_Enumerator_Name (E)));
504
      end Visit_Virtual_Bus_Instance;
505

506
      ---------------------------
507
      -- Visit_Device_Instance --
508
      ---------------------------
509

510 1
      procedure Visit_Device_Instance (E : Node_Id) is
511 1
         N                     : Node_Id;
512 1
         U                     : Node_Id;
513 1
         P                     : Node_Id;
514 1
         Q                     : Node_Id;
515 1
         F                     : Node_Id;
516 1
         Conf_Str              : Name_Id          := No_Name;
517 1
         Tmp_Name              : Name_Id;
518 1
         Nb_Connected_Buses    : Unsigned_Long_Long;
519 1
         Accessed_Buses        : constant Node_Id := Make_Array_Values;
520 1
         Accessed_Bus          : Node_Id;
521 1
         Device_Implementation : Node_Id;
522 1
         Configuration_Data    : Node_Id;
523
         The_System            : constant Node_Id :=
524 1
           Parent_Component (Parent_Subcomponent (E));
525 1
         Associated_Process : Node_Id := No_Node;
526
      begin
527 1
         Current_Device := E;
528

529 1
         if Current_Process_Instance /= No_Node
530
           and then
531 1
             Get_Bound_Processor (E) =
532 1
             Get_Bound_Processor (Current_Process_Instance)
533
         then
534

535 1
            if Backend_Node (Identifier (E)) /= No_Node
536
              and then
537 0
                CTN.Enumerator_Node (Backend_Node (Identifier (E))) /=
538
                No_Node
539
            then
540 0
               return;
541
            end if;
542

543 1
            Bind_AADL_To_Enumerator
544 1
              (Identifier (E),
545 1
               Make_Defining_Identifier
546 1
                 (Map_C_Enumerator_Name (E, Entity => False)));
547

548
            --  Try to find the process bounded with the device.
549 1
            Q := First_Node (Subcomponents (The_System));
550

551 1
            while Present (Q) loop
552 1
               if AAU.Is_Process (Corresponding_Instance (Q))
553
                 and then
554 1
                   Get_Bound_Processor (Corresponding_Instance (Q)) =
555 1
                   Get_Bound_Processor (E)
556
               then
557 1
                  Associated_Process := Q;
558
               end if;
559 1
               Q := Next_Node (Q);
560 1
            end loop;
561

562
            N :=
563 1
              Make_Expression
564 1
                (Make_Defining_Identifier
565 1
                   (Map_C_Enumerator_Name (E, Entity => False)),
566
                 Op_Equal,
567 1
                 (Make_Literal (CV.New_Int_Value (Device_Id, 0, 10))));
568 1
            Append_Node_To_List (N, Devices_Enumerator_List);
569

570 1
            if Associated_Process /= No_Node then
571 1
               Append_Node_To_List
572 1
                 (Make_Defining_Identifier
573 1
                    (Map_C_Enumerator_Name (Associated_Process)),
574 1
                  CTN.Values (Devices_To_Nodes));
575
            else
576 0
               Append_Node_To_List
577 0
                 (RE (RE_Unused_Node),
578 0
                  CTN.Values (Devices_To_Nodes));
579
            end if;
580

581 1
            Device_Id := Device_Id + 1;
582

583 1
            CTN.Set_Value (Nb_Devices_Node, New_Int_Value (Device_Id, 1, 10));
584

585 1
            if Get_Location (E) /= No_Name then
586 0
               Get_Name_String (Get_Location (E));
587 0
               Conf_Str := Name_Find;
588 0
               if Get_Port_Number (E) /= Properties.No_Value then
589 0
                  Set_Str_To_Name_Buffer (":");
590 0
                  Add_Str_To_Name_Buffer
591 0
                    (Value_Id'Image (Get_Port_Number (E)));
592 0
                  Tmp_Name := Name_Find;
593
               end if;
594 0
               Get_Name_String (Conf_Str);
595 0
               Get_Name_String_And_Append (Tmp_Name);
596 0
               Conf_Str := Name_Find;
597 1
            elsif Is_Defined_Property (E, "deployment::channel_address") then
598 0
               Set_Str_To_Name_Buffer
599 0
                 (Unsigned_Long_Long'Image
600 0
                    (Get_Integer_Property (E, "deployment::channel_address")));
601 0
               Conf_Str := Name_Find;
602 0
               if Is_Defined_Property (E, "deployment::process_id") then
603 0
                  Set_Str_To_Name_Buffer
604 0
                    (Unsigned_Long_Long'Image
605 0
                       (Get_Integer_Property (E, "deployment::process_id")));
606 0
                  Tmp_Name := Name_Find;
607 0
                  Get_Name_String (Conf_Str);
608 0
                  Add_Str_To_Name_Buffer (":");
609 0
                  Get_Name_String_And_Append (Tmp_Name);
610 0
                  Conf_Str := Name_Find;
611
               end if;
612 1
            elsif Is_Defined_Property (E, "deployment::configuration")
613
              and then
614 0
                Get_String_Property (E, "deployment::configuration") /=
615
                No_Name
616
            then
617 0
               Get_Name_String
618 0
                 (Get_String_Property (E, "deployment::configuration"));
619 0
               Conf_Str := Name_Find;
620
            end if;
621

622
            --  Now, we look at the amount of buses connected to
623
            --  the device and which bus is connected to which
624
            --  device. As a result, the arrays
625
            --  __po_hi_devices_nb_accessed_bus and
626
            --  __po_hi_devices_accessed_bus will be created.
627

628 1
            Nb_Connected_Buses := 0;
629

630 1
            if not AAU.Is_Empty (Features (E)) then
631 1
               F := First_Node (Features (E));
632

633 1
               while Present (F) loop
634 1
                  if Kind (F) = K_Subcomponent_Access_Instance
635 1
                    and then AAU.Is_Bus (Corresponding_Instance (F))
636 1
                    and then First_Node (Sources (F)) /= No_Node
637
                  then
638

639 1
                     Accessed_Bus := Item (First_Node (Sources (F)));
640

641 1
                     Append_Node_To_List
642 1
                       (Make_Defining_Identifier
643 1
                          (Map_C_Enumerator_Name
644 1
                             (Corresponding_Instance (Accessed_Bus))),
645 1
                        CTN.Values (Accessed_Buses));
646

647 1
                     Nb_Connected_Buses := Nb_Connected_Buses + 1;
648
                  end if;
649 1
                  F := Next_Node (F);
650 1
               end loop;
651
            end if;
652

653
            --  If the device accesses at least one bus, we declare
654
            --  an array in ALL processed that detail the buses
655
            --  it accesses. Then, this array is contained
656
            --  in the global array __po_hi_devices_accessed_buses.
657
            --  For this reason, we are forced to process again
658
            --  all processes to add the new array to all processes.
659

660 1
            if not Is_Empty (CTN.Values (Accessed_Buses)) then
661 1
               Set_Deployment_Source;
662

663
               --  Here, we browse all the process components
664
               --  of the root system.
665 1
               Q := First_Node (Subcomponents (The_System));
666

667 1
               while Present (Q) loop
668 1
                  if AAU.Is_Process (Corresponding_Instance (Q)) then
669
                     U :=
670 1
                       CTN.Distributed_Application_Unit
671 1
                         (CTN.Naming_Node
672 1
                            (Backend_Node
673 1
                               (Identifier (Corresponding_Instance (Q)))));
674 1
                     P := CTN.Entity (U);
675

676 1
                     Push_Entity (P);
677 1
                     Push_Entity (U);
678

679 1
                     Set_Deployment_Source;
680

681
                     --  Here, we build the array that details the buses
682
                     --  accessed by the device and add it to each
683
                     --  deployment.c file of ALL processes.
684

685
                     N :=
686 1
                       Make_Expression
687
                         (Left_Expr =>
688 1
                            Make_Variable_Declaration
689
                              (Defining_Identifier =>
690 1
                                 Make_Array_Declaration
691
                                   (Defining_Identifier =>
692 1
                                      Make_Defining_Identifier
693 1
                                        (Map_Devices_Buses_Array_Name (E)),
694
                                    Array_Size =>
695 1
                                      Make_Literal
696 1
                                        (CV.New_Int_Value
697
                                           (Nb_Connected_Buses,
698
                                            1,
699
                                            10))),
700 1
                               Used_Type => RE (RE_Bus_Id)),
701
                          Operator   => Op_Equal,
702
                          Right_Expr => Accessed_Buses);
703

704 1
                     Append_Node_To_List (N, CTN.Declarations (Current_File));
705 1
                     Pop_Entity;
706 1
                     Pop_Entity;
707 1
                     Set_Deployment_Header;
708
                  end if;
709 1
                  Q := Next_Node (Q);
710 1
               end loop;
711

712 1
               Set_Deployment_Header;
713

714
               --  Finally, here, we reference the array name that
715
               --  contains connected buses to the main array
716
               --  __po_hi_devices_accessed_buses.
717

718 1
               Append_Node_To_List
719 1
                 (Make_Defining_Identifier (Map_Devices_Buses_Array_Name (E)),
720 1
                  CTN.Values (Devices_Buses_Array));
721
            else
722
               --  If no bus is connected, we just specify
723
               --  a null pointer, meaning that no bus is
724
               --  connected to this device.
725 0
               Append_Node_To_List
726 0
                 (Make_Defining_Identifier
727
                    (CONST (C_Null),
728
                     C_Conversion => False),
729 0
                  CTN.Values (Devices_Buses_Array));
730
            end if;
731

732 1
            Append_Node_To_List
733 1
              (Make_Literal (CV.New_Int_Value (Nb_Connected_Buses, 1, 10)),
734 1
               CTN.Values (Devices_Nb_Buses_Array));
735

736 1
            if Is_Defined_Property (E, "source_text") then
737 1
               Append_Node_To_List
738 1
                 (Make_Type_Conversion
739 1
                    (Make_Pointer_Type (RE (RE_Uint32_T)),
740 1
                     Make_Variable_Address
741 1
                       (Make_Defining_Identifier
742 1
                          (Map_Device_Confvar_Name (E)))),
743 1
                  CTN.Values (Devices_Confvars));
744 1
               Set_Deployment_Source;
745

746 1
               Device_Implementation := Get_Implementation (Current_Device);
747

748 1
               if Is_Defined_Property
749
                   (Device_Implementation,
750
                    "deployment::configuration_type")
751
               then
752
                  Configuration_Data :=
753 1
                    Get_Classifier_Property
754
                      (Device_Implementation,
755
                       "deployment::configuration_type");
756 1
                  if Configuration_Data /= No_Node
757 1
                    and then Is_Defined_Property
758
                      (Configuration_Data,
759
                       "type_source_name")
760
                  then
761
                     --  Here, we browse all the process components
762
                     --  of the root system to declare external
763
                     --  variable that contain the configuration
764
                     --  of the device.
765

766 1
                     Q := First_Node (Subcomponents (The_System));
767

768 1
                     while Present (Q) loop
769 1
                        if AAU.Is_Process (Corresponding_Instance (Q)) then
770
                           U :=
771 1
                             CTN.Distributed_Application_Unit
772 1
                               (CTN.Naming_Node
773 1
                                  (Backend_Node
774 1
                                     (Identifier
775 1
                                        (Corresponding_Instance (Q)))));
776 1
                           P := CTN.Entity (U);
777

778 1
                           Push_Entity (P);
779 1
                           Push_Entity (U);
780

781 1
                           Set_Deployment_Source;
782

783
                           N :=
784 1
                             Make_Extern_Entity_Declaration
785 1
                               (Make_Variable_Declaration
786
                                  (Defining_Identifier =>
787 1
                                     Make_Defining_Identifier
788 1
                                       (Map_Device_Confvar_Name (E)),
789
                                   Used_Type =>
790 1
                                     Make_Pointer_Type
791 1
                                       (Make_Defining_Identifier
792 1
                                          (Map_ASN_Type
793 1
                                             (Get_String_Property
794
                                                (Configuration_Data,
795
                                                 "type_source_name"))))));
796 1
                           Append_Node_To_List
797
                             (N,
798 1
                              CTN.Declarations (Current_File));
799 1
                           declare
800 1
                              ST : constant Name_Array :=
801 1
                                Get_Source_Text (Configuration_Data);
802 1
                              Include_Name : Name_Id;
803
                           begin
804 1
                              Set_Deployment_Header;
805

806 1
                              if ST'Length = 0 then
807 0
                                 Display_Error
808
                                   ("Source_Text property of " &
809
                                    "configuration data" &
810
                                    " must have at least one element " &
811
                                    "(the header file).",
812
                                    Fatal => True);
813
                              end if;
814

815 1
                              Include_Name := No_Name;
816

817 1
                              for Index in ST'Range loop
818 1
                                 Get_Name_String (ST (Index));
819 1
                                 if Name_Buffer (Name_Len - 1 .. Name_Len) =
820
                                   ".h"
821
                                 then
822
                                    Include_Name :=
823 1
                                      Get_String_Name
824 1
                                        (Name_Buffer (1 .. Name_Len - 2));
825
                                 end if;
826 1
                              end loop;
827

828 1
                              if Include_Name = No_Name then
829 0
                                 Display_Error
830
                                   ("Cannot find header file " &
831
                                    "that implements the data type",
832
                                    Fatal => True);
833
                              end if;
834

835 1
                              Add_Include
836 1
                                (Make_Include_Clause
837 1
                                   (Make_Defining_Identifier (Include_Name)));
838 1
                           end;
839 1
                           Pop_Entity;
840 1
                           Pop_Entity;
841
                        end if;
842 1
                        Q := Next_Node (Q);
843 1
                     end loop;
844
                  end if;
845
               end if;
846 1
               Append_Node_To_List
847 1
                 (Make_Literal
848 1
                    (CV.New_Pointed_Char_Value (Get_String_Name ("noaddr"))),
849 1
                  CTN.Values (Devices_Array));
850

851 1
               Set_Deployment_Header;
852
            else
853 0
               Append_Node_To_List
854 0
                 (Make_Literal (CV.New_Int_Value (0, 0, 10)),
855 0
                  CTN.Values (Devices_Confvars));
856

857 0
               if Conf_Str /= No_Name then
858 0
                  Append_Node_To_List
859 0
                    (Make_Literal (CV.New_Pointed_Char_Value (Conf_Str)),
860 0
                     CTN.Values (Devices_Array));
861
               else
862 0
                  Append_Node_To_List
863 0
                    (Make_Literal
864 0
                       (CV.New_Pointed_Char_Value
865 0
                          (Get_String_Name ("noaddr"))),
866 0
                     CTN.Values (Devices_Array));
867
               end if;
868
            end if;
869
         end if;
870 1
         Current_Device := No_Node;
871 1
      end Visit_Device_Instance;
872

873
      ----------------------------
874
      -- Visit_Process_Instance --
875
      ----------------------------
876

877 1
      procedure Visit_Process_Instance (E : Node_Id) is
878
         U : constant Node_Id :=
879 1
           CTN.Distributed_Application_Unit
880 1
             (CTN.Naming_Node (Backend_Node (Identifier (E))));
881 1
         P        : constant Node_Id := CTN.Entity (U);
882 1
         S        : constant Node_Id := Parent_Subcomponent (E);
883
         Root_Sys : constant Node_Id :=
884 1
           Parent_Component (Parent_Subcomponent (E));
885 1
         Driver_Name : Name_Id;
886 1
         Q           : Node_Id;
887 1
         N           : Node_Id;
888 1
         C           : Node_Id;
889 1
         F           : Node_Id;
890 1
         Data        : Node_Id;
891 1
         Src         : Node_Id;
892 1
         Dst         : Node_Id;
893 1
         Parent      : Node_Id;
894
         The_System  : constant Node_Id :=
895 1
           Parent_Component (Parent_Subcomponent (E));
896 1
         Device_Implementation : Node_Id;
897 1
         Node_Name   : Name_Id;
898

899
      begin
900 1
         pragma Assert (AAU.Is_System (Root_Sys));
901

902 1
         Nb_Nodes := 0;
903

904 1
         Set_Added (E, E);
905

906 1
         Current_Process_Instance := E;
907

908 1
         Tasks_Enumerator_List := New_List (CTN.K_Enumeration_Literals);
909 1
         Node_Enumerator_List  := New_List (CTN.K_Enumeration_Literals);
910

911 1
         Nb_Ports_List := New_List (CTN.K_List_Id);
912

913 1
         Push_Entity (P);
914 1
         Push_Entity (U);
915 1
         Set_Deployment_Header;
916

917 1
         Node_Identifier     := 0;
918 1
         Task_Identifier     := 0;
919 1
         Tasks_Stack         := 0;
920 1
         Nb_Protected        := 0;
921 1
         Nb_Ports_In_Process := 0;
922

923
         --  Define the name of the current node
924

925
         N :=
926 1
           Make_Define_Statement
927 1
             (Defining_Identifier => (RE (RE_My_Node)),
928
              Value               =>
929 1
                Make_Defining_Identifier
930 1
                  (Map_C_Enumerator_Name (Parent_Subcomponent (E))));
931 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
932

933
         Node_Name :=
934 1
           Map_C_Enumerator_Name (Parent_Subcomponent (E));
935 1
         Set_Str_To_Name_Buffer ("");
936 1
         Get_Name_String (Token_Image (Tok_Quote));
937 1
         Get_Name_String_And_Append (Node_Name);
938 1
         Get_Name_String_And_Append (Token_Image (Tok_Quote));
939

940 1
         Node_Name := Name_Find;
941

942
         N :=
943 1
           Make_Define_Statement
944 1
             (Defining_Identifier => RE (RE_My_Node_Name),
945
              Value               =>
946 1
                Make_Defining_Identifier (Node_Name));
947 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
948

949
         --  Visit all devices attached to the parent system that
950
         --  share the same processor as process E.
951

952 1
         if not AAU.Is_Empty (Subcomponents (The_System)) then
953 1
            C := First_Node (Subcomponents (The_System));
954 1
            while Present (C) loop
955 1
               if AAU.Is_Device (Corresponding_Instance (C))
956
                 and then
957 1
                   Get_Bound_Processor (Corresponding_Instance (C)) =
958 1
                   Get_Bound_Processor (E)
959
               then
960
                  --  Build the enumerator corresponding to the device
961
                  --  Note: we reuse the process name XXX
962

963 1
                  Visit_Device_Instance (Corresponding_Instance (C));
964

965 1
                  Current_Device := Corresponding_Instance (C);
966

967 1
                  Device_Implementation := Get_Implementation (Current_Device);
968

969 1
                  if Device_Implementation /= No_Node then
970 1
                     if not AAU.Is_Empty
971 1
                         (AAN.Subcomponents (Device_Implementation))
972
                     then
973
                        N :=
974 1
                          First_Node (Subcomponents (Device_Implementation));
975 1
                        while Present (N) loop
976 1
                           Visit_Component_Instance
977 1
                             (Corresponding_Instance (N));
978 1
                           N := Next_Node (N);
979 1
                        end loop;
980
                     end if;
981
                  end if;
982

983 1
                  Current_Device := No_Node;
984

985
               end if;
986 1
               C := Next_Node (C);
987 1
            end loop;
988
         end if;
989

990
         --  Visit all the subcomponents of the process
991

992 1
         if not AAU.Is_Empty (Subcomponents (E)) then
993 1
            C := First_Node (Subcomponents (E));
994

995 1
            while Present (C) loop
996 1
               if AAU.Is_Data (Corresponding_Instance (C)) then
997 1
                  N := Make_Literal (New_Int_Value (Nb_Protected, 1, 10));
998 1
                  Bind_AADL_To_Default_Value (Identifier (C), N);
999

1000 1
                  Nb_Protected := Nb_Protected + 1;
1001
               else
1002
                  --  Visit the component instance corresponding to the
1003
                  --  subcomponent S.
1004 1
                  Visit (Corresponding_Instance (C));
1005
               end if;
1006

1007 1
               C := Next_Node (C);
1008 1
            end loop;
1009
         end if;
1010

1011
         --  For each of the processes P connected to E, (1) we add an
1012
         --  enumerator corresponding to P and (2) for each one of the
1013
         --  threads of P, we add an enumerator.
1014

1015 1
         if not AAU.Is_Empty (Features (E)) then
1016 1
            F := First_Node (Features (E));
1017

1018 1
            while Present (F) loop
1019
               --  The sources of F
1020

1021 1
               if not AAU.Is_Empty (Sources (F)) then
1022 1
                  Src := First_Node (Sources (F));
1023

1024 1
                  while Present (Src) loop
1025

1026 1
                     Parent := Parent_Component (Item (Src));
1027

1028 1
                     if AAU.Is_Process (Parent) and then Parent /= E then
1029 1
                        if Get_Provided_Virtual_Bus_Class (Extra_Item (Src)) /=
1030
                          No_Node
1031
                        then
1032 0
                           Visit
1033 0
                             (Get_Provided_Virtual_Bus_Class
1034 0
                                (Extra_Item (Src)));
1035
                        end if;
1036

1037 1
                        Set_Added (Parent, E);
1038
                        --  Traverse all the subcomponents of Parent
1039

1040 1
                        if not AAU.Is_Empty (Subcomponents (Parent)) then
1041 1
                           C := First_Node (Subcomponents (Parent));
1042

1043 1
                           while Present (C) loop
1044 1
                              Visit (Corresponding_Instance (C));
1045

1046 1
                              C := Next_Node (C);
1047 1
                           end loop;
1048
                        end if;
1049

1050
                     --  Mark P as being Added
1051 1
                     elsif AAU.Is_Device (Parent) and then Parent /= E then
1052 0
                        Driver_Name := Get_Driver_Name (Parent);
1053

1054 0
                        if Driver_Name /= No_Name then
1055 0
                           Set_Str_To_Name_Buffer ("__PO_HI_NEED_DRIVER_");
1056 0
                           Get_Name_String_And_Append (Driver_Name);
1057

1058 0
                           Driver_Name := Name_Find;
1059 0
                           Driver_Name := To_Upper (Driver_Name);
1060

1061 0
                           Add_Define_Deployment
1062 0
                             (Make_Defining_Identifier
1063
                                (Driver_Name,
1064
                                 C_Conversion => False));
1065
                        end if;
1066
                     end if;
1067

1068 1
                     Src := Next_Node (Src);
1069 1
                  end loop;
1070
               end if;
1071

1072
               --  The destinations of F
1073

1074 1
               if not AAU.Is_Empty (Destinations (F)) then
1075 1
                  Dst := First_Node (Destinations (F));
1076

1077 1
                  while Present (Dst) loop
1078 1
                     Parent := Parent_Component (Item (Dst));
1079

1080 1
                     if AAU.Is_Process (Parent) and then Parent /= E then
1081 1
                        if Get_Provided_Virtual_Bus_Class (Extra_Item (Dst)) /=
1082
                          No_Node
1083
                        then
1084 0
                           Visit
1085 0
                             (Get_Provided_Virtual_Bus_Class
1086 0
                                (Extra_Item (Dst)));
1087
                        end if;
1088

1089 1
                        Set_Added (Parent, E);
1090

1091 1
                        if not AAU.Is_Empty (Subcomponents (Parent)) then
1092 1
                           C := First_Node (Subcomponents (Parent));
1093

1094 1
                           while Present (C) loop
1095 1
                              Visit (Corresponding_Instance (C));
1096

1097 1
                              C := Next_Node (C);
1098 1
                           end loop;
1099
                        end if;
1100 1
                     elsif AAU.Is_Device (Parent) and then Parent /= E then
1101 0
                        Driver_Name := Get_Driver_Name (Parent);
1102

1103 0
                        if Driver_Name /= No_Name then
1104 0
                           Set_Str_To_Name_Buffer ("__PO_HI_NEED_DRIVER_");
1105 0
                           Get_Name_String_And_Append (Driver_Name);
1106

1107 0
                           Driver_Name := Name_Find;
1108 0
                           Driver_Name := To_Upper (Driver_Name);
1109

1110 0
                           Append_Node_To_List
1111 0
                             (Make_Define_Statement
1112
                                (Defining_Identifier =>
1113 0
                                   (Make_Defining_Identifier
1114
                                      (Driver_Name,
1115
                                       C_Conversion => False)),
1116
                                 Value =>
1117 0
                                   (Make_Literal
1118 0
                                      (CV.New_Int_Value (1, 1, 10)))),
1119 0
                              CTN.Declarations (Current_File));
1120
                        end if;
1121
                     end if;
1122

1123 1
                     Dst := Next_Node (Dst);
1124 1
                  end loop;
1125
               end if;
1126

1127 1
               if Is_Data (F) then
1128 1
                  if Get_Source_Language (Corresponding_Instance (F)) =
1129
                    Language_Simulink
1130
                  then
1131 0
                     Data := Corresponding_Instance (F);
1132

1133 0
                     if Get_Source_Name (Data) /= No_Name then
1134
                        N :=
1135 0
                          Make_Define_Statement
1136 0
                            (Defining_Identifier => (RE (RE_Simulink_Node)),
1137
                             Value               =>
1138 0
                               Make_Defining_Identifier
1139 0
                                 (Get_Source_Name (Data)));
1140 0
                        Append_Node_To_List
1141
                          (N,
1142 0
                           CTN.Declarations (Current_File));
1143

1144
                        N :=
1145 0
                          Make_Define_Statement
1146
                            (Defining_Identifier =>
1147 0
                               (RE (RE_Simulink_Init_Func)),
1148 0
                             Value => Map_Simulink_Init_Func (Data));
1149 0
                        Append_Node_To_List
1150
                          (N,
1151 0
                           CTN.Declarations (Current_File));
1152

1153
                        N :=
1154 0
                          Make_Define_Statement
1155
                            (Defining_Identifier =>
1156 0
                               (RE (RE_Simulink_Model_Type)),
1157 0
                             Value => Map_Simulink_Model_Type (Data));
1158 0
                        Append_Node_To_List
1159
                          (N,
1160 0
                           CTN.Declarations (Current_File));
1161
                     end if;
1162
                  end if;
1163

1164
               end if;
1165

1166 1
               F := Next_Node (F);
1167 1
            end loop;
1168
         end if;
1169

1170 1
         Q := First_Node (Subcomponents (Root_Sys));
1171

1172 1
         while Present (Q) loop
1173 1
            if AAU.Is_Process (Corresponding_Instance (Q)) then
1174 1
               if Is_Added (Corresponding_Instance (Q), E) then
1175
                  N :=
1176 1
                    Make_Expression
1177 1
                      (Make_Defining_Identifier (Map_C_Enumerator_Name (Q)),
1178
                       Op_Equal,
1179 1
                       Make_Literal
1180 1
                         (CV.New_Int_Value (Node_Identifier, 0, 10)));
1181 1
                  Append_Node_To_List (N, Node_Enumerator_List);
1182 1
                  Node_Identifier := Node_Identifier + 1;
1183 1
                  Nb_Nodes        := Nb_Nodes + 1;
1184
               else
1185
                  N :=
1186 1
                    Make_Expression
1187 1
                      (Make_Defining_Identifier (Map_C_Enumerator_Name (Q)),
1188
                       Op_Equal,
1189 1
                       RE (RE_Unused_Node));
1190 1
                  Append_Node_To_List (N, Node_Enumerator_List);
1191
               end if;
1192
            end if;
1193

1194 1
            Q := Next_Node (Q);
1195 1
         end loop;
1196

1197
         --  Create the node enumeration type declaration. Note that
1198
         --  the type creation is possible even the enumeration list
1199
         --  is incomplete. We can do this in the first traversal
1200
         --  since we are sure that the enumerator list is not empty.
1201

1202
         N :=
1203 1
           Message_Comment
1204
             ("For each node in the distributed" &
1205
              " application add an enumerator");
1206 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1207

1208
         N :=
1209 1
           Make_Full_Type_Declaration
1210 1
             (Defining_Identifier => RE (RE_Node_T),
1211 1
              Type_Definition => Make_Enum_Aggregate (Node_Enumerator_List));
1212 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1213

1214
         --  Make sure the __po_hi_protocol_t enum type is defined
1215
         --  with at least the invalid_protocol value.
1216

1217 1
         if not Invalid_Protocol_Added then
1218 1
            Set_Str_To_Name_Buffer ("invalid_protocol");
1219
            N :=
1220 1
              Make_Expression
1221 1
                (Make_Defining_Identifier (Name_Find),
1222
                 Op_Equal,
1223 1
                 (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1224 1
            Append_Node_To_List (N, Protocol_List);
1225

1226 1
            Invalid_Protocol_Added := True;
1227
         end if;
1228

1229
         N :=
1230 1
           Make_Full_Type_Declaration
1231 1
             (Defining_Identifier => RE (RE_Protocol_T),
1232 1
              Type_Definition     => Make_Enum_Aggregate (Protocol_List));
1233 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1234

1235
         --  Create the thread enumeration type declaration. Note that
1236
         --  the type creation is possible even the enumeration list
1237
         --  is incomplete. This type may not be generated in case the
1238
         --  application is local.
1239

1240 1
         if not Is_Empty (Entity_Enumerator_List) then
1241
            N :=
1242 1
              Message_Comment
1243
                ("For each thread in the distributed" &
1244
                 " application nodes, add an" &
1245
                 " enumerator");
1246 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1247

1248 1
            if not Invalid_Entity_Added then
1249 1
               Set_Str_To_Name_Buffer ("invalid_entity");
1250
               N :=
1251 1
                 Make_Expression
1252 1
                   (Make_Defining_Identifier (Name_Find),
1253
                    Op_Equal,
1254 1
                    (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1255 1
               Append_Node_To_List (N, Entity_Enumerator_List);
1256 1
               Invalid_Entity_Added := True;
1257
            end if;
1258

1259
            N :=
1260 1
              Make_Full_Type_Declaration
1261 1
                (Defining_Identifier => RE (RE_Entity_T),
1262
                 Type_Definition     =>
1263 1
                   Make_Enum_Aggregate (Entity_Enumerator_List));
1264 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1265
         end if;
1266

1267 1
         Set_Str_To_Name_Buffer ("invalid_task_id");
1268
         N :=
1269 1
           Make_Expression
1270 1
             (Make_Defining_Identifier (Name_Find),
1271
              Op_Equal,
1272 1
              (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1273 1
         Append_Node_To_List (N, Tasks_Enumerator_List);
1274

1275
         N :=
1276 1
           Make_Full_Type_Declaration
1277 1
             (Defining_Identifier => RE (RE_Task_Id),
1278 1
              Type_Definition => Make_Enum_Aggregate (Tasks_Enumerator_List));
1279 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1280

1281
         N :=
1282 1
           Make_Full_Type_Declaration
1283 1
             (Defining_Identifier => RE (RE_Device_Id),
1284
              Type_Definition     =>
1285 1
                Make_Enum_Aggregate (Devices_Enumerator_List));
1286 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1287

1288
         N :=
1289 1
           Make_Full_Type_Declaration
1290 1
             (Defining_Identifier => RE (RE_Bus_Id),
1291 1
              Type_Definition => Make_Enum_Aggregate (Buses_Enumerator_List));
1292 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1293

1294
         N :=
1295 1
           Make_Define_Statement
1296 1
             (Defining_Identifier => RE (RE_Nb_Tasks),
1297 1
              Value => Make_Literal (New_Int_Value (Task_Identifier, 1, 10)));
1298 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1299

1300
         N :=
1301 1
           Make_Define_Statement
1302 1
             (Defining_Identifier => RE (RE_Tasks_Stack),
1303 1
              Value => Make_Literal (New_Int_Value (Tasks_Stack, 1, 10)));
1304 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1305

1306
         --  Add an enumerator corresponding to an INVALID server
1307
         --  entity to the entity list.
1308

1309
         N :=
1310 1
           Make_Define_Statement
1311 1
             (Defining_Identifier => RE (RE_Nb_Protected),
1312 1
              Value => Make_Literal (New_Int_Value (Nb_Protected, 1, 10)));
1313 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1314

1315
         N :=
1316 1
           Make_Define_Statement
1317 1
             (Defining_Identifier => RE (RE_Nb_Nodes),
1318 1
              Value => Make_Literal (New_Int_Value (Nb_Nodes, 1, 10)));
1319 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1320

1321
         N :=
1322 1
           Make_Define_Statement
1323 1
             (Defining_Identifier => RE (RE_Nb_Entities),
1324
              Value               => Nb_Entities_Node);
1325 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1326

1327
         --  If there are ports in the local process, we generate a
1328
         --  macro indicating the total number of ports in the
1329
         --  application, otherwise we generate a value of 0 to avoid
1330
         --  dragging the whole transport logic. This may happen in
1331
         --  corner cases when using external API for communication.
1332

1333 1
         if Nb_Ports_In_Process > 0 then
1334
            N :=
1335 1
              Make_Define_Statement
1336 1
              (Defining_Identifier => RE (RE_Nb_Ports),
1337
               Value               => Total_Ports_Node);
1338 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1339
         else
1340
            N :=
1341 1
              Make_Define_Statement
1342 1
              (Defining_Identifier => RE (RE_Nb_Ports),
1343 1
               Value               => Make_Literal (New_Int_Value (0, 1, 10)));
1344 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1345
         end if;
1346

1347 1
         if not Is_Empty (Global_Port_List) then
1348 1
            if not Invalid_Global_Port_Added then
1349 1
               Set_Str_To_Name_Buffer ("invalid_port_t");
1350
               N :=
1351 1
                 Make_Expression
1352 1
                   (Make_Defining_Identifier (Name_Find),
1353
                    Op_Equal,
1354 1
                    (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1355 1
               Append_Node_To_List (N, Global_Port_List);
1356

1357 1
               Invalid_Global_Port_Added := True;
1358
            end if;
1359

1360
            N :=
1361 1
              Make_Full_Type_Declaration
1362 1
                (Defining_Identifier => RE (RE_Port_T),
1363 1
                 Type_Definition => Make_Enum_Aggregate (Global_Port_List));
1364 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1365
         end if;
1366

1367 1
         if not Is_Empty (CTN.Values (Global_Port_To_Local)) then
1368 1
            Bind_AADL_To_Local_Port (Identifier (S), Global_Port_To_Local);
1369
         end if;
1370

1371 1
         if not Is_Empty (CTN.Values (Global_Port_To_Entity)) then
1372 1
            Bind_AADL_To_Global_Port (Identifier (S), Global_Port_To_Entity);
1373
         end if;
1374

1375 1
         if not Is_Empty (CTN.Values (Global_Port_Names)) then
1376 1
            Bind_AADL_To_Global_Names (Identifier (S), Global_Port_Names);
1377
         end if;
1378

1379 1
         if not Is_Empty (CTN.Values (Global_Port_Model_Names)) then
1380 1
            Bind_AADL_To_Global_Model_Names
1381 1
              (Identifier (S),
1382
               Global_Port_Model_Names);
1383
         end if;
1384

1385 1
         if not Invalid_Local_Port_Added then
1386 1
            Set_Str_To_Name_Buffer ("invalid_local_port_t");
1387
            N :=
1388 1
              Make_Expression
1389 1
              (Make_Defining_Identifier (Name_Find),
1390
               Op_Equal,
1391 1
               (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1392 1
            Append_Node_To_List (N, Local_Port_List);
1393

1394 1
            Invalid_Local_Port_Added := True;
1395
         end if;
1396

1397
         N :=
1398 1
           Make_Full_Type_Declaration
1399 1
           (Defining_Identifier => RE (RE_Local_Port_T),
1400 1
            Type_Definition     => Make_Enum_Aggregate (Local_Port_List));
1401 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1402

1403
         N :=
1404 1
           Make_Define_Statement
1405 1
             (Defining_Identifier => RE (RE_Nb_Devices),
1406
              Value               => Nb_Devices_Node);
1407 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1408

1409
         N :=
1410 1
           Make_Define_Statement
1411 1
             (Defining_Identifier => RE (RE_Nb_Buses),
1412
              Value               => Nb_Buses_Node);
1413 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1414

1415
         N :=
1416 1
           Make_Define_Statement
1417 1
             (Defining_Identifier => RE (RE_Nb_Protocols),
1418
              Value               => Nb_Protocols_Node);
1419 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
1420

1421
         --  Define the PORT_TYPE_CONTENT macro for the monitoring of entities
1422

1423
         declare
1424 1
            K                  : Node_Id;
1425 1
            Nb_Ports_List_Name : Name_Id := No_Name;
1426
         begin
1427 1
            K := CTN.First_Node (Nb_Ports_List);
1428

1429 1
            if Present (K) then
1430 1
               Get_Name_String (CTN.Name (K));
1431 1
               K := CTN.Next_Node (K);
1432 1
               while Present (K) loop
1433 1
                  Add_Str_To_Name_Buffer
1434 1
                    (", " & Get_Name_String (CTN.Name (K)));
1435 1
                  K := CTN.Next_Node (K);
1436 1
               end loop;
1437
            end if;
1438 1
            Nb_Ports_List_Name := Name_Find;
1439

1440
            N :=
1441 1
              Make_Define_Statement
1442 1
                (Defining_Identifier => RE (RE_Port_Type_Content),
1443 1
                 Value => Make_Defining_Identifier (Nb_Ports_List_Name));
1444 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1445
         end;
1446

1447 1
         Current_Process_Instance := No_Node;
1448

1449 1
         Pop_Entity; -- U
1450 1
         Pop_Entity; -- P
1451 1
      end Visit_Process_Instance;
1452

1453
      ---------------------------
1454
      -- Visit_System_Instance --
1455
      ---------------------------
1456

1457 1
      procedure Visit_System_Instance (E : Node_Id) is
1458 1
         S : Node_Id;
1459 1
         N : Node_Id;
1460
      begin
1461 1
         Push_Entity (C_Root);
1462

1463 1
         Global_Ports           := AAU.New_List (K_List_Id, No_Location);
1464 1
         Devices_Array          := Make_Array_Values;
1465 1
         Devices_Nb_Buses_Array := Make_Array_Values;
1466 1
         Devices_Confvars       := Make_Array_Values;
1467 1
         Protocols_Conf         := Make_Array_Values;
1468 1
         Devices_Buses_Array    := Make_Array_Values;
1469 1
         Port_To_Devices        := Make_Array_Values;
1470 1
         Devices_To_Nodes       := Make_Array_Values;
1471

1472 1
         Devices_Enumerator_List := New_List (CTN.K_Enumeration_Literals);
1473 1
         Buses_Enumerator_List   := New_List (CTN.K_Enumeration_Literals);
1474 1
         Global_Port_List        := New_List (CTN.K_Enumeration_Literals);
1475 1
         Protocol_List           := New_List (CTN.K_Enumeration_Literals);
1476 1
         Global_Port_Names       := Make_Array_Values;
1477 1
         Global_Port_Model_Names := Make_Array_Values;
1478 1
         Global_Port_Kind        := Make_Array_Values;
1479 1
         Global_Port_Queue_Size  := Make_Array_Values;
1480 1
         Global_Port_Data_Size   := Make_Array_Values;
1481 1
         Global_Port_To_Entity   := Make_Array_Values;
1482 1
         Global_Port_To_Local    := Make_Array_Values;
1483 1
         Entity_Enumerator_List  := New_List (CTN.K_Enumeration_Literals);
1484 1
         Local_Port_Values       := Make_Array_Values;
1485 1
         Local_Port_List         := New_List (CTN.K_Enumeration_Literals);
1486 1
         Total_Ports_Node        := Make_Literal (New_Int_Value (0, 1, 10));
1487 1
         Nb_Entities_Node        := Make_Literal (New_Int_Value (0, 1, 10));
1488 1
         Nb_Devices_Node         := Make_Literal (New_Int_Value (0, 1, 10));
1489 1
         Nb_Buses_Node           := Make_Literal (New_Int_Value (0, 1, 10));
1490 1
         Nb_Protocols_Node       := Make_Literal (New_Int_Value (0, 1, 10));
1491 1
         Entity_Array            := Make_Array_Values;
1492 1
         Device_Id               := 0;
1493

1494
         --  Automatically define invalid identifier
1495
         --  for devices and buses. These are fixed identifier
1496
         --  so that developpers can ALWAYS rely on it.
1497

1498 1
         Set_Str_To_Name_Buffer ("invalid_device_id");
1499
         N :=
1500 1
           Make_Expression
1501 1
             (Make_Defining_Identifier (Name_Find),
1502
              Op_Equal,
1503 1
              (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1504 1
         Append_Node_To_List (N, Devices_Enumerator_List);
1505

1506 1
         Set_Str_To_Name_Buffer ("invalid_bus_id");
1507
         N :=
1508 1
           Make_Expression
1509 1
             (Make_Defining_Identifier (Name_Find),
1510
              Op_Equal,
1511 1
              (Make_Literal (CV.New_Int_Value (1, -1, 10))));
1512 1
         Append_Node_To_List (N, Buses_Enumerator_List);
1513

1514
         --  Visit all the subcomponents of the system
1515

1516 1
         if not AAU.Is_Empty (Subcomponents (E)) then
1517 1
            S := First_Node (Subcomponents (E));
1518 1
            while Present (S) loop
1519
               --  Visit the component instance corresponding to the
1520
               --  subcomponent S.
1521

1522 1
               if Get_Current_Backend_Kind = PolyORB_HI_C
1523 1
                 and then not AAU.Is_Device (Corresponding_Instance (S))
1524
               then
1525 1
                  Visit (Corresponding_Instance (S));
1526
               else
1527 1
                  Visit (Corresponding_Instance (S));
1528
               end if;
1529 1
               S := Next_Node (S);
1530 1
            end loop;
1531
         end if;
1532

1533 1
         Set_Str_To_Name_Buffer ("constant_out_identifier");
1534
         N :=
1535 1
           Make_Expression
1536 1
             (Make_Defining_Identifier (Name_Find),
1537
              Op_Equal,
1538 1
              (Make_Literal
1539 1
                 (CV.New_Int_Value (Global_Port_Identifier + 1, 1, 10))));
1540 1
         Append_Node_To_List (N, Global_Port_List);
1541

1542 1
         CTN.Set_Value
1543
           (Total_Ports_Node,
1544 1
            New_Int_Value (Nb_Ports_Total, 1, 10));
1545

1546 1
         CTN.Set_Value
1547
           (Nb_Entities_Node,
1548 1
            New_Int_Value (Entity_Identifier, 1, 10));
1549

1550 1
         Pop_Entity; --  C_Root
1551 1
      end Visit_System_Instance;
1552

1553
      ---------------------------
1554
      -- Visit_Thread_Instance --
1555
      ---------------------------
1556

1557 1
      procedure Visit_Thread_Instance (E : Node_Id) is
1558 1
         N           : Node_Id;
1559 1
         F           : Node_Id;
1560 1
         P           : Node_Id;
1561 1
         S           : constant Node_Id := Parent_Subcomponent (E);
1562 1
         Call_Seq    : Node_Id;
1563 1
         Spg_Call    : Node_Id;
1564 1
         Used_Bus    : Node_Id;
1565 1
         Used_Device : Node_Id;
1566
         Impl_Kind   : constant Supported_Thread_Implementation :=
1567 1
           Get_Thread_Implementation_Kind (E);
1568
         Dispatch_Protocol : constant Supported_Thread_Dispatch_Protocol :=
1569 1
           Get_Thread_Dispatch_Protocol (E);
1570 1
         BA          : Node_Id;
1571
      begin
1572

1573 1
         Local_Port_Identifier := 0;
1574
         --  Build the enumerator corresponding to the thread. The
1575
         --  enumerator name is mapped from the the thread name and
1576
         --  its containing process name.
1577

1578 1
         Append_Existing
1579
           (S,
1580
            Entity_Enumerator_List,
1581
            Entity_Identifier,
1582
            Is_Entity => True);
1583

1584 1
         if not (Present (Backend_Node (Identifier (S))))
1585
           or else
1586 1
           (Present (Backend_Node (Identifier (S)))
1587 1
            and then No (CTN.Naming_Node (Backend_Node (Identifier (S)))))
1588
         then
1589 1
            if Current_Device /= No_Node then
1590
               N :=
1591 0
                 Make_Defining_Identifier
1592 0
                   (Map_C_Enumerator_Name
1593 0
                      (Parent_Subcomponent (Current_Process_Instance)));
1594
            else
1595
               N :=
1596 1
                 Make_Defining_Identifier
1597 1
                   (Map_C_Enumerator_Name
1598 1
                      (Parent_Subcomponent
1599 1
                         (Parent_Component (Parent_Subcomponent (E)))));
1600
            end if;
1601 1
            Bind_AADL_To_Naming (Identifier (S), N);
1602 1
            Append_Node_To_List (N, CTN.Values (Entity_Array));
1603
         end if;
1604

1605 1
         if Parent_Component (Parent_Subcomponent (E)) =
1606
           Current_Process_Instance
1607
         then
1608
            N :=
1609 1
              Make_Expression
1610 1
                (Make_Defining_Identifier
1611 1
                   (Map_C_Enumerator_Name (S, Entity => False)),
1612
                 Op_Equal,
1613 1
                 (Make_Literal (CV.New_Int_Value (Task_Identifier, 0, 10))));
1614 1
            Append_Node_To_List (N, Tasks_Enumerator_List);
1615 1
            Task_Identifier := Task_Identifier + 1;
1616

1617 1
            Tasks_Stack := Tasks_Stack + To_Bytes (Get_Thread_Stack_Size (E));
1618

1619 1
            if Impl_Kind = Thread_With_Behavior_Specification then
1620 1
               BA := Get_Behavior_Specification (E);
1621 1
               if BANu.Length (BATN.States (BA)) > 1 then
1622 1
                  Create_Enum_Type_Of_States_Names (E);
1623 1
                  Create_State_Type (E);
1624 1
                  if Dispatch_Protocol = Thread_Sporadic and then
1625 1
                    Compute_Nb_On_Dispatch_Transitions (E) > 1
1626
                  then
1627
                     N :=
1628 1
                      Make_Define_Statement
1629
                        (Defining_Identifier =>
1630 1
                          Make_Defining_Identifier
1631 1
                           (Map_C_Define_Name
1632
                              (S,
1633
                               Max_Dispatch_Transitions_Per_Complete_State =>
1634
                                 True)),
1635
                         Value =>
1636 1
                          Make_Literal
1637 1
                           (New_Int_Value
1638 1
                           (Compute_Max_Dispatch_Transitions_Per_Complete_State
1639
                              (E),
1640
                            1,
1641
                            10)));
1642 1
                     Append_Node_To_List (N, CTN.Declarations (Current_File));
1643

1644 1
                     N := Make_Define_Statement
1645
                       (Defining_Identifier =>
1646 1
                          Make_Defining_Identifier
1647 1
                            (Map_C_Define_Name
1648
                                 (S,
1649
                                  Max_Dispatch_Triggers_Per_Dispatch_Transition
1650
                                  => True)),
1651
                        Value =>
1652 1
                          Make_Literal
1653 1
                            (New_Int_Value
1654 1
                         (Compute_Max_Dispatch_Triggers_Per_Dispatch_Transition
1655
                                    (E), 1, 10)));
1656 1
                     Append_Node_To_List (N, CTN.Declarations (Current_File));
1657
                  end if;
1658
               end if;
1659
            end if;
1660
         end if;
1661

1662 1
         if Current_Device /= No_Node
1663 0
           and then Current_Process_Instance /= No_Node
1664
           and then
1665 0
             Get_Bound_Processor (Current_Device) =
1666 0
             Get_Bound_Processor (Current_Process_Instance)
1667
         then
1668
            N :=
1669 0
              Make_Expression
1670 0
                (Make_Defining_Identifier
1671 0
                   (Map_C_Enumerator_Name
1672
                      (S,
1673
                       Custom_Parent => Current_Device,
1674
                       Entity        => False)),
1675
                 Op_Equal,
1676 0
                 (Make_Literal (CV.New_Int_Value (Task_Identifier, 0, 10))));
1677 0
            Append_Node_To_List (N, Tasks_Enumerator_List);
1678 0
            Task_Identifier := Task_Identifier + 1;
1679 0
            Tasks_Stack := Tasks_Stack + To_Bytes (Get_Thread_Stack_Size (E));
1680
         end if;
1681

1682
         --  Get the Process parent of the thread
1683

1684 1
         if Current_Device /= No_Node then
1685 0
            P := Current_Device;
1686
         else
1687 1
            P := Parent_Component (S);
1688
         end if;
1689

1690
         N :=
1691 1
           Make_Defining_Identifier
1692 1
             (Map_C_Enumerator_Name (Parent_Subcomponent (P)));
1693

1694 1
         if Has_Ports (E) then
1695 1
            F := First_Node (Features (E));
1696

1697 1
            while Present (F) loop
1698 1
               if Kind (F) = K_Port_Spec_Instance then
1699 1
                  if No (Backend_Node (Identifier (F)))
1700
                    or else
1701 1
                    (Present (Backend_Node (Identifier (F)))
1702 1
                     and then No
1703 1
                       (CTN.Local_Port_Node (Backend_Node (Identifier (F)))))
1704
                  then
1705

1706
                     N :=
1707 1
                       Make_Expression
1708 1
                         (Make_Defining_Identifier
1709 1
                            (Map_C_Enumerator_Name (F, Local_Port => True)),
1710
                          Op_Equal,
1711 1
                          (Make_Literal
1712 1
                             (CV.New_Int_Value
1713
                                (Local_Port_Identifier,
1714
                                 0,
1715
                                 10))));
1716 1
                     Append_Node_To_List (N, Local_Port_List);
1717

1718 1
                     Append_Node_To_List
1719 1
                       (Make_Defining_Identifier (Map_C_Enumerator_Name (F)),
1720 1
                        CTN.Values (Local_Port_Values));
1721 1
                     Bind_AADL_To_Local_Port
1722 1
                       (Identifier (F),
1723
                        Local_Port_Values);
1724

1725 1
                     Nb_Ports_Total := Nb_Ports_Total + 1;
1726
                  end if;
1727

1728 1
                  Local_Port_Identifier := Local_Port_Identifier + 1;
1729 1
                  Nb_Ports_In_Process   := Nb_Ports_In_Process + 1;
1730

1731 1
                  if No (Backend_Node (Identifier (F)))
1732 1
                    or else No
1733 1
                      (CTN.Global_Port_Node (Backend_Node (Identifier (F))))
1734
                  then
1735 1
                     N := (Make_Literal (CV.New_Int_Value (1, -1, 10)));
1736

1737 1
                     Used_Bus := Get_Associated_Bus (F);
1738

1739 1
                     if Used_Bus /= No_Node then
1740 1
                        if AAU.Is_Virtual_Bus (Used_Bus) then
1741
                           Used_Bus :=
1742 0
                             Parent_Component (Parent_Subcomponent (Used_Bus));
1743
                        end if;
1744

1745
                        Used_Device :=
1746 1
                          Get_Device_Of_Process
1747
                            (Used_Bus,
1748 1
                             (Parent_Component (Parent_Subcomponent (E))));
1749 1
                        if Used_Device /= No_Node then
1750
                           N :=
1751 1
                             Make_Defining_Identifier
1752 1
                               (Map_C_Enumerator_Name
1753 1
                                  (Corresponding_Instance (Used_Device)));
1754
                        end if;
1755
                     end if;
1756

1757 1
                     Append_Node_To_List (N, CTN.Values (Port_To_Devices));
1758

1759
                     N :=
1760 1
                       Make_Defining_Identifier
1761 1
                         (Map_C_Enumerator_Name (F, Local_Port => True));
1762 1
                     Append_Node_To_List
1763
                       (N,
1764 1
                        CTN.Values (Global_Port_To_Local));
1765

1766
                     N :=
1767 1
                       Make_Defining_Identifier
1768 1
                         (Map_C_Enumerator_Name
1769
                            (S,
1770
                             Entity        => True,
1771
                             Custom_Parent => Current_Device));
1772 1
                     Append_Node_To_List
1773
                       (N,
1774 1
                        CTN.Values (Global_Port_To_Entity));
1775

1776
                     --  For each feature of a thread, we define a
1777
                     --  global port name as the name of the process
1778
                     --  port.
1779
                     --
1780
                     --  Note: these names are also used by some other
1781
                     --  backend, e.g. as part of TSP configuration.
1782

1783
                     declare
1784 1
                        F_L : constant List_Id :=
1785 1
                          (if Is_In (F) then
1786 1
                             AAN.Sources (F) else
1787 1
                             AAN.Destinations (F));
1788 1
                        F_N : constant Node_Id := AAN.First_Node (F_L);
1789
                     begin
1790 1
                        if Present (F_N) then
1791
                           N :=
1792 1
                             Make_Literal
1793 1
                             (CV.New_Pointed_Char_Value
1794 1
                                (Map_C_Enumerator_Name
1795 1
                                   (Item (F_N),
1796
                                    Fully_Qualify_Parent => True)));
1797
                        else
1798
                           --  There is no process port (e.g. thread
1799
                           --  to thread connection), then we just use
1800
                           --  the feature name.
1801
                           N :=
1802 1
                             Make_Literal
1803 1
                             (CV.New_Pointed_Char_Value
1804 1
                                (Map_C_Enumerator_Name
1805
                                   (F,
1806
                                    Fully_Qualify_Parent => True)));
1807
                        end if;
1808 1
                        Append_Node_To_List
1809 1
                          (N, CTN.Values (Global_Port_Names));
1810
                     end;
1811

1812
                     N :=
1813 1
                       Make_Literal
1814 1
                         (CV.New_Pointed_Char_Value
1815 1
                            (To_Lower (Display_Name (Identifier (F)))));
1816 1
                     Append_Node_To_List
1817
                       (N,
1818 1
                        CTN.Values (Global_Port_Model_Names));
1819

1820 1
                     if Is_In (F) then
1821 1
                        if Get_Connection_Pattern (F) = Intra_Process then
1822 1
                           if Is_Data (F) and then Is_Event (F) then
1823 1
                              Append_Node_To_List
1824 1
                                (RE (RE_In_Event_Data_Intra_Process),
1825 1
                                 CTN.Values (Global_Port_Kind));
1826 1
                           elsif Is_Data (F) and then not Is_Event (F) then
1827 1
                              Append_Node_To_List
1828 1
                                (RE (RE_In_Data_Intra_Process),
1829 1
                                 CTN.Values (Global_Port_Kind));
1830
                           else
1831 1
                              Append_Node_To_List
1832 1
                                (RE (RE_In_Event_Intra_Process),
1833 1
                                 CTN.Values (Global_Port_Kind));
1834
                           end if;
1835
                        else
1836 1
                           if Is_Data (F) and then Is_Event (F) then
1837 1
                              Append_Node_To_List
1838 1
                                (RE (RE_In_Event_Data_Inter_Process),
1839 1
                                 CTN.Values (Global_Port_Kind));
1840 1
                           elsif Is_Data (F) and then not Is_Event (F) then
1841 1
                              Append_Node_To_List
1842 1
                                (RE (RE_In_Data_Inter_Process),
1843 1
                                 CTN.Values (Global_Port_Kind));
1844
                           else
1845 0
                              Append_Node_To_List
1846 0
                                (RE (RE_In_Event_Inter_Process),
1847 0
                                 CTN.Values (Global_Port_Kind));
1848
                           end if;
1849

1850
                        end if;
1851 1
                     elsif Is_Out (F) then
1852 1
                        if Get_Connection_Pattern (F) = Intra_Process then
1853 1
                           if Is_Data (F) and then Is_Event (F) then
1854 1
                              Append_Node_To_List
1855 1
                                (RE (RE_Out_Event_Data_Intra_Process),
1856 1
                                 CTN.Values (Global_Port_Kind));
1857 1
                           elsif Is_Data (F) and then not Is_Event (F) then
1858 1
                              Append_Node_To_List
1859 1
                                (RE (RE_Out_Data_Intra_Process),
1860 1
                                 CTN.Values (Global_Port_Kind));
1861
                           else
1862 1
                              Append_Node_To_List
1863 1
                                (RE (RE_Out_Event_Intra_Process),
1864 1
                                 CTN.Values (Global_Port_Kind));
1865
                           end if;
1866
                        else
1867 1
                           if Is_Data (F) and then Is_Event (F) then
1868 1
                              Append_Node_To_List
1869 1
                                (RE (RE_Out_Event_Data_Inter_Process),
1870 1
                                 CTN.Values (Global_Port_Kind));
1871 1
                           elsif Is_Data (F) and then not Is_Event (F) then
1872 1
                              Append_Node_To_List
1873 1
                                (RE (RE_Out_Data_Inter_Process),
1874 1
                                 CTN.Values (Global_Port_Kind));
1875
                           else
1876 0
                              Append_Node_To_List
1877 0
                                (RE (RE_Out_Event_Inter_Process),
1878 0
                                 CTN.Values (Global_Port_Kind));
1879
                           end if;
1880
                        end if;
1881
                     end if;
1882

1883 1
                     if Is_Data (F) then
1884 1
                        Append_Node_To_List
1885 1
                          (Get_Data_Size (Corresponding_Instance (F),
1886
                                          Maximum_Size => True),
1887 1
                           CTN.Values (Global_Port_Data_Size));
1888
                     end if;
1889

1890
                     --  Map port queue size in Global_Port_Size We
1891
                     --  consider process ports, and then thread port
1892
                     --  when computing queue size. This is to be
1893
                     --  consistent with process (or TSP partitions)
1894
                     --  defining a queue size for inter-partition
1895
                     --  communications.
1896

1897 1
                     if Is_Event (F) then
1898
                        declare
1899 1
                           F_L : constant List_Id :=
1900 1
                             (if Is_In (F) then
1901 1
                             AAN.Sources (F) else
1902 1
                             AAN.Destinations (F));
1903 1
                           F_N : constant Node_Id := AAN.First_Node (F_L);
1904
                        begin
1905 1
                           if Present (F_N)  and then
1906 1
                             Is_Event (Item (F_N)) and then
1907 1
                             Get_Queue_Size (Item (F_N)) /= -1
1908
                           then
1909 1
                              Append_Node_To_List
1910 1
                                (Make_Literal
1911 1
                                   (CV.New_Int_Value
1912
                                      (Unsigned_Long_Long
1913 1
                                         (Get_Queue_Size (Item (F_N))),
1914
                                       0,
1915
                                       10)),
1916 1
                                 CTN.Values (Global_Port_Queue_Size));
1917
                           else
1918 1
                              Append_Node_To_List
1919 1
                                (Make_Literal (CV.New_Int_Value (1, 0, 10)),
1920 1
                                 CTN.Values (Global_Port_Queue_Size));
1921
                           end if;
1922
                        end;
1923
                     else
1924 1
                        if Is_Event (F) and then Get_Queue_Size (F) /= -1 then
1925 0
                           Append_Node_To_List
1926 0
                             (Make_Literal
1927 0
                                (CV.New_Int_Value
1928 0
                                   (Unsigned_Long_Long (Get_Queue_Size (F)),
1929
                                    0,
1930
                                    10)),
1931 0
                              CTN.Values (Global_Port_Queue_Size));
1932
                        else
1933 1
                           Append_Node_To_List
1934 1
                             (Make_Literal (CV.New_Int_Value (1, 0, 10)),
1935 1
                              CTN.Values (Global_Port_Queue_Size));
1936
                        end if;
1937
                     end if;
1938

1939
                     --  We associate a unique identifier to the port
1940
                     --  within the global distributed architecture.
1941

1942
                     N :=
1943 1
                       Make_Expression
1944 1
                         (Make_Defining_Identifier (Map_C_Enumerator_Name (F)),
1945
                          Op_Equal,
1946 1
                          (Make_Literal
1947 1
                             (CV.New_Int_Value
1948
                                (Global_Port_Identifier,
1949
                                 0,
1950
                                 10))));
1951 1
                     Append_Node_To_List (N, Global_Port_List);
1952

1953
                     --  We also store the port in a list to process
1954
                     --  it later. By doing so, we ensure that we have
1955
                     --  each port only one time in this time and in
1956
                     --  the same order than the identifiers.
1957

1958 1
                     AAU.Append_Node_To_List
1959 1
                       (AAU.Make_Node_Container (F),
1960
                        Global_Ports);
1961

1962
                     --  Finally, we associate the backend node
1963
                     --  with something to indicate that we already
1964
                     --  processed this port. It avoids any double
1965
                     --  processing of the same port.
1966

1967 1
                     Bind_AADL_To_Global_Port
1968 1
                       (Identifier (F),
1969 1
                        Make_Defining_Identifier (Map_C_Enumerator_Name (F)));
1970

1971 1
                     Global_Port_Identifier := Global_Port_Identifier + 1;
1972
                  end if;
1973

1974
               end if;
1975

1976 1
               F := Next_Node (F);
1977 1
            end loop;
1978

1979 1
            if Parent_Component (Parent_Subcomponent (E)) =
1980
              Current_Process_Instance
1981
              or else
1982 1
              (Current_Device /= No_Node
1983
               and then
1984 0
                 Get_Bound_Processor (Current_Device) =
1985 0
                 Get_Bound_Processor (Current_Process_Instance))
1986
            then
1987
               N :=
1988 1
                 Make_Define_Statement
1989
                   (Defining_Identifier =>
1990 1
                      Make_Defining_Identifier
1991 1
                        (Map_C_Define_Name (S, Nb_Ports => True)),
1992
                    Value =>
1993 1
                      Make_Literal
1994 1
                        (New_Int_Value (Local_Port_Identifier, 1, 10)));
1995 1
               Append_Node_To_List (N, CTN.Declarations (Current_File));
1996

1997
               N :=
1998 1
                 Make_Defining_Identifier
1999 1
                   (Map_C_Define_Name (S, Nb_Ports => True));
2000 1
               Append_Node_To_List (N, Nb_Ports_List);
2001
            end if;
2002
         end if;
2003

2004 1
         if Parent_Component (Parent_Subcomponent (E)) =
2005
           Current_Process_Instance
2006 1
           and then not AAU.Is_Empty (Calls (E))
2007
         then
2008 1
            Call_Seq := First_Node (Calls (E));
2009

2010 1
            while Present (Call_Seq) loop
2011
               --  For each call sequence visit all the called
2012
               --  subprograms.
2013

2014 1
               if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
2015 1
                  Spg_Call := First_Node (Subprogram_Calls (Call_Seq));
2016

2017 1
                  while Present (Spg_Call) loop
2018 1
                     Visit (Corresponding_Instance (Spg_Call));
2019

2020 1
                     Spg_Call := Next_Node (Spg_Call);
2021 1
                  end loop;
2022
               end if;
2023

2024 1
               Call_Seq := Next_Node (Call_Seq);
2025 1
            end loop;
2026
         end if;
2027

2028 1
      end Visit_Thread_Instance;
2029

2030
      -------------------------------
2031
      -- Visit_Subprogram_Instance --
2032
      -------------------------------
2033

2034 1
      procedure Visit_Subprogram_Instance (E : Node_Id) is
2035 1
         N : Node_Id;
2036 1
         S : constant Node_Id := Parent_Subcomponent (E);
2037
      begin
2038 1
         if Get_Subprogram_Kind (E) = Subprogram_Simulink then
2039

2040 0
            if Get_Source_Name (E) = No_Name then
2041 0
               Display_Error
2042
                 ("Simulink subprogram must have a" & " source_name property",
2043
                  Fatal => True);
2044
            end if;
2045

2046 0
            if not (Present (Backend_Node (Identifier (S))))
2047
              or else
2048 0
              (Present (Backend_Node (Identifier (S)))
2049 0
               and then No (CTN.Naming_Node (Backend_Node (Identifier (S)))))
2050
            then
2051
               N :=
2052 0
                 Make_Define_Statement
2053 0
                   (Defining_Identifier => (RE (RE_Simulink_Node)),
2054 0
                    Value => Make_Defining_Identifier (Get_Source_Name (E)));
2055 0
               Append_Node_To_List (N, CTN.Declarations (Current_File));
2056

2057
               N :=
2058 0
                 Make_Define_Statement
2059 0
                   (Defining_Identifier => (RE (RE_Simulink_Init_Func)),
2060 0
                    Value               => Map_Simulink_Init_Func (E));
2061 0
               Append_Node_To_List (N, CTN.Declarations (Current_File));
2062

2063
               N :=
2064 0
                 Make_Define_Statement
2065 0
                   (Defining_Identifier => (RE (RE_Simulink_Model_Type)),
2066 0
                    Value               => Map_Simulink_Model_Type (E));
2067 0
               Append_Node_To_List (N, CTN.Declarations (Current_File));
2068

2069 0
               Bind_AADL_To_Naming (Identifier (S), N);
2070
            end if;
2071

2072
         end if;
2073 1
      end Visit_Subprogram_Instance;
2074

2075
   end Header_File;
2076

2077
   -----------------
2078
   -- Source_File --
2079
   -----------------
2080

2081
   package body Source_File is
2082

2083
      procedure Visit_Architecture_Instance (E : Node_Id);
2084
      procedure Visit_Component_Instance (E : Node_Id);
2085
      procedure Visit_System_Instance (E : Node_Id);
2086
      procedure Visit_Process_Instance (E : Node_Id);
2087
      procedure Visit_Thread_Instance (E : Node_Id);
2088

2089 1
      Protocols_Ports_Array : Node_Id;
2090

2091
      -----------
2092
      -- Visit --
2093
      -----------
2094

2095 1
      procedure Visit (E : Node_Id) is
2096
      begin
2097 1
         case Kind (E) is
2098 1
            when K_Architecture_Instance =>
2099 1
               Visit_Architecture_Instance (E);
2100

2101 1
            when K_Component_Instance =>
2102 1
               Visit_Component_Instance (E);
2103

2104 0
            when others =>
2105 0
               null;
2106 1
         end case;
2107 1
      end Visit;
2108

2109
      ---------------------------------
2110
      -- Visit_Architecture_Instance --
2111
      ---------------------------------
2112

2113 1
      procedure Visit_Architecture_Instance (E : Node_Id) is
2114
      begin
2115 1
         Visit (Root_System (E));
2116 1
      end Visit_Architecture_Instance;
2117

2118
      ------------------------------
2119
      -- Visit_Component_Instance --
2120
      ------------------------------
2121

2122 1
      procedure Visit_Component_Instance (E : Node_Id) is
2123
         Category : constant Component_Category :=
2124 1
           Get_Category_Of_Component (E);
2125
      begin
2126 1
         case Category is
2127 1
            when CC_System =>
2128 1
               Visit_System_Instance (E);
2129

2130 1
            when CC_Process =>
2131 1
               Visit_Process_Instance (E);
2132

2133 1
            when CC_Thread =>
2134 1
               Visit_Thread_Instance (E);
2135

2136 1
            when others =>
2137 1
               null;
2138 1
         end case;
2139 1
      end Visit_Component_Instance;
2140

2141
      ----------------------------
2142
      -- Visit_Process_Instance --
2143
      ----------------------------
2144

2145 1
      procedure Visit_Process_Instance (E : Node_Id) is
2146
         U : constant Node_Id :=
2147 1
           CTN.Distributed_Application_Unit
2148 1
             (CTN.Naming_Node (Backend_Node (Identifier (E))));
2149 1
         P        : constant Node_Id := CTN.Entity (U);
2150 1
         S        : constant Node_Id := Parent_Subcomponent (E);
2151 1
         N        : Node_Id;
2152 1
         Q        : Node_Id;
2153 1
         C        : Node_Id;
2154
         Root_Sys : constant Node_Id :=
2155 1
           Parent_Component (Parent_Subcomponent (E));
2156 1
         Endiannesses            : constant Node_Id := Make_Array_Values;
2157 1
         Execution_Platform      : Supported_Execution_Platform;
2158 1
         Protected_Configuration : constant Node_Id := Make_Array_Values;
2159 1
         Protected_Priorities    : constant Node_Id := Make_Array_Values;
2160 1
         Protected_Protocol      : Node_Id;
2161 1
         Protected_Priority      : Node_Id;
2162
      begin
2163 1
         Push_Entity (P);
2164 1
         Push_Entity (U);
2165 1
         Set_Deployment_Source;
2166

2167 1
         if not AAU.Is_Empty (Subcomponents (E)) then
2168 1
            C := First_Node (Subcomponents (E));
2169

2170 1
            while Present (C) loop
2171 1
               if AAU.Is_Data (Corresponding_Instance (C)) then
2172
                  Protected_Priority :=
2173 1
                    Make_Literal (New_Int_Value (0, 1, 10));
2174

2175 1
                  case Get_Concurrency_Protocol (Corresponding_Instance (C)) is
2176
                     when Priority_Ceiling =>
2177
                        Protected_Priority :=
2178 0
                          Make_Literal
2179 0
                            (New_Int_Value
2180 0
                               (Get_Priority_Celing_Of_Data_Access
2181 0
                                  (Corresponding_Instance (C)),
2182
                                1,
2183
                                10));
2184 0
                        Protected_Protocol := RE (RE_Protected_PCP);
2185

2186
                     when others =>
2187 1
                        Protected_Protocol := RE (RE_Protected_Regular);
2188
                  end case;
2189

2190 1
                  Append_Node_To_List
2191
                    (Protected_Protocol,
2192 1
                     CTN.Values (Protected_Configuration));
2193

2194 1
                  Append_Node_To_List
2195
                    (Protected_Priority,
2196 1
                     CTN.Values (Protected_Priorities));
2197
               end if;
2198

2199 1
               Visit (Corresponding_Instance (C));
2200 1
               C := Next_Node (C);
2201 1
            end loop;
2202
         end if;
2203

2204 1
         if not Is_Empty (CTN.Values (Protected_Configuration)) then
2205
            N :=
2206 1
              Make_Expression
2207
                (Left_Expr =>
2208 1
                   Make_Variable_Declaration
2209
                     (Defining_Identifier =>
2210 1
                        Make_Array_Declaration
2211
                          (Defining_Identifier =>
2212 1
                             RE (RE_Protected_Configuration),
2213 1
                           Array_Size => RE (RE_Nb_Protected)),
2214 1
                      Used_Type => RE (RE_Protected_Protocol_T)),
2215
                 Operator   => Op_Equal,
2216
                 Right_Expr => Protected_Configuration);
2217 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2218

2219
            N :=
2220 1
              Make_Expression
2221
                (Left_Expr =>
2222 1
                   Make_Variable_Declaration
2223
                     (Defining_Identifier =>
2224 1
                        Make_Array_Declaration
2225 1
                          (Defining_Identifier => RE (RE_Protected_Priorities),
2226 1
                           Array_Size          => RE (RE_Nb_Protected)),
2227 1
                      Used_Type => RE (RE_Uint8_T)),
2228
                 Operator   => Op_Equal,
2229
                 Right_Expr => Protected_Priorities);
2230 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2231
         end if;
2232

2233 1
         if Present (Backend_Node (Identifier (S)))
2234 1
           and then Present
2235 1
             (CTN.Global_Port_Node (Backend_Node (Identifier (S))))
2236
         then
2237
            N :=
2238 1
              Make_Expression
2239
                (Left_Expr =>
2240 1
                   Make_Variable_Declaration
2241
                     (Defining_Identifier =>
2242 1
                        Make_Array_Declaration
2243
                          (Defining_Identifier =>
2244 1
                             RE (RE_Port_Global_To_Entity),
2245 1
                           Array_Size => RE (RE_Nb_Ports)),
2246 1
                      Used_Type => RE (RE_Entity_T)),
2247
                 Operator   => Op_Equal,
2248
                 Right_Expr =>
2249 1
                   CTN.Global_Port_Node (Backend_Node (Identifier (S))));
2250 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2251
         end if;
2252

2253 1
         if Present (Backend_Node (Identifier (S)))
2254 1
           and then Present
2255 1
             (CTN.Global_Names_Node (Backend_Node (Identifier (S))))
2256
         then
2257
            N :=
2258 1
              Make_Expression
2259
                (Left_Expr =>
2260 1
                   Make_Variable_Declaration
2261
                     (Defining_Identifier =>
2262 1
                        Make_Array_Declaration
2263 1
                          (Defining_Identifier => RE (RE_Port_Global_Names),
2264 1
                           Array_Size          => RE (RE_Nb_Ports)),
2265
                      Used_Type =>
2266 1
                        CTU.Make_Pointer_Type (New_Node (CTN.K_Char))),
2267
                 Operator   => Op_Equal,
2268
                 Right_Expr =>
2269 1
                   CTN.Global_Names_Node (Backend_Node (Identifier (S))));
2270 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2271
         end if;
2272

2273 1
         if Present (Backend_Node (Identifier (S)))
2274 1
           and then Present
2275 1
             (CTN.Global_Model_Names_Node (Backend_Node (Identifier (S))))
2276
         then
2277
            N :=
2278 1
              Make_Expression
2279
                (Left_Expr =>
2280 1
                   Make_Variable_Declaration
2281
                     (Defining_Identifier =>
2282 1
                        Make_Array_Declaration
2283
                          (Defining_Identifier =>
2284 1
                             RE (RE_Port_Global_Model_Names),
2285 1
                           Array_Size => RE (RE_Nb_Ports)),
2286
                      Used_Type =>
2287 1
                        CTU.Make_Pointer_Type (New_Node (CTN.K_Char))),
2288
                 Operator   => Op_Equal,
2289
                 Right_Expr =>
2290 1
                   CTN.Global_Model_Names_Node
2291 1
                     (Backend_Node (Identifier (S))));
2292 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2293

2294
            N :=
2295 1
              Make_Expression
2296
                (Left_Expr =>
2297 1
                   Make_Variable_Declaration
2298
                     (Defining_Identifier =>
2299 1
                        Make_Array_Declaration
2300 1
                          (Defining_Identifier => RE (RE_Port_Global_Kind),
2301 1
                           Array_Size          => RE (RE_Nb_Ports)),
2302 1
                      Used_Type => RE (RE_Port_Kind_T)),
2303
                 Operator   => Op_Equal,
2304
                 Right_Expr => Global_Port_Kind);
2305 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2306

2307
            N :=
2308 1
              Make_Expression
2309
                (Left_Expr =>
2310 1
                   Make_Variable_Declaration
2311
                     (Defining_Identifier =>
2312 1
                        Make_Array_Declaration
2313
                          (Defining_Identifier =>
2314 1
                             RE (RE_Port_Global_Data_Size),
2315 1
                           Array_Size => RE (RE_Nb_Ports)),
2316 1
                      Used_Type => RE (RE_Uint32_T)),
2317
                 Operator   => Op_Equal,
2318
                 Right_Expr => Global_Port_Data_Size);
2319 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2320

2321
            N :=
2322 1
              Make_Expression
2323
                (Left_Expr =>
2324 1
                   Make_Variable_Declaration
2325
                     (Defining_Identifier =>
2326 1
                        Make_Array_Declaration
2327
                          (Defining_Identifier =>
2328 1
                             RE (RE_Port_Global_Queue_Size),
2329 1
                           Array_Size => RE (RE_Nb_Ports)),
2330 1
                      Used_Type => RE (RE_Uint32_T)),
2331
                 Operator   => Op_Equal,
2332
                 Right_Expr => Global_Port_Queue_Size);
2333 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2334

2335
            --  Add the array that contains the protocols
2336
            --  used for each port.
2337

2338 1
            if not CTU.Is_Empty (CTN.Values (Protocols_Ports_Array))
2339 1
              and then not CTU.Is_Empty
2340 1
                (CTN.Values
2341 1
                   (CTN.First_Node (CTN.Values (Protocols_Ports_Array))))
2342 1
              and then not AAU.Is_Empty (Global_Ports)
2343 1
              and then Protocol_Identifier > 0
2344
            then
2345
               N :=
2346 0
                 Make_Expression
2347
                   (Left_Expr =>
2348 0
                      Make_Variable_Declaration
2349
                        (Defining_Identifier =>
2350 0
                           Make_Array_Declaration
2351
                             (Defining_Identifier =>
2352 0
                                Make_Array_Declaration
2353
                                  (Defining_Identifier =>
2354 0
                                     RE (RE_Ports_Protocols),
2355 0
                                   Array_Size => RE (RE_Nb_Ports)),
2356 0
                              Array_Size => RE (RE_Nb_Ports)),
2357 0
                         Used_Type => RE (RE_Protocol_T)),
2358
                    Operator   => Op_Equal,
2359
                    Right_Expr => Protocols_Ports_Array);
2360 0
               Append_Node_To_List (N, CTN.Declarations (Current_File));
2361
            end if;
2362
         end if;
2363

2364 1
         if Present (Backend_Node (Identifier (S)))
2365 1
           and then Present
2366 1
             (CTN.Local_Port_Node (Backend_Node (Identifier (S))))
2367
         then
2368
            N :=
2369 1
              Make_Expression
2370
                (Left_Expr =>
2371 1
                   Make_Variable_Declaration
2372
                     (Defining_Identifier =>
2373 1
                        Make_Array_Declaration
2374 1
                          (Defining_Identifier => RE (RE_Port_Global_To_Local),
2375 1
                           Array_Size          => RE (RE_Nb_Ports)),
2376 1
                      Used_Type => RE (RE_Local_Port_T)),
2377
                 Operator   => Op_Equal,
2378
                 Right_Expr =>
2379 1
                   CTN.Local_Port_Node (Backend_Node (Identifier (S))));
2380 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2381
         end if;
2382

2383
--         if Present (Backend_Node (Identifier (S))) and then
2384
--           Present (CTN.Entities_Node (Backend_Node (Identifier (S)))) then
2385
         N :=
2386 1
           Make_Expression
2387
             (Left_Expr =>
2388 1
                Make_Variable_Declaration
2389
                  (Defining_Identifier =>
2390 1
                     Make_Array_Declaration
2391 1
                       (Defining_Identifier => RE (RE_Entity_Table),
2392 1
                        Array_Size          => RE (RE_Nb_Entities)),
2393 1
                   Used_Type => RE (RE_Node_T)),
2394
              Operator   => Op_Equal,
2395
              Right_Expr => Entity_Array);
2396
--              CTN.Entities_Node (Backend_Node (Identifier (S))));
2397 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
2398
--         end if;
2399

2400 1
         Q := First_Node (Subcomponents (Root_Sys));
2401

2402 1
         while Present (Q) loop
2403 1
            if AAU.Is_Process (Corresponding_Instance (Q))
2404 1
              and then Is_Added (Corresponding_Instance (Q), E)
2405
            then
2406
               Execution_Platform :=
2407 1
                 Get_Execution_Platform
2408 1
                   (Get_Bound_Processor (Corresponding_Instance (Q)));
2409 1
               case Execution_Platform is
2410 1
                  when Platform_Native              |
2411
                    Platform_None                   |
2412
                    Platform_MSP430_FREERTOS        |
2413
                    Platform_LINUX32_XENOMAI_NATIVE |
2414
                    Platform_Native_Compcert        |
2415
                    Platform_LINUX32_XENOMAI_POSIX  |
2416
                    Platform_WIN32                  |
2417
                    Platform_LINUX_DLL              |
2418
                    Platform_LINUX64                |
2419
                    Platform_LINUX32                =>
2420 1
                     Append_Node_To_List
2421 1
                       (RE (RE_Littleendian),
2422 1
                        CTN.Values (Endiannesses));
2423

2424 1
                  when Platform_AIR              |
2425
                    Platform_AIR_IOP             |
2426
                    Platform_LEON_RTEMS          |
2427
                    Platform_LEON_RTEMS_POSIX    |
2428
                    Platform_LEON_ORK            |
2429
                    Platform_LEON3_XM3           =>
2430 1
                     Append_Node_To_List
2431 1
                       (RE (RE_Bigendian),
2432 1
                        CTN.Values (Endiannesses));
2433

2434 0
                  when others =>
2435 0
                     Append_Node_To_List
2436 0
                       (RE (RE_Bigendian),
2437 0
                        CTN.Values (Endiannesses));
2438 0
                     Display_Error
2439 0
                       ("Unknown endianess of " & Execution_Platform'Img,
2440
                        Fatal => False);
2441 1
               end case;
2442
            end if;
2443 1
            Q := Next_Node (Q);
2444 1
         end loop;
2445

2446
         N :=
2447 1
           Make_Expression
2448
             (Left_Expr =>
2449 1
                Make_Variable_Declaration
2450
                  (Defining_Identifier =>
2451 1
                     Make_Array_Declaration
2452 1
                       (Defining_Identifier => RE (RE_Deployment_Endiannesses),
2453 1
                        Array_Size          => RE (RE_Nb_Nodes)),
2454 1
                   Used_Type => RE (RE_Uint8_T)),
2455
              Operator   => Op_Equal,
2456
              Right_Expr => Endiannesses);
2457 1
         Append_Node_To_List (N, CTN.Declarations (Current_File));
2458

2459 1
         if not Is_Empty (CTN.Values (Devices_Array)) then
2460
            N :=
2461 1
              Make_Expression
2462
                (Left_Expr =>
2463 1
                   Make_Variable_Declaration
2464
                     (Defining_Identifier =>
2465 1
                        Make_Array_Declaration
2466 1
                          (Defining_Identifier => RE (RE_Devices_Naming),
2467 1
                           Array_Size          => RE (RE_Nb_Devices)),
2468 1
                      Used_Type => Make_Pointer_Type (New_Node (CTN.K_Char))),
2469
                 Operator   => Op_Equal,
2470
                 Right_Expr => Devices_Array);
2471 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2472
         end if;
2473

2474
         --  Here, we define an array that contains reference
2475
         --  to all configuration variables.
2476

2477 1
         if not Is_Empty (CTN.Values (Devices_Confvars)) then
2478
            N :=
2479 1
              Make_Expression
2480
                (Left_Expr =>
2481 1
                   Make_Variable_Declaration
2482
                     (Defining_Identifier =>
2483 1
                        Make_Array_Declaration
2484
                          (Defining_Identifier =>
2485 1
                             RE (RE_Devices_Configuration_Values),
2486 1
                           Array_Size => RE (RE_Nb_Devices)),
2487 1
                      Used_Type => Make_Pointer_Type (RE (RE_Uint32_T))),
2488
                 Operator   => Op_Equal,
2489
                 Right_Expr => Devices_Confvars);
2490 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2491
         end if;
2492

2493 1
         if not Is_Empty (CTN.Values (Protocols_Conf)) then
2494
            N :=
2495 0
              Make_Expression
2496
                (Left_Expr =>
2497 0
                   Make_Variable_Declaration
2498
                     (Defining_Identifier =>
2499 0
                        Make_Array_Declaration
2500
                          (Defining_Identifier =>
2501 0
                             RE (RE_Protocols_Configuration),
2502 0
                           Array_Size => RE (RE_Nb_Protocols)),
2503 0
                      Used_Type => RE (RE_Protocol_Conf_T)),
2504
                 Operator   => Op_Equal,
2505
                 Right_Expr => Protocols_Conf);
2506 0
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2507
         end if;
2508

2509
         --  In the following, we add arrays previously filled arrays
2510
         --  in the header part of the package. These arrays describe
2511
         --  the number of buses accessed by each device and which
2512
         --  bus is under control of which device.
2513

2514 1
         if not Is_Empty (CTN.Values (Devices_Nb_Buses_Array)) then
2515
            N :=
2516 1
              Make_Expression
2517
                (Left_Expr =>
2518 1
                   Make_Variable_Declaration
2519
                     (Defining_Identifier =>
2520 1
                        Make_Array_Declaration
2521
                          (Defining_Identifier =>
2522 1
                             RE (RE_Devices_Nb_Accessed_Buses),
2523 1
                           Array_Size => RE (RE_Nb_Devices)),
2524 1
                      Used_Type => RE (RE_Uint32_T)),
2525
                 Operator   => Op_Equal,
2526
                 Right_Expr => Devices_Nb_Buses_Array);
2527 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2528
         end if;
2529

2530 1
         if not Is_Empty (CTN.Values (Devices_Buses_Array)) then
2531
            N :=
2532 1
              Make_Expression
2533
                (Left_Expr =>
2534 1
                   Make_Variable_Declaration
2535
                     (Defining_Identifier =>
2536 1
                        Make_Array_Declaration
2537
                          (Defining_Identifier =>
2538 1
                             RE (RE_Devices_Accessed_Buses),
2539 1
                           Array_Size => RE (RE_Nb_Devices)),
2540 1
                      Used_Type => Make_Pointer_Type (RE (RE_Bus_Id))),
2541
                 Operator   => Op_Equal,
2542
                 Right_Expr => Devices_Buses_Array);
2543 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2544
         end if;
2545

2546
         --  In the following, we describe the association between
2547
         --  ports and devices. It corresponds to the
2548
         --  __po_hi_port_to_devices array generated in deployment.c.
2549

2550 1
         if not Is_Empty (CTN.Values (Port_To_Devices)) then
2551
            N :=
2552 1
              Make_Expression
2553
                (Left_Expr =>
2554 1
                   Make_Variable_Declaration
2555
                     (Defining_Identifier =>
2556 1
                        Make_Array_Declaration
2557 1
                          (Defining_Identifier => RE (RE_Port_To_Device),
2558 1
                           Array_Size          => RE (RE_Nb_Ports)),
2559 1
                      Used_Type => RE (RE_Device_Id)),
2560
                 Operator   => Op_Equal,
2561
                 Right_Expr => Port_To_Devices);
2562 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2563
         end if;
2564

2565
         --  In the following, we describe the association between
2566
         --  devices and their nodes.
2567

2568 1
         if not Is_Empty (CTN.Values (Devices_To_Nodes)) then
2569
            N :=
2570 1
              Make_Expression
2571
                (Left_Expr =>
2572 1
                   Make_Variable_Declaration
2573
                     (Defining_Identifier =>
2574 1
                        Make_Array_Declaration
2575 1
                          (Defining_Identifier => RE (RE_Devices_To_Nodes),
2576 1
                           Array_Size          => RE (RE_Nb_Devices)),
2577 1
                      Used_Type => RE (RE_Port_T)),
2578
                 Operator   => Op_Equal,
2579
                 Right_Expr => Devices_To_Nodes);
2580 1
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2581
         end if;
2582

2583 1
         Pop_Entity; -- U
2584 1
         Pop_Entity; -- P
2585 1
      end Visit_Process_Instance;
2586

2587
      ---------------------------
2588
      -- Visit_Thread_Instance --
2589
      ---------------------------
2590

2591 1
      procedure Visit_Thread_Instance (E : Node_Id) is
2592 1
         S : constant Node_Id := Parent_Subcomponent (E);
2593 1
         N : Node_Id;
2594
      begin
2595 1
         if Present (Backend_Node (Identifier (S)))
2596 1
           and then Present
2597 1
             (CTN.Local_Port_Node (Backend_Node (Identifier (S))))
2598
         then
2599
            N :=
2600 0
              Make_Expression
2601
                (Left_Expr =>
2602 0
                   Make_Variable_Declaration
2603
                     (Defining_Identifier =>
2604 0
                        Make_Array_Declaration
2605
                          (Defining_Identifier =>
2606 0
                             Make_Defining_Identifier
2607 0
                               (Map_C_Variable_Name
2608
                                  (S,
2609
                                   Port_Variable => True)),
2610
                           Array_Size =>
2611 0
                             Make_Defining_Identifier
2612 0
                               (Map_C_Define_Name (S, Nb_Ports => True))),
2613 0
                      Used_Type => RE (RE_Port_T)),
2614
                 Operator   => Op_Equal,
2615
                 Right_Expr =>
2616 0
                   CTN.Local_Port_Node (Backend_Node (Identifier (S))));
2617 0
            Append_Node_To_List (N, CTN.Declarations (Current_File));
2618
         end if;
2619 1
      end Visit_Thread_Instance;
2620

2621
      ---------------------------
2622
      -- Visit_System_Instance --
2623
      ---------------------------
2624

2625 1
      procedure Visit_System_Instance (E : Node_Id) is
2626 1
         S             : Node_Id;
2627 1
         S2            : Node_Id;
2628 1
         A             : Node_Id;
2629 1
         Lst           : List_Id;
2630 1
         Tmp           : Node_Id;
2631 1
         Port          : Node_Id;
2632 1
         Port2         : Node_Id;
2633 1
         Virtual_Bus   : Node_Id;
2634 1
         Protocol_Name : Name_Id;
2635
      begin
2636 1
         Push_Entity (C_Root);
2637

2638 1
         Protocols_Ports_Array := Make_Array_Values;
2639

2640 1
         if not AAU.Is_Empty (Global_Ports) then
2641 1
            S := AAN.First_Node (Global_Ports);
2642 1
            while Present (S) loop
2643 1
               A := Make_Array_Values;
2644

2645 1
               if S = No_Node then
2646 0
                  Display_Located_Error
2647 0
                    (AAN.Loc (S),
2648
                     "Port is not connected",
2649
                     Fatal => True);
2650
               end if;
2651

2652 1
               Port := AAN.Item (S);
2653

2654 1
               if Port = No_Node then
2655 0
                  Display_Located_Error
2656 0
                    (AAN.Loc (Port),
2657
                     "Port is not connected",
2658
                     Fatal => True);
2659
               end if;
2660

2661 1
               if Is_In (Port) and then not AAU.Is_Empty (Sources (Port)) then
2662 1
                  Port := Item (AAN.First_Node (Sources (Port)));
2663 1
                  Lst  := Sources (Port);
2664
               else
2665 1
                  if AAU.Is_Empty (Destinations (Port)) then
2666 0
                     Display_Located_Error
2667 0
                       (AAN.Loc (Port),
2668
                        "Port destination empty",
2669
                        Fatal => True);
2670
                  end if;
2671

2672 1
                  Port := Item (AAN.First_Node (Destinations (Port)));
2673 1
                  Lst  := Destinations (Port);
2674
               end if;
2675

2676 1
               S2 := AAN.First_Node (Global_Ports);
2677 1
               while Present (S2) loop
2678 1
                  Port2 := AAN.Item (S2);
2679 1
                  if not AAU.Is_Empty (Sources (Port2)) then
2680 1
                     Port2 := Item (AAN.First_Node (Sources (Port2)));
2681
                  else
2682 1
                     if AAU.Is_Empty (Destinations (Port2)) then
2683 0
                        Display_Located_Error
2684 0
                          (AAN.Loc (Port2),
2685
                           "Port destination empty",
2686
                           Fatal => True);
2687
                     end if;
2688

2689 1
                     Port2 := Item (AAN.First_Node (Destinations (Port2)));
2690
                  end if;
2691

2692 1
                  Tmp := First_Node (Lst);
2693

2694 1
                  Protocol_Name := Get_String_Name ("invalid_protocol");
2695

2696 1
                  while Present (Tmp) loop
2697 1
                     if AAN.Item (Tmp) = Port2
2698 1
                       and then Extra_Item (Tmp) /= No_Node
2699
                       and then
2700 1
                         Get_Provided_Virtual_Bus_Class (Extra_Item (Tmp)) /=
2701
                         No_Node
2702
                     then
2703
                        Virtual_Bus :=
2704 0
                          Get_Provided_Virtual_Bus_Class (Extra_Item (Tmp));
2705 0
                        Protocol_Name := Map_C_Enumerator_Name (Virtual_Bus);
2706
                     end if;
2707 1
                     Tmp := Next_Node (Tmp);
2708 1
                  end loop;
2709

2710 1
                  Append_Node_To_List
2711 1
                    (Make_Defining_Identifier (Protocol_Name),
2712 1
                     CTN.Values (A));
2713

2714 1
                  S2 := Next_Node (S2);
2715 1
               end loop;
2716

2717 1
               Append_Node_To_List (A, CTN.Values (Protocols_Ports_Array));
2718 1
               S := Next_Node (S);
2719 1
            end loop;
2720
         end if;
2721

2722
         --  Visit all the subcomponents of the system
2723

2724 1
         if not AAU.Is_Empty (Subcomponents (E)) then
2725 1
            S := First_Node (Subcomponents (E));
2726 1
            while Present (S) loop
2727
               --  Visit the component instance corresponding to the
2728
               --  subcomponent S.
2729

2730 1
               Visit (Corresponding_Instance (S));
2731 1
               S := Next_Node (S);
2732 1
            end loop;
2733
         end if;
2734

2735 1
         Pop_Entity; --  C_Root
2736 1
      end Visit_System_Instance;
2737

2738
   end Source_File;
2739

2740 1
end Ocarina.Backends.PO_HI_C.Deployment;

Read our documentation on viewing source code .

Loading