ocarina-backends-po_hi_c-main.adb 27.6 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 _ C . M A I N         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--          Copyright (C) 2008-2011, European Space Agency (ESA).           --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--                                                                          --
-- 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.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

with Namet; use Namet;

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.Properties;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Messages;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Values;
47
with Ocarina.Backends.PO_HI_C;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
with Ocarina.Backends.PO_HI_C.Runtime;
with Ocarina.Backends.C_Common.Mapping;

package body Ocarina.Backends.PO_HI_C.Main is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.Properties;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.C_Tree.Nutils;
   use Ocarina.Backends.C_Values;
   use Ocarina.Backends.PO_HI_C.Runtime;
   use Ocarina.Backends.C_Common.Mapping;
   use Ocarina.Backends.Utils;

   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
   package CTU renames Ocarina.Backends.C_Tree.Nutils;

   ---------------------
   -- Subprogram_Body --
   ---------------------

   package body Source_File is

74
75
76
      Main_Function              : Node_Id;
      Current_Device             : Node_Id := No_Node;
      Period_Variable_Declared   : Boolean := False;
77
78
79
80
81

      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);
82
      procedure Visit_Device_Instance (E : Node_Id);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
      procedure Visit_Thread_Instance (E : Node_Id);
      procedure Visit_Subprogram_Instance (E : Node_Id);

      procedure Setup_Thread (E : Node_Id);
      --  Create a task according to all its properties
      --  (like period, priority, ...). The task creation
      --  is made in the main function, calling the function
      --  __po_hi_create_<>_task().

      Ada_Initialized : Boolean := False;

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

      procedure Setup_Thread (E : Node_Id) is
         N          : Node_Id;
         Parameters : List_Id;
         Priority   : Unsigned_Long_Long;
         Stack_Size : Unsigned_Long_Long;
         S          : constant Node_Id := Parent_Subcomponent (E);
      begin
         Parameters := New_List (CTN.K_Parameter_List);

         --  Add the task name to the parameters list

109
110
111
112
         N := Make_Defining_Identifier
            (Map_C_Enumerator_Name
               (S,
               Custom_Parent => Current_Device));
113
114
115
116
117
         Append_Node_To_List (N, Parameters);

         --  Add the period of the task to the parameters list. We use
         --  the fact that an aperiodic thread is sporadic, with
         --  period of 0.
118
         if Period_Variable_Declared = False then
119
120
121
122
123
124
125
126
127
128
129
            N := Make_Doxygen_C_Comment
               (Brief => "Variable for task period",
               Is_Variable => True,
               Desc => "This variable is used to store the value" &
               "of the period of a task when we create it. The " &
               "value put in the variable is set according to " &
               "AADL model description",
               Element_Name => Get_Name_String (VN (V_Period)),
               Has_Header_Spaces => False);
            Append_Node_To_List (N, CTN.Declarations (Main_Function));

130
            N := Make_Variable_Declaration
131
            (Make_Defining_Identifier (VN (V_Period)),
132
133
134
135
136
               RE (RE_Time_T));
            Append_Node_To_List (N, CTN.Declarations (Main_Function));

            Period_Variable_Declared := True;
         end if;
137

138
139
140
141
142
143
         N := Make_Doxygen_C_Comment
            (Desc => "Store the period time for task " &
               Get_Name_String (Name (Identifier (S))),
            Has_Header_Spaces => False);
         Append_Node_To_List (N, CTN.Statements (Main_Function));

144
145
146
         if Get_Thread_Dispatch_Protocol (E) /= Thread_Aperiodic
           and then Get_Thread_Dispatch_Protocol (E) /= Thread_Background
         then
147
            N := Map_Time (Get_Thread_Period (E), VN (V_Period));
148

149
         else
150
            N := Map_Time ((0, Second), VN (V_Period));
151
         end if;
