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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
--                                                                          --
------------------------------------------------------------------------------

32
with Ocarina.Namet;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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

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

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

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

            --  Add the TO argument (second argument)

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

            Append_Node_To_List (N, Profile);

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

            --  Create the subprogram call

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

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

      end Update_Remote_Calls;

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

      --  The lists have to be created

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

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

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

      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;

579
580
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
   -------------------------------
   -- 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;

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
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
   -----------------------------
   -- 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
782
783
      pragma Assert (Present (A));

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

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

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

      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
926
927
928
929
930
931
     (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
932
933
934
935
936
   is
      C_Name_1 : Name_Id;
      C_Name_2 : Name_Id;
   begin
      if Kind (E) = K_Port_Spec_Instance then
937
         C_Name_1 := CTU.To_C_Name (Display_Name (Identifier (E)));
938
939
940
941

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

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

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

         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
1018
         raise Program_Error with "Wrong node kind for Map_C_Enumerator_Name";
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
      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
1032
1033
     (E        : Node_Id;
      Nb_Ports : Boolean := False) return Name_Id
1034
1035
1036
1037
1038
1039
1040
   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.

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

         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
1050
         raise Program_Error with "Wrong node kind for Map_C_Enumerator_Name";
1051
1052
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
      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;
1080
      Request_Variable  : Boolean := False) return Name_Id
1081
1082
1083
1084
1085
1086
   is
      C_Name : Name_Id;
   begin

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

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

         if Port_Local_Dest then
            Get_Name_String_And_Append
              (AIN.Name
1093
                 (Identifier (Parent_Subcomponent (Parent_Component (E)))));
1094
1095
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
            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 --
   --------------------------

1145
   function Map_C_Operation_Name (E : Node_Id) return Name_Id is
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
      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;
1160
      Suffix : Character := ASCII.NUL) return Name_Id
1161
1162
1163
1164
1165
   is
   begin
      pragma Assert (Kind (P) = K_Parameter_Instance);

      if Kind (Spg) = K_Component_Instance
1166
1167
        and then AINU.Is_Subprogram (Spg)
      then
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
         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 --
   --------------------------

1191
   function Map_C_Port_Data_Name (E : Node_Id; P : Node_Id) return Name_Id is
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
   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));
1212

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

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

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

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

      return No_Node;
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
   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
1247
1248
1249
1250
      pragma Assert
        (AINU.Is_Thread (E)
         or else AINU.Is_Subprogram (E)
         or else Kind (E) = K_Port_Spec_Instance);
1251
1252
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

      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
1280
1281
1282
1283
1284
     (A          : Node_Id;
      Is_Pointer : Boolean := False) return Node_Id
   is
      I, J      : Node_Id;
      Result    : Node_Id;
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
      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
1308
1309
               Add_Str_To_Name_Buffer
                 ("__" & Get_Name_String (Display_Name (J)));
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
               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;

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

      return Result;
   end Map_C_Defining_Identifier;

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

1330
   function Map_Scade_Function_Name (Subprogram : Node_Id) return Node_Id is
1331
1332
1333
   begin
      Get_Name_String (Get_Source_Name (Subprogram));

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

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

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

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

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

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

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

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

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

1370
1371
1372
1373
1374
1375
      if Scade_Name = No_Name then
         Scade_Name := Get_Source_Name (Parameter);
      end if;

      if Scade_Name = No_Name then
         Display_Located_Error
yoogx's avatar
yoogx committed
1376
1377
1378
           (AIN.Loc (Parameter),
            "The Parameter does not specify a SCADE mapping",
            Fatal => True);
1379
1380
1381
      end if;

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

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

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

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

      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;

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

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

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

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

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

1435
   function Map_Simulink_Model_Type (Subprogram : Node_Id) return Node_Id is
1436
1437
1438
1439
1440
   begin

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

