ocarina-backends-po_hi_c-deployment.adb 59.5 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--  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   --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2008-2010, European Space Agency (ESA).           --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with Namet;
35
with Utils; use Utils;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;

with Ocarina.Backends.Utils;
with Ocarina.Backends.C_Values;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Messages;

50
51
with Ocarina.Instances.Queries;

52
53
54
55
56
57
58
59
60
61
62
63
64
package body Ocarina.Backends.PO_HI_C.Deployment is

   use Namet;
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.C_Values;
   use Ocarina.Backends.C_Tree.Nutils;
   use Ocarina.Backends.C_Common.Mapping;
   use Ocarina.Backends.PO_HI_C.Runtime;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Messages;
65
   use Ocarina.Instances.Queries;
66

67
   package AAN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
68
69
70
   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package CV renames Ocarina.Backends.C_Values;
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
71
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
72

73
74
75
   Entity_Array      : Node_Id;
   Devices_Array     : Node_Id;
   Port_To_Devices   : Node_Id;
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
   function Is_Added (P : Node_Id; E : Node_Id) return Boolean;
   function Added_Internal_Name (P : Node_Id; E : Node_Id) return Name_Id;

   --------------
   -- Is_Added --
   --------------

   function Is_Added (P : Node_Id; E : Node_Id) return Boolean is
      I_Name : constant Name_Id := Added_Internal_Name (P, E);
   begin
      return Get_Name_Table_Byte (I_Name) = 1;
   end Is_Added;

   -------------------------
   -- Added_Internal_Name --
   -------------------------

   function Added_Internal_Name (P : Node_Id; E : Node_Id) return Name_Id is
   begin
      Set_Str_To_Name_Buffer ("%add%enumerator%");
      Add_Nat_To_Name_Buffer (Nat (P));
      Add_Char_To_Name_Buffer ('%');
      Add_Nat_To_Name_Buffer (Nat (E));

      return Name_Find;
   end Added_Internal_Name;

104
105
106
107
108
109
110
111
112
113
114
115
   -----------------
   -- Header_File --
   -----------------

   package body Header_File is

      procedure Visit_Architecture_Instance (E : Node_Id);
      procedure Visit_Component_Instance (E : Node_Id);
      procedure Visit_System_Instance (E : Node_Id);
      procedure Visit_Process_Instance (E : Node_Id);
      procedure Visit_Thread_Instance (E : Node_Id);
      procedure Visit_Subprogram_Instance (E : Node_Id);
116
      procedure Visit_Device_Instance (E : Node_Id);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

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

      procedure Append_Existing
        (S : Node_Id;
         L : List_Id;
         Id : in out Unsigned_Long_Long;
         Is_Entity : Boolean := False);

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

133
134
      Node_Enumerator_List          : List_Id;
      Tasks_Enumerator_List         : List_Id;
135
      Devices_Enumerator_List       : List_Id;
136
137
138
139
140
      Entity_Enumerator_List        : List_Id;
      Global_Port_List              : List_Id;
      Global_Port_Names             : Node_Id;
      Global_Port_Model_Names       : Node_Id;
      Local_Port_List               : List_Id;
141

142
      Nb_Nodes                      : Unsigned_Long_Long;
143

144
      Current_Process_Instance      : Node_Id := No_Node;
145
146
147
148
149
150
151
152
153

      Global_Port_To_Entity     : Node_Id;
      Global_Port_To_Local      : Node_Id;
      Local_Port_Values         : Node_Id;

      Invalid_Local_Port_Added  : Boolean := False;
      Invalid_Global_Port_Added : Boolean := False;
      Invalid_Entity_Added      : Boolean := False;

154
155
156
      Current_Device : Node_Id := No_Node;
      --  Current_Process : Node_Id := No_Node;

