ocarina-backends-pok_c-main.adb 66.4 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 K _ C . M A I N           --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2014 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
--                                                                          --
------------------------------------------------------------------------------

34
with Ocarina.Namet;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Properties;
with Ocarina.Backends.C_Values;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.POK_C.Runtime;
with Ocarina.Backends.C_Common.Mapping;

with Ocarina.Instances.Queries;

package body Ocarina.Backends.POK_C.Main is

52
   use Ocarina.Namet;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.C_Values;
   use Ocarina.Backends.C_Tree.Nutils;
   use Ocarina.Backends.POK_C.Runtime;
   use Ocarina.Backends.C_Common.Mapping;

   use Ocarina.Instances.Queries;

   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 CV renames Ocarina.Backends.C_Values;

   -----------------
   -- Source_File --
   -----------------

   package body Source_File is

78
79
80
81
82
      Tattr                 : Node_Id;
      Main_Function         : Node_Id;
      Statements            : List_Id;
      Init_Function         : Node_Id            := No_Node;
      Thread_Id             : Unsigned_Long_Long := 0;
83
84
85
86
87
88
89
90
91
92
93
94
95
      Process_Variable_Type : Node_Id;
      Process_Variable_Name : Node_Id;

      Error_Switch_Alternatives : List_Id;

      Use_Error_Handling : Boolean := False;

      Current_Device : Node_Id := No_Node;

      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
96
97
98
        (E                       : Node_Id;
         Real_Process            : Boolean := True;
         Corresponding_Component : Node_Id := No_Node);
99
100
101
102
103
104
105
106
107
108
      procedure Visit_Device_Instance (E : Node_Id);
      procedure Visit_Processor_Instance (E : Node_Id);
      procedure Visit_Virtual_Processor_Instance (E : Node_Id);
      procedure Visit_Thread_Instance (E : Node_Id);

      procedure Setup_Thread (E : Node_Id);

      function Map_Queueing_Policy (Port : Node_Id) return Node_Id;

      function Map_Queueing_Policy (Port : Node_Id) return Node_Id is
109
110
         ARINC653_Discipline : constant ARINC653_Queuing_Discipline :=
           Get_ARINC653_Queuing_Discipline (Port);
111
      begin
112
113
114
         if ARINC653_Discipline /= Invalid
           and then ARINC653_Discipline = Priority_Based
         then
115

Julien's avatar
Julien committed
116
            if Use_ARINC653_API then
117
118
119
120
121
122
               return RE (RE_Priority);
            else
               return RE (RE_Pok_Port_Queueing_Discipline_Fifo);
            end if;
         end if;

Julien's avatar
Julien committed
123
         if Use_ARINC653_API then
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
            return RE (RE_Fifo);
         else
            return RE (RE_Pok_Port_Queueing_Discipline_Fifo);
         end if;
      end Map_Queueing_Policy;

      ------------------
      -- Setup_Thread --
      ------------------

      procedure Setup_Thread (E : Node_Id) is
         Parameters   : List_Id;
         N            : Node_Id;
         S            : constant Node_Id := Parent_Subcomponent (E);
         Member_Value : Node_Id;
139
         Stack_Size   : Unsigned_Long_Long;
140
141
      begin
         --  Initializes thread attributes.
142
         if Use_ARINC653_API = False then
143
144
145
146
            N :=
              POK_Make_Function_Call_With_Assert
                (RF (RE_Pok_Thread_Attr_Init),
                 Make_List_Id (Make_Variable_Address (Copy_Node (Tattr))));
147
148
149
150
151
152
153
154

            Append_Node_To_List (N, Statements);

            POK_Add_Return_Assertion (Statements);
         end if;

         --  Make tattr.entry = entrypoint

Julien's avatar
Julien committed
155
         if Use_ARINC653_API then