152
153
154

         Append_Node_To_List
            (Make_Variable_Address
155
               (Make_Defining_Identifier (VN (V_Period))),
156
157
158
            Parameters);

         Append_Node_To_List (N, CTN.Statements (Main_Function));
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

         --  Add the priority of the task in the parameters list. If
         --  the task does not have any priority, we use the macro
         --  DEFAULT_PRIORITY.

         Priority := Get_Thread_Priority (E);
         if Priority = 0 then
            N := RE (RE_Default_Priority);
         else
            N := Make_Literal (New_Int_Value (Priority, 1, 10));
         end if;
         Append_Node_To_List (N, Parameters);

         --  Add thread stack size

         Stack_Size := To_Bytes (Get_Thread_Stack_Size (E));
         N := Make_Literal (New_Int_Value (Stack_Size, 1, 10));
         Append_Node_To_List (N, Parameters);

         --  Add the name of function executed by the task in the
         --  parameters list.

         N := Copy_Node
           (CTN.Defining_Identifier
            (CTN.Job_Node
             (Backend_Node
              (Identifier (S)))));
         Append_Node_To_List (N, Parameters);

         case Get_Thread_Dispatch_Protocol (E) is
            when Thread_Periodic =>
190
               N := Make_Doxygen_C_Comment
191
192
                  (Brief => "Making Periodic Task " &
                   Get_Name_String (Name (Identifier (S))),
193
194
195
                  Desc => "Make a periodic task according to " &
                           "AADL model requirements. The first " &
                           "parameter is the task identifier defined " &
196
197
198
                           "in deployment.h (" &
                           Get_Name_String (Map_C_Enumerator_Name (S)) &
                           ") the second is the period " &
199
                           "defined in the AADL model. Third is the task " &
200
201
202
203
204
205
206
                           "priority (" &
                           Unsigned_Long_Long'Image (Get_Thread_Priority (E)) &
                           "), fourth is the stack size ("&
                           Unsigned_Long_Long'Image
                              (To_Bytes (Get_Thread_Stack_Size (E))) &
                           " bytes) and last is the subprogram executed "&
                           "by the task",
207
208
209
                  Has_Header_Spaces => False);
               Append_Node_To_List (N, CTN.Statements (Main_Function));

210
211
212
213
214
215
216
               Append_Node_To_List
                 (CTU.Make_Call_Profile
                    (RE (RE_Create_Periodic_Task), Parameters),
                  CTN.Statements (Main_Function));

            when Thread_Sporadic
              | Thread_Aperiodic =>
217
218
219
220
               N := Make_Doxygen_C_Comment
                  ("Making Sporadic task", Has_Header_Spaces => False);
               Append_Node_To_List (N, CTN.Statements (Main_Function));

221
222
223
224
225
               Append_Node_To_List
                 (CTU.Make_Call_Profile
                    (RE (RE_Create_Sporadic_Task), Parameters),
                  CTN.Statements (Main_Function));

226
            when Thread_Background =>
227
228
229
230
               N := Make_Doxygen_C_Comment
                  ("Making background task", Has_Header_Spaces => False);
               Append_Node_To_List (N, CTN.Statements (Main_Function));

231
232
233
234
235
               Append_Node_To_List
                 (CTU.Make_Call_Profile
                    (RE (RE_Create_Sporadic_Task), Parameters),
                  CTN.Statements (Main_Function));

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
296
297
298
299
300
301
302
303
304
305
            when others =>
               Display_Located_Error
                 (Loc (E),
                  "Thread kind is not supported",
                  Fatal => True);
         end case;
      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
         Category : constant Component_Category
           := Get_Category_Of_Component (E);
      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 CC_Subprogram =>
               Visit_Subprogram_Instance (E);

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

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

      procedure Visit_Process_Instance (E : Node_Id) is
         U               : constant Node_Id := CTN.Distributed_Application_Unit
           (CTN.Naming_Node (Backend_Node (Identifier (E))));
         P               : constant Node_Id := CTN.Entity (U);
         N               : Node_Id;
306
         C               : Node_Id;
307
         S               : Node_Id;
308
309
310
311
         Spec            : Node_Id;
         Declarations    : constant List_Id := New_List
           (CTN.K_Declaration_List);
         Statements      : constant List_Id := New_List (CTN.K_Statement_List);
312
313
         The_System      : constant Node_Id := Parent_Component
           (Parent_Subcomponent (E));
314
315
316
317
318
319
320
      begin
         Push_Entity (P);
         Push_Entity (U);

         Set_Main_Source;
         Ada_Initialized := False;

321
322
         Period_Variable_Declared := False;

