ocarina-backends-c_common-mapping.adb 143 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                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2014 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
with Ocarina.Namet;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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

59
   use Ocarina.Namet;
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
   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
90
91
92
93
     (Caller_Thread : Node_Id;
      Spg_Call      : Node_Id;
      Declarations  : List_Id;
      Statements    : List_Id)
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
   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.

153
154
155
156
157
         pragma Assert
           (AINU.Is_Thread
              (Parent_Component
                 (Parent_Sequence
                    (Parent_Subcomponent (Parent_Component (Root_F))))));
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

         --  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)
225
226
227
228
229
            N :=
              Make_Defining_Identifier
                (Map_C_Enumerator_Name
                   (Parent_Subcomponent (Caller_Thread),
                    Entity => True));
230
231
232
233
            Append_Node_To_List (N, Profile);

            --  Add the TO argument (second argument)

234
235
236
237
238
            N :=
              Make_Defining_Identifier
                (Map_C_Enumerator_Name
                   (Parent_Subcomponent (Get_Container_Thread (Remote_Spg)),
                    Entity => True));
239
240
241
242

            Append_Node_To_List (N, Profile);

            --  Add the message argument (third argument)
243
244
245
            N :=
              Make_Variable_Address
                (Make_Defining_Identifier (PN (P_Message)));
246
247
248
249
            Append_Node_To_List (N, Profile);

            --  Create the subprogram call

250
            N := Make_Call_Profile (Map_Stub_Identifier (Remote_Spg), Profile);
251
252
253
254
255
256
257
258
259
260
261
            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;

262
263
264
         N :=
           Make_Defining_Identifier
             (Map_C_Full_Parameter_Name (Spg_Call, Param_Value));
265
266
267
268
         Append_Node_To_List (N, Profile);

      end Update_Remote_Calls;

269
270
      Spg : constant Node_Id := Corresponding_Instance (Spg_Call);
      F   : Node_Id;
271
272
273
274
275
276
   begin
      pragma Assert (AINU.Is_Thread (Caller_Thread));

      --  The lists have to be created

      if Declarations = No_List or else Statements = No_List then
277
278
279
         raise Program_Error
           with "Lists have to be created before any " &
           "call to Get_Remote_Subprogram";
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
      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
317
318
319
320
321
         CTN.Set_Name
           (D,
            To_C_Name
              (AIN.Name (AIN.Identifier (Parent_Subcomponent (E))),
               Keyword_Check => False));
322
      else
hugues.jerome's avatar
hugues.jerome committed
323
         CTN.Set_Name (D, To_C_Name (AIN.Name (AIN.Identifier (E))));
324
      end if;
hugues.jerome's avatar
hugues.jerome committed
325

326
327
328
329
330
331
332
333
334
335
      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 --
   -----------------

336
337
338
339
   function Map_HI_Node
     (E      : Node_Id;
      Kernel : Boolean := False) return Node_Id
   is
340
341
342
      N : constant Node_Id := New_Node (CTN.K_HI_Node);
   begin
      pragma Assert
343
        (AINU.Is_Process_Or_Device (E)
344
345
346
347
348
349
350
351
352
353
354
         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
355
356
357
358
359
         CTN.Set_Name
           (N,
            To_C_Name
              (AIN.Name (AIN.Identifier (AIN.Parent_Subcomponent (E))),
               Keyword_Check => False));
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
      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
379
380
381
382
383
      U : Node_Id;
      S : List_Id;
      H : List_Id;
      N : Node_Id;
      P : Node_Id;
384
   begin
385
386
387
388
      pragma Assert
        (AINU.Is_System (E)
         or else AINU.Is_Process_Or_Device (E)
         or else AINU.Is_Processor (E));
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

      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
   function Map_Task_Job_Identifier
858
859
860
     (E                : Node_Id;
      Prefix_Component : Node_Id := No_Node) return Node_Id
   is
861
      Name : Name_Id;
jdelange's avatar
jdelange committed
862
863
      C1   : Name_Id := No_Name;
      C2   : Name_Id := No_Name;
864
   begin
jdelange's avatar
jdelange committed
865
866
      if Prefix_Component /= No_Node then
         Get_Name_String
867
           (To_C_Name (AIN.Display_Name (Identifier (Prefix_Component))));
jdelange's avatar
jdelange committed
868
869
         C1 := Name_Find;
      end if;
870
      Get_Name_String (To_C_Name (AIN.Display_Name (Identifier (E))));
jdelange's avatar
jdelange committed
871
872
873
874
875
876
877
878
879
880
      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);
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
      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 --
   ---------------------