156
157
158
159
            N :=
              Make_Expression
                (Left_Expr =>
                   Make_Member_Designator
160
                     (RE (RE_Entry_Point),
161
162
163
164
                      Copy_Node (Tattr)),
                 Operator   => Op_Equal,
                 Right_Expr =>
                   Copy_Node
165
                     (CTN.Defining_Identifier
166
                        (CTN.Job_Node (Backend_Node (Identifier (S))))));
167
168

         else
169
170
171
172
173
174
175
            N :=
              Make_Expression
                (Left_Expr =>
                   Make_Member_Designator (RE (RE_Entry), Copy_Node (Tattr)),
                 Operator   => Op_Equal,
                 Right_Expr =>
                   Copy_Node
176
                     (CTN.Defining_Identifier
177
                        (CTN.Job_Node (Backend_Node (Identifier (S))))));
178
179
180
181
182
183
184
         end if;

         Append_Node_To_List (N, Statements);

         --  Add priority to tattr, tattr.priority = threadpriority

         if Get_Thread_Priority (E) /= 0 then
185
            N := Make_Literal (New_Int_Value (Get_Thread_Priority (E), 1, 10));
186

Julien's avatar
Julien committed
187
            if Use_ARINC653_API then
188
189
190
191
               N :=
                 Make_Expression
                   (Left_Expr =>
                      Make_Member_Designator
192
                        (RE (RE_Base_Priority),
193
194
195
                         Copy_Node (Tattr)),
                    Operator   => Op_Equal,
                    Right_Expr => N);
196
            else
197
198
199
200
               N :=
                 Make_Expression
                   (Left_Expr =>
                      Make_Member_Designator
201
                        (Make_Defining_Identifier (MN (M_Priority)),
202
203
204
                         Copy_Node (Tattr)),
                    Operator   => Op_Equal,
                    Right_Expr => N);
205
206
207
208
209
210
            end if;

            Append_Node_To_List (N, Statements);
         end if;

         if Get_Thread_Deadline (E) /= Null_Time then
Julien's avatar
Julien committed
211
            if POK_Flavor = ARINC653 then
212
213
               Member_Value :=
                 Map_Time_To_Millisecond (Get_Thread_Deadline (E));
Julien's avatar
Julien committed
214
            elsif POK_Flavor = POK then
215
               Member_Value := Map_Time (Get_Thread_Deadline (E));
Julien's avatar
Julien committed
216
217
            else
               Member_Value := No_Node;
218
219
            end if;

Julien's avatar
Julien committed
220
221
222
223
224
225
226
227
228
229
230
            if Member_Value /= No_Node then
               N :=
                 Make_Expression
                   (Left_Expr =>
                      Make_Member_Designator
                        (RE (RE_Deadline),
                         Copy_Node (Tattr)),
                    Operator   => Op_Equal,
                    Right_Expr => Member_Value);
               Append_Node_To_List (N, Statements);
            end if;
231
232
233
234
235
         else
            Display_Error ("Deadline not specified", Fatal => False);
         end if;

         if Get_Thread_Period (E) /= Null_Time then
236
            if Use_ARINC653_API then
Julien's avatar
Julien committed
237
238
239
240
241
242
243
               if POK_Flavor = POK then
                  Member_Value := Map_Time_To_Millisecond
                                    (Get_Thread_Period (E));
               elsif POK_Flavor = DEOS then
                  Member_Value := Map_Time_To_Nanosecond
                                    (Get_Thread_Period (E));
               end if;
244
245
246
247
            else
               Member_Value := Map_Time (Get_Thread_Period (E));
            end if;

Julien's avatar
Julien committed
248
249
250
251
252
253
254
255
            if Member_Value /= No_Node then
               N :=
                 Make_Expression
                   (Left_Expr =>
                      Make_Member_Designator
                        (RE (RE_Period), Copy_Node (Tattr)),
                    Operator   => Op_Equal,
                    Right_Expr => Member_Value);
256

Julien's avatar
Julien committed
257
258
               Append_Node_To_List (N, Statements);
            end if;
