1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Binde; use Binde;
28 with Casing; use Casing;
29 with Fname; use Fname;
30 with Gnatvsn; use Gnatvsn;
32 with Namet; use Namet;
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
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 Lib_Final_Built : Boolean := False;
76 ----------------------------------
77 -- Interface_State Pragma Table --
78 ----------------------------------
80 -- This table assembles the interface state pragma information from
81 -- all the units in the partition. Note that Bcheck has already checked
82 -- that the information is consistent across units. The entries
83 -- in this table are n/u/r/s for not set/user/runtime/system.
85 package IS_Pragma_Settings is new Table.Table (
86 Table_Component_Type => Character,
87 Table_Index_Type => Int,
90 Table_Increment => 200,
91 Table_Name => "IS_Pragma_Settings");
93 -- This table assembles the Priority_Specific_Dispatching pragma
94 -- information from all the units in the partition. Note that Bcheck has
95 -- already checked that the information is consistent across units.
96 -- The entries in this table are the upper case first character of the
97 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
99 package PSD_Pragma_Settings is new Table.Table (
100 Table_Component_Type => Character,
101 Table_Index_Type => Int,
102 Table_Low_Bound => 0,
103 Table_Initial => 100,
104 Table_Increment => 200,
105 Table_Name => "PSD_Pragma_Settings");
107 ----------------------
108 -- Run-Time Globals --
109 ----------------------
111 -- This section documents the global variables that set from the
112 -- generated binder file.
114 -- Main_Priority : Integer;
115 -- Time_Slice_Value : Integer;
116 -- Heap_Size : Natural;
117 -- WC_Encoding : Character;
118 -- Locking_Policy : Character;
119 -- Queuing_Policy : Character;
120 -- Task_Dispatching_Policy : Character;
121 -- Priority_Specific_Dispatching : System.Address;
122 -- Num_Specific_Dispatching : Integer;
123 -- Restrictions : System.Address;
124 -- Interrupt_States : System.Address;
125 -- Num_Interrupt_States : Integer;
126 -- Unreserve_All_Interrupts : Integer;
127 -- Exception_Tracebacks : Integer;
128 -- Zero_Cost_Exceptions : Integer;
129 -- Detect_Blocking : Integer;
130 -- Default_Stack_Size : Integer;
131 -- Leap_Seconds_Support : Integer;
132 -- Main_CPU : Integer;
134 -- Main_Priority is the priority value set by pragma Priority in the main
135 -- program. If no such pragma is present, the value is -1.
137 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
138 -- main program, or by the use of a -Tnnn parameter for the binder (if both
139 -- are present, the binder value overrides). The value is in milliseconds.
140 -- A value of zero indicates that time slicing should be suppressed. If no
141 -- pragma is present, and no -T switch was used, the value is -1.
143 -- Heap_Size is the heap to use for memory allocations set by use of a
144 -- -Hnn parameter for the binder or by the GNAT$NO_MALLOC_64 logical.
145 -- Valid values are 32 and 64. This switch is only effective on VMS.
147 -- WC_Encoding shows the wide character encoding method used for the main
148 -- program. This is one of the encoding letters defined in
149 -- System.WCh_Con.WC_Encoding_Letters.
151 -- Locking_Policy is a space if no locking policy was specified for the
152 -- partition. If a locking policy was specified, the value is the upper
153 -- case first character of the locking policy name, for example, 'C' for
156 -- Queuing_Policy is a space if no queuing policy was specified for the
157 -- partition. If a queuing policy was specified, the value is the upper
158 -- case first character of the queuing policy name for example, 'F' for
161 -- Task_Dispatching_Policy is a space if no task dispatching policy was
162 -- specified for the partition. If a task dispatching policy was specified,
163 -- the value is the upper case first character of the policy name, e.g. 'F'
164 -- for FIFO_Within_Priorities.
166 -- Priority_Specific_Dispatching is the address of a string used to store
167 -- the task dispatching policy specified for the different priorities in
168 -- the partition. The length of this string is determined by the last
169 -- priority for which such a pragma applies (the string will be a null
170 -- string if no specific dispatching policies were used). If pragma were
171 -- present, the entries apply to the priorities in sequence from the first
172 -- priority. The value stored is the upper case first character of the
173 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
174 -- for those priority ranges not specified.
176 -- Num_Specific_Dispatching is the length of the
177 -- Priority_Specific_Dispatching string. It will be set to zero if no
178 -- Priority_Specific_Dispatching pragmas are present.
180 -- Restrictions is the address of a null-terminated string specifying the
181 -- restrictions information for the partition. The format is identical to
182 -- that of the parameter string found on R lines in ali files (see Lib.Writ
183 -- spec in lib-writ.ads for full details). The difference is that in this
184 -- context the values are the cumulative ones for the entire partition.
186 -- Interrupt_States is the address of a string used to specify the
187 -- cumulative results of Interrupt_State pragmas used in the partition.
188 -- The length of this string is determined by the last interrupt for which
189 -- such a pragma is given (the string will be a null string if no pragmas
190 -- were used). If pragma were present the entries apply to the interrupts
191 -- in sequence from the first interrupt, and are set to one of four
192 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
193 -- time, 's' for system, see description of Interrupt_State pragma for
196 -- Num_Interrupt_States is the length of the Interrupt_States string. It
197 -- will be set to zero if no Interrupt_State pragmas are present.
199 -- Unreserve_All_Interrupts is set to one if at least one unit in the
200 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
202 -- Exception_Tracebacks is set to one if the -E parameter was present
203 -- in the bind and to zero otherwise. Note that on some targets exception
204 -- tracebacks are provided by default, so a value of zero for this
205 -- parameter does not necessarily mean no trace backs are available.
207 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
208 -- this partition, and to zero if longjmp/setjmp exceptions are used.
210 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
211 -- not. A value of zero indicates that the pragma is not present, while a
212 -- value of 1 signals its presence in the partition.
214 -- Default_Stack_Size is the default stack size used when creating an Ada
215 -- task with no explicit Storage_Size clause.
217 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
218 -- disabled. A value of zero indicates that leap seconds are turned "off",
219 -- while a value of one signifies "on" status.
221 -- Main_CPU is the processor set by pragma CPU in the main program. If no
222 -- such pragma is present, the value is -1.
224 -----------------------
225 -- Local Subprograms --
226 -----------------------
228 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
229 -- Convenient shorthand used throughout
231 procedure Check_System_Restrictions_Used;
232 -- Sets flag System_Restrictions_Used (Set to True if and only if the unit
233 -- System.Restrictions is present in the partition, otherwise False).
235 procedure Gen_Adainit_Ada;
236 -- Generates the Adainit procedure (Ada code case)
238 procedure Gen_Adainit_C;
239 -- Generates the Adainit procedure (C code case)
241 procedure Gen_Adafinal_Ada;
242 -- Generate the Adafinal procedure (Ada code case)
244 procedure Gen_Adafinal_C;
245 -- Generate the Adafinal procedure (C code case)
247 procedure Gen_Elab_Calls_Ada;
248 -- Generate sequence of elaboration calls (Ada code case)
250 procedure Gen_Elab_Calls_C;
251 -- Generate sequence of elaboration calls (C code case)
253 procedure Gen_Elab_Order_Ada;
254 -- Generate comments showing elaboration order chosen (Ada code case)
256 procedure Gen_Elab_Order_C;
257 -- Generate comments showing elaboration order chosen (C code case)
259 procedure Gen_Elab_Defs_C;
260 -- Generate sequence of definitions for elaboration routines (C code case)
262 procedure Gen_Finalize_Library_Ada;
263 -- Generate a sequence of finalization calls to elaborated packages (Ada)
265 procedure Gen_Finalize_Library_C;
266 -- Generate a sequence of finalization calls to elaborated packages (C)
268 procedure Gen_Finalize_Library_Defs_C;
269 -- Generate a sequence of defininitions for package finalizers (C case)
271 procedure Gen_Main_Ada;
272 -- Generate procedure main (Ada code case)
274 procedure Gen_Main_C;
275 -- Generate main() procedure (C code case)
277 procedure Gen_Object_Files_Options;
278 -- Output comments containing a list of the full names of the object
279 -- files to be linked and the list of linker options supplied by
280 -- Linker_Options pragmas in the source. (C and Ada code case)
282 procedure Gen_Output_File_Ada (Filename : String);
283 -- Generate output file (Ada code case)
285 procedure Gen_Output_File_C (Filename : String);
286 -- Generate output file (C code case)
288 procedure Gen_Restrictions_Ada;
289 -- Generate initialization of restrictions variable (Ada code case)
291 procedure Gen_Restrictions_C;
292 -- Generate initialization of restrictions variable (C code case)
294 procedure Gen_Versions_Ada;
295 -- Output series of definitions for unit versions (Ada code case)
297 procedure Gen_Versions_C;
298 -- Output series of definitions for unit versions (C code case)
300 function Get_Ada_Main_Name return String;
301 -- This function is used in the Ada main output case to compute a usable
302 -- name for the generated main program. The normal main program name is
303 -- Ada_Main, but this won't work if the user has a unit with this name.
304 -- This function tries Ada_Main first, and if there is such a clash, then
305 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
307 function Get_Main_Unit_Name (S : String) return String;
308 -- Return the main unit name corresponding to S by replacing '.' with '_'
310 function Get_Main_Name return String;
311 -- This function is used in the Ada main output case to compute the
312 -- correct external main program. It is "main" by default, unless the
313 -- flag Use_Ada_Main_Program_Name_On_Target is set, in which case it
314 -- is the name of the Ada main name without the "_ada". This default
315 -- can be overridden explicitly using the -Mname binder switch.
317 function Get_WC_Encoding return Character;
318 -- Return wide character encoding method to set as WC_Encoding in output.
319 -- If -W has been used, returns the specified encoding, otherwise returns
320 -- the encoding method used for the main program source. If there is no
321 -- main program source (-z switch used), returns brackets ('b').
323 function Has_Finalizer return Boolean;
324 -- Determine whether the current unit has at least one library-level
327 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
328 -- Compare linker options, when sorting, first according to
329 -- Is_Internal_File (internal files come later) and then by
330 -- elaboration order position (latest to earliest).
332 procedure Move_Linker_Option (From : Natural; To : Natural);
333 -- Move routine for sorting linker options
335 procedure Resolve_Binder_Options;
336 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
337 -- since it tests for a package named "dec" which might cause a conflict
338 -- on non-VMS systems.
340 procedure Set_Char (C : Character);
341 -- Set given character in Statement_Buffer at the Last + 1 position
342 -- and increment Last by one to reflect the stored character.
344 procedure Set_Int (N : Int);
345 -- Set given value in decimal in Statement_Buffer with no spaces
346 -- starting at the Last + 1 position, and updating Last past the value.
347 -- A minus sign is output for a negative value.
349 procedure Set_Boolean (B : Boolean);
350 -- Set given boolean value in Statement_Buffer at the Last + 1 position
351 -- and update Last past the value.
353 procedure Set_IS_Pragma_Table;
354 -- Initializes contents of IS_Pragma_Settings table from ALI table
356 procedure Set_Main_Program_Name;
357 -- Given the main program name in Name_Buffer (length in Name_Len)
358 -- generate the name of the routine to be used in the call. The name
359 -- is generated starting at Last + 1, and Last is updated past it.
361 procedure Set_Name_Buffer;
362 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
364 procedure Set_PSD_Pragma_Table;
365 -- Initializes contents of PSD_Pragma_Settings table from ALI table
367 procedure Set_String (S : String);
368 -- Sets characters of given string in Statement_Buffer, starting at the
369 -- Last + 1 position, and updating last past the string value.
371 procedure Set_String_Replace (S : String);
372 -- Replaces the last S'Length characters in the Statement_Buffer with
373 -- the characters of S. The caller must ensure that these characters do
374 -- in fact exist in the Statement_Buffer.
376 type Qualification_Mode is (Dollar_Sign, Dot, Double_Underscores);
378 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores);
379 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
380 -- starting at the Last + 1 position and update Last past the value.
381 -- Depending on parameter Mode, a dot (.) can be qualified into double
382 -- underscores (__), a dollar sign ($) or left as is.
384 procedure Set_Unit_Number (U : Unit_Id);
385 -- Sets unit number (first unit is 1, leading zeroes output to line
386 -- up all output unit numbers nicely as required by the value, and
387 -- by the total number of units.
389 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String);
390 -- For C code case, write C & Common, for Ada case write Ada & Common
391 -- to current binder output file using Write_Binder_Info.
393 procedure Write_Statement_Buffer;
394 -- Write out contents of statement buffer up to Last, and reset Last to 0
396 procedure Write_Statement_Buffer (S : String);
397 -- First writes its argument (using Set_String (S)), then writes out the
398 -- contents of statement buffer up to Last, and reset Last to 0
400 ------------------------------------
401 -- Check_System_Restrictions_Used --
402 ------------------------------------
404 procedure Check_System_Restrictions_Used is
406 for J in Units.First .. Units.Last loop
407 if Get_Name_String (Units.Table (J).Sfile) = "s-restri.ads" then
408 System_Restrictions_Used := True;
413 System_Restrictions_Used := False;
414 end Check_System_Restrictions_Used;
416 ----------------------
417 -- Gen_Adafinal_Ada --
418 ----------------------
420 procedure Gen_Adafinal_Ada is
422 WBI (" procedure " & Ada_Final_Name.all & " is");
424 -- Do nothing if finalization is disabled
426 if Cumulative_Restrictions.Set (No_Finalization) then
432 elsif VM_Target = No_VM then
433 WBI (" procedure s_stalib_adafinal;");
434 WBI (" pragma Import (C, s_stalib_adafinal, " &
435 """system__standard_library__adafinal"");");
437 WBI (" s_stalib_adafinal;");
439 -- Pragma Import C cannot be used on virtual machine targets, therefore
440 -- call the runtime finalization routine directly.
444 WBI (" System.Standard_Library.Adafinal;");
447 WBI (" end " & Ada_Final_Name.all & ";");
449 end Gen_Adafinal_Ada;
455 procedure Gen_Adafinal_C is
457 WBI ("void " & Ada_Final_Name.all & " (void) {");
458 WBI (" system__standard_library__adafinal ();");
463 ---------------------
464 -- Gen_Adainit_Ada --
465 ---------------------
467 procedure Gen_Adainit_Ada is
468 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
469 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
472 WBI (" procedure " & Ada_Init_Name.all & " is");
474 -- Generate externals for elaboration entities
476 for E in Elab_Order.First .. Elab_Order.Last loop
478 Unum : constant Unit_Id := Elab_Order.Table (E);
479 U : Unit_Record renames Units.Table (Unum);
482 -- Check for Elab_Entity to be set for this unit
486 -- Don't generate reference for stand alone library
488 and then not U.SAL_Interface
490 -- Don't generate reference for predefined file in No_Run_Time
491 -- mode, since we don't include the object files in this case
495 and then Is_Predefined_File_Name (U.Sfile))
499 Set_Unit_Number (Unum);
502 when No_VM | JVM_Target =>
503 Set_String (" : Boolean; pragma Import (Ada, ");
505 Set_String (" : Boolean; pragma Import (CIL, ");
509 Set_Unit_Number (Unum);
511 Get_Name_String (U.Uname);
513 -- In the case of JGNAT we need to emit an Import name that
514 -- includes the class name (using '$' separators in the case
515 -- of a child unit name).
517 if VM_Target /= No_VM then
518 for J in 1 .. Name_Len - 2 loop
519 if VM_Target = CLI_Target
520 or else Name_Buffer (J) /= '.'
522 Set_Char (Name_Buffer (J));
528 if VM_Target /= CLI_Target or else U.Unit_Kind = 's' then
531 Set_String ("_pkg.");
534 -- If the unit name is very long, then split the
535 -- Import link name across lines using "&" (occurs
536 -- in some C2 tests).
538 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
540 Write_Statement_Buffer;
546 Set_String ("_E"");");
547 Write_Statement_Buffer;
552 Write_Statement_Buffer;
554 -- If the standard library is suppressed, then the only global variables
555 -- that might be needed (by the Ravenscar profile) are the priority and
556 -- the processor for the environment task.
558 if Suppress_Standard_Library_On_Target then
559 if Main_Priority /= No_Main_Priority then
560 WBI (" Main_Priority : Integer;");
561 WBI (" pragma Import (C, Main_Priority," &
562 " ""__gl_main_priority"");");
566 if Main_CPU /= No_Main_CPU then
567 WBI (" Main_CPU : Integer;");
568 WBI (" pragma Import (C, Main_CPU," &
569 " ""__gl_main_cpu"");");
575 if Main_Priority /= No_Main_Priority then
576 Set_String (" Main_Priority := ");
577 Set_Int (Main_Priority);
579 Write_Statement_Buffer;
582 if Main_CPU /= No_Main_CPU then
583 Set_String (" Main_CPU := ");
586 Write_Statement_Buffer;
589 if Main_Priority = No_Main_Priority
590 and then Main_CPU = No_Main_CPU
595 -- Normal case (standard library not suppressed). Set all global values
596 -- used by the run time.
599 WBI (" Main_Priority : Integer;");
600 WBI (" pragma Import (C, Main_Priority, " &
601 """__gl_main_priority"");");
602 WBI (" Time_Slice_Value : Integer;");
603 WBI (" pragma Import (C, Time_Slice_Value, " &
604 """__gl_time_slice_val"");");
605 WBI (" WC_Encoding : Character;");
606 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
607 WBI (" Locking_Policy : Character;");
608 WBI (" pragma Import (C, Locking_Policy, " &
609 """__gl_locking_policy"");");
610 WBI (" Queuing_Policy : Character;");
611 WBI (" pragma Import (C, Queuing_Policy, " &
612 """__gl_queuing_policy"");");
613 WBI (" Task_Dispatching_Policy : Character;");
614 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
615 """__gl_task_dispatching_policy"");");
616 WBI (" Priority_Specific_Dispatching : System.Address;");
617 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
618 """__gl_priority_specific_dispatching"");");
619 WBI (" Num_Specific_Dispatching : Integer;");
620 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
621 """__gl_num_specific_dispatching"");");
622 WBI (" Main_CPU : Integer;");
623 WBI (" pragma Import (C, Main_CPU, " &
624 """__gl_main_cpu"");");
626 WBI (" Interrupt_States : System.Address;");
627 WBI (" pragma Import (C, Interrupt_States, " &
628 """__gl_interrupt_states"");");
629 WBI (" Num_Interrupt_States : Integer;");
630 WBI (" pragma Import (C, Num_Interrupt_States, " &
631 """__gl_num_interrupt_states"");");
632 WBI (" Unreserve_All_Interrupts : Integer;");
633 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
634 """__gl_unreserve_all_interrupts"");");
636 if Exception_Tracebacks then
637 WBI (" Exception_Tracebacks : Integer;");
638 WBI (" pragma Import (C, Exception_Tracebacks, " &
639 """__gl_exception_tracebacks"");");
642 WBI (" Zero_Cost_Exceptions : Integer;");
643 WBI (" pragma Import (C, Zero_Cost_Exceptions, " &
644 """__gl_zero_cost_exceptions"");");
645 WBI (" Detect_Blocking : Integer;");
646 WBI (" pragma Import (C, Detect_Blocking, " &
647 """__gl_detect_blocking"");");
648 WBI (" Default_Stack_Size : Integer;");
649 WBI (" pragma Import (C, Default_Stack_Size, " &
650 """__gl_default_stack_size"");");
651 WBI (" Leap_Seconds_Support : Integer;");
652 WBI (" pragma Import (C, Leap_Seconds_Support, " &
653 """__gl_leap_seconds_support"");");
655 -- Import entry point for elaboration time signal handler
656 -- installation, and indication of if it's been called previously.
659 WBI (" procedure Install_Handler;");
660 WBI (" pragma Import (C, Install_Handler, " &
661 """__gnat_install_handler"");");
663 WBI (" Handler_Installed : Integer;");
664 WBI (" pragma Import (C, Handler_Installed, " &
665 """__gnat_handler_installed"");");
667 -- The import of the soft link which performs library-level object
668 -- finalization is not needed for VM targets. Regular Ada is used in
671 if VM_Target = No_VM then
673 WBI (" type No_Param_Proc is access procedure;");
674 WBI (" Finalize_Library_Objects : No_Param_Proc;");
675 WBI (" pragma Import (C, Finalize_Library_Objects, " &
676 """__gnat_finalize_library_objects"");");
679 -- Import entry point for environment feature enable/disable
680 -- routine, and indication that it's been called previously.
682 if OpenVMS_On_Target then
684 WBI (" procedure Set_Features;");
685 WBI (" pragma Import (C, Set_Features, " &
686 """__gnat_set_features"");");
688 WBI (" Features_Set : Integer;");
689 WBI (" pragma Import (C, Features_Set, " &
690 """__gnat_features_set"");");
692 if Opt.Heap_Size /= 0 then
694 WBI (" Heap_Size : Integer;");
695 WBI (" pragma Import (C, Heap_Size, " &
696 """__gl_heap_size"");");
698 Write_Statement_Buffer;
702 -- Initialize stack limit variable of the environment task if the
703 -- stack check method is stack limit and stack check is enabled.
705 if Stack_Check_Limits_On_Target
706 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
709 WBI (" procedure Initialize_Stack_Limit;");
710 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
711 """__gnat_initialize_stack_limit"");");
714 -- Special processing when main program is CIL function/procedure
716 if VM_Target = CLI_Target
717 and then Bind_Main_Program
718 and then not No_Main_Subprogram
722 -- Function case, use Set_Exit_Status to report the returned
723 -- status code, since that is the only mechanism available.
725 if ALIs.Table (ALIs.First).Main_Program = Func then
726 WBI (" Result : Integer;");
727 WBI (" procedure Set_Exit_Status (Code : Integer);");
728 WBI (" pragma Import (C, Set_Exit_Status, " &
729 """__gnat_set_exit_status"");");
731 WBI (" function Ada_Main_Program return Integer;");
736 WBI (" procedure Ada_Main_Program;");
739 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
740 Name_Len := Name_Len - 2;
741 WBI (" pragma Import (CIL, Ada_Main_Program, """
742 & Name_Buffer (1 .. Name_Len) & "."
743 & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len)) & """);");
748 Set_String (" Main_Priority := ");
749 Set_Int (Main_Priority);
751 Write_Statement_Buffer;
753 Set_String (" Time_Slice_Value := ");
755 if Task_Dispatching_Policy_Specified = 'F'
756 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
760 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
764 Write_Statement_Buffer;
766 Set_String (" WC_Encoding := '");
767 Set_Char (Get_WC_Encoding);
770 Write_Statement_Buffer;
772 Set_String (" Locking_Policy := '");
773 Set_Char (Locking_Policy_Specified);
775 Write_Statement_Buffer;
777 Set_String (" Queuing_Policy := '");
778 Set_Char (Queuing_Policy_Specified);
780 Write_Statement_Buffer;
782 Set_String (" Task_Dispatching_Policy := '");
783 Set_Char (Task_Dispatching_Policy_Specified);
785 Write_Statement_Buffer;
787 Gen_Restrictions_Ada;
789 WBI (" Priority_Specific_Dispatching :=");
790 WBI (" Local_Priority_Specific_Dispatching'Address;");
792 Set_String (" Num_Specific_Dispatching := ");
793 Set_Int (PSD_Pragma_Settings.Last + 1);
795 Write_Statement_Buffer;
797 Set_String (" Main_CPU := ");
800 Write_Statement_Buffer;
802 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
804 Set_String (" Num_Interrupt_States := ");
805 Set_Int (IS_Pragma_Settings.Last + 1);
807 Write_Statement_Buffer;
809 Set_String (" Unreserve_All_Interrupts := ");
811 if Unreserve_All_Interrupts_Specified then
818 Write_Statement_Buffer;
820 if Exception_Tracebacks then
821 WBI (" Exception_Tracebacks := 1;");
824 Set_String (" Zero_Cost_Exceptions := ");
826 if Zero_Cost_Exceptions_Specified then
833 Write_Statement_Buffer;
835 Set_String (" Detect_Blocking := ");
837 if Detect_Blocking then
844 Write_Statement_Buffer;
846 Set_String (" Default_Stack_Size := ");
847 Set_Int (Default_Stack_Size);
849 Write_Statement_Buffer;
851 Set_String (" Leap_Seconds_Support := ");
853 if Leap_Seconds_Support then
860 Write_Statement_Buffer;
862 -- Generate call to Install_Handler
864 -- In .NET, when binding with -z, we don't install the signal handler
865 -- to let the caller handle the last exception handler.
867 if VM_Target /= CLI_Target
868 or else Bind_Main_Program
871 WBI (" if Handler_Installed = 0 then");
872 WBI (" Install_Handler;");
876 -- Generate call to Set_Features
878 if OpenVMS_On_Target then
880 WBI (" if Features_Set = 0 then");
881 WBI (" Set_Features;");
884 -- Features_Set may twiddle the heap size according to a logical
885 -- name, but the binder switch must override.
887 if Opt.Heap_Size /= 0 then
888 Set_String (" Heap_Size := ");
889 Set_Int (Opt.Heap_Size);
891 Write_Statement_Buffer;
896 -- Generate call to set Initialize_Scalar values if active
898 if Initialize_Scalars_Used then
900 Set_String (" System.Scalar_Values.Initialize ('");
901 Set_Char (Initialize_Scalars_Mode1);
903 Set_Char (Initialize_Scalars_Mode2);
905 Write_Statement_Buffer;
908 -- Generate assignment of default secondary stack size if set
910 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
912 Set_String (" System.Secondary_Stack.");
913 Set_String ("Default_Secondary_Stack_Size := ");
914 Set_Int (Opt.Default_Sec_Stack_Size);
916 Write_Statement_Buffer;
919 -- Initialize stack limit variable of the environment task if the
920 -- stack check method is stack limit and stack check is enabled.
922 if Stack_Check_Limits_On_Target
923 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
926 WBI (" Initialize_Stack_Limit;");
929 -- Attach Finalize_Library to the right softlink
931 if not Suppress_Standard_Library_On_Target then
934 if VM_Target = No_VM then
935 if Lib_Final_Built then
936 Set_String (" Finalize_Library_Objects := ");
937 Set_String ("Finalize_Library'access;");
939 Set_String (" Finalize_Library_Objects := null;");
942 -- On VM targets use regular Ada to set the soft link
945 if Lib_Final_Built then
946 Set_String (" System.Soft_Links.Finalize_Library_Objects");
947 Set_String (" := Finalize_Library'access;");
949 Set_String (" System.Soft_Links.Finalize_Library_Objects");
950 Set_String (" := null;");
954 Write_Statement_Buffer;
957 -- Generate elaboration calls
962 -- Case of main program is CIL function or procedure
964 if VM_Target = CLI_Target
965 and then Bind_Main_Program
966 and then not No_Main_Subprogram
968 -- For function case, use Set_Exit_Status to set result
970 if ALIs.Table (ALIs.First).Main_Program = Func then
971 WBI (" Result := Ada_Main_Program;");
972 WBI (" Set_Exit_Status (Result);");
977 WBI (" Ada_Main_Program;");
981 WBI (" end " & Ada_Init_Name.all & ";");
989 procedure Gen_Adainit_C is
990 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
991 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
994 WBI ("void " & Ada_Init_Name.all & " (void)");
997 -- Generate externals for elaboration entities
999 for E in Elab_Order.First .. Elab_Order.Last loop
1001 Unum : constant Unit_Id := Elab_Order.Table (E);
1002 U : Unit_Record renames Units.Table (Unum);
1005 -- Check for Elab entity to be set for this unit
1007 if U.Set_Elab_Entity
1009 -- Don't generate reference for stand alone library
1011 and then not U.SAL_Interface
1013 -- Don't generate reference for predefined file in No_Run_Time
1014 -- mode, since we don't include the object files in this case
1018 and then Is_Predefined_File_Name (U.Sfile))
1020 Set_String (" extern char ");
1021 Get_Name_String (U.Uname);
1024 Write_Statement_Buffer;
1029 Write_Statement_Buffer;
1031 -- Standard library suppressed
1033 if Suppress_Standard_Library_On_Target then
1035 -- Case of High_Integrity_Mode mode. Set __gl_main_priority and
1036 -- __gl_main_cpu if needed for the Ravenscar profile.
1038 if Main_Priority /= No_Main_Priority then
1039 WBI (" extern int __gl_main_priority;");
1040 Set_String (" __gl_main_priority = ");
1041 Set_Int (Main_Priority);
1043 Write_Statement_Buffer;
1046 if Main_CPU /= No_Main_CPU then
1047 WBI (" extern int __gl_main_cpu;");
1048 Set_String (" __gl_main_cpu = ");
1051 Write_Statement_Buffer;
1054 -- Normal case (standard library not suppressed)
1057 -- Generate definition for interrupt states string
1059 Set_String (" static const char *local_interrupt_states = """);
1061 for J in 0 .. IS_Pragma_Settings.Last loop
1062 Set_Char (IS_Pragma_Settings.Table (J));
1066 Write_Statement_Buffer;
1068 -- Generate definition for priority specific dispatching string
1071 (" static const char *local_priority_specific_dispatching = """);
1073 for J in 0 .. PSD_Pragma_Settings.Last loop
1074 Set_Char (PSD_Pragma_Settings.Table (J));
1078 Write_Statement_Buffer;
1080 -- Generate declaration for secondary stack default if needed
1082 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1083 WBI (" extern int system__secondary_stack__" &
1084 "default_secondary_stack_size;");
1089 -- Code for normal case (standard library not suppressed)
1091 -- We call the routine from inside adainit() because this works for
1092 -- both programs with and without binder generated "main" functions.
1094 WBI (" extern int __gl_main_priority;");
1095 Set_String (" __gl_main_priority = ");
1096 Set_Int (Main_Priority);
1098 Write_Statement_Buffer;
1100 WBI (" extern int __gl_time_slice_val;");
1101 Set_String (" __gl_time_slice_val = ");
1103 if Task_Dispatching_Policy = 'F'
1104 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
1108 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
1112 Write_Statement_Buffer;
1114 WBI (" extern char __gl_wc_encoding;");
1115 Set_String (" __gl_wc_encoding = '");
1116 Set_Char (Get_WC_Encoding);
1119 Write_Statement_Buffer;
1121 WBI (" extern char __gl_locking_policy;");
1122 Set_String (" __gl_locking_policy = '");
1123 Set_Char (Locking_Policy_Specified);
1125 Write_Statement_Buffer;
1127 WBI (" extern char __gl_queuing_policy;");
1128 Set_String (" __gl_queuing_policy = '");
1129 Set_Char (Queuing_Policy_Specified);
1131 Write_Statement_Buffer;
1133 WBI (" extern char __gl_task_dispatching_policy;");
1134 Set_String (" __gl_task_dispatching_policy = '");
1135 Set_Char (Task_Dispatching_Policy_Specified);
1137 Write_Statement_Buffer;
1139 WBI (" extern int __gl_main_cpu;");
1140 Set_String (" __gl_main_cpu = ");
1143 Write_Statement_Buffer;
1147 WBI (" extern const void *__gl_interrupt_states;");
1148 WBI (" __gl_interrupt_states = local_interrupt_states;");
1150 WBI (" extern int __gl_num_interrupt_states;");
1151 Set_String (" __gl_num_interrupt_states = ");
1152 Set_Int (IS_Pragma_Settings.Last + 1);
1154 Write_Statement_Buffer;
1156 WBI (" extern const void *__gl_priority_specific_dispatching;");
1157 WBI (" __gl_priority_specific_dispatching =" &
1158 " local_priority_specific_dispatching;");
1160 WBI (" extern int __gl_num_specific_dispatching;");
1161 Set_String (" __gl_num_specific_dispatching = ");
1162 Set_Int (PSD_Pragma_Settings.Last + 1);
1164 Write_Statement_Buffer;
1166 WBI (" extern int __gl_unreserve_all_interrupts;");
1167 Set_String (" __gl_unreserve_all_interrupts = ");
1168 Set_Int (Boolean'Pos (Unreserve_All_Interrupts_Specified));
1170 Write_Statement_Buffer;
1172 if Exception_Tracebacks then
1173 WBI (" extern int __gl_exception_tracebacks;");
1174 WBI (" __gl_exception_tracebacks = 1;");
1177 WBI (" extern int __gl_zero_cost_exceptions;");
1178 Set_String (" __gl_zero_cost_exceptions = ");
1179 Set_Int (Boolean'Pos (Zero_Cost_Exceptions_Specified));
1181 Write_Statement_Buffer;
1183 WBI (" extern int __gl_detect_blocking;");
1184 Set_String (" __gl_detect_blocking = ");
1186 if Detect_Blocking then
1193 Write_Statement_Buffer;
1195 WBI (" extern int __gl_default_stack_size;");
1196 Set_String (" __gl_default_stack_size = ");
1197 Set_Int (Default_Stack_Size);
1199 Write_Statement_Buffer;
1201 WBI (" extern int __gl_leap_seconds_support;");
1202 Set_String (" __gl_leap_seconds_support = ");
1204 if Leap_Seconds_Support then
1211 Write_Statement_Buffer;
1215 -- Install elaboration time signal handler
1217 WBI (" if (__gnat_handler_installed == 0)");
1219 WBI (" __gnat_install_handler ();");
1222 -- Call feature enable/disable routine
1224 if OpenVMS_On_Target then
1225 WBI (" if (__gnat_features_set == 0)");
1227 WBI (" __gnat_set_features ();");
1232 -- Initialize stack limit for the environment task if the stack
1233 -- check method is stack limit and stack check is enabled.
1235 if Stack_Check_Limits_On_Target
1236 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
1239 WBI (" __gnat_initialize_stack_limit ();");
1242 -- Generate call to set Initialize_Scalar values if needed
1244 if Initialize_Scalars_Used then
1246 Set_String (" system__scalar_values__initialize('");
1247 Set_Char (Initialize_Scalars_Mode1);
1248 Set_String ("', '");
1249 Set_Char (Initialize_Scalars_Mode2);
1251 Write_Statement_Buffer;
1254 -- Generate assignment of default secondary stack size if set
1256 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1258 Set_String (" system__secondary_stack__");
1259 Set_String ("default_secondary_stack_size = ");
1260 Set_Int (Opt.Default_Sec_Stack_Size);
1262 Write_Statement_Buffer;
1265 -- Generate elaboration calls
1273 ------------------------
1274 -- Gen_Elab_Calls_Ada --
1275 ------------------------
1277 procedure Gen_Elab_Calls_Ada is
1279 for E in Elab_Order.First .. Elab_Order.Last loop
1281 Unum : constant Unit_Id := Elab_Order.Table (E);
1282 U : Unit_Record renames Units.Table (Unum);
1284 Unum_Spec : Unit_Id;
1285 -- This is the unit number of the spec that corresponds to
1286 -- this entry. It is the same as Unum except when the body
1287 -- and spec are different and we are currently processing
1288 -- the body, in which case it is the spec (Unum + 1).
1291 if U.Utype = Is_Body then
1292 Unum_Spec := Unum + 1;
1297 -- Nothing to do if predefined unit in no run time mode
1299 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1302 -- Case of no elaboration code
1304 elsif U.No_Elab then
1306 -- The only case in which we have to do something is if
1307 -- this is a body, with a separate spec, where the separate
1308 -- spec has an elaboration entity defined.
1310 -- In that case, this is where we set the elaboration entity
1311 -- to True, we do not need to test if this has already been
1312 -- done, since it is quicker to set the flag than to test it.
1314 if not U.SAL_Interface and then U.Utype = Is_Body
1315 and then Units.Table (Unum_Spec).Set_Elab_Entity
1318 Set_Unit_Number (Unum_Spec);
1319 Set_String (" := True;");
1320 Write_Statement_Buffer;
1323 -- Here if elaboration code is present. If binding a library
1324 -- or if there is a non-Ada main subprogram then we generate:
1326 -- if not uname_E then
1327 -- uname'elab_[spec|body];
1331 -- Otherwise, elaboration routines are called unconditionally:
1333 -- uname'elab_[spec|body];
1336 -- The uname_E assignment is skipped if this is a separate spec,
1337 -- since the assignment will be done when we process the body.
1339 elsif not U.SAL_Interface then
1340 if Force_Checking_Of_Elaboration_Flags or
1341 Interface_Library_Unit or
1342 (not Bind_Main_Program)
1344 Set_String (" if not E");
1345 Set_Unit_Number (Unum_Spec);
1346 Set_String (" then");
1347 Write_Statement_Buffer;
1352 Get_Decoded_Name_String_With_Brackets (U.Uname);
1354 if VM_Target = CLI_Target and then U.Unit_Kind /= 's' then
1355 if Name_Buffer (Name_Len) = 's' then
1356 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1359 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1363 Name_Len := Name_Len + 12;
1366 if Name_Buffer (Name_Len) = 's' then
1367 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1370 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1374 Name_Len := Name_Len + 8;
1377 Set_Casing (U.Icasing);
1380 Write_Statement_Buffer;
1382 if U.Utype /= Is_Spec then
1383 if Force_Checking_Of_Elaboration_Flags or
1384 Interface_Library_Unit or
1385 (not Bind_Main_Program)
1391 Set_Unit_Number (Unum_Spec);
1392 Set_String (" := True;");
1393 Write_Statement_Buffer;
1396 if Force_Checking_Of_Elaboration_Flags or
1397 Interface_Library_Unit or
1398 (not Bind_Main_Program)
1405 end Gen_Elab_Calls_Ada;
1407 ----------------------
1408 -- Gen_Elab_Calls_C --
1409 ----------------------
1411 procedure Gen_Elab_Calls_C is
1413 for E in Elab_Order.First .. Elab_Order.Last loop
1415 Unum : constant Unit_Id := Elab_Order.Table (E);
1416 U : Unit_Record renames Units.Table (Unum);
1418 Unum_Spec : Unit_Id;
1419 -- This is the unit number of the spec that corresponds to
1420 -- this entry. It is the same as Unum except when the body
1421 -- and spec are different and we are currently processing
1422 -- the body, in which case it is the spec (Unum + 1).
1425 if U.Utype = Is_Body then
1426 Unum_Spec := Unum + 1;
1431 -- Nothing to do if predefined unit in no run time mode
1433 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1436 -- Case of no elaboration code
1438 elsif U.No_Elab then
1440 -- The only case in which we have to do something is if
1441 -- this is a body, with a separate spec, where the separate
1442 -- spec has an elaboration entity defined.
1444 -- In that case, this is where we set the elaboration entity
1445 -- to True, we do not need to test if this has already been
1446 -- done, since it is quicker to set the flag than to test it.
1448 if not U.SAL_Interface and then U.Utype = Is_Body
1449 and then Units.Table (Unum_Spec).Set_Elab_Entity
1452 Get_Name_String (U.Uname);
1454 Set_String ("_E = 1;");
1455 Write_Statement_Buffer;
1458 -- Here if elaboration code is present. If binding a library
1459 -- or if there is a non-Ada main subprogram then we generate:
1461 -- if (uname_E == 0) {
1462 -- uname__elab[s|b] ();
1466 -- The uname_E assignment is skipped if this is a separate spec,
1467 -- since the assignment will be done when we process the body.
1469 elsif not U.SAL_Interface then
1470 Get_Name_String (U.Uname);
1472 if Force_Checking_Of_Elaboration_Flags or
1473 Interface_Library_Unit or
1474 (not Bind_Main_Program)
1476 Set_String (" if (");
1478 Set_String ("_E == 0) {");
1479 Write_Statement_Buffer;
1485 Set_String ("___elab");
1486 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1487 Set_String (" ();");
1488 Write_Statement_Buffer;
1490 if U.Utype /= Is_Spec then
1491 if Force_Checking_Of_Elaboration_Flags or
1492 Interface_Library_Unit or
1493 (not Bind_Main_Program)
1500 Set_String ("_E++;");
1501 Write_Statement_Buffer;
1504 if Force_Checking_Of_Elaboration_Flags or
1505 Interface_Library_Unit or
1506 (not Bind_Main_Program)
1513 end Gen_Elab_Calls_C;
1515 ----------------------
1516 -- Gen_Elab_Defs_C --
1517 ----------------------
1519 procedure Gen_Elab_Defs_C is
1521 WBI ("/* BEGIN ELABORATION DEFINITIONS */");
1523 for E in Elab_Order.First .. Elab_Order.Last loop
1525 -- Generate declaration of elaboration procedure if elaboration
1526 -- needed. Note that passive units are always excluded.
1528 if not Units.Table (Elab_Order.Table (E)).No_Elab then
1529 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1530 Set_String ("extern void ");
1532 Set_String ("___elab");
1533 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1534 Set_String (" (void);");
1535 Write_Statement_Buffer;
1539 end Gen_Elab_Defs_C;
1541 ------------------------
1542 -- Gen_Elab_Order_Ada --
1543 ------------------------
1545 procedure Gen_Elab_Order_Ada is
1547 WBI (" -- BEGIN ELABORATION ORDER");
1549 for J in Elab_Order.First .. Elab_Order.Last loop
1550 Set_String (" -- ");
1551 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1553 Write_Statement_Buffer;
1556 WBI (" -- END ELABORATION ORDER");
1558 end Gen_Elab_Order_Ada;
1560 ----------------------
1561 -- Gen_Elab_Order_C --
1562 ----------------------
1564 procedure Gen_Elab_Order_C is
1566 WBI ("/* BEGIN ELABORATION ORDER");
1568 for J in Elab_Order.First .. Elab_Order.Last loop
1569 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1571 Write_Statement_Buffer;
1574 WBI (" END ELABORATION ORDER */");
1576 end Gen_Elab_Order_C;
1578 ------------------------------
1579 -- Gen_Finalize_Library_Ada --
1580 ------------------------------
1582 procedure Gen_Finalize_Library_Ada is
1585 Uspec : Unit_Record;
1589 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1590 Unum := Elab_Order.Table (E);
1591 U := Units.Table (Unum);
1593 -- We are only interested in non-generic packages
1595 if U.Unit_Kind = 'p'
1596 and then U.Has_Finalizer
1597 and then not U.Is_Generic
1598 and then not U.No_Elab
1600 if not Lib_Final_Built then
1601 Lib_Final_Built := True;
1603 WBI (" procedure Finalize_Library is");
1605 -- The following flag is used to check for library-level
1606 -- exceptions raised during finalization. The symbol comes
1607 -- from System.Soft_Links. VM targets use regular Ada to
1608 -- reference the entity.
1610 if VM_Target = No_VM then
1611 WBI (" LE_Set : Boolean;");
1613 Set_String (" pragma Import (Ada, LE_Set, ");
1614 Set_String ("""__gnat_library_exception_set"");");
1615 Write_Statement_Buffer;
1623 -- procedure F<Count>;
1625 Set_String (" declare");
1626 Write_Statement_Buffer;
1628 Set_String (" procedure F");
1631 Write_Statement_Buffer;
1634 -- pragma Import (CIL, F<Count>, "xx.yy_pkg.Finalize[B/S]");
1635 -- -- for .NET targets
1637 -- pragma Import (Java, F<Count>, "xx$yy.Finalize[B/S]");
1638 -- -- for JVM targets
1640 -- pragma Import (Ada, F<Count>, "xx__yy__Finalize[B/S]");
1641 -- -- for default targets
1643 if VM_Target = CLI_Target then
1644 Set_String (" pragma Import (CIL, F");
1645 elsif VM_Target = JVM_Target then
1646 Set_String (" pragma Import (Java, F");
1648 Set_String (" pragma Import (Ada, F");
1652 Set_String (", """);
1654 -- Dealing with package bodies is a little complicated. In such
1655 -- cases we must retrieve the package spec since it contains the
1656 -- spec of the body finalizer.
1658 if U.Utype = Is_Body then
1660 Uspec := Units.Table (Unum);
1665 Get_Name_String (Uspec.Uname);
1667 -- Perform name construction
1669 -- .NET xx.yy_pkg.finalize
1671 if VM_Target = CLI_Target then
1672 Set_Unit_Name (Mode => Dot);
1673 Set_String ("_pkg.finalize");
1675 -- JVM xx$yy.finalize
1677 elsif VM_Target = JVM_Target then
1678 Set_Unit_Name (Mode => Dollar_Sign);
1679 Set_String (".finalize");
1681 -- Default xx__yy__finalize
1685 Set_String ("__finalize");
1688 -- Package spec processing
1690 if U.Utype = Is_Spec
1691 or else U.Utype = Is_Spec_Only
1695 -- Package body processing
1701 Set_String (""");");
1702 Write_Statement_Buffer;
1713 Write_Statement_Buffer;
1720 if Lib_Final_Built then
1722 -- It is possible that the finalization of a library-level object
1723 -- raised an exception. In that case import the actual exception
1724 -- and the routine necessary to raise it.
1726 if VM_Target = No_VM then
1727 WBI (" if LE_Set then");
1729 WBI (" LE : Ada.Exceptions.Exception_Occurrence;");
1731 Set_String (" pragma Import (Ada, LE, ");
1732 Set_String ("""__gnat_library_exception"");");
1733 Write_Statement_Buffer;
1735 Set_String (" procedure Raise_Controlled ");
1736 Set_String ("(E : Ada.Exceptions.Exception_Occurrence);");
1737 Write_Statement_Buffer;
1739 Set_String (" pragma Import (Ada, Raise_Controlled, ");
1740 Set_String ("""__gnat_raise_from_controlled_operation"");");
1741 Write_Statement_Buffer;
1744 WBI (" Raise_Controlled (LE);");
1747 -- VM-specific code, use regular Ada to produce the desired behavior
1750 WBI (" if System.Soft_Links.Library_Exception_Set then");
1752 Set_String (" Ada.Exceptions.Reraise_Occurrence (");
1753 Set_String ("System.Soft_Links.Library_Exception);");
1754 Write_Statement_Buffer;
1758 WBI (" end Finalize_Library;");
1761 end Gen_Finalize_Library_Ada;
1763 ----------------------------
1764 -- Gen_Finalize_Library_C --
1765 ----------------------------
1767 procedure Gen_Finalize_Library_C is
1769 Uspec : Unit_Record;
1773 WBI (" /* BEGIN FINALIZE */");
1775 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1776 Unum := Elab_Order.Table (E);
1777 U := Units.Table (Unum);
1779 -- We are only interested in non-generic packages
1781 if U.Unit_Kind = 'p'
1782 and then U.Has_Finalizer
1783 and then not U.Is_Generic
1784 and then not U.No_Elab
1788 -- Dealing with package bodies is a little complicated. In such
1789 -- cases we must retrieve the package spec since it contains the
1790 -- spec of the body finalizer.
1792 if U.Utype = Is_Body then
1794 Uspec := Units.Table (Unum);
1799 Get_Name_String (Uspec.Uname);
1801 Set_String ("__finalize");
1803 -- Package spec processing
1805 if U.Utype = Is_Spec
1806 or else U.Utype = Is_Spec_Only
1810 -- Package body processing
1816 Set_String (" ();");
1818 Write_Statement_Buffer;
1822 WBI (" /* END FINALIZE */");
1824 end Gen_Finalize_Library_C;
1826 ---------------------------------
1827 -- Gen_Finalize_Library_Defs_C --
1828 ---------------------------------
1830 procedure Gen_Finalize_Library_Defs_C is
1832 Uspec : Unit_Record;
1836 WBI ("/* BEGIN FINALIZE DEFINITIONS */");
1838 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1839 Unum := Elab_Order.Table (E);
1840 U := Units.Table (Unum);
1842 -- We are only interested in non-generic packages
1844 if U.Unit_Kind = 'p'
1845 and then U.Has_Finalizer
1846 and then not U.Is_Generic
1847 and then not U.No_Elab
1849 -- Dealing with package bodies is a little complicated. In such
1850 -- cases we must retrieve the package spec since it contains the
1851 -- spec of the body finalizer.
1853 if U.Utype = Is_Body then
1855 Uspec := Units.Table (Unum);
1860 Set_String ("extern void ");
1861 Get_Name_String (Uspec.Uname);
1863 Set_String ("__finalize");
1865 if U.Utype = Is_Spec
1866 or else U.Utype = Is_Spec_Only
1873 Set_String (" (void);");
1874 Write_Statement_Buffer;
1878 WBI ("/* END FINALIZE DEFINITIONS */");
1880 end Gen_Finalize_Library_Defs_C;
1886 procedure Gen_Main_Ada is
1888 if Exit_Status_Supported_On_Target then
1889 Set_String (" function ");
1891 Set_String (" procedure ");
1894 Set_String (Get_Main_Name);
1896 if Command_Line_Args_On_Target then
1897 Write_Statement_Buffer;
1898 WBI (" (argc : Integer;");
1899 WBI (" argv : System.Address;");
1900 WBI (" envp : System.Address)");
1902 if Exit_Status_Supported_On_Target then
1903 WBI (" return Integer");
1909 if Exit_Status_Supported_On_Target then
1910 Set_String (" return Integer is");
1915 Write_Statement_Buffer;
1918 if Opt.Default_Exit_Status /= 0
1919 and then Bind_Main_Program
1920 and then not Configurable_Run_Time_Mode
1922 WBI (" procedure Set_Exit_Status (Status : Integer);");
1923 WBI (" pragma Import (C, Set_Exit_Status, " &
1924 """__gnat_set_exit_status"");");
1928 -- Initialize and Finalize
1930 if not Cumulative_Restrictions.Set (No_Finalization) then
1931 WBI (" procedure Initialize (Addr : System.Address);");
1932 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1934 WBI (" procedure Finalize;");
1935 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1938 -- If we want to analyze the stack, we have to import corresponding
1941 if Dynamic_Stack_Measurement then
1943 WBI (" procedure Output_Results;");
1944 WBI (" pragma Import (C, Output_Results, " &
1945 """__gnat_stack_usage_output_results"");");
1949 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1950 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1951 """__gnat_stack_usage_initialize"");");
1954 -- Deal with declarations for main program case
1956 if not No_Main_Subprogram then
1958 -- To call the main program, we declare it using a pragma Import
1959 -- Ada with the right link name.
1961 -- It might seem more obvious to "with" the main program, and call
1962 -- it in the normal Ada manner. We do not do this for three reasons:
1964 -- 1. It is more efficient not to recompile the main program
1965 -- 2. We are not entitled to assume the source is accessible
1966 -- 3. We don't know what options to use to compile it
1968 -- It is really reason 3 that is most critical (indeed we used
1969 -- to generate the "with", but several regression tests failed).
1973 if ALIs.Table (ALIs.First).Main_Program = Func then
1974 WBI (" Result : Integer;");
1976 WBI (" function Ada_Main_Program return Integer;");
1979 WBI (" procedure Ada_Main_Program;");
1982 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1983 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1984 Set_Main_Program_Name;
1985 Set_String (""");");
1987 Write_Statement_Buffer;
1990 if Bind_Main_Program
1991 and then not Suppress_Standard_Library_On_Target
1993 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1998 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1999 -- not referenced elsewhere in the generated program, but is needed
2000 -- by the debugger (that's why it is generated in the first place).
2001 -- The reference stops Ada_Main_Program_Name from being optimized
2002 -- away by smart linkers, such as the AiX linker.
2004 -- Because this variable is unused, we make this variable "aliased"
2005 -- with a pragma Volatile in order to tell the compiler to preserve
2006 -- this variable at any level of optimization.
2008 if Bind_Main_Program then
2010 (" Ensure_Reference : aliased System.Address := " &
2011 "Ada_Main_Program_Name'Address;");
2012 WBI (" pragma Volatile (Ensure_Reference);");
2018 -- Acquire command line arguments if present on target
2020 if Command_Line_Args_On_Target then
2021 WBI (" gnat_argc := argc;");
2022 WBI (" gnat_argv := argv;");
2023 WBI (" gnat_envp := envp;");
2026 -- If configurable run time and no command line args, then nothing
2027 -- needs to be done since the gnat_argc/argv/envp variables are
2028 -- suppressed in this case.
2030 elsif Configurable_Run_Time_On_Target then
2033 -- Otherwise set dummy values (to be filled in by some other unit?)
2036 WBI (" gnat_argc := 0;");
2037 WBI (" gnat_argv := System.Null_Address;");
2038 WBI (" gnat_envp := System.Null_Address;");
2041 if Opt.Default_Exit_Status /= 0
2042 and then Bind_Main_Program
2043 and then not Configurable_Run_Time_Mode
2045 Set_String (" Set_Exit_Status (");
2046 Set_Int (Opt.Default_Exit_Status);
2048 Write_Statement_Buffer;
2051 if Dynamic_Stack_Measurement then
2052 Set_String (" Initialize_Stack_Analysis (");
2053 Set_Int (Dynamic_Stack_Measurement_Array_Size);
2055 Write_Statement_Buffer;
2058 if not Cumulative_Restrictions.Set (No_Finalization) then
2059 if not No_Main_Subprogram
2060 and then Bind_Main_Program
2061 and then not Suppress_Standard_Library_On_Target
2063 WBI (" Initialize (SEH'Address);");
2065 WBI (" Initialize (System.Null_Address);");
2069 WBI (" " & Ada_Init_Name.all & ";");
2071 if not No_Main_Subprogram then
2072 WBI (" Break_Start;");
2074 if ALIs.Table (ALIs.First).Main_Program = Proc then
2075 WBI (" Ada_Main_Program;");
2077 WBI (" Result := Ada_Main_Program;");
2081 -- Adafinal call is skipped if no finalization
2083 if not Cumulative_Restrictions.Set (No_Finalization) then
2087 -- Prints the result of static stack analysis
2089 if Dynamic_Stack_Measurement then
2090 WBI (" Output_Results;");
2093 -- Finalize is only called if we have a run time
2095 if not Cumulative_Restrictions.Set (No_Finalization) then
2101 if Exit_Status_Supported_On_Target then
2102 if No_Main_Subprogram
2103 or else ALIs.Table (ALIs.First).Main_Program = Proc
2105 WBI (" return (gnat_exit_status);");
2107 WBI (" return (Result);");
2119 procedure Gen_Main_C is
2120 Needs_Library_Finalization : constant Boolean := Has_Finalizer;
2123 if Exit_Status_Supported_On_Target then
2124 WBI ("#include <stdlib.h>");
2125 Set_String ("int ");
2127 Set_String ("void ");
2130 Set_String (Get_Main_Name);
2132 -- Generate command line args in prototype if present on target
2134 if Command_Line_Args_On_Target then
2135 Write_Statement_Buffer (" (int argc, char **argv, char **envp)");
2137 -- Case of no command line arguments on target
2140 Write_Statement_Buffer (" (void)");
2145 -- Generate a reference to __gnat_ada_main_program_name. This symbol
2146 -- is not referenced elsewhere in the generated program, but is
2147 -- needed by the debugger (that's why it is generated in the first
2148 -- place). The reference stops Ada_Main_Program_Name from being
2149 -- optimized away by smart linkers, such as the AiX linker.
2151 -- Because this variable is unused, we declare this variable as
2152 -- volatile in order to tell the compiler to preserve it at any
2153 -- level of optimization.
2155 if Bind_Main_Program then
2156 WBI (" char * volatile ensure_reference " &
2157 "__attribute__ ((__unused__)) = " &
2158 "__gnat_ada_main_program_name;");
2161 if not Suppress_Standard_Library_On_Target
2162 and then not No_Main_Subprogram
2164 WBI (" int SEH [2];");
2169 -- If main program is a function, generate result variable
2171 if ALIs.Table (ALIs.First).Main_Program = Func then
2172 WBI (" int result;");
2175 -- Set command line argument values from parameters if command line
2176 -- arguments are present on target
2178 if Command_Line_Args_On_Target then
2179 WBI (" gnat_argc = argc;");
2180 WBI (" gnat_argv = argv;");
2181 WBI (" gnat_envp = envp;");
2184 -- If configurable run-time, then nothing to do, since in this case
2185 -- the gnat_argc/argv/envp variables are entirely suppressed.
2187 elsif Configurable_Run_Time_On_Target then
2190 -- if no command line arguments on target, set dummy values
2193 WBI (" gnat_argc = 0;");
2194 WBI (" gnat_argv = 0;");
2195 WBI (" gnat_envp = 0;");
2198 if Opt.Default_Exit_Status /= 0
2199 and then Bind_Main_Program
2200 and then not Configurable_Run_Time_Mode
2202 Set_String (" __gnat_set_exit_status (");
2203 Set_Int (Opt.Default_Exit_Status);
2205 Write_Statement_Buffer;
2208 -- Initializes dynamic stack measurement if needed
2210 if Dynamic_Stack_Measurement then
2211 Set_String (" __gnat_stack_usage_initialize (");
2212 Set_Int (Dynamic_Stack_Measurement_Array_Size);
2214 Write_Statement_Buffer;
2217 -- The __gnat_initialize routine is used only if we have a run-time
2219 if not Suppress_Standard_Library_On_Target then
2220 if not No_Main_Subprogram and then Bind_Main_Program then
2221 WBI (" __gnat_initialize ((void *)SEH);");
2223 WBI (" __gnat_initialize ((void *)0);");
2227 WBI (" " & Ada_Init_Name.all & " ();");
2229 if not No_Main_Subprogram then
2230 WBI (" __gnat_break_start ();");
2233 -- Output main program name
2235 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2237 -- Main program is procedure case
2239 if ALIs.Table (ALIs.First).Main_Program = Proc then
2241 Set_Main_Program_Name;
2242 Set_String (" ();");
2243 Write_Statement_Buffer;
2245 -- Main program is function case
2247 else -- ALIs.Table (ALIs_First).Main_Program = Func
2248 Set_String (" result = ");
2249 Set_Main_Program_Name;
2250 Set_String (" ();");
2251 Write_Statement_Buffer;
2256 -- Call adafinal if finalization active
2258 if not Cumulative_Restrictions.Set (No_Finalization)
2259 and then Needs_Library_Finalization
2261 Gen_Finalize_Library_C;
2264 -- Outputs the dynamic stack measurement if needed
2266 if Dynamic_Stack_Measurement then
2267 WBI (" __gnat_stack_usage_output_results ();");
2270 -- The finalize routine is used only if we have a run-time
2272 if not Suppress_Standard_Library_On_Target then
2273 WBI (" __gnat_finalize ();");
2276 -- Case of main program is a function, so the value it returns
2277 -- is the exit status in this case.
2279 if ALIs.Table (ALIs.First).Main_Program = Func then
2280 if Exit_Status_Supported_On_Target then
2282 -- VMS must use Posix exit routine in order to get the effect
2283 -- of a Unix compatible setting of the program exit status.
2284 -- For all other systems, we use the standard exit routine.
2286 if OpenVMS_On_Target then
2287 WBI (" decc$__posix_exit (result);");
2289 WBI (" exit (result);");
2293 -- Case of main program is a procedure, in which case the exit
2294 -- status is whatever was set by a Set_Exit call most recently
2297 if Exit_Status_Supported_On_Target then
2299 -- VMS must use Posix exit routine in order to get the effect
2300 -- of a Unix compatible setting of the program exit status.
2301 -- For all other systems, we use the standard exit routine.
2303 if OpenVMS_On_Target then
2304 WBI (" decc$__posix_exit (gnat_exit_status);");
2306 WBI (" exit (gnat_exit_status);");
2315 ------------------------------
2316 -- Gen_Object_Files_Options --
2317 ------------------------------
2319 procedure Gen_Object_Files_Options is
2321 -- This keeps track of the position in the sorted set of entries
2322 -- in the Linker_Options table of where the first entry from an
2323 -- internal file appears.
2325 Linker_Option_List_Started : Boolean := False;
2326 -- Set to True when "LINKER OPTION LIST" is displayed
2328 procedure Write_Linker_Option;
2329 -- Write binder info linker option
2331 -------------------------
2332 -- Write_Linker_Option --
2333 -------------------------
2335 procedure Write_Linker_Option is
2340 -- Loop through string, breaking at null's
2343 while Start < Name_Len loop
2345 -- Find null ending this section
2348 while Name_Buffer (Stop) /= ASCII.NUL
2349 and then Stop <= Name_Len loop
2353 -- Process section if non-null
2355 if Stop > Start then
2356 if Output_Linker_Option_List then
2357 if not Zero_Formatting then
2358 if not Linker_Option_List_Started then
2359 Linker_Option_List_Started := True;
2361 Write_Str (" LINKER OPTION LIST");
2369 Write_Str (Name_Buffer (Start .. Stop - 1));
2373 (" -- ", "", Name_Buffer (Start .. Stop - 1));
2378 end Write_Linker_Option;
2380 -- Start of processing for Gen_Object_Files_Options
2383 Write_Info_Ada_C ("-- ", "/* ", " BEGIN Object file/option list");
2385 if Object_List_Filename /= null then
2386 Set_List_File (Object_List_Filename.all);
2389 for E in Elab_Order.First .. Elab_Order.Last loop
2391 -- If not spec that has an associated body, then generate a comment
2392 -- giving the name of the corresponding object file.
2394 if (not Units.Table (Elab_Order.Table (E)).SAL_Interface)
2395 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
2399 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
2401 -- If the presence of an object file is necessary or if it exists,
2404 if not Hostparm.Exclude_Missing_Objects
2406 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
2408 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
2410 if Output_Object_List then
2411 Write_Str (Name_Buffer (1 .. Name_Len));
2415 -- Don't link with the shared library on VMS if an internal
2416 -- filename object is seen. Multiply defined symbols will
2419 if OpenVMS_On_Target
2420 and then Is_Internal_File_Name
2422 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
2424 -- Special case for g-trasym.obj (not included in libgnat)
2426 Get_Name_String (ALIs.Table
2427 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
2429 if Name_Buffer (1 .. 8) /= "g-trasym" then
2430 Opt.Shared_Libgnat := False;
2437 if Object_List_Filename /= null then
2441 -- Add a "-Ldir" for each directory in the object path
2442 if VM_Target /= CLI_Target then
2443 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
2445 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
2448 Add_Str_To_Name_Buffer ("-L");
2449 Add_Str_To_Name_Buffer (Dir.all);
2450 Write_Linker_Option;
2455 -- Sort linker options
2457 -- This sort accomplishes two important purposes:
2459 -- a) All application files are sorted to the front, and all GNAT
2460 -- internal files are sorted to the end. This results in a well
2461 -- defined dividing line between the two sets of files, for the
2462 -- purpose of inserting certain standard library references into
2463 -- the linker arguments list.
2465 -- b) Given two different units, we sort the linker options so that
2466 -- those from a unit earlier in the elaboration order comes later
2467 -- in the list. This is a heuristic designed to create a more
2468 -- friendly order of linker options when the operations appear in
2469 -- separate units. The idea is that if unit A must be elaborated
2470 -- before unit B, then it is more likely that B references
2471 -- libraries included by A, than vice versa, so we want libraries
2472 -- included by A to come after libraries included by B.
2474 -- These two criteria are implemented by function Lt_Linker_Option. Note
2475 -- that a special case of b) is that specs are elaborated before bodies,
2476 -- so linker options from specs come after linker options for bodies,
2477 -- and again, the assumption is that libraries used by the body are more
2478 -- likely to reference libraries used by the spec, than vice versa.
2481 (Linker_Options.Last,
2482 Move_Linker_Option'Access,
2483 Lt_Linker_Option'Access);
2485 -- Write user linker options, i.e. the set of linker options that come
2486 -- from all files other than GNAT internal files, Lgnat is left set to
2487 -- point to the first entry from a GNAT internal file, or past the end
2488 -- of the entries if there are no internal files.
2490 Lgnat := Linker_Options.Last + 1;
2492 for J in 1 .. Linker_Options.Last loop
2493 if not Linker_Options.Table (J).Internal_File then
2494 Get_Name_String (Linker_Options.Table (J).Name);
2495 Write_Linker_Option;
2502 -- Now we insert standard linker options that must appear after the
2503 -- entries from user files, and before the entries from GNAT run-time
2504 -- files. The reason for this decision is that libraries referenced
2505 -- by internal routines may reference these standard library entries.
2507 -- Note that we do not insert anything when pragma No_Run_Time has been
2508 -- specified or when the standard libraries are not to be used,
2509 -- otherwise on some platforms, such as VMS, we may get duplicate
2510 -- symbols when linking.
2512 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
2515 if Opt.Shared_Libgnat then
2516 Add_Str_To_Name_Buffer ("-shared");
2518 Add_Str_To_Name_Buffer ("-static");
2521 -- Write directly to avoid -K output (why???)
2523 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
2525 if With_DECGNAT then
2528 if Opt.Shared_Libgnat then
2529 Add_Str_To_Name_Buffer (Shared_Lib ("decgnat"));
2531 Add_Str_To_Name_Buffer ("-ldecgnat");
2534 Write_Linker_Option;
2540 if Opt.Shared_Libgnat then
2541 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
2543 Add_Str_To_Name_Buffer ("-lgnarl");
2546 Write_Linker_Option;
2551 if Opt.Shared_Libgnat then
2552 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
2554 Add_Str_To_Name_Buffer ("-lgnat");
2557 Write_Linker_Option;
2560 -- Write linker options from all internal files
2562 for J in Lgnat .. Linker_Options.Last loop
2563 Get_Name_String (Linker_Options.Table (J).Name);
2564 Write_Linker_Option;
2567 if Output_Linker_Option_List and then not Zero_Formatting then
2571 if Ada_Bind_File then
2572 WBI ("-- END Object file/option list ");
2574 WBI (" END Object file/option list */");
2576 end Gen_Object_Files_Options;
2578 ---------------------
2579 -- Gen_Output_File --
2580 ---------------------
2582 procedure Gen_Output_File (Filename : String) is
2584 -- Acquire settings for Interrupt_State pragmas
2586 Set_IS_Pragma_Table;
2588 -- Acquire settings for Priority_Specific_Dispatching pragma
2590 Set_PSD_Pragma_Table;
2592 -- Override Ada_Bind_File and Bind_Main_Program for VMs since JGNAT only
2593 -- supports Ada code, and the main program is already generated by the
2596 if VM_Target /= No_VM then
2597 Ada_Bind_File := True;
2599 if VM_Target = JVM_Target then
2600 Bind_Main_Program := False;
2604 -- Override time slice value if -T switch is set
2606 if Time_Slice_Set then
2607 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
2610 -- Count number of elaboration calls
2612 for E in Elab_Order.First .. Elab_Order.Last loop
2613 if Units.Table (Elab_Order.Table (E)).No_Elab then
2616 Num_Elab_Calls := Num_Elab_Calls + 1;
2620 -- Generate output file in appropriate language
2622 Check_System_Restrictions_Used;
2624 if Ada_Bind_File then
2625 Gen_Output_File_Ada (Filename);
2627 Gen_Output_File_C (Filename);
2629 end Gen_Output_File;
2631 -------------------------
2632 -- Gen_Output_File_Ada --
2633 -------------------------
2635 procedure Gen_Output_File_Ada (Filename : String) is
2637 Ada_Main : constant String := Get_Ada_Main_Name;
2638 -- Name to be used for generated Ada main program. See the body of
2639 -- function Get_Ada_Main_Name for details on the form of the name.
2641 Needs_Library_Finalization : constant Boolean := Has_Finalizer;
2644 -- Name of generated bind file (spec)
2647 -- Name of generated bind file (body)
2650 -- Create spec first
2652 Create_Binder_Output (Filename, 's', Bfiles);
2654 -- We always compile the binder file in Ada 95 mode so that we properly
2655 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2656 -- of the Ada 2005 constructs are needed by the binder file.
2658 WBI ("pragma Ada_95;");
2660 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2661 -- then we need to make sure that the binder program is compiled with
2662 -- the same restriction, so that no exception tables are generated.
2664 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2665 WBI ("pragma Restrictions (No_Exception_Handlers);");
2668 -- Same processing for Restrictions (No_Exception_Propagation)
2670 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
2671 WBI ("pragma Restrictions (No_Exception_Propagation);");
2674 -- Same processing for pragma No_Run_Time
2676 if No_Run_Time_Mode then
2677 WBI ("pragma No_Run_Time;");
2680 -- Generate with of System so we can reference System.Address
2682 WBI ("with System;");
2684 -- Generate with of System.Initialize_Scalars if active
2686 if Initialize_Scalars_Used then
2687 WBI ("with System.Scalar_Values;");
2690 -- Generate with of System.Secondary_Stack if active
2692 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2693 WBI ("with System.Secondary_Stack;");
2696 Resolve_Binder_Options;
2698 -- Usually, adafinal is called using a pragma Import C. Since Import C
2699 -- doesn't have the same semantics for JGNAT, we use standard Ada.
2701 if VM_Target /= No_VM
2702 and then not Suppress_Standard_Library_On_Target
2704 WBI ("with System.Soft_Links;");
2705 WBI ("with System.Standard_Library;");
2708 WBI ("package " & Ada_Main & " is");
2709 WBI (" pragma Warnings (Off);");
2711 -- Main program case
2713 if Bind_Main_Program then
2714 if VM_Target = No_VM then
2716 -- Generate argc/argv stuff unless suppressed
2718 if Command_Line_Args_On_Target
2719 or not Configurable_Run_Time_On_Target
2722 WBI (" gnat_argc : Integer;");
2723 WBI (" gnat_argv : System.Address;");
2724 WBI (" gnat_envp : System.Address;");
2726 -- If the standard library is not suppressed, these variables
2727 -- are in the run-time data area for easy run time access.
2729 if not Suppress_Standard_Library_On_Target then
2731 WBI (" pragma Import (C, gnat_argc);");
2732 WBI (" pragma Import (C, gnat_argv);");
2733 WBI (" pragma Import (C, gnat_envp);");
2737 -- Define exit status. Again in normal mode, this is in the
2738 -- run-time library, and is initialized there, but in the
2739 -- configurable runtime case, the variable is declared and
2740 -- initialized in this file.
2744 if Configurable_Run_Time_Mode then
2745 if Exit_Status_Supported_On_Target then
2746 WBI (" gnat_exit_status : Integer := 0;");
2750 WBI (" gnat_exit_status : Integer;");
2751 WBI (" pragma Import (C, gnat_exit_status);");
2755 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2756 -- the main program. Otherwise, it can lead under some circumstances
2757 -- to a symbol duplication during the link (for instance when a C
2758 -- program uses two Ada libraries). Also zero terminate the string
2759 -- so that its end can be found reliably at run time.
2762 WBI (" GNAT_Version : constant String :=");
2763 WBI (" """ & Ver_Prefix &
2764 Gnat_Version_String &
2766 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2769 Set_String (" Ada_Main_Program_Name : constant String := """);
2770 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2772 if VM_Target = No_VM then
2773 Set_Main_Program_Name;
2774 Set_String (""" & ASCII.NUL;");
2776 Set_String (Name_Buffer (1 .. Name_Len - 2) & """;");
2779 Write_Statement_Buffer;
2782 (" pragma Export (C, Ada_Main_Program_Name, " &
2783 """__gnat_ada_main_program_name"");");
2786 if not Cumulative_Restrictions.Set (No_Finalization) then
2788 WBI (" procedure " & Ada_Final_Name.all & ";");
2789 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2790 Ada_Final_Name.all & """);");
2794 WBI (" procedure " & Ada_Init_Name.all & ";");
2795 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2796 Ada_Init_Name.all & """);");
2798 -- If -a has been specified use pragma Linker_Constructor for the init
2799 -- procedure. No need to use a similar pragma for the final procedure as
2800 -- global finalization will occur when the executable finishes execution
2801 -- and for plugins (shared stand-alone libraries that can be
2802 -- "unloaded"), finalization should not occur automatically, otherwise
2803 -- the main executable may not continue to work properly.
2805 if Use_Pragma_Linker_Constructor then
2806 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2809 if Bind_Main_Program and then VM_Target = No_VM then
2811 -- If we have the standard library, then Break_Start is defined
2812 -- there, but when the standard library is suppressed, Break_Start
2816 WBI (" procedure Break_Start;");
2818 if Suppress_Standard_Library_On_Target then
2819 WBI (" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2821 WBI (" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2826 if Exit_Status_Supported_On_Target then
2827 Set_String (" function ");
2829 Set_String (" procedure ");
2832 Set_String (Get_Main_Name);
2834 -- Generate argument list if present
2836 if Command_Line_Args_On_Target then
2837 Write_Statement_Buffer;
2838 WBI (" (argc : Integer;");
2839 WBI (" argv : System.Address;");
2841 (" envp : System.Address)");
2843 if Exit_Status_Supported_On_Target then
2844 Write_Statement_Buffer;
2845 WBI (" return Integer;");
2847 Write_Statement_Buffer (";");
2851 if Exit_Status_Supported_On_Target then
2852 Write_Statement_Buffer (" return Integer;");
2854 Write_Statement_Buffer (";");
2858 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2859 Get_Main_Name & """);");
2868 WBI ("end " & Ada_Main & ";");
2869 Close_Binder_Output;
2871 -- Prepare to write body
2873 Create_Binder_Output (Filename, 'b', Bfileb);
2875 -- We always compile the binder file in Ada 95 mode so that we properly
2876 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2877 -- of the Ada 2005 constructs are needed by the binder file.
2879 WBI ("pragma Ada_95;");
2881 -- Output Source_File_Name pragmas which look like
2883 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2884 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2886 -- where sss/bbb are the spec/body file names respectively
2888 Get_Name_String (Bfiles);
2889 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2891 WBI ("pragma Source_File_Name (" &
2893 ", Spec_File_Name => """ &
2894 Name_Buffer (1 .. Name_Len + 3));
2896 Get_Name_String (Bfileb);
2897 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2899 WBI ("pragma Source_File_Name (" &
2901 ", Body_File_Name => """ &
2902 Name_Buffer (1 .. Name_Len + 3));
2904 -- Generate with of System.Restrictions to initialize
2905 -- Run_Time_Restrictions.
2907 if System_Restrictions_Used
2908 and not Suppress_Standard_Library_On_Target
2911 WBI ("with System.Restrictions;");
2914 if Needs_Library_Finalization then
2915 WBI ("with Ada.Exceptions;");
2919 WBI ("package body " & Ada_Main & " is");
2920 WBI (" pragma Warnings (Off);");
2922 if not Suppress_Standard_Library_On_Target then
2924 -- Generate Priority_Specific_Dispatching pragma string
2927 (" Local_Priority_Specific_Dispatching : constant String := """);
2929 for J in 0 .. PSD_Pragma_Settings.Last loop
2930 Set_Char (PSD_Pragma_Settings.Table (J));
2934 Write_Statement_Buffer;
2936 -- Generate Interrupt_State pragma string
2938 Set_String (" Local_Interrupt_States : constant String := """);
2940 for J in 0 .. IS_Pragma_Settings.Last loop
2941 Set_Char (IS_Pragma_Settings.Table (J));
2945 Write_Statement_Buffer;
2949 -- Generate the adafinal routine unless there is no finalization to do
2951 if not Cumulative_Restrictions.Set (No_Finalization) then
2954 if Needs_Library_Finalization then
2955 Gen_Finalize_Library_Ada;
2961 if Bind_Main_Program and then VM_Target = No_VM then
2963 -- When suppressing the standard library then generate dummy body
2966 if Suppress_Standard_Library_On_Target then
2968 WBI (" procedure Break_Start is");
2977 -- Output object file list and the Ada body is complete
2979 Gen_Object_Files_Options;
2982 WBI ("end " & Ada_Main & ";");
2984 Close_Binder_Output;
2985 end Gen_Output_File_Ada;
2987 -----------------------
2988 -- Gen_Output_File_C --
2989 -----------------------
2991 procedure Gen_Output_File_C (Filename : String) is
2993 Needs_Library_Finalization : constant Boolean := Has_Finalizer;
2996 pragma Warnings (Off, Bfile);
2997 -- Name of generated bind file (not referenced)
3000 Create_Binder_Output (Filename, 'c', Bfile);
3002 Resolve_Binder_Options;
3004 WBI ("extern void " & Ada_Final_Name.all & " (void);");
3006 -- If -a has been specified use __attribute__((constructor)) for the
3007 -- init procedure. No need to use a similar featute for the final
3008 -- procedure as global finalization will occur when the executable
3009 -- finishes execution and for plugins (shared stand-alone libraries that
3010 -- can be "unloaded"), finalization should not occur automatically,
3011 -- otherwise the main executable may not continue to work properly.
3013 if Use_Pragma_Linker_Constructor then
3014 WBI ("extern void " & Ada_Init_Name.all &
3015 " (void) __attribute__((constructor));");
3017 WBI ("extern void " & Ada_Init_Name.all & " (void);");
3020 WBI ("extern void system__standard_library__adafinal (void);");
3022 if not No_Main_Subprogram then
3023 Set_String ("extern ");
3025 if Exit_Status_Supported_On_Target then
3028 Set_String ("void");
3031 Set_String (" main ");
3033 if Command_Line_Args_On_Target then
3034 Write_Statement_Buffer ("(int, char **, char **);");
3036 Write_Statement_Buffer ("(void);");
3039 if OpenVMS_On_Target then
3040 WBI ("extern void decc$__posix_exit (int);");
3042 WBI ("extern void exit (int);");
3045 WBI ("extern void __gnat_break_start (void);");
3046 Set_String ("extern ");
3048 if ALIs.Table (ALIs.First).Main_Program = Proc then
3049 Set_String ("void ");
3051 Set_String ("int ");
3054 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3055 Set_Main_Program_Name;
3056 Set_String (" (void);");
3057 Write_Statement_Buffer;
3060 if not Suppress_Standard_Library_On_Target then
3061 WBI ("extern void __gnat_initialize (void *);");
3062 WBI ("extern void __gnat_finalize (void);");
3063 WBI ("extern void __gnat_install_handler (void);");
3066 if Dynamic_Stack_Measurement then
3068 WBI ("extern void __gnat_stack_usage_output_results (void);");
3069 WBI ("extern void __gnat_stack_usage_initialize (int size);");
3072 -- Initialize stack limit for the environment task if the stack check
3073 -- method is stack limit and stack check is enabled.
3075 if Stack_Check_Limits_On_Target
3076 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
3079 WBI ("extern void __gnat_initialize_stack_limit (void);");
3086 if Needs_Library_Finalization then
3087 Gen_Finalize_Library_Defs_C;
3090 -- Imported variables used only when we have a runtime
3092 if not Suppress_Standard_Library_On_Target then
3094 -- Track elaboration/finalization phase
3096 WBI ("extern int __gnat_handler_installed;");
3099 -- Track feature enable/disable on VMS
3101 if OpenVMS_On_Target then
3102 WBI ("extern int __gnat_features_set;");
3107 -- Write argv/argc exit status stuff if main program case
3109 if Bind_Main_Program then
3111 -- First deal with argc/argv/envp. In the normal case they are in the
3112 -- run-time library.
3114 if not Configurable_Run_Time_On_Target then
3115 WBI ("extern int gnat_argc;");
3116 WBI ("extern char **gnat_argv;");
3117 WBI ("extern char **gnat_envp;");
3119 -- If configurable run time and no command line args, then the
3120 -- generation of these variables is entirely suppressed.
3122 elsif not Command_Line_Args_On_Target then
3125 -- Otherwise, in the configurable run-time case they are right in the
3129 WBI ("int gnat_argc;");
3130 WBI ("char **gnat_argv;");
3131 WBI ("char **gnat_envp;");
3134 -- Similarly deal with exit status
3136 if not Configurable_Run_Time_On_Target then
3137 WBI ("extern int gnat_exit_status;");
3139 -- If configurable run time and no exit status on target, then the
3140 -- generation of this variables is entirely suppressed.
3142 elsif not Exit_Status_Supported_On_Target then
3145 -- Otherwise, in the configurable run-time case this variable is
3146 -- right in the binder file, and initialized to zero there.
3149 WBI ("int gnat_exit_status = 0;");
3155 -- When suppressing the standard library, the __gnat_break_start routine
3156 -- (for the debugger to get initial control) is defined in this file.
3158 if Suppress_Standard_Library_On_Target then
3160 WBI ("void __gnat_break_start (void) {}");
3163 -- Generate the __gnat_version and __gnat_ada_main_program_name info
3164 -- only for the main program. Otherwise, it can lead under some
3165 -- circumstances to a symbol duplication during the link (for instance
3166 -- when a C program uses 2 Ada libraries)
3168 if Bind_Main_Program then
3170 WBI ("char __gnat_version[] = """ & Ver_Prefix &
3171 Gnat_Version_String & """;");
3173 Set_String ("char __gnat_ada_main_program_name[] = """);
3174 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3175 Set_Main_Program_Name;
3177 Write_Statement_Buffer;
3180 -- Generate the adafinal routine. In no runtime mode, this is not
3181 -- needed, since there is no finalization to do.
3183 if not Cumulative_Restrictions.Set (No_Finalization) then
3189 -- Main is only present for Ada main case
3191 if Bind_Main_Program then
3195 -- Generate versions, elaboration order, list of object files
3199 Gen_Object_Files_Options;
3201 -- C binder output is complete
3203 Close_Binder_Output;
3204 end Gen_Output_File_C;
3206 --------------------------
3207 -- Gen_Restrictions_Ada --
3208 --------------------------
3210 procedure Gen_Restrictions_Ada is
3214 if Suppress_Standard_Library_On_Target
3215 or not System_Restrictions_Used
3220 WBI (" System.Restrictions.Run_Time_Restrictions :=");
3226 for J in Cumulative_Restrictions.Set'Range loop
3227 Set_Boolean (Cumulative_Restrictions.Set (J));
3231 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
3232 Write_Statement_Buffer;
3238 Set_String_Replace ("),");
3239 Write_Statement_Buffer;
3240 Set_String (" Value => (");
3242 for J in Cumulative_Restrictions.Value'Range loop
3243 Set_Int (Int (Cumulative_Restrictions.Value (J)));
3247 Set_String_Replace ("),");
3248 Write_Statement_Buffer;
3249 WBI (" Violated =>");
3253 for J in Cumulative_Restrictions.Violated'Range loop
3254 Set_Boolean (Cumulative_Restrictions.Violated (J));
3258 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
3259 Write_Statement_Buffer;
3265 Set_String_Replace ("),");
3266 Write_Statement_Buffer;
3267 Set_String (" Count => (");
3269 for J in Cumulative_Restrictions.Count'Range loop
3270 Set_Int (Int (Cumulative_Restrictions.Count (J)));
3274 Set_String_Replace ("),");
3275 Write_Statement_Buffer;
3276 Set_String (" Unknown => (");
3278 for J in Cumulative_Restrictions.Unknown'Range loop
3279 Set_Boolean (Cumulative_Restrictions.Unknown (J));
3283 Set_String_Replace ("))");
3285 Write_Statement_Buffer;
3286 end Gen_Restrictions_Ada;
3288 ------------------------
3289 -- Gen_Restrictions_C --
3290 ------------------------
3292 procedure Gen_Restrictions_C is
3294 if Suppress_Standard_Library_On_Target
3295 or not System_Restrictions_Used
3300 WBI (" typedef struct {");
3301 Set_String (" char set [");
3302 Set_Int (Cumulative_Restrictions.Set'Length);
3304 Write_Statement_Buffer;
3306 Set_String (" int value [");
3307 Set_Int (Cumulative_Restrictions.Value'Length);
3309 Write_Statement_Buffer;
3311 Set_String (" char violated [");
3312 Set_Int (Cumulative_Restrictions.Violated'Length);
3314 Write_Statement_Buffer;
3316 Set_String (" int count [");
3317 Set_Int (Cumulative_Restrictions.Count'Length);
3319 Write_Statement_Buffer;
3321 Set_String (" char unknown [");
3322 Set_Int (Cumulative_Restrictions.Unknown'Length);
3324 Write_Statement_Buffer;
3325 WBI (" } restrictions;");
3326 WBI (" extern restrictions " &
3327 "system__restrictions__run_time_restrictions;");
3328 WBI (" restrictions r = {");
3331 for J in Cumulative_Restrictions.Set'Range loop
3332 Set_Int (Boolean'Pos (Cumulative_Restrictions.Set (J)));
3336 Set_String_Replace ("},");
3337 Write_Statement_Buffer;
3340 for J in Cumulative_Restrictions.Value'Range loop
3341 Set_Int (Int (Cumulative_Restrictions.Value (J)));
3345 Set_String_Replace ("},");
3346 Write_Statement_Buffer;
3349 for J in Cumulative_Restrictions.Violated'Range loop
3350 Set_Int (Boolean'Pos (Cumulative_Restrictions.Violated (J)));
3354 Set_String_Replace ("},");
3355 Write_Statement_Buffer;
3358 for J in Cumulative_Restrictions.Count'Range loop
3359 Set_Int (Int (Cumulative_Restrictions.Count (J)));
3363 Set_String_Replace ("},");
3364 Write_Statement_Buffer;
3367 for J in Cumulative_Restrictions.Unknown'Range loop
3368 Set_Int (Boolean'Pos (Cumulative_Restrictions.Unknown (J)));
3372 Set_String_Replace ("}}");
3374 Write_Statement_Buffer;
3375 WBI (" system__restrictions__run_time_restrictions = r;");
3376 end Gen_Restrictions_C;
3378 ----------------------
3379 -- Gen_Versions_Ada --
3380 ----------------------
3382 -- This routine generates lines such as:
3384 -- unnnnn : constant Integer := 16#hhhhhhhh#;
3385 -- pragma Export (C, unnnnn, unam);
3387 -- for each unit, where unam is the unit name suffixed by either B or S for
3388 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
3389 -- the version number, and nnnnn is a 5-digits serial number.
3391 procedure Gen_Versions_Ada is
3392 Ubuf : String (1 .. 6) := "u00000";
3394 procedure Increment_Ubuf;
3395 -- Little procedure to increment the serial number
3397 --------------------
3398 -- Increment_Ubuf --
3399 --------------------
3401 procedure Increment_Ubuf is
3403 for J in reverse Ubuf'Range loop
3404 Ubuf (J) := Character'Succ (Ubuf (J));
3405 exit when Ubuf (J) <= '9';
3410 -- Start of processing for Gen_Versions_Ada
3415 WBI (" type Version_32 is mod 2 ** 32;");
3416 for U in Units.First .. Units.Last loop
3417 if not Units.Table (U).SAL_Interface and then
3418 ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
3421 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
3422 Units.Table (U).Version & "#;");
3423 Set_String (" pragma Export (C, ");
3425 Set_String (", """);
3427 Get_Name_String (Units.Table (U).Uname);
3429 for K in 1 .. Name_Len loop
3430 if Name_Buffer (K) = '.' then
3434 elsif Name_Buffer (K) = '%' then
3438 Set_Char (Name_Buffer (K));
3442 if Name_Buffer (Name_Len) = 's' then
3448 Set_String (""");");
3449 Write_Statement_Buffer;
3452 end Gen_Versions_Ada;
3454 --------------------
3455 -- Gen_Versions_C --
3456 --------------------
3458 -- This routine generates a line of the form:
3460 -- unsigned unam = 0xhhhhhhhh;
3462 -- for each unit, where unam is the unit name suffixed by either B or S for
3463 -- body or spec, with dots replaced by double underscores.
3465 procedure Gen_Versions_C is
3467 for U in Units.First .. Units.Last loop
3468 if not Units.Table (U).SAL_Interface and then
3469 ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
3471 Set_String ("unsigned ");
3473 Get_Name_String (Units.Table (U).Uname);
3475 for K in 1 .. Name_Len loop
3476 if Name_Buffer (K) = '.' then
3479 elsif Name_Buffer (K) = '%' then
3483 Set_Char (Name_Buffer (K));
3487 if Name_Buffer (Name_Len) = 's' then
3493 Set_String (" = 0x");
3494 Set_String (Units.Table (U).Version);
3496 Write_Statement_Buffer;
3501 ------------------------
3502 -- Get_Main_Unit_Name --
3503 ------------------------
3505 function Get_Main_Unit_Name (S : String) return String is
3506 Result : String := S;
3509 for J in S'Range loop
3510 if Result (J) = '.' then
3516 end Get_Main_Unit_Name;
3518 -----------------------
3519 -- Get_Ada_Main_Name --
3520 -----------------------
3522 function Get_Ada_Main_Name return String is
3523 Suffix : constant String := "_00";
3524 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
3525 Opt.Ada_Main_Name.all & Suffix;
3529 -- The main program generated by JGNAT expects a package called
3530 -- ada_<main procedure>.
3532 if VM_Target /= No_VM then
3533 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3534 return "ada_" & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
3537 -- This loop tries the following possibilities in order
3543 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
3544 -- it is set to 'ada_main'.
3546 for J in 0 .. 99 loop
3548 Nlen := Name'Length - Suffix'Length;
3550 Nlen := Name'Length;
3551 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
3552 Name (Name'Last - 1) :=
3553 Character'Val (J / 10 + Character'Pos ('0'));
3556 for K in ALIs.First .. ALIs.Last loop
3557 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
3559 -- Get unit name, removing %b or %e at end
3561 Get_Name_String (Units.Table (L).Uname);
3562 Name_Len := Name_Len - 2;
3564 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
3570 return Name (1 .. Nlen);
3576 -- If we fall through, just use a peculiar unlikely name
3578 return ("Qwertyuiop");
3579 end Get_Ada_Main_Name;
3585 function Get_Main_Name return String is
3587 -- Explicit name given with -M switch
3589 if Bind_Alternate_Main_Name then
3590 return Alternate_Main_Name.all;
3592 -- Case of main program name to be used directly
3594 elsif Use_Ada_Main_Program_Name_On_Target then
3596 -- Get main program name
3598 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3600 -- If this is a child name, return only the name of the child, since
3601 -- we can't have dots in a nested program name. Note that we do not
3602 -- include the %b at the end of the unit name.
3604 for J in reverse 1 .. Name_Len - 2 loop
3605 if J = 1 or else Name_Buffer (J - 1) = '.' then
3606 return Name_Buffer (J .. Name_Len - 2);
3610 raise Program_Error; -- impossible exit
3612 -- Case where "main" is to be used as default
3619 ---------------------
3620 -- Get_WC_Encoding --
3621 ---------------------
3623 function Get_WC_Encoding return Character is
3625 -- If encoding method specified by -W switch, then return it
3627 if Wide_Character_Encoding_Method_Specified then
3628 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
3630 -- If no main program, and not specified, set brackets, we really have
3631 -- no better choice. If some other encoding is required when there is
3632 -- no main, it must be set explicitly using -Wx.
3634 -- Note: if the ALI file always passed the wide character encoding of
3635 -- every file, then we could use the encoding of the initial specified
3636 -- file, but this information is passed only for potential main
3637 -- programs. We could fix this sometime, but it is a very minor point
3638 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
3639 -- is no main program).
3641 elsif No_Main_Subprogram then
3644 -- Otherwise if there is a main program, take encoding from it
3647 return ALIs.Table (ALIs.First).WC_Encoding;
3649 end Get_WC_Encoding;
3655 function Has_Finalizer return Boolean is
3660 for E in reverse Elab_Order.First .. Elab_Order.Last loop
3661 Unum := Elab_Order.Table (E);
3662 U := Units.Table (Unum);
3664 -- We are only interested in non-generic packages
3666 if U.Unit_Kind = 'p'
3667 and then U.Has_Finalizer
3668 and then not U.Is_Generic
3669 and then not U.No_Elab
3678 ----------------------
3679 -- Lt_Linker_Option --
3680 ----------------------
3682 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
3684 -- Sort internal files last
3686 if Linker_Options.Table (Op1).Internal_File
3688 Linker_Options.Table (Op2).Internal_File
3690 -- Note: following test uses False < True
3692 return Linker_Options.Table (Op1).Internal_File
3694 Linker_Options.Table (Op2).Internal_File;
3696 -- If both internal or both non-internal, sort according to the
3697 -- elaboration position. A unit that is elaborated later should come
3698 -- earlier in the linker options list.
3701 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
3703 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
3706 end Lt_Linker_Option;
3708 ------------------------
3709 -- Move_Linker_Option --
3710 ------------------------
3712 procedure Move_Linker_Option (From : Natural; To : Natural) is
3714 Linker_Options.Table (To) := Linker_Options.Table (From);
3715 end Move_Linker_Option;
3717 ----------------------------
3718 -- Resolve_Binder_Options --
3719 ----------------------------
3721 procedure Resolve_Binder_Options is
3723 for E in Elab_Order.First .. Elab_Order.Last loop
3724 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
3726 -- This is not a perfect approach, but is the current protocol
3727 -- between the run-time and the binder to indicate that tasking is
3728 -- used: system.os_interface should always be used by any tasking
3731 if Name_Buffer (1 .. 19) = "system.os_interface" then
3735 -- Ditto for declib and the "dec" package
3737 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
3738 With_DECGNAT := True;
3741 end Resolve_Binder_Options;
3747 procedure Set_Boolean (B : Boolean) is
3748 True_Str : constant String := "True";
3749 False_Str : constant String := "False";
3752 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
3753 Last := Last + True_Str'Length;
3755 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
3756 Last := Last + False_Str'Length;
3764 procedure Set_Char (C : Character) is
3767 Statement_Buffer (Last) := C;
3774 procedure Set_Int (N : Int) is
3786 Statement_Buffer (Last) :=
3787 Character'Val (N mod 10 + Character'Pos ('0'));
3791 -------------------------
3792 -- Set_IS_Pragma_Table --
3793 -------------------------
3795 procedure Set_IS_Pragma_Table is
3797 for F in ALIs.First .. ALIs.Last loop
3798 for K in ALIs.Table (F).First_Interrupt_State ..
3799 ALIs.Table (F).Last_Interrupt_State
3802 Inum : constant Int :=
3803 Interrupt_States.Table (K).Interrupt_Id;
3804 Stat : constant Character :=
3805 Interrupt_States.Table (K).Interrupt_State;
3808 while IS_Pragma_Settings.Last < Inum loop
3809 IS_Pragma_Settings.Append ('n');
3812 IS_Pragma_Settings.Table (Inum) := Stat;
3816 end Set_IS_Pragma_Table;
3818 ---------------------------
3819 -- Set_Main_Program_Name --
3820 ---------------------------
3822 procedure Set_Main_Program_Name is
3824 -- Note that name has %b on the end which we ignore
3826 -- First we output the initial _ada_ since we know that the main
3827 -- program is a library level subprogram.
3829 Set_String ("_ada_");
3831 -- Copy name, changing dots to double underscores
3833 for J in 1 .. Name_Len - 2 loop
3834 if Name_Buffer (J) = '.' then
3837 Set_Char (Name_Buffer (J));
3840 end Set_Main_Program_Name;
3842 ---------------------
3843 -- Set_Name_Buffer --
3844 ---------------------
3846 procedure Set_Name_Buffer is
3848 for J in 1 .. Name_Len loop
3849 Set_Char (Name_Buffer (J));
3851 end Set_Name_Buffer;
3853 -------------------------
3854 -- Set_PSD_Pragma_Table --
3855 -------------------------
3857 procedure Set_PSD_Pragma_Table is
3859 for F in ALIs.First .. ALIs.Last loop
3860 for K in ALIs.Table (F).First_Specific_Dispatching ..
3861 ALIs.Table (F).Last_Specific_Dispatching
3864 DTK : Specific_Dispatching_Record
3865 renames Specific_Dispatching.Table (K);
3868 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
3869 PSD_Pragma_Settings.Append ('F');
3872 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
3873 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
3878 end Set_PSD_Pragma_Table;
3884 procedure Set_String (S : String) is
3886 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
3887 Last := Last + S'Length;
3890 ------------------------
3891 -- Set_String_Replace --
3892 ------------------------
3894 procedure Set_String_Replace (S : String) is
3896 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
3897 end Set_String_Replace;
3903 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores) is
3905 for J in 1 .. Name_Len - 2 loop
3906 if Name_Buffer (J) = '.' then
3907 if Mode = Double_Underscores then
3909 elsif Mode = Dot then
3915 Set_Char (Name_Buffer (J));
3920 ---------------------
3921 -- Set_Unit_Number --
3922 ---------------------
3924 procedure Set_Unit_Number (U : Unit_Id) is
3925 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
3926 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
3929 if Num_Units >= 10 and then Unum < 10 then
3933 if Num_Units >= 100 and then Unum < 100 then
3938 end Set_Unit_Number;
3940 ----------------------
3941 -- Write_Info_Ada_C --
3942 ----------------------
3944 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String) is
3946 if Ada_Bind_File then
3948 S : String (1 .. Ada'Length + Common'Length);
3950 S (1 .. Ada'Length) := Ada;
3951 S (Ada'Length + 1 .. S'Length) := Common;
3957 S : String (1 .. C'Length + Common'Length);
3959 S (1 .. C'Length) := C;
3960 S (C'Length + 1 .. S'Length) := Common;
3964 end Write_Info_Ada_C;
3966 ----------------------------
3967 -- Write_Statement_Buffer --
3968 ----------------------------
3970 procedure Write_Statement_Buffer is
3972 WBI (Statement_Buffer (1 .. Last));
3974 end Write_Statement_Buffer;
3976 procedure Write_Statement_Buffer (S : String) is
3979 Write_Statement_Buffer;
3980 end Write_Statement_Buffer;