905
906
907
   function Map_C_Enum_Name
     (E          : Node_Id;
      Enumerator : Name_Id) return Name_Id
908
909
910
911
912
913
914
   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.

915
      Enum_Name := To_C_Name (Display_Name (Identifier (E)));
916
917
918
919
920
921
922
923
924
925
926
927

      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
928
929
930
931
932
933
     (E             : Node_Id;
      Custom_Parent : Node_Id := No_Node;
      Entity        : Boolean := False;
      Server        : Boolean := False;
      Port_Type     : Boolean := False;
      Local_Port    : Boolean := False) return Name_Id
934
935
936
937
938
   is
      C_Name_1 : Name_Id;
      C_Name_2 : Name_Id;
   begin
      if Kind (E) = K_Port_Spec_Instance then
939
         C_Name_1 := CTU.To_C_Name (Display_Name (Identifier (E)));
940
941
942
943

         Get_Name_String
           (CTU.To_C_Name
              (Display_Name
944
                 (Identifier (Parent_Subcomponent (Parent_Component (E))))));
945
946
947
948
949
950
951
         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;
952
953
954
      elsif AINU.Is_Bus (E) then
         Set_Str_To_Name_Buffer ("bus_");
         Get_Name_String_And_Append
955
           (AIN.Name (AIN.Identifier (Parent_Subcomponent (E))));
956
957
958
959
      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
960
              (AIN.Name (AIN.Identifier (Parent_Subcomponent (E))));
961
         else
962
            Get_Name_String_And_Append (AIN.Name (AIN.Identifier (E)));
963
         end if;
964
      elsif AINU.Is_Subprogram (E) then
965
966
967
968
969
         --  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");
970
971
972
      elsif Get_Current_Backend_Kind = PolyORB_HI_C
        and then AINU.Is_Device (E)
      then
973
         Get_Name_String
974
975
           (CTU.To_C_Name
              (Display_Name (Identifier (Parent_Subcomponent (E)))));
976
         Add_Str_To_Name_Buffer ("_device_id");
977
978
979
980
      elsif
        (Present (Corresponding_Instance (E))
         and then AINU.Is_Process_Or_Device (Corresponding_Instance (E)))
      then
981

982
983
         Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
         Add_Str_To_Name_Buffer ("_k");
984
985
986
      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.
987
         if Custom_Parent /= No_Node then
988
989
990
991
            C_Name_1 :=
              CTU.To_C_Name
                (Display_Name
                   (Identifier (Parent_Subcomponent (Custom_Parent))));
992
         else
993
994
995
996
            C_Name_1 :=
              CTU.To_C_Name
                (Display_Name
                   (Identifier (Parent_Subcomponent (Parent_Component (E)))));
997
998
         end if;

999
         C_Name_2 := CTU.To_C_Name (Display_Name (Identifier (E)));
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

         if Port_Type then
            Set_Str_To_Name_Buffer ("__po_hi_");
            Get_Name_String_And_Append (C_Name_2);
            Add_Str_To_Name_Buffer ("_t");
         else
            Get_Name_String (C_Name_1);
            Add_Char_To_Name_Buffer ('_');
            Get_Name_String_And_Append (C_Name_2);
            Add_Str_To_Name_Buffer ("_k");
         end if;

         if Server then
            Add_Str_To_Name_Buffer ("_server");
         end if;

         if Entity then
            Add_Str_To_Name_Buffer ("_entity");
         end if;
      else
1020
         raise Program_Error with "Wrong node kind for Map_C_Enumerator_Name";
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
      end if;

      C_Name_1 := Name_Find;
      C_Name_1 := To_Lower (C_Name_1);

      return C_Name_1;
   end Map_C_Enumerator_Name;

   -----------------------
   -- Map_C_Define_Name --
   -----------------------

   function Map_C_Define_Name
1034
1035
     (E        : Node_Id;
      Nb_Ports : Boolean := False) return Name_Id
1036
1037
1038
1039
1040
1041
1042
   is
      C_Name : Name_Id;
   begin
      if AINU.Is_Thread (Corresponding_Instance (E)) then
         --  For threads, the enumerator name is mapped from the
         --  containing process name and the thread subcomponent name.