259
260
261
262
         else
            Display_Error ("Period not specified", Fatal => True);
         end if;

263
264
265
266
267
268
         --
         --  Set up the Stack Size
         --  On most system, the default is 4096. So, we set
         --  up 4096 if not explicitly declared. We use
         --  The AADL property Stack_Size if declared.
         --
269

270
271
272
273
         Stack_Size := 4096;

         if Get_Thread_Stack_Size (E) /= Null_Size then
            Stack_Size := To_Bytes (Get_Thread_Stack_Size (E));
274
         end if;
275
276
277
278
279
280
281
282
283
284
285
286
287
         N :=
           Make_Expression
             (Left_Expr =>
                Make_Member_Designator
                  (RE (RE_Stack_Size),
                   Copy_Node (Tattr)),
              Operator   => Op_Equal,
              Right_Expr =>
                Make_Literal
                  (New_Int_Value (Stack_Size,
                                 1,
                                 10)));
         Append_Node_To_List (N, Statements);
288
289

         declare
290
            TA       : constant Time_Array := Get_Execution_Time (E);
291
292
293
            Capacity : Node_Id;
         begin
            if TA /= Empty_Time_Array then
294
               if Use_ARINC653_API then
Julien's avatar
Julien committed
295
296
297
298
299
300
301
                  if POK_Flavor = ARINC653 then
                     Capacity := Map_Time_To_Millisecond (TA (1));
                  elsif POK_Flavor = DEOS then
                     Capacity := Map_Time_To_Nanosecond (TA (1));
                  else
                     Capacity := No_Node;
                  end if;
302
303
304
305
306
               else
                  Capacity := Map_Time (TA (1));
               end if;
            else
               Display_Error
307
308
                 ("Compute execution time not declared",
                  Fatal => False);
309
310

               --  By default, we allocate 1 ms for thread execution.
311
312
               Capacity :=
                 CTU.Make_Literal (CV.New_Int_Value (Thread_Id, 1, 10));
313
            end if;
314

315
316
317
318
            N :=
              Make_Expression
                (Left_Expr =>
                   Make_Member_Designator
319
                     (RE (RE_Time_Capacity),
320
321
322
                      Copy_Node (Tattr)),
                 Operator   => Op_Equal,
                 Right_Expr => Capacity);
323

324
            Append_Node_To_List (N, Statements);
325
326
327
328
329
330
331
         end;

         --  Add tid and other stuff to the parameters and call
         --  pok_thread_create

         Parameters := New_List (CTN.K_Parameter_List);

332
         if Use_ARINC653_API then
333
334
335
336
337
338
339
340
341
342
            Append_Node_To_List
              (Make_Variable_Address (Copy_Node (Tattr)),
               Parameters);

            Append_Node_To_List
              (Make_Variable_Address
                 (Make_Array_Value
                    (Copy_Node (Process_Variable_Name),
                     CTU.Make_Literal (CV.New_Int_Value (Thread_Id, 1, 10)))),
               Parameters);
343
344
            Add_Return_Variable_In_Parameters (Parameters);
         else
345
346
347
348
349
350
            Append_Node_To_List
              (Make_Variable_Address
                 (Make_Array_Value
                    (Copy_Node (Process_Variable_Name),
                     CTU.Make_Literal (CV.New_Int_Value (Thread_Id, 1, 10)))),
               Parameters);
351

352
353
354
            Append_Node_To_List
              (Make_Variable_Address (Copy_Node (Tattr)),
               Parameters);
355
356
357

         end if;

Julien's avatar
Julien committed
358
         if Use_ARINC653_API then
359
            Append_Node_To_List
360
361
362
              (POK_Make_Function_Call_With_Assert
                 (RF (RE_Create_Process),
                  Parameters),
363
               Statements);
jhugues's avatar
jhugues committed
364
            Parameters := New_List (CTN.K_Parameter_List);