1441
      return CTU.Make_Defining_Identifier (Name_Find, C_Conversion => False);
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
   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 --
   ---------------------

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   function Map_Lustre_Input_Function_Name
1546
1547
1548
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1549
1550
1551
1552
1553
1554
   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));

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

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

   function Map_Lustre_Temp_Var
1563
1564
1565
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1566
1567
1568
1569
1570
1571
1572
   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");

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

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

   function Map_Lustre_Output_Function_Name
1581
1582
1583
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1584
1585
1586
1587
1588
1589
   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));

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

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

1597
   function Map_Esterel_Header (Subprogram : Node_Id) return Node_Id is
1598
1599
1600
1601
1602
1603
   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");

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

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

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

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

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

   function Map_Esterel_Input_Function
1625
1626
1627
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id
   is
1628
1629
1630
1631
1632
1633
   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));

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

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

   function Map_Esterel_Output_Function
1642
1643
1644
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id
   is
1645
1646
1647
1648
1649
1650
   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));

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

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

   function Map_Esterel_Temp_Var
1659
1660
1661
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id
   is
1662
1663
1664
1665
1666
1667
1668
   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");

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

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

   function Map_C_Feature_Subprogram
     (A     : Node_Id;
1678
      Owner : Node_Id := No_Node) return Node_Id
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
   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);

1701
      N      := Name_Find;
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
      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;
1714
1715
1716
1717
1718
1719
      Is_Request    : Boolean := False) return Node_Id
   is
      I      : Node_Id;
      Result : Node_Id;
      N      : Name_Id;
      C_Name : Name_Id;
1720
1721
1722
1723
   begin
      I := Identifier (A);

      if Kind (A) = K_Port_Spec_Instance then
1724
1725
1726
1727
         C_Name :=
           CTU.To_C_Name
             (Display_Name
                (Identifier (Parent_Subcomponent (Parent_Component (A)))));
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
      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);

1753
1754
      N      := Name_Find;
      Result := CTU.Make_Defining_Identifier (N);
1755
1756
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
      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
1881
   function Map_C_Subprogram_Spec
1882
1883
1884
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id
   is
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
      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
1895
      if Get_Current_Backend_Kind = PolyORB_HI_C
1896
1897
1898
1899
1900
1901
        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
1902
1903
1904
         CTU.Append_Node_To_List (Param, Profile);
      end if;

1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
      --  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
1931
1932
1933
1934
                  Param :=
                    CTU.Make_Parameter_Specification
                      (Defining_Identifier => Map_C_Defining_Identifier (F),
                       Parameter_Type      => Map_C_Data_Type_Designator (D));
1935
               else
1936
1937
1938
1939
1940
1941
                  Param :=
                    CTU.Make_Parameter_Specification
                      (Defining_Identifier => Map_C_Defining_Identifier (F),
                       Parameter_Type      =>
                         CTU.Make_Pointer_Type
                           (Map_C_Data_Type_Designator (D)));
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
               end if;
               CTU.Append_Node_To_List (Param, Profile);
            end if;

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

      --  Second, the data access mapping. The data accesses are not
      --  mapped in the case of pure call sequence subprogram because
      --  they are used only to close the access chain.

Julien's avatar
Julien committed
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
      if not AINU.Is_Empty (Features (S)) then
         F := AIN.First_Node (Features (S));

         while Present (F) loop
            if Kind (F) = K_Subcomponent_Access_Instance then
               case Get_Required_Data_Access (Corresponding_Instance (F)) is
                  when Access_Read_Only =>
                     Mode := Mode_In;
                  when Access_Write_Only =>
                     Mode := Mode_Out;
                  when Access_Read_Write =>
                     Mode := Mode_Inout;
                  when Access_None =>
                     --  By default, we allow read/write access
                     Mode := Mode_Inout;
                  when others =>
                     Display_Located_Error
                       (AIN.Loc (F),
                        "Unsupported required access",
                        Fatal => True);
               end case;

               D := Corresponding_Instance (F);
1977