ocarina-backends-po_hi_ada-activity.adb 175 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--  O C A R I N A . B A C K E N D S . P O _ H I _ A D A . A C T I V I T Y   --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2006-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
with Locations;

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

with Ocarina.Backends.Utils;
with Ocarina.Backends.Properties;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Ada_Tree.Nutils;
with Ocarina.Backends.Ada_Tree.Nodes;
with Ocarina.Backends.Ada_Values;
with Ocarina.Backends.PO_HI_Ada.Mapping;
with Ocarina.Backends.PO_HI_Ada.Runtime;

package body Ocarina.Backends.PO_HI_Ada.Activity is

54
   use Ocarina.Namet;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
   use Locations;
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.Ada_Tree.Nutils;
   use Ocarina.Backends.Ada_Values;
   use Ocarina.Backends.PO_HI_Ada.Mapping;
   use Ocarina.Backends.PO_HI_Ada.Runtime;

   package AAN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package ADN renames Ocarina.Backends.Ada_Tree.Nodes;

   function Send_Output_Spec (E : Node_Id) return Node_Id;
   function Put_Value_Spec (E : Node_Id) return Node_Id;
   function Receive_Input_Spec (E : Node_Id) return Node_Id;
   function Get_Value_Spec (E : Node_Id) return Node_Id;
   function Get_Sender_Spec (E : Node_Id) return Node_Id;
   function Get_Count_Spec (E : Node_Id) return Node_Id;
   function Get_Time_Stamp_Spec (E : Node_Id) return Node_Id;
   function Next_Value_Spec (E : Node_Id) return Node_Id;
   function Store_Received_Message_Spec (E : Node_Id) return Node_Id;
   function Wait_For_Incoming_Events_Spec (E : Node_Id) return Node_Id;
   --  Runtime routines provided for each AADL thread

   ----------------------
   -- Send_Output_Spec --
   ----------------------

   function Send_Output_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier =>
             Make_Defining_Identifier (SN (S_Send_Output)),
           Parameter_Profile =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => RE (RE_Error_Kind));
111
112
113
114
115
116
117
118
119
120
121

      return N;
   end Send_Output_Spec;

   --------------------
   -- Put_Value_Spec --
   --------------------

   function Put_Value_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Put_Value)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Thread_Interface)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Interface_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => No_Node);
139
140
141
142
143
144
145
146
147
148
149

      return N;
   end Put_Value_Spec;

   ------------------------
   -- Receive_Input_Spec --
   ------------------------

   function Receive_Input_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier =>
             Make_Defining_Identifier (SN (S_Receive_Input)),
           Parameter_Profile =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => No_Node);
168
169
170
171
172
173
174
175
176
177
178

      return N;
   end Receive_Input_Spec;

   --------------------
   -- Get_Value_Spec --
   --------------------

   function Get_Value_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Get_Value)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type =>
             Make_Defining_Identifier (Map_Port_Interface_Name (E)));
197
198
199
200
201
202
203
204
205
206
207

      return N;
   end Get_Value_Spec;

   ---------------------
   -- Get_Sender_Spec --
   ---------------------

   function Get_Sender_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Get_Sender)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => RE (RE_Entity_Type));
225
226
227
228
229
230
231
232
233
234
235

      return N;
   end Get_Sender_Spec;

   --------------------
   -- Get_Count_Spec --
   --------------------

   function Get_Count_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Get_Count)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => RE (RE_Integer));
253
254
255
256
257
258
259
260
261
262
263

      return N;
   end Get_Count_Spec;

   -------------------------
   -- Get_Time_Stamp_Spec --
   -------------------------

   function Get_Time_Stamp_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier =>
             Make_Defining_Identifier (SN (S_Get_Time_Stamp)),
           Parameter_Profile =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => RE (RE_Time));
282
283
284
285
286
287
288
289
290
291
292

      return N;
   end Get_Time_Stamp_Spec;

   ---------------------
   -- Next_Value_Spec --
   ---------------------

   function Next_Value_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier => Make_Defining_Identifier (SN (S_Next_Value)),
           Parameter_Profile   =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_In)),
           Return_Type => No_Node);
310
311
312
313
314
315
316
317
318
319
320

      return N;
   end Next_Value_Spec;

   ---------------------------------
   -- Store_Received_Message_Spec --
   ---------------------------------

   function Store_Received_Message_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier =>
             Make_Defining_Identifier (SN (S_Store_Received_Message)),
           Parameter_Profile =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Thread_Interface)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Interface_Name (E)),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_From)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Time_Stamp)),
                   Subtype_Mark   => RE (RE_Time),
                   Parameter_Mode => Mode_In,
                   Expression     => RE (RE_Clock))),
           Return_Type => No_Node);
350
351
352
353
354
355
356
357
358
359
360

      return N;
   end Store_Received_Message_Spec;

   -----------------------------------
   -- Wait_For_Incoming_Events_Spec --
   -----------------------------------

   function Wait_For_Incoming_Events_Spec (E : Node_Id) return Node_Id is
      N : Node_Id;
   begin
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
      N :=
        Make_Subprogram_Specification
          (Defining_Identifier =>
             Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)),
           Parameter_Profile =>
             Make_List_Id
               (Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Entity)),
                   Subtype_Mark   => RE (RE_Entity_Type),
                   Parameter_Mode => Mode_In),
                Make_Parameter_Specification
                  (Defining_Identifier =>
                     Make_Defining_Identifier (PN (P_Port)),
                   Subtype_Mark =>
                     Make_Defining_Identifier (Map_Port_Enumeration_Name (E)),
                   Parameter_Mode => Mode_Out)),
           Return_Type => No_Node);
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
      return N;
   end Wait_For_Incoming_Events_Spec;

   ------------------
   -- Package_Spec --
   ------------------

   package body Package_Spec is

      procedure Visit_Architecture_Instance (E : Node_Id);
      procedure Visit_Component_Instance (E : Node_Id);
      procedure Visit_System_Instance (E : Node_Id);
      procedure Visit_Process_Instance (E : Node_Id);
      procedure Visit_Thread_Instance (E : Node_Id);
      procedure Visit_Device_Instance (E : Node_Id);

      procedure Cyclic_Task_Instantiation_Formals
        (E      : Node_Id;
         P_List : List_Id);
      --  Appends the formal generic parameter association which are
      --  common between periodic and sporadic tasks.

      function Periodic_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a periodic task

      function Sporadic_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a sporadic task

      function Aperiodic_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for an aperiodic task

      function Hybrid_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a hybrid task

      function Background_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a background task