157
158
159
160
161
162
163
164
165
166
167
      --  Point to the process currently visited. When we visit a process
      --  we look at all its ports and visit the called subprograms. So,
      --  we need to know if these subprograms are linked with the currrent
      --  process.

      Node_Identifier          : Unsigned_Long_Long := 0;
      Global_Port_Identifier   : Unsigned_Long_Long := 0;
      Local_Port_Identifier    : Unsigned_Long_Long := 0;
      Entity_Identifier        : Unsigned_Long_Long := 0;
      Task_Identifier          : Unsigned_Long_Long := 0;
      Nb_Protected             : Unsigned_Long_Long := 0;
168
      Device_Id                : Unsigned_Long_Long := 0;
169
170
171
172
      Nb_Ports_In_Process      : Unsigned_Long_Long := 0;
      Nb_Ports_Total           : Unsigned_Long_Long := 0;
      Total_Ports_Node         : Node_Id := No_Node;
      Nb_Entities_Node         : Node_Id := No_Node;
173
      Nb_Devices_Node          : Node_Id := No_Node;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

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

      ---------------------
      -- Append_Existing --
      ---------------------

      procedure Append_Existing
        (S         : Node_Id;
         L         : List_Id;
         Id        : in out Unsigned_Long_Long;
         Is_Entity : Boolean := False) is
         N         : Node_Id;
      begin
         if No (Backend_Node (Identifier (S))) or else
            (Present (Backend_Node (Identifier (S))) and then
            No (CTN.Enumerator_Node
                 (Backend_Node (Identifier (S))))) then

            N := Make_Expression
               (Make_Defining_Identifier
199
200
201
202
                  (Map_C_Enumerator_Name
                     (S,
                     Custom_Parent => Current_Device,
                     Entity => Is_Entity)),
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
               Op_Equal,
               Make_Literal
                  (CV.New_Int_Value (Id, 0, 10)));
            Bind_AADL_To_Enumerator (Identifier (S), N);
            Append_Node_To_List (N, L);
            Id := Id + 1;
         end if;
      end Append_Existing;

      ---------------
      -- Set_Added --
      ---------------

      procedure Set_Added (P : Node_Id; E : Node_Id) is
         I_Name : constant Name_Id := Added_Internal_Name (P, E);
      begin
         Set_Name_Table_Byte (I_Name, 1);
      end Set_Added;

      -----------
      -- Visit --
      -----------

      procedure Visit (E : Node_Id) is
      begin
         case Kind (E) is
            when K_Architecture_Instance =>
               Visit_Architecture_Instance (E);

            when K_Component_Instance =>
               Visit_Component_Instance (E);

            when others =>
               null;
         end case;
      end Visit;

      ---------------------------------
      -- Visit_Architecture_Instance --
      ---------------------------------

      procedure Visit_Architecture_Instance (E : Node_Id) is
      begin
         Visit (Root_System (E));
      end Visit_Architecture_Instance;

      ------------------------------
      -- Visit_Component_Instance --
      ------------------------------

      procedure Visit_Component_Instance (E : Node_Id) is
         Category : constant Component_Category
           := Get_Category_Of_Component (E);
      begin
         case Category is
            when CC_System =>
               Visit_System_Instance (E);

            when CC_Process =>
               Visit_Process_Instance (E);

            when CC_Thread =>
               Visit_Thread_Instance (E);

            when CC_Subprogram =>
               Visit_Subprogram_Instance (E);

270
271
272
            when CC_Device =>
               Visit_Device_Instance (E);

273
274
275
276
277
            when others =>
               null;
         end case;
      end Visit_Component_Instance;

278
279
280
281
282
      ---------------------------
      -- Visit_Device_Instance --
      ---------------------------

      procedure Visit_Device_Instance (E : Node_Id) is
283
         N        : Node_Id;
julien.delange's avatar
julien.delange committed
284
         Conf_Str : Name_Id := No_Name;
285
         Tmp_Name : Name_Id;
286
287
288
      begin
         Current_Device := E;

289
290
291
         if Current_Process_Instance /= No_Node and then
            Get_Bound_Processor (E) =
            Get_Bound_Processor (Current_Process_Instance) then
