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

34
35
with Namet; use Namet;

36
37
38
39
40
41
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.MAST_Tree.Nodes;
with Ocarina.Backends.MAST_Tree.Nutils;
julien.delange's avatar
julien.delange committed
42
with Ocarina.Backends.MAST_Values;
julien.delange's avatar
julien.delange committed
43
44
with Ocarina.Backends.Properties;
with Ocarina.Backends.Utils;
45
46
47
48
49
50
51

package body Ocarina.Backends.MAST.Main is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.MAST_Tree.Nutils;
julien.delange's avatar
julien.delange committed
52
53
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.Properties;
julien.delange's avatar
julien.delange committed
54
   use Ocarina.Backends.MAST_Values;
55

julien.delange's avatar
julien.delange committed
56
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
57
58
59
60
61
62
63
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package MTN renames Ocarina.Backends.MAST_Tree.Nodes;
   package MTU renames Ocarina.Backends.MAST_Tree.Nutils;

   procedure Visit_Component (E : Node_Id);
   procedure Visit_System (E : Node_Id);
   procedure Visit_Processor (E : Node_Id);
julien.delange's avatar
julien.delange committed
64
65
   procedure Visit_Process (E : Node_Id);
   procedure Visit_Thread (E : Node_Id);
julien.delange's avatar
julien.delange committed
66
   procedure Visit_Subprogram (E : Node_Id);
67
   procedure Visit_Bus (E : Node_Id);
68
69
   procedure Visit_Data (E : Node_Id);
   procedure Visit_Device (E : Node_Id);
70
71
   procedure Visit_Virtual_Processor (E : Node_Id);

72
73
   function Map_Port_Operation_Name (The_Thread : Node_Id; The_Port : Node_Id)
      return Name_Id;
74
75
76
77
78
79
   function Map_Driver_Receive_Operation_Name (The_Device : Node_Id)
      return Name_Id;
   function Map_Driver_Send_Operation_Name (The_Device : Node_Id)
      return Name_Id;
   function Map_Driver_Scheduling_Server_Name (The_Device : Node_Id)
      return Name_Id;
80
   function Map_Scheduler_Name (The_Processor : Node_Id) return Name_Id;
81
82
83
84
   function Map_Port_Shared_Resource_Name (The_Port : Node_Id)
      return Name_Id;
   function Map_Port_Shared_Resource_Operation_Name (The_Port : Node_Id)
      return Name_Id;
85

86
   function Make_Driver_Wrapper (The_Device : Node_Id) return Node_Id;
87
88
89
   function Map_Operation_Message_Transmission_Name
      (The_Data : Node_Id)
      return Name_Id;
90

91
92
   Root_System_Node                 : Node_Id := No_Node;

93
94
95
96
   ------------------------
   -- Map_Scheduler_Name --
   ------------------------

97
98
99
100
101
102
103
104
105
106
107
108
109
   function Map_Scheduler_Name (The_Processor : Node_Id) return Name_Id is
      N : Name_Id;
   begin
      Get_Name_String
         (Normalize_Name
          (Name
           (Identifier
            (Parent_Subcomponent (The_Processor)))));
      Add_Str_To_Name_Buffer ("_scheduler");
      N := Name_Find;
      return N;
   end Map_Scheduler_Name;

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
   ---------------------------------------------
   -- Map_Operation_Message_Transmission_Name --
   ---------------------------------------------

   function Map_Operation_Message_Transmission_Name (The_Data : Node_Id)
      return Name_Id
   is
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String
         (Normalize_Name
            (Name
               (Identifier
                  (The_Data))));
      Add_Str_To_Name_Buffer ("_transmission_operation");
      N := Name_Find;
      return N;
   end Map_Operation_Message_Transmission_Name;

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
   -----------------------------------
   -- Map_Port_Shared_Resource_Name --
   -----------------------------------

   function Map_Port_Shared_Resource_Name
      (The_Port : Node_Id)
      return Name_Id
   is
      Port_Name : Name_Id;
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Port_Name :=
         (Normalize_Name (Name (Identifier (The_Port))));
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Port_Name);
      Add_Str_To_Name_Buffer ("_shared_resource");
      N := Name_Find;
      return N;
   end Map_Port_Shared_Resource_Name;

   ---------------------------------------------
   -- Map_Port_Shared_Resource_Operation_Name --
   ---------------------------------------------

   function Map_Port_Shared_Resource_Operation_Name
      (The_Port : Node_Id)
      return Name_Id
   is
      Port_Name : Name_Id;
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Port_Name :=
         (Normalize_Name (Name (Identifier (The_Port))));
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Port_Name);
      Add_Str_To_Name_Buffer ("_shared_resource_operation");
      N := Name_Find;
      return N;
   end Map_Port_Shared_Resource_Operation_Name;

