1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Binde; use Binde;
29 with Casing; use Casing;
30 with Fname; use Fname;
31 with GNAT.OS_Lib; use GNAT.OS_Lib;
32 with Gnatvsn; use Gnatvsn;
34 with Namet; use Namet;
36 with Osint; use Osint;
37 with Osint.B; use Osint.B;
38 with Output; use Output;
39 with Rident; use Rident;
40 with Table; use Table;
41 with Targparm; use Targparm;
42 with Types; use Types;
44 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
46 package body Bindgen is
48 Statement_Buffer : String (1 .. 1000);
49 -- Buffer used for constructing output statements
52 -- Last location in Statement_Buffer currently set
54 With_DECGNAT : Boolean := False;
55 -- Flag which indicates whether the program uses the DECGNAT library
56 -- (presence of the unit DEC).
58 With_GNARL : Boolean := False;
59 -- Flag which indicates whether the program uses the GNARL library
60 -- (presence of the unit System.OS_Interface)
62 Num_Elab_Calls : Nat := 0;
63 -- Number of generated calls to elaboration routines
65 ----------------------------------
66 -- Interface_State Pragma Table --
67 ----------------------------------
69 -- This table assembles the interface state pragma information from
70 -- all the units in the partition. Note that Bcheck has already checked
71 -- that the information is consistent across partitions. The entries
72 -- in this table are n/u/r/s for not set/user/runtime/system.
74 package IS_Pragma_Settings is new Table.Table (
75 Table_Component_Type => Character,
76 Table_Index_Type => Int,
79 Table_Increment => 200,
80 Table_Name => "IS_Pragma_Settings");
82 ----------------------
83 -- Run-Time Globals --
84 ----------------------
86 -- This section documents the global variables that are passed to the
87 -- run time from the generated binder file. The call that is made is
88 -- to the routine Set_Globals, which has the following spec:
90 -- procedure Set_Globals
91 -- (Main_Priority : Integer;
92 -- Time_Slice_Value : Integer;
93 -- WC_Encoding : Character;
94 -- Locking_Policy : Character;
95 -- Queuing_Policy : Character;
96 -- Task_Dispatching_Policy : Character;
97 -- Restrictions : System.Address;
98 -- Interrupt_States : System.Address;
99 -- Num_Interrupt_States : Integer;
100 -- Unreserve_All_Interrupts : Integer;
101 -- Exception_Tracebacks : Integer;
102 -- Zero_Cost_Exceptions : Integer;
103 -- Detect_Blocking : Integer);
105 -- Main_Priority is the priority value set by pragma Priority in the
106 -- main program. If no such pragma is present, the value is -1.
108 -- Time_Slice_Value is the time slice value set by pragma Time_Slice
109 -- in the main program, or by the use of a -Tnnn parameter for the
110 -- binder (if both are present, the binder value overrides). The
111 -- value is in milliseconds. A value of zero indicates that time
112 -- slicing should be suppressed. If no pragma is present, and no
113 -- -T switch was used, the value is -1.
115 -- WC_Encoding shows the wide character encoding method used for
116 -- the main program. This is one of the encoding letters defined
117 -- in System.WCh_Con.WC_Encoding_Letters.
119 -- Locking_Policy is a space if no locking policy was specified
120 -- for the partition. If a locking policy was specified, the value
121 -- is the upper case first character of the locking policy name,
122 -- for example, 'C' for Ceiling_Locking.
124 -- Queuing_Policy is a space if no queuing policy was specified
125 -- for the partition. If a queuing policy was specified, the value
126 -- is the upper case first character of the queuing policy name
127 -- for example, 'F' for FIFO_Queuing.
129 -- Task_Dispatching_Policy is a space if no task dispatching policy
130 -- was specified for the partition. If a task dispatching policy
131 -- was specified, the value is the upper case first character of
132 -- the policy name, e.g. 'F' for FIFO_Within_Priorities.
134 -- Restrictions is the address of a null-terminated string specifying the
135 -- restrictions information for the partition. The format is identical to
136 -- that of the parameter string found on R lines in ali files (see Lib.Writ
137 -- spec in lib-writ.ads for full details). The difference is that in this
138 -- context the values are the cumulative ones for the entire partition.
140 -- Interrupt_States is the address of a string used to specify the
141 -- cumulative results of Interrupt_State pragmas used in the partition.
142 -- The length of this string is determined by the last interrupt for which
143 -- such a pragma is given (the string will be a null string if no pragmas
144 -- were used). If pragma were present the entries apply to the interrupts
145 -- in sequence from the first interrupt, and are set to one of four
146 -- possible settings: 'n' for not specified, 'u' for user, 'r' for
147 -- run time, 's' for system, see description of Interrupt_State pragma
148 -- for further details.
150 -- Num_Interrupt_States is the length of the Interrupt_States string.
151 -- It will be set to zero if no Interrupt_State pragmas are present.
153 -- Unreserve_All_Interrupts is set to one if at least one unit in the
154 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
156 -- Exception_Tracebacks is set to one if the -E parameter was present
157 -- in the bind and to zero otherwise. Note that on some targets exception
158 -- tracebacks are provided by default, so a value of zero for this
159 -- parameter does not necessarily mean no trace backs are available.
161 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
162 -- this partition, and to zero if longjmp/setjmp exceptions are used.
165 -- Detect_Blocking indicates whether pragma Detect_Blocking is
166 -- active or not. A value of zero indicates that the pragma is not
167 -- present, while a value of 1 signals its presence in the
170 -----------------------
171 -- Local Subprograms --
172 -----------------------
174 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
175 -- Convenient shorthand used throughout
177 procedure Gen_Adainit_Ada;
178 -- Generates the Adainit procedure (Ada code case)
180 procedure Gen_Adainit_C;
181 -- Generates the Adainit procedure (C code case)
183 procedure Gen_Adafinal_Ada;
184 -- Generate the Adafinal procedure (Ada code case)
186 procedure Gen_Adafinal_C;
187 -- Generate the Adafinal procedure (C code case)
189 procedure Gen_Elab_Calls_Ada;
190 -- Generate sequence of elaboration calls (Ada code case)
192 procedure Gen_Elab_Calls_C;
193 -- Generate sequence of elaboration calls (C code case)
195 procedure Gen_Elab_Order_Ada;
196 -- Generate comments showing elaboration order chosen (Ada case)
198 procedure Gen_Elab_Order_C;
199 -- Generate comments showing elaboration order chosen (C case)
201 procedure Gen_Elab_Defs_C;
202 -- Generate sequence of definitions for elaboration routines (C code case)
204 procedure Gen_Main_Ada;
205 -- Generate procedure main (Ada code case)
207 procedure Gen_Main_C;
208 -- Generate main() procedure (C code case)
210 procedure Gen_Object_Files_Options;
211 -- Output comments containing a list of the full names of the object
212 -- files to be linked and the list of linker options supplied by
213 -- Linker_Options pragmas in the source. (C and Ada code case)
215 procedure Gen_Output_File_Ada (Filename : String);
216 -- Generate output file (Ada code case)
218 procedure Gen_Output_File_C (Filename : String);
219 -- Generate output file (C code case)
221 procedure Gen_Restrictions_String_1;
222 -- Generate first restrictions string, which consists of the parameters
223 -- the first R line, as described in lib-writ.ads, with the restrictions
224 -- being those for the entire partition (from Cumulative_Restrictions).
226 procedure Gen_Restrictions_String_2;
227 -- Generate first restrictions string, which consists of the parameters
228 -- the second R line, as described in lib-writ.ads, with the restrictions
229 -- being those for the entire partition (from Cumulative_Restrictions).
231 procedure Gen_Versions_Ada;
232 -- Output series of definitions for unit versions (Ada code case)
234 procedure Gen_Versions_C;
235 -- Output series of definitions for unit versions (C code case)
237 function Get_Ada_Main_Name return String;
238 -- This function is used in the Ada main output case to compute a usable
239 -- name for the generated main program. The normal main program name is
240 -- Ada_Main, but this won't work if the user has a unit with this name.
241 -- This function tries Ada_Main first, and if there is such a clash, then
242 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
244 function Get_Main_Name return String;
245 -- This function is used in the Ada main output case to compute the
246 -- correct external main program. It is "main" by default, unless the
247 -- flag Use_Ada_Main_Program_Name_On_Target is set, in which case it
248 -- is the name of the Ada main name without the "_ada". This default
249 -- can be overridden explicitly using the -Mname binder switch.
251 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
252 -- Compare linker options, when sorting, first according to
253 -- Is_Internal_File (internal files come later) and then by
254 -- elaboration order position (latest to earliest).
256 procedure Move_Linker_Option (From : Natural; To : Natural);
257 -- Move routine for sorting linker options
259 procedure Public_Version_Warning;
260 -- Emit a warning concerning the use of the Public version under
261 -- certain circumstances. See details in body.
263 procedure Resolve_Binder_Options;
264 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
265 -- since it tests for a package named "dec" which might cause a conflict
266 -- on non-VMS systems.
268 procedure Set_Char (C : Character);
269 -- Set given character in Statement_Buffer at the Last + 1 position
270 -- and increment Last by one to reflect the stored character.
272 procedure Set_Int (N : Int);
273 -- Set given value in decimal in Statement_Buffer with no spaces
274 -- starting at the Last + 1 position, and updating Last past the value.
275 -- A minus sign is output for a negative value.
277 procedure Set_IS_Pragma_Table;
278 -- Initializes contents of IS_Pragma_Settings table from ALI table
280 procedure Set_Main_Program_Name;
281 -- Given the main program name in Name_Buffer (length in Name_Len)
282 -- generate the name of the routine to be used in the call. The name
283 -- is generated starting at Last + 1, and Last is updated past it.
285 procedure Set_Name_Buffer;
286 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
288 procedure Set_String (S : String);
289 -- Sets characters of given string in Statement_Buffer, starting at the
290 -- Last + 1 position, and updating last past the string value.
292 procedure Set_Unit_Name;
293 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
294 -- starting at the Last + 1 position, and updating last past the value.
295 -- changing periods to double underscores, and updating Last appropriately.
297 procedure Set_Unit_Number (U : Unit_Id);
298 -- Sets unit number (first unit is 1, leading zeroes output to line
299 -- up all output unit numbers nicely as required by the value, and
300 -- by the total number of units.
302 procedure Tab_To (N : Natural);
303 -- If Last is greater than or equal to N, no effect, otherwise store
304 -- blanks in Statement_Buffer bumping Last, until Last = N.
306 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String);
307 -- For C code case, write C & Common, for Ada case write Ada & Common
308 -- to current binder output file using Write_Binder_Info.
310 procedure Write_Statement_Buffer;
311 -- Write out contents of statement buffer up to Last, and reset Last to 0
313 procedure Write_Statement_Buffer (S : String);
314 -- First writes its argument (using Set_String (S)), then writes out the
315 -- contents of statement buffer up to Last, and reset Last to 0
317 ----------------------
318 -- Gen_Adafinal_Ada --
319 ----------------------
321 procedure Gen_Adafinal_Ada is
324 WBI (" procedure " & Ada_Final_Name.all & " is");
327 -- If compiling for the JVM, we directly call Adafinal because
328 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
330 if Hostparm.Java_VM then
331 WBI (" System.Standard_Library.Adafinal;");
333 -- If there is no finalization, there is nothing to do
335 elsif Cumulative_Restrictions.Set (No_Finalization) then
338 WBI (" Do_Finalize;");
341 WBI (" end " & Ada_Final_Name.all & ";");
342 end Gen_Adafinal_Ada;
348 procedure Gen_Adafinal_C is
350 WBI ("void " & Ada_Final_Name.all & " () {");
351 WBI (" system__standard_library__adafinal ();");
356 ---------------------
357 -- Gen_Adainit_Ada --
358 ---------------------
360 procedure Gen_Adainit_Ada is
361 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
364 WBI (" procedure " & Ada_Init_Name.all & " is");
366 -- Generate externals for elaboration entities
368 for E in Elab_Order.First .. Elab_Order.Last loop
370 Unum : constant Unit_Id := Elab_Order.Table (E);
371 U : Unit_Record renames Units.Table (Unum);
374 -- Check for Elab_Entity to be set for this unit
378 -- Don't generate reference for stand alone library
380 and then not U.SAL_Interface
382 -- Don't generate reference for predefined file in No_Run_Time
383 -- mode, since we don't include the object files in this case
387 and then Is_Predefined_File_Name (U.Sfile))
391 Set_Unit_Number (Unum);
392 Set_String (" : Boolean; pragma Import (Ada, ");
394 Set_Unit_Number (Unum);
396 Get_Name_String (U.Uname);
398 -- In the case of JGNAT we need to emit an Import name
399 -- that includes the class name (using '$' separators
400 -- in the case of a child unit name).
402 if Hostparm.Java_VM then
403 for J in 1 .. Name_Len - 2 loop
404 if Name_Buffer (J) /= '.' then
405 Set_Char (Name_Buffer (J));
413 -- If the unit name is very long, then split the
414 -- Import link name across lines using "&" (occurs
415 -- in some C2 tests).
417 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
419 Write_Statement_Buffer;
425 Set_String ("_E"");");
426 Write_Statement_Buffer;
431 Write_Statement_Buffer;
433 -- If the standard library is suppressed, then the only global variable
434 -- that might be needed (by the Ravenscar profile) is the priority of
435 -- the environment. Also no exception tables are needed.
437 if Suppress_Standard_Library_On_Target then
438 if Main_Priority /= No_Main_Priority then
439 WBI (" Main_Priority : Integer;");
440 WBI (" pragma Import (C, Main_Priority," &
441 " ""__gl_main_priority"");");
447 if Main_Priority /= No_Main_Priority then
448 Set_String (" Main_Priority := ");
449 Set_Int (Main_Priority);
451 Write_Statement_Buffer;
457 -- Normal case (standard library not suppressed). Global values are
458 -- assigned using the runtime routine Set_Globals (we have to use
459 -- the routine call, rather than define the globals in the binder
460 -- file to deal with cross-library calls in some systems.
463 -- Generate restrictions string
465 Set_String (" Restrictions : constant String :=");
466 Write_Statement_Buffer;
469 Gen_Restrictions_String_1;
471 Write_Statement_Buffer;
474 Gen_Restrictions_String_2;
475 Set_String (""" & ASCII.Nul;");
476 Write_Statement_Buffer;
479 -- Generate Interrupt_State pragma string
481 Set_String (" Interrupt_States : constant String :=");
482 Write_Statement_Buffer;
491 for J in 0 .. IS_Pragma_Settings.Last loop
494 Write_Statement_Buffer;
502 Set_Char (IS_Pragma_Settings.Table (J));
507 Write_Statement_Buffer;
510 -- Generate spec for Set_Globals procedure
512 WBI (" procedure Set_Globals");
513 WBI (" (Main_Priority : Integer;");
514 WBI (" Time_Slice_Value : Integer;");
515 WBI (" WC_Encoding : Character;");
516 WBI (" Locking_Policy : Character;");
517 WBI (" Queuing_Policy : Character;");
518 WBI (" Task_Dispatching_Policy : Character;");
520 WBI (" Restrictions : System.Address;");
521 WBI (" Interrupt_States : System.Address;");
522 WBI (" Num_Interrupt_States : Integer;");
523 WBI (" Unreserve_All_Interrupts : Integer;");
524 WBI (" Exception_Tracebacks : Integer;");
525 WBI (" Zero_Cost_Exceptions : Integer;");
526 WBI (" Detect_Blocking : Integer);");
527 WBI (" pragma Import (C, Set_Globals, ""__gnat_set_globals"");");
529 -- Import entry point for elaboration time signal handler
530 -- installation, and indication of if it's been called previously.
533 WBI (" procedure Install_Handler;");
534 WBI (" pragma Import (C, Install_Handler, " &
535 """__gnat_install_handler"");");
537 WBI (" Handler_Installed : Integer;");
538 WBI (" pragma Import (C, Handler_Installed, " &
539 """__gnat_handler_installed"");");
542 -- Generate the call to Set_Globals
544 WBI (" Set_Globals");
546 Set_String (" (Main_Priority => ");
547 Set_Int (Main_Priority);
549 Write_Statement_Buffer;
551 Set_String (" Time_Slice_Value => ");
553 if Task_Dispatching_Policy_Specified = 'F'
554 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
558 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
562 Write_Statement_Buffer;
564 Set_String (" WC_Encoding => '");
565 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
567 Write_Statement_Buffer;
569 Set_String (" Locking_Policy => '");
570 Set_Char (Locking_Policy_Specified);
572 Write_Statement_Buffer;
574 Set_String (" Queuing_Policy => '");
575 Set_Char (Queuing_Policy_Specified);
577 Write_Statement_Buffer;
579 Set_String (" Task_Dispatching_Policy => '");
580 Set_Char (Task_Dispatching_Policy_Specified);
582 Write_Statement_Buffer;
584 WBI (" Restrictions => Restrictions'Address,");
586 WBI (" Interrupt_States => " &
587 "Interrupt_States'Address,");
589 Set_String (" Num_Interrupt_States => ");
590 Set_Int (IS_Pragma_Settings.Last + 1);
592 Write_Statement_Buffer;
594 Set_String (" Unreserve_All_Interrupts => ");
596 if Unreserve_All_Interrupts_Specified then
603 Write_Statement_Buffer;
605 Set_String (" Exception_Tracebacks => ");
607 if Exception_Tracebacks then
614 Write_Statement_Buffer;
616 Set_String (" Zero_Cost_Exceptions => ");
618 if Zero_Cost_Exceptions_Specified then
625 Write_Statement_Buffer;
627 Set_String (" Detect_Blocking => ");
629 if Detect_Blocking then
636 Write_Statement_Buffer;
638 -- Generate call to Install_Handler
641 WBI (" if Handler_Installed = 0 then");
642 WBI (" Install_Handler;");
646 -- Generate call to set Initialize_Scalar values if active
648 if Initialize_Scalars_Used then
650 Set_String (" System.Scalar_Values.Initialize ('");
651 Set_Char (Initialize_Scalars_Mode1);
653 Set_Char (Initialize_Scalars_Mode2);
655 Write_Statement_Buffer;
658 -- Generate assignment of default secondary stack size if set
660 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
662 Set_String (" System.Secondary_Stack.");
663 Set_String ("Default_Secondary_Stack_Size := ");
664 Set_Int (Opt.Default_Sec_Stack_Size);
666 Write_Statement_Buffer;
669 -- Generate elaboration calls
674 WBI (" end " & Ada_Init_Name.all & ";");
681 procedure Gen_Adainit_C is
682 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
685 WBI ("void " & Ada_Init_Name.all & " (void)");
688 -- Generate externals for elaboration entities
690 for E in Elab_Order.First .. Elab_Order.Last loop
692 Unum : constant Unit_Id := Elab_Order.Table (E);
693 U : Unit_Record renames Units.Table (Unum);
696 -- Check for Elab entity to be set for this unit
700 -- Don't generate reference for stand alone library
702 and then not U.SAL_Interface
704 -- Don't generate reference for predefined file in No_Run_Time
705 -- mode, since we don't include the object files in this case
709 and then Is_Predefined_File_Name (U.Sfile))
711 Set_String (" extern char ");
712 Get_Name_String (U.Uname);
715 Write_Statement_Buffer;
720 Write_Statement_Buffer;
722 -- Standard library suppressed
724 if Suppress_Standard_Library_On_Target then
726 -- Case of High_Integrity_Mode mode. Set __gl_main_priority if needed
727 -- for the Ravenscar profile.
729 if Main_Priority /= No_Main_Priority then
730 Set_String (" extern int __gl_main_priority = ");
731 Set_Int (Main_Priority);
733 Write_Statement_Buffer;
736 -- Normal case (standard library not suppressed)
739 -- Generate definition for restrictions string
741 Set_String (" const char *restrictions = """);
742 Gen_Restrictions_String_1;
743 Gen_Restrictions_String_2;
745 Write_Statement_Buffer;
747 -- Generate definition for interrupt states string
749 Set_String (" const char *interrupt_states = """);
751 for J in 0 .. IS_Pragma_Settings.Last loop
752 Set_Char (IS_Pragma_Settings.Table (J));
756 Write_Statement_Buffer;
758 -- Generate declaration for secondary stack default if needed
760 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
761 WBI (" extern int system__secondary_stack__" &
762 "default_secondary_stack_size;");
767 -- Code for normal case (standard library not suppressed)
769 -- Generate call to set the runtime global variables defined in
770 -- init.c. We define the varables in init.c, rather than in
771 -- the binder generated file itself to avoid undefined externals
772 -- when the runtime is linked as a shareable image library.
774 -- We call the routine from inside adainit() because this works for
775 -- both programs with and without binder generated "main" functions.
777 WBI (" __gnat_set_globals (");
780 Set_Int (Main_Priority);
783 Set_String ("/* Main_Priority */");
784 Write_Statement_Buffer;
788 if Task_Dispatching_Policy = 'F'
789 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
793 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
798 Set_String ("/* Time_Slice_Value */");
799 Write_Statement_Buffer;
802 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
805 Set_String ("/* WC_Encoding */");
806 Write_Statement_Buffer;
809 Set_Char (Locking_Policy_Specified);
812 Set_String ("/* Locking_Policy */");
813 Write_Statement_Buffer;
816 Set_Char (Queuing_Policy_Specified);
819 Set_String ("/* Queuing_Policy */");
820 Write_Statement_Buffer;
823 Set_Char (Task_Dispatching_Policy_Specified);
826 Set_String ("/* Tasking_Dispatching_Policy */");
827 Write_Statement_Buffer;
830 Set_String ("restrictions");
833 Set_String ("/* Restrictions */");
834 Write_Statement_Buffer;
837 Set_String ("interrupt_states");
840 Set_String ("/* Interrupt_States */");
841 Write_Statement_Buffer;
844 Set_Int (IS_Pragma_Settings.Last + 1);
847 Set_String ("/* Num_Interrupt_States */");
848 Write_Statement_Buffer;
851 Set_Int (Boolean'Pos (Unreserve_All_Interrupts_Specified));
854 Set_String ("/* Unreserve_All_Interrupts */");
855 Write_Statement_Buffer;
858 Set_Int (Boolean'Pos (Exception_Tracebacks));
861 Set_String ("/* Exception_Tracebacks */");
862 Write_Statement_Buffer;
865 Set_Int (Boolean'Pos (Zero_Cost_Exceptions_Specified));
868 Set_String ("/* Zero_Cost_Exceptions */");
869 Write_Statement_Buffer;
873 if Detect_Blocking then
881 Set_String ("/* Detect_Blocking */");
882 Write_Statement_Buffer;
885 -- Install elaboration time signal handler
887 WBI (" if (__gnat_handler_installed == 0)");
889 WBI (" __gnat_install_handler ();");
893 -- Generate call to set Initialize_Scalar values if needed
895 if Initialize_Scalars_Used then
897 Set_String (" system__scalar_values__initialize('");
898 Set_Char (Initialize_Scalars_Mode1);
900 Set_Char (Initialize_Scalars_Mode2);
902 Write_Statement_Buffer;
905 -- Generate assignment of default secondary stack size if set
907 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
909 Set_String (" system__secondary_stack__");
910 Set_String ("default_secondary_stack_size = ");
911 Set_Int (Opt.Default_Sec_Stack_Size);
913 Write_Statement_Buffer;
916 -- Generate elaboration calls
923 ------------------------
924 -- Gen_Elab_Calls_Ada --
925 ------------------------
927 procedure Gen_Elab_Calls_Ada is
929 for E in Elab_Order.First .. Elab_Order.Last loop
931 Unum : constant Unit_Id := Elab_Order.Table (E);
932 U : Unit_Record renames Units.Table (Unum);
935 -- This is the unit number of the spec that corresponds to
936 -- this entry. It is the same as Unum except when the body
937 -- and spec are different and we are currently processing
938 -- the body, in which case it is the spec (Unum + 1).
941 if U.Utype = Is_Body then
942 Unum_Spec := Unum + 1;
947 -- Nothing to do if predefined unit in no run time mode
949 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
952 -- Case of no elaboration code
956 -- The only case in which we have to do something is if
957 -- this is a body, with a separate spec, where the separate
958 -- spec has an elaboration entity defined.
960 -- In that case, this is where we set the elaboration entity
961 -- to True, we do not need to test if this has already been
962 -- done, since it is quicker to set the flag than to test it.
964 if not U.SAL_Interface and then U.Utype = Is_Body
965 and then Units.Table (Unum_Spec).Set_Elab_Entity
968 Set_Unit_Number (Unum_Spec);
969 Set_String (" := True;");
970 Write_Statement_Buffer;
973 -- Here if elaboration code is present. If binding a library
974 -- or if there is a non-Ada main subprogram then we generate:
976 -- if not uname_E then
977 -- uname'elab_[spec|body];
981 -- Otherwise, elaboration routines are called unconditionally:
983 -- uname'elab_[spec|body];
986 -- The uname_E assignment is skipped if this is a separate spec,
987 -- since the assignment will be done when we process the body.
989 elsif not U.SAL_Interface then
990 if Force_Checking_Of_Elaboration_Flags or
991 Interface_Library_Unit or
992 (not Bind_Main_Program)
994 Set_String (" if not E");
995 Set_Unit_Number (Unum_Spec);
996 Set_String (" then");
997 Write_Statement_Buffer;
1002 Get_Decoded_Name_String_With_Brackets (U.Uname);
1004 if Name_Buffer (Name_Len) = 's' then
1005 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_spec";
1007 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_body";
1010 Name_Len := Name_Len + 8;
1011 Set_Casing (U.Icasing);
1014 Write_Statement_Buffer;
1016 if U.Utype /= Is_Spec then
1017 if Force_Checking_Of_Elaboration_Flags or
1018 Interface_Library_Unit or
1019 (not Bind_Main_Program)
1025 Set_Unit_Number (Unum_Spec);
1026 Set_String (" := True;");
1027 Write_Statement_Buffer;
1030 if Force_Checking_Of_Elaboration_Flags or
1031 Interface_Library_Unit or
1032 (not Bind_Main_Program)
1039 end Gen_Elab_Calls_Ada;
1041 ----------------------
1042 -- Gen_Elab_Calls_C --
1043 ----------------------
1045 procedure Gen_Elab_Calls_C is
1047 for E in Elab_Order.First .. Elab_Order.Last loop
1049 Unum : constant Unit_Id := Elab_Order.Table (E);
1050 U : Unit_Record renames Units.Table (Unum);
1052 Unum_Spec : Unit_Id;
1053 -- This is the unit number of the spec that corresponds to
1054 -- this entry. It is the same as Unum except when the body
1055 -- and spec are different and we are currently processing
1056 -- the body, in which case it is the spec (Unum + 1).
1059 if U.Utype = Is_Body then
1060 Unum_Spec := Unum + 1;
1065 -- Nothing to do if predefined unit in no run time mode
1067 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1070 -- Case of no elaboration code
1072 elsif U.No_Elab then
1074 -- The only case in which we have to do something is if
1075 -- this is a body, with a separate spec, where the separate
1076 -- spec has an elaboration entity defined.
1078 -- In that case, this is where we set the elaboration entity
1079 -- to True, we do not need to test if this has already been
1080 -- done, since it is quicker to set the flag than to test it.
1082 if not U.SAL_Interface and then U.Utype = Is_Body
1083 and then Units.Table (Unum_Spec).Set_Elab_Entity
1086 Get_Name_String (U.Uname);
1088 Set_String ("_E = 1;");
1089 Write_Statement_Buffer;
1092 -- Here if elaboration code is present. If binding a library
1093 -- or if there is a non-Ada main subprogram then we generate:
1095 -- if (uname_E == 0) {
1096 -- uname__elab[s|b] ();
1100 -- The uname_E assignment is skipped if this is a separate spec,
1101 -- since the assignment will be done when we process the body.
1103 elsif not U.SAL_Interface then
1104 Get_Name_String (U.Uname);
1106 if Force_Checking_Of_Elaboration_Flags or
1107 Interface_Library_Unit or
1108 (not Bind_Main_Program)
1110 Set_String (" if (");
1112 Set_String ("_E == 0) {");
1113 Write_Statement_Buffer;
1119 Set_String ("___elab");
1120 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1121 Set_String (" ();");
1122 Write_Statement_Buffer;
1124 if U.Utype /= Is_Spec then
1125 if Force_Checking_Of_Elaboration_Flags or
1126 Interface_Library_Unit or
1127 (not Bind_Main_Program)
1134 Set_String ("_E++;");
1135 Write_Statement_Buffer;
1138 if Force_Checking_Of_Elaboration_Flags or
1139 Interface_Library_Unit or
1140 (not Bind_Main_Program)
1148 end Gen_Elab_Calls_C;
1150 ----------------------
1151 -- Gen_Elab_Defs_C --
1152 ----------------------
1154 procedure Gen_Elab_Defs_C is
1156 for E in Elab_Order.First .. Elab_Order.Last loop
1158 -- Generate declaration of elaboration procedure if elaboration
1159 -- needed. Note that passive units are always excluded.
1161 if not Units.Table (Elab_Order.Table (E)).No_Elab then
1162 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1163 Set_String ("extern void ");
1165 Set_String ("___elab");
1166 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1167 Set_String (" (void);");
1168 Write_Statement_Buffer;
1174 end Gen_Elab_Defs_C;
1176 ------------------------
1177 -- Gen_Elab_Order_Ada --
1178 ------------------------
1180 procedure Gen_Elab_Order_Ada is
1183 WBI (" -- BEGIN ELABORATION ORDER");
1185 for J in Elab_Order.First .. Elab_Order.Last loop
1186 Set_String (" -- ");
1187 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1189 Write_Statement_Buffer;
1192 WBI (" -- END ELABORATION ORDER");
1193 end Gen_Elab_Order_Ada;
1195 ----------------------
1196 -- Gen_Elab_Order_C --
1197 ----------------------
1199 procedure Gen_Elab_Order_C is
1202 WBI ("/* BEGIN ELABORATION ORDER");
1204 for J in Elab_Order.First .. Elab_Order.Last loop
1205 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1207 Write_Statement_Buffer;
1210 WBI (" END ELABORATION ORDER */");
1211 end Gen_Elab_Order_C;
1217 procedure Gen_Main_Ada is
1221 if Exit_Status_Supported_On_Target then
1222 Set_String (" function ");
1224 Set_String (" procedure ");
1227 Set_String (Get_Main_Name);
1229 if Command_Line_Args_On_Target then
1230 Write_Statement_Buffer;
1231 WBI (" (argc : Integer;");
1232 WBI (" argv : System.Address;");
1233 WBI (" envp : System.Address)");
1235 if Exit_Status_Supported_On_Target then
1236 WBI (" return Integer");
1242 if Exit_Status_Supported_On_Target then
1243 Set_String (" return Integer is");
1248 Write_Statement_Buffer;
1251 if Opt.Default_Exit_Status /= 0
1252 and then Bind_Main_Program
1253 and then not Configurable_Run_Time_Mode
1255 WBI (" procedure Set_Exit_Status (Status : Integer);");
1256 WBI (" pragma Import (C, Set_Exit_Status, " &
1257 """__gnat_set_exit_status"");");
1261 -- Initialize and Finalize
1263 if not Cumulative_Restrictions.Set (No_Finalization) then
1264 WBI (" procedure initialize (Addr : System.Address);");
1265 WBI (" pragma Import (C, initialize, ""__gnat_initialize"");");
1267 WBI (" procedure finalize;");
1268 WBI (" pragma Import (C, finalize, ""__gnat_finalize"");");
1271 -- If we want to analyze the stack, we have to import corresponding
1274 if Dynamic_Stack_Measurement then
1276 WBI (" procedure Output_Results;");
1277 WBI (" pragma Import (C, Output_Results, " &
1278 """__gnat_stack_usage_output_results"");");
1282 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1283 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1284 """__gnat_stack_usage_initialize"");");
1287 -- Deal with declarations for main program case
1289 if not No_Main_Subprogram then
1291 -- To call the main program, we declare it using a pragma Import
1292 -- Ada with the right link name.
1294 -- It might seem more obvious to "with" the main program, and call
1295 -- it in the normal Ada manner. We do not do this for three reasons:
1297 -- 1. It is more efficient not to recompile the main program
1298 -- 2. We are not entitled to assume the source is accessible
1299 -- 3. We don't know what options to use to compile it
1301 -- It is really reason 3 that is most critical (indeed we used
1302 -- to generate the "with", but several regression tests failed).
1306 if ALIs.Table (ALIs.First).Main_Program = Func then
1307 WBI (" Result : Integer;");
1309 WBI (" function Ada_Main_Program return Integer;");
1312 WBI (" procedure Ada_Main_Program;");
1315 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1316 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1317 Set_Main_Program_Name;
1318 Set_String (""");");
1320 Write_Statement_Buffer;
1323 if Bind_Main_Program
1324 and then not Suppress_Standard_Library_On_Target
1326 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1331 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1332 -- not referenced elsewhere in the generated program, but is needed
1333 -- by the debugger (that's why it is generated in the first place).
1334 -- The reference stops Ada_Main_Program_Name from being optimized
1335 -- away by smart linkers, such as the AiX linker.
1337 if Bind_Main_Program then
1339 (" Ensure_Reference : System.Address := " &
1340 "Ada_Main_Program_Name'Address;");
1346 -- Acquire command line arguments if present on target
1348 if Command_Line_Args_On_Target then
1349 WBI (" gnat_argc := argc;");
1350 WBI (" gnat_argv := argv;");
1351 WBI (" gnat_envp := envp;");
1354 -- If configurable run time and no command line args, then nothing
1355 -- needs to be done since the gnat_argc/argv/envp variables are
1356 -- suppressed in this case.
1358 elsif Configurable_Run_Time_On_Target then
1361 -- Otherwise set dummy values (to be filled in by some other unit?)
1364 WBI (" gnat_argc := 0;");
1365 WBI (" gnat_argv := System.Null_Address;");
1366 WBI (" gnat_envp := System.Null_Address;");
1369 if Opt.Default_Exit_Status /= 0
1370 and then Bind_Main_Program
1371 and then not Configurable_Run_Time_Mode
1373 Set_String (" Set_Exit_Status (");
1374 Set_Int (Opt.Default_Exit_Status);
1376 Write_Statement_Buffer;
1379 if Dynamic_Stack_Measurement then
1380 Set_String (" Initialize_Stack_Analysis (");
1381 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1383 Write_Statement_Buffer;
1386 if not Cumulative_Restrictions.Set (No_Finalization) then
1388 if not No_Main_Subprogram
1389 and then Bind_Main_Program
1390 and then not Suppress_Standard_Library_On_Target
1392 WBI (" Initialize (SEH'Address);");
1394 WBI (" Initialize (System.Null_Address);");
1398 WBI (" " & Ada_Init_Name.all & ";");
1400 if not No_Main_Subprogram then
1401 WBI (" Break_Start;");
1403 if ALIs.Table (ALIs.First).Main_Program = Proc then
1404 WBI (" Ada_Main_Program;");
1406 WBI (" Result := Ada_Main_Program;");
1410 -- Adafinal call is skipped if no finalization
1412 if not Cumulative_Restrictions.Set (No_Finalization) then
1414 -- If compiling for the JVM, we directly call Adafinal because
1415 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1417 if Hostparm.Java_VM then
1418 WBI (" System.Standard_Library.Adafinal;");
1420 WBI (" Do_Finalize;");
1424 -- Prints the result of static stack analysis
1426 if Dynamic_Stack_Measurement then
1427 WBI (" Output_Results;");
1430 -- Finalize is only called if we have a run time
1432 if not Cumulative_Restrictions.Set (No_Finalization) then
1438 if Exit_Status_Supported_On_Target then
1439 if No_Main_Subprogram
1440 or else ALIs.Table (ALIs.First).Main_Program = Proc
1442 WBI (" return (gnat_exit_status);");
1444 WBI (" return (Result);");
1455 procedure Gen_Main_C is
1457 if Exit_Status_Supported_On_Target then
1458 WBI ("#include <stdlib.h>");
1459 Set_String ("int ");
1461 Set_String ("void ");
1464 Set_String (Get_Main_Name);
1466 -- Generate command line args in prototype if present on target
1468 if Command_Line_Args_On_Target then
1469 Write_Statement_Buffer (" (int argc, char **argv, char **envp)");
1471 -- Case of no command line arguments on target
1474 Write_Statement_Buffer (" ()");
1479 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1480 -- is not referenced elsewhere in the generated program, but is
1481 -- needed by the debugger (that's why it is generated in the first
1482 -- place). The reference stops Ada_Main_Program_Name from being
1483 -- optimized away by smart linkers, such as the AiX linker.
1485 if Bind_Main_Program then
1486 WBI (" char *ensure_reference __attribute__ ((__unused__)) = " &
1487 "__gnat_ada_main_program_name;");
1490 if not Suppress_Standard_Library_On_Target
1491 and then not No_Main_Subprogram
1493 WBI (" int SEH [2];");
1498 -- If main program is a function, generate result variable
1500 if ALIs.Table (ALIs.First).Main_Program = Func then
1501 WBI (" int result;");
1504 -- Set command line argument values from parameters if command line
1505 -- arguments are present on target
1507 if Command_Line_Args_On_Target then
1508 WBI (" gnat_argc = argc;");
1509 WBI (" gnat_argv = argv;");
1510 WBI (" gnat_envp = envp;");
1513 -- If configurable run-time, then nothing to do, since in this case
1514 -- the gnat_argc/argv/envp variables are entirely suppressed.
1516 elsif Configurable_Run_Time_On_Target then
1519 -- if no command line arguments on target, set dummy values
1522 WBI (" int result;");
1523 WBI (" gnat_argc = 0;");
1524 WBI (" gnat_argv = 0;");
1525 WBI (" gnat_envp = 0;");
1528 if Opt.Default_Exit_Status /= 0
1529 and then Bind_Main_Program
1530 and then not Configurable_Run_Time_Mode
1532 Set_String (" __gnat_set_exit_status (");
1533 Set_Int (Opt.Default_Exit_Status);
1535 Write_Statement_Buffer;
1538 -- Initializes dynamic stack measurement if needed
1540 if Dynamic_Stack_Measurement then
1541 Set_String (" __gnat_stack_usage_initialize (");
1542 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1544 Write_Statement_Buffer;
1547 -- The __gnat_initialize routine is used only if we have a run-time
1549 if not Suppress_Standard_Library_On_Target then
1550 if not No_Main_Subprogram and then Bind_Main_Program then
1551 WBI (" __gnat_initialize ((void *)SEH);");
1553 WBI (" __gnat_initialize ((void *)0);");
1557 WBI (" " & Ada_Init_Name.all & " ();");
1559 if not No_Main_Subprogram then
1560 WBI (" __gnat_break_start ();");
1563 -- Output main program name
1565 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1567 -- Main program is procedure case
1569 if ALIs.Table (ALIs.First).Main_Program = Proc then
1571 Set_Main_Program_Name;
1572 Set_String (" ();");
1573 Write_Statement_Buffer;
1575 -- Main program is function case
1577 else -- ALIs.Table (ALIs_First).Main_Program = Func
1578 Set_String (" result = ");
1579 Set_Main_Program_Name;
1580 Set_String (" ();");
1581 Write_Statement_Buffer;
1586 -- Call adafinal if finalization active
1588 if not Cumulative_Restrictions.Set (No_Finalization) then
1590 WBI (" system__standard_library__adafinal ();");
1593 -- Outputs the dynamic stack measurement if needed
1595 if Dynamic_Stack_Measurement then
1596 WBI (" __gnat_stack_usage_output_results ();");
1599 -- The finalize routine is used only if we have a run-time
1601 if not Suppress_Standard_Library_On_Target then
1602 WBI (" __gnat_finalize ();");
1605 -- Case of main program is a function, so the value it returns
1606 -- is the exit status in this case.
1608 if ALIs.Table (ALIs.First).Main_Program = Func then
1609 if Exit_Status_Supported_On_Target then
1611 -- VMS must use Posix exit routine in order to get the effect
1612 -- of a Unix compatible setting of the program exit status.
1613 -- For all other systems, we use the standard exit routine.
1615 if OpenVMS_On_Target then
1616 WBI (" decc$__posix_exit (result);");
1618 WBI (" exit (result);");
1622 -- Case of main program is a procedure, in which case the exit
1623 -- status is whatever was set by a Set_Exit call most recently
1626 if Exit_Status_Supported_On_Target then
1628 -- VMS must use Posix exit routine in order to get the effect
1629 -- of a Unix compatible setting of the program exit status.
1630 -- For all other systems, we use the standard exit routine.
1632 if OpenVMS_On_Target then
1633 WBI (" decc$__posix_exit (gnat_exit_status);");
1635 WBI (" exit (gnat_exit_status);");
1643 ------------------------------
1644 -- Gen_Object_Files_Options --
1645 ------------------------------
1647 procedure Gen_Object_Files_Options is
1649 -- This keeps track of the position in the sorted set of entries
1650 -- in the Linker_Options table of where the first entry from an
1651 -- internal file appears.
1653 procedure Write_Linker_Option;
1654 -- Write binder info linker option
1656 -------------------------
1657 -- Write_Linker_Option --
1658 -------------------------
1660 procedure Write_Linker_Option is
1665 -- Loop through string, breaking at null's
1668 while Start < Name_Len loop
1670 -- Find null ending this section
1673 while Name_Buffer (Stop) /= ASCII.NUL
1674 and then Stop <= Name_Len loop
1678 -- Process section if non-null
1680 if Stop > Start then
1681 if Output_Linker_Option_List then
1682 Write_Str (Name_Buffer (Start .. Stop - 1));
1686 (" -- ", "", Name_Buffer (Start .. Stop - 1));
1691 end Write_Linker_Option;
1693 -- Start of processing for Gen_Object_Files_Options
1697 Write_Info_Ada_C ("-- ", "/* ", " BEGIN Object file/option list");
1699 for E in Elab_Order.First .. Elab_Order.Last loop
1701 -- If not spec that has an associated body, then generate a
1702 -- comment giving the name of the corresponding object file.
1704 if (not Units.Table (Elab_Order.Table (E)).SAL_Interface)
1705 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1709 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1711 -- If the presence of an object file is necessary or if it
1712 -- exists, then use it.
1714 if not Hostparm.Exclude_Missing_Objects
1715 or else GNAT.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1717 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1719 if Output_Object_List then
1720 Write_Str (Name_Buffer (1 .. Name_Len));
1724 -- Don't link with the shared library on VMS if an internal
1725 -- filename object is seen. Multiply defined symbols will
1728 if OpenVMS_On_Target
1729 and then Is_Internal_File_Name
1731 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
1733 -- Special case for g-trasym.obj, which is not included
1736 Get_Name_String (ALIs.Table
1737 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
1739 if Name_Buffer (1 .. 8) /= "g-trasym" then
1740 Opt.Shared_Libgnat := False;
1747 -- Add a "-Ldir" for each directory in the object path
1749 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1751 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1754 Add_Str_To_Name_Buffer ("-L");
1755 Add_Str_To_Name_Buffer (Dir.all);
1756 Write_Linker_Option;
1760 -- Sort linker options
1762 -- This sort accomplishes two important purposes:
1764 -- a) All application files are sorted to the front, and all
1765 -- GNAT internal files are sorted to the end. This results
1766 -- in a well defined dividing line between the two sets of
1767 -- files, for the purpose of inserting certain standard
1768 -- library references into the linker arguments list.
1770 -- b) Given two different units, we sort the linker options so
1771 -- that those from a unit earlier in the elaboration order
1772 -- comes later in the list. This is a heuristic designed
1773 -- to create a more friendly order of linker options when
1774 -- the operations appear in separate units. The idea is that
1775 -- if unit A must be elaborated before unit B, then it is
1776 -- more likely that B references libraries included by A,
1777 -- than vice versa, so we want the libraries included by
1778 -- A to come after the libraries included by B.
1780 -- These two criteria are implemented by function Lt_Linker_Option.
1781 -- Note that a special case of b) is that specs are elaborated before
1782 -- bodies, so linker options from specs come after linker options
1783 -- for bodies, and again, the assumption is that libraries used by
1784 -- the body are more likely to reference libraries used by the spec,
1788 (Linker_Options.Last,
1789 Move_Linker_Option'Access,
1790 Lt_Linker_Option'Access);
1792 -- Write user linker options, i.e. the set of linker options that
1793 -- come from all files other than GNAT internal files, Lgnat is
1794 -- left set to point to the first entry from a GNAT internal file,
1795 -- or past the end of the entriers if there are no internal files.
1797 Lgnat := Linker_Options.Last + 1;
1799 for J in 1 .. Linker_Options.Last loop
1800 if not Linker_Options.Table (J).Internal_File then
1801 Get_Name_String (Linker_Options.Table (J).Name);
1802 Write_Linker_Option;
1809 -- Now we insert standard linker options that must appear after the
1810 -- entries from user files, and before the entries from GNAT run-time
1811 -- files. The reason for this decision is that libraries referenced
1812 -- by internal routines may reference these standard library entries.
1814 if not Opt.No_Stdlib then
1817 if Opt.Shared_Libgnat then
1818 Add_Str_To_Name_Buffer ("-shared");
1820 Add_Str_To_Name_Buffer ("-static");
1823 -- Write directly to avoid -K output (why???)
1825 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1827 if With_DECGNAT then
1829 Add_Str_To_Name_Buffer ("-ldecgnat");
1830 Write_Linker_Option;
1836 if Opt.Shared_Libgnat then
1837 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1839 Add_Str_To_Name_Buffer ("-lgnarl");
1842 Write_Linker_Option;
1847 if Opt.Shared_Libgnat then
1848 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1850 Add_Str_To_Name_Buffer ("-lgnat");
1853 Write_Linker_Option;
1856 -- Write linker options from all internal files
1858 for J in Lgnat .. Linker_Options.Last loop
1859 Get_Name_String (Linker_Options.Table (J).Name);
1860 Write_Linker_Option;
1863 if Ada_Bind_File then
1864 WBI ("-- END Object file/option list ");
1866 WBI (" END Object file/option list */");
1868 end Gen_Object_Files_Options;
1870 ---------------------
1871 -- Gen_Output_File --
1872 ---------------------
1874 procedure Gen_Output_File (Filename : String) is
1875 Is_Public_Version : constant Boolean := Get_Gnat_Build_Type = Public;
1876 Is_GAP_Version : constant Boolean := Get_Gnat_Build_Type = GAP;
1879 -- Acquire settings for Interrupt_State pragmas
1881 Set_IS_Pragma_Table;
1883 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1884 -- JGNAT only supports Ada code, and the main program is already
1885 -- generated by the compiler.
1887 if Hostparm.Java_VM then
1888 Ada_Bind_File := True;
1889 Bind_Main_Program := False;
1892 -- Override time slice value if -T switch is set
1894 if Time_Slice_Set then
1895 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
1898 -- Count number of elaboration calls
1900 for E in Elab_Order.First .. Elab_Order.Last loop
1901 if Units.Table (Elab_Order.Table (E)).No_Elab then
1904 Num_Elab_Calls := Num_Elab_Calls + 1;
1908 -- Get the time stamp of the former bind for public version warning
1910 if Is_Public_Version or Is_GAP_Version then
1911 Record_Time_From_Last_Bind;
1914 -- Generate output file in appropriate language
1916 if Ada_Bind_File then
1917 Gen_Output_File_Ada (Filename);
1919 Gen_Output_File_C (Filename);
1922 -- Periodically issue a warning when the public version is used on
1925 if Is_Public_Version then
1926 Public_Version_Warning;
1928 end Gen_Output_File;
1930 -------------------------
1931 -- Gen_Output_File_Ada --
1932 -------------------------
1934 procedure Gen_Output_File_Ada (Filename : String) is
1937 -- Name of generated bind file (spec)
1940 -- Name of generated bind file (body)
1942 Ada_Main : constant String := Get_Ada_Main_Name;
1943 -- Name to be used for generated Ada main program. See the body of
1944 -- function Get_Ada_Main_Name for details on the form of the name.
1947 -- Create spec first
1949 Create_Binder_Output (Filename, 's', Bfiles);
1951 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
1952 -- then we need to make sure that the binder program is compiled with
1953 -- the same restriction, so that no exception tables are generated.
1955 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
1956 WBI ("pragma Restrictions (No_Exception_Handlers);");
1959 -- Generate with of System so we can reference System.Address
1961 WBI ("with System;");
1963 -- Generate with of System.Initialize_Scalars if active
1965 if Initialize_Scalars_Used then
1966 WBI ("with System.Scalar_Values;");
1969 -- Generate with of System.Secondary_Stack if active
1971 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1972 WBI ("with System.Secondary_Stack;");
1975 Resolve_Binder_Options;
1977 if not Suppress_Standard_Library_On_Target then
1979 -- Usually, adafinal is called using a pragma Import C. Since
1980 -- Import C doesn't have the same semantics for JGNAT, we use
1983 if Hostparm.Java_VM then
1984 WBI ("with System.Standard_Library;");
1988 WBI ("package " & Ada_Main & " is");
1989 WBI (" pragma Warnings (Off);");
1991 -- Main program case
1993 if Bind_Main_Program then
1995 -- Generate argc/argv stuff unless suppressed
1997 if Command_Line_Args_On_Target
1998 or not Configurable_Run_Time_On_Target
2001 WBI (" gnat_argc : Integer;");
2002 WBI (" gnat_argv : System.Address;");
2003 WBI (" gnat_envp : System.Address;");
2005 -- If the standard library is not suppressed, these variables are
2006 -- in the runtime data area for easy access from the runtime
2008 if not Suppress_Standard_Library_On_Target then
2010 WBI (" pragma Import (C, gnat_argc);");
2011 WBI (" pragma Import (C, gnat_argv);");
2012 WBI (" pragma Import (C, gnat_envp);");
2016 -- Define exit status. Again in normal mode, this is in the
2017 -- run-time library, and is initialized there, but in the
2018 -- configurable runtime case, the variable is declared and
2019 -- initialized in this file.
2023 if Configurable_Run_Time_Mode then
2024 if Exit_Status_Supported_On_Target then
2025 WBI (" gnat_exit_status : Integer := 0;");
2028 WBI (" gnat_exit_status : Integer;");
2029 WBI (" pragma Import (C, gnat_exit_status);");
2033 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2034 -- the main program. Otherwise, it can lead under some circumstances
2035 -- to a symbol duplication during the link (for instance when a
2036 -- C program uses 2 Ada libraries)
2038 if Bind_Main_Program then
2040 WBI (" GNAT_Version : constant String :=");
2041 WBI (" ""GNAT Version: " &
2042 Gnat_Version_String & """;");
2043 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2046 Set_String (" Ada_Main_Program_Name : constant String := """);
2047 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2048 Set_Main_Program_Name;
2049 Set_String (""" & Ascii.NUL;");
2050 Write_Statement_Buffer;
2053 (" pragma Export (C, Ada_Main_Program_Name, " &
2054 """__gnat_ada_main_program_name"");");
2058 WBI (" procedure " & Ada_Final_Name.all & ";");
2059 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2060 Ada_Final_Name.all & """);");
2062 if Use_Pragma_Linker_Constructor then
2063 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2067 WBI (" procedure " & Ada_Init_Name.all & ";");
2068 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2069 Ada_Init_Name.all & """);");
2071 if Use_Pragma_Linker_Constructor then
2072 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2075 if Bind_Main_Program then
2077 -- If we have the standard library, then Break_Start is defined
2078 -- there, but when the standard library is suppressed, Break_Start
2082 WBI (" procedure Break_Start;");
2084 if Suppress_Standard_Library_On_Target then
2085 WBI (" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2087 WBI (" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2092 if Exit_Status_Supported_On_Target then
2093 Set_String (" function ");
2095 Set_String (" procedure ");
2098 Set_String (Get_Main_Name);
2100 -- Generate argument list if present
2102 if Command_Line_Args_On_Target then
2103 Write_Statement_Buffer;
2104 WBI (" (argc : Integer;");
2105 WBI (" argv : System.Address;");
2107 (" envp : System.Address)");
2109 if Exit_Status_Supported_On_Target then
2110 Write_Statement_Buffer;
2111 WBI (" return Integer;");
2113 Write_Statement_Buffer (";");
2117 if Exit_Status_Supported_On_Target then
2118 Write_Statement_Buffer (" return Integer;");
2120 Write_Statement_Buffer (";");
2124 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2125 Get_Main_Name & """);");
2134 WBI ("end " & Ada_Main & ";");
2135 Close_Binder_Output;
2137 -- Prepare to write body
2139 Create_Binder_Output (Filename, 'b', Bfileb);
2141 -- Output Source_File_Name pragmas which look like
2143 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2144 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2146 -- where sss/bbb are the spec/body file names respectively
2148 Get_Name_String (Bfiles);
2149 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2151 WBI ("pragma Source_File_Name (" &
2153 ", Spec_File_Name => """ &
2154 Name_Buffer (1 .. Name_Len + 3));
2156 Get_Name_String (Bfileb);
2157 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2159 WBI ("pragma Source_File_Name (" &
2161 ", Body_File_Name => """ &
2162 Name_Buffer (1 .. Name_Len + 3));
2165 WBI ("package body " & Ada_Main & " is");
2166 WBI (" pragma Warnings (Off);");
2168 -- Import the finalization procedure only if finalization active
2170 if not Cumulative_Restrictions.Set (No_Finalization) then
2172 -- In the Java case, pragma Import C cannot be used, so the
2173 -- standard Ada constructs will be used instead.
2175 if not Hostparm.Java_VM then
2177 WBI (" procedure Do_Finalize;");
2179 (" pragma Import (C, Do_Finalize, " &
2180 """system__standard_library__adafinal"");");
2189 if Bind_Main_Program then
2191 -- When suppressing the standard library then generate dummy body
2194 if Suppress_Standard_Library_On_Target then
2196 WBI (" procedure Break_Start is");
2205 -- Output object file list and the Ada body is complete
2207 Gen_Object_Files_Options;
2210 WBI ("end " & Ada_Main & ";");
2212 Close_Binder_Output;
2213 end Gen_Output_File_Ada;
2215 -----------------------
2216 -- Gen_Output_File_C --
2217 -----------------------
2219 procedure Gen_Output_File_C (Filename : String) is
2222 -- Name of generated bind file
2225 Create_Binder_Output (Filename, 'c', Bfile);
2227 Resolve_Binder_Options;
2229 WBI ("extern void __gnat_set_globals");
2230 WBI (" (int, int, char, char, char, char,");
2231 WBI (" const char *, const char *,");
2232 WBI (" int, int, int, int, int);");
2234 if Use_Pragma_Linker_Constructor then
2235 WBI ("extern void " & Ada_Final_Name.all &
2236 " (void) __attribute__((destructor));");
2237 WBI ("extern void " & Ada_Init_Name.all &
2238 " (void) __attribute__((constructor));");
2241 WBI ("extern void " & Ada_Final_Name.all & " (void);");
2242 WBI ("extern void " & Ada_Init_Name.all & " (void);");
2245 WBI ("extern void system__standard_library__adafinal (void);");
2247 if not No_Main_Subprogram then
2248 Set_String ("extern ");
2250 if Exit_Status_Supported_On_Target then
2253 Set_String ("void");
2256 Set_String (" main ");
2258 if Command_Line_Args_On_Target then
2259 Write_Statement_Buffer ("(int, char **, char **);");
2261 Write_Statement_Buffer ("(void);");
2264 if OpenVMS_On_Target then
2265 WBI ("extern void decc$__posix_exit (int);");
2267 WBI ("extern void exit (int);");
2270 WBI ("extern void __gnat_break_start (void);");
2271 Set_String ("extern ");
2273 if ALIs.Table (ALIs.First).Main_Program = Proc then
2274 Set_String ("void ");
2276 Set_String ("int ");
2279 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2280 Set_Main_Program_Name;
2281 Set_String (" (void);");
2282 Write_Statement_Buffer;
2285 if not Suppress_Standard_Library_On_Target then
2286 WBI ("extern void __gnat_initialize (void *);");
2287 WBI ("extern void __gnat_finalize (void);");
2288 WBI ("extern void __gnat_install_handler (void);");
2291 if Dynamic_Stack_Measurement then
2293 WBI ("extern void __gnat_stack_usage_output_results (void);");
2294 WBI ("extern void __gnat_stack_usage_initialize (int size);");
2301 -- Imported variable used to track elaboration/finalization phase.
2302 -- Used only when we have a runtime.
2304 if not Suppress_Standard_Library_On_Target then
2305 WBI ("extern int __gnat_handler_installed;");
2309 -- Write argv/argc exit status stuff if main program case
2311 if Bind_Main_Program then
2313 -- First deal with argc/argv/envp. In the normal case they
2314 -- are in the run-time library.
2316 if not Configurable_Run_Time_On_Target then
2317 WBI ("extern int gnat_argc;");
2318 WBI ("extern char **gnat_argv;");
2319 WBI ("extern char **gnat_envp;");
2321 -- If configurable run time and no command line args, then the
2322 -- generation of these variables is entirely suppressed.
2324 elsif not Command_Line_Args_On_Target then
2327 -- Otherwise, in the configurable run-time case they are right in
2331 WBI ("int gnat_argc;");
2332 WBI ("char **gnat_argv;");
2333 WBI ("char **gnat_envp;");
2336 -- Similarly deal with exit status
2337 -- are in the run-time library.
2339 if not Configurable_Run_Time_On_Target then
2340 WBI ("extern int gnat_exit_status;");
2342 -- If configurable run time and no exit status on target, then
2343 -- the generation of this variables is entirely suppressed.
2345 elsif not Exit_Status_Supported_On_Target then
2348 -- Otherwise, in the configurable run-time case this variable is
2349 -- right in the binder file, and initialized to zero there.
2352 WBI ("int gnat_exit_status = 0;");
2358 -- When suppressing the standard library, the __gnat_break_start
2359 -- routine (for the debugger to get initial control) is defined in
2362 if Suppress_Standard_Library_On_Target then
2364 WBI ("void __gnat_break_start () {}");
2367 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2368 -- only for the main program. Otherwise, it can lead under some
2369 -- circumstances to a symbol duplication during the link (for instance
2370 -- when a C program uses 2 Ada libraries)
2372 if Bind_Main_Program then
2374 WBI ("char __gnat_version[] = ""GNAT Version: " &
2375 Gnat_Version_String & """;");
2377 Set_String ("char __gnat_ada_main_program_name[] = """);
2378 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2379 Set_Main_Program_Name;
2381 Write_Statement_Buffer;
2384 -- Generate the adafinal routine. In no runtime mode, this is
2385 -- not needed, since there is no finalization to do.
2387 if not Cumulative_Restrictions.Set (No_Finalization) then
2393 -- Main is only present for Ada main case
2395 if Bind_Main_Program then
2399 -- Generate versions, elaboration order, list of object files
2403 Gen_Object_Files_Options;
2405 -- C binder output is complete
2407 Close_Binder_Output;
2408 end Gen_Output_File_C;
2410 -------------------------------
2411 -- Gen_Restrictions_String_1 --
2412 -------------------------------
2414 procedure Gen_Restrictions_String_1 is
2416 for R in All_Boolean_Restrictions loop
2417 if Cumulative_Restrictions.Set (R) then
2419 elsif Cumulative_Restrictions.Violated (R) then
2425 end Gen_Restrictions_String_1;
2427 -------------------------------
2428 -- Gen_Restrictions_String_2 --
2429 -------------------------------
2431 procedure Gen_Restrictions_String_2 is
2433 for RP in All_Parameter_Restrictions loop
2434 if Cumulative_Restrictions.Set (RP) then
2436 Set_Int (Int (Cumulative_Restrictions.Value (RP)));
2441 if not Cumulative_Restrictions.Violated (RP)
2442 or else RP not in Checked_Parameter_Restrictions
2447 Set_Int (Int (Cumulative_Restrictions.Count (RP)));
2449 if Cumulative_Restrictions.Unknown (RP) then
2454 end Gen_Restrictions_String_2;
2456 ----------------------
2457 -- Gen_Versions_Ada --
2458 ----------------------
2460 -- This routine generates two sets of lines. The first set has the form:
2462 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2464 -- The second set has the form
2466 -- pragma Export (C, unnnnn, unam);
2468 -- for each unit, where unam is the unit name suffixed by either B or
2469 -- S for body or spec, with dots replaced by double underscores, and
2470 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2472 procedure Gen_Versions_Ada is
2473 Ubuf : String (1 .. 6) := "u00000";
2475 procedure Increment_Ubuf;
2476 -- Little procedure to increment the serial number
2478 procedure Increment_Ubuf is
2480 for J in reverse Ubuf'Range loop
2481 Ubuf (J) := Character'Succ (Ubuf (J));
2482 exit when Ubuf (J) <= '9';
2487 -- Start of processing for Gen_Versions_Ada
2490 if Bind_For_Library then
2492 -- When building libraries, the version number of each unit can
2493 -- not be computed, since the binder does not know the full list
2494 -- of units. Therefore, the 'Version and 'Body_Version
2495 -- attributes cannot supported in this case.
2502 WBI (" type Version_32 is mod 2 ** 32;");
2503 for U in Units.First .. Units.Last loop
2505 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2506 Units.Table (U).Version & "#;");
2512 for U in Units.First .. Units.Last loop
2514 Set_String (" pragma Export (C, ");
2516 Set_String (", """);
2518 Get_Name_String (Units.Table (U).Uname);
2520 for K in 1 .. Name_Len loop
2521 if Name_Buffer (K) = '.' then
2525 elsif Name_Buffer (K) = '%' then
2529 Set_Char (Name_Buffer (K));
2533 if Name_Buffer (Name_Len) = 's' then
2539 Set_String (""");");
2540 Write_Statement_Buffer;
2543 end Gen_Versions_Ada;
2545 --------------------
2546 -- Gen_Versions_C --
2547 --------------------
2549 -- This routine generates a line of the form:
2551 -- unsigned unam = 0xhhhhhhhh;
2553 -- for each unit, where unam is the unit name suffixed by either B or
2554 -- S for body or spec, with dots replaced by double underscores.
2556 procedure Gen_Versions_C is
2558 if Bind_For_Library then
2560 -- When building libraries, the version number of each unit can
2561 -- not be computed, since the binder does not know the full list
2562 -- of units. Therefore, the 'Version and 'Body_Version
2563 -- attributes cannot supported.
2568 for U in Units.First .. Units.Last loop
2569 Set_String ("unsigned ");
2571 Get_Name_String (Units.Table (U).Uname);
2573 for K in 1 .. Name_Len loop
2574 if Name_Buffer (K) = '.' then
2577 elsif Name_Buffer (K) = '%' then
2581 Set_Char (Name_Buffer (K));
2585 if Name_Buffer (Name_Len) = 's' then
2591 Set_String (" = 0x");
2592 Set_String (Units.Table (U).Version);
2594 Write_Statement_Buffer;
2599 -----------------------
2600 -- Get_Ada_Main_Name --
2601 -----------------------
2603 function Get_Ada_Main_Name return String is
2604 Suffix : constant String := "_00";
2605 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2606 Opt.Ada_Main_Name.all & Suffix;
2610 -- The main program generated by JGNAT expects a package called
2611 -- ada_<main procedure>.
2613 if Hostparm.Java_VM then
2614 -- Get main program name
2616 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2620 return "ada_" & Name_Buffer (1 .. Name_Len - 2);
2623 -- This loop tries the following possibilities in order
2629 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2630 -- it is set to 'ada_main'.
2632 for J in 0 .. 99 loop
2634 Nlen := Name'Length - Suffix'Length;
2636 Nlen := Name'Length;
2637 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2638 Name (Name'Last - 1) :=
2639 Character'Val (J / 10 + Character'Pos ('0'));
2642 for K in ALIs.First .. ALIs.Last loop
2643 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2645 -- Get unit name, removing %b or %e at end
2647 Get_Name_String (Units.Table (L).Uname);
2648 Name_Len := Name_Len - 2;
2650 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2656 return Name (1 .. Nlen);
2662 -- If we fall through, just use a peculiar unlikely name
2664 return ("Qwertyuiop");
2665 end Get_Ada_Main_Name;
2671 function Get_Main_Name return String is
2673 -- Explicit name given with -M switch
2675 if Bind_Alternate_Main_Name then
2676 return Alternate_Main_Name.all;
2678 -- Case of main program name to be used directly
2680 elsif Use_Ada_Main_Program_Name_On_Target then
2682 -- Get main program name
2684 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2686 -- If this is a child name, return only the name of the child,
2687 -- since we can't have dots in a nested program name. Note that
2688 -- we do not include the %b at the end of the unit name.
2690 for J in reverse 1 .. Name_Len - 2 loop
2691 if J = 1 or else Name_Buffer (J - 1) = '.' then
2692 return Name_Buffer (J .. Name_Len - 2);
2696 raise Program_Error; -- impossible exit
2698 -- Case where "main" is to be used as default
2705 ----------------------
2706 -- Lt_Linker_Option --
2707 ----------------------
2709 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2711 -- Sort internal files last
2713 if Linker_Options.Table (Op1).Internal_File
2715 Linker_Options.Table (Op2).Internal_File
2717 -- Note: following test uses False < True
2719 return Linker_Options.Table (Op1).Internal_File
2721 Linker_Options.Table (Op2).Internal_File;
2723 -- If both internal or both non-internal, sort according to the
2724 -- elaboration position. A unit that is elaborated later should
2725 -- come earlier in the linker options list.
2728 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2730 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2733 end Lt_Linker_Option;
2735 ------------------------
2736 -- Move_Linker_Option --
2737 ------------------------
2739 procedure Move_Linker_Option (From : Natural; To : Natural) is
2741 Linker_Options.Table (To) := Linker_Options.Table (From);
2742 end Move_Linker_Option;
2744 ----------------------------
2745 -- Public_Version_Warning --
2746 ----------------------------
2748 procedure Public_Version_Warning is
2749 Time : constant Int := Time_From_Last_Bind;
2751 -- Constants to help defining periods
2753 Hour : constant := 60;
2754 Day : constant := 24 * Hour;
2756 Never : constant := Integer'Last;
2757 -- Special value indicating no warnings should be given
2759 -- Constants defining when the warning is issued. Programs with more
2760 -- than Large Units will issue a warning every Period_Large amount of
2761 -- time. Smaller programs will generate a warning every Period_Small
2764 Large : constant := 20;
2765 -- Threshold for considering a program small or large
2767 Period_Large : constant := Day;
2768 -- Periodic warning time for large programs
2770 Period_Small : constant := Never;
2771 -- Periodic warning time for small programs
2776 -- Compute the number of units that are not GNAT internal files
2779 for A in ALIs.First .. ALIs.Last loop
2780 if not Is_Internal_File_Name (ALIs.Table (A).Sfile) then
2781 Nb_Unit := Nb_Unit + 1;
2785 -- Do not emit the message if the last message was emitted in the
2786 -- specified period taking into account the number of units.
2788 pragma Warnings (Off);
2789 -- Turn off warning of constant condition, which may happen here
2790 -- depending on the choice of constants in the above declarations.
2792 if Nb_Unit < Large and then Time <= Period_Small then
2794 elsif Time <= Period_Large then
2798 pragma Warnings (On);
2801 Write_Str ("IMPORTANT NOTICE:");
2803 Write_Str (" This version of GNAT is unsupported"
2804 & " and comes with absolutely no warranty.");
2806 Write_Str (" If you intend to evaluate or use GNAT for building "
2807 & "commercial applications,");
2809 Write_Str (" please consult http://www.gnat.com/ for information");
2811 Write_Str (" on the GNAT Professional product line.");
2814 end Public_Version_Warning;
2816 ----------------------------
2817 -- Resolve_Binder_Options --
2818 ----------------------------
2820 procedure Resolve_Binder_Options is
2822 for E in Elab_Order.First .. Elab_Order.Last loop
2823 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2825 -- The procedure of looking for specific packages and setting
2826 -- flags is somewhat dubious, but there isn't a good alternative
2827 -- at the current time ???
2829 if Name_Buffer (1 .. 19) = "system.os_interface" then
2833 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
2834 With_DECGNAT := True;
2837 end Resolve_Binder_Options;
2843 procedure Set_Char (C : Character) is
2846 Statement_Buffer (Last) := C;
2853 procedure Set_Int (N : Int) is
2865 Statement_Buffer (Last) :=
2866 Character'Val (N mod 10 + Character'Pos ('0'));
2870 -------------------------
2871 -- Set_IS_Pragma_Table --
2872 -------------------------
2874 procedure Set_IS_Pragma_Table is
2876 for F in ALIs.First .. ALIs.Last loop
2877 for K in ALIs.Table (F).First_Interrupt_State ..
2878 ALIs.Table (F).Last_Interrupt_State
2881 Inum : constant Int :=
2882 Interrupt_States.Table (K).Interrupt_Id;
2883 Stat : constant Character :=
2884 Interrupt_States.Table (K).Interrupt_State;
2887 while IS_Pragma_Settings.Last < Inum loop
2888 IS_Pragma_Settings.Append ('n');
2891 IS_Pragma_Settings.Table (Inum) := Stat;
2895 end Set_IS_Pragma_Table;
2897 ---------------------------
2898 -- Set_Main_Program_Name --
2899 ---------------------------
2901 procedure Set_Main_Program_Name is
2903 -- Note that name has %b on the end which we ignore
2905 -- First we output the initial _ada_ since we know that the main
2906 -- program is a library level subprogram.
2908 Set_String ("_ada_");
2910 -- Copy name, changing dots to double underscores
2912 for J in 1 .. Name_Len - 2 loop
2913 if Name_Buffer (J) = '.' then
2916 Set_Char (Name_Buffer (J));
2919 end Set_Main_Program_Name;
2921 ---------------------
2922 -- Set_Name_Buffer --
2923 ---------------------
2925 procedure Set_Name_Buffer is
2927 for J in 1 .. Name_Len loop
2928 Set_Char (Name_Buffer (J));
2930 end Set_Name_Buffer;
2936 procedure Set_String (S : String) is
2938 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
2939 Last := Last + S'Length;
2946 procedure Set_Unit_Name is
2948 for J in 1 .. Name_Len - 2 loop
2949 if Name_Buffer (J) /= '.' then
2950 Set_Char (Name_Buffer (J));
2957 ---------------------
2958 -- Set_Unit_Number --
2959 ---------------------
2961 procedure Set_Unit_Number (U : Unit_Id) is
2962 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
2963 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
2966 if Num_Units >= 10 and then Unum < 10 then
2970 if Num_Units >= 100 and then Unum < 100 then
2975 end Set_Unit_Number;
2981 procedure Tab_To (N : Natural) is
2988 ----------------------
2989 -- Write_Info_Ada_C --
2990 ----------------------
2992 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String) is
2994 if Ada_Bind_File then
2996 S : String (1 .. Ada'Length + Common'Length);
2998 S (1 .. Ada'Length) := Ada;
2999 S (Ada'Length + 1 .. S'Length) := Common;
3005 S : String (1 .. C'Length + Common'Length);
3007 S (1 .. C'Length) := C;
3008 S (C'Length + 1 .. S'Length) := Common;
3012 end Write_Info_Ada_C;
3014 ----------------------------
3015 -- Write_Statement_Buffer --
3016 ----------------------------
3018 procedure Write_Statement_Buffer is
3020 WBI (Statement_Buffer (1 .. Last));
3022 end Write_Statement_Buffer;
3024 procedure Write_Statement_Buffer (S : String) is
3027 Write_Statement_Buffer;
3028 end Write_Statement_Buffer;