* config/rs6000/aix61.h (TARGET_DEFAULT): Add MASK_PPC_GPOPT,
[official-gcc.git] / gcc / ada / bindgen.adb
blob686082d61ac5bf65b22b602b319335d13975cdc7
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-2012, 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 ------------------------------------------------------------------------------
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;
42 with System.OS_Lib; use System.OS_Lib;
43 with System.WCh_Con; use System.WCh_Con;
45 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
47 package body Bindgen is
49 Statement_Buffer : String (1 .. 1000);
50 -- Buffer used for constructing output statements
52 Last : Natural := 0;
53 -- Last location in Statement_Buffer currently set
55 With_DECGNAT : Boolean := False;
56 -- Flag which indicates whether the program uses the DECGNAT library
57 -- (presence of the unit DEC).
59 With_GNARL : Boolean := False;
60 -- Flag which indicates whether the program uses the GNARL library
61 -- (presence of the unit System.OS_Interface)
63 Num_Elab_Calls : Nat := 0;
64 -- Number of generated calls to elaboration routines
66 System_Restrictions_Used : Boolean;
67 -- Flag indicating whether the unit System.Restrictions is in the closure
68 -- of the partition. This is set by Check_System_Restrictions_Used, and
69 -- is used to determine whether or not to initialize the restrictions
70 -- information in the body of the binder generated file (we do not want
71 -- to do this unconditionally, since it drags in the System.Restrictions
72 -- unit unconditionally, which is unpleasand, especially for ZFP etc.)
74 Dispatching_Domains_Used : Boolean;
75 -- Flag indicating whether multiprocessor dispatching domains are used in
76 -- the closure of the partition. This is set by
77 -- Check_Dispatching_Domains_Used, and is used to call the routine to
78 -- disallow the creation of new dispatching domains just before calling
79 -- the main procedure from the environment task.
81 Lib_Final_Built : Boolean := False;
82 -- Flag indicating whether the finalize_library rountine has been built
84 CodePeer_Wrapper_Name : constant String := "call_main_subprogram";
85 -- For CodePeer, introduce a wrapper subprogram which calls the
86 -- user-defined main subprogram.
88 ----------------------------------
89 -- Interface_State Pragma Table --
90 ----------------------------------
92 -- This table assembles the interface state pragma information from
93 -- all the units in the partition. Note that Bcheck has already checked
94 -- that the information is consistent across units. The entries
95 -- in this table are n/u/r/s for not set/user/runtime/system.
97 package IS_Pragma_Settings is new Table.Table (
98 Table_Component_Type => Character,
99 Table_Index_Type => Int,
100 Table_Low_Bound => 0,
101 Table_Initial => 100,
102 Table_Increment => 200,
103 Table_Name => "IS_Pragma_Settings");
105 -- This table assembles the Priority_Specific_Dispatching pragma
106 -- information from all the units in the partition. Note that Bcheck has
107 -- already checked that the information is consistent across units.
108 -- The entries in this table are the upper case first character of the
109 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
111 package PSD_Pragma_Settings is new Table.Table (
112 Table_Component_Type => Character,
113 Table_Index_Type => Int,
114 Table_Low_Bound => 0,
115 Table_Initial => 100,
116 Table_Increment => 200,
117 Table_Name => "PSD_Pragma_Settings");
119 ----------------------
120 -- Run-Time Globals --
121 ----------------------
123 -- This section documents the global variables that set from the
124 -- generated binder file.
126 -- Main_Priority : Integer;
127 -- Time_Slice_Value : Integer;
128 -- Heap_Size : Natural;
129 -- WC_Encoding : Character;
130 -- Locking_Policy : Character;
131 -- Queuing_Policy : Character;
132 -- Task_Dispatching_Policy : Character;
133 -- Priority_Specific_Dispatching : System.Address;
134 -- Num_Specific_Dispatching : Integer;
135 -- Restrictions : System.Address;
136 -- Interrupt_States : System.Address;
137 -- Num_Interrupt_States : Integer;
138 -- Unreserve_All_Interrupts : Integer;
139 -- Exception_Tracebacks : Integer;
140 -- Zero_Cost_Exceptions : Integer;
141 -- Detect_Blocking : Integer;
142 -- Default_Stack_Size : Integer;
143 -- Leap_Seconds_Support : Integer;
144 -- Main_CPU : Integer;
146 -- Main_Priority is the priority value set by pragma Priority in the main
147 -- program. If no such pragma is present, the value is -1.
149 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
150 -- main program, or by the use of a -Tnnn parameter for the binder (if both
151 -- are present, the binder value overrides). The value is in milliseconds.
152 -- A value of zero indicates that time slicing should be suppressed. If no
153 -- pragma is present, and no -T switch was used, the value is -1.
155 -- Heap_Size is the heap to use for memory allocations set by use of a
156 -- -Hnn parameter for the binder or by the GNAT$NO_MALLOC_64 logical.
157 -- Valid values are 32 and 64. This switch is only effective on VMS.
159 -- WC_Encoding shows the wide character encoding method used for the main
160 -- program. This is one of the encoding letters defined in
161 -- System.WCh_Con.WC_Encoding_Letters.
163 -- Locking_Policy is a space if no locking policy was specified for the
164 -- partition. If a locking policy was specified, the value is the upper
165 -- case first character of the locking policy name, for example, 'C' for
166 -- Ceiling_Locking.
168 -- Queuing_Policy is a space if no queuing policy was specified for the
169 -- partition. If a queuing policy was specified, the value is the upper
170 -- case first character of the queuing policy name for example, 'F' for
171 -- FIFO_Queuing.
173 -- Task_Dispatching_Policy is a space if no task dispatching policy was
174 -- specified for the partition. If a task dispatching policy was specified,
175 -- the value is the upper case first character of the policy name, e.g. 'F'
176 -- for FIFO_Within_Priorities.
178 -- Priority_Specific_Dispatching is the address of a string used to store
179 -- the task dispatching policy specified for the different priorities in
180 -- the partition. The length of this string is determined by the last
181 -- priority for which such a pragma applies (the string will be a null
182 -- string if no specific dispatching policies were used). If pragma were
183 -- present, the entries apply to the priorities in sequence from the first
184 -- priority. The value stored is the upper case first character of the
185 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
186 -- for those priority ranges not specified.
188 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
189 -- string. It will be set to zero if no Priority_Specific_Dispatching
190 -- pragmas are present.
192 -- Restrictions is the address of a null-terminated string specifying the
193 -- restrictions information for the partition. The format is identical to
194 -- that of the parameter string found on R lines in ali files (see Lib.Writ
195 -- spec in lib-writ.ads for full details). The difference is that in this
196 -- context the values are the cumulative ones for the entire partition.
198 -- Interrupt_States is the address of a string used to specify the
199 -- cumulative results of Interrupt_State pragmas used in the partition.
200 -- The length of this string is determined by the last interrupt for which
201 -- such a pragma is given (the string will be a null string if no pragmas
202 -- were used). If pragma were present the entries apply to the interrupts
203 -- in sequence from the first interrupt, and are set to one of four
204 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
205 -- time, 's' for system, see description of Interrupt_State pragma for
206 -- further details.
208 -- Num_Interrupt_States is the length of the Interrupt_States string. It
209 -- will be set to zero if no Interrupt_State pragmas are present.
211 -- Unreserve_All_Interrupts is set to one if at least one unit in the
212 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
214 -- Exception_Tracebacks is set to one if the -E parameter was present
215 -- in the bind and to zero otherwise. Note that on some targets exception
216 -- tracebacks are provided by default, so a value of zero for this
217 -- parameter does not necessarily mean no trace backs are available.
219 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
220 -- this partition, and to zero if longjmp/setjmp exceptions are used.
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.
226 -- Default_Stack_Size is the default stack size used when creating an Ada
227 -- task with no explicit Storage_Size clause.
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.
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.
236 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
237 -- Convenient shorthand used throughout
239 -----------------------
240 -- Local Subprograms --
241 -----------------------
243 procedure Check_File_In_Partition
244 (File_Name : String;
245 Flag : out Boolean);
246 -- If the file indicated by File_Name is in the partition the Flag is set
247 -- to True, False otherwise.
249 procedure Check_System_Restrictions_Used;
250 -- Sets flag System_Restrictions_Used (Set to True if and only if the unit
251 -- System.Restrictions is present in the partition, otherwise False).
253 procedure Check_Dispatching_Domains_Used;
254 -- Sets flag Dispatching_Domains_Used to True when using the unit
255 -- System.Multiprocessors.Dispatching_Domains is present in the partition,
256 -- otherwise set to False.
258 procedure Gen_Adainit;
259 -- Generates the Adainit procedure
261 procedure Gen_Adafinal;
262 -- Generate the Adafinal procedure
264 procedure Gen_CodePeer_Wrapper;
265 -- For CodePeer, generate wrapper which calls user-defined main subprogram
267 procedure Gen_Elab_Calls;
268 -- Generate sequence of elaboration calls
270 procedure Gen_Elab_Externals;
271 -- Generate sequence of external declarations for elaboration
273 procedure Gen_Elab_Order;
274 -- Generate comments showing elaboration order chosen
276 procedure Gen_Finalize_Library;
277 -- Generate a sequence of finalization calls to elaborated packages
279 procedure Gen_Main;
280 -- Generate procedure main
282 procedure Gen_Object_Files_Options;
283 -- Output comments containing a list of the full names of the object
284 -- files to be linked and the list of linker options supplied by
285 -- Linker_Options pragmas in the source.
287 procedure Gen_Output_File_Ada (Filename : String);
288 -- Generate Ada output file
290 procedure Gen_Restrictions;
291 -- Generate initialization of restrictions variable
293 procedure Gen_Versions;
294 -- Output series of definitions for unit versions
296 function Get_Ada_Main_Name return String;
297 -- This function is used for the Ada main output to compute a usable name
298 -- for the generated main program. The normal main program name is
299 -- Ada_Main, but this won't work if the user has a unit with this name.
300 -- This function tries Ada_Main first, and if there is such a clash, then
301 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
303 function Get_Main_Unit_Name (S : String) return String;
304 -- Return the main unit name corresponding to S by replacing '.' with '_'
306 function Get_Main_Name return String;
307 -- This function is used in the main output case to compute the correct
308 -- external main program. It is "main" by default, unless the flag
309 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
310 -- of the Ada main name without the "_ada". This default can be overridden
311 -- explicitly using the -Mname binder switch.
313 function Get_WC_Encoding return Character;
314 -- Return wide character encoding method to set as WC_Encoding in output.
315 -- If -W has been used, returns the specified encoding, otherwise returns
316 -- the encoding method used for the main program source. If there is no
317 -- main program source (-z switch used), returns brackets ('b').
319 function Has_Finalizer return Boolean;
320 -- Determine whether the current unit has at least one library-level
321 -- finalizer.
323 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
324 -- Compare linker options, when sorting, first according to
325 -- Is_Internal_File (internal files come later) and then by
326 -- elaboration order position (latest to earliest).
328 procedure Move_Linker_Option (From : Natural; To : Natural);
329 -- Move routine for sorting linker options
331 procedure Resolve_Binder_Options;
332 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
333 -- since it tests for a package named "dec" which might cause a conflict
334 -- on non-VMS systems.
336 procedure Set_Char (C : Character);
337 -- Set given character in Statement_Buffer at the Last + 1 position
338 -- and increment Last by one to reflect the stored character.
340 procedure Set_Int (N : Int);
341 -- Set given value in decimal in Statement_Buffer with no spaces
342 -- starting at the Last + 1 position, and updating Last past the value.
343 -- A minus sign is output for a negative value.
345 procedure Set_Boolean (B : Boolean);
346 -- Set given boolean value in Statement_Buffer at the Last + 1 position
347 -- and update Last past the value.
349 procedure Set_IS_Pragma_Table;
350 -- Initializes contents of IS_Pragma_Settings table from ALI table
352 procedure Set_Main_Program_Name;
353 -- Given the main program name in Name_Buffer (length in Name_Len)
354 -- generate the name of the routine to be used in the call. The name
355 -- is generated starting at Last + 1, and Last is updated past it.
357 procedure Set_Name_Buffer;
358 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
360 procedure Set_PSD_Pragma_Table;
361 -- Initializes contents of PSD_Pragma_Settings table from ALI table
363 procedure Set_String (S : String);
364 -- Sets characters of given string in Statement_Buffer, starting at the
365 -- Last + 1 position, and updating last past the string value.
367 procedure Set_String_Replace (S : String);
368 -- Replaces the last S'Length characters in the Statement_Buffer with
369 -- the characters of S. The caller must ensure that these characters do
370 -- in fact exist in the Statement_Buffer.
372 type Qualification_Mode is (Dollar_Sign, Dot, Double_Underscores);
374 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores);
375 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
376 -- starting at the Last + 1 position and update Last past the value.
377 -- Depending on parameter Mode, a dot (.) can be qualified into double
378 -- underscores (__), a dollar sign ($) or left as is.
380 procedure Set_Unit_Number (U : Unit_Id);
381 -- Sets unit number (first unit is 1, leading zeroes output to line
382 -- up all output unit numbers nicely as required by the value, and
383 -- by the total number of units.
385 procedure Write_Statement_Buffer;
386 -- Write out contents of statement buffer up to Last, and reset Last to 0
388 procedure Write_Statement_Buffer (S : String);
389 -- First writes its argument (using Set_String (S)), then writes out the
390 -- contents of statement buffer up to Last, and reset Last to 0
392 ------------------------------------
393 -- Check_Dispatching_Domains_Used --
394 ------------------------------------
396 procedure Check_Dispatching_Domains_Used is
397 begin
398 Check_File_In_Partition ("s-mudido.ads", Dispatching_Domains_Used);
399 end Check_Dispatching_Domains_Used;
401 -----------------------------
402 -- Check_File_In_Partition --
403 -----------------------------
405 procedure Check_File_In_Partition
406 (File_Name : String;
407 Flag : out Boolean)
409 begin
410 for J in Units.First .. Units.Last loop
411 if Get_Name_String (Units.Table (J).Sfile) = File_Name then
412 Flag := True;
413 return;
414 end if;
415 end loop;
417 Flag := False;
418 end Check_File_In_Partition;
420 ------------------------------------
421 -- Check_System_Restrictions_Used --
422 ------------------------------------
424 procedure Check_System_Restrictions_Used is
425 begin
426 Check_File_In_Partition ("s-restri.ads", System_Restrictions_Used);
427 end Check_System_Restrictions_Used;
429 ------------------
430 -- Gen_Adafinal --
431 ------------------
433 procedure Gen_Adafinal is
434 begin
435 WBI (" procedure " & Ada_Final_Name.all & " is");
437 if VM_Target = No_VM
438 and Bind_Main_Program
439 and not CodePeer_Mode
440 then
441 WBI (" procedure s_stalib_adafinal;");
442 Set_String (" pragma Import (C, s_stalib_adafinal, ");
443 Set_String ("""system__standard_library__adafinal"");");
444 Write_Statement_Buffer;
445 end if;
447 WBI (" begin");
449 if not CodePeer_Mode then
450 WBI (" if not Is_Elaborated then");
451 WBI (" return;");
452 WBI (" end if;");
453 WBI (" Is_Elaborated := False;");
454 end if;
456 -- On non-virtual machine targets, finalization is done differently
457 -- depending on whether this is the main program or a library.
459 if VM_Target = No_VM and then not CodePeer_Mode then
460 if Bind_Main_Program then
461 WBI (" s_stalib_adafinal;");
462 elsif Lib_Final_Built then
463 WBI (" finalize_library;");
464 else
465 WBI (" null;");
466 end if;
468 -- Pragma Import C cannot be used on virtual machine targets, therefore
469 -- call the runtime finalization routine directly. Similarly in CodePeer
470 -- mode, where imported functions are ignored.
472 else
473 WBI (" System.Standard_Library.Adafinal;");
474 end if;
476 WBI (" end " & Ada_Final_Name.all & ";");
477 WBI ("");
478 end Gen_Adafinal;
480 -----------------
481 -- Gen_Adainit --
482 -----------------
484 procedure Gen_Adainit is
485 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
486 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
488 begin
489 -- Declare the access-to-subprogram type used for initialization of
490 -- of __gnat_finalize_library_objects. This is declared at library
491 -- level for compatibility with the type used in System.Soft_Links.
492 -- The import of the soft link which performs library-level object
493 -- finalization is not needed for VM targets; regular Ada is used in
494 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
495 -- tasks are non-terminating, so we do not want finalization.
497 if not Suppress_Standard_Library_On_Target
498 and then VM_Target = No_VM
499 and then not CodePeer_Mode
500 and then not Configurable_Run_Time_On_Target
501 then
502 WBI (" type No_Param_Proc is access procedure;");
503 WBI ("");
504 end if;
506 WBI (" procedure " & Ada_Init_Name.all & " is");
508 -- In CodePeer mode, simplify adainit procedure by only calling
509 -- elaboration procedures.
511 if CodePeer_Mode then
512 WBI (" begin");
514 -- When compiling for the AAMP small library, where the standard library
515 -- is no longer suppressed, we still want to exclude the setting of the
516 -- various imported globals, which aren't present for that library.
518 elsif AAMP_On_Target and then Configurable_Run_Time_On_Target then
519 WBI (" begin");
520 WBI (" null;");
522 -- If the standard library is suppressed, then the only global variables
523 -- that might be needed (by the Ravenscar profile) are the priority and
524 -- the processor for the environment task.
526 elsif Suppress_Standard_Library_On_Target then
527 if Main_Priority /= No_Main_Priority then
528 WBI (" Main_Priority : Integer;");
529 WBI (" pragma Import (C, Main_Priority," &
530 " ""__gl_main_priority"");");
531 WBI ("");
532 end if;
534 if Main_CPU /= No_Main_CPU then
535 WBI (" Main_CPU : Integer;");
536 WBI (" pragma Import (C, Main_CPU," &
537 " ""__gl_main_cpu"");");
538 WBI ("");
539 end if;
541 WBI (" begin");
543 if Main_Priority /= No_Main_Priority then
544 Set_String (" Main_Priority := ");
545 Set_Int (Main_Priority);
546 Set_Char (';');
547 Write_Statement_Buffer;
548 end if;
550 if Main_CPU /= No_Main_CPU then
551 Set_String (" Main_CPU := ");
552 Set_Int (Main_CPU);
553 Set_Char (';');
554 Write_Statement_Buffer;
555 end if;
557 if Main_Priority = No_Main_Priority
558 and then Main_CPU = No_Main_CPU
559 then
560 WBI (" null;");
561 end if;
563 -- Normal case (standard library not suppressed). Set all global values
564 -- used by the run time.
566 else
567 WBI (" Main_Priority : Integer;");
568 WBI (" pragma Import (C, Main_Priority, " &
569 """__gl_main_priority"");");
570 WBI (" Time_Slice_Value : Integer;");
571 WBI (" pragma Import (C, Time_Slice_Value, " &
572 """__gl_time_slice_val"");");
573 WBI (" WC_Encoding : Character;");
574 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
575 WBI (" Locking_Policy : Character;");
576 WBI (" pragma Import (C, Locking_Policy, " &
577 """__gl_locking_policy"");");
578 WBI (" Queuing_Policy : Character;");
579 WBI (" pragma Import (C, Queuing_Policy, " &
580 """__gl_queuing_policy"");");
581 WBI (" Task_Dispatching_Policy : Character;");
582 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
583 """__gl_task_dispatching_policy"");");
584 WBI (" Priority_Specific_Dispatching : System.Address;");
585 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
586 """__gl_priority_specific_dispatching"");");
587 WBI (" Num_Specific_Dispatching : Integer;");
588 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
589 """__gl_num_specific_dispatching"");");
590 WBI (" Main_CPU : Integer;");
591 WBI (" pragma Import (C, Main_CPU, " &
592 """__gl_main_cpu"");");
594 WBI (" Interrupt_States : System.Address;");
595 WBI (" pragma Import (C, Interrupt_States, " &
596 """__gl_interrupt_states"");");
597 WBI (" Num_Interrupt_States : Integer;");
598 WBI (" pragma Import (C, Num_Interrupt_States, " &
599 """__gl_num_interrupt_states"");");
600 WBI (" Unreserve_All_Interrupts : Integer;");
601 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
602 """__gl_unreserve_all_interrupts"");");
604 if Exception_Tracebacks then
605 WBI (" Exception_Tracebacks : Integer;");
606 WBI (" pragma Import (C, Exception_Tracebacks, " &
607 """__gl_exception_tracebacks"");");
608 end if;
610 WBI (" Zero_Cost_Exceptions : Integer;");
611 WBI (" pragma Import (C, Zero_Cost_Exceptions, " &
612 """__gl_zero_cost_exceptions"");");
613 WBI (" Detect_Blocking : Integer;");
614 WBI (" pragma Import (C, Detect_Blocking, " &
615 """__gl_detect_blocking"");");
616 WBI (" Default_Stack_Size : Integer;");
617 WBI (" pragma Import (C, Default_Stack_Size, " &
618 """__gl_default_stack_size"");");
619 WBI (" Leap_Seconds_Support : Integer;");
620 WBI (" pragma Import (C, Leap_Seconds_Support, " &
621 """__gl_leap_seconds_support"");");
623 -- Import entry point for elaboration time signal handler
624 -- installation, and indication of if it's been called previously.
626 WBI ("");
627 WBI (" procedure Install_Handler;");
628 WBI (" pragma Import (C, Install_Handler, " &
629 """__gnat_install_handler"");");
630 WBI ("");
631 WBI (" Handler_Installed : Integer;");
632 WBI (" pragma Import (C, Handler_Installed, " &
633 """__gnat_handler_installed"");");
635 -- The import of the soft link which performs library-level object
636 -- finalization is not needed for VM targets; regular Ada is used in
637 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
638 -- tasks are non-terminating, so we do not want finalization.
640 if VM_Target = No_VM and then not Configurable_Run_Time_On_Target then
641 WBI ("");
642 WBI (" Finalize_Library_Objects : No_Param_Proc;");
643 WBI (" pragma Import (C, Finalize_Library_Objects, " &
644 """__gnat_finalize_library_objects"");");
645 end if;
647 -- Import entry point for environment feature enable/disable
648 -- routine, and indication that it's been called previously.
650 if OpenVMS_On_Target then
651 WBI ("");
652 WBI (" procedure Set_Features;");
653 WBI (" pragma Import (C, Set_Features, " &
654 """__gnat_set_features"");");
655 WBI ("");
656 WBI (" Features_Set : Integer;");
657 WBI (" pragma Import (C, Features_Set, " &
658 """__gnat_features_set"");");
660 if Opt.Heap_Size /= 0 then
661 WBI ("");
662 WBI (" Heap_Size : Integer;");
663 WBI (" pragma Import (C, Heap_Size, " &
664 """__gl_heap_size"");");
666 Write_Statement_Buffer;
667 end if;
668 end if;
670 -- Initialize stack limit variable of the environment task if the
671 -- stack check method is stack limit and stack check is enabled.
673 if Stack_Check_Limits_On_Target
674 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
675 then
676 WBI ("");
677 WBI (" procedure Initialize_Stack_Limit;");
678 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
679 """__gnat_initialize_stack_limit"");");
680 end if;
682 -- Special processing when main program is CIL function/procedure
684 if VM_Target = CLI_Target
685 and then Bind_Main_Program
686 and then not No_Main_Subprogram
687 then
688 WBI ("");
690 -- Function case, use Set_Exit_Status to report the returned
691 -- status code, since that is the only mechanism available.
693 if ALIs.Table (ALIs.First).Main_Program = Func then
694 WBI (" Result : Integer;");
695 WBI (" procedure Set_Exit_Status (Code : Integer);");
696 WBI (" pragma Import (C, Set_Exit_Status, " &
697 """__gnat_set_exit_status"");");
698 WBI ("");
699 WBI (" function Ada_Main_Program return Integer;");
701 -- Procedure case
703 else
704 WBI (" procedure Ada_Main_Program;");
705 end if;
707 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
708 Name_Len := Name_Len - 2;
709 WBI (" pragma Import (CIL, Ada_Main_Program, """
710 & Name_Buffer (1 .. Name_Len) & "."
711 & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len)) & """);");
712 end if;
714 -- When dispatching domains are used then we need to signal it
715 -- before calling the main procedure.
717 if Dispatching_Domains_Used then
718 WBI (" procedure Freeze_Dispatching_Domains;");
719 WBI (" pragma Import");
720 WBI (" (Ada, Freeze_Dispatching_Domains, " &
721 """__gnat_freeze_dispatching_domains"");");
722 end if;
724 WBI (" begin");
725 WBI (" if Is_Elaborated then");
726 WBI (" return;");
727 WBI (" end if;");
728 WBI (" Is_Elaborated := True;");
730 Set_String (" Main_Priority := ");
731 Set_Int (Main_Priority);
732 Set_Char (';');
733 Write_Statement_Buffer;
735 Set_String (" Time_Slice_Value := ");
737 if Task_Dispatching_Policy_Specified = 'F'
738 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
739 then
740 Set_Int (0);
741 else
742 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
743 end if;
745 Set_Char (';');
746 Write_Statement_Buffer;
748 Set_String (" WC_Encoding := '");
749 Set_Char (Get_WC_Encoding);
751 Set_String ("';");
752 Write_Statement_Buffer;
754 Set_String (" Locking_Policy := '");
755 Set_Char (Locking_Policy_Specified);
756 Set_String ("';");
757 Write_Statement_Buffer;
759 Set_String (" Queuing_Policy := '");
760 Set_Char (Queuing_Policy_Specified);
761 Set_String ("';");
762 Write_Statement_Buffer;
764 Set_String (" Task_Dispatching_Policy := '");
765 Set_Char (Task_Dispatching_Policy_Specified);
766 Set_String ("';");
767 Write_Statement_Buffer;
769 Gen_Restrictions;
771 WBI (" Priority_Specific_Dispatching :=");
772 WBI (" Local_Priority_Specific_Dispatching'Address;");
774 Set_String (" Num_Specific_Dispatching := ");
775 Set_Int (PSD_Pragma_Settings.Last + 1);
776 Set_Char (';');
777 Write_Statement_Buffer;
779 Set_String (" Main_CPU := ");
780 Set_Int (Main_CPU);
781 Set_Char (';');
782 Write_Statement_Buffer;
784 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
786 Set_String (" Num_Interrupt_States := ");
787 Set_Int (IS_Pragma_Settings.Last + 1);
788 Set_Char (';');
789 Write_Statement_Buffer;
791 Set_String (" Unreserve_All_Interrupts := ");
793 if Unreserve_All_Interrupts_Specified then
794 Set_String ("1");
795 else
796 Set_String ("0");
797 end if;
799 Set_Char (';');
800 Write_Statement_Buffer;
802 if Exception_Tracebacks then
803 WBI (" Exception_Tracebacks := 1;");
804 end if;
806 Set_String (" Zero_Cost_Exceptions := ");
808 if Zero_Cost_Exceptions_Specified then
809 Set_String ("1");
810 else
811 Set_String ("0");
812 end if;
814 Set_String (";");
815 Write_Statement_Buffer;
817 Set_String (" Detect_Blocking := ");
819 if Detect_Blocking then
820 Set_Int (1);
821 else
822 Set_Int (0);
823 end if;
825 Set_String (";");
826 Write_Statement_Buffer;
828 Set_String (" Default_Stack_Size := ");
829 Set_Int (Default_Stack_Size);
830 Set_String (";");
831 Write_Statement_Buffer;
833 Set_String (" Leap_Seconds_Support := ");
835 if Leap_Seconds_Support then
836 Set_Int (1);
837 else
838 Set_Int (0);
839 end if;
841 Set_String (";");
842 Write_Statement_Buffer;
844 -- Generate call to Install_Handler
846 -- In .NET, when binding with -z, we don't install the signal handler
847 -- to let the caller handle the last exception handler.
849 if VM_Target /= CLI_Target
850 or else Bind_Main_Program
851 then
852 WBI ("");
853 WBI (" if Handler_Installed = 0 then");
854 WBI (" Install_Handler;");
855 WBI (" end if;");
856 end if;
858 -- Generate call to Set_Features
860 if OpenVMS_On_Target then
861 WBI ("");
862 WBI (" if Features_Set = 0 then");
863 WBI (" Set_Features;");
864 WBI (" end if;");
866 -- Features_Set may twiddle the heap size according to a logical
867 -- name, but the binder switch must override.
869 if Opt.Heap_Size /= 0 then
870 Set_String (" Heap_Size := ");
871 Set_Int (Opt.Heap_Size);
872 Set_Char (';');
873 Write_Statement_Buffer;
874 end if;
875 end if;
876 end if;
878 -- Generate call to set Initialize_Scalar values if active
880 if Initialize_Scalars_Used then
881 WBI ("");
882 Set_String (" System.Scalar_Values.Initialize ('");
883 Set_Char (Initialize_Scalars_Mode1);
884 Set_String ("', '");
885 Set_Char (Initialize_Scalars_Mode2);
886 Set_String ("');");
887 Write_Statement_Buffer;
888 end if;
890 -- Generate assignment of default secondary stack size if set
892 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
893 WBI ("");
894 Set_String (" System.Secondary_Stack.");
895 Set_String ("Default_Secondary_Stack_Size := ");
896 Set_Int (Opt.Default_Sec_Stack_Size);
897 Set_Char (';');
898 Write_Statement_Buffer;
899 end if;
901 -- Initialize stack limit variable of the environment task if the
902 -- stack check method is stack limit and stack check is enabled.
904 if Stack_Check_Limits_On_Target
905 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
906 then
907 WBI ("");
908 WBI (" Initialize_Stack_Limit;");
909 end if;
911 -- On CodePeer, the finalization of library objects is not relevant
913 if CodePeer_Mode then
914 null;
916 -- On virtual machine targets, or on non-virtual machine ones if this
917 -- is the main program case, attach finalize_library to the soft link.
918 -- Do it only when not using a restricted run time, in which case tasks
919 -- are non-terminating, so we do not want library-level finalization.
921 elsif (VM_Target /= No_VM or else Bind_Main_Program)
922 and then not Configurable_Run_Time_On_Target
923 and then not Suppress_Standard_Library_On_Target
924 then
925 WBI ("");
927 if VM_Target = No_VM then
928 if Lib_Final_Built then
929 Set_String (" Finalize_Library_Objects := ");
930 Set_String ("finalize_library'access;");
931 else
932 Set_String (" Finalize_Library_Objects := null;");
933 end if;
935 -- On VM targets use regular Ada to set the soft link
937 else
938 if Lib_Final_Built then
939 Set_String
940 (" System.Soft_Links.Finalize_Library_Objects");
941 Set_String (" := finalize_library'access;");
942 else
943 Set_String
944 (" System.Soft_Links.Finalize_Library_Objects");
945 Set_String (" := null;");
946 end if;
947 end if;
949 Write_Statement_Buffer;
950 end if;
952 -- Generate elaboration calls
954 if not CodePeer_Mode then
955 WBI ("");
956 end if;
958 Gen_Elab_Calls;
960 -- From this point, no new dispatching domain can be created.
962 if Dispatching_Domains_Used then
963 WBI (" Freeze_Dispatching_Domains;");
964 end if;
966 -- Case of main program is CIL function or procedure
968 if VM_Target = CLI_Target
969 and then Bind_Main_Program
970 and then not No_Main_Subprogram
971 then
972 -- For function case, use Set_Exit_Status to set result
974 if ALIs.Table (ALIs.First).Main_Program = Func then
975 WBI (" Result := Ada_Main_Program;");
976 WBI (" Set_Exit_Status (Result);");
978 -- Procedure case
980 else
981 WBI (" Ada_Main_Program;");
982 end if;
983 end if;
985 WBI (" end " & Ada_Init_Name.all & ";");
986 WBI ("");
987 end Gen_Adainit;
989 --------------------------
990 -- Gen_CodePeer_Wrapper --
991 --------------------------
993 procedure Gen_CodePeer_Wrapper is
994 Callee_Name : constant String := "Ada_Main_Program";
996 begin
997 if ALIs.Table (ALIs.First).Main_Program = Proc then
998 WBI (" procedure " & CodePeer_Wrapper_Name & " is ");
999 WBI (" begin");
1000 WBI (" " & Callee_Name & ";");
1002 else
1003 WBI (" function " & CodePeer_Wrapper_Name & " return Integer is");
1004 WBI (" begin");
1005 WBI (" return " & Callee_Name & ";");
1006 end if;
1008 WBI (" end " & CodePeer_Wrapper_Name & ";");
1009 WBI ("");
1010 end Gen_CodePeer_Wrapper;
1012 --------------------
1013 -- Gen_Elab_Calls --
1014 --------------------
1016 procedure Gen_Elab_Calls is
1017 Check_Elab_Flag : Boolean;
1019 begin
1020 for E in Elab_Order.First .. Elab_Order.Last loop
1021 declare
1022 Unum : constant Unit_Id := Elab_Order.Table (E);
1023 U : Unit_Record renames Units.Table (Unum);
1025 Unum_Spec : Unit_Id;
1026 -- This is the unit number of the spec that corresponds to
1027 -- this entry. It is the same as Unum except when the body
1028 -- and spec are different and we are currently processing
1029 -- the body, in which case it is the spec (Unum + 1).
1031 begin
1032 if U.Utype = Is_Body then
1033 Unum_Spec := Unum + 1;
1034 else
1035 Unum_Spec := Unum;
1036 end if;
1038 -- Nothing to do if predefined unit in no run time mode
1040 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1041 null;
1043 -- Likewise if this is an interface to a stand alone library
1045 elsif U.SAL_Interface then
1046 null;
1048 -- Case of no elaboration code
1050 -- In CodePeer mode, we special case subprogram bodies which
1051 -- are handled in the 'else' part below, and lead to a call to
1052 -- <subp>'Elab_Subp_Body.
1054 elsif U.No_Elab
1055 and then (not CodePeer_Mode
1056 or else U.Utype = Is_Spec
1057 or else U.Utype = Is_Spec_Only
1058 or else U.Unit_Kind /= 's')
1059 then
1061 -- In the case of a body with a separate spec, where the
1062 -- separate spec has an elaboration entity defined, this is
1063 -- where we increment the elaboration entity.
1065 if U.Utype = Is_Body
1066 and then Units.Table (Unum_Spec).Set_Elab_Entity
1067 and then not CodePeer_Mode
1068 then
1069 Set_String (" E");
1070 Set_Unit_Number (Unum_Spec);
1072 -- The AAMP target has no notion of shared libraries, and
1073 -- there's no possibility of reelaboration, so we treat the
1074 -- the elaboration var as a flag instead of a counter and
1075 -- simply set it.
1077 if AAMP_On_Target then
1078 Set_String (" := 1;");
1080 -- Otherwise (normal case), increment elaboration counter
1082 else
1083 Set_String (" := E");
1084 Set_Unit_Number (Unum_Spec);
1085 Set_String (" + 1;");
1086 end if;
1088 Write_Statement_Buffer;
1090 -- In the special case where the target is AAMP and the unit is
1091 -- a spec with a body, the elaboration entity is initialized
1092 -- here. This is done because it's the only way to accomplish
1093 -- initialization of such entities, as there is no mechanism
1094 -- provided for initializing global variables at load time on
1095 -- AAMP.
1097 elsif AAMP_On_Target
1098 and then U.Utype = Is_Spec
1099 and then Units.Table (Unum_Spec).Set_Elab_Entity
1100 then
1101 Set_String (" E");
1102 Set_Unit_Number (Unum_Spec);
1103 Set_String (" := 0;");
1104 Write_Statement_Buffer;
1105 end if;
1107 -- Here if elaboration code is present. If binding a library
1108 -- or if there is a non-Ada main subprogram then we generate:
1110 -- if uname_E = 0 then
1111 -- uname'elab_[spec|body];
1112 -- end if;
1113 -- uname_E := uname_E + 1;
1115 -- Otherwise, elaboration routines are called unconditionally:
1117 -- uname'elab_[spec|body];
1118 -- uname_E := uname_E + 1;
1120 -- The uname_E increment is skipped if this is a separate spec,
1121 -- since it will be done when we process the body.
1123 -- In CodePeer mode, we do not generate any reference to xxx_E
1124 -- variables, only calls to 'Elab* subprograms.
1126 else
1127 -- In the special case where the target is AAMP and the unit is
1128 -- a spec with a body, the elaboration entity is initialized
1129 -- here. This is done because it's the only way to accomplish
1130 -- initialization of such entities, as there is no mechanism
1131 -- provided for initializing global variables at load time on
1132 -- AAMP.
1134 if AAMP_On_Target
1135 and then U.Utype = Is_Spec
1136 and then Units.Table (Unum_Spec).Set_Elab_Entity
1137 then
1138 Set_String (" E");
1139 Set_Unit_Number (Unum_Spec);
1140 Set_String (" := 0;");
1141 Write_Statement_Buffer;
1142 end if;
1144 Check_Elab_Flag :=
1145 not CodePeer_Mode
1146 and then (Force_Checking_Of_Elaboration_Flags
1147 or Interface_Library_Unit
1148 or not Bind_Main_Program);
1150 if Check_Elab_Flag then
1151 Set_String (" if E");
1152 Set_Unit_Number (Unum_Spec);
1153 Set_String (" = 0 then");
1154 Write_Statement_Buffer;
1155 Set_String (" ");
1156 end if;
1158 Set_String (" ");
1159 Get_Decoded_Name_String_With_Brackets (U.Uname);
1161 if VM_Target = CLI_Target and then U.Unit_Kind /= 's' then
1162 if Name_Buffer (Name_Len) = 's' then
1163 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1164 "_pkg'elab_spec";
1165 else
1166 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1167 "_pkg'elab_body";
1168 end if;
1170 Name_Len := Name_Len + 12;
1172 else
1173 if Name_Buffer (Name_Len) = 's' then
1174 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1175 "'elab_spec";
1176 Name_Len := Name_Len + 8;
1178 -- Special case in CodePeer mode for subprogram bodies
1179 -- which correspond to CodePeer 'Elab_Subp_Body special
1180 -- init procedure.
1182 elsif U.Unit_Kind = 's' and CodePeer_Mode then
1183 Name_Buffer (Name_Len - 1 .. Name_Len + 13) :=
1184 "'elab_subp_body";
1185 Name_Len := Name_Len + 13;
1187 else
1188 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1189 "'elab_body";
1190 Name_Len := Name_Len + 8;
1191 end if;
1192 end if;
1194 Set_Casing (U.Icasing);
1195 Set_Name_Buffer;
1196 Set_Char (';');
1197 Write_Statement_Buffer;
1199 if Check_Elab_Flag then
1200 WBI (" end if;");
1201 end if;
1203 if U.Utype /= Is_Spec
1204 and then not CodePeer_Mode
1205 then
1206 Set_String (" E");
1207 Set_Unit_Number (Unum_Spec);
1209 -- The AAMP target has no notion of shared libraries, and
1210 -- there's no possibility of reelaboration, so we treat the
1211 -- the elaboration var as a flag instead of a counter and
1212 -- simply set it.
1214 if AAMP_On_Target then
1215 Set_String (" := 1;");
1217 -- Otherwise (normal case), increment elaboration counter
1219 else
1220 Set_String (" := E");
1221 Set_Unit_Number (Unum_Spec);
1222 Set_String (" + 1;");
1223 end if;
1225 Write_Statement_Buffer;
1226 end if;
1227 end if;
1228 end;
1229 end loop;
1230 end Gen_Elab_Calls;
1232 ------------------------
1233 -- Gen_Elab_Externals --
1234 ------------------------
1236 procedure Gen_Elab_Externals is
1237 begin
1238 if CodePeer_Mode then
1239 return;
1240 end if;
1242 for E in Elab_Order.First .. Elab_Order.Last loop
1243 declare
1244 Unum : constant Unit_Id := Elab_Order.Table (E);
1245 U : Unit_Record renames Units.Table (Unum);
1247 begin
1248 -- Check for Elab_Entity to be set for this unit
1250 if U.Set_Elab_Entity
1252 -- Don't generate reference for stand alone library
1254 and then not U.SAL_Interface
1256 -- Don't generate reference for predefined file in No_Run_Time
1257 -- mode, since we don't include the object files in this case
1259 and then not
1260 (No_Run_Time_Mode
1261 and then Is_Predefined_File_Name (U.Sfile))
1262 then
1263 Set_String (" ");
1264 Set_String ("E");
1265 Set_Unit_Number (Unum);
1267 case VM_Target is
1268 when No_VM | JVM_Target =>
1269 Set_String (" : Short_Integer; pragma Import (Ada, ");
1270 when CLI_Target =>
1271 Set_String (" : Short_Integer; pragma Import (CIL, ");
1272 end case;
1274 Set_String ("E");
1275 Set_Unit_Number (Unum);
1276 Set_String (", """);
1277 Get_Name_String (U.Uname);
1279 -- In the case of JGNAT we need to emit an Import name that
1280 -- includes the class name (using '$' separators in the case
1281 -- of a child unit name).
1283 if VM_Target /= No_VM then
1284 for J in 1 .. Name_Len - 2 loop
1285 if VM_Target = CLI_Target
1286 or else Name_Buffer (J) /= '.'
1287 then
1288 Set_Char (Name_Buffer (J));
1289 else
1290 Set_String ("$");
1291 end if;
1292 end loop;
1294 if VM_Target /= CLI_Target or else U.Unit_Kind = 's' then
1295 Set_String (".");
1296 else
1297 Set_String ("_pkg.");
1298 end if;
1300 -- If the unit name is very long, then split the
1301 -- Import link name across lines using "&" (occurs
1302 -- in some C2 tests).
1304 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
1305 Set_String (""" &");
1306 Write_Statement_Buffer;
1307 Set_String (" """);
1308 end if;
1309 end if;
1311 Set_Unit_Name;
1312 Set_String ("_E"");");
1313 Write_Statement_Buffer;
1314 end if;
1315 end;
1316 end loop;
1318 WBI ("");
1319 end Gen_Elab_Externals;
1321 --------------------
1322 -- Gen_Elab_Order --
1323 --------------------
1325 procedure Gen_Elab_Order is
1326 begin
1327 WBI (" -- BEGIN ELABORATION ORDER");
1329 for J in Elab_Order.First .. Elab_Order.Last loop
1330 Set_String (" -- ");
1331 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1332 Set_Name_Buffer;
1333 Write_Statement_Buffer;
1334 end loop;
1336 WBI (" -- END ELABORATION ORDER");
1337 WBI ("");
1338 end Gen_Elab_Order;
1340 --------------------------
1341 -- Gen_Finalize_Library --
1342 --------------------------
1344 procedure Gen_Finalize_Library is
1345 Count : Int := 1;
1346 U : Unit_Record;
1347 Uspec : Unit_Record;
1348 Unum : Unit_Id;
1350 procedure Gen_Header;
1351 -- Generate the header of the finalization routine
1353 ----------------
1354 -- Gen_Header --
1355 ----------------
1357 procedure Gen_Header is
1358 begin
1359 WBI (" procedure finalize_library is");
1360 WBI (" begin");
1361 end Gen_Header;
1363 -- Start of processing for Gen_Finalize_Library
1365 begin
1366 if CodePeer_Mode then
1367 return;
1368 end if;
1370 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1371 Unum := Elab_Order.Table (E);
1372 U := Units.Table (Unum);
1374 -- Dealing with package bodies is a little complicated. In such
1375 -- cases we must retrieve the package spec since it contains the
1376 -- spec of the body finalizer.
1378 if U.Utype = Is_Body then
1379 Unum := Unum + 1;
1380 Uspec := Units.Table (Unum);
1381 else
1382 Uspec := U;
1383 end if;
1385 Get_Name_String (Uspec.Uname);
1387 -- We are only interested in non-generic packages
1389 if U.Unit_Kind /= 'p' or else U.Is_Generic then
1390 null;
1392 -- That aren't an interface to a stand alone library
1394 elsif U.SAL_Interface then
1395 null;
1397 -- Case of no finalization
1399 elsif not U.Has_Finalizer then
1401 -- The only case in which we have to do something is if this
1402 -- is a body, with a separate spec, where the separate spec
1403 -- has a finalizer. In that case, this is where we decrement
1404 -- the elaboration entity.
1406 if U.Utype = Is_Body and then Uspec.Has_Finalizer then
1407 if not Lib_Final_Built then
1408 Gen_Header;
1409 Lib_Final_Built := True;
1410 end if;
1412 Set_String (" E");
1413 Set_Unit_Number (Unum);
1414 Set_String (" := E");
1415 Set_Unit_Number (Unum);
1416 Set_String (" - 1;");
1417 Write_Statement_Buffer;
1418 end if;
1420 else
1421 if not Lib_Final_Built then
1422 Gen_Header;
1423 Lib_Final_Built := True;
1424 end if;
1426 -- Generate:
1427 -- declare
1428 -- procedure F<Count>;
1430 Set_String (" declare");
1431 Write_Statement_Buffer;
1433 Set_String (" procedure F");
1434 Set_Int (Count);
1435 Set_Char (';');
1436 Write_Statement_Buffer;
1438 -- Generate:
1439 -- pragma Import (CIL, F<Count>,
1440 -- "xx.yy_pkg.xx__yy__finalize_[body|spec]");
1441 -- -- for .NET targets
1443 -- pragma Import (Java, F<Count>,
1444 -- "xx$yy.xx__yy__finalize_[body|spec]");
1445 -- -- for JVM targets
1447 -- pragma Import (Ada, F<Count>,
1448 -- "xx__yy__finalize_[body|spec]");
1449 -- -- for default targets
1451 if VM_Target = CLI_Target then
1452 Set_String (" pragma Import (CIL, F");
1453 elsif VM_Target = JVM_Target then
1454 Set_String (" pragma Import (Java, F");
1455 else
1456 Set_String (" pragma Import (Ada, F");
1457 end if;
1459 Set_Int (Count);
1460 Set_String (", """);
1462 -- Perform name construction
1464 -- .NET xx.yy_pkg.xx__yy__finalize
1466 if VM_Target = CLI_Target then
1467 Set_Unit_Name (Mode => Dot);
1468 Set_String ("_pkg.");
1470 -- JVM xx$yy.xx__yy__finalize
1472 elsif VM_Target = JVM_Target then
1473 Set_Unit_Name (Mode => Dollar_Sign);
1474 Set_Char ('.');
1475 end if;
1477 -- Default xx__yy__finalize
1479 Set_Unit_Name;
1480 Set_String ("__finalize_");
1482 -- Package spec processing
1484 if U.Utype = Is_Spec
1485 or else U.Utype = Is_Spec_Only
1486 then
1487 Set_String ("spec");
1489 -- Package body processing
1491 else
1492 Set_String ("body");
1493 end if;
1495 Set_String (""");");
1496 Write_Statement_Buffer;
1498 -- If binding a library or if there is a non-Ada main subprogram
1499 -- then we generate:
1501 -- begin
1502 -- uname_E := uname_E - 1;
1503 -- if uname_E = 0 then
1504 -- F<Count>;
1505 -- end if;
1506 -- end;
1508 -- Otherwise, finalization routines are called unconditionally:
1510 -- begin
1511 -- uname_E := uname_E - 1;
1512 -- F<Count>;
1513 -- end;
1515 -- The uname_E decrement is skipped if this is a separate spec,
1516 -- since it will be done when we process the body.
1518 WBI (" begin");
1520 if U.Utype /= Is_Spec then
1521 Set_String (" E");
1522 Set_Unit_Number (Unum);
1523 Set_String (" := E");
1524 Set_Unit_Number (Unum);
1525 Set_String (" - 1;");
1526 Write_Statement_Buffer;
1527 end if;
1529 if Interface_Library_Unit or not Bind_Main_Program then
1530 Set_String (" if E");
1531 Set_Unit_Number (Unum);
1532 Set_String (" = 0 then");
1533 Write_Statement_Buffer;
1534 Set_String (" ");
1535 end if;
1537 Set_String (" F");
1538 Set_Int (Count);
1539 Set_Char (';');
1540 Write_Statement_Buffer;
1542 if Interface_Library_Unit or not Bind_Main_Program then
1543 WBI (" end if;");
1544 end if;
1546 WBI (" end;");
1548 Count := Count + 1;
1549 end if;
1550 end loop;
1552 if Lib_Final_Built then
1554 -- It is possible that the finalization of a library-level object
1555 -- raised an exception. In that case import the actual exception
1556 -- and the routine necessary to raise it.
1558 if VM_Target = No_VM then
1559 WBI (" declare");
1560 WBI (" procedure Reraise_Library_Exception_If_Any;");
1562 Set_String (" pragma Import (Ada, ");
1563 Set_String ("Reraise_Library_Exception_If_Any, ");
1564 Set_String ("""__gnat_reraise_library_exception_if_any"");");
1565 Write_Statement_Buffer;
1567 WBI (" begin");
1568 WBI (" Reraise_Library_Exception_If_Any;");
1569 WBI (" end;");
1571 -- VM-specific code, use regular Ada to produce the desired behavior
1573 else
1574 WBI (" if System.Soft_Links.Library_Exception_Set then");
1576 Set_String (" Ada.Exceptions.Reraise_Occurrence (");
1577 Set_String ("System.Soft_Links.Library_Exception);");
1578 Write_Statement_Buffer;
1580 WBI (" end if;");
1581 end if;
1583 WBI (" end finalize_library;");
1584 WBI ("");
1585 end if;
1586 end Gen_Finalize_Library;
1588 --------------
1589 -- Gen_Main --
1590 --------------
1592 procedure Gen_Main is
1593 begin
1594 if not No_Main_Subprogram then
1596 -- To call the main program, we declare it using a pragma Import
1597 -- Ada with the right link name.
1599 -- It might seem more obvious to "with" the main program, and call
1600 -- it in the normal Ada manner. We do not do this for three
1601 -- reasons:
1603 -- 1. It is more efficient not to recompile the main program
1604 -- 2. We are not entitled to assume the source is accessible
1605 -- 3. We don't know what options to use to compile it
1607 -- It is really reason 3 that is most critical (indeed we used
1608 -- to generate the "with", but several regression tests failed).
1610 if ALIs.Table (ALIs.First).Main_Program = Func then
1611 WBI (" function Ada_Main_Program return Integer;");
1612 else
1613 WBI (" procedure Ada_Main_Program;");
1614 end if;
1616 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1617 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1618 Set_Main_Program_Name;
1619 Set_String (""");");
1621 Write_Statement_Buffer;
1622 WBI ("");
1624 -- For CodePeer, declare a wrapper for the user-defined main program
1626 if CodePeer_Mode then
1627 Gen_CodePeer_Wrapper;
1628 end if;
1629 end if;
1631 if Exit_Status_Supported_On_Target then
1632 Set_String (" function ");
1633 else
1634 Set_String (" procedure ");
1635 end if;
1637 Set_String (Get_Main_Name);
1639 if Command_Line_Args_On_Target then
1640 Write_Statement_Buffer;
1641 WBI (" (argc : Integer;");
1642 WBI (" argv : System.Address;");
1643 WBI (" envp : System.Address)");
1645 if Exit_Status_Supported_On_Target then
1646 WBI (" return Integer");
1647 end if;
1649 WBI (" is");
1651 else
1652 if Exit_Status_Supported_On_Target then
1653 Set_String (" return Integer is");
1654 else
1655 Set_String (" is");
1656 end if;
1658 Write_Statement_Buffer;
1659 end if;
1661 if Opt.Default_Exit_Status /= 0
1662 and then Bind_Main_Program
1663 and then not Configurable_Run_Time_Mode
1664 then
1665 WBI (" procedure Set_Exit_Status (Status : Integer);");
1666 WBI (" pragma Import (C, Set_Exit_Status, " &
1667 """__gnat_set_exit_status"");");
1668 WBI ("");
1669 end if;
1671 -- Initialize and Finalize
1673 if not CodePeer_Mode
1674 and then not Cumulative_Restrictions.Set (No_Finalization)
1675 then
1676 WBI (" procedure Initialize (Addr : System.Address);");
1677 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1678 WBI ("");
1679 WBI (" procedure Finalize;");
1680 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1681 end if;
1683 -- If we want to analyze the stack, we must import corresponding symbols
1685 if Dynamic_Stack_Measurement then
1686 WBI ("");
1687 WBI (" procedure Output_Results;");
1688 WBI (" pragma Import (C, Output_Results, " &
1689 """__gnat_stack_usage_output_results"");");
1691 WBI ("");
1692 WBI (" " &
1693 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1694 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1695 """__gnat_stack_usage_initialize"");");
1696 end if;
1698 -- Deal with declarations for main program case
1700 if not No_Main_Subprogram then
1701 if ALIs.Table (ALIs.First).Main_Program = Func then
1702 WBI (" Result : Integer;");
1703 WBI ("");
1704 end if;
1706 if Bind_Main_Program
1707 and not Suppress_Standard_Library_On_Target
1708 and not CodePeer_Mode
1709 then
1710 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1711 WBI ("");
1712 end if;
1713 end if;
1715 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1716 -- not referenced elsewhere in the generated program, but is needed
1717 -- by the debugger (that's why it is generated in the first place).
1718 -- The reference stops Ada_Main_Program_Name from being optimized
1719 -- away by smart linkers, such as the AiX linker.
1721 -- Because this variable is unused, we make this variable "aliased"
1722 -- with a pragma Volatile in order to tell the compiler to preserve
1723 -- this variable at any level of optimization.
1725 if Bind_Main_Program and not CodePeer_Mode then
1726 WBI (" Ensure_Reference : aliased System.Address := " &
1727 "Ada_Main_Program_Name'Address;");
1728 WBI (" pragma Volatile (Ensure_Reference);");
1729 WBI ("");
1730 end if;
1732 WBI (" begin");
1734 -- Acquire command line arguments if present on target
1736 if CodePeer_Mode then
1737 null;
1739 elsif Command_Line_Args_On_Target then
1740 WBI (" gnat_argc := argc;");
1741 WBI (" gnat_argv := argv;");
1742 WBI (" gnat_envp := envp;");
1743 WBI ("");
1745 -- If configurable run time and no command line args, then nothing
1746 -- needs to be done since the gnat_argc/argv/envp variables are
1747 -- suppressed in this case.
1749 elsif Configurable_Run_Time_On_Target then
1750 null;
1752 -- Otherwise set dummy values (to be filled in by some other unit?)
1754 else
1755 WBI (" gnat_argc := 0;");
1756 WBI (" gnat_argv := System.Null_Address;");
1757 WBI (" gnat_envp := System.Null_Address;");
1758 end if;
1760 if Opt.Default_Exit_Status /= 0
1761 and then Bind_Main_Program
1762 and then not Configurable_Run_Time_Mode
1763 then
1764 Set_String (" Set_Exit_Status (");
1765 Set_Int (Opt.Default_Exit_Status);
1766 Set_String (");");
1767 Write_Statement_Buffer;
1768 end if;
1770 if Dynamic_Stack_Measurement then
1771 Set_String (" Initialize_Stack_Analysis (");
1772 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1773 Set_String (");");
1774 Write_Statement_Buffer;
1775 end if;
1777 if not Cumulative_Restrictions.Set (No_Finalization)
1778 and then not CodePeer_Mode
1779 then
1780 if not No_Main_Subprogram
1781 and then Bind_Main_Program
1782 and then not Suppress_Standard_Library_On_Target
1783 then
1784 WBI (" Initialize (SEH'Address);");
1785 else
1786 WBI (" Initialize (System.Null_Address);");
1787 end if;
1788 end if;
1790 WBI (" " & Ada_Init_Name.all & ";");
1792 if not No_Main_Subprogram then
1793 if CodePeer_Mode then
1794 if ALIs.Table (ALIs.First).Main_Program = Proc then
1795 WBI (" " & CodePeer_Wrapper_Name & ";");
1796 else
1797 WBI (" Result := " & CodePeer_Wrapper_Name & ";");
1798 end if;
1800 elsif ALIs.Table (ALIs.First).Main_Program = Proc then
1801 WBI (" Ada_Main_Program;");
1803 else
1804 WBI (" Result := Ada_Main_Program;");
1805 end if;
1806 end if;
1808 -- Adafinal call is skipped if no finalization
1810 if not Cumulative_Restrictions.Set (No_Finalization) then
1811 WBI (" adafinal;");
1812 end if;
1814 -- Prints the result of static stack analysis
1816 if Dynamic_Stack_Measurement then
1817 WBI (" Output_Results;");
1818 end if;
1820 -- Finalize is only called if we have a run time
1822 if not Cumulative_Restrictions.Set (No_Finalization)
1823 and then not CodePeer_Mode
1824 then
1825 WBI (" Finalize;");
1826 end if;
1828 -- Return result
1830 if Exit_Status_Supported_On_Target then
1831 if No_Main_Subprogram
1832 or else ALIs.Table (ALIs.First).Main_Program = Proc
1833 then
1834 WBI (" return (gnat_exit_status);");
1835 else
1836 WBI (" return (Result);");
1837 end if;
1838 end if;
1840 WBI (" end;");
1841 WBI ("");
1842 end Gen_Main;
1844 ------------------------------
1845 -- Gen_Object_Files_Options --
1846 ------------------------------
1848 procedure Gen_Object_Files_Options is
1849 Lgnat : Natural;
1850 -- This keeps track of the position in the sorted set of entries
1851 -- in the Linker_Options table of where the first entry from an
1852 -- internal file appears.
1854 Linker_Option_List_Started : Boolean := False;
1855 -- Set to True when "LINKER OPTION LIST" is displayed
1857 procedure Write_Linker_Option;
1858 -- Write binder info linker option
1860 -------------------------
1861 -- Write_Linker_Option --
1862 -------------------------
1864 procedure Write_Linker_Option is
1865 Start : Natural;
1866 Stop : Natural;
1868 begin
1869 -- Loop through string, breaking at null's
1871 Start := 1;
1872 while Start < Name_Len loop
1874 -- Find null ending this section
1876 Stop := Start + 1;
1877 while Name_Buffer (Stop) /= ASCII.NUL
1878 and then Stop <= Name_Len loop
1879 Stop := Stop + 1;
1880 end loop;
1882 -- Process section if non-null
1884 if Stop > Start then
1885 if Output_Linker_Option_List then
1886 if not Zero_Formatting then
1887 if not Linker_Option_List_Started then
1888 Linker_Option_List_Started := True;
1889 Write_Eol;
1890 Write_Str (" LINKER OPTION LIST");
1891 Write_Eol;
1892 Write_Eol;
1893 end if;
1895 Write_Str (" ");
1896 end if;
1898 Write_Str (Name_Buffer (Start .. Stop - 1));
1899 Write_Eol;
1900 end if;
1901 WBI (" -- " & Name_Buffer (Start .. Stop - 1));
1902 end if;
1904 Start := Stop + 1;
1905 end loop;
1906 end Write_Linker_Option;
1908 -- Start of processing for Gen_Object_Files_Options
1910 begin
1911 WBI ("-- BEGIN Object file/option list");
1913 if Object_List_Filename /= null then
1914 Set_List_File (Object_List_Filename.all);
1915 end if;
1917 for E in Elab_Order.First .. Elab_Order.Last loop
1919 -- If not spec that has an associated body, then generate a comment
1920 -- giving the name of the corresponding object file.
1922 if not Units.Table (Elab_Order.Table (E)).SAL_Interface
1923 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1924 then
1925 Get_Name_String
1926 (ALIs.Table
1927 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1929 -- If the presence of an object file is necessary or if it exists,
1930 -- then use it.
1932 if not Hostparm.Exclude_Missing_Objects
1933 or else
1934 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1935 then
1936 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1938 if Output_Object_List then
1939 Write_Str (Name_Buffer (1 .. Name_Len));
1940 Write_Eol;
1941 end if;
1942 end if;
1943 end if;
1944 end loop;
1946 if Object_List_Filename /= null then
1947 Close_List_File;
1948 end if;
1950 -- Add a "-Ldir" for each directory in the object path
1951 if VM_Target /= CLI_Target then
1952 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1953 declare
1954 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1955 begin
1956 Name_Len := 0;
1957 Add_Str_To_Name_Buffer ("-L");
1958 Add_Str_To_Name_Buffer (Dir.all);
1959 Write_Linker_Option;
1960 end;
1961 end loop;
1962 end if;
1964 -- Sort linker options
1966 -- This sort accomplishes two important purposes:
1968 -- a) All application files are sorted to the front, and all GNAT
1969 -- internal files are sorted to the end. This results in a well
1970 -- defined dividing line between the two sets of files, for the
1971 -- purpose of inserting certain standard library references into
1972 -- the linker arguments list.
1974 -- b) Given two different units, we sort the linker options so that
1975 -- those from a unit earlier in the elaboration order comes later
1976 -- in the list. This is a heuristic designed to create a more
1977 -- friendly order of linker options when the operations appear in
1978 -- separate units. The idea is that if unit A must be elaborated
1979 -- before unit B, then it is more likely that B references
1980 -- libraries included by A, than vice versa, so we want libraries
1981 -- included by A to come after libraries included by B.
1983 -- These two criteria are implemented by function Lt_Linker_Option. Note
1984 -- that a special case of b) is that specs are elaborated before bodies,
1985 -- so linker options from specs come after linker options for bodies,
1986 -- and again, the assumption is that libraries used by the body are more
1987 -- likely to reference libraries used by the spec, than vice versa.
1989 Sort
1990 (Linker_Options.Last,
1991 Move_Linker_Option'Access,
1992 Lt_Linker_Option'Access);
1994 -- Write user linker options, i.e. the set of linker options that come
1995 -- from all files other than GNAT internal files, Lgnat is left set to
1996 -- point to the first entry from a GNAT internal file, or past the end
1997 -- of the entries if there are no internal files.
1999 Lgnat := Linker_Options.Last + 1;
2001 for J in 1 .. Linker_Options.Last loop
2002 if not Linker_Options.Table (J).Internal_File then
2003 Get_Name_String (Linker_Options.Table (J).Name);
2004 Write_Linker_Option;
2005 else
2006 Lgnat := J;
2007 exit;
2008 end if;
2009 end loop;
2011 -- Now we insert standard linker options that must appear after the
2012 -- entries from user files, and before the entries from GNAT run-time
2013 -- files. The reason for this decision is that libraries referenced
2014 -- by internal routines may reference these standard library entries.
2016 -- Note that we do not insert anything when pragma No_Run_Time has been
2017 -- specified or when the standard libraries are not to be used,
2018 -- otherwise on some platforms, such as VMS, we may get duplicate
2019 -- symbols when linking.
2021 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
2022 Name_Len := 0;
2024 if Opt.Shared_Libgnat then
2025 Add_Str_To_Name_Buffer ("-shared");
2026 else
2027 Add_Str_To_Name_Buffer ("-static");
2028 end if;
2030 -- Write directly to avoid -K output (why???)
2032 WBI (" -- " & Name_Buffer (1 .. Name_Len));
2034 if With_DECGNAT then
2035 Name_Len := 0;
2037 if Opt.Shared_Libgnat then
2038 Add_Str_To_Name_Buffer (Shared_Lib ("decgnat"));
2039 else
2040 Add_Str_To_Name_Buffer ("-ldecgnat");
2041 end if;
2043 Write_Linker_Option;
2044 end if;
2046 if With_GNARL then
2047 Name_Len := 0;
2049 if Opt.Shared_Libgnat then
2050 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
2051 else
2052 Add_Str_To_Name_Buffer ("-lgnarl");
2053 end if;
2055 Write_Linker_Option;
2056 end if;
2058 Name_Len := 0;
2060 if Opt.Shared_Libgnat then
2061 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
2062 else
2063 Add_Str_To_Name_Buffer ("-lgnat");
2064 end if;
2066 Write_Linker_Option;
2067 end if;
2069 -- Write linker options from all internal files
2071 for J in Lgnat .. Linker_Options.Last loop
2072 Get_Name_String (Linker_Options.Table (J).Name);
2073 Write_Linker_Option;
2074 end loop;
2076 if Output_Linker_Option_List and then not Zero_Formatting then
2077 Write_Eol;
2078 end if;
2080 WBI ("-- END Object file/option list ");
2081 end Gen_Object_Files_Options;
2083 ---------------------
2084 -- Gen_Output_File --
2085 ---------------------
2087 procedure Gen_Output_File (Filename : String) is
2088 begin
2089 -- Acquire settings for Interrupt_State pragmas
2091 Set_IS_Pragma_Table;
2093 -- Acquire settings for Priority_Specific_Dispatching pragma
2095 Set_PSD_Pragma_Table;
2097 -- For JGNAT the main program is already generated by the compiler
2099 if VM_Target = JVM_Target then
2100 Bind_Main_Program := False;
2101 end if;
2103 -- Override time slice value if -T switch is set
2105 if Time_Slice_Set then
2106 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
2107 end if;
2109 -- Count number of elaboration calls
2111 for E in Elab_Order.First .. Elab_Order.Last loop
2112 if Units.Table (Elab_Order.Table (E)).No_Elab then
2113 null;
2114 else
2115 Num_Elab_Calls := Num_Elab_Calls + 1;
2116 end if;
2117 end loop;
2119 -- Generate output file in appropriate language
2121 Check_System_Restrictions_Used;
2122 Check_Dispatching_Domains_Used;
2124 Gen_Output_File_Ada (Filename);
2125 end Gen_Output_File;
2127 -------------------------
2128 -- Gen_Output_File_Ada --
2129 -------------------------
2131 procedure Gen_Output_File_Ada (Filename : String) is
2133 Ada_Main : constant String := Get_Ada_Main_Name;
2134 -- Name to be used for generated Ada main program. See the body of
2135 -- function Get_Ada_Main_Name for details on the form of the name.
2137 Needs_Library_Finalization : constant Boolean :=
2138 not Configurable_Run_Time_On_Target
2139 and then Has_Finalizer;
2140 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2141 -- non-terminating, so we do not want finalization.
2143 Bfiles : Name_Id;
2144 -- Name of generated bind file (spec)
2146 Bfileb : Name_Id;
2147 -- Name of generated bind file (body)
2149 begin
2150 -- Create spec first
2152 Create_Binder_Output (Filename, 's', Bfiles);
2154 -- We always compile the binder file in Ada 95 mode so that we properly
2155 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2156 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2158 WBI ("pragma Ada_95;");
2160 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2161 -- then we need to make sure that the binder program is compiled with
2162 -- the same restriction, so that no exception tables are generated.
2164 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2165 WBI ("pragma Restrictions (No_Exception_Handlers);");
2166 end if;
2168 -- Same processing for Restrictions (No_Exception_Propagation)
2170 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
2171 WBI ("pragma Restrictions (No_Exception_Propagation);");
2172 end if;
2174 -- Same processing for pragma No_Run_Time
2176 if No_Run_Time_Mode then
2177 WBI ("pragma No_Run_Time;");
2178 end if;
2180 -- Generate with of System so we can reference System.Address
2182 WBI ("with System;");
2184 -- Generate with of System.Initialize_Scalars if active
2186 if Initialize_Scalars_Used then
2187 WBI ("with System.Scalar_Values;");
2188 end if;
2190 -- Generate with of System.Secondary_Stack if active
2192 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2193 WBI ("with System.Secondary_Stack;");
2194 end if;
2196 Resolve_Binder_Options;
2198 -- Usually, adafinal is called using a pragma Import C. Since Import C
2199 -- doesn't have the same semantics for VMs or CodePeer use standard Ada.
2201 if not Suppress_Standard_Library_On_Target then
2202 if CodePeer_Mode then
2203 WBI ("with System.Standard_Library;");
2204 elsif VM_Target /= No_VM then
2205 WBI ("with System.Soft_Links;");
2206 WBI ("with System.Standard_Library;");
2207 end if;
2208 end if;
2210 WBI ("package " & Ada_Main & " is");
2211 WBI (" pragma Warnings (Off);");
2213 -- Main program case
2215 if Bind_Main_Program then
2216 if VM_Target = No_VM then
2218 -- Generate argc/argv stuff unless suppressed
2220 if Command_Line_Args_On_Target
2221 or not Configurable_Run_Time_On_Target
2222 then
2223 WBI ("");
2224 WBI (" gnat_argc : Integer;");
2225 WBI (" gnat_argv : System.Address;");
2226 WBI (" gnat_envp : System.Address;");
2228 -- If the standard library is not suppressed, these variables
2229 -- are in the run-time data area for easy run time access.
2231 if not Suppress_Standard_Library_On_Target then
2232 WBI ("");
2233 WBI (" pragma Import (C, gnat_argc);");
2234 WBI (" pragma Import (C, gnat_argv);");
2235 WBI (" pragma Import (C, gnat_envp);");
2236 end if;
2237 end if;
2239 -- Define exit status. Again in normal mode, this is in the
2240 -- run-time library, and is initialized there, but in the
2241 -- configurable runtime case, the variable is declared and
2242 -- initialized in this file.
2244 WBI ("");
2246 if Configurable_Run_Time_Mode then
2247 if Exit_Status_Supported_On_Target then
2248 WBI (" gnat_exit_status : Integer := 0;");
2249 end if;
2251 else
2252 WBI (" gnat_exit_status : Integer;");
2253 WBI (" pragma Import (C, gnat_exit_status);");
2254 end if;
2255 end if;
2257 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2258 -- the main program. Otherwise, it can lead under some circumstances
2259 -- to a symbol duplication during the link (for instance when a C
2260 -- program uses two Ada libraries). Also zero terminate the string
2261 -- so that its end can be found reliably at run time.
2263 WBI ("");
2264 WBI (" GNAT_Version : constant String :=");
2265 WBI (" """ & Ver_Prefix &
2266 Gnat_Version_String &
2267 """ & ASCII.NUL;");
2268 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2270 WBI ("");
2271 Set_String (" Ada_Main_Program_Name : constant String := """);
2272 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2274 if VM_Target = No_VM then
2275 Set_Main_Program_Name;
2276 Set_String (""" & ASCII.NUL;");
2277 else
2278 Set_String (Name_Buffer (1 .. Name_Len - 2) & """;");
2279 end if;
2281 Write_Statement_Buffer;
2284 (" pragma Export (C, Ada_Main_Program_Name, " &
2285 """__gnat_ada_main_program_name"");");
2286 end if;
2288 WBI ("");
2289 WBI (" procedure " & Ada_Init_Name.all & ";");
2290 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2291 Ada_Init_Name.all & """);");
2293 -- If -a has been specified use pragma Linker_Constructor for the init
2294 -- procedure and pragma Linker_Destructor for the final procedure.
2296 if Use_Pragma_Linker_Constructor then
2297 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2298 end if;
2300 if not Cumulative_Restrictions.Set (No_Finalization) then
2301 WBI ("");
2302 WBI (" procedure " & Ada_Final_Name.all & ";");
2303 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2304 Ada_Final_Name.all & """);");
2306 if Use_Pragma_Linker_Constructor then
2307 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2308 end if;
2309 end if;
2311 if Bind_Main_Program and then VM_Target = No_VM then
2313 WBI ("");
2315 if Exit_Status_Supported_On_Target then
2316 Set_String (" function ");
2317 else
2318 Set_String (" procedure ");
2319 end if;
2321 Set_String (Get_Main_Name);
2323 -- Generate argument list if present
2325 if Command_Line_Args_On_Target then
2326 Write_Statement_Buffer;
2327 WBI (" (argc : Integer;");
2328 WBI (" argv : System.Address;");
2329 Set_String
2330 (" envp : System.Address)");
2332 if Exit_Status_Supported_On_Target then
2333 Write_Statement_Buffer;
2334 WBI (" return Integer;");
2335 else
2336 Write_Statement_Buffer (";");
2337 end if;
2339 else
2340 if Exit_Status_Supported_On_Target then
2341 Write_Statement_Buffer (" return Integer;");
2342 else
2343 Write_Statement_Buffer (";");
2344 end if;
2345 end if;
2347 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2348 Get_Main_Name & """);");
2349 end if;
2351 Gen_Versions;
2352 Gen_Elab_Order;
2354 -- Spec is complete
2356 WBI ("");
2357 WBI ("end " & Ada_Main & ";");
2358 Close_Binder_Output;
2360 -- Prepare to write body
2362 Create_Binder_Output (Filename, 'b', Bfileb);
2364 -- We always compile the binder file in Ada 95 mode so that we properly
2365 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2366 -- of the Ada 2005/2012 constructs are needed by the binder file.
2368 WBI ("pragma Ada_95;");
2370 -- Output Source_File_Name pragmas which look like
2372 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2373 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2375 -- where sss/bbb are the spec/body file names respectively
2377 Get_Name_String (Bfiles);
2378 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2380 WBI ("pragma Source_File_Name (" &
2381 Ada_Main &
2382 ", Spec_File_Name => """ &
2383 Name_Buffer (1 .. Name_Len + 3));
2385 Get_Name_String (Bfileb);
2386 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2388 WBI ("pragma Source_File_Name (" &
2389 Ada_Main &
2390 ", Body_File_Name => """ &
2391 Name_Buffer (1 .. Name_Len + 3));
2393 -- Generate with of System.Restrictions to initialize
2394 -- Run_Time_Restrictions.
2396 if System_Restrictions_Used
2397 and not Suppress_Standard_Library_On_Target
2398 then
2399 WBI ("");
2400 WBI ("with System.Restrictions;");
2401 end if;
2403 if Needs_Library_Finalization then
2404 WBI ("with Ada.Exceptions;");
2405 end if;
2407 WBI ("");
2408 WBI ("package body " & Ada_Main & " is");
2409 WBI (" pragma Warnings (Off);");
2410 WBI ("");
2412 -- Generate externals for elaboration entities
2414 Gen_Elab_Externals;
2416 if not CodePeer_Mode then
2417 if not Suppress_Standard_Library_On_Target then
2419 -- Generate Priority_Specific_Dispatching pragma string
2421 Set_String
2422 (" Local_Priority_Specific_Dispatching : " &
2423 "constant String := """);
2425 for J in 0 .. PSD_Pragma_Settings.Last loop
2426 Set_Char (PSD_Pragma_Settings.Table (J));
2427 end loop;
2429 Set_String (""";");
2430 Write_Statement_Buffer;
2432 -- Generate Interrupt_State pragma string
2434 Set_String (" Local_Interrupt_States : constant String := """);
2436 for J in 0 .. IS_Pragma_Settings.Last loop
2437 Set_Char (IS_Pragma_Settings.Table (J));
2438 end loop;
2440 Set_String (""";");
2441 Write_Statement_Buffer;
2442 WBI ("");
2443 end if;
2445 -- The B.1 (39) implementation advice says that the adainit/adafinal
2446 -- routines should be idempotent. Generate a flag to ensure that.
2448 WBI (" Is_Elaborated : Boolean := False;");
2449 WBI ("");
2450 end if;
2452 -- Generate the adafinal routine unless there is no finalization to do
2454 if not Cumulative_Restrictions.Set (No_Finalization) then
2455 if Needs_Library_Finalization then
2456 Gen_Finalize_Library;
2457 end if;
2459 Gen_Adafinal;
2460 end if;
2462 Gen_Adainit;
2464 if Bind_Main_Program and then VM_Target = No_VM then
2465 Gen_Main;
2466 end if;
2468 -- Output object file list and the Ada body is complete
2470 Gen_Object_Files_Options;
2472 WBI ("");
2473 WBI ("end " & Ada_Main & ";");
2475 Close_Binder_Output;
2476 end Gen_Output_File_Ada;
2478 ----------------------
2479 -- Gen_Restrictions --
2480 ----------------------
2482 procedure Gen_Restrictions is
2483 Count : Integer;
2485 begin
2486 if Suppress_Standard_Library_On_Target
2487 or not System_Restrictions_Used
2488 then
2489 return;
2490 end if;
2492 WBI (" System.Restrictions.Run_Time_Restrictions :=");
2493 WBI (" (Set =>");
2494 Set_String (" (");
2496 Count := 0;
2498 for J in Cumulative_Restrictions.Set'Range loop
2499 Set_Boolean (Cumulative_Restrictions.Set (J));
2500 Set_String (", ");
2501 Count := Count + 1;
2503 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2504 Write_Statement_Buffer;
2505 Set_String (" ");
2506 Count := 0;
2507 end if;
2508 end loop;
2510 Set_String_Replace ("),");
2511 Write_Statement_Buffer;
2512 Set_String (" Value => (");
2514 for J in Cumulative_Restrictions.Value'Range loop
2515 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2516 Set_String (", ");
2517 end loop;
2519 Set_String_Replace ("),");
2520 Write_Statement_Buffer;
2521 WBI (" Violated =>");
2522 Set_String (" (");
2523 Count := 0;
2525 for J in Cumulative_Restrictions.Violated'Range loop
2526 Set_Boolean (Cumulative_Restrictions.Violated (J));
2527 Set_String (", ");
2528 Count := Count + 1;
2530 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2531 Write_Statement_Buffer;
2532 Set_String (" ");
2533 Count := 0;
2534 end if;
2535 end loop;
2537 Set_String_Replace ("),");
2538 Write_Statement_Buffer;
2539 Set_String (" Count => (");
2541 for J in Cumulative_Restrictions.Count'Range loop
2542 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2543 Set_String (", ");
2544 end loop;
2546 Set_String_Replace ("),");
2547 Write_Statement_Buffer;
2548 Set_String (" Unknown => (");
2550 for J in Cumulative_Restrictions.Unknown'Range loop
2551 Set_Boolean (Cumulative_Restrictions.Unknown (J));
2552 Set_String (", ");
2553 end loop;
2555 Set_String_Replace ("))");
2556 Set_String (";");
2557 Write_Statement_Buffer;
2558 end Gen_Restrictions;
2560 ------------------
2561 -- Gen_Versions --
2562 ------------------
2564 -- This routine generates lines such as:
2566 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2567 -- pragma Export (C, unnnnn, unam);
2569 -- for each unit, where unam is the unit name suffixed by either B or S for
2570 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2571 -- the version number, and nnnnn is a 5-digits serial number.
2573 procedure Gen_Versions is
2574 Ubuf : String (1 .. 6) := "u00000";
2576 procedure Increment_Ubuf;
2577 -- Little procedure to increment the serial number
2579 --------------------
2580 -- Increment_Ubuf --
2581 --------------------
2583 procedure Increment_Ubuf is
2584 begin
2585 for J in reverse Ubuf'Range loop
2586 Ubuf (J) := Character'Succ (Ubuf (J));
2587 exit when Ubuf (J) <= '9';
2588 Ubuf (J) := '0';
2589 end loop;
2590 end Increment_Ubuf;
2592 -- Start of processing for Gen_Versions
2594 begin
2595 WBI ("");
2597 WBI (" type Version_32 is mod 2 ** 32;");
2598 for U in Units.First .. Units.Last loop
2599 if not Units.Table (U).SAL_Interface
2600 and then
2601 (not Bind_For_Library or else Units.Table (U).Directly_Scanned)
2602 then
2603 Increment_Ubuf;
2604 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2605 Units.Table (U).Version & "#;");
2606 Set_String (" pragma Export (C, ");
2607 Set_String (Ubuf);
2608 Set_String (", """);
2610 Get_Name_String (Units.Table (U).Uname);
2612 for K in 1 .. Name_Len loop
2613 if Name_Buffer (K) = '.' then
2614 Set_Char ('_');
2615 Set_Char ('_');
2617 elsif Name_Buffer (K) = '%' then
2618 exit;
2620 else
2621 Set_Char (Name_Buffer (K));
2622 end if;
2623 end loop;
2625 if Name_Buffer (Name_Len) = 's' then
2626 Set_Char ('S');
2627 else
2628 Set_Char ('B');
2629 end if;
2631 Set_String (""");");
2632 Write_Statement_Buffer;
2633 end if;
2634 end loop;
2635 end Gen_Versions;
2637 ------------------------
2638 -- Get_Main_Unit_Name --
2639 ------------------------
2641 function Get_Main_Unit_Name (S : String) return String is
2642 Result : String := S;
2644 begin
2645 for J in S'Range loop
2646 if Result (J) = '.' then
2647 Result (J) := '_';
2648 end if;
2649 end loop;
2651 return Result;
2652 end Get_Main_Unit_Name;
2654 -----------------------
2655 -- Get_Ada_Main_Name --
2656 -----------------------
2658 function Get_Ada_Main_Name return String is
2659 Suffix : constant String := "_00";
2660 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2661 Opt.Ada_Main_Name.all & Suffix;
2662 Nlen : Natural;
2664 begin
2665 -- The main program generated by JGNAT expects a package called
2666 -- ada_<main procedure>.
2667 if VM_Target /= No_VM then
2668 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2669 return "ada_" & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2670 end if;
2672 -- For CodePeer, we want reproducible names (independent of other
2673 -- mains that may or may not be present) that don't collide
2674 -- when analyzing multiple mains and which are easily recognizable
2675 -- as "ada_main" names.
2676 if CodePeer_Mode then
2677 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2678 return "ada_main_for_" &
2679 Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2680 end if;
2682 -- This loop tries the following possibilities in order
2683 -- <Ada_Main>
2684 -- <Ada_Main>_01
2685 -- <Ada_Main>_02
2686 -- ..
2687 -- <Ada_Main>_99
2688 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2689 -- it is set to 'ada_main'.
2691 for J in 0 .. 99 loop
2692 if J = 0 then
2693 Nlen := Name'Length - Suffix'Length;
2694 else
2695 Nlen := Name'Length;
2696 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2697 Name (Name'Last - 1) :=
2698 Character'Val (J / 10 + Character'Pos ('0'));
2699 end if;
2701 for K in ALIs.First .. ALIs.Last loop
2702 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2704 -- Get unit name, removing %b or %e at end
2706 Get_Name_String (Units.Table (L).Uname);
2707 Name_Len := Name_Len - 2;
2709 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2710 goto Continue;
2711 end if;
2712 end loop;
2713 end loop;
2715 return Name (1 .. Nlen);
2717 <<Continue>>
2718 null;
2719 end loop;
2721 -- If we fall through, just use a peculiar unlikely name
2723 return ("Qwertyuiop");
2724 end Get_Ada_Main_Name;
2726 -------------------
2727 -- Get_Main_Name --
2728 -------------------
2730 function Get_Main_Name return String is
2731 begin
2732 -- Explicit name given with -M switch
2734 if Bind_Alternate_Main_Name then
2735 return Alternate_Main_Name.all;
2737 -- Case of main program name to be used directly
2739 elsif Use_Ada_Main_Program_Name_On_Target then
2741 -- Get main program name
2743 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2745 -- If this is a child name, return only the name of the child, since
2746 -- we can't have dots in a nested program name. Note that we do not
2747 -- include the %b at the end of the unit name.
2749 for J in reverse 1 .. Name_Len - 2 loop
2750 if J = 1 or else Name_Buffer (J - 1) = '.' then
2751 return Name_Buffer (J .. Name_Len - 2);
2752 end if;
2753 end loop;
2755 raise Program_Error; -- impossible exit
2757 -- Case where "main" is to be used as default
2759 else
2760 return "main";
2761 end if;
2762 end Get_Main_Name;
2764 ---------------------
2765 -- Get_WC_Encoding --
2766 ---------------------
2768 function Get_WC_Encoding return Character is
2769 begin
2770 -- If encoding method specified by -W switch, then return it
2772 if Wide_Character_Encoding_Method_Specified then
2773 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
2775 -- If no main program, and not specified, set brackets, we really have
2776 -- no better choice. If some other encoding is required when there is
2777 -- no main, it must be set explicitly using -Wx.
2779 -- Note: if the ALI file always passed the wide character encoding of
2780 -- every file, then we could use the encoding of the initial specified
2781 -- file, but this information is passed only for potential main
2782 -- programs. We could fix this sometime, but it is a very minor point
2783 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
2784 -- is no main program).
2786 elsif No_Main_Subprogram then
2787 return 'b';
2789 -- Otherwise if there is a main program, take encoding from it
2791 else
2792 return ALIs.Table (ALIs.First).WC_Encoding;
2793 end if;
2794 end Get_WC_Encoding;
2796 -------------------
2797 -- Has_Finalizer --
2798 -------------------
2800 function Has_Finalizer return Boolean is
2801 U : Unit_Record;
2802 Unum : Unit_Id;
2804 begin
2805 for E in reverse Elab_Order.First .. Elab_Order.Last loop
2806 Unum := Elab_Order.Table (E);
2807 U := Units.Table (Unum);
2809 -- We are only interested in non-generic packages
2811 if U.Unit_Kind = 'p'
2812 and then U.Has_Finalizer
2813 and then not U.Is_Generic
2814 and then not U.No_Elab
2815 then
2816 return True;
2817 end if;
2818 end loop;
2820 return False;
2821 end Has_Finalizer;
2823 ----------------------
2824 -- Lt_Linker_Option --
2825 ----------------------
2827 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2828 begin
2829 -- Sort internal files last
2831 if Linker_Options.Table (Op1).Internal_File
2833 Linker_Options.Table (Op2).Internal_File
2834 then
2835 -- Note: following test uses False < True
2837 return Linker_Options.Table (Op1).Internal_File
2839 Linker_Options.Table (Op2).Internal_File;
2841 -- If both internal or both non-internal, sort according to the
2842 -- elaboration position. A unit that is elaborated later should come
2843 -- earlier in the linker options list.
2845 else
2846 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2848 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2850 end if;
2851 end Lt_Linker_Option;
2853 ------------------------
2854 -- Move_Linker_Option --
2855 ------------------------
2857 procedure Move_Linker_Option (From : Natural; To : Natural) is
2858 begin
2859 Linker_Options.Table (To) := Linker_Options.Table (From);
2860 end Move_Linker_Option;
2862 ----------------------------
2863 -- Resolve_Binder_Options --
2864 ----------------------------
2866 procedure Resolve_Binder_Options is
2867 begin
2868 for E in Elab_Order.First .. Elab_Order.Last loop
2869 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2871 -- This is not a perfect approach, but is the current protocol
2872 -- between the run-time and the binder to indicate that tasking is
2873 -- used: system.os_interface should always be used by any tasking
2874 -- application.
2876 if Name_Buffer (1 .. 19) = "system.os_interface" then
2877 With_GNARL := True;
2878 end if;
2880 -- Ditto for declib and the "dec" package
2882 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
2883 With_DECGNAT := True;
2884 end if;
2885 end loop;
2886 end Resolve_Binder_Options;
2888 -----------------
2889 -- Set_Boolean --
2890 -----------------
2892 procedure Set_Boolean (B : Boolean) is
2893 True_Str : constant String := "True";
2894 False_Str : constant String := "False";
2895 begin
2896 if B then
2897 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
2898 Last := Last + True_Str'Length;
2899 else
2900 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
2901 Last := Last + False_Str'Length;
2902 end if;
2903 end Set_Boolean;
2905 --------------
2906 -- Set_Char --
2907 --------------
2909 procedure Set_Char (C : Character) is
2910 begin
2911 Last := Last + 1;
2912 Statement_Buffer (Last) := C;
2913 end Set_Char;
2915 -------------
2916 -- Set_Int --
2917 -------------
2919 procedure Set_Int (N : Int) is
2920 begin
2921 if N < 0 then
2922 Set_String ("-");
2923 Set_Int (-N);
2925 else
2926 if N > 9 then
2927 Set_Int (N / 10);
2928 end if;
2930 Last := Last + 1;
2931 Statement_Buffer (Last) :=
2932 Character'Val (N mod 10 + Character'Pos ('0'));
2933 end if;
2934 end Set_Int;
2936 -------------------------
2937 -- Set_IS_Pragma_Table --
2938 -------------------------
2940 procedure Set_IS_Pragma_Table is
2941 begin
2942 for F in ALIs.First .. ALIs.Last loop
2943 for K in ALIs.Table (F).First_Interrupt_State ..
2944 ALIs.Table (F).Last_Interrupt_State
2945 loop
2946 declare
2947 Inum : constant Int :=
2948 Interrupt_States.Table (K).Interrupt_Id;
2949 Stat : constant Character :=
2950 Interrupt_States.Table (K).Interrupt_State;
2952 begin
2953 while IS_Pragma_Settings.Last < Inum loop
2954 IS_Pragma_Settings.Append ('n');
2955 end loop;
2957 IS_Pragma_Settings.Table (Inum) := Stat;
2958 end;
2959 end loop;
2960 end loop;
2961 end Set_IS_Pragma_Table;
2963 ---------------------------
2964 -- Set_Main_Program_Name --
2965 ---------------------------
2967 procedure Set_Main_Program_Name is
2968 begin
2969 -- Note that name has %b on the end which we ignore
2971 -- First we output the initial _ada_ since we know that the main
2972 -- program is a library level subprogram.
2974 Set_String ("_ada_");
2976 -- Copy name, changing dots to double underscores
2978 for J in 1 .. Name_Len - 2 loop
2979 if Name_Buffer (J) = '.' then
2980 Set_String ("__");
2981 else
2982 Set_Char (Name_Buffer (J));
2983 end if;
2984 end loop;
2985 end Set_Main_Program_Name;
2987 ---------------------
2988 -- Set_Name_Buffer --
2989 ---------------------
2991 procedure Set_Name_Buffer is
2992 begin
2993 for J in 1 .. Name_Len loop
2994 Set_Char (Name_Buffer (J));
2995 end loop;
2996 end Set_Name_Buffer;
2998 -------------------------
2999 -- Set_PSD_Pragma_Table --
3000 -------------------------
3002 procedure Set_PSD_Pragma_Table is
3003 begin
3004 for F in ALIs.First .. ALIs.Last loop
3005 for K in ALIs.Table (F).First_Specific_Dispatching ..
3006 ALIs.Table (F).Last_Specific_Dispatching
3007 loop
3008 declare
3009 DTK : Specific_Dispatching_Record
3010 renames Specific_Dispatching.Table (K);
3012 begin
3013 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
3014 PSD_Pragma_Settings.Append ('F');
3015 end loop;
3017 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
3018 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
3019 end loop;
3020 end;
3021 end loop;
3022 end loop;
3023 end Set_PSD_Pragma_Table;
3025 ----------------
3026 -- Set_String --
3027 ----------------
3029 procedure Set_String (S : String) is
3030 begin
3031 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
3032 Last := Last + S'Length;
3033 end Set_String;
3035 ------------------------
3036 -- Set_String_Replace --
3037 ------------------------
3039 procedure Set_String_Replace (S : String) is
3040 begin
3041 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
3042 end Set_String_Replace;
3044 -------------------
3045 -- Set_Unit_Name --
3046 -------------------
3048 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores) is
3049 begin
3050 for J in 1 .. Name_Len - 2 loop
3051 if Name_Buffer (J) = '.' then
3052 if Mode = Double_Underscores then
3053 Set_String ("__");
3054 elsif Mode = Dot then
3055 Set_Char ('.');
3056 else
3057 Set_Char ('$');
3058 end if;
3059 else
3060 Set_Char (Name_Buffer (J));
3061 end if;
3062 end loop;
3063 end Set_Unit_Name;
3065 ---------------------
3066 -- Set_Unit_Number --
3067 ---------------------
3069 procedure Set_Unit_Number (U : Unit_Id) is
3070 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
3071 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
3073 begin
3074 if Num_Units >= 10 and then Unum < 10 then
3075 Set_Char ('0');
3076 end if;
3078 if Num_Units >= 100 and then Unum < 100 then
3079 Set_Char ('0');
3080 end if;
3082 Set_Int (Unum);
3083 end Set_Unit_Number;
3085 ----------------------------
3086 -- Write_Statement_Buffer --
3087 ----------------------------
3089 procedure Write_Statement_Buffer is
3090 begin
3091 WBI (Statement_Buffer (1 .. Last));
3092 Last := 0;
3093 end Write_Statement_Buffer;
3095 procedure Write_Statement_Buffer (S : String) is
3096 begin
3097 Set_String (S);
3098 Write_Statement_Buffer;
3099 end Write_Statement_Buffer;
3101 end Bindgen;