292
293
294
295
296
297
298

            if Backend_Node (Identifier (E)) /= No_Node and then
               CTN.Enumerator_Node
                  (Backend_Node (Identifier (E))) /= No_Node then
               return;
            end if;

299
300
301
302
303
304
305
306
307
308
309
            Bind_AADL_To_Enumerator
               (Identifier (E),
                Make_Defining_Identifier
                  (Map_C_Enumerator_Name (E, Entity => False)));

            N := Make_Expression
              (Make_Defining_Identifier
               (Map_C_Enumerator_Name
                (E, Entity => False)),
               Op_Equal,
               (Make_Literal
310
             (CV.New_Int_Value (Device_Id, 0, 10))));
311
312
313
            Append_Node_To_List
              (N, Devices_Enumerator_List);

314
315
316
317
318
319
320
321
            Device_Id  := Device_Id + 1;

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

            if Get_Location (E) /= No_Name then
               Get_Name_String (Get_Location (E));
julien.delange's avatar
julien.delange committed
322
323
324
325
326
327
328
329
330
               Conf_Str := Name_Find;
               if Get_Port_Number (E) /= Properties.No_Value then
                  Set_Str_To_Name_Buffer (":");
                  Add_Str_To_Name_Buffer
                     (Value_Id'Image (Get_Port_Number (E)));
                  Tmp_Name := Name_Find;
               end if;
               Get_Name_String (Conf_Str);
               Get_Name_String_And_Append (Tmp_Name);
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
               Conf_Str := Name_Find;
            elsif Is_Defined_Property (E, "deployment::channel_address") then
               Set_Str_To_Name_Buffer
                  (Unsigned_Long_Long'Image
                     (Get_Integer_Property
                        (E, "deployment::channel_address")));
               Conf_Str := Name_Find;
               if Is_Defined_Property (E, "deployment::process_id") then
                  Set_Str_To_Name_Buffer
                  (Unsigned_Long_Long'Image
                   (Get_Integer_Property (E, "deployment::process_id")));
                  Tmp_Name := Name_Find;
                  Get_Name_String (Conf_Str);
                  Add_Str_To_Name_Buffer (":");
                  Get_Name_String_And_Append (Tmp_Name);
                  Conf_Str := Name_Find;
               end if;
348
349
350
            elsif Is_Defined_Property (E, "deployment::configuration") and then
               Get_String_Property
                  (E, "deployment::configuration") /= No_Name then
351
352
353
354
               Get_Name_String
                  (Get_String_Property
                     (E, "deployment::configuration"));
               Conf_Str := Name_Find;
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
            end if;

            if Conf_Str /= No_Name then
               Append_Node_To_List
               (Make_Literal
                (CV.New_Pointed_Char_Value (Conf_Str)),
               CTN.Values (Devices_Array));
            else
               Append_Node_To_List
               (Make_Literal
                (CV.New_Pointed_Char_Value
                 (Get_String_Name ("noaddr"))),
               CTN.Values (Devices_Array));
            end if;

370
371
         end if;

372
373
374
         Current_Device := No_Node;
      end Visit_Device_Instance;

375
376
377
378
379
      ----------------------------
      -- Visit_Process_Instance --
      ----------------------------

      procedure Visit_Process_Instance (E : Node_Id) is
380
381
382
383
384
385
         U           : constant Node_Id
               := CTN.Distributed_Application_Unit
                  (CTN.Naming_Node (Backend_Node (Identifier (E))));
         P           : constant Node_Id := CTN.Entity (U);
         S           : constant Node_Id := Parent_Subcomponent (E);
         Root_Sys    : constant Node_Id
386
           := Parent_Component (Parent_Subcomponent (E));
387
388
389
390
391
392
393
394
395
396
         Driver_Name : Name_Id;
         Q           : Node_Id;
         N           : Node_Id;
         C           : Node_Id;
         F           : Node_Id;
         Data        : Node_Id;
         Src         : Node_Id;
         Dst         : Node_Id;
         Parent      : Node_Id;
         The_System  : constant Node_Id := Parent_Component
397
           (Parent_Subcomponent (E));
398
         Device_Implementation : Node_Id;
399
400
401
      begin
         pragma Assert (AAU.Is_System (Root_Sys));

402
403
         Nb_Nodes := 0;

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
         Set_Added (E, E);

         Current_Process_Instance := E;

         Tasks_Enumerator_List      := New_List (CTN.K_Enumeration_Literals);
         Node_Enumerator_List       := New_List (CTN.K_Enumeration_Literals);

         Push_Entity (P);
         Push_Entity (U);
         Set_Deployment_Header;

         Node_Identifier       := 0;
         Task_Identifier       := 0;
         Nb_Protected          := 0;
         Nb_Ports_In_Process   := 0;

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
         N := Make_Define_Statement
         (Defining_Identifier =>
          (RE (RE_My_Node)),
          Value => Make_Defining_Identifier
          (Map_C_Enumerator_Name (Parent_Subcomponent (E))));
         Append_Node_To_List
         (N, CTN.Declarations (Current_File));

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

         if not AAU.Is_Empty (Subcomponents (The_System)) then
            C := First_Node (Subcomponents (The_System));
            while Present (C) loop
               if AAU.Is_Device (Corresponding_Instance (C))
               and then
                 Get_Bound_Processor (Corresponding_Instance (C))
                 = Get_Bound_Processor (E)
               then
                  --  Build the enumerator corresponding to the device
                  --  Note: we reuse the process name XXX

                  Visit_Device_Instance (Corresponding_Instance (C));
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463

                  Current_Device := Corresponding_Instance (C);

                  Device_Implementation :=
                     Get_Implementation (Corresponding_Instance (C));

                  if Device_Implementation /= No_Node then
                     if not AAU.Is_Empty
                        (AAN.Subcomponents (Device_Implementation)) then
                        N := First_Node (Subcomponents
                           (Device_Implementation));
                        while Present (N) loop
                           Visit_Component_Instance
                              (Corresponding_Instance (N));
                           N := Next_Node (N);
                        end loop;
                     end if;
                  end if;

                  Current_Device := No_Node;

464
465
466
467
               end if;
               C := Next_Node (C);
            end loop;
         end if;
468
469
470
471
472
473
474
475
476
477
478
479
480
481

         --  Visit all the subcomponents of the process

         if not AAU.Is_Empty (Subcomponents (E)) then
            C := First_Node (Subcomponents (E));

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

482
                  Nb_Protected := Nb_Protected + 1;
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
               else
                  --  Visit the component instance corresponding to the
                  --  subcomponent S.
                  Visit (Corresponding_Instance (C));
               end if;

               C := Next_Node (C);
            end loop;
         end if;

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

         if not AAU.Is_Empty (Features (E)) then
            F := First_Node (Features (E));

            while Present (F) loop
               --  The sources of F

               if not AAU.Is_Empty (Sources (F)) then
                  Src := First_Node (Sources (F));

                  while Present (Src) loop

                     Parent := Parent_Component (Item (Src));

                     if AAU.Is_Process (Parent)
                       and then Parent /= E
                     then
                        Set_Added (Parent, E);
                        --  Traverse all the subcomponents of Parent

                        if not AAU.Is_Empty (Subcomponents (Parent)) then
                           C := First_Node (Subcomponents (Parent));

                           while Present (C) loop
                              Visit (Corresponding_Instance (C));

                              C := Next_Node (C);
                           end loop;
                        end if;

                        --  Mark P as being Added
527
528
529
530
531
532
533
534
535
536
537
                     elsif AAU.Is_Device (Parent)
                        and then Parent /= E then
                        Driver_Name := Get_Driver_Name (Parent);

                        if Driver_Name /= No_Name then
                           Set_Str_To_Name_Buffer ("__PO_HI_NEED_DRIVER_");
                           Get_Name_String_And_Append (Driver_Name);

                           Driver_Name := Name_Find;
                           Driver_Name := To_Upper (Driver_Name);

538
                           Add_Define_Deployment
539
540
                                    (Make_Defining_Identifier
                                       (Driver_Name,
541
                                       C_Conversion => False));
542
                        end if;
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
                     end if;

                     Src := Next_Node (Src);
                  end loop;
               end if;

               --  The destinations of F

               if not AAU.Is_Empty (Destinations (F)) then
                  Dst := First_Node (Destinations (F));

                  while Present (Dst) loop
                     Parent := Parent_Component (Item (Dst));

                     if AAU.Is_Process (Parent)
                       and then Parent /= E
                     then
                        Set_Added (Parent, E);

                        if not AAU.Is_Empty (Subcomponents (Parent)) then
                           C := First_Node (Subcomponents (Parent));

                           while Present (C) loop
                              Visit (Corresponding_Instance (C));

                              C := Next_Node (C);
                           end loop;
                        end if;
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
                     elsif AAU.Is_Device (Parent)
                        and then Parent /= E then
                        Driver_Name := Get_Driver_Name (Parent);

                        if Driver_Name /= No_Name then
                           Set_Str_To_Name_Buffer ("__PO_HI_NEED_DRIVER_");
                           Get_Name_String_And_Append (Driver_Name);

                           Driver_Name := Name_Find;
                           Driver_Name := To_Upper (Driver_Name);

                           Append_Node_To_List
                              (Make_Define_Statement
                                 (Defining_Identifier =>
                                    (Make_Defining_Identifier
                                       (Driver_Name,
                                       C_Conversion => False)),
                                 Value =>
                                    (Make_Literal
                                       (CV.New_Int_Value (1, 1, 10)))),
                              CTN.Declarations (Current_File));
                        end if;
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
                     end if;

                     Dst := Next_Node (Dst);
                  end loop;
               end if;

               if Is_Data (F) then
                  if Get_Source_Language (Corresponding_Instance (F))
                     = Language_Simulink then
                     Data := Corresponding_Instance (F);

                     if Get_Source_Name (Data) /= No_Name then
                        N := Make_Define_Statement
                           (Defining_Identifier =>
                              (RE (RE_Simulink_Node)),
                           Value => Make_Defining_Identifier
                                    (Get_Source_Name (Data)));
                        Append_Node_To_List
                           (N, CTN.Declarations (Current_File));

                        N := Make_Define_Statement
                           (Defining_Identifier =>
                              (RE (RE_Simulink_Init_Func)),
                           Value => Map_Simulink_Init_Func (Data));
                        Append_Node_To_List
                           (N, CTN.Declarations (Current_File));

                        N := Make_Define_Statement
                           (Defining_Identifier =>
                              (RE (RE_Simulink_Model_Type)),
                           Value => Map_Simulink_Model_Type (Data));
                        Append_Node_To_List
                           (N, CTN.Declarations (Current_File));
                     end if;
                  end if;

               end if;

               F := Next_Node (F);
            end loop;
         end if;

         Q := First_Node (Subcomponents (Root_Sys));

         while Present (Q) loop
            if AAU.Is_Process (Corresponding_Instance (Q)) then
               if Is_Added (Corresponding_Instance (Q), E) then
                  N := Make_Expression
                     (Make_Defining_Identifier
                        (Map_C_Enumerator_Name (Q)),
                     Op_Equal,
                     Make_Literal
                        (CV.New_Int_Value
                           (Node_Identifier, 0, 10)));
                  Append_Node_To_List
                     (N, Node_Enumerator_List);
                  Node_Identifier := Node_Identifier + 1;
650
                  Nb_Nodes := Nb_Nodes + 1;
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
               else
                  N := Make_Expression
                     (Make_Defining_Identifier
                        (Map_C_Enumerator_Name (Q)),
                     Op_Equal,
                     RE (RE_Unused_Node));
                  Append_Node_To_List
                     (N, Node_Enumerator_List);
               end if;
            end if;

            Q := Next_Node (Q);
         end loop;

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

         N := Message_Comment ("For each node in the distributed"
                               & " application add an enumerator");
         Append_Node_To_List (N, CTN.Declarations (Current_File));

         N := Make_Full_Type_Declaration
           (Defining_Identifier => RE (RE_Node_T),
            Type_Definition     => Make_Enum_Aggregate
              (Node_Enumerator_List));
         Append_Node_To_List (N, CTN.Declarations (Current_File));

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

         if not Is_Empty (Entity_Enumerator_List) then
            N := Message_Comment ("For each thread in the distributed"
                                  & " application nodes, add an"
                                  & " enumerator");
            Append_Node_To_List (N, CTN.Declarations (Current_File));

            if not Invalid_Entity_Added then
               Set_Str_To_Name_Buffer ("invalid_entity");
               N := Make_Expression
                 (Make_Defining_Identifier
                  (Name_Find),
                  Op_Equal,
                  (Make_Literal
                (CV.New_Int_Value (1, -1, 10))));
               Append_Node_To_List
                  (N, Entity_Enumerator_List);
               Invalid_Entity_Added := True;
            end if;

            N := Make_Full_Type_Declaration
              (Defining_Identifier => RE (RE_Entity_T),
               Type_Definition     => Make_Enum_Aggregate
                 (Entity_Enumerator_List));
            Append_Node_To_List (N, CTN.Declarations (Current_File));
         end if;

         Set_Str_To_Name_Buffer ("invalid_task_id");
         N := Make_Expression
           (Make_Defining_Identifier
            (Name_Find),
            Op_Equal,
            (Make_Literal
          (CV.New_Int_Value (1, -1, 10))));
         Append_Node_To_List
            (N, Tasks_Enumerator_List);

         N := Make_Full_Type_Declaration
           (Defining_Identifier => RE (RE_Task_Id),
            Type_Definition     => Make_Enum_Aggregate
              (Tasks_Enumerator_List));
         Append_Node_To_List (N, CTN.Declarations (Current_File));

727
728
729
730
731
732
         N := Make_Full_Type_Declaration
           (Defining_Identifier => RE (RE_Device_Id),
            Type_Definition     => Make_Enum_Aggregate
              (Devices_Enumerator_List));
         Append_Node_To_List (N, CTN.Declarations (Current_File));

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Tasks),
             Value => Make_Literal (New_Int_Value (Task_Identifier, 1, 10)));
         Append_Node_To_List (N, CTN.Declarations (Current_File));

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

         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Protected),
            Value => Make_Literal
              (New_Int_Value
               (Nb_Protected, 1, 10)));
         Append_Node_To_List (N, CTN.Declarations (Current_File));

         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Nodes),
