ocarina-backends-c_common-mapping.adb 142 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 . C _ C O M M O N . M A P P I N G     --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
jhugues's avatar
jhugues committed
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2012 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- 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.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
199
200
201
202
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
--                                                                          --
------------------------------------------------------------------------------

with Namet;
with Utils; use Utils;

with Ocarina.Backends.Messages;
with Ocarina.Backends.Utils;
with Ocarina.Backends.C_Values;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.POK_C.Runtime;
with Ocarina.Backends.POK_C;

with Ocarina.Instances.Queries;

with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.ME_AADL.AADL_Tree.Entities.Properties;
with Ocarina.ME_AADL.AADL_Tree.Entities;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;

package body Ocarina.Backends.C_Common.Mapping is

   use Namet;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.C_Values;
   use Ocarina.Backends.C_Tree.Nodes;
   use Ocarina.Backends.C_Tree.Nutils;
   use Ocarina.Backends.PO_HI_C.Runtime;
   use Ocarina.Backends.POK_C.Runtime;
   use Ocarina.Backends.POK_C;
   use Ocarina.Instances.Queries;

   use Ocarina.ME_AADL.AADL_Tree.Entities.Properties;
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;

   package AAN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package ATU renames Ocarina.ME_AADL.AADL_Tree.Nutils;