1043
         C_Name := Display_Name (Identifier (E));
1044
1045
1046
1047
1048
1049
1050
1051

         Set_Str_To_Name_Buffer ("__PO_HI_");

         Get_Name_String_And_Append (C_Name);
         if Nb_Ports then
            Add_Str_To_Name_Buffer ("_NB_PORTS");
         end if;
      else
1052
         raise Program_Error with "Wrong node kind for Map_C_Enumerator_Name";
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
      end if;

      C_Name := Name_Find;
      C_Name := To_Upper (C_Name);

      return C_Name;
   end Map_C_Define_Name;

   -------------------------
   -- Map_C_Variable_Name --
   -------------------------

   function Map_C_Variable_Name
     (E                 : Node_Id;
      Port_Variable     : Boolean := False;
      Port_History      : Boolean := False;
      Port_Woffsets     : Boolean := False;
      Port_Empties      : Boolean := False;
      Port_First        : Boolean := False;
      Port_Queue        : Boolean := False;
      Port_Recent       : Boolean := False;
      Port_Fifo_Size    : Boolean := False;
      Port_Offsets      : Boolean := False;
      Port_Used_Size    : Boolean := False;
      Port_N_Dest       : Boolean := False;
      Port_Local_Dest   : Boolean := False;
      Port_Destinations : Boolean := False;
      Port_Total_Fifo   : Boolean := False;
      Port_Request      : Boolean := False;
1082
      Request_Variable  : Boolean := False) return Name_Id
1083
1084
1085
1086
1087
1088
   is
      C_Name : Name_Id;
   begin

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

1089
      if not Port_Request and then not Request_Variable then
1090
1091
1092
1093
1094
         Set_Str_To_Name_Buffer ("__po_hi_");

         if Port_Local_Dest then
            Get_Name_String_And_Append
              (AIN.Name
1095
                 (Identifier (Parent_Subcomponent (Parent_Component (E)))));
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
            Add_Str_To_Name_Buffer ("_");
         end if;

         Get_Name_String_And_Append (C_Name);
      else
         Get_Name_String (C_Name);
      end if;

      if Port_Variable then
         Add_Str_To_Name_Buffer ("_local_to_global");
      elsif Port_History then
         Add_Str_To_Name_Buffer ("_history");
      elsif Port_Woffsets then
         Add_Str_To_Name_Buffer ("_woffsets");
      elsif Port_Empties then
         Add_Str_To_Name_Buffer ("_empties");
      elsif Port_First then
         Add_Str_To_Name_Buffer ("_first");
      elsif Port_Queue then
         Add_Str_To_Name_Buffer ("_queue");
      elsif Port_Recent then
         Add_Str_To_Name_Buffer ("_recent");
      elsif Port_Fifo_Size then
         Add_Str_To_Name_Buffer ("_fifo_size");
      elsif Port_Offsets then
         Add_Str_To_Name_Buffer ("_offsets");
      elsif Port_Used_Size then
         Add_Str_To_Name_Buffer ("_used_size");
      elsif Port_N_Dest then
         Add_Str_To_Name_Buffer ("_n_dest");
      elsif Port_Local_Dest then
         Add_Str_To_Name_Buffer ("_local_destinations");
      elsif Port_Destinations then
         Add_Str_To_Name_Buffer ("_destinations");
      elsif Port_Total_Fifo then
         Add_Str_To_Name_Buffer ("_total_fifo_size");
      elsif Port_Request then
         Add_Str_To_Name_Buffer ("_request");
      elsif Request_Variable then
         Add_Str_To_Name_Buffer ("_request_var");
      end if;

      C_Name := Name_Find;

      return C_Name;
   end Map_C_Variable_Name;

   --------------------------
   -- Map_C_Operation_Name --
   --------------------------

1147
   function Map_C_Operation_Name (E : Node_Id) return Name_Id is
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
      C_Name : Name_Id;
   begin
      Get_Name_String (CTU.To_C_Name (Display_Name (Identifier (E))));
      C_Name := Name_Find;
      return C_Name;
   end Map_C_Operation_Name;

   -------------------------------
   -- Map_C_Full_Parameter_Name --
   -------------------------------

   function Map_C_Full_Parameter_Name
     (Spg    : Node_Id;
      P      : Node_Id;
1162
      Suffix : Character := ASCII.NUL) return Name_Id