172
173
174
175
176
177
178
   -----------------------------
   -- Map_Port_Operation_Name --
   -----------------------------

   function Map_Port_Operation_Name (The_Thread : Node_Id; The_Port : Node_Id)
      return Name_Id
   is
179
180
181
      Thread_Name : Name_Id;
      Port_Name   : Name_Id;
      N : Name_Id;
182
183
   begin
      Set_Str_To_Name_Buffer ("");
184
185
186
187
188
189
      Thread_Name :=
         (Normalize_Name
            (Name
               (Identifier
                  (Parent_Subcomponent (The_Thread)))));
      Port_Name :=
190
         (Normalize_Name (Name (Identifier (The_Port))));
191
192
193
194
195
196
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Port_Name);
      Add_Str_To_Name_Buffer ("_port_");
      Get_Name_String_And_Append (Thread_Name);
      N := Name_Find;
      return N;
197
198
   end Map_Port_Operation_Name;

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
   ------------------------------------
   -- Map_Driver_Send_Operation_Name --
   ------------------------------------

   function Map_Driver_Send_Operation_Name (The_Device : Node_Id)
      return Name_Id is
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String
         (Normalize_Name
            (Name (Identifier (Parent_Subcomponent (The_Device)))));
      Add_Str_To_Name_Buffer ("_operation_send");
      N := Name_Find;
      return N;
   end Map_Driver_Send_Operation_Name;

   ---------------------------------------
   -- Map_Driver_Receive_Operation_Name --
   ---------------------------------------

   function Map_Driver_Receive_Operation_Name (The_Device : Node_Id)
      return Name_Id is
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String
         (Normalize_Name
            (Name (Identifier (Parent_Subcomponent (The_Device)))));
      Add_Str_To_Name_Buffer ("_operation_receive");
      N := Name_Find;
      return N;
   end Map_Driver_Receive_Operation_Name;

   ---------------------------------------
   -- Map_Driver_Scheduling_Server_Name --
   ---------------------------------------

   function Map_Driver_Scheduling_Server_Name (The_Device : Node_Id)
      return Name_Id is
      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer ("");
      Get_Name_String
         (Normalize_Name
            (Name (Identifier (Parent_Subcomponent (The_Device)))));
      Add_Str_To_Name_Buffer ("_scheduling_server");
      N := Name_Find;
      return N;
   end Map_Driver_Scheduling_Server_Name;

250
251
252
   -------------------------
   -- Make_Driver_Wrapper --
   -------------------------