323
324
325
326
327
328
329
330
331
332
333
334
335
         Add_Include (E => RH (RH_Activity));

         --  Make the main function specification and add it in the current
         --  file (main.c).

         Spec := Make_Function_Specification
           (Defining_Identifier => RE (RE_Main_Name),
            Parameters          => No_List,
            Return_Type         => RE (RE_Main_Type)
           );
         Main_Function := Make_Function_Implementation
           (Spec, Declarations, Statements);

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
         N := CTU.Make_Call_Profile (RE (RE_Initialize_Early));
         Append_Node_To_List (N, CTN.Statements (Main_Function));

         --  Visit all devices attached to the parent system that
         --  share the same processor as process E.
         --  This is done to initialize all devices before system starts.

         if not AAU.Is_Empty (Subcomponents (The_System)) then
            C := First_Node (Subcomponents (The_System));
            while Present (C) loop
               if AAU.Is_Device (Corresponding_Instance (C))
               and then
                 Get_Bound_Processor (Corresponding_Instance (C))
                 = Get_Bound_Processor (E)
               then
                  Visit_Device_Instance
                    (Corresponding_Instance (C));
               end if;
               C := Next_Node (C);
            end loop;
         end if;

358
359
360
361
         N := Make_Doxygen_C_Comment
            ("Initialize the runtime", Has_Header_Spaces => False);
         Append_Node_To_List (N, CTN.Statements (Main_Function));

362
363
364
         N := CTU.Make_Call_Profile (RE (RE_Initialize));
         Append_Node_To_List (N, CTN.Statements (Main_Function));

365
366
367
368
369
370
371
372
373
         if Process_Use_Defaults_Sockets (E) then
            Add_Include
               (Make_Include_Clause
                  (Make_Defining_Identifier
                     (Get_String_Name
                        ("drivers/po_hi_driver_sockets"))));
            N := Make_Call_Profile
               (Make_Defining_Identifier
                  (Get_String_Name ("__po_hi_driver_sockets_init")),
374
375
               Make_List_Id
                  (Make_Literal (New_Int_Value (0, 0, 10))));
376
377
            Append_Node_To_List (N, CTN.Statements (Main_Function));
         end if;
378

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
         --  Visit all threads and see if there is an initialize entrypoint.
         --  In that case, call the initialize entrypoint.

         --  There is two ways to deal with initialize entrypoint. The
         --  entrypoint can point a subprogram classifier (a node)
         --  or just reference text. We have to handle both cases.

         if not AAU.Is_Empty (Subcomponents (E)) then
            C := First_Node (Subcomponents (E));
            while Present (C) loop

               --  First, handle the case when the initialize_entrypoint
               --  is a subprogram classifier reference.

               if AAU.Is_Thread (Corresponding_Instance (C)) and then
                  Get_Thread_Initialize_Entrypoint
                     (Corresponding_Instance (C)) /= No_Node
               then
397
398
399
400
401
402
403
404
405
406
                  Append_Node_To_List
                     (Make_Extern_Entity_Declaration
                        (Make_Function_Specification
                              (Map_C_Subprogram_Identifier
                                 (Get_Thread_Initialize_Entrypoint
                                    (Corresponding_Instance (C))),
                           Parameters   => No_List,
                           Return_Type  => New_Node (CTN.K_Void))),
                     CTN.Declarations (Current_File));

407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
                  Append_Node_To_List
                     (Make_Call_Profile
                        (Map_C_Subprogram_Identifier
                           (Get_Thread_Initialize_Entrypoint
                              (Corresponding_Instance (C))), No_List),
                     CTN.Statements (Main_Function));
               end if;

               --  Then, handle the case when the initialize entrypoint
               --  is just a string.

               if AAU.Is_Thread (Corresponding_Instance (C)) and then
                  Get_Thread_Initialize_Entrypoint
                     (Corresponding_Instance (C)) /= No_Name
               then
422
423
424
425
426
427
428
429
430
431
                  Append_Node_To_List
                     (Make_Extern_Entity_Declaration
                        (Make_Function_Specification
                              (Make_Defining_Identifier
                                 (Get_Thread_Initialize_Entrypoint
                                    (Corresponding_Instance (C))),
                           Parameters   => No_List,
                           Return_Type  => New_Node (CTN.K_Void))),
                     CTN.Declarations (Current_File));