416
417
418
      function Null_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a null task

yoogx's avatar
yoogx committed
419
420
421
      function ISR_Task_Instantiation (E : Node_Id) return Node_Id;
      --  Build a package instantiation for a background task

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
      function Task_Job_Spec (E : Node_Id) return Node_Id;
      --  Creates the parameterless subprogram specification that does
      --  the thread's job.

      procedure Runtime_Routine_Specs (E : Node_Id);
      --  Creates the specs of all the routines provided by the runtime
      --  to the user-code to manipulate thread interface.

      function Make_Mode_Updater_Spec (E : Node_Id) return Node_Id;
      --  Create the procedure which will update the current mode

      function Make_Modes_Enumeration (E : Node_Id) return Node_Id;
      --  Create the mode enumeration

      ---------------------------------------
      -- Cyclic_Task_Instantiation_Formals --
      ---------------------------------------

      procedure Cyclic_Task_Instantiation_Formals
        (E      : Node_Id;
         P_List : List_Id)
      is
         N : Node_Id;
         I : Unsigned_Long_Long;
         T : Time_Type;

      begin
         --  The entity name

451
452
453
454
         N :=
           Make_Parameter_Association
             (Selector_Name    => Make_Defining_Identifier (PN (P_Entity)),
              Actual_Parameter => Extract_Enumerator (E));
455
456
457
458
459
         Append_Node_To_List (N, P_List);

         if Get_Thread_Dispatch_Protocol (E) = Thread_Periodic
           or else Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic
           or else Get_Thread_Dispatch_Protocol (E) = Thread_Hybrid
yoogx's avatar
yoogx committed
460
           or else Get_Thread_Dispatch_Protocol (E) = Thread_ISR
461
462
463
         then
            --  The task period of minimal interarrival time

464
465
466
467
468
            N :=
              Make_Parameter_Association
                (Selector_Name =>
                   Make_Defining_Identifier (PN (P_Task_Period)),
                 Actual_Parameter => Map_Ada_Time (Get_Thread_Period (E)));
469
470
471
472
473
474
            Append_Node_To_List (N, P_List);

            --  The task deadline

            N := Map_Ada_Time (Get_Thread_Deadline (E));

475
476
477
478
479
            N :=
              Make_Parameter_Association
                (Selector_Name =>
                   Make_Defining_Identifier (PN (P_Task_Deadline)),
                 Actual_Parameter => N);
480
481
482
483
484
485
486
487
            Append_Node_To_List (N, P_List);
         end if;

         if Get_Thread_Dispatch_Protocol (E) = Thread_Periodic then
            --  The dispatch offset
            T := Get_Dispatch_Offset (E);

            if T /= Null_Time then
488
489
490
491
492
               N :=
                 Make_Parameter_Association
                   (Selector_Name =>
                      Make_Defining_Identifier (PN (P_Dispatch_Offset)),
                    Actual_Parameter => Map_Ada_Time (T));
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
               Append_Node_To_List (N, P_List);
            end if;
         end if;

         --  The task priority, if the thread has no priority, we
         --  assign a default one.

         I := Get_Thread_Priority (E);

         if I = 0 then
            N := RE (RE_Default_Priority);
         else
            N := Map_Ada_Priority (I);
         end if;

508
509
510
511
         N :=
           Make_Parameter_Association
             (Selector_Name => Make_Defining_Identifier (PN (P_Task_Priority)),
              Actual_Parameter => N);
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
         Append_Node_To_List (N, P_List);

         --  The task stack size, if the thread has no stack size, we
         --  assign a default one.

         I := To_Bytes (Get_Thread_Stack_Size (E));

         if I = 0 then
            --  The default stack size is 100 Kb

            N := Make_Literal (New_Integer_Value (100_000, 1, 10));
         else
            N := Make_Literal (New_Integer_Value (I, 1, 10));
         end if;

527
528
529
530
531
         N :=
           Make_Parameter_Association
             (Selector_Name =>
                Make_Defining_Identifier (PN (P_Task_Stack_Size)),
              Actual_Parameter => N);
532
533
534
535
         Append_Node_To_List (N, P_List);

         --  The task job

536
537
538
539
         N :=
           Make_Parameter_Association
             (Selector_Name    => Make_Defining_Identifier (PN (P_Job)),
              Actual_Parameter => Map_Task_Job_Identifier (E));
540
541
         Append_Node_To_List (N, P_List);

542
         --  If an activate entrypoint has been specified for the
543
544
545
         --  thread, add an additional parameter association

         declare
546
547
            Activate_Entrypoint : constant Name_Id :=
              Get_Thread_Activate_Entrypoint (E);
548
         begin
549
550
            if Activate_Entrypoint /= No_Name then
               --  We cannot use direcly the activate entrypoint
551
552
553
554
               --  because the Activity spec must not depend on user
               --  package specs (to avoid introducing elaboration
               --  cycles). We use subprogram renaming as workaround.

555
556
557
558
559
               N :=
                 Make_Subprogram_Specification
                   (Defining_Identifier => Map_Task_Init_Identifier (E),
                    Parameter_Profile   => No_List,
                    Return_Type         => No_Node);
560
561
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

562
563
564
565
566
               N :=
                 Make_Parameter_Association
                   (Selector_Name =>
                      Make_Defining_Identifier (PN (P_Activate_Entrypoint)),
                    Actual_Parameter => Map_Task_Init_Identifier (E));
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
               Append_Node_To_List (N, P_List);
            end if;
         end;

         --  If a recover entrypoint has been specified for the
         --  thread, add an additional parameter association

         declare
            Rec_Entrypoint : constant Name_Id :=
              Get_Thread_Recover_Entrypoint (E);
         begin
            if Rec_Entrypoint /= No_Name then
               --  We cannot use direcly the recover entrypoint
               --  because the Activity spec must not depend on user
               --  package specs (to avoid introducing elaboration
               --  cycles). We use subprogram renaminng as workaround.