253
254
255
256
257
258
259

   function Make_Driver_Wrapper (The_Device : Node_Id) return Node_Id is
      M : Node_Id;
      New_Drv : Node_Id;
   begin
      M := Make_Scheduling_Server
         (Map_Driver_Scheduling_Server_Name (The_Device),
jhugues's avatar
jhugues committed
260
261
262
263
264
265
266
267
268
          No_Name);
      if Present (Get_Bound_Processor (The_Device)) then
         MTN.Set_Associated_Scheduler
           (M, Map_Scheduler_Name (Get_Bound_Processor (The_Device)));
      else
         --  XXX this is the sign of an incomplete model for MAST ?
         MTN.Set_Associated_Scheduler (M, No_Name);
      end if;

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
      MTN.Set_Parameters
         (M, Make_Scheduling_Server_Parameters
          (Fixed_Priority, 1));

      MTU.Append_Node_To_List (M, MTN.Declarations (MAST_File));

      M := Make_Operation
         (Map_Driver_Send_Operation_Name (The_Device), Simple, No_List);
      MTU.Append_Node_To_List (M, MTN.Declarations (MAST_File));

      M := Make_Operation
         (Map_Driver_Receive_Operation_Name (The_Device), Simple, No_List);
      MTU.Append_Node_To_List (M, MTN.Declarations (MAST_File));

      New_Drv := MTU.Make_Driver
         (Normalize_Name
            (Name
               (Identifier (Parent_Subcomponent (The_Device)))),
         Packet,
         Map_Driver_Scheduling_Server_Name (The_Device),
         Map_Driver_Send_Operation_Name (The_Device),
         Map_Driver_Receive_Operation_Name (The_Device),
         False,
         Coupled);
      return New_Drv;
   end Make_Driver_Wrapper;

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
   -----------
   -- Visit --
   -----------

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

         when K_Component_Instance =>
            Visit_Component (E);

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

   ---------------------
   -- Visit_Component --
   ---------------------

   procedure Visit_Component (E : Node_Id) is
      Category : constant Component_Category
        := Get_Category_Of_Component (E);
   begin
      case Category is
         when CC_System =>
            Visit_System (E);

         when CC_Processor =>
            Visit_Processor (E);

julien.delange's avatar
julien.delange committed
330
331
332
         when CC_Subprogram =>
            Visit_Subprogram (E);

julien.delange's avatar
julien.delange committed
333
334
335
         when CC_Process =>
            Visit_Process (E);

336
337
338
339
340
341
         when CC_Data =>
            Visit_Data (E);

         when CC_Device =>
            Visit_Device (E);

julien.delange's avatar
julien.delange committed
342
343
344
         when CC_Thread =>
            Visit_Thread (E);

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
         when CC_Bus =>
            Visit_Bus (E);

         when CC_Virtual_Processor =>
            Visit_Virtual_Processor (E);

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

   ---------------
   -- Visit_Bus --
   ---------------

   procedure Visit_Bus (E : Node_Id) is
julien.delange's avatar
julien.delange committed
361
      N : Node_Id;
362
363
364
365
366
      C : Node_Id;
      C_Src : Node_Id;
      C_Dst : Node_Id;
      Src_Component : Node_Id;
      Dst_Component : Node_Id;
367
   begin
julien.delange's avatar
julien.delange committed
368
369
370
371
      N := MTU.Make_Processing_Resource
         (Normalize_Name (Name (Identifier (Parent_Subcomponent (E)))),
         PR_Packet_Based_Network);

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
      if not AINU.Is_Empty (Connections (Root_System_Node)) then
         C := First_Node (Connections (Root_System_Node));
         while Present (C) loop
            C_Src := Source (C);
            if Kind (C_Src) = K_Entity_Reference_Instance then
               Src_Component := Get_Referenced_Entity (C_Src);
            end if;
            C_Dst := Get_Referenced_Entity (Destination (C));

            if C_Src /= No_Node and then C_Dst /= No_Node then
               Dst_Component := Parent_Subcomponent
                  (Parent_Component (C_Dst));

               if Src_Component = Parent_Subcomponent (E) and then
                  Get_Category_Of_Component (Dst_Component) = CC_Device then
                  Append_Node_To_List
                     (Make_Driver_Wrapper
                        (Corresponding_Instance (Dst_Component)),
                     MTN.List_Of_Drivers (N));
               end if;
            end if;

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

julien.delange's avatar
julien.delange committed
398
399
      MTN.Set_Is_Full_Duplex (N, True);
      MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));
400
401
402
403
404
405
406
407
408
409
410
411
   end Visit_Bus;

   --------------------------------------
   -- Visit_Virtual_Processor_Instance --
   --------------------------------------

   procedure Visit_Virtual_Processor (E : Node_Id) is
      pragma Unreferenced (E);
   begin
      null;
   end Visit_Virtual_Processor;

412
413
414
415
416
417
418
419
   ------------------
   -- Visit_Device --
   ------------------

   procedure Visit_Device (E : Node_Id) is
      S        : Node_Id;
      N        : Node_Id;
   begin