750
            Value => Make_Literal (New_Int_Value (Nb_Nodes, 1, 10)));
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
         Append_Node_To_List
           (N, CTN.Declarations (Current_File));

         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Entities),
            Value => Nb_Entities_Node);
         Append_Node_To_List (N, CTN.Declarations (Current_File));

         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Ports),
            Value => Total_Ports_Node);
         Append_Node_To_List (N, CTN.Declarations (Current_File));

         if not Is_Empty (Global_Port_List) then
            if not Invalid_Global_Port_Added then
               Set_Str_To_Name_Buffer ("invalid_port_t");
               N := Make_Expression
                 (Make_Defining_Identifier
                  (Name_Find),
                  Op_Equal,
                  (Make_Literal
                (CV.New_Int_Value (1, -1, 10))));
               Append_Node_To_List
                  (N, Global_Port_List);

               Invalid_Global_Port_Added := True;
            end if;

            N := Make_Full_Type_Declaration
              (Defining_Identifier => RE (RE_Port_T),
               Type_Definition     => Make_Enum_Aggregate
                 (Global_Port_List));
            Append_Node_To_List (N, CTN.Declarations (Current_File));
         end if;

         if not Is_Empty (CTN.Values (Global_Port_To_Local)) then
            Bind_AADL_To_Local_Port (Identifier (S), Global_Port_To_Local);
         end if;

         if not Is_Empty (CTN.Values (Global_Port_To_Entity)) then
            Bind_AADL_To_Global_Port (Identifier (S), Global_Port_To_Entity);
         end if;