432
433
434
435
436
437
438
439
440
441
442
443
                  Append_Node_To_List
                     (Make_Call_Profile
                        (Make_Defining_Identifier
                           (Get_Thread_Initialize_Entrypoint
                              (Corresponding_Instance (C))), No_List),
                     CTN.Statements (Main_Function));
               end if;

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

444
445
         --  Here, we should automatically initialize the sockets layer

446
447
448
449
450
451
452
453
454
455
456
457
458
459
         if not AAU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Handle protected data, the following lines initialize
               --  the protected_id attribute for each protected data
               --  The generated code will look like :
               --  data_variable.protected_id = value.

               if AAU.Is_Data (Corresponding_Instance (S)) then
                  --  Automatically use the types.h header if we use
                  --  protected data.

                  Add_Include (RH (RH_Types));

460
461
462
463
464
465
466
467
                  N := Make_Variable_Declaration
                    (Map_C_Defining_Identifier (S),
                     Map_C_Data_Type_Designator
                     (Corresponding_Instance (S)));

                  Append_Node_To_List
                    (N, CTN.Declarations (Current_File));

468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
                  N := Make_Expression
                    (Left_Expr =>
                       Make_Member_Designator
                       (Defining_Identifier =>
                          Make_Defining_Identifier (MN (M_Protected_Id)),
                        Aggregate_Name =>
                          Map_C_Defining_Identifier (S)),
                     Operator => Op_Equal,
                     Right_Expr =>
                       CTN.Default_Value_Node
                       (Backend_Node
                        (Identifier (S))));
                  Append_Node_To_List
                    (N, CTN.Statements (Main_Function));
               else
                  --  Visit the component instance corresponding to the
                  --  subcomponent S.

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

492
493
494
495
496
497
498
499
500
501
         N := Make_Doxygen_C_Comment
            (Is_Function => True,
            Element_Name => "__PO_HI_MAIN_TYPE __PO_HI_MAIN_NAME (void)",
            Brief => "Main function executed by the system",
            Desc =>
               "Full function name and return types are available " &
               " in the PolyORB-HI-C runtime header files.",
               Has_Header_Spaces => False);
         Append_Node_To_List (N, CTN.Declarations (Current_File));

502
503
504
505
         Append_Node_To_List (Main_Function, CTN.Declarations (Current_File));
         --  Call __po_hi_wait_initialization(). With this function,
         --  the main function will wait all other tasks initialization.

506
507
508
509
510
         N := Make_Doxygen_C_Comment
            ("Waiting for other tasks initialization",
               Has_Header_Spaces => False);
         Append_Node_To_List (N, Statements);

511
512
513
514
515
516
517
518
         N := CTU.Make_Call_Profile (RE (RE_Wait_Initialization),
                                     No_List);
         Append_Node_To_List (N, Statements);

         --  Make the call to __po_hi_wait_for_tasks(). This function will wait
         --  all other task. In fact, no task will terminate, so this function
         --  will only switch the main task to the sleep state all the time.

519
520
521
522
523
         N := Make_Doxygen_C_Comment
            ("Used to switch the main task to sleep all the time",
            Has_Header_Spaces => False);
         Append_Node_To_List (N, CTN.Statements (Main_Function));

524
525
526
527
528
529
         if not PO_HI_C.Use_Performance_Analysis then
            N := CTU.Make_Call_Profile (RE (RE_Wait_For_Tasks));
         else
            N := CTU.Make_Call_Profile (RE (RE_Wait_End_Of_Instrumentation));
         end if;

530
531
         Append_Node_To_List (N, CTN.Statements (Main_Function));

532
533
534
535
         N := Make_Doxygen_C_Comment
               ("Return Statement", Has_Header_Spaces => False);
         Append_Node_To_List (N, CTN.Statements (Main_Function));

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
         N := CTU.Make_Return_Statement (RE (RE_Main_Return));
         Append_Node_To_List (N, CTN.Statements (Main_Function));

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

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

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

         --  Visit all the subcomponents of the system

         if not AAU.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; --  C_Root
      end Visit_System_Instance;

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

      procedure Visit_Thread_Instance (E : Node_Id) is
         S        : Node_Id;
         Call_Seq : Node_Id;
         Spg_Call : Node_Id;
      begin
         if not AAU.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;

         if not AAU.Is_Empty (Calls (E)) then
            Call_Seq := First_Node (Calls (E));

            while Present (Call_Seq) loop
               --  For each call sequence visit all the called
               --  subprograms.

               if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
                  Spg_Call := First_Node (Subprogram_Calls (Call_Seq));

                  while Present (Spg_Call) loop
                     Visit (Corresponding_Instance (Spg_Call));

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

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

         Setup_Thread (E);
      end Visit_Thread_Instance;

      -------------------------------
      -- Visit_Subprogram_Instance --
      -------------------------------

      procedure Visit_Subprogram_Instance (E : Node_Id) is