--   package ATE renames Ocarina.ME_AADL.AADL_Tree.Entities;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
   package PKR renames Ocarina.Backends.POK_C.Runtime;
   package PHR renames Ocarina.Backends.PO_HI_C.Runtime;

   ---------------------------
   -- Call_Remote_Functions --
   ---------------------------

   procedure Call_Remote_Functions
     (Caller_Thread    : Node_Id;
      Spg_Call         : Node_Id;
      Declarations     : List_Id;
      Statements       : List_Id)
   is
      procedure Check_Connection_Consistency (F : Node_Id);
      --  Verifies that the feature F is connected to at least one
      --  destination.

      procedure Call_Remote_Functions
        (Root_F         : Node_Id;
         Intermediate_F : Node_Id);
      --  This recursive procedure will unwind recursively all the
      --  destinations of the Root_F feature until it finds a
      --  subprogram. If the remote subprogram is found, add a call
      --  to the subprogram call table (if necessary) and add a
      --  parameter association corresponding to Root_F the the
      --  call to this subprogram. At the top level call to
      --  Call_Remote_Subprograms, Intermediate_F = Root_F.

      procedure Update_Remote_Calls
        (Remote_Spg  : Node_Id;
         Param_Value : Node_Id);
      --  If the call to Spg has not been added yet, create
      --  it. Adds a parameter association Param_Name =>
      --  Param_Value to the call profile.

      Call_List : constant List_Id := New_List (CTN.K_Statement_List);
      --  List that contains the calls to all remote subprogram
      --  connected to Spg.

      ----------------------------------
      -- Check_Connection_Consistency --
      ----------------------------------

      procedure Check_Connection_Consistency (F : Node_Id) is
      begin
         if AINU.Length (Destinations (F)) = 0 then
            Display_Located_Error
              (AIN.Loc (F),
               "This feature does not have any destinations",
               Fatal => True);
         end if;
      end Check_Connection_Consistency;

      ---------------------------
      -- Call_Remote_Functions --
      ---------------------------

      procedure Call_Remote_Functions
        (Root_F         : Node_Id;
         Intermediate_F : Node_Id)
      is
         Destination_F : Node_Id;
         C             : Node_Id;
      begin
         --  Root F has to be a parameter instance

         pragma Assert (Kind (Root_F) = K_Parameter_Instance);

         --  The container of the subprogram containing F has to be
         --  necessarily a Thread.

         pragma Assert (AINU.Is_Thread
                        (Parent_Component
                           (Parent_Sequence
                              (Parent_Subcomponent
                                 (Parent_Component
                                    (Root_F))))));

         --  Check the feature consistency

         Check_Connection_Consistency (Intermediate_F);

         Destination_F := AIN.First_Node (Destinations (Intermediate_F));

         while Present (Destination_F) loop
            C := Parent_Component (Item (Destination_F));

            --  If C is also the parent component of Root_F (which
            --  is necessarily a subprogram). Then display an error
            --  and exit.

            if C = Parent_Component (Root_F) then
               Display_Located_Error
                 (AIN.Loc (C),
                  "This subprogram is involved in a connection cycle",
                  Fatal => True);
            end if;

            if AINU.Is_Subprogram (C) then
               --  If C is a subprogram, then append it to the call
               --  list (if necessary, and add a parameter
               --  association corresponding to Root_F and
               --  Destination_F.

               Update_Remote_Calls (C, Root_F);
            else
               --  Otherwise, keep unwinding the destinations

               Call_Remote_Functions (Root_F, Item (Destination_F));
            end if;

            Destination_F := AIN.Next_Node (Destination_F);
         end loop;
      end Call_Remote_Functions;

      -------------------------
      -- Update_Remote_Calls --
      -------------------------

      procedure Update_Remote_Calls
        (Remote_Spg  : Node_Id;
         Param_Value : Node_Id)
      is
         R_Name  : Name_Id;
         N       : Node_Id;
         Profile : List_Id;
      begin
         --  Check whether a call corresponding to Spg has already
         --  been added to Call_List (we use name table infos
         --  instead of looping on Call list, which is a very fast
         --  way.

         Set_Nat_To_Name_Buffer (Nat (Remote_Spg));
         Add_Str_To_Name_Buffer ("%RemoteCall%");
         Add_Nat_To_Name_Buffer (Nat (Spg_Call));
         R_Name := Name_Find;

         if Get_Name_Table_Info (R_Name) = 0 then
            N := Message_Comment ("Call stub ");
            Append_Node_To_List (N, Statements);

            Profile := New_List (CTN.K_List_Id);

            --  Add the FROM argument (first argument)
            N := Make_Defining_Identifier
              (Map_C_Enumerator_Name
                 (Parent_Subcomponent
                    (Caller_Thread),
                  Entity => True));
            Append_Node_To_List (N, Profile);

            --  Add the TO argument (second argument)

            N := Make_Defining_Identifier
              (Map_C_Enumerator_Name
                 (Parent_Subcomponent
                    (Get_Container_Thread
                       (Remote_Spg)),
                  Entity => True));

            Append_Node_To_List (N, Profile);

            --  Add the message argument (third argument)
            N := Make_Variable_Address
              (Make_Defining_Identifier (PN (P_Message)));
            Append_Node_To_List (N, Profile);

            --  Create the subprogram call

            N := Make_Call_Profile
              (Map_Stub_Identifier
                 (Remote_Spg),
               Profile);
            Append_Node_To_List (N, Statements);

            --  Mark the call as being added. The info we associate
            --  to the name is the value of the profile list to be
            --  able to get it to add parameter associations.

            Set_Name_Table_Info (R_Name, Nat (Profile));
         else
            Profile := List_Id (Get_Name_Table_Info (R_Name));
         end if;

         N := Make_Defining_Identifier
           (Map_C_Full_Parameter_Name
              (Spg_Call, Param_Value));
         Append_Node_To_List (N, Profile);

      end Update_Remote_Calls;

      Spg              : constant Node_Id := Corresponding_Instance (Spg_Call);
      F                : Node_Id;
   begin
      pragma Assert (AINU.Is_Thread (Caller_Thread));

      --  The lists have to be created

      if Declarations = No_List or else Statements = No_List then
         raise Program_Error with "Lists have to be created before any "
           & "call to Get_Remote_Subprogram";
      end if;

      if not AINU.Is_Empty (Features (Spg)) then
         F := AIN.First_Node (Features (Spg));

         while Present (F) loop
            if Kind (F) = K_Parameter_Instance and then Is_Out (F) then
               --  Call all the remote subprograms connected the
               --  feature F.

               Call_Remote_Functions (F, F);
            end if;

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

      --  Append the calls to the Statements list

      if not CTU.Is_Empty (Call_List) then
         Append_Node_To_List (CTN.First_Node (Call_List), Statements);
      end if;
   end Call_Remote_Functions;

   ---------------------------------
   -- Map_Distributed_Application --
   ---------------------------------

   function Map_Distributed_Application (E : Node_Id) return Node_Id is
      D : constant Node_Id := New_Node (CTN.K_HI_Distributed_Application);
   begin
      pragma Assert (AINU.Is_System (E) or else AINU.Is_Processor (E));

      --  Update the global variable to be able to fetch the root of
      --  the distributed application and generate the source files.

      if Get_Current_Backend_Kind = PolyORB_Kernel_C then
         CTN.Set_Name (D, To_C_Name
                         (AIN.Name
322
323
                            (AIN.Identifier (Parent_Subcomponent (E))),
                         Keyword_Check => False));
324
      else
hugues.jerome's avatar
hugues.jerome committed
325
         CTN.Set_Name (D, To_C_Name (AIN.Name (AIN.Identifier (E))));
326
      end if;
hugues.jerome's avatar
hugues.jerome committed
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
      CTN.Set_Units (D, New_List (CTN.K_List_Id));
      CTN.Set_HI_Nodes (D, New_List (CTN.K_List_Id));

      return D;
   end Map_Distributed_Application;

   -----------------
   -- Map_HI_Node --
   -----------------

   function Map_HI_Node (E : Node_Id; Kernel : Boolean := False)
                        return Node_Id is
      N : constant Node_Id := New_Node (CTN.K_HI_Node);
   begin
      pragma Assert
         (AINU.Is_Process_Or_Device (E)
         or else AINU.Is_System (E)
         or else AINU.Is_Processor (E));

      --  The name of the node is not the name of the process
      --  component instance, but the name of the process subcomponent
      --  corresponding to this instance.

      if Kernel then
         Set_Str_To_Name_Buffer ("kernel");
         CTN.Set_Name (N, Name_Find);
      else
         CTN.Set_Name (N, To_C_Name
                         (AIN.Name
                            (AIN.Identifier
                               (AIN.Parent_Subcomponent
359
360
                                  (E))),
                         Keyword_Check => False));
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
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
571
572
573
574
575
576
577
578
579
580
      end if;

      Set_Units (N, New_List (K_List_Id));

      --  Append the partition N to the node list of the PolyORB-HI
      --  distributed application. We are sure that the top of the
      --  entity stack contains the C distributed application node.

      Append_Node_To_List (N, HI_Nodes (Current_Entity));
      Set_Distributed_Application (N, Current_Entity);

      return N;
   end Map_HI_Node;

   -----------------
   -- Map_HI_Unit --
   -----------------

   function Map_HI_Unit (E : Node_Id) return Node_Id is
      U        : Node_Id;
      S        : List_Id;
      H        : List_Id;
      N        : Node_Id;
      P        : Node_Id;
   begin
      pragma Assert (AINU.Is_System (E)
                     or else AINU.Is_Process_Or_Device (E)
                     or else AINU.Is_Processor (E));

      U := New_Node (CTN.K_HI_Unit, AIN.Identifier (E));
      S := New_List (K_Sources);
      H := New_List (K_Headers);

      --  Packages that are common to all nodes

      if AINU.Is_Process_Or_Device (E) then
         Set_Str_To_Name_Buffer ("subprograms");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Subprograms_Source (U, P);
         Append_Node_To_List (P, S);

         if Get_Current_Backend_Kind = PolyORB_Kernel_C then
            Set_Str_To_Name_Buffer ("gtypes");
         elsif Get_Current_Backend_Kind = PolyORB_HI_C then
            Set_Str_To_Name_Buffer ("types");
         end if;
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Types_Source (U, P);
         Append_Node_To_List (P, S);

         Set_Str_To_Name_Buffer ("marshallers");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Marshallers_Source (U, P);
         Append_Node_To_List (P, S);

         Set_Str_To_Name_Buffer ("request");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Request_Source (U, P);
         Append_Node_To_List (P, S);

         Set_Str_To_Name_Buffer ("activity");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Activity_Source (U, P);
         Append_Node_To_List (P, S);
         Bind_AADL_To_Activity (Identifier (E), P);

         Set_Str_To_Name_Buffer ("activity");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Header_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Activity_Header (U, P);
         Append_Node_To_List (P, H);

         Set_Str_To_Name_Buffer ("main");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Source_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Main_Source (U, P);
         Append_Node_To_List (P, S);
         Bind_AADL_To_Main (Identifier (E), P);

         Set_Str_To_Name_Buffer ("request");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Header_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Request_Header (U, P);
         Append_Node_To_List (P, H);

         if Get_Current_Backend_Kind = PolyORB_Kernel_C then
            Set_Str_To_Name_Buffer ("gtypes");
         elsif Get_Current_Backend_Kind = PolyORB_HI_C then
            Set_Str_To_Name_Buffer ("types");
         end if;
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Header_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Types_Header (U, P);
         Append_Node_To_List (P, H);

         Set_Str_To_Name_Buffer ("marshallers");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Header_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Marshallers_Header (U, P);
         Append_Node_To_List (P, H);

         Set_Str_To_Name_Buffer ("subprograms");
         N := Make_Defining_Identifier (Name_Find);
         P := Make_Header_File (N);
         Set_Distributed_Application_Unit (P, U);
         CTN.Set_Subprograms_Header (U, P);
         Append_Node_To_List (P, H);

      end if;

      Set_Str_To_Name_Buffer ("deployment");
      N := Make_Defining_Identifier (Name_Find);
      P := Make_Source_File (N);
      Set_Distributed_Application_Unit (P, U);
      CTN.Set_Deployment_Source (U, P);
      Append_Node_To_List (P, S);

      Set_Str_To_Name_Buffer ("deployment");
      N := Make_Defining_Identifier (Name_Find);
      P := Make_Header_File (N);
      Set_Distributed_Application_Unit (P, U);
      CTN.Set_Deployment_Header (U, P);
      Append_Node_To_List (P, H);

      Set_Str_To_Name_Buffer ("naming");
      N := Make_Defining_Identifier (Name_Find);
      P := Make_Header_File (N);
      Set_Distributed_Application_Unit (P, U);
      CTN.Set_Naming_Header (U, P);
      Append_Node_To_List (P, H);

      Set_Str_To_Name_Buffer ("naming");
      N := Make_Defining_Identifier (Name_Find);
      P := Make_Source_File (N);
      Set_Distributed_Application_Unit (P, U);
      CTN.Set_Naming_Source (U, P);
      Append_Node_To_List (P, S);
      Bind_AADL_To_Naming (Identifier (E), P);

      --  Append the Unit to the units list of the current C
      --  partition.

      CTN.Set_Sources (U, S);
      CTN.Set_Headers (U, H);

      Append_Node_To_List (U, Units (Current_Entity));
      CTN.Set_Entity (U, Current_Entity);

      return U;
   end Map_HI_Unit;

   -------------------------------------
   -- Bind_AADL_To_Feature_Subprogram --
   -------------------------------------

   procedure Bind_AADL_To_Feature_Subprogram (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Feature_Subprogram_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Feature_Subprogram;

   -----------------------------
   -- Bind_AADL_To_Deployment --
   -----------------------------

   procedure Bind_AADL_To_Deployment (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Deployment_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Deployment;

   ------------------------------
   -- Bind_AADL_To_Global_Port --
   ------------------------------

   procedure Bind_AADL_To_Global_Port (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Global_Port_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Global_Port;

581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
   -------------------------------
   -- Bind_AADL_To_Global_Names --
   -------------------------------

   procedure Bind_AADL_To_Global_Names (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Global_Names_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Global_Names;

   -------------------------------------
   -- Bind_AADL_To_Global_Model_Names --
   -------------------------------------

   procedure Bind_AADL_To_Global_Model_Names (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Global_Model_Names_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Global_Model_Names;

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
650
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
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
   -----------------------------
   -- Bind_AADL_To_Local_Port --
   -----------------------------

   procedure Bind_AADL_To_Local_Port (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Local_Port_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Local_Port;

   --------------------------
   -- Bind_AADL_To_Request --
   --------------------------

   procedure Bind_AADL_To_Request (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Request_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Request;

   ---------------------------
   -- Bind_AADL_To_Entities --
   ---------------------------

   procedure Bind_AADL_To_Entities (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Entities_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Entities;

   --------------------------
   -- Bind_AADL_To_Servers --
   --------------------------

   procedure Bind_AADL_To_Servers (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Servers_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Servers;

   -----------------------------
   -- Bind_AADL_To_Subprogram --
   -----------------------------

   procedure Bind_AADL_To_Subprogram (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Subprogram_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Subprogram;

   ---------------------------
   -- Bind_AADL_To_Activity --
   ---------------------------

   procedure Bind_AADL_To_Activity (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Activity_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Activity;

   -------------------------
   -- Bind_AADL_To_Naming --
   -------------------------

   procedure Bind_AADL_To_Naming (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Naming_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Naming;

   ----------------------
   -- Bind_AADL_To_Job --
   ----------------------

   procedure Bind_AADL_To_Job (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Job_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Job;

   -----------------------------
   -- Bind_AADL_To_Enumerator --
   -----------------------------

   procedure Bind_AADL_To_Enumerator (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Enumerator_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Enumerator;

   ----------------------------------
   -- Bind_AADL_To_Type_Definition --
   ----------------------------------

   procedure Bind_AADL_To_Type_Definition (G : Node_Id; A : Node_Id) is
784
785
      pragma Assert (Present (A));

786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Type_Definition_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Type_Definition;

   ----------------------------------
   -- Bind_AADL_To_Process_Request --
   ----------------------------------

   procedure Bind_AADL_To_Process_Request (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Process_Request_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Process_Request;

   -------------------------------
   -- Bind_AADL_To_Request_Type --
   -------------------------------

   procedure Bind_AADL_To_Request_Type (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Request_Type_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Request_Type;

   -----------------------
   -- Bind_AADL_To_Main --
   -----------------------

   procedure Bind_AADL_To_Main (G : Node_Id; A : Node_Id) is
      N : Node_Id;
   begin
      N := AIN.Backend_Node (G);

      if No (N) then
         N := New_Node (CTN.K_HI_Tree_Bindings);
         AIN.Set_Backend_Node (G, N);
      end if;

      CTN.Set_Main_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Main;

   -----------------------------
   -- Map_Task_Job_Identifier --
   -----------------------------

jdelange's avatar
jdelange committed
857
858
859
   function Map_Task_Job_Identifier
      (E : Node_Id; Prefix_Component : Node_Id := No_Node)
      return Node_Id is
860
      Name : Name_Id;
jdelange's avatar
jdelange committed
861
862
      C1   : Name_Id := No_Name;
      C2   : Name_Id := No_Name;
863
   begin
jdelange's avatar
jdelange committed
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
      if Prefix_Component /= No_Node then
         Get_Name_String
            (To_C_Name
               (AIN.Display_Name
                  (Identifier (Prefix_Component))));
         C1 := Name_Find;
      end if;
      Get_Name_String
         (To_C_Name (AIN.Display_Name (Identifier (E))));
      C2 := Name_Find;

      Set_Str_To_Name_Buffer ("");

      if C1 /= No_Name then
         Get_Name_String (C1);
         Add_Str_To_Name_Buffer ("_");
      end if;

      Get_Name_String_And_Append (C2);
883
884
885
886
887
888
889
890
891
892
893
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
928
      Add_Str_To_Name_Buffer ("_job");
      Name := Name_Find;
      Name := To_Lower (Name);
      return Make_Defining_Identifier (Name);
   end Map_Task_Job_Identifier;

   ---------------------------------
   -- Map_Task_Deliver_Identifier --
   ---------------------------------

   function Map_Task_Deliver_Identifier (E : Node_Id) return Node_Id is
      Name : Name_Id;
   begin
      Get_Name_String (To_C_Name (AIN.Display_Name (Identifier (E))));
      Add_Str_To_Name_Buffer ("_deliver");
      Name := Name_Find;
      Name := To_Lower (Name);
      return Make_Defining_Identifier (Name);
   end Map_Task_Deliver_Identifier;

   ---------------------
   -- Map_C_Enum_Name --
   ---------------------

   function Map_C_Enum_Name (E : Node_Id; Enumerator : Name_Id) return Name_Id
   is
      Enum_Name : Name_Id;
   begin
      --  Note: we need to adapt the name of the enumerator to avoid
      --  collision of enumerators, as C does not allow twice the same
      --  enumerators in two different enum types.

      Enum_Name := To_C_Name
        (Display_Name (Identifier (E)));

      Get_Name_String_And_Append (Enum_Name);
      Add_Str_To_Name_Buffer ("_");
      Get_Name_String_And_Append (Enumerator);
      return Name_Find;
   end Map_C_Enum_Name;

   ---------------------------
   -- Map_C_Enumerator_Name --
   ---------------------------

   function Map_C_Enumerator_Name
929
930
931
932
933
934
     (E              : Node_Id;
      Custom_Parent  : Node_Id := No_Node;
      Entity         : Boolean := False;
      Server         : Boolean := False;
      Port_Type      : Boolean := False;
      Local_Port     : Boolean := False)
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
     return Name_Id
   is
      C_Name_1 : Name_Id;
      C_Name_2 : Name_Id;
   begin
      if Kind (E) = K_Port_Spec_Instance then
         C_Name_1 := CTU.To_C_Name
           (Display_Name (Identifier (E)));

         Get_Name_String
           (CTU.To_C_Name
              (Display_Name
                 (Identifier
                    (Parent_Subcomponent
                       (Parent_Component (E))))));
         if Local_Port then
            Add_Str_To_Name_Buffer ("_local_");
            Get_Name_String_And_Append (C_Name_1);
         else
            Add_Str_To_Name_Buffer ("_global_");
            Get_Name_String_And_Append (C_Name_1);
         end if;
957
958
959
960
961
      elsif AINU.Is_Bus (E) then
         Set_Str_To_Name_Buffer ("bus_");
         Get_Name_String_And_Append
            (AIN.Name
               (AIN.Identifier (Parent_Subcomponent (E))));
962
963
964
965
966
967
968
969
970
971
972
973
      elsif AINU.Is_Virtual_Bus (E) then
         Set_Str_To_Name_Buffer ("virtual_bus_");
         if Parent_Subcomponent (E) /= No_Node then
            Get_Name_String_And_Append
               (AIN.Name
                  (AIN.Identifier
                     (Parent_Subcomponent (E))));
         else
            Get_Name_String_And_Append
               (AIN.Name
                  (AIN.Identifier (E)));
         end if;
974
      elsif AINU.Is_Subprogram (E) then
975
976
977
978
979
         --  For subprograms and processes, the enemerator name is
         --  mapped from the entity name.

         Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
         Add_Str_To_Name_Buffer ("_k");
980
981
      elsif Get_Current_Backend_Kind = PolyORB_HI_C and then
         AINU.Is_Device (E) then
982
983
984
985
986
         Get_Name_String
            (CTU.To_C_Name
               (Display_Name
                  (Identifier
                     (Parent_Subcomponent (E)))));
987
         Add_Str_To_Name_Buffer ("_device_id");
988
989
990
      elsif (Present (Corresponding_Instance (E))
         and then AINU.Is_Process_Or_Device
            (Corresponding_Instance (E))) then
991

992
993
         Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
         Add_Str_To_Name_Buffer ("_k");
994
995
996
      elsif AINU.Is_Thread (Corresponding_Instance (E)) then
         --  For threads, the enumerator name is mapped from the
         --  containing process name and the thread subcomponent name.
997
         if Custom_Parent /= No_Node then
998
999
1000
            C_Name_1 := CTU.To_C_Name
              (Display_Name
                 (Identifier
For faster browsing, not all history is shown. View entire blame