794
795
796
797
798
799
800
801
802
         if not Is_Empty (CTN.Values (Global_Port_Names)) then
            Bind_AADL_To_Global_Names (Identifier (S), Global_Port_Names);
         end if;

         if not Is_Empty (CTN.Values (Global_Port_Model_Names)) then
            Bind_AADL_To_Global_Model_Names
               (Identifier (S), Global_Port_Model_Names);
         end if;

803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
         if not Is_Empty (Local_Port_List) then
            if not Invalid_Local_Port_Added then
               Set_Str_To_Name_Buffer ("invalid_local_port_t");
               N := Make_Expression
                 (Make_Defining_Identifier
                  (Name_Find),
                  Op_Equal,
                  (Make_Literal
                (CV.New_Int_Value (1, -1, 10))));
               Append_Node_To_List
                  (N, Local_Port_List);

               Invalid_Local_Port_Added := True;
            end if;

            N := Make_Full_Type_Declaration
               (Defining_Identifier =>
                  RE (RE_Local_Port_T),
               Type_Definition     => Make_Enum_Aggregate
                  (Local_Port_List));
            Append_Node_To_List (N, CTN.Declarations (Current_File));
         end if;

826
827
         N := Make_Define_Statement
           (Defining_Identifier => RE (RE_Nb_Devices),
828
            Value => Nb_Devices_Node);