365
366
367
368
369
            Append_Node_To_List
              (Make_Array_Value
                 (Copy_Node (Process_Variable_Name),
                  CTU.Make_Literal (CV.New_Int_Value (Thread_Id, 1, 10))),
               Parameters);
jhugues's avatar
jhugues committed
370
            Add_Return_Variable_In_Parameters (Parameters);
371
            Append_Node_To_List
372
              (POK_Make_Function_Call_With_Assert (RF (RE_Start), Parameters),
373
               Statements);
374
375
         else
            Append_Node_To_List
376
377
378
              (POK_Make_Function_Call_With_Assert
                 (RF (RE_Pok_Thread_Create),
                  Parameters),
379
380
381
               Statements);
         end if;

382
383
384
385
386
         N :=
           Message_Comment
             ("This thread was mapped from a thread component contained" &
              "in this process. The function it executes is also generated" &
              "in the file activity.c.");
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

         POK_Add_Return_Assertion (Statements);

         CTU.Append_Node_To_List (N, Statements);
      end Setup_Thread;

      -----------
      -- 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
425
426
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
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
      begin
         case Category is
            when CC_System =>
               Visit_System_Instance (E);

            when CC_Process =>
               Visit_Process_Instance (E);

            when CC_Device =>
               Visit_Device_Instance (E);

            when CC_Processor =>
               Visit_Processor_Instance (E);

            when CC_Virtual_Processor =>
               Visit_Virtual_Processor_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
457
458
459
        (E                       : Node_Id;
         Real_Process            : Boolean := True;
         Corresponding_Component : Node_Id := No_Node)
460
      is