584
585
586
587
588
               N :=
                 Make_Subprogram_Specification
                   (Defining_Identifier => Map_Task_Recover_Identifier (E),
                    Parameter_Profile   => No_List,
                    Return_Type         => No_Node);
589
590
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

591
592
593
594
595
               N :=
                 Make_Parameter_Association
                   (Selector_Name =>
                      Make_Defining_Identifier (PN (P_Recover_Entrypoint)),
                    Actual_Parameter => Map_Task_Recover_Identifier (E));
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
               Append_Node_To_List (N, P_List);
            end if;
         end;
      end Cyclic_Task_Instantiation_Formals;

      ---------------------------------
      -- Periodic_Task_Instantiation --
      ---------------------------------

      function Periodic_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id :=
           New_List (ADN.K_Parameter_Profile);
      begin
         --  Build the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  Build the package instantiation

616
617
618
619
620
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_Periodic_Task),
              Parameter_List      => Parameter_List);
621
622
623
624
625
626
627
628
629
630
631
632
633
         return N;
      end Periodic_Task_Instantiation;

      ---------------------------------
      -- Sporadic_Task_Instantiation --
      ---------------------------------

      function Sporadic_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
      begin
         --  Port_Type

634
635
636
637
638
         N :=
           Make_Parameter_Association
             (Selector_Name    => Make_Defining_Identifier (TN (T_Port_Type)),
              Actual_Parameter =>
                Make_Defining_Identifier (Map_Port_Enumeration_Name (E)));
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
         Append_Node_To_List (N, Parameter_List);

         --  Raise an error if the thread does not have IN ports

         if not Has_In_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "This sporadic thread does not have IN ports",
               Fatal => True);
         end if;

         --  Raise an error if the thread does not have 'in event'
         --  ports.

         if not Has_In_Event_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "None of the IN ports of this sporadic thread is an event port",
               Fatal => True);
         end if;

         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  The blocking routine

666
667
668
669
670
671
         N :=
           Make_Parameter_Association
             (Selector_Name =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)),
              Actual_Parameter =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)));
672
673
674
675
         Append_Node_To_List (N, Parameter_List);

         --  Build the package instantiation

676
677
678
679
680
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_Sporadic_Task),
              Parameter_List      => Parameter_List);
681
682
683
684
685
686
687
688
689
690
691
692
693
         return N;
      end Sporadic_Task_Instantiation;

      ----------------------------------
      -- Aperiodic_Task_Instantiation --
      ----------------------------------

      function Aperiodic_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
      begin
         --  Port_Type

694
695
696
697
698
         N :=
           Make_Parameter_Association
             (Selector_Name    => Make_Defining_Identifier (TN (T_Port_Type)),
              Actual_Parameter =>
                Make_Defining_Identifier (Map_Port_Enumeration_Name (E)));
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
         Append_Node_To_List (N, Parameter_List);

         --  Raise an error if the thread does not have IN ports

         if not Has_In_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "This sporadic thread does not have IN ports",
               Fatal => True);
         end if;

         --  Raise an error if the thread has no 'in event' ports

         if not Has_In_Event_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "None of the IN ports of this thread is an event port",
               Fatal => True);
         end if;

         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  The blocking routine

725
726
727
728
729
730
         N :=
           Make_Parameter_Association
             (Selector_Name =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)),
              Actual_Parameter =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)));
731
732
733
734
         Append_Node_To_List (N, Parameter_List);

         --  Build the package instantiation

735
736
737
738
739
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_Aperiodic_Task),
              Parameter_List      => Parameter_List);
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
         return N;
      end Aperiodic_Task_Instantiation;

      -----------------------------------
      -- Background_Task_Instantiation --
      -----------------------------------

      function Background_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
      begin
         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  Build the package instantiation

757
758
759
760
761
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_Background_Task),
              Parameter_List      => Parameter_List);
762
763
764
         return N;
      end Background_Task_Instantiation;

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
      -----------------------------
      -- Null_Task_Instantiation --
      -----------------------------

      function Null_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
      begin
         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  Build the package instantiation

         N := Make_Package_Instantiation
           (Defining_Identifier => Map_Task_Identifier (E),
            Generic_Package     => RU (RU_PolyORB_HI_Null_Task),
            Parameter_List      => Parameter_List);
         return N;
      end Null_Task_Instantiation;

yoogx's avatar
yoogx committed
786
787
788
789
790
791
792
      ----------------------------
      -- ISR_Task_Instantiation --
      ----------------------------

      function ISR_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
793
         Configuration  : Name_Id;
yoogx's avatar
yoogx committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
      begin
         Configuration := Get_Configuration (E);
         if Configuration = No_Name then
            Display_Located_Error
              (Loc (E),
               "No interrupt configured",
               Fatal => True);
         end if;

         N := Make_Withed_Package (RU (RU_Ada_Interrupts_Names));
         Append_Node_To_List (N, ADN.Withed_Packages (Current_Package));
         N := Make_Used_Package (RU (RU_Ada_Interrupts_Names));
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

808
809
810
811
812
813
         N :=
           Make_Parameter_Association
             (Selector_Name =>
                Make_Defining_Identifier (PN (P_Interrupt_Identifier)),
              Actual_Parameter =>
                Make_Defining_Identifier (Get_Configuration (E)));
yoogx's avatar
yoogx committed
814
815
816
817
818
819
820
821
         Append_Node_To_List (N, Parameter_List);

         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  Build the package instantiation

822
823
824
825
826
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_ISR_Task),
              Parameter_List      => Parameter_List);
yoogx's avatar
yoogx committed
827
828
829
         return N;
      end ISR_Task_Instantiation;

830
831
832
833
834
835
836
837
838
839
      -------------------------------
      -- Hybrid_Task_Instantiation --
      -------------------------------

      function Hybrid_Task_Instantiation (E : Node_Id) return Node_Id is
         N              : Node_Id;
         Parameter_List : constant List_Id := New_List (ADN.K_List_Id);
      begin
         --  Port_Type