829
830
831
         Append_Node_To_List
           (N, CTN.Declarations (Current_File));

832
833
         Current_Process_Instance := No_Node;

834
835
836
837
838
839
840
841
842
843
844
845
846
847
         Pop_Entity; -- U
         Pop_Entity; -- P
      end Visit_Process_Instance;

      ---------------------------
      -- Visit_System_Instance --
      ---------------------------

      procedure Visit_System_Instance (E : Node_Id) is
         S : Node_Id;
         N : Node_Id;
      begin
         Push_Entity (C_Root);

848
849
850
851
         Devices_Array              := Make_Array_Values;
         Port_To_Devices            := Make_Array_Values;

         Devices_Enumerator_List    := New_List (CTN.K_Enumeration_Literals);
852
         Global_Port_List           := New_List (CTN.K_Enumeration_Literals);
853
854
         Global_Port_Names          := Make_Array_Values;
         Global_Port_Model_Names    := Make_Array_Values;
855
856
857
858
859
860
861
862
863
         Global_Port_To_Entity      := Make_Array_Values;
         Global_Port_To_Local       := Make_Array_Values;
         Entity_Enumerator_List     := New_List (CTN.K_Enumeration_Literals);
         Local_Port_Values          := Make_Array_Values;
         Local_Port_List            := New_List (CTN.K_Enumeration_Literals);
         Total_Ports_Node           := Make_Literal
                                       (New_Int_Value (0, 1, 10));
         Nb_Entities_Node           := Make_Literal
                                       (New_Int_Value (0, 1, 10));