1163
1164
1165
1166
1167
   is
   begin
      pragma Assert (Kind (P) = K_Parameter_Instance);

      if Kind (Spg) = K_Component_Instance
1168
1169
        and then AINU.Is_Subprogram (Spg)
      then
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
         Get_Name_String (AINU.Compute_Full_Name_Of_Instance (Spg, True));
      elsif Kind (Spg) = K_Call_Instance then
         Get_Name_String (Display_Name (Identifier (Spg)));
      else
         raise Program_Error with "Wrong subprogram kind";
      end if;

      Add_Char_To_Name_Buffer ('_');
      Get_Name_String_And_Append (Display_Name (Identifier (P)));

      Get_Name_String (CTU.To_C_Name (Name_Find));

      if Suffix /= ASCII.NUL then
         Add_Str_To_Name_Buffer ('_' & Suffix);
      end if;

      return Name_Find;
   end Map_C_Full_Parameter_Name;

   --------------------------
   -- Map_C_Port_Data_Name --
   --------------------------

1193
   function Map_C_Port_Data_Name (E : Node_Id; P : Node_Id) return Name_Id is
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
   begin
      Get_Name_String (AINU.Compute_Full_Name_Of_Instance (E, True));

      Add_Char_To_Name_Buffer ('_');
      Get_Name_String_And_Append (Display_Name (Identifier (P)));

      Get_Name_String (CTU.To_C_Name (Name_Find));

      return Name_Find;
   end Map_C_Port_Data_Name;

   --------------------------------
   -- Map_C_Data_Type_Designator --
   --------------------------------

   function Map_C_Data_Type_Designator (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
      if Get_Current_Backend_Kind = PolyORB_Kernel_C then
         Add_Include (PKR.RH (RH_Gtypes));
1214

1215
1216
1217
1218
1219
      elsif Get_Current_Backend_Kind = PolyORB_HI_C then
         Add_Include (PHR.RH (RH_Types));
      end if;

      if Present (Backend_Node (Identifier (E)))
1220
1221
        and then Present
          (CTN.Type_Definition_Node (Backend_Node (Identifier (E))))
1222
      then
1223
1224
1225
         N :=
           Type_Name
             (CTN.Type_Definition_Node (Backend_Node (Identifier (E))));
1226
1227
1228

         if Kind (N) = K_Defining_Identifier then
            return N;
1229

1230
1231
1232
1233
         elsif Kind (N) = K_Array_Declaration then
            return Defining_Identifier (N);
         end if;
      else
1234
1235
         --  XXX why do we need this hack?
         return Map_C_Defining_Identifier (E);
1236
      end if;
1237
1238

      return No_Node;
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
   end Map_C_Data_Type_Designator;

   ---------------------------------
   -- Map_C_Subprogram_Identifier --
   ---------------------------------

   function Map_C_Subprogram_Identifier (E : Node_Id) return Node_Id is
      Result   : Node_Id;
      Spg_Name : Name_Id;
   begin
1249
1250
1251
1252
      pragma Assert
        (AINU.Is_Thread (E)
         or else AINU.Is_Subprogram (E)
         or else Kind (E) = K_Port_Spec_Instance);
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281

      if AINU.Is_Subprogram (E)
        and then Get_Source_Language (E) /= Language_C
      then
         Display_Error ("This is not a C function", Fatal => True);
      end if;

      --  Get the subprogram name

      if AINU.Is_Subprogram (E) then
         Spg_Name := Get_Source_Name (E);
      elsif AINU.Is_Thread (E) then
         Spg_Name := Get_Thread_Compute_Entrypoint (E);
      else
         Spg_Name := Get_Port_Compute_Entrypoint (E);
      end if;

      --  Get the full implementation name

      Get_Name_String (Spg_Name);
      Result := Make_Defining_Identifier (Name_Find);
      return Result;
   end Map_C_Subprogram_Identifier;

   -------------------------------
   -- Map_C_Defining_Identifier --
   -------------------------------

   function Map_C_Defining_Identifier
1282
1283
1284
1285
1286
     (A          : Node_Id;
      Is_Pointer : Boolean := False) return Node_Id
   is
      I, J      : Node_Id;
      Result    : Node_Id;
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
      Name_List : List_Id;

   begin
      if Kind (A) /= K_Identifier then
         I := Identifier (A);
      end if;

      if Kind (A) = K_Component_Instance
        and then Display_Name (Identifier (Namespace (A))) /= No_Name
      then
         --  If this is a component instance, use both namespace and
         --  identifier to build the C defining identifier, to avoid
         --  collisions in the C namespace.

         Name_List := AINU.Split_Name (Namespace (A));

         J := AIN.First_Node (Name_List);

         if Present (J) then
            Get_Name_String (To_C_Name (Display_Name (J)));
            J := AIN.Next_Node (J);

            while Present (J) loop
1310
1311
               Add_Str_To_Name_Buffer
                 ("__" & Get_Name_String (Display_Name (J)));
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
               J := AIN.Next_Node (J);
            end loop;
         end if;

         Add_Str_To_Name_Buffer ("__" & Get_Name_String (Display_Name (I)));

      else
         Get_Name_String (Display_Name (I));
      end if;

1322
1323
      Result :=
        CTU.Make_Defining_Identifier (To_C_Name (Name_Find), True, Is_Pointer);
1324
1325
1326
1327
1328
1329
1330
1331

      return Result;
   end Map_C_Defining_Identifier;

   ------------------------
   -- Map_Scade_Function --
   ------------------------

1332
   function Map_Scade_Function_Name (Subprogram : Node_Id) return Node_Id is
1333
1334
1335
   begin
      Get_Name_String (Get_Source_Name (Subprogram));

1336
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1337
1338
1339
1340
1341
1342
   end Map_Scade_Function_Name;

   -------------------------
   -- Map_Scade_Struct_In --
   -------------------------

1343
   function Map_Scade_Struct_In (Subprogram : Node_Id) return Node_Id is
1344
1345
1346
1347
   begin
      Set_Str_To_Name_Buffer ("inC_");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));