420
      N := Make_Driver_Wrapper (E);
421
422
423
424
425
426
427
428
429
430
431
432
433
434
      MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));

      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;
   end Visit_Device;

435
436
437
438
439
440
441
442
443
   ---------------------
   -- Visit_Processor --
   ---------------------

   procedure Visit_Processor (E : Node_Id) is
      S        : Node_Id;
      N        : Node_Id;
   begin
      N := MTU.Make_Processing_Resource
444
         (Normalize_Name (Name (Identifier (Parent_Subcomponent (E)))),
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
         PR_Regular_Processor);

      MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));

      N := MTU.Make_Scheduler
         (Map_Scheduler_Name (E),
         Normalize_Name (Name (Identifier (Parent_Subcomponent (E)))));
      MTN.Set_Is_Primary_Scheduler (N, True);
      MTN.Set_Use_Fixed_Priority (N, True);
      MTN.Set_Min_Priority
      (N, Make_Literal
       (New_Numeric_Value (1, 1, 10)));
      MTN.Set_Max_Priority
      (N, Make_Literal
       (New_Numeric_Value (256, 1, 10)));
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474

      MTU.Append_Node_To_List (N, MTN.Declarations (MAST_File));

      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;
   end Visit_Processor;

julien.delange's avatar
julien.delange committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
   -------------------
   -- Visit_Process --
   -------------------

   procedure Visit_Process (E : Node_Id) is
      S        : Node_Id;
   begin
      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;
   end Visit_Process;

494
495
496
497
498
499
500
501
502
503
   ----------------
   -- Visit_Data --
   -------------------

   procedure Visit_Data (E : Node_Id) is
      S        : Node_Id;
      N        : Node_Id;
      CP       : constant Supported_Concurrency_Control_Protocol
         := Get_Concurrency_Protocol (E);
   begin
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
      N := Make_Operation
         (Map_Operation_Message_Transmission_Name (E),
         Message_Transmission,
         No_List);
      if Get_Data_Size (E) /= Null_Size then
         MTN.Set_Max_Message_Size
            (N, Make_Literal
               (New_Numeric_Value
                  (To_Bytes (Get_Data_Size (E)), 1, 10)));

         MTN.Set_Avg_Message_Size
            (N, Make_Literal
               (New_Numeric_Value
                  (To_Bytes (Get_Data_Size (E)), 1, 10)));

         MTN.Set_Min_Message_Size
            (N, Make_Literal
               (New_Numeric_Value
                  (To_Bytes (Get_Data_Size (E)), 1, 10)));
      end if;
      Append_Node_To_List (N, MTN.Declarations (MAST_File));

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
      if CP = Concurrency_Protected_Access or else
         CP = concurrency_Priority_Ceiling or else
         Is_Protected_Data (E) or else
         Get_Data_Representation (E) = Data_With_Accessors then
         N := Make_Shared_Resource
            (Immediate_Ceiling, Normalize_Name (Name (Identifier (E))));
         Append_Node_To_List (N, MTN.Declarations (MAST_File));
      end if;

      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;
   end Visit_Data;

julien.delange's avatar
julien.delange committed
547
548
549
550
551
   ------------------
   -- Visit_Thread --
   ------------------

   procedure Visit_Thread (E : Node_Id) is
552
553
      S                       : Node_Id;
      N                       : Node_Id;
julien.delange's avatar
julien.delange committed
554
555
556
      Call                    : Node_Id;
      Spg_Call                : Node_Id;
      Spg                     : Node_Id;
557
558
559
560
561
562
      Activation_Event        : Node_Id;
      Activation_Kind         : Event_Kind := Regular;
      Activation_Event_Name   : Name_Id;
      Output_Event            : Node_Id;
      Output_Event_Name       : Name_Id;
      Event_Handler           : Node_Id;
563
      Server_Parameters       : Node_Id;
564
565
566
      Server_Sched_Name       : Name_Id;
      Operation_Name          : Name_Id;
      Operation               : Node_Id;