840
841
842
843
844
         N :=
           Make_Parameter_Association
             (Selector_Name    => Make_Defining_Identifier (TN (T_Port_Type)),
              Actual_Parameter =>
                Make_Defining_Identifier (Map_Port_Enumeration_Name (E)));
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
         Append_Node_To_List (N, Parameter_List);

         --  Raise an error if the thread does not have IN ports

         if not Has_In_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "This hybrid thread does not have IN ports",
               Fatal => True);
         end if;

         --  Raise an error if the thread does not have 'in event'
         --  ports.

         if not Has_In_Event_Ports (E) then
            Display_Located_Error
              (Loc (E),
               "None of the IN ports of this hybrid thread is an event port",
               Fatal => True);
         end if;

         --  Append the common parameters

         Cyclic_Task_Instantiation_Formals (E, Parameter_List);

         --  The blocking routine

872
873
874
875
876
877
         N :=
           Make_Parameter_Association
             (Selector_Name =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)),
              Actual_Parameter =>
                Make_Defining_Identifier (SN (S_Wait_For_Incoming_Events)));
878
879
880
881
         Append_Node_To_List (N, Parameter_List);

         --  Build the package instantiation

882
883
884
885
886
         N :=
           Make_Package_Instantiation
             (Defining_Identifier => Map_Task_Identifier (E),
              Generic_Package     => RU (RU_PolyORB_HI_Hybrid_Task),
              Parameter_List      => Parameter_List);
887
888
889
890
891
892
893
894
895
         return N;
      end Hybrid_Task_Instantiation;

      -------------------
      -- Task_Job_Spec --
      -------------------

      function Task_Job_Spec (E : Node_Id) return Node_Id is
         N          : Node_Id;
896
         Param_List : List_Id                                     := No_List;
897
898
899
900
901
902
903
         P          : constant Supported_Thread_Dispatch_Protocol :=
           Get_Thread_Dispatch_Protocol (E);
      begin
         if P = Thread_Sporadic
           or else P = Thread_Hybrid
           or else P = Thread_Aperiodic
         then
904
905
906
907
908
            N :=
              Make_Parameter_Specification
                (Defining_Identifier => Make_Defining_Identifier (PN (P_Port)),
                 Subtype_Mark        =>
                   Make_Defining_Identifier (Map_Port_Enumeration_Name (E)));
909
910
911
912

            Param_List := Make_List_Id (N);
         end if;

913
914
915
916
917
         N :=
           Make_Subprogram_Specification
             (Defining_Identifier => Map_Task_Job_Identifier (E),
              Parameter_Profile   => Param_List,
              Return_Type         => RE (RE_Error_Kind));
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
         return N;
      end Task_Job_Spec;

      ---------------------------
      -- Runtime_Routine_Specs --
      ---------------------------

      procedure Runtime_Routine_Specs (E : Node_Id) is
         N : Node_Id;
      begin
         --  Send_Output

         N := Send_Output_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Put_Value

         N := Put_Value_Spec (E);
         Bind_AADL_To_Put_Value (Identifier (E), N);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Receive_Input

         N := Receive_Input_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Get_Value

         N := Get_Value_Spec (E);
         Bind_AADL_To_Get_Value (Identifier (E), N);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Get_Sender

         N := Get_Sender_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Get_Count

         N := Get_Count_Spec (E);
         Bind_AADL_To_Get_Count (Identifier (E), N);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Get_Time_Stamp

         N := Get_Time_Stamp_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Next_Value

         N := Next_Value_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         N := Store_Received_Message_Spec (E);
         Bind_AADL_To_Store_Received_Message (Identifier (E), N);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         --  Wait_For_Incoming_Events

         N := Wait_For_Incoming_Events_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
      end Runtime_Routine_Specs;

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

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

            when K_Component_Instance =>
               Visit_Component_Instance (E);

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

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

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

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

      procedure Visit_Component_Instance (E : Node_Id) is
1013
1014
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
      begin
         case Category is
            when CC_System =>
               Visit_System_Instance (E);

            when CC_Process =>
               Visit_Process_Instance (E);

            when CC_Thread =>
               Visit_Thread_Instance (E);

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

      ----------------------------
      -- Visit_Process_Instance --
      ----------------------------

      procedure Visit_Process_Instance (E : Node_Id) is
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
         U : constant Node_Id :=
           ADN.Distributed_Application_Unit
             (ADN.Deployment_Node (Backend_Node (Identifier (E))));
         P                   : constant Node_Id := ADN.Entity (U);
         S                   : Node_Id;
         N                   : Node_Id;
         Scheduling_Protocol : constant Supported_Scheduling_Protocol :=
           Get_Scheduling_Protocol (Get_Bound_Processor (E));
         The_System : constant Node_Id :=
           Parent_Component (Parent_Subcomponent (E));
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
      begin
         Push_Entity (P);
         Push_Entity (U);
         Set_Activity_Spec;

         --  Start recording the handling since they have to be reset
         --  for each node.

         Start_Recording_Handlings;

         if Scheduling_Protocol = Unknown_Scheduler then
            Display_Located_Error
1058
              (Loc (Get_Bound_Processor (E)),
1059
1060
1061
1062
               "Undefined scheduling protocol, " &
               "will use FIFO_WITHIN_PRIORITIES",
               Fatal   => False,
               Warning => True);
1063
1064
1065

         elsif Scheduling_Protocol
           /= POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL
1066
           and then Scheduling_Protocol /= ROUND_ROBIN_PROTOCOL
1067
1068
1069
1070
         then
            Display_Located_Error
              (Loc (Parent_Subcomponent (E)),
               "Incompatible scheduling protocol, "
1071
1072
1073
1074
                 & "PolyORB-HI/Ada runtime requires "
                 & "POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL or"
                 & " ROUND_ROBIN_PROTOCOL",
               Fatal => True);
1075
1076
1077

            --  XXX In case of Round robin, we should also check that
            --  the scheduler is set to non-preemptive mode.
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
         end if;

         --  Visit all the subcomponents of the process

         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));

            while Present (S) loop
               --  If the process has a data subcomponent, then map a
               --  shared variable.

               if AINU.Is_Data (Corresponding_Instance (S)) then
1090
1091
1092
1093
1094
1095
                  N :=
                    Make_Object_Declaration
                      (Defining_Identifier => Map_Ada_Defining_Identifier (S),
                       Object_Definition   =>
                         Map_Ada_Data_Type_Designator
                           (Corresponding_Instance (S)));
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

                  --  Link the variable and the object

                  Bind_AADL_To_Object (Identifier (S), N);
               else
                  --  Visit the component instance corresponding to the
                  --  subcomponent S.

                  Visit (Corresponding_Instance (S));
               end if;

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

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

         if not AAU.Is_Empty (Subcomponents (The_System)) then
            S := First_Node (Subcomponents (The_System));
            while Present (S) loop
               if AAU.Is_Device (Corresponding_Instance (S))