1348
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1349
1350
1351
1352
1353
1354
   end Map_Scade_Struct_In;

   --------------------------
   -- Map_Scade_Struct_Out --
   --------------------------

1355
   function Map_Scade_Struct_Out (Subprogram : Node_Id) return Node_Id is
1356
1357
1358
1359
   begin
      Set_Str_To_Name_Buffer ("outC_");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));

1360
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1361
1362
1363
1364
1365
1366
   end Map_Scade_Struct_Out;

   -------------------------
   -- Map_Scade_Parameter --
   -------------------------

1367
   function Map_Scade_Parameter (Parameter : Node_Id) return Node_Id is
1368
      Scade_Name : Name_Id;
1369
   begin
1370
      Scade_Name := Get_Scade_Signal (Parameter);
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
      if Scade_Name = No_Name then
         Scade_Name := Get_Source_Name (Parameter);
      end if;

      if Scade_Name = No_Name then
         Display_Located_Error
            (AIN.Loc (Parameter),
             "The Parameter does not specify a SCADE mapping",
             Fatal => True);
      end if;

      return CTU.Make_Defining_Identifier (Scade_Name, C_Conversion => False);
1384
1385
1386
1387
1388
1389
   end Map_Scade_Parameter;

   ----------------------
   -- Map_Simulink_Var --
   ----------------------

1390
1391
1392
   function Map_Simulink_Var
     (Corresponding_Feature : Node_Id) return Node_Id
   is
1393
1394
1395
1396
1397
1398
      Variable_Name : Name_Id;
      Simulink_Var  : Node_Id;
   begin
      Set_Str_To_Name_Buffer ("");

      Get_Name_String
1399
        (Get_Source_Name (Parent_Component (Corresponding_Feature)));
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

      if Is_In (Corresponding_Feature) then
         Add_Str_To_Name_Buffer ("_U");
      end if;

      if Is_Out (Corresponding_Feature) then
         Add_Str_To_Name_Buffer ("_Y");
      end if;

      Variable_Name := Name_Find;

1411
1412
1413
1414
1415
1416
1417
      Simulink_Var :=
        Make_Member_Designator
          (Make_Defining_Identifier
             (Get_Source_Name (Corresponding_Feature),
              False),
           Make_Defining_Identifier (Variable_Name, False),
           False);
1418
1419
1420
1421
1422
1423
1424
      return Simulink_Var;
   end Map_Simulink_Var;

   ----------------------------
   -- Map_Simulink_Init_Func --
   ----------------------------

1425
   function Map_Simulink_Init_Func (Subprogram : Node_Id) return Node_Id is