julien.delange's avatar
julien.delange committed
567
568
569
      Operations_List         : constant List_Id
                  := MTU.New_List (MTN.K_List_Id);
      Output_Event_Req        : Node_Id := No_Node;
570
      Prio                    : Unsigned_Long_Long;
571
572
      Exec_Time               : constant Time_Array := Get_Execution_Time (E);
      The_Feature             : Node_Id;
573
574
575
576
      Port_Operation                : Node_Id;
      Port_Shared_Resource          : Node_Id;
      Port_Shared_Resource_Op       : Node_Id;
      Port_Shared_Resource_Op_List  : List_Id;
julien.delange's avatar
julien.delange committed
577
   begin
578
      Set_Str_To_Name_Buffer ("");
579
      Get_Name_String (Fully_Qualified_Instance_Name (E));
580
581
582
      Add_Str_To_Name_Buffer ("_sched_server");
      Server_Sched_Name := Name_Find;

583
584
585
586
587
      Set_Str_To_Name_Buffer ("");
      Get_Name_String (Fully_Qualified_Instance_Name (E));
      Add_Str_To_Name_Buffer ("_operations");
      Operation_Name := Name_Find;

588
589
590
591
592
593
594
      Prio := Get_Thread_Priority (E);
      if Prio = 0 then
         Prio := 1;
      end if;
      Server_Parameters := Make_Scheduling_Server_Parameters
         (Fixed_Priority, Prio);

julien.delange's avatar
julien.delange committed
595
      N := Make_Scheduling_Server
596
         (Server_Sched_Name,
597
598
599
600
601
602
603
         No_Name);
      MTN.Set_Associated_Scheduler
         (N,
         Map_Scheduler_Name
            (Get_Bound_Processor
               (Parent_Component
                  (Parent_Subcomponent (E)))));
604
605
606

      MTN.Set_Parameters (N, Server_Parameters);

julien.delange's avatar
julien.delange committed
607
608
      Append_Node_To_List (N, MTN.Declarations (MAST_File));

609
      N := Make_Transaction
610
        (Fully_Qualified_Instance_Name (E),
611
         Regular);
612
613
614
      Append_Node_To_List (N, MTN.Declarations (MAST_File));

      Set_Str_To_Name_Buffer ("");
615
      Get_Name_String (Fully_Qualified_Instance_Name (E));
616
617
618
619
620
      Add_Str_To_Name_Buffer ("_activation_event");
      Activation_Event_Name := Name_Find;

      if Get_Thread_Dispatch_Protocol (E) = Thread_Periodic then
         Activation_Kind := Periodic;
julien.delange's avatar
julien.delange committed
621
622
623
624
625
626

         Output_Event_Req
            := Make_Event_Timing_Requirement
               (Hard_Deadline,
               To_Milliseconds (Get_Thread_Deadline (E)),
               Activation_Event_Name);
627
628
      elsif Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic then
         Activation_Kind := Sporadic;
629
630
631
632
633
634
635

         Output_Event_Req
            := Make_Event_Timing_Requirement
               (Hard_Deadline,
               To_Milliseconds (Get_Thread_Deadline (E)),
               Activation_Event_Name);

636
637
638
639
640
641
      else
         Activation_Kind := Regular;
      end if;

      Activation_Event := Make_Event (Activation_Event_Name, Activation_Kind);

julien.delange's avatar
julien.delange committed
642
643
644
645
646
647
      if Get_Thread_Dispatch_Protocol (E) = Thread_Periodic then
         MTN.Set_Period
            (Activation_Event,
            Make_Literal
               (New_Numeric_Value
                  (To_Milliseconds (Get_Thread_Period (E)), 1, 10)));
648
649
650
651
652
653
      elsif Get_Thread_Dispatch_Protocol (E) = Thread_Sporadic then
         MTN.Set_Min_Interarrival
            (Activation_Event,
            Make_Literal
               (New_Numeric_Value
                  (To_Milliseconds (Get_Thread_Period (E)), 1, 10)));
julien.delange's avatar
julien.delange committed
654
655
656
657
      else
         MTN.Set_Period (Activation_Event, No_Node);
      end if;

