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
669 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
670 -- tasks are non-terminating, so we do not want finalization.
672 if VM_Target = No_VM and then not Configurable_Run_Time_On_Target then
674 WBI (" type No_Param_Proc is access procedure;");
675 WBI (" Finalize_Library_Objects : No_Param_Proc;");
676 WBI (" pragma Import (C, Finalize_Library_Objects, " &
677 """__gnat_finalize_library_objects"");");
680 -- Import entry point for environment feature enable/disable
681 -- routine, and indication that it's been called previously.
683 if OpenVMS_On_Target then
685 WBI (" procedure Set_Features;");
686 WBI (" pragma Import (C, Set_Features, " &
687 """__gnat_set_features"");");
689 WBI (" Features_Set : Integer;");
690 WBI (" pragma Import (C, Features_Set, " &
691 """__gnat_features_set"");");
693 if Opt.Heap_Size /= 0 then
695 WBI (" Heap_Size : Integer;");
696 WBI (" pragma Import (C, Heap_Size, " &
697 """__gl_heap_size"");");
699 Write_Statement_Buffer;
703 -- Initialize stack limit variable of the environment task if the
704 -- stack check method is stack limit and stack check is enabled.
706 if Stack_Check_Limits_On_Target
707 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
710 WBI (" procedure Initialize_Stack_Limit;");
711 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
712 """__gnat_initialize_stack_limit"");");
715 -- Special processing when main program is CIL function/procedure
717 if VM_Target = CLI_Target
718 and then Bind_Main_Program
719 and then not No_Main_Subprogram
723 -- Function case, use Set_Exit_Status to report the returned
724 -- status code, since that is the only mechanism available.
726 if ALIs.Table (ALIs.First).Main_Program = Func then
727 WBI (" Result : Integer;");
728 WBI (" procedure Set_Exit_Status (Code : Integer);");
729 WBI (" pragma Import (C, Set_Exit_Status, " &
730 """__gnat_set_exit_status"");");
732 WBI (" function Ada_Main_Program return Integer;");
737 WBI (" procedure Ada_Main_Program;");
740 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
741 Name_Len := Name_Len - 2;
742 WBI (" pragma Import (CIL, Ada_Main_Program, """
743 & Name_Buffer (1 .. Name_Len) & "."
744 & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len)) & """);");
749 Set_String (" Main_Priority := ");
750 Set_Int (Main_Priority);
752 Write_Statement_Buffer;
754 Set_String (" Time_Slice_Value := ");
756 if Task_Dispatching_Policy_Specified = 'F'
757 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
761 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
765 Write_Statement_Buffer;
767 Set_String (" WC_Encoding := '");
768 Set_Char (Get_WC_Encoding);
771 Write_Statement_Buffer;
773 Set_String (" Locking_Policy := '");
774 Set_Char (Locking_Policy_Specified);
776 Write_Statement_Buffer;
778 Set_String (" Queuing_Policy := '");
779 Set_Char (Queuing_Policy_Specified);
781 Write_Statement_Buffer;
783 Set_String (" Task_Dispatching_Policy := '");
784 Set_Char (Task_Dispatching_Policy_Specified);
786 Write_Statement_Buffer;
788 Gen_Restrictions_Ada;
790 WBI (" Priority_Specific_Dispatching :=");
791 WBI (" Local_Priority_Specific_Dispatching'Address;");
793 Set_String (" Num_Specific_Dispatching := ");
794 Set_Int (PSD_Pragma_Settings.Last + 1);
796 Write_Statement_Buffer;
798 Set_String (" Main_CPU := ");
801 Write_Statement_Buffer;
803 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
805 Set_String (" Num_Interrupt_States := ");
806 Set_Int (IS_Pragma_Settings.Last + 1);
808 Write_Statement_Buffer;
810 Set_String (" Unreserve_All_Interrupts := ");
812 if Unreserve_All_Interrupts_Specified then
819 Write_Statement_Buffer;
821 if Exception_Tracebacks then
822 WBI (" Exception_Tracebacks := 1;");
825 Set_String (" Zero_Cost_Exceptions := ");
827 if Zero_Cost_Exceptions_Specified then
834 Write_Statement_Buffer;
836 Set_String (" Detect_Blocking := ");
838 if Detect_Blocking then
845 Write_Statement_Buffer;
847 Set_String (" Default_Stack_Size := ");
848 Set_Int (Default_Stack_Size);
850 Write_Statement_Buffer;
852 Set_String (" Leap_Seconds_Support := ");
854 if Leap_Seconds_Support then
861 Write_Statement_Buffer;
863 -- Generate call to Install_Handler
865 -- In .NET, when binding with -z, we don't install the signal handler
866 -- to let the caller handle the last exception handler.
868 if VM_Target /= CLI_Target
869 or else Bind_Main_Program
872 WBI (" if Handler_Installed = 0 then");
873 WBI (" Install_Handler;");
877 -- Generate call to Set_Features
879 if OpenVMS_On_Target then
881 WBI (" if Features_Set = 0 then");
882 WBI (" Set_Features;");
885 -- Features_Set may twiddle the heap size according to a logical
886 -- name, but the binder switch must override.
888 if Opt.Heap_Size /= 0 then
889 Set_String (" Heap_Size := ");
890 Set_Int (Opt.Heap_Size);
892 Write_Statement_Buffer;
897 -- Generate call to set Initialize_Scalar values if active
899 if Initialize_Scalars_Used then
901 Set_String (" System.Scalar_Values.Initialize ('");
902 Set_Char (Initialize_Scalars_Mode1);
904 Set_Char (Initialize_Scalars_Mode2);
906 Write_Statement_Buffer;
909 -- Generate assignment of default secondary stack size if set
911 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
913 Set_String (" System.Secondary_Stack.");
914 Set_String ("Default_Secondary_Stack_Size := ");
915 Set_Int (Opt.Default_Sec_Stack_Size);
917 Write_Statement_Buffer;
920 -- Initialize stack limit variable of the environment task if the
921 -- stack check method is stack limit and stack check is enabled.
923 if Stack_Check_Limits_On_Target
924 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
927 WBI (" Initialize_Stack_Limit;");
930 -- Attach Finalize_Library to the right soft link. Do it only when not
931 -- using a restricted run time, in which case tasks are
932 -- non-terminating, so we do not want library-level finalization.
934 if not Configurable_Run_Time_On_Target then
935 if not Suppress_Standard_Library_On_Target then
938 if VM_Target = No_VM then
939 if Lib_Final_Built then
940 Set_String (" Finalize_Library_Objects := ");
941 Set_String ("Finalize_Library'access;");
943 Set_String (" Finalize_Library_Objects := null;");
946 -- On VM targets use regular Ada to set the soft link
949 if Lib_Final_Built then
951 (" System.Soft_Links.Finalize_Library_Objects");
952 Set_String (" := Finalize_Library'access;");
955 (" System.Soft_Links.Finalize_Library_Objects");
956 Set_String (" := null;");
960 Write_Statement_Buffer;
964 -- Generate elaboration calls
969 -- Case of main program is CIL function or procedure
971 if VM_Target = CLI_Target
972 and then Bind_Main_Program
973 and then not No_Main_Subprogram
975 -- For function case, use Set_Exit_Status to set result
977 if ALIs.Table (ALIs.First).Main_Program = Func then
978 WBI (" Result := Ada_Main_Program;");
979 WBI (" Set_Exit_Status (Result);");
984 WBI (" Ada_Main_Program;");
988 WBI (" end " & Ada_Init_Name.all & ";");
996 procedure Gen_Adainit_C is
997 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
998 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
1001 WBI ("void " & Ada_Init_Name.all & " (void)");
1004 -- Generate externals for elaboration entities
1006 for E in Elab_Order.First .. Elab_Order.Last loop
1008 Unum : constant Unit_Id := Elab_Order.Table (E);
1009 U : Unit_Record renames Units.Table (Unum);
1012 -- Check for Elab entity to be set for this unit
1014 if U.Set_Elab_Entity
1016 -- Don't generate reference for stand alone library
1018 and then not U.SAL_Interface
1020 -- Don't generate reference for predefined file in No_Run_Time
1021 -- mode, since we don't include the object files in this case
1025 and then Is_Predefined_File_Name (U.Sfile))
1027 Set_String (" extern char ");
1028 Get_Name_String (U.Uname);
1031 Write_Statement_Buffer;
1036 Write_Statement_Buffer;
1038 -- Standard library suppressed
1040 if Suppress_Standard_Library_On_Target then
1042 -- Case of High_Integrity_Mode mode. Set __gl_main_priority and
1043 -- __gl_main_cpu if needed for the Ravenscar profile.
1045 if Main_Priority /= No_Main_Priority then
1046 WBI (" extern int __gl_main_priority;");
1047 Set_String (" __gl_main_priority = ");
1048 Set_Int (Main_Priority);
1050 Write_Statement_Buffer;
1053 if Main_CPU /= No_Main_CPU then
1054 WBI (" extern int __gl_main_cpu;");
1055 Set_String (" __gl_main_cpu = ");
1058 Write_Statement_Buffer;
1061 -- Normal case (standard library not suppressed)
1064 -- Generate definition for interrupt states string
1066 Set_String (" static const char *local_interrupt_states = """);
1068 for J in 0 .. IS_Pragma_Settings.Last loop
1069 Set_Char (IS_Pragma_Settings.Table (J));
1073 Write_Statement_Buffer;
1075 -- Generate definition for priority specific dispatching string
1078 (" static const char *local_priority_specific_dispatching = """);
1080 for J in 0 .. PSD_Pragma_Settings.Last loop
1081 Set_Char (PSD_Pragma_Settings.Table (J));
1085 Write_Statement_Buffer;
1087 -- Generate declaration for secondary stack default if needed
1089 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1090 WBI (" extern int system__secondary_stack__" &
1091 "default_secondary_stack_size;");
1096 -- Code for normal case (standard library not suppressed)
1098 -- We call the routine from inside adainit() because this works for
1099 -- both programs with and without binder generated "main" functions.
1101 WBI (" extern int __gl_main_priority;");
1102 Set_String (" __gl_main_priority = ");
1103 Set_Int (Main_Priority);
1105 Write_Statement_Buffer;
1107 WBI (" extern int __gl_time_slice_val;");
1108 Set_String (" __gl_time_slice_val = ");
1110 if Task_Dispatching_Policy = 'F'
1111 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
1115 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
1119 Write_Statement_Buffer;
1121 WBI (" extern char __gl_wc_encoding;");
1122 Set_String (" __gl_wc_encoding = '");
1123 Set_Char (Get_WC_Encoding);
1126 Write_Statement_Buffer;
1128 WBI (" extern char __gl_locking_policy;");
1129 Set_String (" __gl_locking_policy = '");
1130 Set_Char (Locking_Policy_Specified);
1132 Write_Statement_Buffer;
1134 WBI (" extern char __gl_queuing_policy;");
1135 Set_String (" __gl_queuing_policy = '");
1136 Set_Char (Queuing_Policy_Specified);
1138 Write_Statement_Buffer;
1140 WBI (" extern char __gl_task_dispatching_policy;");
1141 Set_String (" __gl_task_dispatching_policy = '");
1142 Set_Char (Task_Dispatching_Policy_Specified);
1144 Write_Statement_Buffer;
1146 WBI (" extern int __gl_main_cpu;");
1147 Set_String (" __gl_main_cpu = ");
1150 Write_Statement_Buffer;
1154 WBI (" extern const void *__gl_interrupt_states;");
1155 WBI (" __gl_interrupt_states = local_interrupt_states;");
1157 WBI (" extern int __gl_num_interrupt_states;");
1158 Set_String (" __gl_num_interrupt_states = ");
1159 Set_Int (IS_Pragma_Settings.Last + 1);
1161 Write_Statement_Buffer;
1163 WBI (" extern const void *__gl_priority_specific_dispatching;");
1164 WBI (" __gl_priority_specific_dispatching =" &
1165 " local_priority_specific_dispatching;");
1167 WBI (" extern int __gl_num_specific_dispatching;");
1168 Set_String (" __gl_num_specific_dispatching = ");
1169 Set_Int (PSD_Pragma_Settings.Last + 1);
1171 Write_Statement_Buffer;
1173 WBI (" extern int __gl_unreserve_all_interrupts;");
1174 Set_String (" __gl_unreserve_all_interrupts = ");
1175 Set_Int (Boolean'Pos (Unreserve_All_Interrupts_Specified));
1177 Write_Statement_Buffer;
1179 if Exception_Tracebacks then
1180 WBI (" extern int __gl_exception_tracebacks;");
1181 WBI (" __gl_exception_tracebacks = 1;");
1184 WBI (" extern int __gl_zero_cost_exceptions;");
1185 Set_String (" __gl_zero_cost_exceptions = ");
1186 Set_Int (Boolean'Pos (Zero_Cost_Exceptions_Specified));
1188 Write_Statement_Buffer;
1190 WBI (" extern int __gl_detect_blocking;");
1191 Set_String (" __gl_detect_blocking = ");
1193 if Detect_Blocking then
1200 Write_Statement_Buffer;
1202 WBI (" extern int __gl_default_stack_size;");
1203 Set_String (" __gl_default_stack_size = ");
1204 Set_Int (Default_Stack_Size);
1206 Write_Statement_Buffer;
1208 WBI (" extern int __gl_leap_seconds_support;");
1209 Set_String (" __gl_leap_seconds_support = ");
1211 if Leap_Seconds_Support then
1218 Write_Statement_Buffer;
1222 -- Install elaboration time signal handler
1224 WBI (" if (__gnat_handler_installed == 0)");
1226 WBI (" __gnat_install_handler ();");
1229 -- Call feature enable/disable routine
1231 if OpenVMS_On_Target then
1232 WBI (" if (__gnat_features_set == 0)");
1234 WBI (" __gnat_set_features ();");
1239 -- Initialize stack limit for the environment task if the stack
1240 -- check method is stack limit and stack check is enabled.
1242 if Stack_Check_Limits_On_Target
1243 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
1246 WBI (" __gnat_initialize_stack_limit ();");
1249 -- Generate call to set Initialize_Scalar values if needed
1251 if Initialize_Scalars_Used then
1253 Set_String (" system__scalar_values__initialize('");
1254 Set_Char (Initialize_Scalars_Mode1);
1255 Set_String ("', '");
1256 Set_Char (Initialize_Scalars_Mode2);
1258 Write_Statement_Buffer;
1261 -- Generate assignment of default secondary stack size if set
1263 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1265 Set_String (" system__secondary_stack__");
1266 Set_String ("default_secondary_stack_size = ");
1267 Set_Int (Opt.Default_Sec_Stack_Size);
1269 Write_Statement_Buffer;
1272 -- Generate elaboration calls
1280 ------------------------
1281 -- Gen_Elab_Calls_Ada --
1282 ------------------------
1284 procedure Gen_Elab_Calls_Ada is
1286 for E in Elab_Order.First .. Elab_Order.Last loop
1288 Unum : constant Unit_Id := Elab_Order.Table (E);
1289 U : Unit_Record renames Units.Table (Unum);
1291 Unum_Spec : Unit_Id;
1292 -- This is the unit number of the spec that corresponds to
1293 -- this entry. It is the same as Unum except when the body
1294 -- and spec are different and we are currently processing
1295 -- the body, in which case it is the spec (Unum + 1).
1298 if U.Utype = Is_Body then
1299 Unum_Spec := Unum + 1;
1304 -- Nothing to do if predefined unit in no run time mode
1306 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1309 -- Case of no elaboration code
1311 elsif U.No_Elab then
1313 -- The only case in which we have to do something is if
1314 -- this is a body, with a separate spec, where the separate
1315 -- spec has an elaboration entity defined.
1317 -- In that case, this is where we set the elaboration entity
1318 -- to True, we do not need to test if this has already been
1319 -- done, since it is quicker to set the flag than to test it.
1321 if not U.SAL_Interface and then U.Utype = Is_Body
1322 and then Units.Table (Unum_Spec).Set_Elab_Entity
1325 Set_Unit_Number (Unum_Spec);
1326 Set_String (" := True;");
1327 Write_Statement_Buffer;
1330 -- Here if elaboration code is present. If binding a library
1331 -- or if there is a non-Ada main subprogram then we generate:
1333 -- if not uname_E then
1334 -- uname'elab_[spec|body];
1338 -- Otherwise, elaboration routines are called unconditionally:
1340 -- uname'elab_[spec|body];
1343 -- The uname_E assignment is skipped if this is a separate spec,
1344 -- since the assignment will be done when we process the body.
1346 elsif not U.SAL_Interface then
1347 if Force_Checking_Of_Elaboration_Flags or
1348 Interface_Library_Unit or
1349 (not Bind_Main_Program)
1351 Set_String (" if not E");
1352 Set_Unit_Number (Unum_Spec);
1353 Set_String (" then");
1354 Write_Statement_Buffer;
1359 Get_Decoded_Name_String_With_Brackets (U.Uname);
1361 if VM_Target = CLI_Target and then U.Unit_Kind /= 's' then
1362 if Name_Buffer (Name_Len) = 's' then
1363 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1366 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1370 Name_Len := Name_Len + 12;
1373 if Name_Buffer (Name_Len) = 's' then
1374 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1377 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1381 Name_Len := Name_Len + 8;
1384 Set_Casing (U.Icasing);
1387 Write_Statement_Buffer;
1389 if U.Utype /= Is_Spec then
1390 if Force_Checking_Of_Elaboration_Flags or
1391 Interface_Library_Unit or
1392 (not Bind_Main_Program)
1398 Set_Unit_Number (Unum_Spec);
1399 Set_String (" := True;");
1400 Write_Statement_Buffer;
1403 if Force_Checking_Of_Elaboration_Flags or
1404 Interface_Library_Unit or
1405 (not Bind_Main_Program)
1412 end Gen_Elab_Calls_Ada;
1414 ----------------------
1415 -- Gen_Elab_Calls_C --
1416 ----------------------
1418 procedure Gen_Elab_Calls_C is
1420 for E in Elab_Order.First .. Elab_Order.Last loop
1422 Unum : constant Unit_Id := Elab_Order.Table (E);
1423 U : Unit_Record renames Units.Table (Unum);
1425 Unum_Spec : Unit_Id;
1426 -- This is the unit number of the spec that corresponds to
1427 -- this entry. It is the same as Unum except when the body
1428 -- and spec are different and we are currently processing
1429 -- the body, in which case it is the spec (Unum + 1).
1432 if U.Utype = Is_Body then
1433 Unum_Spec := Unum + 1;
1438 -- Nothing to do if predefined unit in no run time mode
1440 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1443 -- Case of no elaboration code
1445 elsif U.No_Elab then
1447 -- The only case in which we have to do something is if
1448 -- this is a body, with a separate spec, where the separate
1449 -- spec has an elaboration entity defined.
1451 -- In that case, this is where we set the elaboration entity
1452 -- to True, we do not need to test if this has already been
1453 -- done, since it is quicker to set the flag than to test it.
1455 if not U.SAL_Interface and then U.Utype = Is_Body
1456 and then Units.Table (Unum_Spec).Set_Elab_Entity
1459 Get_Name_String (U.Uname);
1461 Set_String ("_E = 1;");
1462 Write_Statement_Buffer;
1465 -- Here if elaboration code is present. If binding a library
1466 -- or if there is a non-Ada main subprogram then we generate:
1468 -- if (uname_E == 0) {
1469 -- uname__elab[s|b] ();
1473 -- The uname_E assignment is skipped if this is a separate spec,
1474 -- since the assignment will be done when we process the body.
1476 elsif not U.SAL_Interface then
1477 Get_Name_String (U.Uname);
1479 if Force_Checking_Of_Elaboration_Flags or
1480 Interface_Library_Unit or
1481 (not Bind_Main_Program)
1483 Set_String (" if (");
1485 Set_String ("_E == 0) {");
1486 Write_Statement_Buffer;
1492 Set_String ("___elab");
1493 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1494 Set_String (" ();");
1495 Write_Statement_Buffer;
1497 if U.Utype /= Is_Spec then
1498 if Force_Checking_Of_Elaboration_Flags or
1499 Interface_Library_Unit or
1500 (not Bind_Main_Program)
1507 Set_String ("_E++;");
1508 Write_Statement_Buffer;
1511 if Force_Checking_Of_Elaboration_Flags or
1512 Interface_Library_Unit or
1513 (not Bind_Main_Program)
1520 end Gen_Elab_Calls_C;
1522 ----------------------
1523 -- Gen_Elab_Defs_C --
1524 ----------------------
1526 procedure Gen_Elab_Defs_C is
1528 WBI ("/* BEGIN ELABORATION DEFINITIONS */");
1530 for E in Elab_Order.First .. Elab_Order.Last loop
1532 -- Generate declaration of elaboration procedure if elaboration
1533 -- needed. Note that passive units are always excluded.
1535 if not Units.Table (Elab_Order.Table (E)).No_Elab then
1536 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1537 Set_String ("extern void ");
1539 Set_String ("___elab");
1540 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1541 Set_String (" (void);");
1542 Write_Statement_Buffer;
1546 end Gen_Elab_Defs_C;
1548 ------------------------
1549 -- Gen_Elab_Order_Ada --
1550 ------------------------
1552 procedure Gen_Elab_Order_Ada is
1554 WBI (" -- BEGIN ELABORATION ORDER");
1556 for J in Elab_Order.First .. Elab_Order.Last loop
1557 Set_String (" -- ");
1558 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1560 Write_Statement_Buffer;
1563 WBI (" -- END ELABORATION ORDER");
1565 end Gen_Elab_Order_Ada;
1567 ----------------------
1568 -- Gen_Elab_Order_C --
1569 ----------------------
1571 procedure Gen_Elab_Order_C is
1573 WBI ("/* BEGIN ELABORATION ORDER");
1575 for J in Elab_Order.First .. Elab_Order.Last loop
1576 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1578 Write_Statement_Buffer;
1581 WBI (" END ELABORATION ORDER */");
1583 end Gen_Elab_Order_C;
1585 ------------------------------
1586 -- Gen_Finalize_Library_Ada --
1587 ------------------------------
1589 procedure Gen_Finalize_Library_Ada is
1592 Uspec : Unit_Record;
1596 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1597 Unum := Elab_Order.Table (E);
1598 U := Units.Table (Unum);
1600 -- We are only interested in non-generic packages
1602 if U.Unit_Kind = 'p'
1603 and then U.Has_Finalizer
1604 and then not U.Is_Generic
1605 and then not U.No_Elab
1607 if not Lib_Final_Built then
1608 Lib_Final_Built := True;
1610 WBI (" procedure Finalize_Library is");
1612 -- The following flag is used to check for library-level
1613 -- exceptions raised during finalization. The symbol comes
1614 -- from System.Soft_Links. VM targets use regular Ada to
1615 -- reference the entity.
1617 if VM_Target = No_VM then
1618 WBI (" LE_Set : Boolean;");
1620 Set_String (" pragma Import (Ada, LE_Set, ");
1621 Set_String ("""__gnat_library_exception_set"");");
1622 Write_Statement_Buffer;
1630 -- procedure F<Count>;
1632 Set_String (" declare");
1633 Write_Statement_Buffer;
1635 Set_String (" procedure F");
1638 Write_Statement_Buffer;
1641 -- pragma Import (CIL, F<Count>, "xx.yy_pkg.Finalize[B/S]");
1642 -- -- for .NET targets
1644 -- pragma Import (Java, F<Count>, "xx$yy.Finalize[B/S]");
1645 -- -- for JVM targets
1647 -- pragma Import (Ada, F<Count>, "xx__yy__Finalize[B/S]");
1648 -- -- for default targets
1650 if VM_Target = CLI_Target then
1651 Set_String (" pragma Import (CIL, F");
1652 elsif VM_Target = JVM_Target then
1653 Set_String (" pragma Import (Java, F");
1655 Set_String (" pragma Import (Ada, F");
1659 Set_String (", """);
1661 -- Dealing with package bodies is a little complicated. In such
1662 -- cases we must retrieve the package spec since it contains the
1663 -- spec of the body finalizer.
1665 if U.Utype = Is_Body then
1667 Uspec := Units.Table (Unum);
1672 Get_Name_String (Uspec.Uname);
1674 -- Perform name construction
1676 -- .NET xx.yy_pkg.finalize
1678 if VM_Target = CLI_Target then
1679 Set_Unit_Name (Mode => Dot);
1680 Set_String ("_pkg.finalize");
1682 -- JVM xx$yy.finalize
1684 elsif VM_Target = JVM_Target then
1685 Set_Unit_Name (Mode => Dollar_Sign);
1686 Set_String (".finalize");
1688 -- Default xx__yy__finalize
1692 Set_String ("__finalize");
1695 -- Package spec processing
1697 if U.Utype = Is_Spec
1698 or else U.Utype = Is_Spec_Only
1702 -- Package body processing
1708 Set_String (""");");
1709 Write_Statement_Buffer;
1720 Write_Statement_Buffer;
1727 if Lib_Final_Built then
1729 -- It is possible that the finalization of a library-level object
1730 -- raised an exception. In that case import the actual exception
1731 -- and the routine necessary to raise it.
1733 if VM_Target = No_VM then
1734 WBI (" if LE_Set then");
1736 WBI (" LE : Ada.Exceptions.Exception_Occurrence;");
1738 Set_String (" pragma Import (Ada, LE, ");
1739 Set_String ("""__gnat_library_exception"");");
1740 Write_Statement_Buffer;
1742 Set_String (" procedure Raise_Controlled ");
1743 Set_String ("(E : Ada.Exceptions.Exception_Occurrence);");
1744 Write_Statement_Buffer;
1746 Set_String (" pragma Import (Ada, Raise_Controlled, ");
1747 Set_String ("""__gnat_raise_from_controlled_operation"");");
1748 Write_Statement_Buffer;
1751 WBI (" Raise_Controlled (LE);");
1754 -- VM-specific code, use regular Ada to produce the desired behavior
1757 WBI (" if System.Soft_Links.Library_Exception_Set then");
1759 Set_String (" Ada.Exceptions.Reraise_Occurrence (");
1760 Set_String ("System.Soft_Links.Library_Exception);");
1761 Write_Statement_Buffer;
1765 WBI (" end Finalize_Library;");
1768 end Gen_Finalize_Library_Ada;
1770 ----------------------------
1771 -- Gen_Finalize_Library_C --
1772 ----------------------------
1774 procedure Gen_Finalize_Library_C is
1776 Uspec : Unit_Record;
1780 WBI (" /* BEGIN FINALIZE */");
1782 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1783 Unum := Elab_Order.Table (E);
1784 U := Units.Table (Unum);
1786 -- We are only interested in non-generic packages
1788 if U.Unit_Kind = 'p'
1789 and then U.Has_Finalizer
1790 and then not U.Is_Generic
1791 and then not U.No_Elab
1795 -- Dealing with package bodies is a little complicated. In such
1796 -- cases we must retrieve the package spec since it contains the
1797 -- spec of the body finalizer.
1799 if U.Utype = Is_Body then
1801 Uspec := Units.Table (Unum);
1806 Get_Name_String (Uspec.Uname);
1808 Set_String ("__finalize");
1810 -- Package spec processing
1812 if U.Utype = Is_Spec
1813 or else U.Utype = Is_Spec_Only
1817 -- Package body processing
1823 Set_String (" ();");
1825 Write_Statement_Buffer;
1829 WBI (" /* END FINALIZE */");
1831 end Gen_Finalize_Library_C;
1833 ---------------------------------
1834 -- Gen_Finalize_Library_Defs_C --
1835 ---------------------------------
1837 procedure Gen_Finalize_Library_Defs_C is
1839 Uspec : Unit_Record;
1843 WBI ("/* BEGIN FINALIZE DEFINITIONS */");
1845 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1846 Unum := Elab_Order.Table (E);
1847 U := Units.Table (Unum);
1849 -- We are only interested in non-generic packages
1851 if U.Unit_Kind = 'p'
1852 and then U.Has_Finalizer
1853 and then not U.Is_Generic
1854 and then not U.No_Elab
1856 -- Dealing with package bodies is a little complicated. In such
1857 -- cases we must retrieve the package spec since it contains the
1858 -- spec of the body finalizer.
1860 if U.Utype = Is_Body then
1862 Uspec := Units.Table (Unum);
1867 Set_String ("extern void ");
1868 Get_Name_String (Uspec.Uname);
1870 Set_String ("__finalize");
1872 if U.Utype = Is_Spec
1873 or else U.Utype = Is_Spec_Only
1880 Set_String (" (void);");
1881 Write_Statement_Buffer;
1885 WBI ("/* END FINALIZE DEFINITIONS */");
1887 end Gen_Finalize_Library_Defs_C;
1893 procedure Gen_Main_Ada is
1895 if Exit_Status_Supported_On_Target then
1896 Set_String (" function ");
1898 Set_String (" procedure ");
1901 Set_String (Get_Main_Name);
1903 if Command_Line_Args_On_Target then
1904 Write_Statement_Buffer;
1905 WBI (" (argc : Integer;");
1906 WBI (" argv : System.Address;");
1907 WBI (" envp : System.Address)");
1909 if Exit_Status_Supported_On_Target then
1910 WBI (" return Integer");
1916 if Exit_Status_Supported_On_Target then
1917 Set_String (" return Integer is");
1922 Write_Statement_Buffer;
1925 if Opt.Default_Exit_Status /= 0
1926 and then Bind_Main_Program
1927 and then not Configurable_Run_Time_Mode
1929 WBI (" procedure Set_Exit_Status (Status : Integer);");
1930 WBI (" pragma Import (C, Set_Exit_Status, " &
1931 """__gnat_set_exit_status"");");
1935 -- Initialize and Finalize
1937 if not Cumulative_Restrictions.Set (No_Finalization) then
1938 WBI (" procedure Initialize (Addr : System.Address);");
1939 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1941 WBI (" procedure Finalize;");
1942 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1945 -- If we want to analyze the stack, we have to import corresponding
1948 if Dynamic_Stack_Measurement then
1950 WBI (" procedure Output_Results;");
1951 WBI (" pragma Import (C, Output_Results, " &
1952 """__gnat_stack_usage_output_results"");");
1956 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1957 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1958 """__gnat_stack_usage_initialize"");");
1961 -- Deal with declarations for main program case
1963 if not No_Main_Subprogram then
1965 -- To call the main program, we declare it using a pragma Import
1966 -- Ada with the right link name.
1968 -- It might seem more obvious to "with" the main program, and call
1969 -- it in the normal Ada manner. We do not do this for three reasons:
1971 -- 1. It is more efficient not to recompile the main program
1972 -- 2. We are not entitled to assume the source is accessible
1973 -- 3. We don't know what options to use to compile it
1975 -- It is really reason 3 that is most critical (indeed we used
1976 -- to generate the "with", but several regression tests failed).
1980 if ALIs.Table (ALIs.First).Main_Program = Func then
1981 WBI (" Result : Integer;");
1983 WBI (" function Ada_Main_Program return Integer;");
1986 WBI (" procedure Ada_Main_Program;");
1989 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1990 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1991 Set_Main_Program_Name;
1992 Set_String (""");");
1994 Write_Statement_Buffer;
1997 if Bind_Main_Program
1998 and then not Suppress_Standard_Library_On_Target
2000 WBI (" SEH : aliased array (1 .. 2) of Integer;");
2005 -- Generate a reference to Ada_Main_Program_Name. This symbol is
2006 -- not referenced elsewhere in the generated program, but is needed
2007 -- by the debugger (that's why it is generated in the first place).
2008 -- The reference stops Ada_Main_Program_Name from being optimized
2009 -- away by smart linkers, such as the AiX linker.
2011 -- Because this variable is unused, we make this variable "aliased"
2012 -- with a pragma Volatile in order to tell the compiler to preserve
2013 -- this variable at any level of optimization.
2015 if Bind_Main_Program then
2017 (" Ensure_Reference : aliased System.Address := " &
2018 "Ada_Main_Program_Name'Address;");
2019 WBI (" pragma Volatile (Ensure_Reference);");
2025 -- Acquire command line arguments if present on target
2027 if Command_Line_Args_On_Target then
2028 WBI (" gnat_argc := argc;");
2029 WBI (" gnat_argv := argv;");
2030 WBI (" gnat_envp := envp;");
2033 -- If configurable run time and no command line args, then nothing
2034 -- needs to be done since the gnat_argc/argv/envp variables are
2035 -- suppressed in this case.
2037 elsif Configurable_Run_Time_On_Target then
2040 -- Otherwise set dummy values (to be filled in by some other unit?)
2043 WBI (" gnat_argc := 0;");
2044 WBI (" gnat_argv := System.Null_Address;");
2045 WBI (" gnat_envp := System.Null_Address;");
2048 if Opt.Default_Exit_Status /= 0
2049 and then Bind_Main_Program
2050 and then not Configurable_Run_Time_Mode
2052 Set_String (" Set_Exit_Status (");
2053 Set_Int (Opt.Default_Exit_Status);
2055 Write_Statement_Buffer;
2058 if Dynamic_Stack_Measurement then
2059 Set_String (" Initialize_Stack_Analysis (");
2060 Set_Int (Dynamic_Stack_Measurement_Array_Size);
2062 Write_Statement_Buffer;
2065 if not Cumulative_Restrictions.Set (No_Finalization) then
2066 if not No_Main_Subprogram
2067 and then Bind_Main_Program
2068 and then not Suppress_Standard_Library_On_Target
2070 WBI (" Initialize (SEH'Address);");
2072 WBI (" Initialize (System.Null_Address);");
2076 WBI (" " & Ada_Init_Name.all & ";");
2078 if not No_Main_Subprogram then
2079 WBI (" Break_Start;");
2081 if ALIs.Table (ALIs.First).Main_Program = Proc then
2082 WBI (" Ada_Main_Program;");
2084 WBI (" Result := Ada_Main_Program;");
2088 -- Adafinal call is skipped if no finalization
2090 if not Cumulative_Restrictions.Set (No_Finalization) then
2094 -- Prints the result of static stack analysis
2096 if Dynamic_Stack_Measurement then
2097 WBI (" Output_Results;");
2100 -- Finalize is only called if we have a run time
2102 if not Cumulative_Restrictions.Set (No_Finalization) then
2108 if Exit_Status_Supported_On_Target then
2109 if No_Main_Subprogram
2110 or else ALIs.Table (ALIs.First).Main_Program = Proc
2112 WBI (" return (gnat_exit_status);");
2114 WBI (" return (Result);");
2126 procedure Gen_Main_C is
2127 Needs_Library_Finalization : constant Boolean :=
2128 not Configurable_Run_Time_On_Target
2129 and then Has_Finalizer;
2130 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2131 -- non-terminating, so we do not want library-level finalization.
2134 if Exit_Status_Supported_On_Target then
2135 WBI ("#include <stdlib.h>");
2136 Set_String ("int ");
2138 Set_String ("void ");
2141 Set_String (Get_Main_Name);
2143 -- Generate command line args in prototype if present on target
2145 if Command_Line_Args_On_Target then
2146 Write_Statement_Buffer (" (int argc, char **argv, char **envp)");
2148 -- Case of no command line arguments on target
2151 Write_Statement_Buffer (" (void)");
2156 -- Generate a reference to __gnat_ada_main_program_name. This symbol
2157 -- is not referenced elsewhere in the generated program, but is
2158 -- needed by the debugger (that's why it is generated in the first
2159 -- place). The reference stops Ada_Main_Program_Name from being
2160 -- optimized away by smart linkers, such as the AiX linker.
2162 -- Because this variable is unused, we declare this variable as
2163 -- volatile in order to tell the compiler to preserve it at any
2164 -- level of optimization.
2166 if Bind_Main_Program then
2167 WBI (" char * volatile ensure_reference " &
2168 "__attribute__ ((__unused__)) = " &
2169 "__gnat_ada_main_program_name;");
2172 if not Suppress_Standard_Library_On_Target
2173 and then not No_Main_Subprogram
2175 WBI (" int SEH [2];");
2180 -- If main program is a function, generate result variable
2182 if ALIs.Table (ALIs.First).Main_Program = Func then
2183 WBI (" int result;");
2186 -- Set command line argument values from parameters if command line
2187 -- arguments are present on target
2189 if Command_Line_Args_On_Target then
2190 WBI (" gnat_argc = argc;");
2191 WBI (" gnat_argv = argv;");
2192 WBI (" gnat_envp = envp;");
2195 -- If configurable run-time, then nothing to do, since in this case
2196 -- the gnat_argc/argv/envp variables are entirely suppressed.
2198 elsif Configurable_Run_Time_On_Target then
2201 -- if no command line arguments on target, set dummy values
2204 WBI (" gnat_argc = 0;");
2205 WBI (" gnat_argv = 0;");
2206 WBI (" gnat_envp = 0;");
2209 if Opt.Default_Exit_Status /= 0
2210 and then Bind_Main_Program
2211 and then not Configurable_Run_Time_Mode
2213 Set_String (" __gnat_set_exit_status (");
2214 Set_Int (Opt.Default_Exit_Status);
2216 Write_Statement_Buffer;
2219 -- Initializes dynamic stack measurement if needed
2221 if Dynamic_Stack_Measurement then
2222 Set_String (" __gnat_stack_usage_initialize (");
2223 Set_Int (Dynamic_Stack_Measurement_Array_Size);
2225 Write_Statement_Buffer;
2228 -- The __gnat_initialize routine is used only if we have a run-time
2230 if not Suppress_Standard_Library_On_Target then
2231 if not No_Main_Subprogram and then Bind_Main_Program then
2232 WBI (" __gnat_initialize ((void *)SEH);");
2234 WBI (" __gnat_initialize ((void *)0);");
2238 WBI (" " & Ada_Init_Name.all & " ();");
2240 if not No_Main_Subprogram then
2241 WBI (" __gnat_break_start ();");
2244 -- Output main program name
2246 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2248 -- Main program is procedure case
2250 if ALIs.Table (ALIs.First).Main_Program = Proc then
2252 Set_Main_Program_Name;
2253 Set_String (" ();");
2254 Write_Statement_Buffer;
2256 -- Main program is function case
2258 else -- ALIs.Table (ALIs_First).Main_Program = Func
2259 Set_String (" result = ");
2260 Set_Main_Program_Name;
2261 Set_String (" ();");
2262 Write_Statement_Buffer;
2267 -- Call adafinal if finalization active
2269 if not Cumulative_Restrictions.Set (No_Finalization)
2270 and then Needs_Library_Finalization
2272 Gen_Finalize_Library_C;
2275 -- Outputs the dynamic stack measurement if needed
2277 if Dynamic_Stack_Measurement then
2278 WBI (" __gnat_stack_usage_output_results ();");
2281 -- The finalize routine is used only if we have a run-time
2283 if not Suppress_Standard_Library_On_Target then
2284 WBI (" __gnat_finalize ();");
2287 -- Case of main program is a function, so the value it returns
2288 -- is the exit status in this case.
2290 if ALIs.Table (ALIs.First).Main_Program = Func then
2291 if Exit_Status_Supported_On_Target then
2293 -- VMS must use Posix exit routine in order to get the effect
2294 -- of a Unix compatible setting of the program exit status.
2295 -- For all other systems, we use the standard exit routine.
2297 if OpenVMS_On_Target then
2298 WBI (" decc$__posix_exit (result);");
2300 WBI (" exit (result);");
2304 -- Case of main program is a procedure, in which case the exit
2305 -- status is whatever was set by a Set_Exit call most recently
2308 if Exit_Status_Supported_On_Target then
2310 -- VMS must use Posix exit routine in order to get the effect
2311 -- of a Unix compatible setting of the program exit status.
2312 -- For all other systems, we use the standard exit routine.
2314 if OpenVMS_On_Target then
2315 WBI (" decc$__posix_exit (gnat_exit_status);");
2317 WBI (" exit (gnat_exit_status);");
2326 ------------------------------
2327 -- Gen_Object_Files_Options --
2328 ------------------------------
2330 procedure Gen_Object_Files_Options is
2332 -- This keeps track of the position in the sorted set of entries
2333 -- in the Linker_Options table of where the first entry from an
2334 -- internal file appears.
2336 Linker_Option_List_Started : Boolean := False;
2337 -- Set to True when "LINKER OPTION LIST" is displayed
2339 procedure Write_Linker_Option;
2340 -- Write binder info linker option
2342 -------------------------
2343 -- Write_Linker_Option --
2344 -------------------------
2346 procedure Write_Linker_Option is
2351 -- Loop through string, breaking at null's
2354 while Start < Name_Len loop
2356 -- Find null ending this section
2359 while Name_Buffer (Stop) /= ASCII.NUL
2360 and then Stop <= Name_Len loop
2364 -- Process section if non-null
2366 if Stop > Start then
2367 if Output_Linker_Option_List then
2368 if not Zero_Formatting then
2369 if not Linker_Option_List_Started then
2370 Linker_Option_List_Started := True;
2372 Write_Str (" LINKER OPTION LIST");
2380 Write_Str (Name_Buffer (Start .. Stop - 1));
2384 (" -- ", "", Name_Buffer (Start .. Stop - 1));
2389 end Write_Linker_Option;
2391 -- Start of processing for Gen_Object_Files_Options
2394 Write_Info_Ada_C ("-- ", "/* ", " BEGIN Object file/option list");
2396 if Object_List_Filename /= null then
2397 Set_List_File (Object_List_Filename.all);
2400 for E in Elab_Order.First .. Elab_Order.Last loop
2402 -- If not spec that has an associated body, then generate a comment
2403 -- giving the name of the corresponding object file.
2405 if (not Units.Table (Elab_Order.Table (E)).SAL_Interface)
2406 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
2410 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
2412 -- If the presence of an object file is necessary or if it exists,
2415 if not Hostparm.Exclude_Missing_Objects
2417 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
2419 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
2421 if Output_Object_List then
2422 Write_Str (Name_Buffer (1 .. Name_Len));
2426 -- Don't link with the shared library on VMS if an internal
2427 -- filename object is seen. Multiply defined symbols will
2430 if OpenVMS_On_Target
2431 and then Is_Internal_File_Name
2433 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
2435 -- Special case for g-trasym.obj (not included in libgnat)
2437 Get_Name_String (ALIs.Table
2438 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
2440 if Name_Buffer (1 .. 8) /= "g-trasym" then
2441 Opt.Shared_Libgnat := False;
2448 if Object_List_Filename /= null then
2452 -- Add a "-Ldir" for each directory in the object path
2453 if VM_Target /= CLI_Target then
2454 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
2456 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
2459 Add_Str_To_Name_Buffer ("-L");
2460 Add_Str_To_Name_Buffer (Dir.all);
2461 Write_Linker_Option;
2466 -- Sort linker options
2468 -- This sort accomplishes two important purposes:
2470 -- a) All application files are sorted to the front, and all GNAT
2471 -- internal files are sorted to the end. This results in a well
2472 -- defined dividing line between the two sets of files, for the
2473 -- purpose of inserting certain standard library references into
2474 -- the linker arguments list.
2476 -- b) Given two different units, we sort the linker options so that
2477 -- those from a unit earlier in the elaboration order comes later
2478 -- in the list. This is a heuristic designed to create a more
2479 -- friendly order of linker options when the operations appear in
2480 -- separate units. The idea is that if unit A must be elaborated
2481 -- before unit B, then it is more likely that B references
2482 -- libraries included by A, than vice versa, so we want libraries
2483 -- included by A to come after libraries included by B.
2485 -- These two criteria are implemented by function Lt_Linker_Option. Note
2486 -- that a special case of b) is that specs are elaborated before bodies,
2487 -- so linker options from specs come after linker options for bodies,
2488 -- and again, the assumption is that libraries used by the body are more
2489 -- likely to reference libraries used by the spec, than vice versa.
2492 (Linker_Options.Last,
2493 Move_Linker_Option'Access,
2494 Lt_Linker_Option'Access);
2496 -- Write user linker options, i.e. the set of linker options that come
2497 -- from all files other than GNAT internal files, Lgnat is left set to
2498 -- point to the first entry from a GNAT internal file, or past the end
2499 -- of the entries if there are no internal files.
2501 Lgnat := Linker_Options.Last + 1;
2503 for J in 1 .. Linker_Options.Last loop
2504 if not Linker_Options.Table (J).Internal_File then
2505 Get_Name_String (Linker_Options.Table (J).Name);
2506 Write_Linker_Option;
2513 -- Now we insert standard linker options that must appear after the
2514 -- entries from user files, and before the entries from GNAT run-time
2515 -- files. The reason for this decision is that libraries referenced
2516 -- by internal routines may reference these standard library entries.
2518 -- Note that we do not insert anything when pragma No_Run_Time has been
2519 -- specified or when the standard libraries are not to be used,
2520 -- otherwise on some platforms, such as VMS, we may get duplicate
2521 -- symbols when linking.
2523 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
2526 if Opt.Shared_Libgnat then
2527 Add_Str_To_Name_Buffer ("-shared");
2529 Add_Str_To_Name_Buffer ("-static");
2532 -- Write directly to avoid -K output (why???)
2534 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
2536 if With_DECGNAT then
2539 if Opt.Shared_Libgnat then
2540 Add_Str_To_Name_Buffer (Shared_Lib ("decgnat"));
2542 Add_Str_To_Name_Buffer ("-ldecgnat");
2545 Write_Linker_Option;
2551 if Opt.Shared_Libgnat then
2552 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
2554 Add_Str_To_Name_Buffer ("-lgnarl");
2557 Write_Linker_Option;
2562 if Opt.Shared_Libgnat then
2563 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
2565 Add_Str_To_Name_Buffer ("-lgnat");
2568 Write_Linker_Option;
2571 -- Write linker options from all internal files
2573 for J in Lgnat .. Linker_Options.Last loop
2574 Get_Name_String (Linker_Options.Table (J).Name);
2575 Write_Linker_Option;
2578 if Output_Linker_Option_List and then not Zero_Formatting then
2582 if Ada_Bind_File then
2583 WBI ("-- END Object file/option list ");
2585 WBI (" END Object file/option list */");
2587 end Gen_Object_Files_Options;
2589 ---------------------
2590 -- Gen_Output_File --
2591 ---------------------
2593 procedure Gen_Output_File (Filename : String) is
2595 -- Acquire settings for Interrupt_State pragmas
2597 Set_IS_Pragma_Table;
2599 -- Acquire settings for Priority_Specific_Dispatching pragma
2601 Set_PSD_Pragma_Table;
2603 -- Override Ada_Bind_File and Bind_Main_Program for VMs since JGNAT only
2604 -- supports Ada code, and the main program is already generated by the
2607 if VM_Target /= No_VM then
2608 Ada_Bind_File := True;
2610 if VM_Target = JVM_Target then
2611 Bind_Main_Program := False;
2615 -- Override time slice value if -T switch is set
2617 if Time_Slice_Set then
2618 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
2621 -- Count number of elaboration calls
2623 for E in Elab_Order.First .. Elab_Order.Last loop
2624 if Units.Table (Elab_Order.Table (E)).No_Elab then
2627 Num_Elab_Calls := Num_Elab_Calls + 1;
2631 -- Generate output file in appropriate language
2633 Check_System_Restrictions_Used;
2635 if Ada_Bind_File then
2636 Gen_Output_File_Ada (Filename);
2638 Gen_Output_File_C (Filename);
2640 end Gen_Output_File;
2642 -------------------------
2643 -- Gen_Output_File_Ada --
2644 -------------------------
2646 procedure Gen_Output_File_Ada (Filename : String) is
2648 Ada_Main : constant String := Get_Ada_Main_Name;
2649 -- Name to be used for generated Ada main program. See the body of
2650 -- function Get_Ada_Main_Name for details on the form of the name.
2652 Needs_Library_Finalization : constant Boolean :=
2653 not Configurable_Run_Time_On_Target
2654 and then Has_Finalizer;
2655 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2656 -- non-terminating, so we do not want finalization.
2659 -- Name of generated bind file (spec)
2662 -- Name of generated bind file (body)
2665 -- Create spec first
2667 Create_Binder_Output (Filename, 's', Bfiles);
2669 -- We always compile the binder file in Ada 95 mode so that we properly
2670 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2671 -- of the Ada 2005 constructs are needed by the binder file.
2673 WBI ("pragma Ada_95;");
2675 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2676 -- then we need to make sure that the binder program is compiled with
2677 -- the same restriction, so that no exception tables are generated.
2679 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2680 WBI ("pragma Restrictions (No_Exception_Handlers);");
2683 -- Same processing for Restrictions (No_Exception_Propagation)
2685 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
2686 WBI ("pragma Restrictions (No_Exception_Propagation);");
2689 -- Same processing for pragma No_Run_Time
2691 if No_Run_Time_Mode then
2692 WBI ("pragma No_Run_Time;");
2695 -- Generate with of System so we can reference System.Address
2697 WBI ("with System;");
2699 -- Generate with of System.Initialize_Scalars if active
2701 if Initialize_Scalars_Used then
2702 WBI ("with System.Scalar_Values;");
2705 -- Generate with of System.Secondary_Stack if active
2707 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2708 WBI ("with System.Secondary_Stack;");
2711 Resolve_Binder_Options;
2713 -- Usually, adafinal is called using a pragma Import C. Since Import C
2714 -- doesn't have the same semantics for JGNAT, we use standard Ada.
2716 if VM_Target /= No_VM
2717 and then not Suppress_Standard_Library_On_Target
2719 WBI ("with System.Soft_Links;");
2720 WBI ("with System.Standard_Library;");
2723 WBI ("package " & Ada_Main & " is");
2724 WBI (" pragma Warnings (Off);");
2726 -- Main program case
2728 if Bind_Main_Program then
2729 if VM_Target = No_VM then
2731 -- Generate argc/argv stuff unless suppressed
2733 if Command_Line_Args_On_Target
2734 or not Configurable_Run_Time_On_Target
2737 WBI (" gnat_argc : Integer;");
2738 WBI (" gnat_argv : System.Address;");
2739 WBI (" gnat_envp : System.Address;");
2741 -- If the standard library is not suppressed, these variables
2742 -- are in the run-time data area for easy run time access.
2744 if not Suppress_Standard_Library_On_Target then
2746 WBI (" pragma Import (C, gnat_argc);");
2747 WBI (" pragma Import (C, gnat_argv);");
2748 WBI (" pragma Import (C, gnat_envp);");
2752 -- Define exit status. Again in normal mode, this is in the
2753 -- run-time library, and is initialized there, but in the
2754 -- configurable runtime case, the variable is declared and
2755 -- initialized in this file.
2759 if Configurable_Run_Time_Mode then
2760 if Exit_Status_Supported_On_Target then
2761 WBI (" gnat_exit_status : Integer := 0;");
2765 WBI (" gnat_exit_status : Integer;");
2766 WBI (" pragma Import (C, gnat_exit_status);");
2770 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2771 -- the main program. Otherwise, it can lead under some circumstances
2772 -- to a symbol duplication during the link (for instance when a C
2773 -- program uses two Ada libraries). Also zero terminate the string
2774 -- so that its end can be found reliably at run time.
2777 WBI (" GNAT_Version : constant String :=");
2778 WBI (" """ & Ver_Prefix &
2779 Gnat_Version_String &
2781 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2784 Set_String (" Ada_Main_Program_Name : constant String := """);
2785 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2787 if VM_Target = No_VM then
2788 Set_Main_Program_Name;
2789 Set_String (""" & ASCII.NUL;");
2791 Set_String (Name_Buffer (1 .. Name_Len - 2) & """;");
2794 Write_Statement_Buffer;
2797 (" pragma Export (C, Ada_Main_Program_Name, " &
2798 """__gnat_ada_main_program_name"");");
2801 if not Cumulative_Restrictions.Set (No_Finalization) then
2803 WBI (" procedure " & Ada_Final_Name.all & ";");
2804 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2805 Ada_Final_Name.all & """);");
2809 WBI (" procedure " & Ada_Init_Name.all & ";");
2810 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2811 Ada_Init_Name.all & """);");
2813 -- If -a has been specified use pragma Linker_Constructor for the init
2814 -- procedure. No need to use a similar pragma for the final procedure as
2815 -- global finalization will occur when the executable finishes execution
2816 -- and for plugins (shared stand-alone libraries that can be
2817 -- "unloaded"), finalization should not occur automatically, otherwise
2818 -- the main executable may not continue to work properly.
2820 if Use_Pragma_Linker_Constructor then
2821 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2824 if Bind_Main_Program and then VM_Target = No_VM then
2826 -- If we have the standard library, then Break_Start is defined
2827 -- there, but when the standard library is suppressed, Break_Start
2831 WBI (" procedure Break_Start;");
2833 if Suppress_Standard_Library_On_Target then
2834 WBI (" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2836 WBI (" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2841 if Exit_Status_Supported_On_Target then
2842 Set_String (" function ");
2844 Set_String (" procedure ");
2847 Set_String (Get_Main_Name);
2849 -- Generate argument list if present
2851 if Command_Line_Args_On_Target then
2852 Write_Statement_Buffer;
2853 WBI (" (argc : Integer;");
2854 WBI (" argv : System.Address;");
2856 (" envp : System.Address)");
2858 if Exit_Status_Supported_On_Target then
2859 Write_Statement_Buffer;
2860 WBI (" return Integer;");
2862 Write_Statement_Buffer (";");
2866 if Exit_Status_Supported_On_Target then
2867 Write_Statement_Buffer (" return Integer;");
2869 Write_Statement_Buffer (";");
2873 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2874 Get_Main_Name & """);");
2883 WBI ("end " & Ada_Main & ";");
2884 Close_Binder_Output;
2886 -- Prepare to write body
2888 Create_Binder_Output (Filename, 'b', Bfileb);
2890 -- We always compile the binder file in Ada 95 mode so that we properly
2891 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2892 -- of the Ada 2005 constructs are needed by the binder file.
2894 WBI ("pragma Ada_95;");
2896 -- Output Source_File_Name pragmas which look like
2898 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2899 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2901 -- where sss/bbb are the spec/body file names respectively
2903 Get_Name_String (Bfiles);
2904 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2906 WBI ("pragma Source_File_Name (" &
2908 ", Spec_File_Name => """ &
2909 Name_Buffer (1 .. Name_Len + 3));
2911 Get_Name_String (Bfileb);
2912 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2914 WBI ("pragma Source_File_Name (" &
2916 ", Body_File_Name => """ &
2917 Name_Buffer (1 .. Name_Len + 3));
2919 -- Generate with of System.Restrictions to initialize
2920 -- Run_Time_Restrictions.
2922 if System_Restrictions_Used
2923 and not Suppress_Standard_Library_On_Target
2926 WBI ("with System.Restrictions;");
2929 if Needs_Library_Finalization then
2930 WBI ("with Ada.Exceptions;");
2934 WBI ("package body " & Ada_Main & " is");
2935 WBI (" pragma Warnings (Off);");
2937 if not Suppress_Standard_Library_On_Target then
2939 -- Generate Priority_Specific_Dispatching pragma string
2942 (" Local_Priority_Specific_Dispatching : constant String := """);
2944 for J in 0 .. PSD_Pragma_Settings.Last loop
2945 Set_Char (PSD_Pragma_Settings.Table (J));
2949 Write_Statement_Buffer;
2951 -- Generate Interrupt_State pragma string
2953 Set_String (" Local_Interrupt_States : constant String := """);
2955 for J in 0 .. IS_Pragma_Settings.Last loop
2956 Set_Char (IS_Pragma_Settings.Table (J));
2960 Write_Statement_Buffer;
2964 -- Generate the adafinal routine unless there is no finalization to do
2966 if not Cumulative_Restrictions.Set (No_Finalization) then
2969 if Needs_Library_Finalization then
2970 Gen_Finalize_Library_Ada;
2976 if Bind_Main_Program and then VM_Target = No_VM then
2978 -- When suppressing the standard library then generate dummy body
2981 if Suppress_Standard_Library_On_Target then
2983 WBI (" procedure Break_Start is");
2992 -- Output object file list and the Ada body is complete
2994 Gen_Object_Files_Options;
2997 WBI ("end " & Ada_Main & ";");
2999 Close_Binder_Output;
3000 end Gen_Output_File_Ada;
3002 -----------------------
3003 -- Gen_Output_File_C --
3004 -----------------------
3006 procedure Gen_Output_File_C (Filename : String) is
3008 Needs_Library_Finalization : constant Boolean :=
3009 not Configurable_Run_Time_On_Target
3010 and then Has_Finalizer;
3011 -- ??? seems like we repeat this cantation often, should it be global?
3014 pragma Warnings (Off, Bfile);
3015 -- Name of generated bind file (not referenced)
3018 Create_Binder_Output (Filename, 'c', Bfile);
3020 Resolve_Binder_Options;
3022 WBI ("extern void " & Ada_Final_Name.all & " (void);");
3024 -- If -a has been specified use __attribute__((constructor)) for the
3025 -- init procedure. No need to use a similar featute for the final
3026 -- procedure as global finalization will occur when the executable
3027 -- finishes execution and for plugins (shared stand-alone libraries that
3028 -- can be "unloaded"), finalization should not occur automatically,
3029 -- otherwise the main executable may not continue to work properly.
3031 if Use_Pragma_Linker_Constructor then
3032 WBI ("extern void " & Ada_Init_Name.all &
3033 " (void) __attribute__((constructor));");
3035 WBI ("extern void " & Ada_Init_Name.all & " (void);");
3038 WBI ("extern void system__standard_library__adafinal (void);");
3040 if not No_Main_Subprogram then
3041 Set_String ("extern ");
3043 if Exit_Status_Supported_On_Target then
3046 Set_String ("void");
3049 Set_String (" main ");
3051 if Command_Line_Args_On_Target then
3052 Write_Statement_Buffer ("(int, char **, char **);");
3054 Write_Statement_Buffer ("(void);");
3057 if OpenVMS_On_Target then
3058 WBI ("extern void decc$__posix_exit (int);");
3060 WBI ("extern void exit (int);");
3063 WBI ("extern void __gnat_break_start (void);");
3064 Set_String ("extern ");
3066 if ALIs.Table (ALIs.First).Main_Program = Proc then
3067 Set_String ("void ");
3069 Set_String ("int ");
3072 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3073 Set_Main_Program_Name;
3074 Set_String (" (void);");
3075 Write_Statement_Buffer;
3078 if not Suppress_Standard_Library_On_Target then
3079 WBI ("extern void __gnat_initialize (void *);");
3080 WBI ("extern void __gnat_finalize (void);");
3081 WBI ("extern void __gnat_install_handler (void);");
3084 if Dynamic_Stack_Measurement then
3086 WBI ("extern void __gnat_stack_usage_output_results (void);");
3087 WBI ("extern void __gnat_stack_usage_initialize (int size);");
3090 -- Initialize stack limit for the environment task if the stack check
3091 -- method is stack limit and stack check is enabled.
3093 if Stack_Check_Limits_On_Target
3094 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
3097 WBI ("extern void __gnat_initialize_stack_limit (void);");
3104 if Needs_Library_Finalization then
3105 Gen_Finalize_Library_Defs_C;
3108 -- Imported variables used only when we have a runtime
3110 if not Suppress_Standard_Library_On_Target then
3112 -- Track elaboration/finalization phase
3114 WBI ("extern int __gnat_handler_installed;");
3117 -- Track feature enable/disable on VMS
3119 if OpenVMS_On_Target then
3120 WBI ("extern int __gnat_features_set;");
3125 -- Write argv/argc exit status stuff if main program case
3127 if Bind_Main_Program then
3129 -- First deal with argc/argv/envp. In the normal case they are in the
3130 -- run-time library.
3132 if not Configurable_Run_Time_On_Target then
3133 WBI ("extern int gnat_argc;");
3134 WBI ("extern char **gnat_argv;");
3135 WBI ("extern char **gnat_envp;");
3137 -- If configurable run time and no command line args, then the
3138 -- generation of these variables is entirely suppressed.
3140 elsif not Command_Line_Args_On_Target then
3143 -- Otherwise, in the configurable run-time case they are right in the
3147 WBI ("int gnat_argc;");
3148 WBI ("char **gnat_argv;");
3149 WBI ("char **gnat_envp;");
3152 -- Similarly deal with exit status
3154 if not Configurable_Run_Time_On_Target then
3155 WBI ("extern int gnat_exit_status;");
3157 -- If configurable run time and no exit status on target, then the
3158 -- generation of this variables is entirely suppressed.
3160 elsif not Exit_Status_Supported_On_Target then
3163 -- Otherwise, in the configurable run-time case this variable is
3164 -- right in the binder file, and initialized to zero there.
3167 WBI ("int gnat_exit_status = 0;");
3173 -- When suppressing the standard library, the __gnat_break_start routine
3174 -- (for the debugger to get initial control) is defined in this file.
3176 if Suppress_Standard_Library_On_Target then
3178 WBI ("void __gnat_break_start (void) {}");
3181 -- Generate the __gnat_version and __gnat_ada_main_program_name info
3182 -- only for the main program. Otherwise, it can lead under some
3183 -- circumstances to a symbol duplication during the link (for instance
3184 -- when a C program uses 2 Ada libraries)
3186 if Bind_Main_Program then
3188 WBI ("char __gnat_version[] = """ & Ver_Prefix &
3189 Gnat_Version_String & """;");
3191 Set_String ("char __gnat_ada_main_program_name[] = """);
3192 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3193 Set_Main_Program_Name;
3195 Write_Statement_Buffer;
3198 -- Generate the adafinal routine. In no runtime mode, this is not
3199 -- needed, since there is no finalization to do.
3201 if not Cumulative_Restrictions.Set (No_Finalization) then
3207 -- Main is only present for Ada main case
3209 if Bind_Main_Program then
3213 -- Generate versions, elaboration order, list of object files
3217 Gen_Object_Files_Options;
3219 -- C binder output is complete
3221 Close_Binder_Output;
3222 end Gen_Output_File_C;
3224 --------------------------
3225 -- Gen_Restrictions_Ada --
3226 --------------------------
3228 procedure Gen_Restrictions_Ada is
3232 if Suppress_Standard_Library_On_Target
3233 or not System_Restrictions_Used
3238 WBI (" System.Restrictions.Run_Time_Restrictions :=");
3244 for J in Cumulative_Restrictions.Set'Range loop
3245 Set_Boolean (Cumulative_Restrictions.Set (J));
3249 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
3250 Write_Statement_Buffer;
3256 Set_String_Replace ("),");
3257 Write_Statement_Buffer;
3258 Set_String (" Value => (");
3260 for J in Cumulative_Restrictions.Value'Range loop
3261 Set_Int (Int (Cumulative_Restrictions.Value (J)));
3265 Set_String_Replace ("),");
3266 Write_Statement_Buffer;
3267 WBI (" Violated =>");
3271 for J in Cumulative_Restrictions.Violated'Range loop
3272 Set_Boolean (Cumulative_Restrictions.Violated (J));
3276 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
3277 Write_Statement_Buffer;
3283 Set_String_Replace ("),");
3284 Write_Statement_Buffer;
3285 Set_String (" Count => (");
3287 for J in Cumulative_Restrictions.Count'Range loop
3288 Set_Int (Int (Cumulative_Restrictions.Count (J)));
3292 Set_String_Replace ("),");
3293 Write_Statement_Buffer;
3294 Set_String (" Unknown => (");
3296 for J in Cumulative_Restrictions.Unknown'Range loop
3297 Set_Boolean (Cumulative_Restrictions.Unknown (J));
3301 Set_String_Replace ("))");
3303 Write_Statement_Buffer;
3304 end Gen_Restrictions_Ada;
3306 ------------------------
3307 -- Gen_Restrictions_C --
3308 ------------------------
3310 procedure Gen_Restrictions_C is
3312 if Suppress_Standard_Library_On_Target
3313 or not System_Restrictions_Used
3318 WBI (" typedef struct {");
3319 Set_String (" char set [");
3320 Set_Int (Cumulative_Restrictions.Set'Length);
3322 Write_Statement_Buffer;
3324 Set_String (" int value [");
3325 Set_Int (Cumulative_Restrictions.Value'Length);
3327 Write_Statement_Buffer;
3329 Set_String (" char violated [");
3330 Set_Int (Cumulative_Restrictions.Violated'Length);
3332 Write_Statement_Buffer;
3334 Set_String (" int count [");
3335 Set_Int (Cumulative_Restrictions.Count'Length);
3337 Write_Statement_Buffer;
3339 Set_String (" char unknown [");
3340 Set_Int (Cumulative_Restrictions.Unknown'Length);
3342 Write_Statement_Buffer;
3343 WBI (" } restrictions;");
3344 WBI (" extern restrictions " &
3345 "system__restrictions__run_time_restrictions;");
3346 WBI (" restrictions r = {");
3349 for J in Cumulative_Restrictions.Set'Range loop
3350 Set_Int (Boolean'Pos (Cumulative_Restrictions.Set (J)));
3354 Set_String_Replace ("},");
3355 Write_Statement_Buffer;
3358 for J in Cumulative_Restrictions.Value'Range loop
3359 Set_Int (Int (Cumulative_Restrictions.Value (J)));
3363 Set_String_Replace ("},");
3364 Write_Statement_Buffer;
3367 for J in Cumulative_Restrictions.Violated'Range loop
3368 Set_Int (Boolean'Pos (Cumulative_Restrictions.Violated (J)));
3372 Set_String_Replace ("},");
3373 Write_Statement_Buffer;
3376 for J in Cumulative_Restrictions.Count'Range loop
3377 Set_Int (Int (Cumulative_Restrictions.Count (J)));
3381 Set_String_Replace ("},");
3382 Write_Statement_Buffer;
3385 for J in Cumulative_Restrictions.Unknown'Range loop
3386 Set_Int (Boolean'Pos (Cumulative_Restrictions.Unknown (J)));
3390 Set_String_Replace ("}}");
3392 Write_Statement_Buffer;
3393 WBI (" system__restrictions__run_time_restrictions = r;");
3394 end Gen_Restrictions_C;
3396 ----------------------
3397 -- Gen_Versions_Ada --
3398 ----------------------
3400 -- This routine generates lines such as:
3402 -- unnnnn : constant Integer := 16#hhhhhhhh#;
3403 -- pragma Export (C, unnnnn, unam);
3405 -- for each unit, where unam is the unit name suffixed by either B or S for
3406 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
3407 -- the version number, and nnnnn is a 5-digits serial number.
3409 procedure Gen_Versions_Ada is
3410 Ubuf : String (1 .. 6) := "u00000";
3412 procedure Increment_Ubuf;
3413 -- Little procedure to increment the serial number
3415 --------------------
3416 -- Increment_Ubuf --
3417 --------------------
3419 procedure Increment_Ubuf is
3421 for J in reverse Ubuf'Range loop
3422 Ubuf (J) := Character'Succ (Ubuf (J));
3423 exit when Ubuf (J) <= '9';
3428 -- Start of processing for Gen_Versions_Ada
3433 WBI (" type Version_32 is mod 2 ** 32;");
3434 for U in Units.First .. Units.Last loop
3435 if not Units.Table (U).SAL_Interface and then
3436 ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
3439 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
3440 Units.Table (U).Version & "#;");
3441 Set_String (" pragma Export (C, ");
3443 Set_String (", """);
3445 Get_Name_String (Units.Table (U).Uname);
3447 for K in 1 .. Name_Len loop
3448 if Name_Buffer (K) = '.' then
3452 elsif Name_Buffer (K) = '%' then
3456 Set_Char (Name_Buffer (K));
3460 if Name_Buffer (Name_Len) = 's' then
3466 Set_String (""");");
3467 Write_Statement_Buffer;
3470 end Gen_Versions_Ada;
3472 --------------------
3473 -- Gen_Versions_C --
3474 --------------------
3476 -- This routine generates a line of the form:
3478 -- unsigned unam = 0xhhhhhhhh;
3480 -- for each unit, where unam is the unit name suffixed by either B or S for
3481 -- body or spec, with dots replaced by double underscores.
3483 procedure Gen_Versions_C is
3485 for U in Units.First .. Units.Last loop
3486 if not Units.Table (U).SAL_Interface and then
3487 ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
3489 Set_String ("unsigned ");
3491 Get_Name_String (Units.Table (U).Uname);
3493 for K in 1 .. Name_Len loop
3494 if Name_Buffer (K) = '.' then
3497 elsif Name_Buffer (K) = '%' then
3501 Set_Char (Name_Buffer (K));
3505 if Name_Buffer (Name_Len) = 's' then
3511 Set_String (" = 0x");
3512 Set_String (Units.Table (U).Version);
3514 Write_Statement_Buffer;
3519 ------------------------
3520 -- Get_Main_Unit_Name --
3521 ------------------------
3523 function Get_Main_Unit_Name (S : String) return String is
3524 Result : String := S;
3527 for J in S'Range loop
3528 if Result (J) = '.' then
3534 end Get_Main_Unit_Name;
3536 -----------------------
3537 -- Get_Ada_Main_Name --
3538 -----------------------
3540 function Get_Ada_Main_Name return String is
3541 Suffix : constant String := "_00";
3542 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
3543 Opt.Ada_Main_Name.all & Suffix;
3547 -- The main program generated by JGNAT expects a package called
3548 -- ada_<main procedure>.
3550 if VM_Target /= No_VM then
3551 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3552 return "ada_" & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
3555 -- This loop tries the following possibilities in order
3561 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
3562 -- it is set to 'ada_main'.
3564 for J in 0 .. 99 loop
3566 Nlen := Name'Length - Suffix'Length;
3568 Nlen := Name'Length;
3569 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
3570 Name (Name'Last - 1) :=
3571 Character'Val (J / 10 + Character'Pos ('0'));
3574 for K in ALIs.First .. ALIs.Last loop
3575 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
3577 -- Get unit name, removing %b or %e at end
3579 Get_Name_String (Units.Table (L).Uname);
3580 Name_Len := Name_Len - 2;
3582 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
3588 return Name (1 .. Nlen);
3594 -- If we fall through, just use a peculiar unlikely name
3596 return ("Qwertyuiop");
3597 end Get_Ada_Main_Name;
3603 function Get_Main_Name return String is
3605 -- Explicit name given with -M switch
3607 if Bind_Alternate_Main_Name then
3608 return Alternate_Main_Name.all;
3610 -- Case of main program name to be used directly
3612 elsif Use_Ada_Main_Program_Name_On_Target then
3614 -- Get main program name
3616 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
3618 -- If this is a child name, return only the name of the child, since
3619 -- we can't have dots in a nested program name. Note that we do not
3620 -- include the %b at the end of the unit name.
3622 for J in reverse 1 .. Name_Len - 2 loop
3623 if J = 1 or else Name_Buffer (J - 1) = '.' then
3624 return Name_Buffer (J .. Name_Len - 2);
3628 raise Program_Error; -- impossible exit
3630 -- Case where "main" is to be used as default
3637 ---------------------
3638 -- Get_WC_Encoding --
3639 ---------------------
3641 function Get_WC_Encoding return Character is
3643 -- If encoding method specified by -W switch, then return it
3645 if Wide_Character_Encoding_Method_Specified then
3646 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
3648 -- If no main program, and not specified, set brackets, we really have
3649 -- no better choice. If some other encoding is required when there is
3650 -- no main, it must be set explicitly using -Wx.
3652 -- Note: if the ALI file always passed the wide character encoding of
3653 -- every file, then we could use the encoding of the initial specified
3654 -- file, but this information is passed only for potential main
3655 -- programs. We could fix this sometime, but it is a very minor point
3656 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
3657 -- is no main program).
3659 elsif No_Main_Subprogram then
3662 -- Otherwise if there is a main program, take encoding from it
3665 return ALIs.Table (ALIs.First).WC_Encoding;
3667 end Get_WC_Encoding;
3673 function Has_Finalizer return Boolean is
3678 for E in reverse Elab_Order.First .. Elab_Order.Last loop
3679 Unum := Elab_Order.Table (E);
3680 U := Units.Table (Unum);
3682 -- We are only interested in non-generic packages
3684 if U.Unit_Kind = 'p'
3685 and then U.Has_Finalizer
3686 and then not U.Is_Generic
3687 and then not U.No_Elab
3696 ----------------------
3697 -- Lt_Linker_Option --
3698 ----------------------
3700 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
3702 -- Sort internal files last
3704 if Linker_Options.Table (Op1).Internal_File
3706 Linker_Options.Table (Op2).Internal_File
3708 -- Note: following test uses False < True
3710 return Linker_Options.Table (Op1).Internal_File
3712 Linker_Options.Table (Op2).Internal_File;
3714 -- If both internal or both non-internal, sort according to the
3715 -- elaboration position. A unit that is elaborated later should come
3716 -- earlier in the linker options list.
3719 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
3721 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
3724 end Lt_Linker_Option;
3726 ------------------------
3727 -- Move_Linker_Option --
3728 ------------------------
3730 procedure Move_Linker_Option (From : Natural; To : Natural) is
3732 Linker_Options.Table (To) := Linker_Options.Table (From);
3733 end Move_Linker_Option;
3735 ----------------------------
3736 -- Resolve_Binder_Options --
3737 ----------------------------
3739 procedure Resolve_Binder_Options is
3741 for E in Elab_Order.First .. Elab_Order.Last loop
3742 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
3744 -- This is not a perfect approach, but is the current protocol
3745 -- between the run-time and the binder to indicate that tasking is
3746 -- used: system.os_interface should always be used by any tasking
3749 if Name_Buffer (1 .. 19) = "system.os_interface" then
3753 -- Ditto for declib and the "dec" package
3755 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
3756 With_DECGNAT := True;
3759 end Resolve_Binder_Options;
3765 procedure Set_Boolean (B : Boolean) is
3766 True_Str : constant String := "True";
3767 False_Str : constant String := "False";
3770 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
3771 Last := Last + True_Str'Length;
3773 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
3774 Last := Last + False_Str'Length;
3782 procedure Set_Char (C : Character) is
3785 Statement_Buffer (Last) := C;
3792 procedure Set_Int (N : Int) is
3804 Statement_Buffer (Last) :=
3805 Character'Val (N mod 10 + Character'Pos ('0'));
3809 -------------------------
3810 -- Set_IS_Pragma_Table --
3811 -------------------------
3813 procedure Set_IS_Pragma_Table is
3815 for F in ALIs.First .. ALIs.Last loop
3816 for K in ALIs.Table (F).First_Interrupt_State ..
3817 ALIs.Table (F).Last_Interrupt_State
3820 Inum : constant Int :=
3821 Interrupt_States.Table (K).Interrupt_Id;
3822 Stat : constant Character :=
3823 Interrupt_States.Table (K).Interrupt_State;
3826 while IS_Pragma_Settings.Last < Inum loop
3827 IS_Pragma_Settings.Append ('n');
3830 IS_Pragma_Settings.Table (Inum) := Stat;
3834 end Set_IS_Pragma_Table;
3836 ---------------------------
3837 -- Set_Main_Program_Name --
3838 ---------------------------
3840 procedure Set_Main_Program_Name is
3842 -- Note that name has %b on the end which we ignore
3844 -- First we output the initial _ada_ since we know that the main
3845 -- program is a library level subprogram.
3847 Set_String ("_ada_");
3849 -- Copy name, changing dots to double underscores
3851 for J in 1 .. Name_Len - 2 loop
3852 if Name_Buffer (J) = '.' then
3855 Set_Char (Name_Buffer (J));
3858 end Set_Main_Program_Name;
3860 ---------------------
3861 -- Set_Name_Buffer --
3862 ---------------------
3864 procedure Set_Name_Buffer is
3866 for J in 1 .. Name_Len loop
3867 Set_Char (Name_Buffer (J));
3869 end Set_Name_Buffer;
3871 -------------------------
3872 -- Set_PSD_Pragma_Table --
3873 -------------------------
3875 procedure Set_PSD_Pragma_Table is
3877 for F in ALIs.First .. ALIs.Last loop
3878 for K in ALIs.Table (F).First_Specific_Dispatching ..
3879 ALIs.Table (F).Last_Specific_Dispatching
3882 DTK : Specific_Dispatching_Record
3883 renames Specific_Dispatching.Table (K);
3886 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
3887 PSD_Pragma_Settings.Append ('F');
3890 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
3891 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
3896 end Set_PSD_Pragma_Table;
3902 procedure Set_String (S : String) is
3904 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
3905 Last := Last + S'Length;
3908 ------------------------
3909 -- Set_String_Replace --
3910 ------------------------
3912 procedure Set_String_Replace (S : String) is
3914 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
3915 end Set_String_Replace;
3921 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores) is
3923 for J in 1 .. Name_Len - 2 loop
3924 if Name_Buffer (J) = '.' then
3925 if Mode = Double_Underscores then
3927 elsif Mode = Dot then
3933 Set_Char (Name_Buffer (J));
3938 ---------------------
3939 -- Set_Unit_Number --
3940 ---------------------
3942 procedure Set_Unit_Number (U : Unit_Id) is
3943 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
3944 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
3947 if Num_Units >= 10 and then Unum < 10 then
3951 if Num_Units >= 100 and then Unum < 100 then
3956 end Set_Unit_Number;
3958 ----------------------
3959 -- Write_Info_Ada_C --
3960 ----------------------
3962 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String) is
3964 if Ada_Bind_File then
3966 S : String (1 .. Ada'Length + Common'Length);
3968 S (1 .. Ada'Length) := Ada;
3969 S (Ada'Length + 1 .. S'Length) := Common;
3975 S : String (1 .. C'Length + Common'Length);
3977 S (1 .. C'Length) := C;
3978 S (C'Length + 1 .. S'Length) := Common;
3982 end Write_Info_Ada_C;
3984 ----------------------------
3985 -- Write_Statement_Buffer --
3986 ----------------------------
3988 procedure Write_Statement_Buffer is
3990 WBI (Statement_Buffer (1 .. Last));
3992 end Write_Statement_Buffer;
3994 procedure Write_Statement_Buffer (S : String) is
3997 Write_Statement_Buffer;
3998 end Write_Statement_Buffer;