1426
1427
1428
1429
   begin
      Get_Name_String (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_InitializeDataMapInfo");

1430
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1431
1432
1433
1434
1435
1436
   end Map_Simulink_Init_Func;

   -----------------------------
   -- Map_Simulink_Model_Type --
   -----------------------------

1437
   function Map_Simulink_Model_Type (Subprogram : Node_Id) return Node_Id is
1438
1439
1440
1441
1442
   begin

      Set_Str_To_Name_Buffer ("RT_MODEL_");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));

1443
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
   end Map_Simulink_Model_Type;

   -------------------------
   -- Map_Simulink_Header --
   -------------------------

   function Map_Simulink_Header (Subprogram : Node_Id) return Node_Id is
      N : Name_Id;
   begin

      N := Get_Source_Name (Subprogram);

      if N = No_Name then
         return No_Node;
      end if;

      Get_Name_String (N);
      Add_Str_To_Name_Buffer ("_capi");

      return CTU.Make_Defining_Identifier (Name_Find);
   end Map_Simulink_Header;

   ---------------------
   -- Map_Source_Name --
   ---------------------

1470
   function Map_Source_Name (Subprogram : Node_Id) return Node_Id is
1471
1472
1473
1474
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));

1475
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1476
1477
1478
1479
1480
1481
   end Map_Source_Name;

   -----------------------------
   -- Map_Lustre_Context_Name --
   -----------------------------

1482
   function Map_Lustre_Context_Name (Subprogram : Node_Id) return Node_Id is
1483
1484
1485
1486
1487
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_context");

1488
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1489
1490
1491
1492
1493
1494
   end Map_Lustre_Context_Name;

   ------------------------------
   -- Map_Lustre_Context_Reset --
   ------------------------------

1495
   function Map_Lustre_Context_Reset (Subprogram : Node_Id) return Node_Id is
1496
1497
1498
1499
1500
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_reset");

1501
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1502
1503
1504
1505
1506
1507
   end Map_Lustre_Context_Reset;

   -----------------------------
   -- Map_Lustre_Context_Init --
   -----------------------------

1508
   function Map_Lustre_Context_Init (Subprogram : Node_Id) return Node_Id is
1509
1510
1511
1512
1513
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_new_ctx");

1514
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1515
1516
1517
1518
1519
1520
   end Map_Lustre_Context_Init;

   -----------------------------
   -- Map_Lustre_Context_Type --
   -----------------------------

1521
   function Map_Lustre_Context_Type (Subprogram : Node_Id) return Node_Id is
1522
1523
1524
1525
1526
   begin
      Set_Str_To_Name_Buffer ("struct ");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_ctx");

1527
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1528
1529
1530
1531
1532
1533
   end Map_Lustre_Context_Type;

   --------------------------
   -- Map_Lustre_Step_Name --
   --------------------------

1534
   function Map_Lustre_Step_Name (Subprogram : Node_Id) return Node_Id is
1535
1536
1537
1538
1539
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_step");

1540
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1541
1542
1543
1544
1545
1546
1547
   end Map_Lustre_Step_Name;

   ------------------------------------
   -- Map_Lustre_Input_Function_Name --
   ------------------------------------

   function Map_Lustre_Input_Function_Name
1548
1549
1550
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1551
1552
1553
1554
1555
1556
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_I_");
      Get_Name_String_And_Append (Get_Source_Name (Port));

1557
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1558
1559
1560
1561
1562
1563
1564
   end Map_Lustre_Input_Function_Name;

   -------------------------
   -- Map_Lustre_Temp_Var --
   -------------------------

   function Map_Lustre_Temp_Var
1565
1566
1567
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1568
1569
1570
1571
1572
1573
1574
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_");
      Get_Name_String_And_Append (Get_Source_Name (Port));
      Add_Str_To_Name_Buffer ("_lustre_tmpvar");

1575
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1576
1577
1578
1579
1580
1581
1582
   end Map_Lustre_Temp_Var;

   -------------------------------------
   -- Map_Lustre_Output_Function_Name --
   -------------------------------------

   function Map_Lustre_Output_Function_Name
1583
1584
1585
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1586
1587
1588
1589
1590
1591
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_O_");
      Get_Name_String_And_Append (Get_Source_Name (Port));

1592
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1593
1594
1595
1596
1597
1598
   end Map_Lustre_Output_Function_Name;

   ------------------------
   -- Map_Esterel_Header --
   ------------------------