658
659
660
661
      Append_Node_To_List
         (Activation_Event, MTN.External_Events (N));

      Set_Str_To_Name_Buffer ("");
662
      Get_Name_String (Fully_Qualified_Instance_Name (E));
663
664
665
666
667
      Add_Str_To_Name_Buffer ("_output_event");
      Output_Event_Name := Name_Find;

      Output_Event := Make_Event (Output_Event_Name, Regular);

julien.delange's avatar
julien.delange committed
668
669
      MTN.Set_Timing_Requirements (Output_Event, Output_Event_Req);

670
671
672
673
674
675
676
677
678
679
680
681
682
683
      Append_Node_To_List
         (Output_Event, MTN.Internal_Events (N));

      Event_Handler := Make_Event_Handler
         (Activity,
         Activation_Event_Name,
         Output_Event_Name,
         Operation_Name,
         Server_Sched_Name);

      Append_Node_To_List
         (Event_Handler, MTN.Event_Handlers (N));

      Operation := Make_Operation (Operation_Name, Enclosing);
julien.delange's avatar
julien.delange committed
684
685
      MTN.Set_Operations (Operation, Operations_List);

686
687
688
689
690
691
692
693
694
695
696
      if Exec_Time /= Empty_Time_Array then
         MTN.Set_Best_Case_Execution_Time
            (Operation,
            Make_Literal
               (New_Numeric_Value
                  (To_Milliseconds (Exec_Time (0)), 1, 10)));
         MTN.Set_Worst_Case_Execution_Time
            (Operation,
            Make_Literal
               (New_Numeric_Value
                  (To_Milliseconds (Exec_Time (1)), 1, 10)));
697
698
699
700
701
702
703
704
705
706
707
      else
         MTN.Set_Best_Case_Execution_Time
            (Operation,
            Make_Literal
               (New_Numeric_Value
                  (0, 1, 10)));
         MTN.Set_Worst_Case_Execution_Time
            (Operation,
            Make_Literal
               (New_Numeric_Value
                  (1, 1, 10)));
708
709
      end if;

710
711
      Append_Node_To_List (Operation, MTN.Declarations (MAST_File));

712
713
714
715
716
717
718
719
      if Has_Ports (E) then
         The_Feature := First_Node (Features (E));

         while Present (The_Feature) loop
            if Kind (The_Feature) = K_Port_Spec_Instance and then
               Is_In (The_Feature) then
                  Append_Node_To_List
                     (Make_Defining_Identifier
720
721
                        (Map_Port_Shared_Resource_Operation_Name
                           (The_Feature)),
722
                     Operations_List);
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758

               Port_Shared_Resource := Make_Shared_Resource
                     (Immediate_Ceiling,
                     Map_Port_Shared_Resource_Name (The_Feature));
               Append_Node_To_List
                  (Port_Shared_Resource, MTN.Declarations (MAST_File));

               Port_Shared_Resource_Op_List := New_List (MTN.K_List_Id);

               Append_Node_To_List
                  (Make_Defining_Identifier
                     (Map_Port_Shared_Resource_Name (The_Feature)),
                  Port_Shared_Resource_Op_List);

               Port_Shared_Resource_Op := Make_Operation
                     (Map_Port_Shared_Resource_Operation_Name (The_Feature),
                     Simple,
                     No_List);
               MTN.Set_Shared_Resources_List
               (Port_Shared_Resource_Op,
                Port_Shared_Resource_Op_List);

               MTN.Set_Best_Case_Execution_Time
                  (Port_Shared_Resource_Op,
                  Make_Literal
                     (New_Numeric_Value
                        (1, 1, 10)));
               MTN.Set_Worst_Case_Execution_Time
                  (Port_Shared_Resource_Op,
                  Make_Literal
                     (New_Numeric_Value
                        (10, 1, 10)));

               Append_Node_To_List
                  (Port_Shared_Resource_Op, MTN.Declarations (MAST_File));

759
760
761
762
763
            end if;
            The_Feature := Next_Node (The_Feature);
         end loop;
      end if;

