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;
75 -- Flag indicating whether the finalize_library rountine has been built
77 CodePeer_Wrapper_Name : constant String := "call_main_subprogram";
78 -- For CodePeer, introduce a wrapper subprogram which calls the
79 -- user-defined main subprogram.
81 ----------------------------------
82 -- Interface_State Pragma Table --
83 ----------------------------------
85 -- This table assembles the interface state pragma information from
86 -- all the units in the partition. Note that Bcheck has already checked
87 -- that the information is consistent across units. The entries
88 -- in this table are n/u/r/s for not set/user/runtime/system.
90 package IS_Pragma_Settings is new Table.Table (
91 Table_Component_Type => Character,
92 Table_Index_Type => Int,
95 Table_Increment => 200,
96 Table_Name => "IS_Pragma_Settings");
98 -- This table assembles the Priority_Specific_Dispatching pragma
99 -- information from all the units in the partition. Note that Bcheck has
100 -- already checked that the information is consistent across units.
101 -- The entries in this table are the upper case first character of the
102 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
104 package PSD_Pragma_Settings is new Table.Table (
105 Table_Component_Type => Character,
106 Table_Index_Type => Int,
107 Table_Low_Bound => 0,
108 Table_Initial => 100,
109 Table_Increment => 200,
110 Table_Name => "PSD_Pragma_Settings");
112 ----------------------
113 -- Run-Time Globals --
114 ----------------------
116 -- This section documents the global variables that set from the
117 -- generated binder file.
119 -- Main_Priority : Integer;
120 -- Time_Slice_Value : Integer;
121 -- Heap_Size : Natural;
122 -- WC_Encoding : Character;
123 -- Locking_Policy : Character;
124 -- Queuing_Policy : Character;
125 -- Task_Dispatching_Policy : Character;
126 -- Priority_Specific_Dispatching : System.Address;
127 -- Num_Specific_Dispatching : Integer;
128 -- Restrictions : System.Address;
129 -- Interrupt_States : System.Address;
130 -- Num_Interrupt_States : Integer;
131 -- Unreserve_All_Interrupts : Integer;
132 -- Exception_Tracebacks : Integer;
133 -- Zero_Cost_Exceptions : Integer;
134 -- Detect_Blocking : Integer;
135 -- Default_Stack_Size : Integer;
136 -- Leap_Seconds_Support : Integer;
137 -- Main_CPU : Integer;
139 -- Main_Priority is the priority value set by pragma Priority in the main
140 -- program. If no such pragma is present, the value is -1.
142 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
143 -- main program, or by the use of a -Tnnn parameter for the binder (if both
144 -- are present, the binder value overrides). The value is in milliseconds.
145 -- A value of zero indicates that time slicing should be suppressed. If no
146 -- pragma is present, and no -T switch was used, the value is -1.
148 -- Heap_Size is the heap to use for memory allocations set by use of a
149 -- -Hnn parameter for the binder or by the GNAT$NO_MALLOC_64 logical.
150 -- Valid values are 32 and 64. This switch is only effective on VMS.
152 -- WC_Encoding shows the wide character encoding method used for the main
153 -- program. This is one of the encoding letters defined in
154 -- System.WCh_Con.WC_Encoding_Letters.
156 -- Locking_Policy is a space if no locking policy was specified for the
157 -- partition. If a locking policy was specified, the value is the upper
158 -- case first character of the locking policy name, for example, 'C' for
161 -- Queuing_Policy is a space if no queuing policy was specified for the
162 -- partition. If a queuing policy was specified, the value is the upper
163 -- case first character of the queuing policy name for example, 'F' for
166 -- Task_Dispatching_Policy is a space if no task dispatching policy was
167 -- specified for the partition. If a task dispatching policy was specified,
168 -- the value is the upper case first character of the policy name, e.g. 'F'
169 -- for FIFO_Within_Priorities.
171 -- Priority_Specific_Dispatching is the address of a string used to store
172 -- the task dispatching policy specified for the different priorities in
173 -- the partition. The length of this string is determined by the last
174 -- priority for which such a pragma applies (the string will be a null
175 -- string if no specific dispatching policies were used). If pragma were
176 -- present, the entries apply to the priorities in sequence from the first
177 -- priority. The value stored is the upper case first character of the
178 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
179 -- for those priority ranges not specified.
181 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
182 -- string. It will be set to zero if no Priority_Specific_Dispatching
183 -- pragmas are present.
185 -- Restrictions is the address of a null-terminated string specifying the
186 -- restrictions information for the partition. The format is identical to
187 -- that of the parameter string found on R lines in ali files (see Lib.Writ
188 -- spec in lib-writ.ads for full details). The difference is that in this
189 -- context the values are the cumulative ones for the entire partition.
191 -- Interrupt_States is the address of a string used to specify the
192 -- cumulative results of Interrupt_State pragmas used in the partition.
193 -- The length of this string is determined by the last interrupt for which
194 -- such a pragma is given (the string will be a null string if no pragmas
195 -- were used). If pragma were present the entries apply to the interrupts
196 -- in sequence from the first interrupt, and are set to one of four
197 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
198 -- time, 's' for system, see description of Interrupt_State pragma for
201 -- Num_Interrupt_States is the length of the Interrupt_States string. It
202 -- will be set to zero if no Interrupt_State pragmas are present.
204 -- Unreserve_All_Interrupts is set to one if at least one unit in the
205 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
207 -- Exception_Tracebacks is set to one if the -E parameter was present
208 -- in the bind and to zero otherwise. Note that on some targets exception
209 -- tracebacks are provided by default, so a value of zero for this
210 -- parameter does not necessarily mean no trace backs are available.
212 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
213 -- this partition, and to zero if longjmp/setjmp exceptions are used.
215 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
216 -- not. A value of zero indicates that the pragma is not present, while a
217 -- value of 1 signals its presence in the partition.
219 -- Default_Stack_Size is the default stack size used when creating an Ada
220 -- task with no explicit Storage_Size clause.
222 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
223 -- disabled. A value of zero indicates that leap seconds are turned "off",
224 -- while a value of one signifies "on" status.
226 -- Main_CPU is the processor set by pragma CPU in the main program. If no
227 -- such pragma is present, the value is -1.
229 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
230 -- Convenient shorthand used throughout
232 -----------------------
233 -- Local Subprograms --
234 -----------------------
236 procedure Check_System_Restrictions_Used;
237 -- Sets flag System_Restrictions_Used (Set to True if and only if the unit
238 -- System.Restrictions is present in the partition, otherwise False).
240 procedure Gen_Adainit;
241 -- Generates the Adainit procedure
243 procedure Gen_Adafinal;
244 -- Generate the Adafinal procedure
246 procedure Gen_CodePeer_Wrapper;
247 -- For CodePeer, generate wrapper which calls user-defined main subprogram
249 procedure Gen_Elab_Calls;
250 -- Generate sequence of elaboration calls
252 procedure Gen_Elab_Externals;
253 -- Generate sequence of external declarations for elaboration
255 procedure Gen_Elab_Order;
256 -- Generate comments showing elaboration order chosen
258 procedure Gen_Finalize_Library;
259 -- Generate a sequence of finalization calls to elaborated packages
262 -- Generate procedure main
264 procedure Gen_Object_Files_Options;
265 -- Output comments containing a list of the full names of the object
266 -- files to be linked and the list of linker options supplied by
267 -- Linker_Options pragmas in the source.
269 procedure Gen_Output_File_Ada (Filename : String);
270 -- Generate Ada output file
272 procedure Gen_Restrictions;
273 -- Generate initialization of restrictions variable
275 procedure Gen_Versions;
276 -- Output series of definitions for unit versions
278 function Get_Ada_Main_Name return String;
279 -- This function is used for the Ada main output to compute a usable name
280 -- for the generated main program. The normal main program name is
281 -- Ada_Main, but this won't work if the user has a unit with this name.
282 -- This function tries Ada_Main first, and if there is such a clash, then
283 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
285 function Get_Main_Unit_Name (S : String) return String;
286 -- Return the main unit name corresponding to S by replacing '.' with '_'
288 function Get_Main_Name return String;
289 -- This function is used in the main output case to compute the correct
290 -- external main program. It is "main" by default, unless the flag
291 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
292 -- of the Ada main name without the "_ada". This default can be overridden
293 -- explicitly using the -Mname binder switch.
295 function Get_WC_Encoding return Character;
296 -- Return wide character encoding method to set as WC_Encoding in output.
297 -- If -W has been used, returns the specified encoding, otherwise returns
298 -- the encoding method used for the main program source. If there is no
299 -- main program source (-z switch used), returns brackets ('b').
301 function Has_Finalizer return Boolean;
302 -- Determine whether the current unit has at least one library-level
305 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
306 -- Compare linker options, when sorting, first according to
307 -- Is_Internal_File (internal files come later) and then by
308 -- elaboration order position (latest to earliest).
310 procedure Move_Linker_Option (From : Natural; To : Natural);
311 -- Move routine for sorting linker options
313 procedure Resolve_Binder_Options;
314 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
315 -- since it tests for a package named "dec" which might cause a conflict
316 -- on non-VMS systems.
318 procedure Set_Char (C : Character);
319 -- Set given character in Statement_Buffer at the Last + 1 position
320 -- and increment Last by one to reflect the stored character.
322 procedure Set_Int (N : Int);
323 -- Set given value in decimal in Statement_Buffer with no spaces
324 -- starting at the Last + 1 position, and updating Last past the value.
325 -- A minus sign is output for a negative value.
327 procedure Set_Boolean (B : Boolean);
328 -- Set given boolean value in Statement_Buffer at the Last + 1 position
329 -- and update Last past the value.
331 procedure Set_IS_Pragma_Table;
332 -- Initializes contents of IS_Pragma_Settings table from ALI table
334 procedure Set_Main_Program_Name;
335 -- Given the main program name in Name_Buffer (length in Name_Len)
336 -- generate the name of the routine to be used in the call. The name
337 -- is generated starting at Last + 1, and Last is updated past it.
339 procedure Set_Name_Buffer;
340 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
342 procedure Set_PSD_Pragma_Table;
343 -- Initializes contents of PSD_Pragma_Settings table from ALI table
345 procedure Set_String (S : String);
346 -- Sets characters of given string in Statement_Buffer, starting at the
347 -- Last + 1 position, and updating last past the string value.
349 procedure Set_String_Replace (S : String);
350 -- Replaces the last S'Length characters in the Statement_Buffer with
351 -- the characters of S. The caller must ensure that these characters do
352 -- in fact exist in the Statement_Buffer.
354 type Qualification_Mode is (Dollar_Sign, Dot, Double_Underscores);
356 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores);
357 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
358 -- starting at the Last + 1 position and update Last past the value.
359 -- Depending on parameter Mode, a dot (.) can be qualified into double
360 -- underscores (__), a dollar sign ($) or left as is.
362 procedure Set_Unit_Number (U : Unit_Id);
363 -- Sets unit number (first unit is 1, leading zeroes output to line
364 -- up all output unit numbers nicely as required by the value, and
365 -- by the total number of units.
367 procedure Write_Statement_Buffer;
368 -- Write out contents of statement buffer up to Last, and reset Last to 0
370 procedure Write_Statement_Buffer (S : String);
371 -- First writes its argument (using Set_String (S)), then writes out the
372 -- contents of statement buffer up to Last, and reset Last to 0
374 ------------------------------------
375 -- Check_System_Restrictions_Used --
376 ------------------------------------
378 procedure Check_System_Restrictions_Used is
380 for J in Units.First .. Units.Last loop
381 if Get_Name_String (Units.Table (J).Sfile) = "s-restri.ads" then
382 System_Restrictions_Used := True;
387 System_Restrictions_Used := False;
388 end Check_System_Restrictions_Used;
394 procedure Gen_Adafinal is
396 WBI (" procedure " & Ada_Final_Name.all & " is");
399 and Bind_Main_Program
400 and not CodePeer_Mode
402 WBI (" procedure s_stalib_adafinal;");
403 Set_String (" pragma Import (C, s_stalib_adafinal, ");
404 Set_String ("""system__standard_library__adafinal"");");
405 Write_Statement_Buffer;
410 if not CodePeer_Mode then
411 WBI (" if not Is_Elaborated then");
414 WBI (" Is_Elaborated := False;");
417 -- On non-virtual machine targets, finalization is done differently
418 -- depending on whether this is the main program or a library.
420 if VM_Target = No_VM and then not CodePeer_Mode then
421 if Bind_Main_Program then
422 WBI (" s_stalib_adafinal;");
423 elsif Lib_Final_Built then
424 WBI (" finalize_library;");
429 -- Pragma Import C cannot be used on virtual machine targets, therefore
430 -- call the runtime finalization routine directly. Similarly in CodePeer
431 -- mode, where imported functions are ignored.
434 WBI (" System.Standard_Library.Adafinal;");
437 WBI (" end " & Ada_Final_Name.all & ";");
445 procedure Gen_Adainit is
446 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
447 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
450 -- Declare the access-to-subprogram type used for initialization of
451 -- of __gnat_finalize_library_objects. This is declared at library
452 -- level for compatibility with the type used in System.Soft_Links.
453 -- The import of the soft link which performs library-level object
454 -- finalization is not needed for VM targets; regular Ada is used in
455 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
456 -- tasks are non-terminating, so we do not want finalization.
458 if not Suppress_Standard_Library_On_Target
459 and then VM_Target = No_VM
460 and then not CodePeer_Mode
461 and then not Configurable_Run_Time_On_Target
463 WBI (" type No_Param_Proc is access procedure;");
467 WBI (" procedure " & Ada_Init_Name.all & " is");
469 -- In CodePeer mode, simplify adainit procedure by only calling
470 -- elaboration procedures.
472 if CodePeer_Mode then
475 -- If the standard library is suppressed, then the only global variables
476 -- that might be needed (by the Ravenscar profile) are the priority and
477 -- the processor for the environment task.
479 elsif Suppress_Standard_Library_On_Target then
480 if Main_Priority /= No_Main_Priority then
481 WBI (" Main_Priority : Integer;");
482 WBI (" pragma Import (C, Main_Priority," &
483 " ""__gl_main_priority"");");
487 if Main_CPU /= No_Main_CPU then
488 WBI (" Main_CPU : Integer;");
489 WBI (" pragma Import (C, Main_CPU," &
490 " ""__gl_main_cpu"");");
496 if Main_Priority /= No_Main_Priority then
497 Set_String (" Main_Priority := ");
498 Set_Int (Main_Priority);
500 Write_Statement_Buffer;
503 if Main_CPU /= No_Main_CPU then
504 Set_String (" Main_CPU := ");
507 Write_Statement_Buffer;
510 if Main_Priority = No_Main_Priority
511 and then Main_CPU = No_Main_CPU
516 -- Normal case (standard library not suppressed). Set all global values
517 -- used by the run time.
520 WBI (" Main_Priority : Integer;");
521 WBI (" pragma Import (C, Main_Priority, " &
522 """__gl_main_priority"");");
523 WBI (" Time_Slice_Value : Integer;");
524 WBI (" pragma Import (C, Time_Slice_Value, " &
525 """__gl_time_slice_val"");");
526 WBI (" WC_Encoding : Character;");
527 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
528 WBI (" Locking_Policy : Character;");
529 WBI (" pragma Import (C, Locking_Policy, " &
530 """__gl_locking_policy"");");
531 WBI (" Queuing_Policy : Character;");
532 WBI (" pragma Import (C, Queuing_Policy, " &
533 """__gl_queuing_policy"");");
534 WBI (" Task_Dispatching_Policy : Character;");
535 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
536 """__gl_task_dispatching_policy"");");
537 WBI (" Priority_Specific_Dispatching : System.Address;");
538 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
539 """__gl_priority_specific_dispatching"");");
540 WBI (" Num_Specific_Dispatching : Integer;");
541 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
542 """__gl_num_specific_dispatching"");");
543 WBI (" Main_CPU : Integer;");
544 WBI (" pragma Import (C, Main_CPU, " &
545 """__gl_main_cpu"");");
547 WBI (" Interrupt_States : System.Address;");
548 WBI (" pragma Import (C, Interrupt_States, " &
549 """__gl_interrupt_states"");");
550 WBI (" Num_Interrupt_States : Integer;");
551 WBI (" pragma Import (C, Num_Interrupt_States, " &
552 """__gl_num_interrupt_states"");");
553 WBI (" Unreserve_All_Interrupts : Integer;");
554 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
555 """__gl_unreserve_all_interrupts"");");
557 if Exception_Tracebacks then
558 WBI (" Exception_Tracebacks : Integer;");
559 WBI (" pragma Import (C, Exception_Tracebacks, " &
560 """__gl_exception_tracebacks"");");
563 WBI (" Zero_Cost_Exceptions : Integer;");
564 WBI (" pragma Import (C, Zero_Cost_Exceptions, " &
565 """__gl_zero_cost_exceptions"");");
566 WBI (" Detect_Blocking : Integer;");
567 WBI (" pragma Import (C, Detect_Blocking, " &
568 """__gl_detect_blocking"");");
569 WBI (" Default_Stack_Size : Integer;");
570 WBI (" pragma Import (C, Default_Stack_Size, " &
571 """__gl_default_stack_size"");");
572 WBI (" Leap_Seconds_Support : Integer;");
573 WBI (" pragma Import (C, Leap_Seconds_Support, " &
574 """__gl_leap_seconds_support"");");
576 -- Import entry point for elaboration time signal handler
577 -- installation, and indication of if it's been called previously.
580 WBI (" procedure Install_Handler;");
581 WBI (" pragma Import (C, Install_Handler, " &
582 """__gnat_install_handler"");");
584 WBI (" Handler_Installed : Integer;");
585 WBI (" pragma Import (C, Handler_Installed, " &
586 """__gnat_handler_installed"");");
588 -- The import of the soft link which performs library-level object
589 -- finalization is not needed for VM targets; regular Ada is used in
590 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
591 -- tasks are non-terminating, so we do not want finalization.
593 if VM_Target = No_VM and then not Configurable_Run_Time_On_Target then
595 WBI (" Finalize_Library_Objects : No_Param_Proc;");
596 WBI (" pragma Import (C, Finalize_Library_Objects, " &
597 """__gnat_finalize_library_objects"");");
600 -- Import entry point for environment feature enable/disable
601 -- routine, and indication that it's been called previously.
603 if OpenVMS_On_Target then
605 WBI (" procedure Set_Features;");
606 WBI (" pragma Import (C, Set_Features, " &
607 """__gnat_set_features"");");
609 WBI (" Features_Set : Integer;");
610 WBI (" pragma Import (C, Features_Set, " &
611 """__gnat_features_set"");");
613 if Opt.Heap_Size /= 0 then
615 WBI (" Heap_Size : Integer;");
616 WBI (" pragma Import (C, Heap_Size, " &
617 """__gl_heap_size"");");
619 Write_Statement_Buffer;
623 -- Initialize stack limit variable of the environment task if the
624 -- stack check method is stack limit and stack check is enabled.
626 if Stack_Check_Limits_On_Target
627 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
630 WBI (" procedure Initialize_Stack_Limit;");
631 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
632 """__gnat_initialize_stack_limit"");");
635 -- Special processing when main program is CIL function/procedure
637 if VM_Target = CLI_Target
638 and then Bind_Main_Program
639 and then not No_Main_Subprogram
643 -- Function case, use Set_Exit_Status to report the returned
644 -- status code, since that is the only mechanism available.
646 if ALIs.Table (ALIs.First).Main_Program = Func then
647 WBI (" Result : Integer;");
648 WBI (" procedure Set_Exit_Status (Code : Integer);");
649 WBI (" pragma Import (C, Set_Exit_Status, " &
650 """__gnat_set_exit_status"");");
652 WBI (" function Ada_Main_Program return Integer;");
657 WBI (" procedure Ada_Main_Program;");
660 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
661 Name_Len := Name_Len - 2;
662 WBI (" pragma Import (CIL, Ada_Main_Program, """
663 & Name_Buffer (1 .. Name_Len) & "."
664 & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len)) & """);");
668 WBI (" if Is_Elaborated then");
671 WBI (" Is_Elaborated := True;");
673 Set_String (" Main_Priority := ");
674 Set_Int (Main_Priority);
676 Write_Statement_Buffer;
678 Set_String (" Time_Slice_Value := ");
680 if Task_Dispatching_Policy_Specified = 'F'
681 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
685 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
689 Write_Statement_Buffer;
691 Set_String (" WC_Encoding := '");
692 Set_Char (Get_WC_Encoding);
695 Write_Statement_Buffer;
697 Set_String (" Locking_Policy := '");
698 Set_Char (Locking_Policy_Specified);
700 Write_Statement_Buffer;
702 Set_String (" Queuing_Policy := '");
703 Set_Char (Queuing_Policy_Specified);
705 Write_Statement_Buffer;
707 Set_String (" Task_Dispatching_Policy := '");
708 Set_Char (Task_Dispatching_Policy_Specified);
710 Write_Statement_Buffer;
714 WBI (" Priority_Specific_Dispatching :=");
715 WBI (" Local_Priority_Specific_Dispatching'Address;");
717 Set_String (" Num_Specific_Dispatching := ");
718 Set_Int (PSD_Pragma_Settings.Last + 1);
720 Write_Statement_Buffer;
722 Set_String (" Main_CPU := ");
725 Write_Statement_Buffer;
727 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
729 Set_String (" Num_Interrupt_States := ");
730 Set_Int (IS_Pragma_Settings.Last + 1);
732 Write_Statement_Buffer;
734 Set_String (" Unreserve_All_Interrupts := ");
736 if Unreserve_All_Interrupts_Specified then
743 Write_Statement_Buffer;
745 if Exception_Tracebacks then
746 WBI (" Exception_Tracebacks := 1;");
749 Set_String (" Zero_Cost_Exceptions := ");
751 if Zero_Cost_Exceptions_Specified then
758 Write_Statement_Buffer;
760 Set_String (" Detect_Blocking := ");
762 if Detect_Blocking then
769 Write_Statement_Buffer;
771 Set_String (" Default_Stack_Size := ");
772 Set_Int (Default_Stack_Size);
774 Write_Statement_Buffer;
776 Set_String (" Leap_Seconds_Support := ");
778 if Leap_Seconds_Support then
785 Write_Statement_Buffer;
787 -- Generate call to Install_Handler
789 -- In .NET, when binding with -z, we don't install the signal handler
790 -- to let the caller handle the last exception handler.
792 if VM_Target /= CLI_Target
793 or else Bind_Main_Program
796 WBI (" if Handler_Installed = 0 then");
797 WBI (" Install_Handler;");
801 -- Generate call to Set_Features
803 if OpenVMS_On_Target then
805 WBI (" if Features_Set = 0 then");
806 WBI (" Set_Features;");
809 -- Features_Set may twiddle the heap size according to a logical
810 -- name, but the binder switch must override.
812 if Opt.Heap_Size /= 0 then
813 Set_String (" Heap_Size := ");
814 Set_Int (Opt.Heap_Size);
816 Write_Statement_Buffer;
821 -- Generate call to set Initialize_Scalar values if active
823 if Initialize_Scalars_Used then
825 Set_String (" System.Scalar_Values.Initialize ('");
826 Set_Char (Initialize_Scalars_Mode1);
828 Set_Char (Initialize_Scalars_Mode2);
830 Write_Statement_Buffer;
833 -- Generate assignment of default secondary stack size if set
835 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
837 Set_String (" System.Secondary_Stack.");
838 Set_String ("Default_Secondary_Stack_Size := ");
839 Set_Int (Opt.Default_Sec_Stack_Size);
841 Write_Statement_Buffer;
844 -- Initialize stack limit variable of the environment task if the
845 -- stack check method is stack limit and stack check is enabled.
847 if Stack_Check_Limits_On_Target
848 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
851 WBI (" Initialize_Stack_Limit;");
854 -- On CodePeer, the finalization of library objects is not relevant
856 if CodePeer_Mode then
859 -- On virtual machine targets, or on non-virtual machine ones if this
860 -- is the main program case, attach finalize_library to the soft link.
861 -- Do it only when not using a restricted run time, in which case tasks
862 -- are non-terminating, so we do not want library-level finalization.
864 elsif (VM_Target /= No_VM or else Bind_Main_Program)
865 and then not Configurable_Run_Time_On_Target
866 and then not Suppress_Standard_Library_On_Target
870 if VM_Target = No_VM then
871 if Lib_Final_Built then
872 Set_String (" Finalize_Library_Objects := ");
873 Set_String ("finalize_library'access;");
875 Set_String (" Finalize_Library_Objects := null;");
878 -- On VM targets use regular Ada to set the soft link
881 if Lib_Final_Built then
883 (" System.Soft_Links.Finalize_Library_Objects");
884 Set_String (" := finalize_library'access;");
887 (" System.Soft_Links.Finalize_Library_Objects");
888 Set_String (" := null;");
892 Write_Statement_Buffer;
895 -- Generate elaboration calls
897 if not CodePeer_Mode then
903 -- Case of main program is CIL function or procedure
905 if VM_Target = CLI_Target
906 and then Bind_Main_Program
907 and then not No_Main_Subprogram
909 -- For function case, use Set_Exit_Status to set result
911 if ALIs.Table (ALIs.First).Main_Program = Func then
912 WBI (" Result := Ada_Main_Program;");
913 WBI (" Set_Exit_Status (Result);");
918 WBI (" Ada_Main_Program;");
922 WBI (" end " & Ada_Init_Name.all & ";");
926 --------------------------
927 -- Gen_CodePeer_Wrapper --
928 --------------------------
930 procedure Gen_CodePeer_Wrapper is
931 Callee_Name : constant String := "Ada_Main_Program";
934 if ALIs.Table (ALIs.First).Main_Program = Proc then
935 WBI (" procedure " & CodePeer_Wrapper_Name & " is ");
937 WBI (" " & Callee_Name & ";");
940 WBI (" function " & CodePeer_Wrapper_Name & " return Integer is");
942 WBI (" return " & Callee_Name & ";");
945 WBI (" end " & CodePeer_Wrapper_Name & ";");
947 end Gen_CodePeer_Wrapper;
953 procedure Gen_Elab_Calls is
954 Check_Elab_Flag : Boolean;
957 for E in Elab_Order.First .. Elab_Order.Last loop
959 Unum : constant Unit_Id := Elab_Order.Table (E);
960 U : Unit_Record renames Units.Table (Unum);
963 -- This is the unit number of the spec that corresponds to
964 -- this entry. It is the same as Unum except when the body
965 -- and spec are different and we are currently processing
966 -- the body, in which case it is the spec (Unum + 1).
969 if U.Utype = Is_Body then
970 Unum_Spec := Unum + 1;
975 -- Nothing to do if predefined unit in no run time mode
977 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
980 -- Likewise if this is an interface to a stand alone library
982 elsif U.SAL_Interface then
985 -- Case of no elaboration code
989 -- The only case in which we have to do something is if this
990 -- is a body, with a separate spec, where the separate spec
991 -- has an elaboration entity defined. In that case, this is
992 -- where we increment the elaboration entity.
995 and then Units.Table (Unum_Spec).Set_Elab_Entity
996 and then not CodePeer_Mode
999 Set_Unit_Number (Unum_Spec);
1000 Set_String (" := E");
1001 Set_Unit_Number (Unum_Spec);
1002 Set_String (" + 1;");
1003 Write_Statement_Buffer;
1006 -- Here if elaboration code is present. If binding a library
1007 -- or if there is a non-Ada main subprogram then we generate:
1009 -- if uname_E = 0 then
1010 -- uname'elab_[spec|body];
1012 -- uname_E := uname_E + 1;
1014 -- Otherwise, elaboration routines are called unconditionally:
1016 -- uname'elab_[spec|body];
1017 -- uname_E := uname_E + 1;
1019 -- The uname_E increment is skipped if this is a separate spec,
1020 -- since it will be done when we process the body.
1022 -- Ignore subprograms in CodePeer mode, since no useful
1023 -- elaboration subprogram is needed by CodePeer.
1025 elsif U.Unit_Kind /= 's' or else not CodePeer_Mode then
1028 and then (Force_Checking_Of_Elaboration_Flags
1029 or Interface_Library_Unit
1030 or not Bind_Main_Program);
1032 if Check_Elab_Flag then
1033 Set_String (" if E");
1034 Set_Unit_Number (Unum_Spec);
1035 Set_String (" = 0 then");
1036 Write_Statement_Buffer;
1041 Get_Decoded_Name_String_With_Brackets (U.Uname);
1043 if VM_Target = CLI_Target and then U.Unit_Kind /= 's' then
1044 if Name_Buffer (Name_Len) = 's' then
1045 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1048 Name_Buffer (Name_Len - 1 .. Name_Len + 12) :=
1052 Name_Len := Name_Len + 12;
1055 if Name_Buffer (Name_Len) = 's' then
1056 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1059 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1063 Name_Len := Name_Len + 8;
1066 Set_Casing (U.Icasing);
1069 Write_Statement_Buffer;
1071 if Check_Elab_Flag then
1075 if U.Utype /= Is_Spec
1076 and then not CodePeer_Mode
1079 Set_Unit_Number (Unum_Spec);
1080 Set_String (" := E");
1081 Set_Unit_Number (Unum_Spec);
1082 Set_String (" + 1;");
1083 Write_Statement_Buffer;
1090 ------------------------
1091 -- Gen_Elab_Externals --
1092 ------------------------
1094 procedure Gen_Elab_Externals is
1096 if CodePeer_Mode then
1100 for E in Elab_Order.First .. Elab_Order.Last loop
1102 Unum : constant Unit_Id := Elab_Order.Table (E);
1103 U : Unit_Record renames Units.Table (Unum);
1106 -- Check for Elab_Entity to be set for this unit
1108 if U.Set_Elab_Entity
1110 -- Don't generate reference for stand alone library
1112 and then not U.SAL_Interface
1114 -- Don't generate reference for predefined file in No_Run_Time
1115 -- mode, since we don't include the object files in this case
1119 and then Is_Predefined_File_Name (U.Sfile))
1123 Set_Unit_Number (Unum);
1126 when No_VM | JVM_Target =>
1127 Set_String (" : Short_Integer; pragma Import (Ada, ");
1129 Set_String (" : Short_Integer; pragma Import (CIL, ");
1133 Set_Unit_Number (Unum);
1134 Set_String (", """);
1135 Get_Name_String (U.Uname);
1137 -- In the case of JGNAT we need to emit an Import name that
1138 -- includes the class name (using '$' separators in the case
1139 -- of a child unit name).
1141 if VM_Target /= No_VM then
1142 for J in 1 .. Name_Len - 2 loop
1143 if VM_Target = CLI_Target
1144 or else Name_Buffer (J) /= '.'
1146 Set_Char (Name_Buffer (J));
1152 if VM_Target /= CLI_Target or else U.Unit_Kind = 's' then
1155 Set_String ("_pkg.");
1158 -- If the unit name is very long, then split the
1159 -- Import link name across lines using "&" (occurs
1160 -- in some C2 tests).
1162 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
1163 Set_String (""" &");
1164 Write_Statement_Buffer;
1170 Set_String ("_E"");");
1171 Write_Statement_Buffer;
1177 end Gen_Elab_Externals;
1179 --------------------
1180 -- Gen_Elab_Order --
1181 --------------------
1183 procedure Gen_Elab_Order is
1185 WBI (" -- BEGIN ELABORATION ORDER");
1187 for J in Elab_Order.First .. Elab_Order.Last loop
1188 Set_String (" -- ");
1189 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1191 Write_Statement_Buffer;
1194 WBI (" -- END ELABORATION ORDER");
1198 --------------------------
1199 -- Gen_Finalize_Library --
1200 --------------------------
1202 procedure Gen_Finalize_Library is
1205 Uspec : Unit_Record;
1208 procedure Gen_Header;
1209 -- Generate the header of the finalization routine
1215 procedure Gen_Header is
1217 WBI (" procedure finalize_library is");
1219 -- The following flag is used to check for library-level exceptions
1220 -- raised during finalization. Symbol comes from System.Soft_Links.
1221 -- VM targets use regular Ada to reference the entity.
1223 if VM_Target = No_VM then
1224 WBI (" LE_Set : Boolean;");
1226 Set_String (" pragma Import (Ada, LE_Set, ");
1227 Set_String ("""__gnat_library_exception_set"");");
1228 Write_Statement_Buffer;
1234 -- Start of processing for Gen_Finalize_Library
1237 if CodePeer_Mode then
1241 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1242 Unum := Elab_Order.Table (E);
1243 U := Units.Table (Unum);
1245 -- Dealing with package bodies is a little complicated. In such
1246 -- cases we must retrieve the package spec since it contains the
1247 -- spec of the body finalizer.
1249 if U.Utype = Is_Body then
1251 Uspec := Units.Table (Unum);
1256 Get_Name_String (Uspec.Uname);
1258 -- We are only interested in non-generic packages
1260 if U.Unit_Kind /= 'p' or else U.Is_Generic then
1263 -- That aren't an interface to a stand alone library
1265 elsif U.SAL_Interface then
1268 -- Case of no finalization
1270 elsif not U.Has_Finalizer then
1272 -- The only case in which we have to do something is if this
1273 -- is a body, with a separate spec, where the separate spec
1274 -- has a finalizer. In that case, this is where we decrement
1275 -- the elaboration entity.
1277 if U.Utype = Is_Body and then Uspec.Has_Finalizer then
1278 if not Lib_Final_Built then
1280 Lib_Final_Built := True;
1284 Set_Unit_Number (Unum);
1285 Set_String (" := E");
1286 Set_Unit_Number (Unum);
1287 Set_String (" - 1;");
1288 Write_Statement_Buffer;
1292 if not Lib_Final_Built then
1294 Lib_Final_Built := True;
1299 -- procedure F<Count>;
1301 Set_String (" declare");
1302 Write_Statement_Buffer;
1304 Set_String (" procedure F");
1307 Write_Statement_Buffer;
1310 -- pragma Import (CIL, F<Count>,
1311 -- "xx.yy_pkg.xx__yy__finalize_[body|spec]");
1312 -- -- for .NET targets
1314 -- pragma Import (Java, F<Count>,
1315 -- "xx$yy.xx__yy__finalize_[body|spec]");
1316 -- -- for JVM targets
1318 -- pragma Import (Ada, F<Count>,
1319 -- "xx__yy__finalize_[body|spec]");
1320 -- -- for default targets
1322 if VM_Target = CLI_Target then
1323 Set_String (" pragma Import (CIL, F");
1324 elsif VM_Target = JVM_Target then
1325 Set_String (" pragma Import (Java, F");
1327 Set_String (" pragma Import (Ada, F");
1331 Set_String (", """);
1333 -- Perform name construction
1335 -- .NET xx.yy_pkg.xx__yy__finalize
1337 if VM_Target = CLI_Target then
1338 Set_Unit_Name (Mode => Dot);
1339 Set_String ("_pkg.");
1341 -- JVM xx$yy.xx__yy__finalize
1343 elsif VM_Target = JVM_Target then
1344 Set_Unit_Name (Mode => Dollar_Sign);
1348 -- Default xx__yy__finalize
1351 Set_String ("__finalize_");
1353 -- Package spec processing
1355 if U.Utype = Is_Spec
1356 or else U.Utype = Is_Spec_Only
1358 Set_String ("spec");
1360 -- Package body processing
1363 Set_String ("body");
1366 Set_String (""");");
1367 Write_Statement_Buffer;
1369 -- If binding a library or if there is a non-Ada main subprogram
1370 -- then we generate:
1373 -- uname_E := uname_E - 1;
1374 -- if uname_E = 0 then
1379 -- Otherwise, finalization routines are called unconditionally:
1382 -- uname_E := uname_E - 1;
1386 -- The uname_E decrement is skipped if this is a separate spec,
1387 -- since it will be done when we process the body.
1391 if U.Utype /= Is_Spec then
1393 Set_Unit_Number (Unum);
1394 Set_String (" := E");
1395 Set_Unit_Number (Unum);
1396 Set_String (" - 1;");
1397 Write_Statement_Buffer;
1400 if Interface_Library_Unit or not Bind_Main_Program then
1401 Set_String (" if E");
1402 Set_Unit_Number (Unum);
1403 Set_String (" = 0 then");
1404 Write_Statement_Buffer;
1411 Write_Statement_Buffer;
1413 if Interface_Library_Unit or not Bind_Main_Program then
1423 if Lib_Final_Built then
1425 -- It is possible that the finalization of a library-level object
1426 -- raised an exception. In that case import the actual exception
1427 -- and the routine necessary to raise it.
1429 if VM_Target = No_VM then
1430 WBI (" if LE_Set then");
1432 WBI (" LE : Ada.Exceptions.Exception_Occurrence;");
1434 Set_String (" pragma Import (Ada, LE, ");
1435 Set_String ("""__gnat_library_exception"");");
1436 Write_Statement_Buffer;
1438 Set_String (" procedure Raise_From_Controlled_");
1439 Set_String ("Operation ");
1440 Set_String ("(X : Ada.Exceptions.Exception_Occurrence; ");
1441 Set_String (" From_Abort : Boolean);");
1442 Write_Statement_Buffer;
1444 Set_String (" pragma Import (Ada, Raise_From_");
1445 Set_String ("Controlled_Operation, ");
1446 Set_String ("""__gnat_raise_from_controlled_operation"");");
1447 Write_Statement_Buffer;
1450 WBI (" Raise_From_Controlled_Operation (LE, False);");
1453 -- VM-specific code, use regular Ada to produce the desired behavior
1456 WBI (" if System.Soft_Links.Library_Exception_Set then");
1458 Set_String (" Ada.Exceptions.Reraise_Occurrence (");
1459 Set_String ("System.Soft_Links.Library_Exception);");
1460 Write_Statement_Buffer;
1464 WBI (" end finalize_library;");
1467 end Gen_Finalize_Library;
1473 procedure Gen_Main is
1475 if not No_Main_Subprogram then
1477 -- To call the main program, we declare it using a pragma Import
1478 -- Ada with the right link name.
1480 -- It might seem more obvious to "with" the main program, and call
1481 -- it in the normal Ada manner. We do not do this for three
1484 -- 1. It is more efficient not to recompile the main program
1485 -- 2. We are not entitled to assume the source is accessible
1486 -- 3. We don't know what options to use to compile it
1488 -- It is really reason 3 that is most critical (indeed we used
1489 -- to generate the "with", but several regression tests failed).
1491 if ALIs.Table (ALIs.First).Main_Program = Func then
1492 WBI (" function Ada_Main_Program return Integer;");
1494 WBI (" procedure Ada_Main_Program;");
1497 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1498 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1499 Set_Main_Program_Name;
1500 Set_String (""");");
1502 Write_Statement_Buffer;
1505 -- For CodePeer, declare a wrapper for the user-defined main program
1507 if CodePeer_Mode then
1508 Gen_CodePeer_Wrapper;
1512 if Exit_Status_Supported_On_Target then
1513 Set_String (" function ");
1515 Set_String (" procedure ");
1518 Set_String (Get_Main_Name);
1520 if Command_Line_Args_On_Target then
1521 Write_Statement_Buffer;
1522 WBI (" (argc : Integer;");
1523 WBI (" argv : System.Address;");
1524 WBI (" envp : System.Address)");
1526 if Exit_Status_Supported_On_Target then
1527 WBI (" return Integer");
1533 if Exit_Status_Supported_On_Target then
1534 Set_String (" return Integer is");
1539 Write_Statement_Buffer;
1542 if Opt.Default_Exit_Status /= 0
1543 and then Bind_Main_Program
1544 and then not Configurable_Run_Time_Mode
1546 WBI (" procedure Set_Exit_Status (Status : Integer);");
1547 WBI (" pragma Import (C, Set_Exit_Status, " &
1548 """__gnat_set_exit_status"");");
1552 -- Initialize and Finalize
1554 if not CodePeer_Mode
1555 and then not Cumulative_Restrictions.Set (No_Finalization)
1557 WBI (" procedure Initialize (Addr : System.Address);");
1558 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1560 WBI (" procedure Finalize;");
1561 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1564 -- If we want to analyze the stack, we must import corresponding symbols
1566 if Dynamic_Stack_Measurement then
1568 WBI (" procedure Output_Results;");
1569 WBI (" pragma Import (C, Output_Results, " &
1570 """__gnat_stack_usage_output_results"");");
1574 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1575 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1576 """__gnat_stack_usage_initialize"");");
1579 -- Deal with declarations for main program case
1581 if not No_Main_Subprogram then
1582 if ALIs.Table (ALIs.First).Main_Program = Func then
1583 WBI (" Result : Integer;");
1587 if Bind_Main_Program
1588 and not Suppress_Standard_Library_On_Target
1589 and not CodePeer_Mode
1591 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1596 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1597 -- not referenced elsewhere in the generated program, but is needed
1598 -- by the debugger (that's why it is generated in the first place).
1599 -- The reference stops Ada_Main_Program_Name from being optimized
1600 -- away by smart linkers, such as the AiX linker.
1602 -- Because this variable is unused, we make this variable "aliased"
1603 -- with a pragma Volatile in order to tell the compiler to preserve
1604 -- this variable at any level of optimization.
1606 if Bind_Main_Program and not CodePeer_Mode then
1607 WBI (" Ensure_Reference : aliased System.Address := " &
1608 "Ada_Main_Program_Name'Address;");
1609 WBI (" pragma Volatile (Ensure_Reference);");
1615 -- Acquire command line arguments if present on target
1617 if CodePeer_Mode then
1620 elsif Command_Line_Args_On_Target then
1621 WBI (" gnat_argc := argc;");
1622 WBI (" gnat_argv := argv;");
1623 WBI (" gnat_envp := envp;");
1626 -- If configurable run time and no command line args, then nothing
1627 -- needs to be done since the gnat_argc/argv/envp variables are
1628 -- suppressed in this case.
1630 elsif Configurable_Run_Time_On_Target then
1633 -- Otherwise set dummy values (to be filled in by some other unit?)
1636 WBI (" gnat_argc := 0;");
1637 WBI (" gnat_argv := System.Null_Address;");
1638 WBI (" gnat_envp := System.Null_Address;");
1641 if Opt.Default_Exit_Status /= 0
1642 and then Bind_Main_Program
1643 and then not Configurable_Run_Time_Mode
1645 Set_String (" Set_Exit_Status (");
1646 Set_Int (Opt.Default_Exit_Status);
1648 Write_Statement_Buffer;
1651 if Dynamic_Stack_Measurement then
1652 Set_String (" Initialize_Stack_Analysis (");
1653 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1655 Write_Statement_Buffer;
1658 if not Cumulative_Restrictions.Set (No_Finalization)
1659 and then not CodePeer_Mode
1661 if not No_Main_Subprogram
1662 and then Bind_Main_Program
1663 and then not Suppress_Standard_Library_On_Target
1665 WBI (" Initialize (SEH'Address);");
1667 WBI (" Initialize (System.Null_Address);");
1671 WBI (" " & Ada_Init_Name.all & ";");
1673 if not No_Main_Subprogram then
1674 if CodePeer_Mode then
1675 if ALIs.Table (ALIs.First).Main_Program = Proc then
1676 WBI (" " & CodePeer_Wrapper_Name & ";");
1678 WBI (" Result := " & CodePeer_Wrapper_Name & ";");
1681 elsif ALIs.Table (ALIs.First).Main_Program = Proc then
1682 WBI (" Ada_Main_Program;");
1685 WBI (" Result := Ada_Main_Program;");
1689 -- Adafinal call is skipped if no finalization
1691 if not Cumulative_Restrictions.Set (No_Finalization) then
1695 -- Prints the result of static stack analysis
1697 if Dynamic_Stack_Measurement then
1698 WBI (" Output_Results;");
1701 -- Finalize is only called if we have a run time
1703 if not Cumulative_Restrictions.Set (No_Finalization)
1704 and then not CodePeer_Mode
1711 if Exit_Status_Supported_On_Target then
1712 if No_Main_Subprogram
1713 or else ALIs.Table (ALIs.First).Main_Program = Proc
1715 WBI (" return (gnat_exit_status);");
1717 WBI (" return (Result);");
1725 ------------------------------
1726 -- Gen_Object_Files_Options --
1727 ------------------------------
1729 procedure Gen_Object_Files_Options is
1731 -- This keeps track of the position in the sorted set of entries
1732 -- in the Linker_Options table of where the first entry from an
1733 -- internal file appears.
1735 Linker_Option_List_Started : Boolean := False;
1736 -- Set to True when "LINKER OPTION LIST" is displayed
1738 procedure Write_Linker_Option;
1739 -- Write binder info linker option
1741 -------------------------
1742 -- Write_Linker_Option --
1743 -------------------------
1745 procedure Write_Linker_Option is
1750 -- Loop through string, breaking at null's
1753 while Start < Name_Len loop
1755 -- Find null ending this section
1758 while Name_Buffer (Stop) /= ASCII.NUL
1759 and then Stop <= Name_Len loop
1763 -- Process section if non-null
1765 if Stop > Start then
1766 if Output_Linker_Option_List then
1767 if not Zero_Formatting then
1768 if not Linker_Option_List_Started then
1769 Linker_Option_List_Started := True;
1771 Write_Str (" LINKER OPTION LIST");
1779 Write_Str (Name_Buffer (Start .. Stop - 1));
1782 WBI (" -- " & Name_Buffer (Start .. Stop - 1));
1787 end Write_Linker_Option;
1789 -- Start of processing for Gen_Object_Files_Options
1792 WBI ("-- BEGIN Object file/option list");
1794 if Object_List_Filename /= null then
1795 Set_List_File (Object_List_Filename.all);
1798 for E in Elab_Order.First .. Elab_Order.Last loop
1800 -- If not spec that has an associated body, then generate a comment
1801 -- giving the name of the corresponding object file.
1803 if not Units.Table (Elab_Order.Table (E)).SAL_Interface
1804 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1808 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1810 -- If the presence of an object file is necessary or if it exists,
1813 if not Hostparm.Exclude_Missing_Objects
1815 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1817 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1819 if Output_Object_List then
1820 Write_Str (Name_Buffer (1 .. Name_Len));
1824 -- Don't link with the shared library on VMS if an internal
1825 -- filename object is seen. Multiply defined symbols will
1828 if OpenVMS_On_Target
1829 and then Is_Internal_File_Name
1831 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
1833 -- Special case for g-trasym.obj (not included in libgnat)
1835 Get_Name_String (ALIs.Table
1836 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
1838 if Name_Buffer (1 .. 8) /= "g-trasym" then
1839 Opt.Shared_Libgnat := False;
1846 if Object_List_Filename /= null then
1850 -- Add a "-Ldir" for each directory in the object path
1851 if VM_Target /= CLI_Target then
1852 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1854 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1857 Add_Str_To_Name_Buffer ("-L");
1858 Add_Str_To_Name_Buffer (Dir.all);
1859 Write_Linker_Option;
1864 -- Sort linker options
1866 -- This sort accomplishes two important purposes:
1868 -- a) All application files are sorted to the front, and all GNAT
1869 -- internal files are sorted to the end. This results in a well
1870 -- defined dividing line between the two sets of files, for the
1871 -- purpose of inserting certain standard library references into
1872 -- the linker arguments list.
1874 -- b) Given two different units, we sort the linker options so that
1875 -- those from a unit earlier in the elaboration order comes later
1876 -- in the list. This is a heuristic designed to create a more
1877 -- friendly order of linker options when the operations appear in
1878 -- separate units. The idea is that if unit A must be elaborated
1879 -- before unit B, then it is more likely that B references
1880 -- libraries included by A, than vice versa, so we want libraries
1881 -- included by A to come after libraries included by B.
1883 -- These two criteria are implemented by function Lt_Linker_Option. Note
1884 -- that a special case of b) is that specs are elaborated before bodies,
1885 -- so linker options from specs come after linker options for bodies,
1886 -- and again, the assumption is that libraries used by the body are more
1887 -- likely to reference libraries used by the spec, than vice versa.
1890 (Linker_Options.Last,
1891 Move_Linker_Option'Access,
1892 Lt_Linker_Option'Access);
1894 -- Write user linker options, i.e. the set of linker options that come
1895 -- from all files other than GNAT internal files, Lgnat is left set to
1896 -- point to the first entry from a GNAT internal file, or past the end
1897 -- of the entries if there are no internal files.
1899 Lgnat := Linker_Options.Last + 1;
1901 for J in 1 .. Linker_Options.Last loop
1902 if not Linker_Options.Table (J).Internal_File then
1903 Get_Name_String (Linker_Options.Table (J).Name);
1904 Write_Linker_Option;
1911 -- Now we insert standard linker options that must appear after the
1912 -- entries from user files, and before the entries from GNAT run-time
1913 -- files. The reason for this decision is that libraries referenced
1914 -- by internal routines may reference these standard library entries.
1916 -- Note that we do not insert anything when pragma No_Run_Time has been
1917 -- specified or when the standard libraries are not to be used,
1918 -- otherwise on some platforms, such as VMS, we may get duplicate
1919 -- symbols when linking.
1921 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
1924 if Opt.Shared_Libgnat then
1925 Add_Str_To_Name_Buffer ("-shared");
1927 Add_Str_To_Name_Buffer ("-static");
1930 -- Write directly to avoid -K output (why???)
1932 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1934 if With_DECGNAT then
1937 if Opt.Shared_Libgnat then
1938 Add_Str_To_Name_Buffer (Shared_Lib ("decgnat"));
1940 Add_Str_To_Name_Buffer ("-ldecgnat");
1943 Write_Linker_Option;
1949 if Opt.Shared_Libgnat then
1950 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1952 Add_Str_To_Name_Buffer ("-lgnarl");
1955 Write_Linker_Option;
1960 if Opt.Shared_Libgnat then
1961 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1963 Add_Str_To_Name_Buffer ("-lgnat");
1966 Write_Linker_Option;
1969 -- Write linker options from all internal files
1971 for J in Lgnat .. Linker_Options.Last loop
1972 Get_Name_String (Linker_Options.Table (J).Name);
1973 Write_Linker_Option;
1976 if Output_Linker_Option_List and then not Zero_Formatting then
1980 WBI ("-- END Object file/option list ");
1981 end Gen_Object_Files_Options;
1983 ---------------------
1984 -- Gen_Output_File --
1985 ---------------------
1987 procedure Gen_Output_File (Filename : String) is
1989 -- Acquire settings for Interrupt_State pragmas
1991 Set_IS_Pragma_Table;
1993 -- Acquire settings for Priority_Specific_Dispatching pragma
1995 Set_PSD_Pragma_Table;
1997 -- For JGNAT the main program is already generated by the compiler
1999 if VM_Target = JVM_Target then
2000 Bind_Main_Program := False;
2003 -- Override time slice value if -T switch is set
2005 if Time_Slice_Set then
2006 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
2009 -- Count number of elaboration calls
2011 for E in Elab_Order.First .. Elab_Order.Last loop
2012 if Units.Table (Elab_Order.Table (E)).No_Elab then
2015 Num_Elab_Calls := Num_Elab_Calls + 1;
2019 -- Generate output file in appropriate language
2021 Check_System_Restrictions_Used;
2023 Gen_Output_File_Ada (Filename);
2024 end Gen_Output_File;
2026 -------------------------
2027 -- Gen_Output_File_Ada --
2028 -------------------------
2030 procedure Gen_Output_File_Ada (Filename : String) is
2032 Ada_Main : constant String := Get_Ada_Main_Name;
2033 -- Name to be used for generated Ada main program. See the body of
2034 -- function Get_Ada_Main_Name for details on the form of the name.
2036 Needs_Library_Finalization : constant Boolean :=
2037 not Configurable_Run_Time_On_Target
2038 and then Has_Finalizer;
2039 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2040 -- non-terminating, so we do not want finalization.
2043 -- Name of generated bind file (spec)
2046 -- Name of generated bind file (body)
2049 -- Create spec first
2051 Create_Binder_Output (Filename, 's', Bfiles);
2053 -- We always compile the binder file in Ada 95 mode so that we properly
2054 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2055 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2057 WBI ("pragma Ada_95;");
2059 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2060 -- then we need to make sure that the binder program is compiled with
2061 -- the same restriction, so that no exception tables are generated.
2063 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2064 WBI ("pragma Restrictions (No_Exception_Handlers);");
2067 -- Same processing for Restrictions (No_Exception_Propagation)
2069 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
2070 WBI ("pragma Restrictions (No_Exception_Propagation);");
2073 -- Same processing for pragma No_Run_Time
2075 if No_Run_Time_Mode then
2076 WBI ("pragma No_Run_Time;");
2079 -- Generate with of System so we can reference System.Address
2081 WBI ("with System;");
2083 -- Generate with of System.Initialize_Scalars if active
2085 if Initialize_Scalars_Used then
2086 WBI ("with System.Scalar_Values;");
2089 -- Generate with of System.Secondary_Stack if active
2091 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2092 WBI ("with System.Secondary_Stack;");
2095 Resolve_Binder_Options;
2097 -- Usually, adafinal is called using a pragma Import C. Since Import C
2098 -- doesn't have the same semantics for VMs or CodePeer use standard Ada.
2100 if not Suppress_Standard_Library_On_Target then
2101 if CodePeer_Mode then
2102 WBI ("with System.Standard_Library;");
2103 elsif VM_Target /= No_VM then
2104 WBI ("with System.Soft_Links;");
2105 WBI ("with System.Standard_Library;");
2109 WBI ("package " & Ada_Main & " is");
2110 WBI (" pragma Warnings (Off);");
2112 -- Main program case
2114 if Bind_Main_Program then
2115 if VM_Target = No_VM then
2117 -- Generate argc/argv stuff unless suppressed
2119 if Command_Line_Args_On_Target
2120 or not Configurable_Run_Time_On_Target
2123 WBI (" gnat_argc : Integer;");
2124 WBI (" gnat_argv : System.Address;");
2125 WBI (" gnat_envp : System.Address;");
2127 -- If the standard library is not suppressed, these variables
2128 -- are in the run-time data area for easy run time access.
2130 if not Suppress_Standard_Library_On_Target then
2132 WBI (" pragma Import (C, gnat_argc);");
2133 WBI (" pragma Import (C, gnat_argv);");
2134 WBI (" pragma Import (C, gnat_envp);");
2138 -- Define exit status. Again in normal mode, this is in the
2139 -- run-time library, and is initialized there, but in the
2140 -- configurable runtime case, the variable is declared and
2141 -- initialized in this file.
2145 if Configurable_Run_Time_Mode then
2146 if Exit_Status_Supported_On_Target then
2147 WBI (" gnat_exit_status : Integer := 0;");
2151 WBI (" gnat_exit_status : Integer;");
2152 WBI (" pragma Import (C, gnat_exit_status);");
2156 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2157 -- the main program. Otherwise, it can lead under some circumstances
2158 -- to a symbol duplication during the link (for instance when a C
2159 -- program uses two Ada libraries). Also zero terminate the string
2160 -- so that its end can be found reliably at run time.
2163 WBI (" GNAT_Version : constant String :=");
2164 WBI (" """ & Ver_Prefix &
2165 Gnat_Version_String &
2167 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2170 Set_String (" Ada_Main_Program_Name : constant String := """);
2171 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2173 if VM_Target = No_VM then
2174 Set_Main_Program_Name;
2175 Set_String (""" & ASCII.NUL;");
2177 Set_String (Name_Buffer (1 .. Name_Len - 2) & """;");
2180 Write_Statement_Buffer;
2183 (" pragma Export (C, Ada_Main_Program_Name, " &
2184 """__gnat_ada_main_program_name"");");
2188 WBI (" procedure " & Ada_Init_Name.all & ";");
2189 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2190 Ada_Init_Name.all & """);");
2192 -- If -a has been specified use pragma Linker_Constructor for the init
2193 -- procedure and pragma Linker_Destructor for the final procedure.
2195 if Use_Pragma_Linker_Constructor then
2196 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2199 if not Cumulative_Restrictions.Set (No_Finalization) then
2201 WBI (" procedure " & Ada_Final_Name.all & ";");
2202 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2203 Ada_Final_Name.all & """);");
2205 if Use_Pragma_Linker_Constructor then
2206 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2210 if Bind_Main_Program and then VM_Target = No_VM then
2214 if Exit_Status_Supported_On_Target then
2215 Set_String (" function ");
2217 Set_String (" procedure ");
2220 Set_String (Get_Main_Name);
2222 -- Generate argument list if present
2224 if Command_Line_Args_On_Target then
2225 Write_Statement_Buffer;
2226 WBI (" (argc : Integer;");
2227 WBI (" argv : System.Address;");
2229 (" envp : System.Address)");
2231 if Exit_Status_Supported_On_Target then
2232 Write_Statement_Buffer;
2233 WBI (" return Integer;");
2235 Write_Statement_Buffer (";");
2239 if Exit_Status_Supported_On_Target then
2240 Write_Statement_Buffer (" return Integer;");
2242 Write_Statement_Buffer (";");
2246 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2247 Get_Main_Name & """);");
2256 WBI ("end " & Ada_Main & ";");
2257 Close_Binder_Output;
2259 -- Prepare to write body
2261 Create_Binder_Output (Filename, 'b', Bfileb);
2263 -- We always compile the binder file in Ada 95 mode so that we properly
2264 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2265 -- of the Ada 2005/2012 constructs are needed by the binder file.
2267 WBI ("pragma Ada_95;");
2269 -- Output Source_File_Name pragmas which look like
2271 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2272 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2274 -- where sss/bbb are the spec/body file names respectively
2276 Get_Name_String (Bfiles);
2277 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2279 WBI ("pragma Source_File_Name (" &
2281 ", Spec_File_Name => """ &
2282 Name_Buffer (1 .. Name_Len + 3));
2284 Get_Name_String (Bfileb);
2285 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2287 WBI ("pragma Source_File_Name (" &
2289 ", Body_File_Name => """ &
2290 Name_Buffer (1 .. Name_Len + 3));
2292 -- Generate with of System.Restrictions to initialize
2293 -- Run_Time_Restrictions.
2295 if System_Restrictions_Used
2296 and not Suppress_Standard_Library_On_Target
2299 WBI ("with System.Restrictions;");
2302 if Needs_Library_Finalization then
2303 WBI ("with Ada.Exceptions;");
2307 WBI ("package body " & Ada_Main & " is");
2308 WBI (" pragma Warnings (Off);");
2311 -- Generate externals for elaboration entities
2315 if not CodePeer_Mode then
2316 if not Suppress_Standard_Library_On_Target then
2318 -- Generate Priority_Specific_Dispatching pragma string
2321 (" Local_Priority_Specific_Dispatching : " &
2322 "constant String := """);
2324 for J in 0 .. PSD_Pragma_Settings.Last loop
2325 Set_Char (PSD_Pragma_Settings.Table (J));
2329 Write_Statement_Buffer;
2331 -- Generate Interrupt_State pragma string
2333 Set_String (" Local_Interrupt_States : constant String := """);
2335 for J in 0 .. IS_Pragma_Settings.Last loop
2336 Set_Char (IS_Pragma_Settings.Table (J));
2340 Write_Statement_Buffer;
2344 -- The B.1 (39) implementation advice says that the adainit/adafinal
2345 -- routines should be idempotent. Generate a flag to ensure that.
2347 WBI (" Is_Elaborated : Boolean := False;");
2351 -- Generate the adafinal routine unless there is no finalization to do
2353 if not Cumulative_Restrictions.Set (No_Finalization) then
2354 if Needs_Library_Finalization then
2355 Gen_Finalize_Library;
2363 if Bind_Main_Program and then VM_Target = No_VM then
2367 -- Output object file list and the Ada body is complete
2369 Gen_Object_Files_Options;
2372 WBI ("end " & Ada_Main & ";");
2374 Close_Binder_Output;
2375 end Gen_Output_File_Ada;
2377 ----------------------
2378 -- Gen_Restrictions --
2379 ----------------------
2381 procedure Gen_Restrictions is
2385 if Suppress_Standard_Library_On_Target
2386 or not System_Restrictions_Used
2391 WBI (" System.Restrictions.Run_Time_Restrictions :=");
2397 for J in Cumulative_Restrictions.Set'Range loop
2398 Set_Boolean (Cumulative_Restrictions.Set (J));
2402 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2403 Write_Statement_Buffer;
2409 Set_String_Replace ("),");
2410 Write_Statement_Buffer;
2411 Set_String (" Value => (");
2413 for J in Cumulative_Restrictions.Value'Range loop
2414 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2418 Set_String_Replace ("),");
2419 Write_Statement_Buffer;
2420 WBI (" Violated =>");
2424 for J in Cumulative_Restrictions.Violated'Range loop
2425 Set_Boolean (Cumulative_Restrictions.Violated (J));
2429 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2430 Write_Statement_Buffer;
2436 Set_String_Replace ("),");
2437 Write_Statement_Buffer;
2438 Set_String (" Count => (");
2440 for J in Cumulative_Restrictions.Count'Range loop
2441 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2445 Set_String_Replace ("),");
2446 Write_Statement_Buffer;
2447 Set_String (" Unknown => (");
2449 for J in Cumulative_Restrictions.Unknown'Range loop
2450 Set_Boolean (Cumulative_Restrictions.Unknown (J));
2454 Set_String_Replace ("))");
2456 Write_Statement_Buffer;
2457 end Gen_Restrictions;
2463 -- This routine generates lines such as:
2465 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2466 -- pragma Export (C, unnnnn, unam);
2468 -- for each unit, where unam is the unit name suffixed by either B or S for
2469 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2470 -- the version number, and nnnnn is a 5-digits serial number.
2472 procedure Gen_Versions is
2473 Ubuf : String (1 .. 6) := "u00000";
2475 procedure Increment_Ubuf;
2476 -- Little procedure to increment the serial number
2478 --------------------
2479 -- Increment_Ubuf --
2480 --------------------
2482 procedure Increment_Ubuf is
2484 for J in reverse Ubuf'Range loop
2485 Ubuf (J) := Character'Succ (Ubuf (J));
2486 exit when Ubuf (J) <= '9';
2491 -- Start of processing for Gen_Versions
2496 WBI (" type Version_32 is mod 2 ** 32;");
2497 for U in Units.First .. Units.Last loop
2498 if not Units.Table (U).SAL_Interface
2500 (not Bind_For_Library or else Units.Table (U).Directly_Scanned)
2503 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2504 Units.Table (U).Version & "#;");
2505 Set_String (" pragma Export (C, ");
2507 Set_String (", """);
2509 Get_Name_String (Units.Table (U).Uname);
2511 for K in 1 .. Name_Len loop
2512 if Name_Buffer (K) = '.' then
2516 elsif Name_Buffer (K) = '%' then
2520 Set_Char (Name_Buffer (K));
2524 if Name_Buffer (Name_Len) = 's' then
2530 Set_String (""");");
2531 Write_Statement_Buffer;
2536 ------------------------
2537 -- Get_Main_Unit_Name --
2538 ------------------------
2540 function Get_Main_Unit_Name (S : String) return String is
2541 Result : String := S;
2544 for J in S'Range loop
2545 if Result (J) = '.' then
2551 end Get_Main_Unit_Name;
2553 -----------------------
2554 -- Get_Ada_Main_Name --
2555 -----------------------
2557 function Get_Ada_Main_Name return String is
2558 Suffix : constant String := "_00";
2559 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2560 Opt.Ada_Main_Name.all & Suffix;
2564 -- The main program generated by JGNAT expects a package called
2565 -- ada_<main procedure>.
2566 if VM_Target /= No_VM then
2567 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2568 return "ada_" & Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2571 -- For CodePeer, we want reproducible names (independent of other
2572 -- mains that may or may not be present) that don't collide
2573 -- when analyzing multiple mains and which are easily recognizable
2574 -- as "ada_main" names.
2575 if CodePeer_Mode then
2576 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2577 return "ada_main_for_" &
2578 Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2581 -- This loop tries the following possibilities in order
2587 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2588 -- it is set to 'ada_main'.
2590 for J in 0 .. 99 loop
2592 Nlen := Name'Length - Suffix'Length;
2594 Nlen := Name'Length;
2595 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2596 Name (Name'Last - 1) :=
2597 Character'Val (J / 10 + Character'Pos ('0'));
2600 for K in ALIs.First .. ALIs.Last loop
2601 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2603 -- Get unit name, removing %b or %e at end
2605 Get_Name_String (Units.Table (L).Uname);
2606 Name_Len := Name_Len - 2;
2608 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2614 return Name (1 .. Nlen);
2620 -- If we fall through, just use a peculiar unlikely name
2622 return ("Qwertyuiop");
2623 end Get_Ada_Main_Name;
2629 function Get_Main_Name return String is
2631 -- Explicit name given with -M switch
2633 if Bind_Alternate_Main_Name then
2634 return Alternate_Main_Name.all;
2636 -- Case of main program name to be used directly
2638 elsif Use_Ada_Main_Program_Name_On_Target then
2640 -- Get main program name
2642 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2644 -- If this is a child name, return only the name of the child, since
2645 -- we can't have dots in a nested program name. Note that we do not
2646 -- include the %b at the end of the unit name.
2648 for J in reverse 1 .. Name_Len - 2 loop
2649 if J = 1 or else Name_Buffer (J - 1) = '.' then
2650 return Name_Buffer (J .. Name_Len - 2);
2654 raise Program_Error; -- impossible exit
2656 -- Case where "main" is to be used as default
2663 ---------------------
2664 -- Get_WC_Encoding --
2665 ---------------------
2667 function Get_WC_Encoding return Character is
2669 -- If encoding method specified by -W switch, then return it
2671 if Wide_Character_Encoding_Method_Specified then
2672 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
2674 -- If no main program, and not specified, set brackets, we really have
2675 -- no better choice. If some other encoding is required when there is
2676 -- no main, it must be set explicitly using -Wx.
2678 -- Note: if the ALI file always passed the wide character encoding of
2679 -- every file, then we could use the encoding of the initial specified
2680 -- file, but this information is passed only for potential main
2681 -- programs. We could fix this sometime, but it is a very minor point
2682 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
2683 -- is no main program).
2685 elsif No_Main_Subprogram then
2688 -- Otherwise if there is a main program, take encoding from it
2691 return ALIs.Table (ALIs.First).WC_Encoding;
2693 end Get_WC_Encoding;
2699 function Has_Finalizer return Boolean is
2704 for E in reverse Elab_Order.First .. Elab_Order.Last loop
2705 Unum := Elab_Order.Table (E);
2706 U := Units.Table (Unum);
2708 -- We are only interested in non-generic packages
2710 if U.Unit_Kind = 'p'
2711 and then U.Has_Finalizer
2712 and then not U.Is_Generic
2713 and then not U.No_Elab
2722 ----------------------
2723 -- Lt_Linker_Option --
2724 ----------------------
2726 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2728 -- Sort internal files last
2730 if Linker_Options.Table (Op1).Internal_File
2732 Linker_Options.Table (Op2).Internal_File
2734 -- Note: following test uses False < True
2736 return Linker_Options.Table (Op1).Internal_File
2738 Linker_Options.Table (Op2).Internal_File;
2740 -- If both internal or both non-internal, sort according to the
2741 -- elaboration position. A unit that is elaborated later should come
2742 -- earlier in the linker options list.
2745 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2747 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2750 end Lt_Linker_Option;
2752 ------------------------
2753 -- Move_Linker_Option --
2754 ------------------------
2756 procedure Move_Linker_Option (From : Natural; To : Natural) is
2758 Linker_Options.Table (To) := Linker_Options.Table (From);
2759 end Move_Linker_Option;
2761 ----------------------------
2762 -- Resolve_Binder_Options --
2763 ----------------------------
2765 procedure Resolve_Binder_Options is
2767 for E in Elab_Order.First .. Elab_Order.Last loop
2768 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2770 -- This is not a perfect approach, but is the current protocol
2771 -- between the run-time and the binder to indicate that tasking is
2772 -- used: system.os_interface should always be used by any tasking
2775 if Name_Buffer (1 .. 19) = "system.os_interface" then
2779 -- Ditto for declib and the "dec" package
2781 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
2782 With_DECGNAT := True;
2785 end Resolve_Binder_Options;
2791 procedure Set_Boolean (B : Boolean) is
2792 True_Str : constant String := "True";
2793 False_Str : constant String := "False";
2796 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
2797 Last := Last + True_Str'Length;
2799 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
2800 Last := Last + False_Str'Length;
2808 procedure Set_Char (C : Character) is
2811 Statement_Buffer (Last) := C;
2818 procedure Set_Int (N : Int) is
2830 Statement_Buffer (Last) :=
2831 Character'Val (N mod 10 + Character'Pos ('0'));
2835 -------------------------
2836 -- Set_IS_Pragma_Table --
2837 -------------------------
2839 procedure Set_IS_Pragma_Table is
2841 for F in ALIs.First .. ALIs.Last loop
2842 for K in ALIs.Table (F).First_Interrupt_State ..
2843 ALIs.Table (F).Last_Interrupt_State
2846 Inum : constant Int :=
2847 Interrupt_States.Table (K).Interrupt_Id;
2848 Stat : constant Character :=
2849 Interrupt_States.Table (K).Interrupt_State;
2852 while IS_Pragma_Settings.Last < Inum loop
2853 IS_Pragma_Settings.Append ('n');
2856 IS_Pragma_Settings.Table (Inum) := Stat;
2860 end Set_IS_Pragma_Table;
2862 ---------------------------
2863 -- Set_Main_Program_Name --
2864 ---------------------------
2866 procedure Set_Main_Program_Name is
2868 -- Note that name has %b on the end which we ignore
2870 -- First we output the initial _ada_ since we know that the main
2871 -- program is a library level subprogram.
2873 Set_String ("_ada_");
2875 -- Copy name, changing dots to double underscores
2877 for J in 1 .. Name_Len - 2 loop
2878 if Name_Buffer (J) = '.' then
2881 Set_Char (Name_Buffer (J));
2884 end Set_Main_Program_Name;
2886 ---------------------
2887 -- Set_Name_Buffer --
2888 ---------------------
2890 procedure Set_Name_Buffer is
2892 for J in 1 .. Name_Len loop
2893 Set_Char (Name_Buffer (J));
2895 end Set_Name_Buffer;
2897 -------------------------
2898 -- Set_PSD_Pragma_Table --
2899 -------------------------
2901 procedure Set_PSD_Pragma_Table is
2903 for F in ALIs.First .. ALIs.Last loop
2904 for K in ALIs.Table (F).First_Specific_Dispatching ..
2905 ALIs.Table (F).Last_Specific_Dispatching
2908 DTK : Specific_Dispatching_Record
2909 renames Specific_Dispatching.Table (K);
2912 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
2913 PSD_Pragma_Settings.Append ('F');
2916 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
2917 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
2922 end Set_PSD_Pragma_Table;
2928 procedure Set_String (S : String) is
2930 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
2931 Last := Last + S'Length;
2934 ------------------------
2935 -- Set_String_Replace --
2936 ------------------------
2938 procedure Set_String_Replace (S : String) is
2940 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
2941 end Set_String_Replace;
2947 procedure Set_Unit_Name (Mode : Qualification_Mode := Double_Underscores) is
2949 for J in 1 .. Name_Len - 2 loop
2950 if Name_Buffer (J) = '.' then
2951 if Mode = Double_Underscores then
2953 elsif Mode = Dot then
2959 Set_Char (Name_Buffer (J));
2964 ---------------------
2965 -- Set_Unit_Number --
2966 ---------------------
2968 procedure Set_Unit_Number (U : Unit_Id) is
2969 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
2970 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
2973 if Num_Units >= 10 and then Unum < 10 then
2977 if Num_Units >= 100 and then Unum < 100 then
2982 end Set_Unit_Number;
2984 ----------------------------
2985 -- Write_Statement_Buffer --
2986 ----------------------------
2988 procedure Write_Statement_Buffer is
2990 WBI (Statement_Buffer (1 .. Last));
2992 end Write_Statement_Buffer;
2994 procedure Write_Statement_Buffer (S : String) is
2997 Write_Statement_Buffer;
2998 end Write_Statement_Buffer;