1599
   function Map_Esterel_Header (Subprogram : Node_Id) return Node_Id is
1600
1601
1602
1603
1604
1605
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Location (Subprogram));
      Set_Str_To_Name_Buffer (Name_Buffer (1 .. Name_Len - 2));
      Add_Str_To_Name_Buffer ("_strl");

1606
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1607
1608
1609
1610
1611
1612
   end Map_Esterel_Header;

   --------------------------------
   -- Map_Esterel_Reset_Function --
   --------------------------------

1613
   function Map_Esterel_Reset_Function (Subprogram : Node_Id) return Node_Id is
1614
1615
1616
1617
1618
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_reset");

1619
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1620
1621
1622
1623
1624
1625
1626
   end Map_Esterel_Reset_Function;

   --------------------------------
   -- Map_Esterel_Input_Function --
   --------------------------------

   function Map_Esterel_Input_Function
1627
1628
1629
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id
   is
1630
1631
1632
1633
1634
1635
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_I_");
      Get_Name_String_And_Append (Get_Source_Name (Feature));

1636
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1637
1638
1639
1640
1641
1642
1643
   end Map_Esterel_Input_Function;

   ---------------------------------
   -- Map_Esterel_Output_Function --
   ---------------------------------

   function Map_Esterel_Output_Function
1644
1645
1646
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id
   is
1647
1648
1649
1650
1651
1652
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_O_");
      Get_Name_String_And_Append (Get_Source_Name (Feature));

1653
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1654
1655
1656
1657
1658
1659
1660
   end Map_Esterel_Output_Function;

   --------------------------
   -- Map_Esterel_Temp_Var --
   --------------------------

   function Map_Esterel_Temp_Var
1661
1662
1663
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1664
1665
1666
1667
1668
1669
1670
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String_And_Append (Get_Source_Name (Subprogram));
      Add_Str_To_Name_Buffer ("_");
      Get_Name_String_And_Append (Get_Source_Name (Port));
      Add_Str_To_Name_Buffer ("_esterel_tmpvar");

1671
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1672
1673
1674
1675
1676
1677
1678
1679
   end Map_Esterel_Temp_Var;

   ------------------------------
   -- Map_C_Feature_Subprogram --
   ------------------------------

   function Map_C_Feature_Subprogram
     (A     : Node_Id;
1680
      Owner : Node_Id := No_Node) return Node_Id
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
   is
      I      : Node_Id;
      Result : Node_Id;
      M      : Name_Id;
      N      : Name_Id;
   begin
      if Kind (A) /= K_Identifier then
         I := Identifier (A);
      end if;

      if Present (Owner) then
         M := CTU.To_C_Name (Display_Name (Identifier (Owner)));
      else
         M := CTU.To_C_Name (Display_Name (Identifier (Parent_Component (A))));
      end if;

      N := CTU.To_C_Name (Display_Name (I));

      Get_Name_String (M);
      Add_Char_To_Name_Buffer ('_');
      Get_Name_String_And_Append (N);

1703
      N      := Name_Find;
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
      Result := CTU.Make_Defining_Identifier (N);

      return Result;
   end Map_C_Feature_Subprogram;

   ---------------------------------
   -- Map_C_Marshaller_Subprogram --
   ---------------------------------

   function Map_C_Marshaller_Subprogram
     (A             : Node_Id;
      Is_Unmarshall : Boolean := False;
1716
1717
1718
1719
1720
1721
      Is_Request    : Boolean := False) return Node_Id
   is
      I      : Node_Id;
      Result : Node_Id;
      N      : Name_Id;
      C_Name : Name_Id;
1722
1723
1724
1725
   begin
      I := Identifier (A);

      if Kind (A) = K_Port_Spec_Instance then
1726
1727
1728
1729
         C_Name :=
           CTU.To_C_Name
             (Display_Name
                (Identifier (Parent_Subcomponent (Parent_Component (A)))));
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
      end if;

      N := CTU.To_C_Name (Display_Name (I));

      if Is_Request then
         if Is_Unmarshall then
            Set_Str_To_Name_Buffer ("__po_hi_unmarshall_request_");
         else
            Set_Str_To_Name_Buffer ("__po_hi_marshall_request_");
         end if;
      else
         if Is_Unmarshall then
            Set_Str_To_Name_Buffer ("__po_hi_unmarshall_type_");
         else
            Set_Str_To_Name_Buffer ("__po_hi_marshall_type_");
         end if;
      end if;

      if Kind (A) = K_Port_Spec_Instance then
         Get_Name_String_And_Append (C_Name);
         Add_Str_To_Name_Buffer ("_");
      end if;

      Get_Name_String_And_Append (N);