julien.delange's avatar
julien.delange committed
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
      if not AINU.Is_Empty (Calls (E)) then
         Call := AIN.First_Node (Calls (E));
         while Present (Call) loop

            if not AINU.Is_Empty (Subprogram_Calls (Call)) then
               Spg_Call := AIN.First_Node
                  (AIN.Subprogram_Calls (Call));
               while Present (Spg_Call) loop

                  Spg := AIN.Corresponding_Instance (Spg_Call);
                  Append_Node_To_List
                     (Make_Defining_Identifier
                        (Name (Identifier (Spg))),
                     Operations_List);
                  Visit (Spg);
                  Spg_Call := AIN.Next_Node (Spg_Call);
               end loop;
            end if;
            Call := AIN.Next_Node (Call);
         end loop;
      end if;

786
787
788
789
790
791
      if Has_Ports (E) then
         The_Feature := First_Node (Features (E));

         while Present (The_Feature) loop
            if Kind (The_Feature) = K_Port_Spec_Instance and then
               Is_Out (The_Feature) then
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
                  declare
                     Dest_Ports : constant List_Id
                        := Get_Destination_Ports (The_Feature);
                     Dest_Port : Node_Id;
                  begin
                     if not AINU.Is_Empty (Dest_Ports) then
                        Dest_Port := AIN.First_Node (Dest_Ports);
                        while Present (Dest_Port) loop
                           Append_Node_To_List
                              (Make_Defining_Identifier
                                 (Map_Port_Shared_Resource_Operation_Name
                                    (Item (Dest_Port))),
                              Operations_List);
                           Dest_Port := AIN.Next_Node (Dest_Port);
                        end loop;
                     end if;
                  end;
809
810
811
812
813
            end if;
            The_Feature := Next_Node (The_Feature);
         end loop;
      end if;

julien.delange's avatar
julien.delange committed
814
815
816
817
818
819
820
821
822
823
      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;
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852

      if Has_Ports (E) then
         The_Feature := First_Node (Features (E));

         while Present (The_Feature) loop
            if Kind (The_Feature) = K_Port_Spec_Instance then
               Port_Operation :=
                  Make_Operation
                     (Map_Port_Operation_Name (E, The_Feature), Simple);
               MTN.Set_Operations (Port_Operation, New_List (MTN.K_List_Id));

               MTN.Set_Best_Case_Execution_Time
                  (Port_Operation,
                  Make_Literal
                     (New_Numeric_Value
                        (1, 1, 10)));
               MTN.Set_Worst_Case_Execution_Time
                  (Port_Operation,
                  Make_Literal
                     (New_Numeric_Value
                        (2, 1, 10)));

               Append_Node_To_List
                  (Port_Operation, MTN.Declarations (MAST_File));
            end if;
            The_Feature := Next_Node (The_Feature);
         end loop;
      end if;

julien.delange's avatar
julien.delange committed
853
854
   end Visit_Thread;

julien.delange's avatar
julien.delange committed
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
   ----------------------
   -- Visit_Subprogram --
   ----------------------

   procedure Visit_Subprogram (E : Node_Id) is
      Operation               : Node_Id;
      Operation_Name          : Name_Id;
      Operations_List         : constant List_Id
                  := MTU.New_List (MTN.K_List_Id);
   begin
      Operation_Name := Name (Identifier (E));
      Operation := Make_Operation (Operation_Name, Simple);
      MTN.Set_Operations (Operation, Operations_List);

      Append_Node_To_List (Operation, MTN.Declarations (MAST_File));
   end Visit_Subprogram;

872
873
874
875
876
877
878
879
880
881
882
883
   ------------------
   -- Visit_System --
   ------------------

   procedure Visit_System (E : Node_Id) is
      S                    : Node_Id;
   begin
      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.
884
885
886
887
888
            if Get_Category_Of_Component
               (Corresponding_Instance (S)) /= CC_Device then
               Visit (Corresponding_Instance (S));
            end if;

889
890
891
892
893
            S := Next_Node (S);
         end loop;
      end if;
   end Visit_System;
end Ocarina.Backends.MAST.Main;