461
462
463
464
465
466
467
468
469
470
471
472
473
474
         U                : Node_Id;
         P                : Node_Id;
         N                : Node_Id;
         S                : Node_Id;
         Spec             : Node_Id;
         Declarations     : List_Id := New_List (CTN.K_Declaration_List);
         Call_Parameters  : List_Id;
         Called_Function  : Node_Id;
         Used_Type        : Node_Id;
         Used_Member      : Node_Id;
         While_Statements : constant List_Id :=
           New_List (CTN.K_Statement_List);
         Shared_Data             : Node_Id;
         Function_Call           : Node_Id;
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
         Communicating_Component : Node_Id;

         procedure Setup_In_Ports;
         procedure Setup_Out_Ports;

         --------------------
         -- Setup_In_Ports --
         --------------------

         procedure Setup_In_Ports is
            F               : Node_Id;
            Called_Function : Node_Id;
            Added_Parameter : Node_Id;
            Variable_Type   : Node_Id;
         begin
            if AINU.Is_Empty (Features (Communicating_Component)) then
               return;
            end if;

            F := First_Node (Features (Communicating_Component));

            while Present (F) loop
               Call_Parameters := New_List (CTN.K_Parameter_List);

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
               if Kind (F) = K_Port_Spec_Instance
                 and then Is_In (F)
                 and then not Is_Out (F)
                 and then Get_Connection_Pattern (F) = Inter_Process
                 and then not Is_Virtual (Get_Port_By_Name (F, Current_Device))
               then
                  if AIN.Is_Data (F) and then Is_Event (F) then
                     Append_Node_To_List
                       (Make_Literal
                          (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
                        Call_Parameters);

                     if POK_Flavor = POK then
                        N := Map_Queue_Size_With_Data (F);
                        Append_Node_To_List (N, Call_Parameters);
                     else

                        --  Map the size

                        N := Get_Data_Size (Corresponding_Instance (F));

                        Append_Node_To_List (N, Call_Parameters);

                        --  Map the queue size

                        N := Map_Queue_Size (F);
                        Append_Node_To_List (N, Call_Parameters);
                     end if;

528
                     if Use_ARINC653_API then
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
                        Added_Parameter := RE (RE_Destination);
                     else
                        Added_Parameter := RE (RE_Pok_Port_Direction_In);
                     end if;

                     Append_Node_To_List (Added_Parameter, Call_Parameters);

                     Added_Parameter := Map_Queueing_Policy (F);

                     Append_Node_To_List (Added_Parameter, Call_Parameters);

                     Append_Node_To_List
                       (Make_Variable_Address
                          (Make_Defining_Identifier (Map_Port_Var (F))),
                        Call_Parameters);

545
                     if Use_ARINC653_API then
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
                        Append_Node_To_List
                          (Make_Variable_Address
                             (Make_Defining_Identifier (VN (V_Ret))),
                           Call_Parameters);

                        Called_Function := RF (RE_Create_Queuing_Port);
                     else
                        Called_Function := RF (RE_Pok_Port_Queueing_Create);
                     end if;

                     Append_Node_To_List
                       (POK_Make_Function_Call_With_Assert
                          (Called_Function,
                           Call_Parameters),
                        Statements);

                     POK_Add_Return_Assertion (Statements);

564
                     if Use_ARINC653_API then
565
566
567
568
569
570
571
572
573
574
575
576
577
578
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
                        Variable_Type := RE (RE_Queuing_Port_Id_Type);
                     else
                        Variable_Type := RE (RE_Uint8_T);
                     end if;

                     Append_Node_To_List
                       (Make_Variable_Declaration
                          (Defining_Identifier =>
                             (Make_Defining_Identifier (Map_Port_Var (F))),
                           Used_Type => Variable_Type),
                        CTN.Declarations (Current_File));

                     N :=
                       Message_Comment
                         ("This queueing port was mapped from an in" &
                          "event data port contained in the process. It" &
                          "is used for inter-partition communication.");

                     CTU.Append_Node_To_List (N, Statements);
                  elsif AIN.Is_Data (F) and then not Is_Event (F) then
                     Append_Node_To_List
                       (Make_Literal
                          (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
                        Call_Parameters);

                     if Current_Device = No_Node then
                        N := Get_Inter_Partition_Port_Size (F);

                        if Is_Using_Virtual_Bus (F) then
                           Add_Include (RH (RH_Protocols));
                           Add_Define_Deployment (RE (RE_Pok_Needs_Protocols));
                        end if;
                     else
                        N :=
                          Get_Inter_Partition_Port_Size
                            (Get_Port_By_Name (F, Current_Device));

                        if Is_Using_Virtual_Bus
                            (Get_Port_By_Name (F, Current_Device))
                        then
                           Add_Include (RH (RH_Protocols));
                           Add_Define_Deployment (RE (RE_Pok_Needs_Protocols));
                        end if;
                     end if;

                     Append_Node_To_List (N, Call_Parameters);

                     --  Map the port of the sampling port, take in
                     --  account potential virtual bus layers.

615
                     if Use_ARINC653_API then
616
617
618
619
620
621
622
623
624
625
                        Append_Node_To_List
                          (RE (RE_Destination),
                           Call_Parameters);
                     else
                        Append_Node_To_List
                          (RE (RE_Pok_Port_Direction_In),
                           Call_Parameters);
                     end if;

                     if Get_POK_Refresh_Time (F) /= Null_Time then
626
                        if Use_ARINC653_API then
627
628
629
630
631
632
633
634
                           N :=
                             Map_Time_To_Millisecond
                               (Get_POK_Refresh_Time (F));
                        else
                           N := Map_Time (Get_POK_Refresh_Time (F));
                        end if;
                     else
                        N := CTU.Make_Literal (CV.New_Int_Value (0, 1, 10));
635
                     end if;
636
637
638
639
640
641
642
                     Append_Node_To_List (N, Call_Parameters);

                     Append_Node_To_List
                       (Make_Variable_Address
                          (Make_Defining_Identifier (Map_Port_Var (F))),
                        Call_Parameters);

643
                     if Use_ARINC653_API then
644
645
646
647
648
649
650
651
652
653
654
655
656
657
                        Add_Return_Variable_In_Parameters (Call_Parameters);
                        Called_Function := RF (RE_Create_Sampling_Port);
                     else
                        Called_Function := RF (RE_Pok_Port_Sampling_Create);
                     end if;

                     Append_Node_To_List
                       (POK_Make_Function_Call_With_Assert
                          (Called_Function,
                           Call_Parameters),
                        Statements);

                     POK_Add_Return_Assertion (Statements);

658
                     if Use_ARINC653_API then
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
                        Variable_Type := RE (RE_Sampling_Port_Id_Type);
                     else
                        Variable_Type := RE (RE_Uint8_T);
                     end if;

                     Append_Node_To_List
                       (Make_Variable_Declaration
                          (Defining_Identifier =>
                             (Make_Defining_Identifier (Map_Port_Var (F))),
                           Used_Type => (Variable_Type)),
                        CTN.Declarations (Current_File));

                     N :=
                       Message_Comment
                         ("This sampling port was mapped from a in data" &
                          "port contained in the process. It is used" &
                          "for inter-partition communication.");

                     CTU.Append_Node_To_List (N, Statements);
                  end if;
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
               end if;
               F := Next_Node (F);
            end loop;
         end Setup_In_Ports;

         ---------------------
         -- Setup_Out_Ports --
         ---------------------

         procedure Setup_Out_Ports is
            F               : Node_Id;
            Called_Function : Node_Id;
            Added_Parameter : Node_Id;
            Variable_Type   : Node_Id;
         begin

            Error_Switch_Alternatives := New_List (CTN.K_Alternatives_List);

            if AINU.Is_Empty (Features (Communicating_Component)) then
               return;
            end if;

            F := First_Node (Features (Communicating_Component));

            while Present (F) loop

               Call_Parameters := New_List (CTN.K_Parameter_List);

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
               if Kind (F) = K_Port_Spec_Instance
                 and then Is_Out (F)
                 and then not Is_In (F)
                 and then Get_Connection_Pattern (F) = Inter_Process
                 and then not Is_Virtual (Get_Port_By_Name (F, Current_Device))
               then
                  if AIN.Is_Data (F) and then not Is_Event (F) then
                     Append_Node_To_List
                       (Make_Literal
                          (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
                        Call_Parameters);

                     if Current_Device = No_Node then
                        N := Get_Inter_Partition_Port_Size (F);

                        if Is_Using_Virtual_Bus (F) then
                           Add_Include (RH (RH_Protocols));
                           Add_Define_Deployment (RE (RE_Pok_Needs_Protocols));
                        end if;
                     else
                        N :=
                          Get_Inter_Partition_Port_Size
                            (Get_Port_By_Name (F, Current_Device));

                        if Is_Using_Virtual_Bus
                            (Get_Port_By_Name (F, Current_Device))
                        then
                           Add_Include (RH (RH_Protocols));
                           Add_Define_Deployment (RE (RE_Pok_Needs_Protocols));
                        end if;
                     end if;

                     Append_Node_To_List (N, Call_Parameters);

                     --  Map the size of the port, take in account
                     --  potential virtual bus layers.

744
                     if Use_ARINC653_API then
745
746
747
748
749
750
751
752
753
                        Append_Node_To_List (RE (RE_Source), Call_Parameters);
                     else
                        Append_Node_To_List
                          (RE (RE_Pok_Port_Direction_Out),
                           Call_Parameters);
                     end if;

                     if Get_POK_Refresh_Time (F) /= Null_Time then

754
                        if Use_ARINC653_API then
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
                           N :=
                             Map_Time_To_Millisecond
                               (Get_POK_Refresh_Time (F));
                        else
                           N := Map_Time (Get_POK_Refresh_Time (F));
                        end if;

                     else
                        N := CTU.Make_Literal (CV.New_Int_Value (0, 1, 10));
                     end if;

                     Append_Node_To_List (N, Call_Parameters);

                     Append_Node_To_List
                       (Make_Variable_Address
                          (Make_Defining_Identifier (Map_Port_Var (F))),
                        Call_Parameters);

773
                     if Use_ARINC653_API then
774
775
776
777
778
779
780
781
782
783
784
785
786
787
                        Add_Return_Variable_In_Parameters (Call_Parameters);
                        Called_Function := RF (RE_Create_Sampling_Port);
                     else
                        Called_Function := RF (RE_Pok_Port_Sampling_Create);
                     end if;

                     N :=
                       POK_Make_Function_Call_With_Assert
                         (Called_Function,
                          Call_Parameters);
                     Append_Node_To_List (N, Statements);

                     POK_Add_Return_Assertion (Statements);

788
                     if Use_ARINC653_API then
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
                        Variable_Type := RE (RE_Sampling_Port_Id_Type);
                     else
                        Variable_Type := RE (RE_Uint8_T);
                     end if;

                     Append_Node_To_List
                       (Make_Variable_Declaration
                          (Defining_Identifier =>
                             (Make_Defining_Identifier (Map_Port_Var (F))),
                           Used_Type => (Variable_Type)),
                        CTN.Declarations (Current_File));

                     N :=
                       Message_Comment
                         ("This sampling port was mapped from an out" &
                          "data port contained in the process. It is" &
                          "used for inter-partition communication.");

                     CTU.Append_Node_To_List (N, Statements);
                  elsif AIN.Is_Data (F) and then Is_Event (F) then
                     Append_Node_To_List
                       (Make_Literal
                          (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
                        Call_Parameters);

                     if POK_Flavor = POK then
                        N := Map_Queue_Size_With_Data (F);
                        Append_Node_To_List (N, Call_Parameters);
                     else
                        --  Map the size

                        N := Get_Data_Size (Corresponding_Instance (F));

                        Append_Node_To_List (N, Call_Parameters);

                        --  Map the queue size

                        N := Map_Queue_Size (F);
                        Append_Node_To_List (N, Call_Parameters);
                     end if;

830
                     if Use_ARINC653_API then
831
832
833
                        Added_Parameter := RE (RE_Source);
                     else
                        Added_Parameter := RE (RE_Pok_Port_Direction_Out);
834
                     end if;
835
836
837
838
839
840
841
842
843
844
845
846

                     Append_Node_To_List (Added_Parameter, Call_Parameters);

                     Added_Parameter := Map_Queueing_Policy (F);

                     Append_Node_To_List (Added_Parameter, Call_Parameters);

                     Append_Node_To_List
                       (Make_Variable_Address
                          (Make_Defining_Identifier (Map_Port_Var (F))),
                        Call_Parameters);

847
                     if Use_ARINC653_API then
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
                        Add_Return_Variable_In_Parameters (Call_Parameters);

                        Called_Function := RF (RE_Create_Queuing_Port);
                     else
                        Called_Function := RF (RE_Pok_Port_Queueing_Create);
                     end if;

                     N :=
                       POK_Make_Function_Call_With_Assert
                         (Called_Function,
                          Call_Parameters);

                     Append_Node_To_List (N, Statements);

                     POK_Add_Return_Assertion (Statements);

864
                     if Use_ARINC653_API then
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
                        Variable_Type := RE (RE_Queuing_Port_Id_Type);
                     else
                        Variable_Type := RE (RE_Uint8_T);
                     end if;

                     Append_Node_To_List
                       (Make_Variable_Declaration
                          (Defining_Identifier =>
                             (Make_Defining_Identifier (Map_Port_Var (F))),
                           Used_Type => (Variable_Type)),
                        CTN.Declarations (Current_File));

                     N :=
                       Message_Comment
                         ("This queueing port was mapped from an out " &
                          "event data port contained in the process. It" &
                          "is used for inter-partition communication.");

                     CTU.Append_Node_To_List (N, Statements);
                  end if;
885
886
887
888
889
890
891
892
893
894
               end if;
               F := Next_Node (F);
            end loop;
         end Setup_Out_Ports;

         -------------------------
         -- Setup_Virtual_Ports --
         -------------------------

         procedure Setup_Virtual_Ports is
895
            F : Node_Id;
896
897
898
899
900
901
902
903
904
905
906
907
         begin
            Call_Parameters := New_List (CTN.K_Parameter_List);

            if AINU.Is_Empty (Features (Communicating_Component)) then
               return;
            end if;

            F := First_Node (Features (Communicating_Component));

            while Present (F) loop
               Call_Parameters := New_List (CTN.K_Parameter_List);

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
               if Kind (F) = K_Port_Spec_Instance
                 and then Is_Data (F)
                 and then Get_Connection_Pattern (F) = Inter_Process
                 and then Is_Virtual (Get_Port_By_Name (F, Current_Device))
               then
                  Append_Node_To_List
                    (Make_Literal
                       (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
                     Call_Parameters);

                  Append_Node_To_List
                    (Make_Variable_Address
                       (Make_Defining_Identifier (Map_Port_Var (F))),
                     Call_Parameters);

                  N :=
                    Make_Call_Profile
                      (RF (RE_Pok_Port_Virtual_Create),
                       Call_Parameters);
                  Append_Node_To_List (N, Statements);

                  Append_Node_To_List
                    (Make_Variable_Declaration
                       (Defining_Identifier =>
                          (Make_Defining_Identifier (Map_Port_Var (F))),
                        Used_Type => RE (RE_Uint8_T)),
                     CTN.Declarations (Current_File));
935
936
937
938
939
940
941
               end if;
               F := Next_Node (F);
            end loop;
         end Setup_Virtual_Ports;

      begin
         if Real_Process then
942
943
944
            U :=
              CTN.Distributed_Application_Unit
                (CTN.Naming_Node (Backend_Node (Identifier (E))));
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
            P := CTN.Entity (U);

            Push_Entity (P);
            Push_Entity (U);

            Communicating_Component := E;
         else
            Communicating_Component := Corresponding_Component;
         end if;

         Set_Main_Source;

         Use_Error_Handling := False;

         Thread_Id := 1;

         Statements := New_List (CTN.K_Statement_List);

963
         Add_Include (E => RH (RH_Activity));
964

965
         if Use_ARINC653_API then
966
967
968
969
970
971
972
973
974
            Process_Variable_Type := RE (RE_Process_Id_Type);
            Process_Variable_Name := RE (RE_Arinc_Threads);
         else
            Process_Variable_Type := RE (RE_Uint32_T);
            Process_Variable_Name := RE (RE_Pok_Threads);
         end if;

         --  Set up ports of the partition
         Append_Node_To_List
975
976
977
978
           (Make_Variable_Declaration
              (CTU.Make_Array_Declaration
                 (Defining_Identifier => Process_Variable_Name,
                  Array_Size          => RE (RE_Pok_Config_Nb_Threads)),
979
980
981
982
983
984
               Used_Type => Process_Variable_Type),
            CTN.Declarations (Current_File));

         Set_Str_To_Name_Buffer ("tattr");
         Tattr := Make_Defining_Identifier (Name_Find);

985
         if Use_ARINC653_API then
986
987
988
989
            N :=
              Make_Variable_Declaration
                (Defining_Identifier => Copy_Node (Tattr),
                 Used_Type           => RE (RE_Process_Attribute_Type));
990
         else
991
992
993
994
            N :=
              Make_Variable_Declaration
                (Defining_Identifier => Copy_Node (Tattr),
                 Used_Type           => RE (RE_Pok_Thread_Attr_T));
995
996
997
998
999
1000
         end if;

         --  Declare the variable that contain
         --  tasks/process attributes.

         Append_Node_To_List (N, Statements);
For faster browsing, not all history is shown. View entire blame