[multiple changes]
[gcc.git] / gcc / ada / bindgen.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- B I N D G E N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with ALI; use ALI;
27 with Binde; use Binde;
28 with Casing; use Casing;
29 with Fname; use Fname;
30 with Gnatvsn; use Gnatvsn;
31 with Hostparm;
32 with Namet; use Namet;
33 with Opt; use Opt;
34 with Osint; use Osint;
35 with Osint.B; use Osint.B;
36 with Output; use Output;
37 with Rident; use Rident;
38 with Table; use Table;
39 with Targparm; use Targparm;
40 with Types; use Types;
41
42 with System.OS_Lib; use System.OS_Lib;
43 with System.WCh_Con; use System.WCh_Con;
44
45 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
46
47 package body Bindgen is
48
49 Statement_Buffer : String (1 .. 1000);
50 -- Buffer used for constructing output statements
51
52 Last : Natural := 0;
53 -- Last location in Statement_Buffer currently set
54
55 With_GNARL : Boolean := False;
56 -- Flag which indicates whether the program uses the GNARL library
57 -- (presence of the unit System.OS_Interface)
58
59 Num_Elab_Calls : Nat := 0;
60 -- Number of generated calls to elaboration routines
61
62 System_Restrictions_Used : Boolean := False;
63 -- Flag indicating whether the unit System.Restrictions is in the closure
64 -- of the partition. This is set by Resolve_Binder_Options, and is used
65 -- to determine whether or not to initialize the restrictions information
66 -- in the body of the binder generated file (we do not want to do this
67 -- unconditionally, since it drags in the System.Restrictions unit
68 -- unconditionally, which is unpleasand, especially for ZFP etc.)
69
70 Dispatching_Domains_Used : Boolean := False;
71 -- Flag indicating whether multiprocessor dispatching domains are used in
72 -- the closure of the partition. This is set by Resolve_Binder_Options, and
73 -- is used to call the routine to disallow the creation of new dispatching
74 -- domains just before calling the main procedure from the environment
75 -- task.
76
77 System_Tasking_Restricted_Stages_Used : Boolean := False;
78 -- Flag indicating whether the unit System.Tasking.Restricted.Stages is in
79 -- the closure of the partition. This is set by Resolve_Binder_Options,
80 -- and it used to call a routine to active all the tasks at the end of
81 -- the elaboration when partition elaboration policy is sequential.
82
83 System_Interrupts_Used : Boolean := False;
84 -- Flag indicating whether the unit System.Interrups is in the closure of
85 -- the partition. This is set by Resolve_Binder_Options, and it used to
86 -- attach interrupt handlers at the end of the elaboration when partition
87 -- elaboration policy is sequential.
88
89 Lib_Final_Built : Boolean := False;
90 -- Flag indicating whether the finalize_library rountine has been built
91
92 CodePeer_Wrapper_Name : constant String := "call_main_subprogram";
93 -- For CodePeer, introduce a wrapper subprogram which calls the
94 -- user-defined main subprogram.
95
96 ----------------------------------
97 -- Interface_State Pragma Table --
98 ----------------------------------
99
100 -- This table assembles the interface state pragma information from
101 -- all the units in the partition. Note that Bcheck has already checked
102 -- that the information is consistent across units. The entries
103 -- in this table are n/u/r/s for not set/user/runtime/system.
104
105 package IS_Pragma_Settings is new Table.Table (
106 Table_Component_Type => Character,
107 Table_Index_Type => Int,
108 Table_Low_Bound => 0,
109 Table_Initial => 100,
110 Table_Increment => 200,
111 Table_Name => "IS_Pragma_Settings");
112
113 -- This table assembles the Priority_Specific_Dispatching pragma
114 -- information from all the units in the partition. Note that Bcheck has
115 -- already checked that the information is consistent across units.
116 -- The entries in this table are the upper case first character of the
117 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
118
119 package PSD_Pragma_Settings is new Table.Table (
120 Table_Component_Type => Character,
121 Table_Index_Type => Int,
122 Table_Low_Bound => 0,
123 Table_Initial => 100,
124 Table_Increment => 200,
125 Table_Name => "PSD_Pragma_Settings");
126
127 ----------------------
128 -- Run-Time Globals --
129 ----------------------
130
131 -- This section documents the global variables that are set from the
132 -- generated binder file.
133
134 -- Main_Priority : Integer;
135 -- Time_Slice_Value : Integer;
136 -- Heap_Size : Natural;
137 -- WC_Encoding : Character;
138 -- Locking_Policy : Character;
139 -- Queuing_Policy : Character;
140 -- Task_Dispatching_Policy : Character;
141 -- Priority_Specific_Dispatching : System.Address;
142 -- Num_Specific_Dispatching : Integer;
143 -- Restrictions : System.Address;
144 -- Interrupt_States : System.Address;
145 -- Num_Interrupt_States : Integer;
146 -- Unreserve_All_Interrupts : Integer;
147 -- Exception_Tracebacks : Integer;
148 -- Detect_Blocking : Integer;
149 -- Default_Stack_Size : Integer;
150 -- Leap_Seconds_Support : Integer;
151 -- Main_CPU : Integer;
152
153 -- Main_Priority is the priority value set by pragma Priority in the main
154 -- program. If no such pragma is present, the value is -1.
155
156 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
157 -- main program, or by the use of a -Tnnn parameter for the binder (if both
158 -- are present, the binder value overrides). The value is in milliseconds.
159 -- A value of zero indicates that time slicing should be suppressed. If no
160 -- pragma is present, and no -T switch was used, the value is -1.
161
162 -- WC_Encoding shows the wide character encoding method used for the main
163 -- program. This is one of the encoding letters defined in
164 -- System.WCh_Con.WC_Encoding_Letters.
165
166 -- Locking_Policy is a space if no locking policy was specified for the
167 -- partition. If a locking policy was specified, the value is the upper
168 -- case first character of the locking policy name, for example, 'C' for
169 -- Ceiling_Locking.
170
171 -- Queuing_Policy is a space if no queuing policy was specified for the
172 -- partition. If a queuing policy was specified, the value is the upper
173 -- case first character of the queuing policy name for example, 'F' for
174 -- FIFO_Queuing.
175
176 -- Task_Dispatching_Policy is a space if no task dispatching policy was
177 -- specified for the partition. If a task dispatching policy was specified,
178 -- the value is the upper case first character of the policy name, e.g. 'F'
179 -- for FIFO_Within_Priorities.
180
181 -- Priority_Specific_Dispatching is the address of a string used to store
182 -- the task dispatching policy specified for the different priorities in
183 -- the partition. The length of this string is determined by the last
184 -- priority for which such a pragma applies (the string will be a null
185 -- string if no specific dispatching policies were used). If pragma were
186 -- present, the entries apply to the priorities in sequence from the first
187 -- priority. The value stored is the upper case first character of the
188 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
189 -- for those priority ranges not specified.
190
191 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
192 -- string. It will be set to zero if no Priority_Specific_Dispatching
193 -- pragmas are present.
194
195 -- Restrictions is the address of a null-terminated string specifying the
196 -- restrictions information for the partition. The format is identical to
197 -- that of the parameter string found on R lines in ali files (see Lib.Writ
198 -- spec in lib-writ.ads for full details). The difference is that in this
199 -- context the values are the cumulative ones for the entire partition.
200
201 -- Interrupt_States is the address of a string used to specify the
202 -- cumulative results of Interrupt_State pragmas used in the partition.
203 -- The length of this string is determined by the last interrupt for which
204 -- such a pragma is given (the string will be a null string if no pragmas
205 -- were used). If pragma were present the entries apply to the interrupts
206 -- in sequence from the first interrupt, and are set to one of four
207 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
208 -- time, 's' for system, see description of Interrupt_State pragma for
209 -- further details.
210
211 -- Num_Interrupt_States is the length of the Interrupt_States string. It
212 -- will be set to zero if no Interrupt_State pragmas are present.
213
214 -- Unreserve_All_Interrupts is set to one if at least one unit in the
215 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
216
217 -- Exception_Tracebacks is set to one if the -E parameter was present
218 -- in the bind and to zero otherwise. Note that on some targets exception
219 -- tracebacks are provided by default, so a value of zero for this
220 -- parameter does not necessarily mean no trace backs are available.
221
222 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
223 -- not. A value of zero indicates that the pragma is not present, while a
224 -- value of 1 signals its presence in the partition.
225
226 -- Default_Stack_Size is the default stack size used when creating an Ada
227 -- task with no explicit Storage_Size clause.
228
229 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
230 -- disabled. A value of zero indicates that leap seconds are turned "off",
231 -- while a value of one signifies "on" status.
232
233 -- Main_CPU is the processor set by pragma CPU in the main program. If no
234 -- such pragma is present, the value is -1.
235
236 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
237 -- Convenient shorthand used throughout
238
239 -----------------------
240 -- Local Subprograms --
241 -----------------------
242
243 procedure Gen_Adainit;
244 -- Generates the Adainit procedure
245
246 procedure Gen_Adafinal;
247 -- Generate the Adafinal procedure
248
249 procedure Gen_CodePeer_Wrapper;
250 -- For CodePeer, generate wrapper which calls user-defined main subprogram
251
252 procedure Gen_Elab_Calls;
253 -- Generate sequence of elaboration calls
254
255 procedure Gen_Elab_Externals;
256 -- Generate sequence of external declarations for elaboration
257
258 procedure Gen_Elab_Order;
259 -- Generate comments showing elaboration order chosen
260
261 procedure Gen_Finalize_Library;
262 -- Generate a sequence of finalization calls to elaborated packages
263
264 procedure Gen_Main;
265 -- Generate procedure main
266
267 procedure Gen_Object_Files_Options;
268 -- Output comments containing a list of the full names of the object
269 -- files to be linked and the list of linker options supplied by
270 -- Linker_Options pragmas in the source.
271
272 procedure Gen_Output_File_Ada (Filename : String);
273 -- Generate Ada output file
274
275 procedure Gen_Restrictions;
276 -- Generate initialization of restrictions variable
277
278 procedure Gen_Versions;
279 -- Output series of definitions for unit versions
280
281 function Get_Ada_Main_Name return String;
282 -- This function is used for the Ada main output to compute a usable name
283 -- for the generated main program. The normal main program name is
284 -- Ada_Main, but this won't work if the user has a unit with this name.
285 -- This function tries Ada_Main first, and if there is such a clash, then
286 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
287
288 function Get_Main_Unit_Name (S : String) return String;
289 -- Return the main unit name corresponding to S by replacing '.' with '_'
290
291 function Get_Main_Name return String;
292 -- This function is used in the main output case to compute the correct
293 -- external main program. It is "main" by default, unless the flag
294 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
295 -- of the Ada main name without the "_ada". This default can be overridden
296 -- explicitly using the -Mname binder switch.
297
298 function Get_WC_Encoding return Character;
299 -- Return wide character encoding method to set as WC_Encoding in output.
300 -- If -W has been used, returns the specified encoding, otherwise returns
301 -- the encoding method used for the main program source. If there is no
302 -- main program source (-z switch used), returns brackets ('b').
303
304 function Has_Finalizer return Boolean;
305 -- Determine whether the current unit has at least one library-level
306 -- finalizer.
307
308 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
309 -- Compare linker options, when sorting, first according to
310 -- Is_Internal_File (internal files come later) and then by
311 -- elaboration order position (latest to earliest).
312
313 procedure Move_Linker_Option (From : Natural; To : Natural);
314 -- Move routine for sorting linker options
315
316 procedure Resolve_Binder_Options;
317 -- Set the value of With_GNARL
318
319 procedure Set_Char (C : Character);
320 -- Set given character in Statement_Buffer at the Last + 1 position
321 -- and increment Last by one to reflect the stored character.
322
323 procedure Set_Int (N : Int);
324 -- Set given value in decimal in Statement_Buffer with no spaces starting
325 -- at the Last + 1 position, and updating Last past the value. A minus sign
326 -- is output for a negative value.
327
328 procedure Set_Boolean (B : Boolean);
329 -- Set given boolean value in Statement_Buffer at the Last + 1 position
330 -- and update Last past the value.
331
332 procedure Set_IS_Pragma_Table;
333 -- Initializes contents of IS_Pragma_Settings table from ALI table
334
335 procedure Set_Main_Program_Name;
336 -- Given the main program name in Name_Buffer (length in Name_Len) generate
337 -- the name of the routine to be used in the call. The name is generated
338 -- starting at Last + 1, and Last is updated past it.
339
340 procedure Set_Name_Buffer;
341 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
342
343 procedure Set_PSD_Pragma_Table;
344 -- Initializes contents of PSD_Pragma_Settings table from ALI table
345
346 procedure Set_String (S : String);
347 -- Sets characters of given string in Statement_Buffer, starting at the
348 -- Last + 1 position, and updating last past the string value.
349
350 procedure Set_String_Replace (S : String);
351 -- Replaces the last S'Length characters in the Statement_Buffer with the
352 -- characters of S. The caller must ensure that these characters do in fact
353 -- exist in the Statement_Buffer.
354
355 procedure Set_Unit_Name;
356 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
357 -- starting at the Last + 1 position and update Last past the value.
358 -- Each dot (.) will be qualified into double underscores (__).
359
360 procedure Set_Unit_Number (U : Unit_Id);
361 -- Sets unit number (first unit is 1, leading zeroes output to line up all
362 -- output unit numbers nicely as required by the value, and by the total
363 -- number of units.
364
365 procedure Write_Statement_Buffer;
366 -- Write out contents of statement buffer up to Last, and reset Last to 0
367
368 procedure Write_Statement_Buffer (S : String);
369 -- First writes its argument (using Set_String (S)), then writes out the
370 -- contents of statement buffer up to Last, and reset Last to 0
371
372 ------------------
373 -- Gen_Adafinal --
374 ------------------
375
376 procedure Gen_Adafinal is
377 begin
378 WBI (" procedure " & Ada_Final_Name.all & " is");
379
380 if Bind_Main_Program and not CodePeer_Mode then
381 WBI (" procedure s_stalib_adafinal;");
382 Set_String (" pragma Import (C, s_stalib_adafinal, ");
383 Set_String ("""system__standard_library__adafinal"");");
384 Write_Statement_Buffer;
385 end if;
386
387 WBI ("");
388 WBI (" procedure Runtime_Finalize;");
389 WBI (" pragma Import (C, Runtime_Finalize, " &
390 """__gnat_runtime_finalize"");");
391 WBI ("");
392 WBI (" begin");
393
394 if not CodePeer_Mode then
395 WBI (" if not Is_Elaborated then");
396 WBI (" return;");
397 WBI (" end if;");
398 WBI (" Is_Elaborated := False;");
399 end if;
400
401 WBI (" Runtime_Finalize;");
402
403 -- By default (real targets), finalization is done differently depending
404 -- on whether this is the main program or a library.
405
406 if not CodePeer_Mode then
407 if Bind_Main_Program then
408 WBI (" s_stalib_adafinal;");
409 elsif Lib_Final_Built then
410 WBI (" finalize_library;");
411 else
412 WBI (" null;");
413 end if;
414
415 -- Pragma Import C cannot be used on virtual targets, therefore call the
416 -- runtime finalization routine directly in CodePeer mode, where
417 -- imported functions are ignored.
418
419 else
420 WBI (" System.Standard_Library.Adafinal;");
421 end if;
422
423 WBI (" end " & Ada_Final_Name.all & ";");
424 WBI ("");
425 end Gen_Adafinal;
426
427 -----------------
428 -- Gen_Adainit --
429 -----------------
430
431 procedure Gen_Adainit is
432 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
433 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
434
435 begin
436 -- Declare the access-to-subprogram type used for initialization of
437 -- of __gnat_finalize_library_objects. This is declared at library
438 -- level for compatibility with the type used in System.Soft_Links.
439 -- The import of the soft link which performs library-level object
440 -- finalization does not work for CodePeer, so regular Ada is used in
441 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
442 -- tasks are non-terminating, so we do not want finalization.
443
444 if not Suppress_Standard_Library_On_Target
445 and then not CodePeer_Mode
446 and then not Configurable_Run_Time_On_Target
447 then
448 WBI (" type No_Param_Proc is access procedure;");
449 WBI ("");
450 end if;
451
452 WBI (" procedure " & Ada_Init_Name.all & " is");
453
454 -- In CodePeer mode, simplify adainit procedure by only calling
455 -- elaboration procedures.
456
457 if CodePeer_Mode then
458 WBI (" begin");
459
460 -- When compiling for the AAMP small library, where the standard library
461 -- is no longer suppressed, we still want to exclude the setting of the
462 -- various imported globals, which aren't present for that library.
463
464 elsif AAMP_On_Target and then Configurable_Run_Time_On_Target then
465 WBI (" begin");
466 WBI (" null;");
467
468 -- If the standard library is suppressed, then the only global variables
469 -- that might be needed (by the Ravenscar profile) are the priority and
470 -- the processor for the environment task.
471
472 elsif Suppress_Standard_Library_On_Target then
473 if Main_Priority /= No_Main_Priority then
474 WBI (" Main_Priority : Integer;");
475 WBI (" pragma Import (C, Main_Priority," &
476 " ""__gl_main_priority"");");
477 WBI ("");
478 end if;
479
480 if Main_CPU /= No_Main_CPU then
481 WBI (" Main_CPU : Integer;");
482 WBI (" pragma Import (C, Main_CPU," &
483 " ""__gl_main_cpu"");");
484 WBI ("");
485 end if;
486
487 if System_Interrupts_Used
488 and then Partition_Elaboration_Policy_Specified = 'S'
489 then
490 WBI (" procedure Install_Restricted_Handlers_Sequential;");
491 WBI (" pragma Import (C," &
492 "Install_Restricted_Handlers_Sequential," &
493 " ""__gnat_attach_all_handlers"");");
494 WBI ("");
495 end if;
496
497 if System_Tasking_Restricted_Stages_Used
498 and then Partition_Elaboration_Policy_Specified = 'S'
499 then
500 WBI (" Partition_Elaboration_Policy : Character;");
501 WBI (" pragma Import (C, Partition_Elaboration_Policy," &
502 " ""__gnat_partition_elaboration_policy"");");
503 WBI ("");
504 WBI (" procedure Activate_All_Tasks_Sequential;");
505 WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
506 " ""__gnat_activate_all_tasks"");");
507 end if;
508
509 WBI (" begin");
510
511 if Main_Priority /= No_Main_Priority then
512 Set_String (" Main_Priority := ");
513 Set_Int (Main_Priority);
514 Set_Char (';');
515 Write_Statement_Buffer;
516 end if;
517
518 if Main_CPU /= No_Main_CPU then
519 Set_String (" Main_CPU := ");
520 Set_Int (Main_CPU);
521 Set_Char (';');
522 Write_Statement_Buffer;
523 end if;
524
525 if System_Tasking_Restricted_Stages_Used
526 and then Partition_Elaboration_Policy_Specified = 'S'
527 then
528 Set_String (" Partition_Elaboration_Policy := '");
529 Set_Char (Partition_Elaboration_Policy_Specified);
530 Set_String ("';");
531 Write_Statement_Buffer;
532 end if;
533
534 if Main_Priority = No_Main_Priority
535 and then Main_CPU = No_Main_CPU
536 and then not System_Tasking_Restricted_Stages_Used
537 then
538 WBI (" null;");
539 end if;
540
541 -- Normal case (standard library not suppressed). Set all global values
542 -- used by the run time.
543
544 else
545 WBI (" Main_Priority : Integer;");
546 WBI (" pragma Import (C, Main_Priority, " &
547 """__gl_main_priority"");");
548 WBI (" Time_Slice_Value : Integer;");
549 WBI (" pragma Import (C, Time_Slice_Value, " &
550 """__gl_time_slice_val"");");
551 WBI (" WC_Encoding : Character;");
552 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
553 WBI (" Locking_Policy : Character;");
554 WBI (" pragma Import (C, Locking_Policy, " &
555 """__gl_locking_policy"");");
556 WBI (" Queuing_Policy : Character;");
557 WBI (" pragma Import (C, Queuing_Policy, " &
558 """__gl_queuing_policy"");");
559 WBI (" Task_Dispatching_Policy : Character;");
560 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
561 """__gl_task_dispatching_policy"");");
562 WBI (" Priority_Specific_Dispatching : System.Address;");
563 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
564 """__gl_priority_specific_dispatching"");");
565 WBI (" Num_Specific_Dispatching : Integer;");
566 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
567 """__gl_num_specific_dispatching"");");
568 WBI (" Main_CPU : Integer;");
569 WBI (" pragma Import (C, Main_CPU, " &
570 """__gl_main_cpu"");");
571
572 WBI (" Interrupt_States : System.Address;");
573 WBI (" pragma Import (C, Interrupt_States, " &
574 """__gl_interrupt_states"");");
575 WBI (" Num_Interrupt_States : Integer;");
576 WBI (" pragma Import (C, Num_Interrupt_States, " &
577 """__gl_num_interrupt_states"");");
578 WBI (" Unreserve_All_Interrupts : Integer;");
579 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
580 """__gl_unreserve_all_interrupts"");");
581
582 if Exception_Tracebacks then
583 WBI (" Exception_Tracebacks : Integer;");
584 WBI (" pragma Import (C, Exception_Tracebacks, " &
585 """__gl_exception_tracebacks"");");
586 end if;
587
588 WBI (" Detect_Blocking : Integer;");
589 WBI (" pragma Import (C, Detect_Blocking, " &
590 """__gl_detect_blocking"");");
591 WBI (" Default_Stack_Size : Integer;");
592 WBI (" pragma Import (C, Default_Stack_Size, " &
593 """__gl_default_stack_size"");");
594 WBI (" Leap_Seconds_Support : Integer;");
595 WBI (" pragma Import (C, Leap_Seconds_Support, " &
596 """__gl_leap_seconds_support"");");
597
598 -- Import entry point for elaboration time signal handler
599 -- installation, and indication of if it's been called previously.
600
601 WBI ("");
602 WBI (" procedure Runtime_Initialize " &
603 "(Install_Handler : Integer);");
604 WBI (" pragma Import (C, Runtime_Initialize, " &
605 """__gnat_runtime_initialize"");");
606
607 -- Import handlers attach procedure for sequential elaboration policy
608
609 if System_Interrupts_Used
610 and then Partition_Elaboration_Policy_Specified = 'S'
611 then
612 WBI (" procedure Install_Restricted_Handlers_Sequential;");
613 WBI (" pragma Import (C," &
614 "Install_Restricted_Handlers_Sequential," &
615 " ""__gnat_attach_all_handlers"");");
616 WBI ("");
617 end if;
618
619 -- Import task activation procedure for sequential elaboration
620 -- policy.
621
622 if System_Tasking_Restricted_Stages_Used
623 and then Partition_Elaboration_Policy_Specified = 'S'
624 then
625 WBI (" Partition_Elaboration_Policy : Character;");
626 WBI (" pragma Import (C, Partition_Elaboration_Policy," &
627 " ""__gnat_partition_elaboration_policy"");");
628 WBI ("");
629 WBI (" procedure Activate_All_Tasks_Sequential;");
630 WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
631 " ""__gnat_activate_all_tasks"");");
632 end if;
633
634 -- For restricted run-time libraries (ZFP and Ravenscar)
635 -- tasks are non-terminating, so we do not want finalization.
636
637 if not Configurable_Run_Time_On_Target then
638 WBI ("");
639 WBI (" Finalize_Library_Objects : No_Param_Proc;");
640 WBI (" pragma Import (C, Finalize_Library_Objects, " &
641 """__gnat_finalize_library_objects"");");
642 end if;
643
644 -- Initialize stack limit variable of the environment task if the
645 -- stack check method is stack limit and stack check is enabled.
646
647 if Stack_Check_Limits_On_Target
648 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
649 then
650 WBI ("");
651 WBI (" procedure Initialize_Stack_Limit;");
652 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
653 """__gnat_initialize_stack_limit"");");
654 end if;
655
656 -- When dispatching domains are used then we need to signal it
657 -- before calling the main procedure.
658
659 if Dispatching_Domains_Used then
660 WBI (" procedure Freeze_Dispatching_Domains;");
661 WBI (" pragma Import");
662 WBI (" (Ada, Freeze_Dispatching_Domains, "
663 & """__gnat_freeze_dispatching_domains"");");
664 end if;
665
666 WBI (" begin");
667 WBI (" if Is_Elaborated then");
668 WBI (" return;");
669 WBI (" end if;");
670 WBI (" Is_Elaborated := True;");
671
672 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
673 -- restriction No_Standard_Allocators_After_Elaboration is active.
674
675 if Cumulative_Restrictions.Set
676 (No_Standard_Allocators_After_Elaboration)
677 then
678 WBI (" System.Elaboration_Allocators."
679 & "Mark_Start_Of_Elaboration;");
680 end if;
681
682 -- Generate assignments to initialize globals
683
684 Set_String (" Main_Priority := ");
685 Set_Int (Main_Priority);
686 Set_Char (';');
687 Write_Statement_Buffer;
688
689 Set_String (" Time_Slice_Value := ");
690
691 if Task_Dispatching_Policy_Specified = 'F'
692 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
693 then
694 Set_Int (0);
695 else
696 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
697 end if;
698
699 Set_Char (';');
700 Write_Statement_Buffer;
701
702 Set_String (" WC_Encoding := '");
703 Set_Char (Get_WC_Encoding);
704
705 Set_String ("';");
706 Write_Statement_Buffer;
707
708 Set_String (" Locking_Policy := '");
709 Set_Char (Locking_Policy_Specified);
710 Set_String ("';");
711 Write_Statement_Buffer;
712
713 Set_String (" Queuing_Policy := '");
714 Set_Char (Queuing_Policy_Specified);
715 Set_String ("';");
716 Write_Statement_Buffer;
717
718 Set_String (" Task_Dispatching_Policy := '");
719 Set_Char (Task_Dispatching_Policy_Specified);
720 Set_String ("';");
721 Write_Statement_Buffer;
722
723 if System_Tasking_Restricted_Stages_Used
724 and then Partition_Elaboration_Policy_Specified = 'S'
725 then
726 Set_String (" Partition_Elaboration_Policy := '");
727 Set_Char (Partition_Elaboration_Policy_Specified);
728 Set_String ("';");
729 Write_Statement_Buffer;
730 end if;
731
732 Gen_Restrictions;
733
734 WBI (" Priority_Specific_Dispatching :=");
735 WBI (" Local_Priority_Specific_Dispatching'Address;");
736
737 Set_String (" Num_Specific_Dispatching := ");
738 Set_Int (PSD_Pragma_Settings.Last + 1);
739 Set_Char (';');
740 Write_Statement_Buffer;
741
742 Set_String (" Main_CPU := ");
743 Set_Int (Main_CPU);
744 Set_Char (';');
745 Write_Statement_Buffer;
746
747 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
748
749 Set_String (" Num_Interrupt_States := ");
750 Set_Int (IS_Pragma_Settings.Last + 1);
751 Set_Char (';');
752 Write_Statement_Buffer;
753
754 Set_String (" Unreserve_All_Interrupts := ");
755
756 if Unreserve_All_Interrupts_Specified then
757 Set_String ("1");
758 else
759 Set_String ("0");
760 end if;
761
762 Set_Char (';');
763 Write_Statement_Buffer;
764
765 if Exception_Tracebacks then
766 WBI (" Exception_Tracebacks := 1;");
767 end if;
768
769 Set_String (" Detect_Blocking := ");
770
771 if Detect_Blocking then
772 Set_Int (1);
773 else
774 Set_Int (0);
775 end if;
776
777 Set_String (";");
778 Write_Statement_Buffer;
779
780 Set_String (" Default_Stack_Size := ");
781 Set_Int (Default_Stack_Size);
782 Set_String (";");
783 Write_Statement_Buffer;
784
785 Set_String (" Leap_Seconds_Support := ");
786
787 if Leap_Seconds_Support then
788 Set_Int (1);
789 else
790 Set_Int (0);
791 end if;
792
793 Set_String (";");
794 Write_Statement_Buffer;
795
796 -- Generate call to Install_Handler
797
798 WBI ("");
799 WBI (" Runtime_Initialize (1);");
800 end if;
801
802 -- Generate call to set Initialize_Scalar values if active
803
804 if Initialize_Scalars_Used then
805 WBI ("");
806 Set_String (" System.Scalar_Values.Initialize ('");
807 Set_Char (Initialize_Scalars_Mode1);
808 Set_String ("', '");
809 Set_Char (Initialize_Scalars_Mode2);
810 Set_String ("');");
811 Write_Statement_Buffer;
812 end if;
813
814 -- Generate assignment of default secondary stack size if set
815
816 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
817 WBI ("");
818 Set_String (" System.Secondary_Stack.");
819 Set_String ("Default_Secondary_Stack_Size := ");
820 Set_Int (Opt.Default_Sec_Stack_Size);
821 Set_Char (';');
822 Write_Statement_Buffer;
823 end if;
824
825 -- Initialize stack limit variable of the environment task if the
826 -- stack check method is stack limit and stack check is enabled.
827
828 if Stack_Check_Limits_On_Target
829 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
830 then
831 WBI ("");
832 WBI (" Initialize_Stack_Limit;");
833 end if;
834
835 -- On CodePeer, the finalization of library objects is not relevant
836
837 if CodePeer_Mode then
838 null;
839
840 -- If this is the main program case, attach finalize_library to the soft
841 -- link. Do it only when not using a restricted run time, in which case
842 -- tasks are non-terminating, so we do not want library-level
843 -- finalization.
844
845 elsif Bind_Main_Program
846 and then not Configurable_Run_Time_On_Target
847 and then not Suppress_Standard_Library_On_Target
848 then
849 WBI ("");
850
851 if Lib_Final_Built then
852 Set_String (" Finalize_Library_Objects := ");
853 Set_String ("finalize_library'access;");
854 else
855 Set_String (" Finalize_Library_Objects := null;");
856 end if;
857
858 Write_Statement_Buffer;
859 end if;
860
861 -- Generate elaboration calls
862
863 if not CodePeer_Mode then
864 WBI ("");
865 end if;
866
867 Gen_Elab_Calls;
868
869 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
870 -- restriction No_Standard_Allocators_After_Elaboration is active.
871
872 if Cumulative_Restrictions.Set
873 (No_Standard_Allocators_After_Elaboration)
874 then
875 WBI (" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
876 end if;
877
878 -- From this point, no new dispatching domain can be created
879
880 if Dispatching_Domains_Used then
881 WBI (" Freeze_Dispatching_Domains;");
882 end if;
883
884 -- Sequential partition elaboration policy
885
886 if Partition_Elaboration_Policy_Specified = 'S' then
887 if System_Interrupts_Used then
888 WBI (" Install_Restricted_Handlers_Sequential;");
889 end if;
890
891 if System_Tasking_Restricted_Stages_Used then
892 WBI (" Activate_All_Tasks_Sequential;");
893 end if;
894 end if;
895
896 WBI (" end " & Ada_Init_Name.all & ";");
897 WBI ("");
898 end Gen_Adainit;
899
900 --------------------------
901 -- Gen_CodePeer_Wrapper --
902 --------------------------
903
904 procedure Gen_CodePeer_Wrapper is
905 Callee_Name : constant String := "Ada_Main_Program";
906
907 begin
908 if ALIs.Table (ALIs.First).Main_Program = Proc then
909 WBI (" procedure " & CodePeer_Wrapper_Name & " is ");
910 WBI (" begin");
911 WBI (" " & Callee_Name & ";");
912
913 else
914 WBI (" function " & CodePeer_Wrapper_Name & " return Integer is");
915 WBI (" begin");
916 WBI (" return " & Callee_Name & ";");
917 end if;
918
919 WBI (" end " & CodePeer_Wrapper_Name & ";");
920 WBI ("");
921 end Gen_CodePeer_Wrapper;
922
923 --------------------
924 -- Gen_Elab_Calls --
925 --------------------
926
927 procedure Gen_Elab_Calls is
928 Check_Elab_Flag : Boolean;
929
930 begin
931 -- Loop through elaboration order entries
932
933 for E in Elab_Order.First .. Elab_Order.Last loop
934 declare
935 Unum : constant Unit_Id := Elab_Order.Table (E);
936 U : Unit_Record renames Units.Table (Unum);
937
938 Unum_Spec : Unit_Id;
939 -- This is the unit number of the spec that corresponds to
940 -- this entry. It is the same as Unum except when the body
941 -- and spec are different and we are currently processing
942 -- the body, in which case it is the spec (Unum + 1).
943
944 begin
945 if U.Utype = Is_Body then
946 Unum_Spec := Unum + 1;
947 else
948 Unum_Spec := Unum;
949 end if;
950
951 -- Nothing to do if predefined unit in no run time mode
952
953 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
954 null;
955
956 -- Likewise if this is an interface to a stand alone library
957
958 elsif U.SAL_Interface then
959 null;
960
961 -- Case of no elaboration code
962
963 elsif U.No_Elab
964
965 -- In CodePeer mode, we special case subprogram bodies which
966 -- are handled in the 'else' part below, and lead to a call
967 -- to <subp>'Elab_Subp_Body.
968
969 and then (not CodePeer_Mode
970
971 -- Test for spec
972
973 or else U.Utype = Is_Spec
974 or else U.Utype = Is_Spec_Only
975 or else U.Unit_Kind /= 's')
976 then
977 -- In the case of a body with a separate spec, where the
978 -- separate spec has an elaboration entity defined, this is
979 -- where we increment the elaboration entity if one exists
980
981 if U.Utype = Is_Body
982 and then Units.Table (Unum_Spec).Set_Elab_Entity
983 and then not CodePeer_Mode
984 then
985 Set_String (" E");
986 Set_Unit_Number (Unum_Spec);
987
988 -- The AAMP target has no notion of shared libraries, and
989 -- there's no possibility of reelaboration, so we treat the
990 -- the elaboration var as a flag instead of a counter and
991 -- simply set it.
992
993 if AAMP_On_Target then
994 Set_String (" := 1;");
995
996 -- Otherwise (normal case), increment elaboration counter
997
998 else
999 Set_String (" := E");
1000 Set_Unit_Number (Unum_Spec);
1001 Set_String (" + 1;");
1002 end if;
1003
1004 Write_Statement_Buffer;
1005
1006 -- In the special case where the target is AAMP and the unit is
1007 -- a spec with a body, the elaboration entity is initialized
1008 -- here. This is done because it's the only way to accomplish
1009 -- initialization of such entities, as there is no mechanism
1010 -- for load time global variable initialization on AAMP.
1011
1012 elsif AAMP_On_Target
1013 and then U.Utype = Is_Spec
1014 and then Units.Table (Unum_Spec).Set_Elab_Entity
1015 then
1016 Set_String (" E");
1017 Set_Unit_Number (Unum_Spec);
1018 Set_String (" := 0;");
1019 Write_Statement_Buffer;
1020 end if;
1021
1022 -- Here if elaboration code is present. If binding a library
1023 -- or if there is a non-Ada main subprogram then we generate:
1024
1025 -- if uname_E = 0 then
1026 -- uname'elab_[spec|body];
1027 -- end if;
1028 -- uname_E := uname_E + 1;
1029
1030 -- Otherwise, elaboration routines are called unconditionally:
1031
1032 -- uname'elab_[spec|body];
1033 -- uname_E := uname_E + 1;
1034
1035 -- The uname_E increment is skipped if this is a separate spec,
1036 -- since it will be done when we process the body.
1037
1038 -- In CodePeer mode, we do not generate any reference to xxx_E
1039 -- variables, only calls to 'Elab* subprograms.
1040
1041 else
1042 -- In the special case where the target is AAMP and the unit is
1043 -- a spec with a body, the elaboration entity is initialized
1044 -- here. This is done because it's the only way to accomplish
1045 -- initialization of such entities, as there is no mechanism
1046 -- for load time global variable initialization on AAMP.
1047
1048 if AAMP_On_Target
1049 and then U.Utype = Is_Spec
1050 and then Units.Table (Unum_Spec).Set_Elab_Entity
1051 then
1052 Set_String (" E");
1053 Set_Unit_Number (Unum_Spec);
1054 Set_String (" := 0;");
1055 Write_Statement_Buffer;
1056 end if;
1057
1058 -- Check incompatibilities with No_Multiple_Elaboration
1059
1060 if not CodePeer_Mode
1061 and then Cumulative_Restrictions.Set (No_Multiple_Elaboration)
1062 then
1063 -- Force_Checking_Of_Elaboration_Flags (-F) not allowed
1064
1065 if Force_Checking_Of_Elaboration_Flags then
1066 Osint.Fail
1067 ("-F (force elaboration checks) switch not allowed "
1068 & "with restriction No_Multiple_Elaboration active");
1069
1070 -- Interfacing of libraries not allowed
1071
1072 elsif Interface_Library_Unit then
1073 Osint.Fail
1074 ("binding of interfaced libraries not allowed "
1075 & "with restriction No_Multiple_Elaboration active");
1076
1077 -- Non-Ada main program not allowed
1078
1079 elsif not Bind_Main_Program then
1080 Osint.Fail
1081 ("non-Ada main program not allowed "
1082 & "with restriction No_Multiple_Elaboration active");
1083 end if;
1084 end if;
1085
1086 -- OK, see if we need to test elaboration flag
1087
1088 Check_Elab_Flag :=
1089 Units.Table (Unum_Spec).Set_Elab_Entity
1090 and then not CodePeer_Mode
1091 and then (Force_Checking_Of_Elaboration_Flags
1092 or Interface_Library_Unit
1093 or not Bind_Main_Program);
1094
1095 if Check_Elab_Flag then
1096 Set_String (" if E");
1097 Set_Unit_Number (Unum_Spec);
1098 Set_String (" = 0 then");
1099 Write_Statement_Buffer;
1100 Set_String (" ");
1101 end if;
1102
1103 Set_String (" ");
1104 Get_Decoded_Name_String_With_Brackets (U.Uname);
1105
1106 if Name_Buffer (Name_Len) = 's' then
1107 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1108 "'elab_spec";
1109 Name_Len := Name_Len + 8;
1110
1111 -- Special case in CodePeer mode for subprogram bodies
1112 -- which correspond to CodePeer 'Elab_Subp_Body special
1113 -- init procedure.
1114
1115 elsif U.Unit_Kind = 's' and CodePeer_Mode then
1116 Name_Buffer (Name_Len - 1 .. Name_Len + 13) :=
1117 "'elab_subp_body";
1118 Name_Len := Name_Len + 13;
1119
1120 else
1121 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1122 "'elab_body";
1123 Name_Len := Name_Len + 8;
1124 end if;
1125
1126 Set_Casing (U.Icasing);
1127 Set_Name_Buffer;
1128 Set_Char (';');
1129 Write_Statement_Buffer;
1130
1131 if Check_Elab_Flag then
1132 WBI (" end if;");
1133 end if;
1134
1135 if U.Utype /= Is_Spec
1136 and then not CodePeer_Mode
1137 and then Units.Table (Unum_Spec).Set_Elab_Entity
1138 then
1139 Set_String (" E");
1140 Set_Unit_Number (Unum_Spec);
1141
1142 -- The AAMP target has no notion of shared libraries, and
1143 -- there's no possibility of reelaboration, so we treat the
1144 -- the elaboration var as a flag instead of a counter and
1145 -- simply set it.
1146
1147 if AAMP_On_Target then
1148 Set_String (" := 1;");
1149
1150 -- Otherwise (normal case), increment elaboration counter
1151
1152 else
1153 Set_String (" := E");
1154 Set_Unit_Number (Unum_Spec);
1155 Set_String (" + 1;");
1156 end if;
1157
1158 Write_Statement_Buffer;
1159 end if;
1160 end if;
1161 end;
1162 end loop;
1163 end Gen_Elab_Calls;
1164
1165 ------------------------
1166 -- Gen_Elab_Externals --
1167 ------------------------
1168
1169 procedure Gen_Elab_Externals is
1170 begin
1171 if CodePeer_Mode then
1172 return;
1173 end if;
1174
1175 for E in Elab_Order.First .. Elab_Order.Last loop
1176 declare
1177 Unum : constant Unit_Id := Elab_Order.Table (E);
1178 U : Unit_Record renames Units.Table (Unum);
1179
1180 begin
1181 -- Check for Elab_Entity to be set for this unit
1182
1183 if U.Set_Elab_Entity
1184
1185 -- Don't generate reference for stand alone library
1186
1187 and then not U.SAL_Interface
1188
1189 -- Don't generate reference for predefined file in No_Run_Time
1190 -- mode, since we don't include the object files in this case
1191
1192 and then not
1193 (No_Run_Time_Mode
1194 and then Is_Predefined_File_Name (U.Sfile))
1195 then
1196 Set_String (" ");
1197 Set_String ("E");
1198 Set_Unit_Number (Unum);
1199 Set_String (" : Short_Integer; pragma Import (Ada, E");
1200 Set_Unit_Number (Unum);
1201 Set_String (", """);
1202 Get_Name_String (U.Uname);
1203 Set_Unit_Name;
1204 Set_String ("_E"");");
1205 Write_Statement_Buffer;
1206 end if;
1207 end;
1208 end loop;
1209
1210 WBI ("");
1211 end Gen_Elab_Externals;
1212
1213 --------------------
1214 -- Gen_Elab_Order --
1215 --------------------
1216
1217 procedure Gen_Elab_Order is
1218 begin
1219 WBI (" -- BEGIN ELABORATION ORDER");
1220
1221 for J in Elab_Order.First .. Elab_Order.Last loop
1222 Set_String (" -- ");
1223 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1224 Set_Name_Buffer;
1225 Write_Statement_Buffer;
1226 end loop;
1227
1228 WBI (" -- END ELABORATION ORDER");
1229 WBI ("");
1230 end Gen_Elab_Order;
1231
1232 --------------------------
1233 -- Gen_Finalize_Library --
1234 --------------------------
1235
1236 procedure Gen_Finalize_Library is
1237 Count : Int := 1;
1238 U : Unit_Record;
1239 Uspec : Unit_Record;
1240 Unum : Unit_Id;
1241
1242 procedure Gen_Header;
1243 -- Generate the header of the finalization routine
1244
1245 ----------------
1246 -- Gen_Header --
1247 ----------------
1248
1249 procedure Gen_Header is
1250 begin
1251 WBI (" procedure finalize_library is");
1252 WBI (" begin");
1253 end Gen_Header;
1254
1255 -- Start of processing for Gen_Finalize_Library
1256
1257 begin
1258 if CodePeer_Mode then
1259 return;
1260 end if;
1261
1262 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1263 Unum := Elab_Order.Table (E);
1264 U := Units.Table (Unum);
1265
1266 -- Dealing with package bodies is a little complicated. In such
1267 -- cases we must retrieve the package spec since it contains the
1268 -- spec of the body finalizer.
1269
1270 if U.Utype = Is_Body then
1271 Unum := Unum + 1;
1272 Uspec := Units.Table (Unum);
1273 else
1274 Uspec := U;
1275 end if;
1276
1277 Get_Name_String (Uspec.Uname);
1278
1279 -- We are only interested in non-generic packages
1280
1281 if U.Unit_Kind /= 'p' or else U.Is_Generic then
1282 null;
1283
1284 -- That aren't an interface to a stand alone library
1285
1286 elsif U.SAL_Interface then
1287 null;
1288
1289 -- Case of no finalization
1290
1291 elsif not U.Has_Finalizer then
1292
1293 -- The only case in which we have to do something is if this
1294 -- is a body, with a separate spec, where the separate spec
1295 -- has a finalizer. In that case, this is where we decrement
1296 -- the elaboration entity.
1297
1298 if U.Utype = Is_Body and then Uspec.Has_Finalizer then
1299 if not Lib_Final_Built then
1300 Gen_Header;
1301 Lib_Final_Built := True;
1302 end if;
1303
1304 Set_String (" E");
1305 Set_Unit_Number (Unum);
1306 Set_String (" := E");
1307 Set_Unit_Number (Unum);
1308 Set_String (" - 1;");
1309 Write_Statement_Buffer;
1310 end if;
1311
1312 else
1313 if not Lib_Final_Built then
1314 Gen_Header;
1315 Lib_Final_Built := True;
1316 end if;
1317
1318 -- Generate:
1319 -- declare
1320 -- procedure F<Count>;
1321
1322 Set_String (" declare");
1323 Write_Statement_Buffer;
1324
1325 Set_String (" procedure F");
1326 Set_Int (Count);
1327 Set_Char (';');
1328 Write_Statement_Buffer;
1329
1330 -- Generate:
1331 -- pragma Import (Ada, F<Count>,
1332 -- "xx__yy__finalize_[body|spec]");
1333
1334 Set_String (" pragma Import (Ada, F");
1335 Set_Int (Count);
1336 Set_String (", """);
1337
1338 -- Perform name construction
1339
1340 Set_Unit_Name;
1341 Set_String ("__finalize_");
1342
1343 -- Package spec processing
1344
1345 if U.Utype = Is_Spec
1346 or else U.Utype = Is_Spec_Only
1347 then
1348 Set_String ("spec");
1349
1350 -- Package body processing
1351
1352 else
1353 Set_String ("body");
1354 end if;
1355
1356 Set_String (""");");
1357 Write_Statement_Buffer;
1358
1359 -- If binding a library or if there is a non-Ada main subprogram
1360 -- then we generate:
1361
1362 -- begin
1363 -- uname_E := uname_E - 1;
1364 -- if uname_E = 0 then
1365 -- F<Count>;
1366 -- end if;
1367 -- end;
1368
1369 -- Otherwise, finalization routines are called unconditionally:
1370
1371 -- begin
1372 -- uname_E := uname_E - 1;
1373 -- F<Count>;
1374 -- end;
1375
1376 -- The uname_E decrement is skipped if this is a separate spec,
1377 -- since it will be done when we process the body.
1378
1379 WBI (" begin");
1380
1381 if U.Utype /= Is_Spec then
1382 Set_String (" E");
1383 Set_Unit_Number (Unum);
1384 Set_String (" := E");
1385 Set_Unit_Number (Unum);
1386 Set_String (" - 1;");
1387 Write_Statement_Buffer;
1388 end if;
1389
1390 if Interface_Library_Unit or not Bind_Main_Program then
1391 Set_String (" if E");
1392 Set_Unit_Number (Unum);
1393 Set_String (" = 0 then");
1394 Write_Statement_Buffer;
1395 Set_String (" ");
1396 end if;
1397
1398 Set_String (" F");
1399 Set_Int (Count);
1400 Set_Char (';');
1401 Write_Statement_Buffer;
1402
1403 if Interface_Library_Unit or not Bind_Main_Program then
1404 WBI (" end if;");
1405 end if;
1406
1407 WBI (" end;");
1408
1409 Count := Count + 1;
1410 end if;
1411 end loop;
1412
1413 if Lib_Final_Built then
1414
1415 -- It is possible that the finalization of a library-level object
1416 -- raised an exception. In that case import the actual exception
1417 -- and the routine necessary to raise it.
1418
1419 WBI (" declare");
1420 WBI (" procedure Reraise_Library_Exception_If_Any;");
1421
1422 Set_String (" pragma Import (Ada, ");
1423 Set_String ("Reraise_Library_Exception_If_Any, ");
1424 Set_String ("""__gnat_reraise_library_exception_if_any"");");
1425 Write_Statement_Buffer;
1426
1427 WBI (" begin");
1428 WBI (" Reraise_Library_Exception_If_Any;");
1429 WBI (" end;");
1430 WBI (" end finalize_library;");
1431 WBI ("");
1432 end if;
1433 end Gen_Finalize_Library;
1434
1435 --------------
1436 -- Gen_Main --
1437 --------------
1438
1439 procedure Gen_Main is
1440 begin
1441 if not No_Main_Subprogram then
1442
1443 -- To call the main program, we declare it using a pragma Import
1444 -- Ada with the right link name.
1445
1446 -- It might seem more obvious to "with" the main program, and call
1447 -- it in the normal Ada manner. We do not do this for three
1448 -- reasons:
1449
1450 -- 1. It is more efficient not to recompile the main program
1451 -- 2. We are not entitled to assume the source is accessible
1452 -- 3. We don't know what options to use to compile it
1453
1454 -- It is really reason 3 that is most critical (indeed we used
1455 -- to generate the "with", but several regression tests failed).
1456
1457 if ALIs.Table (ALIs.First).Main_Program = Func then
1458 WBI (" function Ada_Main_Program return Integer;");
1459 else
1460 WBI (" procedure Ada_Main_Program;");
1461 end if;
1462
1463 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1464 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1465 Set_Main_Program_Name;
1466 Set_String (""");");
1467
1468 Write_Statement_Buffer;
1469 WBI ("");
1470
1471 -- For CodePeer, declare a wrapper for the user-defined main program
1472
1473 if CodePeer_Mode then
1474 Gen_CodePeer_Wrapper;
1475 end if;
1476 end if;
1477
1478 if Exit_Status_Supported_On_Target then
1479 Set_String (" function ");
1480 else
1481 Set_String (" procedure ");
1482 end if;
1483
1484 Set_String (Get_Main_Name);
1485
1486 if Command_Line_Args_On_Target then
1487 Write_Statement_Buffer;
1488 WBI (" (argc : Integer;");
1489 WBI (" argv : System.Address;");
1490 WBI (" envp : System.Address)");
1491
1492 if Exit_Status_Supported_On_Target then
1493 WBI (" return Integer");
1494 end if;
1495
1496 WBI (" is");
1497
1498 else
1499 if Exit_Status_Supported_On_Target then
1500 Set_String (" return Integer is");
1501 else
1502 Set_String (" is");
1503 end if;
1504
1505 Write_Statement_Buffer;
1506 end if;
1507
1508 if Opt.Default_Exit_Status /= 0
1509 and then Bind_Main_Program
1510 and then not Configurable_Run_Time_Mode
1511 then
1512 WBI (" procedure Set_Exit_Status (Status : Integer);");
1513 WBI (" pragma Import (C, Set_Exit_Status, " &
1514 """__gnat_set_exit_status"");");
1515 WBI ("");
1516 end if;
1517
1518 -- Initialize and Finalize
1519
1520 if not CodePeer_Mode
1521 and then not Cumulative_Restrictions.Set (No_Finalization)
1522 then
1523 WBI (" procedure Initialize (Addr : System.Address);");
1524 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1525 WBI ("");
1526 WBI (" procedure Finalize;");
1527 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1528 end if;
1529
1530 -- If we want to analyze the stack, we must import corresponding symbols
1531
1532 if Dynamic_Stack_Measurement then
1533 WBI ("");
1534 WBI (" procedure Output_Results;");
1535 WBI (" pragma Import (C, Output_Results, " &
1536 """__gnat_stack_usage_output_results"");");
1537
1538 WBI ("");
1539 WBI (" " &
1540 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1541 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1542 """__gnat_stack_usage_initialize"");");
1543 end if;
1544
1545 -- Deal with declarations for main program case
1546
1547 if not No_Main_Subprogram then
1548 if ALIs.Table (ALIs.First).Main_Program = Func then
1549 WBI (" Result : Integer;");
1550 WBI ("");
1551 end if;
1552
1553 if Bind_Main_Program
1554 and not Suppress_Standard_Library_On_Target
1555 and not CodePeer_Mode
1556 then
1557 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1558 WBI ("");
1559 end if;
1560 end if;
1561
1562 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1563 -- not referenced elsewhere in the generated program, but is needed
1564 -- by the debugger (that's why it is generated in the first place).
1565 -- The reference stops Ada_Main_Program_Name from being optimized
1566 -- away by smart linkers, such as the AiX linker.
1567
1568 -- Because this variable is unused, we make this variable "aliased"
1569 -- with a pragma Volatile in order to tell the compiler to preserve
1570 -- this variable at any level of optimization.
1571
1572 if Bind_Main_Program and not CodePeer_Mode then
1573 WBI (" Ensure_Reference : aliased System.Address := " &
1574 "Ada_Main_Program_Name'Address;");
1575 WBI (" pragma Volatile (Ensure_Reference);");
1576 WBI ("");
1577 end if;
1578
1579 WBI (" begin");
1580
1581 -- Acquire command line arguments if present on target
1582
1583 if CodePeer_Mode then
1584 null;
1585
1586 elsif Command_Line_Args_On_Target then
1587 WBI (" gnat_argc := argc;");
1588 WBI (" gnat_argv := argv;");
1589 WBI (" gnat_envp := envp;");
1590 WBI ("");
1591
1592 -- If configurable run time and no command line args, then nothing
1593 -- needs to be done since the gnat_argc/argv/envp variables are
1594 -- suppressed in this case.
1595
1596 elsif Configurable_Run_Time_On_Target then
1597 null;
1598
1599 -- Otherwise set dummy values (to be filled in by some other unit?)
1600
1601 else
1602 WBI (" gnat_argc := 0;");
1603 WBI (" gnat_argv := System.Null_Address;");
1604 WBI (" gnat_envp := System.Null_Address;");
1605 end if;
1606
1607 if Opt.Default_Exit_Status /= 0
1608 and then Bind_Main_Program
1609 and then not Configurable_Run_Time_Mode
1610 then
1611 Set_String (" Set_Exit_Status (");
1612 Set_Int (Opt.Default_Exit_Status);
1613 Set_String (");");
1614 Write_Statement_Buffer;
1615 end if;
1616
1617 if Dynamic_Stack_Measurement then
1618 Set_String (" Initialize_Stack_Analysis (");
1619 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1620 Set_String (");");
1621 Write_Statement_Buffer;
1622 end if;
1623
1624 if not Cumulative_Restrictions.Set (No_Finalization)
1625 and then not CodePeer_Mode
1626 then
1627 if not No_Main_Subprogram
1628 and then Bind_Main_Program
1629 and then not Suppress_Standard_Library_On_Target
1630 then
1631 WBI (" Initialize (SEH'Address);");
1632 else
1633 WBI (" Initialize (System.Null_Address);");
1634 end if;
1635 end if;
1636
1637 WBI (" " & Ada_Init_Name.all & ";");
1638
1639 if not No_Main_Subprogram then
1640 if CodePeer_Mode then
1641 if ALIs.Table (ALIs.First).Main_Program = Proc then
1642 WBI (" " & CodePeer_Wrapper_Name & ";");
1643 else
1644 WBI (" Result := " & CodePeer_Wrapper_Name & ";");
1645 end if;
1646
1647 elsif ALIs.Table (ALIs.First).Main_Program = Proc then
1648 WBI (" Ada_Main_Program;");
1649
1650 else
1651 WBI (" Result := Ada_Main_Program;");
1652 end if;
1653 end if;
1654
1655 -- Adafinal call is skipped if no finalization
1656
1657 if not Cumulative_Restrictions.Set (No_Finalization) then
1658 WBI (" adafinal;");
1659 end if;
1660
1661 -- Prints the result of static stack analysis
1662
1663 if Dynamic_Stack_Measurement then
1664 WBI (" Output_Results;");
1665 end if;
1666
1667 -- Finalize is only called if we have a run time
1668
1669 if not Cumulative_Restrictions.Set (No_Finalization)
1670 and then not CodePeer_Mode
1671 then
1672 WBI (" Finalize;");
1673 end if;
1674
1675 -- Return result
1676
1677 if Exit_Status_Supported_On_Target then
1678 if No_Main_Subprogram
1679 or else ALIs.Table (ALIs.First).Main_Program = Proc
1680 then
1681 WBI (" return (gnat_exit_status);");
1682 else
1683 WBI (" return (Result);");
1684 end if;
1685 end if;
1686
1687 WBI (" end;");
1688 WBI ("");
1689 end Gen_Main;
1690
1691 ------------------------------
1692 -- Gen_Object_Files_Options --
1693 ------------------------------
1694
1695 procedure Gen_Object_Files_Options is
1696 Lgnat : Natural;
1697 -- This keeps track of the position in the sorted set of entries
1698 -- in the Linker_Options table of where the first entry from an
1699 -- internal file appears.
1700
1701 Linker_Option_List_Started : Boolean := False;
1702 -- Set to True when "LINKER OPTION LIST" is displayed
1703
1704 procedure Write_Linker_Option;
1705 -- Write binder info linker option
1706
1707 -------------------------
1708 -- Write_Linker_Option --
1709 -------------------------
1710
1711 procedure Write_Linker_Option is
1712 Start : Natural;
1713 Stop : Natural;
1714
1715 begin
1716 -- Loop through string, breaking at null's
1717
1718 Start := 1;
1719 while Start < Name_Len loop
1720
1721 -- Find null ending this section
1722
1723 Stop := Start + 1;
1724 while Name_Buffer (Stop) /= ASCII.NUL
1725 and then Stop <= Name_Len loop
1726 Stop := Stop + 1;
1727 end loop;
1728
1729 -- Process section if non-null
1730
1731 if Stop > Start then
1732 if Output_Linker_Option_List then
1733 if not Zero_Formatting then
1734 if not Linker_Option_List_Started then
1735 Linker_Option_List_Started := True;
1736 Write_Eol;
1737 Write_Str (" LINKER OPTION LIST");
1738 Write_Eol;
1739 Write_Eol;
1740 end if;
1741
1742 Write_Str (" ");
1743 end if;
1744
1745 Write_Str (Name_Buffer (Start .. Stop - 1));
1746 Write_Eol;
1747 end if;
1748 WBI (" -- " & Name_Buffer (Start .. Stop - 1));
1749 end if;
1750
1751 Start := Stop + 1;
1752 end loop;
1753 end Write_Linker_Option;
1754
1755 -- Start of processing for Gen_Object_Files_Options
1756
1757 begin
1758 WBI ("-- BEGIN Object file/option list");
1759
1760 if Object_List_Filename /= null then
1761 Set_List_File (Object_List_Filename.all);
1762 end if;
1763
1764 for E in Elab_Order.First .. Elab_Order.Last loop
1765
1766 -- If not spec that has an associated body, then generate a comment
1767 -- giving the name of the corresponding object file.
1768
1769 if not Units.Table (Elab_Order.Table (E)).SAL_Interface
1770 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1771 then
1772 Get_Name_String
1773 (ALIs.Table
1774 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1775
1776 -- If the presence of an object file is necessary or if it exists,
1777 -- then use it.
1778
1779 if not Hostparm.Exclude_Missing_Objects
1780 or else
1781 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1782 then
1783 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1784
1785 if Output_Object_List then
1786 Write_Str (Name_Buffer (1 .. Name_Len));
1787 Write_Eol;
1788 end if;
1789 end if;
1790 end if;
1791 end loop;
1792
1793 if Object_List_Filename /= null then
1794 Close_List_File;
1795 end if;
1796
1797 -- Add a "-Ldir" for each directory in the object path
1798
1799 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1800 declare
1801 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1802 begin
1803 Name_Len := 0;
1804 Add_Str_To_Name_Buffer ("-L");
1805 Add_Str_To_Name_Buffer (Dir.all);
1806 Write_Linker_Option;
1807 end;
1808 end loop;
1809
1810 if not (Opt.No_Run_Time_Mode or Opt.No_Stdlib) then
1811 Name_Len := 0;
1812
1813 if Opt.Shared_Libgnat then
1814 Add_Str_To_Name_Buffer ("-shared");
1815 else
1816 Add_Str_To_Name_Buffer ("-static");
1817 end if;
1818
1819 -- Write directly to avoid inclusion in -K output as -static and
1820 -- -shared are not usually specified linker options.
1821
1822 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1823 end if;
1824
1825 -- Sort linker options
1826
1827 -- This sort accomplishes two important purposes:
1828
1829 -- a) All application files are sorted to the front, and all GNAT
1830 -- internal files are sorted to the end. This results in a well
1831 -- defined dividing line between the two sets of files, for the
1832 -- purpose of inserting certain standard library references into
1833 -- the linker arguments list.
1834
1835 -- b) Given two different units, we sort the linker options so that
1836 -- those from a unit earlier in the elaboration order comes later
1837 -- in the list. This is a heuristic designed to create a more
1838 -- friendly order of linker options when the operations appear in
1839 -- separate units. The idea is that if unit A must be elaborated
1840 -- before unit B, then it is more likely that B references
1841 -- libraries included by A, than vice versa, so we want libraries
1842 -- included by A to come after libraries included by B.
1843
1844 -- These two criteria are implemented by function Lt_Linker_Option. Note
1845 -- that a special case of b) is that specs are elaborated before bodies,
1846 -- so linker options from specs come after linker options for bodies,
1847 -- and again, the assumption is that libraries used by the body are more
1848 -- likely to reference libraries used by the spec, than vice versa.
1849
1850 Sort
1851 (Linker_Options.Last,
1852 Move_Linker_Option'Access,
1853 Lt_Linker_Option'Access);
1854
1855 -- Write user linker options, i.e. the set of linker options that come
1856 -- from all files other than GNAT internal files, Lgnat is left set to
1857 -- point to the first entry from a GNAT internal file, or past the end
1858 -- of the entries if there are no internal files.
1859
1860 Lgnat := Linker_Options.Last + 1;
1861
1862 for J in 1 .. Linker_Options.Last loop
1863 if not Linker_Options.Table (J).Internal_File then
1864 Get_Name_String (Linker_Options.Table (J).Name);
1865 Write_Linker_Option;
1866 else
1867 Lgnat := J;
1868 exit;
1869 end if;
1870 end loop;
1871
1872 -- Now we insert standard linker options that must appear after the
1873 -- entries from user files, and before the entries from GNAT run-time
1874 -- files. The reason for this decision is that libraries referenced
1875 -- by internal routines may reference these standard library entries.
1876
1877 -- Note that we do not insert anything when pragma No_Run_Time has
1878 -- been specified or when the standard libraries are not to be used,
1879 -- otherwise on some platforms, we may get duplicate symbols when
1880 -- linking (not clear if this is still the case, but it is harmless).
1881
1882 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
1883 if With_GNARL then
1884 Name_Len := 0;
1885
1886 if Opt.Shared_Libgnat then
1887 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1888 else
1889 Add_Str_To_Name_Buffer ("-lgnarl");
1890 end if;
1891
1892 Write_Linker_Option;
1893 end if;
1894
1895 Name_Len := 0;
1896
1897 if Opt.Shared_Libgnat then
1898 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1899 else
1900 Add_Str_To_Name_Buffer ("-lgnat");
1901 end if;
1902
1903 Write_Linker_Option;
1904 end if;
1905
1906 -- Write linker options from all internal files
1907
1908 for J in Lgnat .. Linker_Options.Last loop
1909 Get_Name_String (Linker_Options.Table (J).Name);
1910 Write_Linker_Option;
1911 end loop;
1912
1913 if Output_Linker_Option_List and then not Zero_Formatting then
1914 Write_Eol;
1915 end if;
1916
1917 WBI ("-- END Object file/option list ");
1918 end Gen_Object_Files_Options;
1919
1920 ---------------------
1921 -- Gen_Output_File --
1922 ---------------------
1923
1924 procedure Gen_Output_File (Filename : String) is
1925 begin
1926 -- Acquire settings for Interrupt_State pragmas
1927
1928 Set_IS_Pragma_Table;
1929
1930 -- Acquire settings for Priority_Specific_Dispatching pragma
1931
1932 Set_PSD_Pragma_Table;
1933
1934 -- Override time slice value if -T switch is set
1935
1936 if Time_Slice_Set then
1937 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
1938 end if;
1939
1940 -- Count number of elaboration calls
1941
1942 for E in Elab_Order.First .. Elab_Order.Last loop
1943 if Units.Table (Elab_Order.Table (E)).No_Elab then
1944 null;
1945 else
1946 Num_Elab_Calls := Num_Elab_Calls + 1;
1947 end if;
1948 end loop;
1949
1950 -- Generate output file in appropriate language
1951
1952 Gen_Output_File_Ada (Filename);
1953 end Gen_Output_File;
1954
1955 -------------------------
1956 -- Gen_Output_File_Ada --
1957 -------------------------
1958
1959 procedure Gen_Output_File_Ada (Filename : String) is
1960
1961 Ada_Main : constant String := Get_Ada_Main_Name;
1962 -- Name to be used for generated Ada main program. See the body of
1963 -- function Get_Ada_Main_Name for details on the form of the name.
1964
1965 Needs_Library_Finalization : constant Boolean :=
1966 not Configurable_Run_Time_On_Target and then Has_Finalizer;
1967 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
1968 -- non-terminating, so we do not want finalization.
1969
1970 Bfiles : Name_Id;
1971 -- Name of generated bind file (spec)
1972
1973 Bfileb : Name_Id;
1974 -- Name of generated bind file (body)
1975
1976 begin
1977 -- Create spec first
1978
1979 Create_Binder_Output (Filename, 's', Bfiles);
1980
1981 -- We always compile the binder file in Ada 95 mode so that we properly
1982 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
1983 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
1984
1985 WBI ("pragma Ada_95;");
1986 WBI ("pragma Warnings (Off);");
1987
1988 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
1989 -- then we need to make sure that the binder program is compiled with
1990 -- the same restriction, so that no exception tables are generated.
1991
1992 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
1993 WBI ("pragma Restrictions (No_Exception_Handlers);");
1994 end if;
1995
1996 -- Same processing for Restrictions (No_Exception_Propagation)
1997
1998 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
1999 WBI ("pragma Restrictions (No_Exception_Propagation);");
2000 end if;
2001
2002 -- Same processing for pragma No_Run_Time
2003
2004 if No_Run_Time_Mode then
2005 WBI ("pragma No_Run_Time;");
2006 end if;
2007
2008 -- Generate with of System so we can reference System.Address
2009
2010 WBI ("with System;");
2011
2012 -- Generate with of System.Initialize_Scalars if active
2013
2014 if Initialize_Scalars_Used then
2015 WBI ("with System.Scalar_Values;");
2016 end if;
2017
2018 -- Generate with of System.Secondary_Stack if active
2019
2020 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2021 WBI ("with System.Secondary_Stack;");
2022 end if;
2023
2024 Resolve_Binder_Options;
2025
2026 -- Generate standard with's
2027
2028 if not Suppress_Standard_Library_On_Target then
2029 if CodePeer_Mode then
2030 WBI ("with System.Standard_Library;");
2031 end if;
2032 end if;
2033
2034 WBI ("package " & Ada_Main & " is");
2035
2036 -- Main program case
2037
2038 if Bind_Main_Program then
2039 -- Generate argc/argv stuff unless suppressed
2040
2041 if Command_Line_Args_On_Target
2042 or not Configurable_Run_Time_On_Target
2043 then
2044 WBI ("");
2045 WBI (" gnat_argc : Integer;");
2046 WBI (" gnat_argv : System.Address;");
2047 WBI (" gnat_envp : System.Address;");
2048
2049 -- If the standard library is not suppressed, these variables
2050 -- are in the run-time data area for easy run time access.
2051
2052 if not Suppress_Standard_Library_On_Target then
2053 WBI ("");
2054 WBI (" pragma Import (C, gnat_argc);");
2055 WBI (" pragma Import (C, gnat_argv);");
2056 WBI (" pragma Import (C, gnat_envp);");
2057 end if;
2058 end if;
2059
2060 -- Define exit status. Again in normal mode, this is in the
2061 -- run-time library, and is initialized there, but in the
2062 -- configurable runtime case, the variable is declared and
2063 -- initialized in this file.
2064
2065 WBI ("");
2066
2067 if Configurable_Run_Time_Mode then
2068 if Exit_Status_Supported_On_Target then
2069 WBI (" gnat_exit_status : Integer := 0;");
2070 end if;
2071
2072 else
2073 WBI (" gnat_exit_status : Integer;");
2074 WBI (" pragma Import (C, gnat_exit_status);");
2075 end if;
2076
2077 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2078 -- the main program. Otherwise, it can lead under some circumstances
2079 -- to a symbol duplication during the link (for instance when a C
2080 -- program uses two Ada libraries). Also zero terminate the string
2081 -- so that its end can be found reliably at run time.
2082
2083 WBI ("");
2084 WBI (" GNAT_Version : constant String :=");
2085 WBI (" """ & Ver_Prefix &
2086 Gnat_Version_String &
2087 """ & ASCII.NUL;");
2088 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2089
2090 WBI ("");
2091 Set_String (" Ada_Main_Program_Name : constant String := """);
2092 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2093
2094 Set_Main_Program_Name;
2095 Set_String (""" & ASCII.NUL;");
2096
2097 Write_Statement_Buffer;
2098
2099 WBI
2100 (" pragma Export (C, Ada_Main_Program_Name, " &
2101 """__gnat_ada_main_program_name"");");
2102 end if;
2103
2104 WBI ("");
2105 WBI (" procedure " & Ada_Init_Name.all & ";");
2106 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2107 Ada_Init_Name.all & """);");
2108
2109 -- If -a has been specified use pragma Linker_Constructor for the init
2110 -- procedure and pragma Linker_Destructor for the final procedure.
2111
2112 if Use_Pragma_Linker_Constructor then
2113 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2114 end if;
2115
2116 if not Cumulative_Restrictions.Set (No_Finalization) then
2117 WBI ("");
2118 WBI (" procedure " & Ada_Final_Name.all & ";");
2119 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2120 Ada_Final_Name.all & """);");
2121
2122 if Use_Pragma_Linker_Constructor then
2123 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2124 end if;
2125 end if;
2126
2127 if Bind_Main_Program then
2128
2129 WBI ("");
2130
2131 if Exit_Status_Supported_On_Target then
2132 Set_String (" function ");
2133 else
2134 Set_String (" procedure ");
2135 end if;
2136
2137 Set_String (Get_Main_Name);
2138
2139 -- Generate argument list if present
2140
2141 if Command_Line_Args_On_Target then
2142 Write_Statement_Buffer;
2143 WBI (" (argc : Integer;");
2144 WBI (" argv : System.Address;");
2145 Set_String
2146 (" envp : System.Address)");
2147
2148 if Exit_Status_Supported_On_Target then
2149 Write_Statement_Buffer;
2150 WBI (" return Integer;");
2151 else
2152 Write_Statement_Buffer (";");
2153 end if;
2154
2155 else
2156 if Exit_Status_Supported_On_Target then
2157 Write_Statement_Buffer (" return Integer;");
2158 else
2159 Write_Statement_Buffer (";");
2160 end if;
2161 end if;
2162
2163 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2164 Get_Main_Name & """);");
2165 end if;
2166
2167 Gen_Versions;
2168 Gen_Elab_Order;
2169
2170 -- Spec is complete
2171
2172 WBI ("");
2173 WBI ("end " & Ada_Main & ";");
2174 Close_Binder_Output;
2175
2176 -- Prepare to write body
2177
2178 Create_Binder_Output (Filename, 'b', Bfileb);
2179
2180 -- We always compile the binder file in Ada 95 mode so that we properly
2181 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2182 -- of the Ada 2005/2012 constructs are needed by the binder file.
2183
2184 WBI ("pragma Ada_95;");
2185 WBI ("pragma Warnings (Off);");
2186
2187 -- Output Source_File_Name pragmas which look like
2188
2189 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2190 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2191
2192 -- where sss/bbb are the spec/body file names respectively
2193
2194 Get_Name_String (Bfiles);
2195 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2196
2197 WBI ("pragma Source_File_Name (" &
2198 Ada_Main &
2199 ", Spec_File_Name => """ &
2200 Name_Buffer (1 .. Name_Len + 3));
2201
2202 Get_Name_String (Bfileb);
2203 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2204
2205 WBI ("pragma Source_File_Name (" &
2206 Ada_Main &
2207 ", Body_File_Name => """ &
2208 Name_Buffer (1 .. Name_Len + 3));
2209
2210 -- Generate pragma Suppress (Overflow_Check). This is needed for recent
2211 -- versions of the compiler which have overflow checks on by default.
2212 -- We do not want overflow checking enabled for the increments of the
2213 -- elaboration variables (since this can cause an unwanted reference to
2214 -- the last chance exception handler for limited run-times).
2215
2216 WBI ("pragma Suppress (Overflow_Check);");
2217
2218 -- Generate with of System.Restrictions to initialize
2219 -- Run_Time_Restrictions.
2220
2221 if System_Restrictions_Used
2222 and not Suppress_Standard_Library_On_Target
2223 then
2224 WBI ("");
2225 WBI ("with System.Restrictions;");
2226 end if;
2227
2228 -- Generate with of Ada.Exceptions if needs library finalization
2229
2230 if Needs_Library_Finalization then
2231 WBI ("with Ada.Exceptions;");
2232 end if;
2233
2234 -- Generate with of System.Elaboration_Allocators if the restriction
2235 -- No_Standard_Allocators_After_Elaboration was present.
2236
2237 if Cumulative_Restrictions.Set
2238 (No_Standard_Allocators_After_Elaboration)
2239 then
2240 WBI ("with System.Elaboration_Allocators;");
2241 end if;
2242
2243 -- Generate start of package body
2244
2245 WBI ("");
2246 WBI ("package body " & Ada_Main & " is");
2247 WBI ("");
2248
2249 -- Generate externals for elaboration entities
2250
2251 Gen_Elab_Externals;
2252
2253 if not CodePeer_Mode then
2254 if not Suppress_Standard_Library_On_Target then
2255
2256 -- Generate Priority_Specific_Dispatching pragma string
2257
2258 Set_String
2259 (" Local_Priority_Specific_Dispatching : " &
2260 "constant String := """);
2261
2262 for J in 0 .. PSD_Pragma_Settings.Last loop
2263 Set_Char (PSD_Pragma_Settings.Table (J));
2264 end loop;
2265
2266 Set_String (""";");
2267 Write_Statement_Buffer;
2268
2269 -- Generate Interrupt_State pragma string
2270
2271 Set_String (" Local_Interrupt_States : constant String := """);
2272
2273 for J in 0 .. IS_Pragma_Settings.Last loop
2274 Set_Char (IS_Pragma_Settings.Table (J));
2275 end loop;
2276
2277 Set_String (""";");
2278 Write_Statement_Buffer;
2279 WBI ("");
2280 end if;
2281
2282 -- The B.1 (39) implementation advice says that the adainit/adafinal
2283 -- routines should be idempotent. Generate a flag to ensure that.
2284 -- This is not needed if we are suppressing the standard library
2285 -- since it would never be referenced.
2286
2287 if not Suppress_Standard_Library_On_Target then
2288 WBI (" Is_Elaborated : Boolean := False;");
2289 end if;
2290
2291 WBI ("");
2292 end if;
2293
2294 -- Generate the adafinal routine unless there is no finalization to do
2295
2296 if not Cumulative_Restrictions.Set (No_Finalization) then
2297 if Needs_Library_Finalization then
2298 Gen_Finalize_Library;
2299 end if;
2300
2301 Gen_Adafinal;
2302 end if;
2303
2304 Gen_Adainit;
2305
2306 if Bind_Main_Program then
2307 Gen_Main;
2308 end if;
2309
2310 -- Output object file list and the Ada body is complete
2311
2312 Gen_Object_Files_Options;
2313
2314 WBI ("");
2315 WBI ("end " & Ada_Main & ";");
2316
2317 Close_Binder_Output;
2318 end Gen_Output_File_Ada;
2319
2320 ----------------------
2321 -- Gen_Restrictions --
2322 ----------------------
2323
2324 procedure Gen_Restrictions is
2325 Count : Integer;
2326
2327 begin
2328 if Suppress_Standard_Library_On_Target
2329 or not System_Restrictions_Used
2330 then
2331 return;
2332 end if;
2333
2334 WBI (" System.Restrictions.Run_Time_Restrictions :=");
2335 WBI (" (Set =>");
2336 Set_String (" (");
2337
2338 Count := 0;
2339
2340 for J in Cumulative_Restrictions.Set'Range loop
2341 Set_Boolean (Cumulative_Restrictions.Set (J));
2342 Set_String (", ");
2343 Count := Count + 1;
2344
2345 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2346 Write_Statement_Buffer;
2347 Set_String (" ");
2348 Count := 0;
2349 end if;
2350 end loop;
2351
2352 Set_String_Replace ("),");
2353 Write_Statement_Buffer;
2354 Set_String (" Value => (");
2355
2356 for J in Cumulative_Restrictions.Value'Range loop
2357 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2358 Set_String (", ");
2359 end loop;
2360
2361 Set_String_Replace ("),");
2362 Write_Statement_Buffer;
2363 WBI (" Violated =>");
2364 Set_String (" (");
2365 Count := 0;
2366
2367 for J in Cumulative_Restrictions.Violated'Range loop
2368 Set_Boolean (Cumulative_Restrictions.Violated (J));
2369 Set_String (", ");
2370 Count := Count + 1;
2371
2372 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2373 Write_Statement_Buffer;
2374 Set_String (" ");
2375 Count := 0;
2376 end if;
2377 end loop;
2378
2379 Set_String_Replace ("),");
2380 Write_Statement_Buffer;
2381 Set_String (" Count => (");
2382
2383 for J in Cumulative_Restrictions.Count'Range loop
2384 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2385 Set_String (", ");
2386 end loop;
2387
2388 Set_String_Replace ("),");
2389 Write_Statement_Buffer;
2390 Set_String (" Unknown => (");
2391
2392 for J in Cumulative_Restrictions.Unknown'Range loop
2393 Set_Boolean (Cumulative_Restrictions.Unknown (J));
2394 Set_String (", ");
2395 end loop;
2396
2397 Set_String_Replace ("))");
2398 Set_String (";");
2399 Write_Statement_Buffer;
2400 end Gen_Restrictions;
2401
2402 ------------------
2403 -- Gen_Versions --
2404 ------------------
2405
2406 -- This routine generates lines such as:
2407
2408 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2409 -- pragma Export (C, unnnnn, unam);
2410
2411 -- for each unit, where unam is the unit name suffixed by either B or S for
2412 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2413 -- the version number, and nnnnn is a 5-digits serial number.
2414
2415 procedure Gen_Versions is
2416 Ubuf : String (1 .. 6) := "u00000";
2417
2418 procedure Increment_Ubuf;
2419 -- Little procedure to increment the serial number
2420
2421 --------------------
2422 -- Increment_Ubuf --
2423 --------------------
2424
2425 procedure Increment_Ubuf is
2426 begin
2427 for J in reverse Ubuf'Range loop
2428 Ubuf (J) := Character'Succ (Ubuf (J));
2429 exit when Ubuf (J) <= '9';
2430 Ubuf (J) := '0';
2431 end loop;
2432 end Increment_Ubuf;
2433
2434 -- Start of processing for Gen_Versions
2435
2436 begin
2437 WBI ("");
2438
2439 WBI (" type Version_32 is mod 2 ** 32;");
2440 for U in Units.First .. Units.Last loop
2441 if not Units.Table (U).SAL_Interface
2442 and then
2443 (not Bind_For_Library or else Units.Table (U).Directly_Scanned)
2444 then
2445 Increment_Ubuf;
2446 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2447 Units.Table (U).Version & "#;");
2448 Set_String (" pragma Export (C, ");
2449 Set_String (Ubuf);
2450 Set_String (", """);
2451
2452 Get_Name_String (Units.Table (U).Uname);
2453
2454 for K in 1 .. Name_Len loop
2455 if Name_Buffer (K) = '.' then
2456 Set_Char ('_');
2457 Set_Char ('_');
2458
2459 elsif Name_Buffer (K) = '%' then
2460 exit;
2461
2462 else
2463 Set_Char (Name_Buffer (K));
2464 end if;
2465 end loop;
2466
2467 if Name_Buffer (Name_Len) = 's' then
2468 Set_Char ('S');
2469 else
2470 Set_Char ('B');
2471 end if;
2472
2473 Set_String (""");");
2474 Write_Statement_Buffer;
2475 end if;
2476 end loop;
2477 end Gen_Versions;
2478
2479 ------------------------
2480 -- Get_Main_Unit_Name --
2481 ------------------------
2482
2483 function Get_Main_Unit_Name (S : String) return String is
2484 Result : String := S;
2485
2486 begin
2487 for J in S'Range loop
2488 if Result (J) = '.' then
2489 Result (J) := '_';
2490 end if;
2491 end loop;
2492
2493 return Result;
2494 end Get_Main_Unit_Name;
2495
2496 -----------------------
2497 -- Get_Ada_Main_Name --
2498 -----------------------
2499
2500 function Get_Ada_Main_Name return String is
2501 Suffix : constant String := "_00";
2502 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2503 Opt.Ada_Main_Name.all & Suffix;
2504 Nlen : Natural;
2505
2506 begin
2507 -- For CodePeer, we want reproducible names (independent of other
2508 -- mains that may or may not be present) that don't collide
2509 -- when analyzing multiple mains and which are easily recognizable
2510 -- as "ada_main" names.
2511
2512 if CodePeer_Mode then
2513 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2514 return "ada_main_for_" &
2515 Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2516 end if;
2517
2518 -- This loop tries the following possibilities in order
2519 -- <Ada_Main>
2520 -- <Ada_Main>_01
2521 -- <Ada_Main>_02
2522 -- ..
2523 -- <Ada_Main>_99
2524 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2525 -- it is set to 'ada_main'.
2526
2527 for J in 0 .. 99 loop
2528 if J = 0 then
2529 Nlen := Name'Length - Suffix'Length;
2530 else
2531 Nlen := Name'Length;
2532 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2533 Name (Name'Last - 1) :=
2534 Character'Val (J / 10 + Character'Pos ('0'));
2535 end if;
2536
2537 for K in ALIs.First .. ALIs.Last loop
2538 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2539
2540 -- Get unit name, removing %b or %e at end
2541
2542 Get_Name_String (Units.Table (L).Uname);
2543 Name_Len := Name_Len - 2;
2544
2545 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2546 goto Continue;
2547 end if;
2548 end loop;
2549 end loop;
2550
2551 return Name (1 .. Nlen);
2552
2553 <<Continue>>
2554 null;
2555 end loop;
2556
2557 -- If we fall through, just use a peculiar unlikely name
2558
2559 return ("Qwertyuiop");
2560 end Get_Ada_Main_Name;
2561
2562 -------------------
2563 -- Get_Main_Name --
2564 -------------------
2565
2566 function Get_Main_Name return String is
2567 begin
2568 -- Explicit name given with -M switch
2569
2570 if Bind_Alternate_Main_Name then
2571 return Alternate_Main_Name.all;
2572
2573 -- Case of main program name to be used directly
2574
2575 elsif Use_Ada_Main_Program_Name_On_Target then
2576
2577 -- Get main program name
2578
2579 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2580
2581 -- If this is a child name, return only the name of the child, since
2582 -- we can't have dots in a nested program name. Note that we do not
2583 -- include the %b at the end of the unit name.
2584
2585 for J in reverse 1 .. Name_Len - 2 loop
2586 if J = 1 or else Name_Buffer (J - 1) = '.' then
2587 return Name_Buffer (J .. Name_Len - 2);
2588 end if;
2589 end loop;
2590
2591 raise Program_Error; -- impossible exit
2592
2593 -- Case where "main" is to be used as default
2594
2595 else
2596 return "main";
2597 end if;
2598 end Get_Main_Name;
2599
2600 ---------------------
2601 -- Get_WC_Encoding --
2602 ---------------------
2603
2604 function Get_WC_Encoding return Character is
2605 begin
2606 -- If encoding method specified by -W switch, then return it
2607
2608 if Wide_Character_Encoding_Method_Specified then
2609 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
2610
2611 -- If no main program, and not specified, set brackets, we really have
2612 -- no better choice. If some other encoding is required when there is
2613 -- no main, it must be set explicitly using -Wx.
2614
2615 -- Note: if the ALI file always passed the wide character encoding of
2616 -- every file, then we could use the encoding of the initial specified
2617 -- file, but this information is passed only for potential main
2618 -- programs. We could fix this sometime, but it is a very minor point
2619 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
2620 -- is no main program).
2621
2622 elsif No_Main_Subprogram then
2623 return 'b';
2624
2625 -- Otherwise if there is a main program, take encoding from it
2626
2627 else
2628 return ALIs.Table (ALIs.First).WC_Encoding;
2629 end if;
2630 end Get_WC_Encoding;
2631
2632 -------------------
2633 -- Has_Finalizer --
2634 -------------------
2635
2636 function Has_Finalizer return Boolean is
2637 U : Unit_Record;
2638 Unum : Unit_Id;
2639
2640 begin
2641 for E in reverse Elab_Order.First .. Elab_Order.Last loop
2642 Unum := Elab_Order.Table (E);
2643 U := Units.Table (Unum);
2644
2645 -- We are only interested in non-generic packages
2646
2647 if U.Unit_Kind = 'p'
2648 and then U.Has_Finalizer
2649 and then not U.Is_Generic
2650 and then not U.No_Elab
2651 then
2652 return True;
2653 end if;
2654 end loop;
2655
2656 return False;
2657 end Has_Finalizer;
2658
2659 ----------------------
2660 -- Lt_Linker_Option --
2661 ----------------------
2662
2663 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2664 begin
2665 -- Sort internal files last
2666
2667 if Linker_Options.Table (Op1).Internal_File
2668 /=
2669 Linker_Options.Table (Op2).Internal_File
2670 then
2671 -- Note: following test uses False < True
2672
2673 return Linker_Options.Table (Op1).Internal_File
2674 <
2675 Linker_Options.Table (Op2).Internal_File;
2676
2677 -- If both internal or both non-internal, sort according to the
2678 -- elaboration position. A unit that is elaborated later should come
2679 -- earlier in the linker options list.
2680
2681 else
2682 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2683 >
2684 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2685
2686 end if;
2687 end Lt_Linker_Option;
2688
2689 ------------------------
2690 -- Move_Linker_Option --
2691 ------------------------
2692
2693 procedure Move_Linker_Option (From : Natural; To : Natural) is
2694 begin
2695 Linker_Options.Table (To) := Linker_Options.Table (From);
2696 end Move_Linker_Option;
2697
2698 ----------------------------
2699 -- Resolve_Binder_Options --
2700 ----------------------------
2701
2702 procedure Resolve_Binder_Options is
2703
2704 procedure Check_Package (Var : in out Boolean; Name : String);
2705 -- Set Var to true iff the current identifier in Namet is Name. Do
2706 -- nothing if it doesn't match. This procedure is just an helper to
2707 -- avoid to explicitely deal with length.
2708
2709 -------------------
2710 -- Check_Package --
2711 -------------------
2712
2713 procedure Check_Package (Var : in out Boolean; Name : String) is
2714 begin
2715 if Name_Len = Name'Length
2716 and then Name_Buffer (1 .. Name_Len) = Name
2717 then
2718 Var := True;
2719 end if;
2720 end Check_Package;
2721
2722 -- Start of processing for Resolve_Binder_Options
2723
2724 begin
2725 for E in Elab_Order.First .. Elab_Order.Last loop
2726 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2727
2728 -- This is not a perfect approach, but is the current protocol
2729 -- between the run-time and the binder to indicate that tasking is
2730 -- used: System.OS_Interface should always be used by any tasking
2731 -- application.
2732
2733 Check_Package (With_GNARL, "system.os_interface%s");
2734
2735 -- Ditto for the use of restricted tasking
2736
2737 Check_Package
2738 (System_Tasking_Restricted_Stages_Used,
2739 "system.tasking.restricted.stages%s");
2740
2741 -- Ditto for the use of interrupts
2742
2743 Check_Package (System_Interrupts_Used, "system.interrupts%s");
2744
2745 -- Ditto for the use of dispatching domains
2746
2747 Check_Package
2748 (Dispatching_Domains_Used,
2749 "system.multiprocessors.dispatching_domains%s");
2750
2751 -- Ditto for the use of restrictions
2752
2753 Check_Package (System_Restrictions_Used, "system.restrictions%s");
2754 end loop;
2755 end Resolve_Binder_Options;
2756
2757 -----------------
2758 -- Set_Boolean --
2759 -----------------
2760
2761 procedure Set_Boolean (B : Boolean) is
2762 True_Str : constant String := "True";
2763 False_Str : constant String := "False";
2764 begin
2765 if B then
2766 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
2767 Last := Last + True_Str'Length;
2768 else
2769 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
2770 Last := Last + False_Str'Length;
2771 end if;
2772 end Set_Boolean;
2773
2774 --------------
2775 -- Set_Char --
2776 --------------
2777
2778 procedure Set_Char (C : Character) is
2779 begin
2780 Last := Last + 1;
2781 Statement_Buffer (Last) := C;
2782 end Set_Char;
2783
2784 -------------
2785 -- Set_Int --
2786 -------------
2787
2788 procedure Set_Int (N : Int) is
2789 begin
2790 if N < 0 then
2791 Set_String ("-");
2792 Set_Int (-N);
2793
2794 else
2795 if N > 9 then
2796 Set_Int (N / 10);
2797 end if;
2798
2799 Last := Last + 1;
2800 Statement_Buffer (Last) :=
2801 Character'Val (N mod 10 + Character'Pos ('0'));
2802 end if;
2803 end Set_Int;
2804
2805 -------------------------
2806 -- Set_IS_Pragma_Table --
2807 -------------------------
2808
2809 procedure Set_IS_Pragma_Table is
2810 begin
2811 for F in ALIs.First .. ALIs.Last loop
2812 for K in ALIs.Table (F).First_Interrupt_State ..
2813 ALIs.Table (F).Last_Interrupt_State
2814 loop
2815 declare
2816 Inum : constant Int :=
2817 Interrupt_States.Table (K).Interrupt_Id;
2818 Stat : constant Character :=
2819 Interrupt_States.Table (K).Interrupt_State;
2820
2821 begin
2822 while IS_Pragma_Settings.Last < Inum loop
2823 IS_Pragma_Settings.Append ('n');
2824 end loop;
2825
2826 IS_Pragma_Settings.Table (Inum) := Stat;
2827 end;
2828 end loop;
2829 end loop;
2830 end Set_IS_Pragma_Table;
2831
2832 ---------------------------
2833 -- Set_Main_Program_Name --
2834 ---------------------------
2835
2836 procedure Set_Main_Program_Name is
2837 begin
2838 -- Note that name has %b on the end which we ignore
2839
2840 -- First we output the initial _ada_ since we know that the main
2841 -- program is a library level subprogram.
2842
2843 Set_String ("_ada_");
2844
2845 -- Copy name, changing dots to double underscores
2846
2847 for J in 1 .. Name_Len - 2 loop
2848 if Name_Buffer (J) = '.' then
2849 Set_String ("__");
2850 else
2851 Set_Char (Name_Buffer (J));
2852 end if;
2853 end loop;
2854 end Set_Main_Program_Name;
2855
2856 ---------------------
2857 -- Set_Name_Buffer --
2858 ---------------------
2859
2860 procedure Set_Name_Buffer is
2861 begin
2862 for J in 1 .. Name_Len loop
2863 Set_Char (Name_Buffer (J));
2864 end loop;
2865 end Set_Name_Buffer;
2866
2867 -------------------------
2868 -- Set_PSD_Pragma_Table --
2869 -------------------------
2870
2871 procedure Set_PSD_Pragma_Table is
2872 begin
2873 for F in ALIs.First .. ALIs.Last loop
2874 for K in ALIs.Table (F).First_Specific_Dispatching ..
2875 ALIs.Table (F).Last_Specific_Dispatching
2876 loop
2877 declare
2878 DTK : Specific_Dispatching_Record
2879 renames Specific_Dispatching.Table (K);
2880
2881 begin
2882 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
2883 PSD_Pragma_Settings.Append ('F');
2884 end loop;
2885
2886 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
2887 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
2888 end loop;
2889 end;
2890 end loop;
2891 end loop;
2892 end Set_PSD_Pragma_Table;
2893
2894 ----------------
2895 -- Set_String --
2896 ----------------
2897
2898 procedure Set_String (S : String) is
2899 begin
2900 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
2901 Last := Last + S'Length;
2902 end Set_String;
2903
2904 ------------------------
2905 -- Set_String_Replace --
2906 ------------------------
2907
2908 procedure Set_String_Replace (S : String) is
2909 begin
2910 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
2911 end Set_String_Replace;
2912
2913 -------------------
2914 -- Set_Unit_Name --
2915 -------------------
2916
2917 procedure Set_Unit_Name is
2918 begin
2919 for J in 1 .. Name_Len - 2 loop
2920 if Name_Buffer (J) = '.' then
2921 Set_String ("__");
2922 else
2923 Set_Char (Name_Buffer (J));
2924 end if;
2925 end loop;
2926 end Set_Unit_Name;
2927
2928 ---------------------
2929 -- Set_Unit_Number --
2930 ---------------------
2931
2932 procedure Set_Unit_Number (U : Unit_Id) is
2933 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
2934 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
2935
2936 begin
2937 if Num_Units >= 10 and then Unum < 10 then
2938 Set_Char ('0');
2939 end if;
2940
2941 if Num_Units >= 100 and then Unum < 100 then
2942 Set_Char ('0');
2943 end if;
2944
2945 Set_Int (Unum);
2946 end Set_Unit_Number;
2947
2948 ----------------------------
2949 -- Write_Statement_Buffer --
2950 ----------------------------
2951
2952 procedure Write_Statement_Buffer is
2953 begin
2954 WBI (Statement_Buffer (1 .. Last));
2955 Last := 0;
2956 end Write_Statement_Buffer;
2957
2958 procedure Write_Statement_Buffer (S : String) is
2959 begin
2960 Set_String (S);
2961 Write_Statement_Buffer;
2962 end Write_Statement_Buffer;
2963
2964 end Bindgen;