864
865
         Nb_Devices_Node            := Make_Literal
                                       (New_Int_Value (0, 1, 10));
866
867
         Entity_Array               := Make_Array_Values;

868
869
870
871
872
873
874
875
876
877
878
879
         Device_Id                  := 0;

         Set_Str_To_Name_Buffer ("invalid_device_id");
         N := Make_Expression
           (Make_Defining_Identifier
            (Name_Find),
            Op_Equal,
            (Make_Literal
          (CV.New_Int_Value (1, -1, 10))));
         Append_Node_To_List
            (N, Devices_Enumerator_List);

880
881
882
883
884
885
886
887
         --  Visit all the subcomponents of the system

         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

888
889
890
891
892
893
               if Get_Current_Backend_Kind = PolyORB_HI_C and then
                  not AAU.Is_Device (Corresponding_Instance (S)) then
                  Visit (Corresponding_Instance (S));
               else
                  Visit (Corresponding_Instance (S));
               end if;
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
               S := Next_Node (S);
            end loop;
         end if;

         Set_Str_To_Name_Buffer ("constant_out_identifier");
         N := Make_Expression
           (Make_Defining_Identifier
            (Name_Find),
            Op_Equal,
            (Make_Literal
          (CV.New_Int_Value (Global_Port_Identifier + 1, 1, 10))));
         Append_Node_To_List
            (N, Global_Port_List);

         CTN.Set_Value (Total_Ports_Node, New_Int_Value
                                    (Nb_Ports_Total, 1, 10));

         CTN.Set_Value (Nb_Entities_Node, New_Int_Value
                                    (Entity_Identifier, 1, 10));

         Pop_Entity; --  C_Root
      end Visit_System_Instance;

      ---------------------------
      -- Visit_Thread_Instance --
      ---------------------------

      procedure Visit_Thread_Instance (E : Node_Id) is
         N                 : Node_Id;
         F                 : Node_Id;
         P                 : Node_Id;
         S                 : constant Node_Id := Parent_Subcomponent (E);
         Call_Seq          : Node_Id;
         Spg_Call          : Node_Id;