--         Initialize_Function_Name : Name_Id;
--         Start_Function_Name : Name_Id;
      begin
         if Get_Subprogram_Kind (E) = Subprogram_Simulink then
            Add_Include
               (Make_Include_Clause
                  (Make_Defining_Identifier
                     (Get_Source_Name (E), False), False), True);

--            Set_Str_To_Name_Buffer ("MdlInitialize");

--            Initialize_Function_Name := Name_Find;

--            Append_Node_To_List
--               (CTU.Make_Call_Profile
--    (Make_Defining_Identifier (Initialize_Function_Name, False),
--                  No_List),
--               CTN.Declarations (Main_Function));

--            Set_Str_To_Name_Buffer ("MdlStart");

--            Start_Function_Name := Name_Find;

--            Append_Node_To_List
--               (CTU.Make_Call_Profile
--      (Make_Defining_Identifier (Start_Function_Name, False),
--                  No_List),
--               CTN.Declarations (Main_Function));

            Append_Node_To_List
              (CTU.Make_Call_Profile
                 (RE (RE_Simulink_Init), No_List),
               CTN.Declarations (Main_Function));

         elsif Get_Subprogram_Kind (E) = Subprogram_Opaque_Ada_95
           and then not Ada_Initialized
         then
            Ada_Initialized := True;
            declare
               Parameter_List : constant List_Id :=
                 New_List (CTN.K_List_Id);
               N : Node_Id;

            begin
               Set_Str_To_Name_Buffer ("adainit");
               N := Make_Extern_Entity_Declaration
                 (Make_Function_Specification
                    (Make_Defining_Identifier (Name_Find),
                     Parameters          => Parameter_List, --  XXX
                     Return_Type         => New_Node (CTN.K_Void)));
               Append_Node_To_List (N, CTN.Declarations (Main_Function));

               Set_Str_To_Name_Buffer ("adainit");
               Append_Node_To_List
                 (CTU.Make_Call_Profile
                    (Make_Defining_Identifier (Name_Find), No_List),
                  CTN.Statements (Main_Function));
            end;
         end if;
      end Visit_Subprogram_Instance;

678
679
680
681
682
683
      ---------------------------
      -- Visit_Device_Instance --
      ---------------------------

      procedure Visit_Device_Instance (E : Node_Id) is
         N          : Node_Id;
684
         S          : Node_Id;
685
686
         Entrypoint : constant Node_Id
           := Get_Thread_Initialize_Entrypoint (E);
687
         Impl       : constant Node_Id := Get_Implementation (E);
688
      begin
689
         Current_Device := E;
690

691
692
693
694
         if Entrypoint /= No_Node then
            N := Make_Extern_Entity_Declaration
              (Make_Function_Specification
                  (Map_C_Subprogram_Identifier (Entrypoint),
695
696
                  Make_List_Id
                     (Make_Parameter_Specification
697
698
                        (Make_Defining_Identifier (Get_String_Name ("id")),
                        RE (RE_Device_Id))),
699
700
701
702
                  New_Node (CTN.K_Void)));
            Append_Node_To_List (N, CTN.Declarations (Current_File));

            N := Make_Call_Profile
703
704
705
706
              (Map_C_Subprogram_Identifier (Entrypoint),
              Make_List_Id
               (Make_Defining_Identifier
                  (Map_C_Enumerator_Name (E))));
707
            Append_Node_To_List (N, CTN.Statements (Main_Function));
708
         end if;
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723

         if Impl /= No_Node then
            if not AAU.Is_Empty (Subcomponents (Impl)) then
               S := First_Node (Subcomponents (Impl));
               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 if;

         Current_Device := No_Node;
724
725
      end Visit_Device_Instance;

726
727
728
   end Source_File;

end Ocarina.Backends.PO_HI_C.Main;