1119
1120
1121
                 and then
                   Get_Bound_Processor (Corresponding_Instance (S)) =
                   Get_Bound_Processor (E)
1122
               then
1123
                  Visit_Device_Instance (Corresponding_Instance (S));
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
               end if;
               S := Next_Node (S);
            end loop;
         end if;

         --  Unmark all the marked types

         Reset_Handlings;

         Pop_Entity; -- U
         Pop_Entity; -- P
      end Visit_Process_Instance;

      ---------------------------
      -- Visit_Device_Instance --
      ---------------------------

      procedure Visit_Device_Instance (E : Node_Id) is
1142
1143
         Implementation : constant Node_Id := Get_Implementation (E);
         S              : Node_Id;
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
      begin
         if Implementation /= No_Node then
            if not AAU.Is_Empty (AAN.Subcomponents (Implementation)) then
               S := First_Node (Subcomponents (Implementation));
               while Present (S) loop
                  Visit_Component_Instance (Corresponding_Instance (S));
                  S := Next_Node (S);
               end loop;
            end if;
         end if;
      end Visit_Device_Instance;

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

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

         --  Visit all the subcomponents of the system

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

               Visit (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         Pop_Entity; --  Ada_Root
      end Visit_System_Instance;

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

      procedure Visit_Thread_Instance (E : Node_Id) is
         P : constant Supported_Thread_Dispatch_Protocol :=
           Get_Thread_Dispatch_Protocol (E);
         S : constant Node_Id := Parent_Subcomponent (E);
         N : Node_Id;
         O : Node_Id;
1191
1192
1193
1194
1195
1196
1197
         Scheduling_Protocol : constant Supported_Scheduling_Protocol
           := Get_Scheduling_Protocol
           (Get_Bound_Processor
              (Corresponding_Instance
                 (Get_Container_Process
                    (Parent_Subcomponent (E)))));

1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
      begin
         if Has_Ports (E) then
            --  The data types and the interrogation routines
            --  generated from a thread are not instance specific. We
            --  generate them once per thread component. This allows
            --  us to support having multiple instances of the same
            --  thread in the model. Multiple thread instances of the
            --  same component share the same generated entities. This
            --  avoids having instance-specific code inside compute
            --  entrypoints.

1209
1210
            if No
                (Get_Handling
1211
1212
1213
1214
                   (Corresponding_Declaration (E),
                    By_Node,
                    H_Ada_Activity_Interr_Spec))
            then
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
               Set_Handling
                 (Corresponding_Declaration (E),
                  By_Node,
                  H_Ada_Activity_Interr_Spec,
                  E);

               N :=
                 Message_Comment
                   ("BEGIN: Entities used by all instances of component " &
                    Get_Name_String (Display_Name (Identifier (E))));
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

               --  Declare the enumeration type gathering all the
               --  thread ports.

               N := Map_Port_Enumeration (E);
               Bind_AADL_To_Port_Enumeration (Identifier (E), N);
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

               --  Declare the thread interface discriminated record type

               N := Map_Port_Interface (E);
               Bind_AADL_To_Port_Interface (Identifier (E), N);
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

               --  Declare the routines that allow user code to
               --  manipulate the thread.

               Runtime_Routine_Specs (E);

1245
1246
1247
1248
               N :=
                 Message_Comment
                   ("END: Entities used by all instances of component " &
                    Get_Name_String (Display_Name (Identifier (E))));
1249
1250
1251
1252
1253
1254
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            else
               --  We bind the entities generated for the found
               --  instance to be able to reference them later.

               declare
1255
1256
1257
1258
1259
1260
                  Found : constant Node_Id :=
                    Get_Handling
                      (Corresponding_Declaration (E),
                       By_Node,
                       H_Ada_Activity_Interr_Spec);
                  BE : constant Node_Id := Backend_Node (Identifier (Found));
1261
1262
               begin
                  Bind_AADL_To_Port_Enumeration
1263
1264
                    (Identifier (E),
                     ADN.Port_Enumeration_Node (BE));
1265
                  Bind_AADL_To_Port_Interface
1266
1267
                    (Identifier (E),
                     ADN.Port_Interface_Node (BE));
1268
                  Bind_AADL_To_Put_Value
1269
1270
                    (Identifier (E),
                     ADN.Put_Value_Node (BE));
1271
                  Bind_AADL_To_Get_Value
1272
1273
                    (Identifier (E),
                     ADN.Get_Value_Node (BE));
1274
                  Bind_AADL_To_Get_Count
1275
1276
                    (Identifier (E),
                     ADN.Get_Count_Node (BE));
1277
                  Bind_AADL_To_Store_Received_Message
1278
1279
                    (Identifier (E),
                     ADN.Store_Received_Message_Node (BE));
1280
1281
1282
1283
1284
1285
               end;
            end if;
         end if;

         case P is
            when Thread_Periodic =>
yoogx's avatar
yoogx committed
1286
<<<<<<< HEAD
1287
1288
               N := Message_Comment
                 ("Periodic task : "
1289
                    & Get_Name_String (Display_Name (Identifier (S))));
1290
1291
1292
1293
1294
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Sporadic =>
               N := Message_Comment
                 ("Sporadic task : "
1295
                    & Get_Name_String (Display_Name (Identifier (S))));
1296
1297
1298
1299
1300
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Hybrid =>
               N := Message_Comment
                 ("Hybrid task : "
1301
                    & Get_Name_String (Display_Name (Identifier (S))));
1302
1303
1304
1305
1306
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Aperiodic =>
               N := Message_Comment
                 ("Aperiodic task : "
1307
                    & Get_Name_String (Display_Name (Identifier (S))));
1308
1309
1310
1311
1312
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Background =>
               N := Message_Comment
                 ("Background task : "
1313
                    & Get_Name_String (Display_Name (Identifier (S))));
1314
1315
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

yoogx's avatar
yoogx committed
1316
1317
1318
            when Thread_ISR =>
               N := Message_Comment
                 ("ISR task : "
1319
                    & Get_Name_String (Display_Name (Identifier (S))));
yoogx's avatar
yoogx committed
1320
=======
1321
1322
1323
1324
               N :=
                 Message_Comment
                   ("Periodic task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
1325
1326
1327
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Sporadic =>
1328
1329
1330
1331
               N :=
                 Message_Comment
                   ("Sporadic task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
1332
1333
1334
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Hybrid =>
1335
1336
1337
1338
               N :=
                 Message_Comment
                   ("Hybrid task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
1339
1340
1341
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Aperiodic =>
1342
1343
1344
1345
               N :=
                 Message_Comment
                   ("Aperiodic task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
1346
1347
1348
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            when Thread_Background =>
1349
1350
1351
1352
               N :=
                 Message_Comment
                   ("Background task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
1353
1354
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

yoogx's avatar
yoogx committed
1355
            when Thread_ISR =>
1356
1357
1358
1359
               N :=
                 Message_Comment
                   ("ISR task : " &
                    Get_Name_String (Display_Name (Identifier (S))));
yoogx's avatar
yoogx committed
1360
>>>>>>> master
yoogx's avatar
yoogx committed
1361
1362
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
            when others =>
               Display_Located_Error
                 (AIN.Loc (E),
                  "Unsupported dispatch protocol",
                  Fatal => True);
         end case;

         --  Create the spec of the parameterless subprogram that
         --  executes the thread job.

         N := Task_Job_Spec (E);
         Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
         Bind_AADL_To_Job (Identifier (S), N);

1377
         --  For each AADL thread, we instantiate a task.
1378

yoogx's avatar
yoogx committed
1379
<<<<<<< HEAD
1380
1381
1382
1383
1384
         if Scheduling_Protocol = POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL
         then
            case P  is
               when Thread_Periodic =>
                  --  Instantiate the periodic task
yoogx's avatar
yoogx committed
1385
=======
1386
         case P is
1387
1388
            when Thread_Periodic =>
               --  Instantiate the periodic task
yoogx's avatar
yoogx committed
1389
>>>>>>> master
1390

1391
1392
                  N := Periodic_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
1393

1394
1395
               when Thread_Sporadic =>
                  --  Instantiate the sporadic task
1396

1397
1398
                  N := Sporadic_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
1399

1400
1401
               when Thread_Hybrid =>
                  --  Instantiate the hybrid task
1402

1403
1404
                  N := Hybrid_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
1405

1406
1407
               when Thread_Aperiodic =>
                  --  Instantiate the aperiodic task
1408

1409
1410
                  N := Aperiodic_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
1411

yoogx's avatar
yoogx committed
1412
<<<<<<< HEAD
1413
1414
               when Thread_Background  =>
                  --  Instantiate the background task
yoogx's avatar
yoogx committed
1415
=======
1416
            when Thread_Background =>
1417
               --  Instantiate the background task
yoogx's avatar
yoogx committed
1418
>>>>>>> master
1419

1420
1421
                  N := Background_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
1422

1423
1424
               when Thread_ISR =>
                  --  Instantiate the ISR task
yoogx's avatar
yoogx committed
1425

1426
1427
                  N := ISR_Task_Instantiation (E);
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
yoogx's avatar
yoogx committed
1428

1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
               when others =>
                  raise Program_Error;
            end case;

         elsif Scheduling_Protocol = ROUND_ROBIN_PROTOCOL then
            N := Null_Task_Instantiation (E);
            Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

         else
            raise Program_Error;
         end if;
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

         if Has_Modes (E) then
            --  If the thread has operational modes, then generate the
            --  enumeration type corresponding to the thread mode list
            --  and the procedure allowing to update the current mode.

            N := Make_Modes_Enumeration (E);
            Append_Node_To_List (N, ADN.Visible_Part (Current_Package));

            if Is_Fusioned (E) then
               N := Make_Mode_Updater_Spec (E);
               Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
            end if;
         end if;

         --  Visit thread local objects

         if not AINU.Is_Empty (Subcomponents (E)) then
            O := First_Node (Subcomponents (E));

            while Present (O) loop
               if AINU.Is_Data (Corresponding_Instance (O)) then
yoogx's avatar
yoogx committed
1462
<<<<<<< HEAD
1463
1464
1465
                  N := Make_Object_Declaration
                    (Defining_Identifier => Map_Ada_Defining_Identifier (O),
                     Object_Definition   => Map_Ada_Data_Type_Designator
1466
1467
1468
                       (Corresponding_Instance (O)));
                  Append_Node_To_List
                    (N, ADN.Visible_Part (Current_Package));
yoogx's avatar
yoogx committed
1469
=======
1470
1471
1472
1473
1474
1475
                  N :=
                    Make_Object_Declaration
                      (Defining_Identifier => Map_Ada_Defining_Identifier (O),
                       Object_Definition   =>
                         Map_Ada_Data_Type_Designator
                           (Corresponding_Instance (O)));
1476
                  Append_Node_To_List (N, ADN.Visible_Part (Current_Package));
yoogx's avatar
yoogx committed
1477
>>>>>>> master
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506

                  --  Link the variable and the object

                  Bind_AADL_To_Object (Identifier (O), N);
               end if;

               O := Next_Node (O);
            end loop;
         end if;
      end Visit_Thread_Instance;

      ----------------------------
      -- Make_Modes_Enumeration --
      ----------------------------

      function Make_Modes_Enumeration (E : Node_Id) return Node_Id is
         Enum_List : constant List_Id := New_List (ADN.K_Enumeration_Literals);
         M         : Node_Id;
         N         : Node_Id;
      begin
         M := First_Node (Modes (E));

         while Present (M) loop
            N := Map_Ada_Defining_Identifier (M);
            Append_Node_To_List (N, Enum_List);

            M := Next_Node (M);
         end loop;

1507
1508
1509
1510
1511
         N :=
           Make_Full_Type_Declaration
             (Defining_Identifier =>
                Make_Defining_Identifier (Map_Modes_Enumeration_Name (E)),
              Type_Definition => Make_Enumeration_Type_Definition (Enum_List));
1512
1513
1514
1515
1516
1517
1518
1519

         return N;
      end Make_Modes_Enumeration;

      ----------------------------
      -- Make_Mode_Updater_Spec --
      ----------------------------

1520
      function Make_Mode_Updater_Spec (E : Node_Id) return Node_Id is
1521
1522
         N : Node_Id;
      begin
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
         N :=
           Make_Subprogram_Specification
             (Defining_Identifier =>
                Make_Defining_Identifier (SN (S_Change_Mode)),
              Parameter_Profile =>
                Make_List_Id
                  (Make_Parameter_Specification
                     (Defining_Identifier =>
                        Make_Defining_Identifier (PN (P_Mode)),
                      Subtype_Mark =>
                        Make_Defining_Identifier
                          (Map_Modes_Enumeration_Name (E)),
                      Parameter_Mode => Mode_In)),
              Return_Type => No_Node);
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
         Set_Backend_Node (Identifier (First_Node (Modes (E))), N);

         return N;
      end Make_Mode_Updater_Spec;

   end Package_Spec;

   ------------------
   -- Package_Body --
   ------------------

   package body Package_Body is

      procedure Visit_Architecture_Instance (E : Node_Id);
      procedure Visit_Component_Instance (E : Node_Id);
      procedure Visit_System_Instance (E : Node_Id);
      procedure Visit_Process_Instance (E : Node_Id);
      procedure Visit_Thread_Instance (E : Node_Id);
      procedure Visit_Device_Instance (E : Node_Id);

      function Task_Job_Body (E : Node_Id) return Node_Id;
      --  Creates the parameterless subprogram body that does the
      --  thread's job.

      procedure Runtime_Routine_Bodies (E : Node_Id);
      --  Creates the implementations of all the routines provided by
      --  the runtime to the user-code to manipulate thread interface.

      function Make_Current_Mode_Declaration (E : Node_Id) return Node_Id;
      --  Create, if necessary, the current mode variable declaration for
      --  thread E.

      function Make_Mode_Updater_body (E : Node_Id) return Node_Id;
      --  Create the procedure which will update the current mode

1572
1573
      Has_Hybrid_Threads       : Boolean            := False;
      Hybrid_Thread_Elements   : List_Id            := No_List;
1574
1575
      Last_Hybrid_Thread_Index : Unsigned_Long_Long := 0;

1576
      Current_Mode_Identifier : Node_Id;
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599

      --  The runtime routines are generated per thread component and
      --  not per thread instance. For each thread instance, we must
      --  complete the case alternative specific to it in each one of
      --  the routines. To perform this, we attache to each thread
      --  component a set of List_Id's which represent the case
      --  statement of the corresponding routines. The entities below
      --  allow to Get/Set these list for each thread component.

      type Runtime_Routine is
        (RR_Send_Output,
         RR_Put_Value,
         RR_Receive_Input,
         RR_Get_Value,
         RR_Get_Sender,
         RR_Get_Count,
         RR_Get_Time_Stamp,
         RR_Next_Value,
         RR_Store_Received_Message,
         RR_Wait_For_Incoming_Events);

      function Get_List_Internal_Name
        (Thread : Node_Id;
1600
         RR     : Runtime_Routine) return Name_Id;
1601
1602
1603
1604
      --  Code factorization between the two subprograms below

      function Get_List
        (Thread : Node_Id;
1605
         RR     : Runtime_Routine) return List_Id;
1606
1607
1608
      --  Return the List_Id corresponding to the runtime routine 'RR'
      --  and associated to 'Thread'.

1609
      procedure Set_List (Thread : Node_Id; RR : Runtime_Routine; L : List_Id);
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
      --  Set a new value (L) to the list corresponding to the runtime
      --  routine 'RR' and associated to 'Thread'.

      Interrogation_Routine_List : List_Id;
      --  This list will hold all the bodies declarations of the
      --  interrogation routines. We do this to ensure all the bodies
      --  are appended after all entities generated for threads since
      --  they need visibility on these entities.

      -------------------
      -- Task_Job_Body --
      -------------------

      function Task_Job_Body (E : Node_Id) return Node_Id is
1624
1625
1626
         S    : constant Node_Id := Parent_Subcomponent (E);
         Spec : constant Node_Id :=
           ADN.Job_Node (Backend_Node (Identifier (S)));
1627
1628
1629
1630
         Declarations : constant List_Id := New_List (ADN.K_Declaration_List);
         Statements   : constant List_Id := New_List (ADN.K_Statement_List);
         P            : constant Supported_Thread_Dispatch_Protocol :=
           Get_Thread_Dispatch_Protocol (E);
1631
         Impl_Kind : constant Supported_Thread_Implementation :=
1632
1633
1634
           Get_Thread_Implementation_Kind (E);
         Need_Error_Initialization : Boolean := True;

1635
         function Get_Fully_Qualified_Subprogram (S : Name_Id) return Node_Id;
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
         --  Return an identifier to S whose parent unit name is the
         --  instantiated package correspodning to the interface of E.

         function Make_Get_Valid_Value (F : Node_Id) return Node_Id;
         --  This function generated an If statement that tests
         --  whether the port ever received a value. In this case, it
         --  returns tha last received value. Otherwithe, it return
         --  the default value for the port data type.

         --------------------------------------------------------------
         -- All routines below do NOT perfom any verification on the --
         -- thread and rely completely on the good faith of their    --
         -- caller.                                                  --
         --------------------------------------------------------------

         procedure Make_Mode_Update;
         --  Generate a case statement that updates the thread mode
         --  depending on the received event port. The event port that
         --  causes the mode switch is dequeued.

         procedure Make_Fetch_In_Ports;
         --  Generate the routines to fetch the values of the thread
         --  IN ports in a non-blocking way.

         procedure Make_Fetch_In_Ports
1661
           (Statements   : List_Id;
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
            Declarations : List_Id);
         --  Generate the routines to fetch the values of the thread
         --  IN ports in a non-blocking way, puting the result in
         --  the parameters.

         procedure Make_Dequeue_In_Ports;
         --  Generate the routines to dequeue the oldest values of the
         --  thread IN ports in a non-blocking way.

         procedure Make_Dequeue_In_Ports
1672
           (Statements   : List_Id;
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
            Declarations : List_Id);
         --  Generate the routines to dequeue the oldest values of the
         --  thread IN ports in a non-blocking way, puting the results
         --  in the parameters.

         procedure Make_Call_Sequence (CS : Node_Id := No_Node);
         --  Generate code relying on the thread call sequence

         procedure Make_Thread_Compute_Entrypoint;
         --  Generate code relying on the thread's own compute
         --  entrypoint.

         procedure Make_Ports_Compute_Entrypoint;
         --  Generate code relying on the compute entrypoints of the
         --  thread ports.

         procedure Make_Set_Call_Sequence_Out_Ports
           (CS         : Node_Id;
            Statements : List_Id);
         --  Generate the routines to set the values of the thread OUT
         --  ports used by the call sequence CS.

         procedure Make_Send_Call_Sequence_Out_Ports
           (CS         : Node_Id;
            Statements : List_Id);
         --  Generate the routines to send the values of the thread
         --  OUT ports from teh call sequence CS.

         procedure Make_Set_Out_Ports;
         --  Generate the routines to set the values of the thread
         --  OUT ports.

         procedure Make_Send_Out_Ports;
         --  Generate the routines to send the values of the thread
         --  OUT ports.

         procedure Create_Call_Sequence
           (Stats : List_Id;
            Decl  : List_Id;
            CS    : Node_Id := No_Node;
            Port  : Node_Id := No_Node);

         ------------------------------------
         -- Get_Fully_Qualified_Subprogram --
         ------------------------------------

         function Get_Fully_Qualified_Subprogram
1720
           (S : Name_Id) return Node_Id
1721
         is
1722
1723
            P : constant Node_Id :=
              Make_Defining_Identifier (Map_Interrogators_Name (E));
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
            N : constant Node_Id := Make_Defining_Identifier (S);
         begin
            Set_Homogeneous_Parent_Unit_Name (N, P);

            return N;
         end Get_Fully_Qualified_Subprogram;

         --------------------------
         -- Make_Get_Valid_Value --
         --------------------------

         function Make_Get_Valid_Value (F : Node_Id) return Node_Id is
            Then_Statements : constant List_Id :=
              New_List (ADN.K_Statement_List);
            Else_Statements : constant List_Id :=
              New_List (ADN.K_Statement_List);
            Condition : Node_Id;
            N         : Node_Id;
         begin
            --  The condition of validity is that the return value of
            --  Get_Count is different from -1.

1746
1747
1748
1749
            N :=
              Make_Subprogram_Call
                (Get_Fully_Qualified_Subprogram (SN (S_Get_Count)),
                 Make_List_Id (Map_Ada_Defining_Identifier (F)));
1750

1751
1752
1753
1754
1755
            Condition :=
              Make_Expression
                (N,
                 Op_Not_Equal,
                 Make_Literal (New_Integer_Value (1, -1, 10)));
1756
1757
1758

            --  Then

1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
            N :=
              Make_Selected_Component
                (Make_Subprogram_Call
                   (Get_Fully_Qualified_Subprogram (SN (S_Get_Value)),
                    Make_List_Id (Map_Ada_Defining_Identifier (F))),
                 Make_Defining_Identifier (Map_Ada_Component_Name (F)));

            N :=
              Make_Assignment_Statement
                (Map_Ada_Defining_Identifier (F, "V"),
                 N);
1770
1771
1772
1773
            Append_Node_To_List (N, Then_Statements);

            --  Else

1774
1775
1776
1777
            N :=
              Extract_Designator
                (ADN.Default_Value_Node
                   (Backend_Node (Identifier (Corresponding_Instance (F)))));
1778

1779
1780
1781
1782
            N :=
              Make_Assignment_Statement
                (Map_Ada_Defining_Identifier (F, "V"),
                 N);
1783
1784
            Append_Node_To_List (N, Else_Statements);

1785
1786
1787
1788
1789
            N :=
              Make_If_Statement
                (Condition       => Condition,
                 Then_Statements => Then_Statements,
                 Else_Statements => Else_Statements);
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
            return N;
         end Make_Get_Valid_Value;

         ----------------------
         -- Make_Mode_Update --
         ----------------------

         procedure Make_Mode_Update is
            Alternatives       : constant List_Id := New_List (ADN.K_List_Id);
            Inner_Alternatives : List_Id;
            Choices            : List_Id;
            Inner_Statements   : List_Id;
            F                  : Node_Id;
            N                  : Node_Id;
            M                  : Node_Id;
            Src                : Node_Id;

            function Belongs (F : Node_Id; L : List_Id) return Boolean;
            --  Return True IFF F is referenced by one of the entity
            --  reference instances of list L.

            -------------
            -- Belongs --
            -------------

            function Belongs (F : Node_Id; L : List_Id) return Boolean is
               Ref : Node_Id;
            begin
               Ref := First_Node (L);

               while Present (Ref) loop
                  if F = Item (Last_Node (Path (Ref))) then
                     return True;
                  end if;

                  Ref := Next_Node (Ref);
               end loop;

               return False;
            end Belongs;

         begin
            --  If no mode transition description is given, we do not
            --  have to generate anything

1835
            if AINU.Is_Empty (Mode_transitions (E)) then
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
               return;
            end if;

            --  FIXME: Taking account of port urgency should NOT be
            --  implemented here but in the event delivery routine
            --  (thread interrogators).

            --  If the thread is sporadic, we already got the value of
            --  the port that triggered the thread. If the thread is
            --  sporadic, we read the value of the oldest triggered
            --  event port.

            if P = Thread_Periodic then
               --  Declare the Port and Valid variables

1851
1852
1853
1854
1855
1856
1857
               N :=
                 Make_Object_Declaration
                   (Defining_Identifier =>
                      Make_Defining_Identifier (PN (P_Port)),
                    Object_Definition =>
                      Make_Defining_Identifier
                        (Map_Port_Enumeration_Name (E)));
1858
1859
               Append_Node_To_List (N, Declarations);

1860
1861
1862
1863
1864
               N :=
                 Make_Object_Declaration
                   (Defining_Identifier =>
                      Make_Defining_Identifier (PN (P_Valid)),
                    Object_Definition => RE (RE_Boolean));
1865
1866
1867
1868
               Append_Node_To_List (N, Declarations);

               --  Call Get_Next_Event

1869
               N := Make_Defining_Identifier (SN (S_Get_Next_Event));
1870
1871
1872
1873
               Set_Homogeneous_Parent_Unit_Name
                 (N,
                  Make_Defining_Identifier (Map_Interrogators_Name (E)));