1755
1756
      N      := Name_Find;
      Result := CTU.Make_Defining_Identifier (N);
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
      return Result;
   end Map_C_Marshaller_Subprogram;

   -----------------------
   -- Bind_AADL_To_Stub --
   -----------------------

   procedure Bind_AADL_To_Stub (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_Stub_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Stub;

   ------------------------
   -- Bind_AADL_To_Types --
   ------------------------

   procedure Bind_AADL_To_Types (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_Types_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Types;

   --------------------------------
   -- Bind_AADL_To_Default_Value --
   --------------------------------

   procedure Bind_AADL_To_Default_Value (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_Default_Value_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Default_Value;

   -------------------------
   -- Bind_AADL_To_Object --
   -------------------------

   procedure Bind_AADL_To_Object (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_Object_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Object;

   -----------------------------
   -- Bind_AADL_To_Marshaller --
   -----------------------------

   procedure Bind_AADL_To_Marshaller (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_Marshaller_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Marshaller;

   -------------------------------
   -- Bind_AADL_To_Unmarshaller --
   -------------------------------

   procedure Bind_AADL_To_Unmarshaller (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_Unmarshaller_Node (N, A);
      CTN.Set_Frontend_Node (A, G);
   end Bind_AADL_To_Unmarshaller;

   -------------------------
   -- Map_Stub_Identifier --
   -------------------------

   function Map_Stub_Identifier (E : Node_Id) return Node_Id is
   begin
      Get_Name_String (To_C_Name (AIN.Display_Name (Identifier (E))));
      Add_Str_To_Name_Buffer ("_stub");
      return Make_Defining_Identifier (Name_Find);
   end Map_Stub_Identifier;

   ---------------------------
   -- Map_C_Subprogram_Spec --
   ---------------------------

jdelange's avatar
jdelange committed
1883
   function Map_C_Subprogram_Spec
1884
1885
1886
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id
   is
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
      Profile : constant List_Id := CTU.New_List (CTN.K_Parameter_Profile);
      Param   : Node_Id;
      Mode    : Mode_Id;
      F       : Node_Id;
      N       : Node_Id;
      D       : Node_Id;
      Field   : Node_Id;
   begin
      pragma Assert (AINU.Is_Subprogram (S));

jdelange's avatar
jdelange committed
1897
      if Get_Current_Backend_Kind = PolyORB_HI_C
1898
1899
1900
1901
1902
1903
        and then Containing_Device /= No_Node
      then
         Param :=
           CTU.Make_Parameter_Specification
             (Defining_Identifier => Make_Defining_Identifier (VN (V_Dev_Id)),
              Parameter_Type      => (RE (RE_Device_Id)));
jdelange's avatar
jdelange committed
1904
1905
1906
         CTU.Append_Node_To_List (Param, Profile);
      end if;

1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
      --  We build the parameter profile of the subprogram instance by
      --  adding:

      --  First, the parameter features mapping

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

         while Present (F) loop
            if Kind (F) = K_Parameter_Instance then
               if Is_In (F) and then Is_Out (F) then
                  Mode := Mode_Inout;
               elsif Is_Out (F) then
                  Mode := Mode_Out;
               elsif Is_In (F) then
                  Mode := Mode_In;
               else
                  Display_Located_Error
                    (AIN.Loc (F),
                     "Unspecified parameter mode",
                     Fatal => True);
               end if;

               D := Corresponding_Instance (F);

               if Mode = Mode_In then
1933
1934
1935
1936
                  Param :=
                    CTU.Make_Parameter_Specification
                      (Defining_Identifier => Map_C_Defining_Identifier (F),
                       Parameter_Type      => Map_C_Data_Type_Designator (D));
1937
               else
1938
1939
1940
1941
1942
1943
                  Param :=
                    CTU.Make_Parameter_Specification
                      (Defining_Identifier => Map_C_Defining_Identifier (F),
                       Parameter_Type      =>
                         CTU.Make_Pointer_Type
                           (Map_C_Data_Type_Designator (D)));
1944
1945
1946
1947
1948