928
929
         Used_Bus          : Node_Id;
         Used_Device       : Node_Id;
930
931
932
933
934
935
936
937
938
939
940
941
942
943
      begin

         Local_Port_Identifier := 0;
         --  Build the enumerator corresponding to the thread. The
         --  enumerator name is mapped from the the thread name and
         --  its containing process name.

         Append_Existing
           (S, Entity_Enumerator_List, Entity_Identifier, Is_Entity => True);

         if not (Present (Backend_Node (Identifier (S)))) or else
            (Present (Backend_Node (Identifier (S))) and then
             No (CTN.Naming_Node (Backend_Node (Identifier (S)))))
         then
944
945
946
947
948
949
950
951
952
            if Current_Device /= No_Node then
               N := Make_Defining_Identifier
                  (Map_C_Enumerator_Name
                     (Parent_Subcomponent (Current_Process_Instance)));
            else
               N := Make_Defining_Identifier
                  (Map_C_Enumerator_Name (Parent_Subcomponent
                        (Parent_Component (Parent_Subcomponent (E)))));
            end if;
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
            Bind_AADL_To_Naming (Identifier (S), N);
            Append_Node_To_List (N, CTN.Values (Entity_Array));
         end if;

         if Parent_Component (Parent_Subcomponent (E))
           = Current_Process_Instance then
            N := Make_Expression
              (Make_Defining_Identifier
               (Map_C_Enumerator_Name
                (S, Entity => False)),
               Op_Equal,
               (Make_Literal
             (CV.New_Int_Value (Task_Identifier, 0, 10))));
            Append_Node_To_List
              (N, Tasks_Enumerator_List);
            Task_Identifier := Task_Identifier + 1;
         end if;

971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
         if Current_Device /= No_Node and then
            Current_Process_Instance /= No_Node and then
            Get_Bound_Processor (Current_Device) =
            Get_Bound_Processor (Current_Process_Instance) then
            N := Make_Expression
              (Make_Defining_Identifier
               (Map_C_Enumerator_Name
                (S, Custom_Parent => Current_Device, Entity => False)),
               Op_Equal,
               (Make_Literal
             (CV.New_Int_Value (Task_Identifier, 0, 10))));
            Append_Node_To_List
              (N, Tasks_Enumerator_List);
            Task_Identifier := Task_Identifier + 1;
         end if;

987
988
         --  Get the Process parent of the thread

989
990
991
992
993
         if Current_Device /= No_Node then
            P := Current_Device;
         else
            P := Parent_Component (S);
         end if;
994
995
996
997
998
999
1000

         N := Make_Defining_Identifier
           (Map_C_Enumerator_Name
            (Parent_Subcomponent
             (P)));

         if Has_Ports (E) then
For faster browsing, not all history is shown. View entire blame