1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Butil; use Butil;
30 with Casing; use Casing;
31 with Fname; use Fname;
32 with GNAT.OS_Lib; use GNAT.OS_Lib;
33 with Gnatvsn; use Gnatvsn;
35 with Namet; use Namet;
37 with Osint; use Osint;
38 with Osint.B; use Osint.B;
39 with Output; use Output;
40 with Rident; use Rident;
41 with Table; use Table;
42 with Targparm; use Targparm;
43 with Types; use Types;
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 ----------------------------------
67 -- Interface_State Pragma Table --
68 ----------------------------------
70 -- This table assembles the interface state pragma information from
71 -- all the units in the partition. Note that Bcheck has already checked
72 -- that the information is consistent across partitions. The entries
73 -- in this table are n/u/r/s for not set/user/runtime/system.
75 package IS_Pragma_Settings is new Table.Table (
76 Table_Component_Type => Character,
77 Table_Index_Type => Int,
80 Table_Increment => 200,
81 Table_Name => "IS_Pragma_Settings");
83 -----------------------
84 -- Local Subprograms --
85 -----------------------
87 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
88 -- Convenient shorthand used throughout
90 procedure Gen_Adainit_Ada;
91 -- Generates the Adainit procedure (Ada code case)
93 procedure Gen_Adainit_C;
94 -- Generates the Adainit procedure (C code case)
96 procedure Gen_Adafinal_Ada;
97 -- Generate the Adafinal procedure (Ada code case)
99 procedure Gen_Adafinal_C;
100 -- Generate the Adafinal procedure (C code case)
102 procedure Gen_Elab_Calls_Ada;
103 -- Generate sequence of elaboration calls (Ada code case)
105 procedure Gen_Elab_Calls_C;
106 -- Generate sequence of elaboration calls (C code case)
108 procedure Gen_Elab_Order_Ada;
109 -- Generate comments showing elaboration order chosen (Ada case)
111 procedure Gen_Elab_Order_C;
112 -- Generate comments showing elaboration order chosen (C case)
114 procedure Gen_Elab_Defs_C;
115 -- Generate sequence of definitions for elaboration routines (C code case)
117 procedure Gen_Exception_Table_Ada;
118 -- Generate binder exception table (Ada code case). This consists of
119 -- declarations followed by a begin followed by a call. If zero cost
120 -- exceptions are not active, then only the begin is generated.
122 procedure Gen_Exception_Table_C;
123 -- Generate binder exception table (C code case). This has no effect
124 -- if zero cost exceptions are not active, otherwise it generates a
125 -- set of declarations followed by a call.
127 procedure Gen_Main_Ada;
128 -- Generate procedure main (Ada code case)
130 procedure Gen_Main_C;
131 -- Generate main() procedure (C code case)
133 procedure Gen_Object_Files_Options;
134 -- Output comments containing a list of the full names of the object
135 -- files to be linked and the list of linker options supplied by
136 -- Linker_Options pragmas in the source. (C and Ada code case)
138 procedure Gen_Output_File_Ada (Filename : String);
139 -- Generate output file (Ada code case)
141 procedure Gen_Output_File_C (Filename : String);
142 -- Generate output file (C code case)
144 procedure Gen_Versions_Ada;
145 -- Output series of definitions for unit versions (Ada code case)
147 procedure Gen_Versions_C;
148 -- Output series of definitions for unit versions (C code case)
150 function Get_Ada_Main_Name return String;
151 -- This function is used in the Ada main output case to compute a usable
152 -- name for the generated main program. The normal main program name is
153 -- Ada_Main, but this won't work if the user has a unit with this name.
154 -- This function tries Ada_Main first, and if there is such a clash, then
155 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
157 function Get_Main_Name return String;
158 -- This function is used in the Ada main output case to compute the
159 -- correct external main program. It is "main" by default, unless the
160 -- flag Use_Ada_Main_Program_Name_On_Target is set, in which case it
161 -- is the name of the Ada main name without the "_ada". This default
162 -- can be overridden explicitly using the -Mname binder switch.
164 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
165 -- Compare linker options, when sorting, first according to
166 -- Is_Internal_File (internal files come later) and then by
167 -- elaboration order position (latest to earliest).
169 procedure Move_Linker_Option (From : Natural; To : Natural);
170 -- Move routine for sorting linker options
172 procedure Public_Version_Warning;
173 -- Emit a warning concerning the use of the Public version under
174 -- certain circumstances. See details in body.
176 procedure Resolve_Binder_Options;
177 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
178 -- since it tests for a package named "dec" which might cause a conflict
179 -- on non-VMS systems.
181 procedure Set_Char (C : Character);
182 -- Set given character in Statement_Buffer at the Last + 1 position
183 -- and increment Last by one to reflect the stored character.
185 procedure Set_Int (N : Int);
186 -- Set given value in decimal in Statement_Buffer with no spaces
187 -- starting at the Last + 1 position, and updating Last past the value.
188 -- A minus sign is output for a negative value.
190 procedure Set_IS_Pragma_Table;
191 -- Initializes contents of IS_Pragma_Settings table from ALI table
193 procedure Set_Main_Program_Name;
194 -- Given the main program name in Name_Buffer (length in Name_Len)
195 -- generate the name of the routine to be used in the call. The name
196 -- is generated starting at Last + 1, and Last is updated past it.
198 procedure Set_Name_Buffer;
199 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer.
201 procedure Set_String (S : String);
202 -- Sets characters of given string in Statement_Buffer, starting at the
203 -- Last + 1 position, and updating last past the string value.
205 procedure Set_Unit_Name;
206 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
207 -- starting at the Last + 1 position, and updating last past the value.
208 -- changing periods to double underscores, and updating Last appropriately.
210 procedure Set_Unit_Number (U : Unit_Id);
211 -- Sets unit number (first unit is 1, leading zeroes output to line
212 -- up all output unit numbers nicely as required by the value, and
213 -- by the total number of units.
215 procedure Tab_To (N : Natural);
216 -- If Last is greater than or equal to N, no effect, otherwise store
217 -- blanks in Statement_Buffer bumping Last, until Last = N.
219 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String);
220 -- For C code case, write C & Common, for Ada case write Ada & Common
221 -- to current binder output file using Write_Binder_Info.
223 procedure Write_Statement_Buffer;
224 -- Write out contents of statement buffer up to Last, and reset Last to 0
226 procedure Write_Statement_Buffer (S : String);
227 -- First writes its argument (using Set_String (S)), then writes out the
228 -- contents of statement buffer up to Last, and reset Last to 0
230 ----------------------
231 -- Gen_Adafinal_Ada --
232 ----------------------
234 procedure Gen_Adafinal_Ada is
237 WBI (" procedure " & Ada_Final_Name.all & " is");
240 -- If compiling for the JVM, we directly call Adafinal because
241 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
243 if Hostparm.Java_VM then
244 WBI (" System.Standard_Library.Adafinal;");
246 WBI (" Do_Finalize;");
249 WBI (" end " & Ada_Final_Name.all & ";");
250 end Gen_Adafinal_Ada;
256 procedure Gen_Adafinal_C is
258 WBI ("void " & Ada_Final_Name.all & " () {");
259 WBI (" system__standard_library__adafinal ();");
264 ---------------------
265 -- Gen_Adainit_Ada --
266 ---------------------
268 procedure Gen_Adainit_Ada is
269 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
272 WBI (" procedure " & Ada_Init_Name.all & " is");
274 -- Generate externals for elaboration entities
276 for E in Elab_Order.First .. Elab_Order.Last loop
278 Unum : constant Unit_Id := Elab_Order.Table (E);
279 U : Unit_Record renames Units.Table (Unum);
282 if U.Set_Elab_Entity and then not U.Interface then
285 Set_Unit_Number (Unum);
286 Set_String (" : Boolean; pragma Import (Ada, ");
288 Set_Unit_Number (Unum);
290 Get_Name_String (U.Uname);
292 -- In the case of JGNAT we need to emit an Import name
293 -- that includes the class name (using '$' separators
294 -- in the case of a child unit name).
296 if Hostparm.Java_VM then
297 for J in 1 .. Name_Len - 2 loop
298 if Name_Buffer (J) /= '.' then
299 Set_Char (Name_Buffer (J));
307 -- If the unit name is very long, then split the
308 -- Import link name across lines using "&" (occurs
309 -- in some C2 tests).
311 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
313 Write_Statement_Buffer;
319 Set_String ("_E"");");
320 Write_Statement_Buffer;
325 Write_Statement_Buffer;
327 -- If the standard library is suppressed, then the only global variable
328 -- that might be needed (by the Ravenscar profile) is the priority of
329 -- the environment. Also no exception tables are needed.
331 if Suppress_Standard_Library_On_Target then
332 if Main_Priority /= No_Main_Priority then
333 WBI (" Main_Priority : Integer;");
334 WBI (" pragma Import (C, Main_Priority," &
335 " ""__gl_main_priority"");");
341 if Main_Priority /= No_Main_Priority then
342 Set_String (" Main_Priority := ");
343 Set_Int (Main_Priority);
345 Write_Statement_Buffer;
351 -- Normal case (standard library not suppressed). Global values are
352 -- assigned using the runtime routine Set_Globals (we have to use
353 -- the routine call, rather than define the globals in the binder
354 -- file to deal with cross-library calls in some systems.
357 -- Generate restrictions string
359 Set_String (" Restrictions : constant String :=");
360 Write_Statement_Buffer;
363 for J in All_Restrictions loop
368 Write_Statement_Buffer;
371 -- Generate Interrupt_State pragma string
373 Set_String (" Interrupt_States : constant String :=");
374 Write_Statement_Buffer;
383 for J in 0 .. IS_Pragma_Settings.Last loop
386 Write_Statement_Buffer;
394 Set_Char (IS_Pragma_Settings.Table (J));
399 Write_Statement_Buffer;
402 -- Generate spec for Set_Globals procedure
404 WBI (" procedure Set_Globals");
405 WBI (" (Main_Priority : Integer;");
406 WBI (" Time_Slice_Value : Integer;");
407 WBI (" WC_Encoding : Character;");
408 WBI (" Locking_Policy : Character;");
409 WBI (" Queuing_Policy : Character;");
410 WBI (" Task_Dispatching_Policy : Character;");
411 WBI (" Restrictions : System.Address;");
412 WBI (" Interrupt_States : System.Address;");
413 WBI (" Num_Interrupt_States : Integer;");
414 WBI (" Unreserve_All_Interrupts : Integer;");
415 WBI (" Exception_Tracebacks : Integer;");
416 WBI (" Zero_Cost_Exceptions : Integer);");
417 WBI (" pragma Import (C, Set_Globals, ""__gnat_set_globals"");");
419 -- Import entry point for elaboration time signal handler
420 -- installation, and indication of if it's been called previously.
423 WBI (" procedure Install_Handler;");
424 WBI (" pragma Import (C, Install_Handler, " &
425 """__gnat_install_handler"");");
427 WBI (" Handler_Installed : Integer;");
428 WBI (" pragma Import (C, Handler_Installed, " &
429 """__gnat_handler_installed"");");
431 -- Generate exception table
433 Gen_Exception_Table_Ada;
435 -- Generate the call to Set_Globals
437 WBI (" Set_Globals");
439 Set_String (" (Main_Priority => ");
440 Set_Int (Main_Priority);
442 Write_Statement_Buffer;
444 Set_String (" Time_Slice_Value => ");
446 if Task_Dispatching_Policy_Specified = 'F'
447 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
451 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
455 Write_Statement_Buffer;
457 Set_String (" WC_Encoding => '");
458 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
460 Write_Statement_Buffer;
462 Set_String (" Locking_Policy => '");
463 Set_Char (Locking_Policy_Specified);
465 Write_Statement_Buffer;
467 Set_String (" Queuing_Policy => '");
468 Set_Char (Queuing_Policy_Specified);
470 Write_Statement_Buffer;
472 Set_String (" Task_Dispatching_Policy => '");
473 Set_Char (Task_Dispatching_Policy_Specified);
475 Write_Statement_Buffer;
477 WBI (" Restrictions => Restrictions'Address,");
479 WBI (" Interrupt_States => " &
480 "Interrupt_States'Address,");
482 Set_String (" Num_Interrupt_States => ");
483 Set_Int (IS_Pragma_Settings.Last + 1);
485 Write_Statement_Buffer;
487 Set_String (" Unreserve_All_Interrupts => ");
489 if Unreserve_All_Interrupts_Specified then
496 Write_Statement_Buffer;
498 Set_String (" Exception_Tracebacks => ");
500 if Exception_Tracebacks then
507 Write_Statement_Buffer;
509 Set_String (" Zero_Cost_Exceptions => ");
511 if Zero_Cost_Exceptions_Specified then
518 Write_Statement_Buffer;
520 -- Generate call to Install_Handler
523 WBI (" if Handler_Installed = 0 then");
524 WBI (" Install_Handler;");
528 -- Generate call to set Initialize_Scalar values if active
530 if Initialize_Scalars_Used then
532 Set_String (" System.Scalar_Values.Initialize ('");
533 Set_Char (Initialize_Scalars_Mode1);
535 Set_Char (Initialize_Scalars_Mode2);
537 Write_Statement_Buffer;
540 -- Generate assignment of default secondary stack size if set
542 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
544 Set_String (" System.Secondary_Stack.");
545 Set_String ("Default_Secondary_Stack_Size := ");
546 Set_Int (Opt.Default_Sec_Stack_Size);
548 Write_Statement_Buffer;
551 -- Generate elaboration calls
556 WBI (" end " & Ada_Init_Name.all & ";");
563 procedure Gen_Adainit_C is
564 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
567 WBI ("void " & Ada_Init_Name.all & " (void)");
570 -- Generate externals for elaboration entities
572 for E in Elab_Order.First .. Elab_Order.Last loop
574 Unum : constant Unit_Id := Elab_Order.Table (E);
575 U : Unit_Record renames Units.Table (Unum);
577 if U.Set_Elab_Entity and then not U.Interface then
578 Set_String (" extern char ");
579 Get_Name_String (U.Uname);
582 Write_Statement_Buffer;
587 Write_Statement_Buffer;
589 -- Standard library suppressed
591 if Suppress_Standard_Library_On_Target then
593 -- Case of High_Integrity_Mode mode. Set __gl_main_priority if needed
594 -- for the Ravenscar profile.
596 if Main_Priority /= No_Main_Priority then
597 Set_String (" extern int __gl_main_priority = ");
598 Set_Int (Main_Priority);
600 Write_Statement_Buffer;
603 -- Normal case (standard library not suppressed)
606 -- Generate definition for restrictions string
608 Set_String (" const char *restrictions = """);
610 for J in All_Restrictions loop
615 Write_Statement_Buffer;
617 -- Generate definition for interrupt states string
619 Set_String (" const char *interrupt_states = """);
621 for J in 0 .. IS_Pragma_Settings.Last loop
622 Set_Char (IS_Pragma_Settings.Table (J));
626 Write_Statement_Buffer;
628 -- Generate declaration for secondary stack default if needed
630 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
631 WBI (" extern int system__secondary_stack__" &
632 "default_secondary_stack_size;");
637 -- Code for normal case (standard library not suppressed)
639 Gen_Exception_Table_C;
641 -- Generate call to set the runtime global variables defined in
642 -- a-init.c. We define the varables in a-init.c, rather than in
643 -- the binder generated file itself to avoid undefined externals
644 -- when the runtime is linked as a shareable image library.
646 -- We call the routine from inside adainit() because this works for
647 -- both programs with and without binder generated "main" functions.
649 WBI (" __gnat_set_globals (");
652 Set_Int (Main_Priority);
655 Set_String ("/* Main_Priority */");
656 Write_Statement_Buffer;
660 if Task_Dispatching_Policy = 'F'
661 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
665 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
670 Set_String ("/* Time_Slice_Value */");
671 Write_Statement_Buffer;
674 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
677 Set_String ("/* WC_Encoding */");
678 Write_Statement_Buffer;
681 Set_Char (Locking_Policy_Specified);
684 Set_String ("/* Locking_Policy */");
685 Write_Statement_Buffer;
688 Set_Char (Queuing_Policy_Specified);
691 Set_String ("/* Queuing_Policy */");
692 Write_Statement_Buffer;
695 Set_Char (Task_Dispatching_Policy_Specified);
698 Set_String ("/* Tasking_Dispatching_Policy */");
699 Write_Statement_Buffer;
702 Set_String ("restrictions");
705 Set_String ("/* Restrictions */");
706 Write_Statement_Buffer;
709 Set_String ("interrupt_states");
712 Set_String ("/* Interrupt_States */");
713 Write_Statement_Buffer;
716 Set_Int (IS_Pragma_Settings.Last + 1);
719 Set_String ("/* Num_Interrupt_States */");
720 Write_Statement_Buffer;
723 Set_Int (Boolean'Pos (Unreserve_All_Interrupts_Specified));
726 Set_String ("/* Unreserve_All_Interrupts */");
727 Write_Statement_Buffer;
730 Set_Int (Boolean'Pos (Exception_Tracebacks));
733 Set_String ("/* Exception_Tracebacks */");
734 Write_Statement_Buffer;
737 Set_Int (Boolean'Pos (Zero_Cost_Exceptions_Specified));
740 Set_String ("/* Zero_Cost_Exceptions */");
741 Write_Statement_Buffer;
744 -- Install elaboration time signal handler
746 WBI (" if (__gnat_handler_installed == 0)");
748 WBI (" __gnat_install_handler ();");
752 -- Generate call to set Initialize_Scalar values if needed
754 if Initialize_Scalars_Used then
756 Set_String (" system__scalar_values__initialize('");
757 Set_Char (Initialize_Scalars_Mode1);
759 Set_Char (Initialize_Scalars_Mode2);
761 Write_Statement_Buffer;
764 -- Generate assignment of default secondary stack size if set
766 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
768 Set_String (" system__secondary_stack__");
769 Set_String ("default_secondary_stack_size = ");
770 Set_Int (Opt.Default_Sec_Stack_Size);
772 Write_Statement_Buffer;
775 -- Generate elaboration calls
782 ------------------------
783 -- Gen_Elab_Calls_Ada --
784 ------------------------
786 procedure Gen_Elab_Calls_Ada is
788 for E in Elab_Order.First .. Elab_Order.Last loop
790 Unum : constant Unit_Id := Elab_Order.Table (E);
791 U : Unit_Record renames Units.Table (Unum);
794 -- This is the unit number of the spec that corresponds to
795 -- this entry. It is the same as Unum except when the body
796 -- and spec are different and we are currently processing
797 -- the body, in which case it is the spec (Unum + 1).
800 if U.Utype = Is_Body then
801 Unum_Spec := Unum + 1;
806 -- Case of no elaboration code
810 -- The only case in which we have to do something is if
811 -- this is a body, with a separate spec, where the separate
812 -- spec has an elaboration entity defined.
814 -- In that case, this is where we set the elaboration entity
815 -- to True, we do not need to test if this has already been
816 -- done, since it is quicker to set the flag than to test it.
818 if not U.Interface and then U.Utype = Is_Body
819 and then Units.Table (Unum_Spec).Set_Elab_Entity
822 Set_Unit_Number (Unum_Spec);
823 Set_String (" := True;");
824 Write_Statement_Buffer;
827 -- Here if elaboration code is present. If binding a library
828 -- or if there is a non-Ada main subprogram then we generate:
830 -- if not uname_E then
831 -- uname'elab_[spec|body];
835 -- Otherwise, elaboration routines are called unconditionally:
837 -- uname'elab_[spec|body];
840 -- The uname_E assignment is skipped if this is a separate spec,
841 -- since the assignment will be done when we process the body.
843 elsif not U.Interface then
844 if Force_Checking_Of_Elaboration_Flags or
845 Interface_Library_Unit or
846 (not Bind_Main_Program)
848 Set_String (" if not E");
849 Set_Unit_Number (Unum_Spec);
850 Set_String (" then");
851 Write_Statement_Buffer;
856 Get_Decoded_Name_String_With_Brackets (U.Uname);
858 if Name_Buffer (Name_Len) = 's' then
859 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_spec";
861 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_body";
864 Name_Len := Name_Len + 8;
865 Set_Casing (U.Icasing);
868 Write_Statement_Buffer;
870 if U.Utype /= Is_Spec then
871 if Force_Checking_Of_Elaboration_Flags or
872 Interface_Library_Unit or
873 (not Bind_Main_Program)
879 Set_Unit_Number (Unum_Spec);
880 Set_String (" := True;");
881 Write_Statement_Buffer;
884 if Force_Checking_Of_Elaboration_Flags or
885 Interface_Library_Unit or
886 (not Bind_Main_Program)
893 end Gen_Elab_Calls_Ada;
895 ----------------------
896 -- Gen_Elab_Calls_C --
897 ----------------------
899 procedure Gen_Elab_Calls_C is
902 for E in Elab_Order.First .. Elab_Order.Last loop
904 Unum : constant Unit_Id := Elab_Order.Table (E);
905 U : Unit_Record renames Units.Table (Unum);
908 -- This is the unit number of the spec that corresponds to
909 -- this entry. It is the same as Unum except when the body
910 -- and spec are different and we are currently processing
911 -- the body, in which case it is the spec (Unum + 1).
914 if U.Utype = Is_Body then
915 Unum_Spec := Unum + 1;
920 -- Case of no elaboration code
924 -- The only case in which we have to do something is if
925 -- this is a body, with a separate spec, where the separate
926 -- spec has an elaboration entity defined.
928 -- In that case, this is where we set the elaboration entity
929 -- to True, we do not need to test if this has already been
930 -- done, since it is quicker to set the flag than to test it.
932 if not U.Interface and then U.Utype = Is_Body
933 and then Units.Table (Unum_Spec).Set_Elab_Entity
936 Get_Name_String (U.Uname);
938 Set_String ("_E = 1;");
939 Write_Statement_Buffer;
942 -- Here if elaboration code is present. If binding a library
943 -- or if there is a non-Ada main subprogram then we generate:
945 -- if (uname_E == 0) {
946 -- uname__elab[s|b] ();
950 -- The uname_E assignment is skipped if this is a separate spec,
951 -- since the assignment will be done when we process the body.
953 elsif not U.Interface then
954 Get_Name_String (U.Uname);
956 if Force_Checking_Of_Elaboration_Flags or
957 Interface_Library_Unit or
958 (not Bind_Main_Program)
960 Set_String (" if (");
962 Set_String ("_E == 0) {");
963 Write_Statement_Buffer;
969 Set_String ("___elab");
970 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
972 Write_Statement_Buffer;
974 if U.Utype /= Is_Spec then
975 if Force_Checking_Of_Elaboration_Flags or
976 Interface_Library_Unit or
977 (not Bind_Main_Program)
984 Set_String ("_E++;");
985 Write_Statement_Buffer;
988 if Force_Checking_Of_Elaboration_Flags or
989 Interface_Library_Unit or
990 (not Bind_Main_Program)
998 end Gen_Elab_Calls_C;
1000 ----------------------
1001 -- Gen_Elab_Defs_C --
1002 ----------------------
1004 procedure Gen_Elab_Defs_C is
1006 for E in Elab_Order.First .. Elab_Order.Last loop
1008 -- Generate declaration of elaboration procedure if elaboration
1009 -- needed. Note that passive units are always excluded.
1011 if not Units.Table (Elab_Order.Table (E)).No_Elab then
1012 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1013 Set_String ("extern void ");
1015 Set_String ("___elab");
1016 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1017 Set_String (" (void);");
1018 Write_Statement_Buffer;
1024 end Gen_Elab_Defs_C;
1026 ------------------------
1027 -- Gen_Elab_Order_Ada --
1028 ------------------------
1030 procedure Gen_Elab_Order_Ada is
1033 WBI (" -- BEGIN ELABORATION ORDER");
1035 for J in Elab_Order.First .. Elab_Order.Last loop
1036 Set_String (" -- ");
1037 Get_Unit_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1039 Write_Statement_Buffer;
1042 WBI (" -- END ELABORATION ORDER");
1043 end Gen_Elab_Order_Ada;
1045 ----------------------
1046 -- Gen_Elab_Order_C --
1047 ----------------------
1049 procedure Gen_Elab_Order_C is
1052 WBI ("/* BEGIN ELABORATION ORDER");
1054 for J in Elab_Order.First .. Elab_Order.Last loop
1055 Get_Unit_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1057 Write_Statement_Buffer;
1060 WBI (" END ELABORATION ORDER */");
1061 end Gen_Elab_Order_C;
1063 -----------------------------
1064 -- Gen_Exception_Table_Ada --
1065 -----------------------------
1067 procedure Gen_Exception_Table_Ada is
1069 Last : ALI_Id := No_ALI_Id;
1072 if not Zero_Cost_Exceptions_Specified then
1077 -- The code we generate looks like
1079 -- procedure SDP_Table_Build
1080 -- (SDP_Addresses : System.Address;
1081 -- SDP_Count : Natural;
1082 -- Elab_Addresses : System.Address;
1083 -- Elab_Addr_Count : Natural);
1084 -- pragma Import (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
1086 -- ST : aliased constant array (1 .. nnn) of System.Address := (
1087 -- unit_name_1'UET_Address,
1088 -- unit_name_2'UET_Address,
1090 -- unit_name_3'UET_Address,
1092 -- EA : aliased constant array (1 .. eee) of System.Address := (
1093 -- adainit'Code_Address,
1094 -- adafinal'Code_Address,
1095 -- unit_name'elab[spec|body]'Code_Address,
1096 -- unit_name'elab[spec|body]'Code_Address,
1097 -- unit_name'elab[spec|body]'Code_Address,
1098 -- unit_name'elab[spec|body]'Code_Address);
1101 -- SDP_Table_Build (ST'Address, nnn, EA'Address, eee);
1104 for A in ALIs.First .. ALIs.Last loop
1105 if not ALIs.Table (A).Interface
1106 and then ALIs.Table (A).Unit_Exception_Table
1115 -- Happens with "gnatmake -a -f -gnatL ..."
1122 WBI (" procedure SDP_Table_Build");
1123 WBI (" (SDP_Addresses : System.Address;");
1124 WBI (" SDP_Count : Natural;");
1125 WBI (" Elab_Addresses : System.Address;");
1126 WBI (" Elab_Addr_Count : Natural);");
1128 "pragma Import (C, SDP_Table_Build, ""__gnat_SDP_Table_Build"");");
1131 Set_String (" ST : aliased constant array (1 .. ");
1133 Set_String (") of System.Address := (");
1136 Set_String ("1 => A1);");
1137 Write_Statement_Buffer;
1140 Write_Statement_Buffer;
1142 for A in ALIs.First .. ALIs.Last loop
1143 if not ALIs.Table (A).Interface
1144 and then ALIs.Table (A).Unit_Exception_Table
1146 Get_Decoded_Name_String_With_Brackets
1147 (Units.Table (ALIs.Table (A).First_Unit).Uname);
1148 Set_Casing (Mixed_Case);
1150 Set_String (Name_Buffer (1 .. Name_Len - 2));
1151 Set_String ("'UET_Address");
1159 Write_Statement_Buffer;
1165 Set_String (" EA : aliased constant array (1 .. ");
1166 Set_Int (Num_Elab_Calls + 2);
1167 Set_String (") of System.Address := (");
1168 Write_Statement_Buffer;
1169 WBI (" " & Ada_Init_Name.all & "'Code_Address,");
1171 -- If compiling for the JVM, we directly reference Adafinal because
1172 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1174 if not Cumulative_Restrictions.Set (No_Finalization) then
1175 if Hostparm.Java_VM then
1177 (" System.Standard_Library.Adafinal'Code_Address");
1180 (" Do_Finalize'Code_Address");
1184 for E in Elab_Order.First .. Elab_Order.Last loop
1185 Get_Decoded_Name_String_With_Brackets
1186 (Units.Table (Elab_Order.Table (E)).Uname);
1188 if Units.Table (Elab_Order.Table (E)).No_Elab then
1193 Write_Statement_Buffer;
1196 if Name_Buffer (Name_Len) = 's' then
1197 Name_Buffer (Name_Len - 1 .. Name_Len + 21) :=
1198 "'elab_spec'code_address";
1200 Name_Buffer (Name_Len - 1 .. Name_Len + 21) :=
1201 "'elab_body'code_address";
1204 Name_Len := Name_Len + 21;
1205 Set_Casing (Units.Table (Elab_Order.Table (E)).Icasing);
1211 Write_Statement_Buffer;
1216 Set_String (" SDP_Table_Build (ST'Address, ");
1218 Set_String (", EA'Address, ");
1219 Set_Int (Num_Elab_Calls + 2);
1221 Write_Statement_Buffer;
1222 end Gen_Exception_Table_Ada;
1224 ---------------------------
1225 -- Gen_Exception_Table_C --
1226 ---------------------------
1228 procedure Gen_Exception_Table_C is
1233 if not Zero_Cost_Exceptions_Specified then
1237 -- The code we generate looks like
1239 -- extern void *__gnat_unitname1__SDP;
1240 -- extern void *__gnat_unitname2__SDP;
1243 -- void **st[nnn] = {
1244 -- &__gnat_unitname1__SDP,
1245 -- &__gnat_unitname2__SDP,
1247 -- &__gnat_unitnamen__SDP};
1249 -- extern void unitname1__elabb ();
1250 -- extern void unitname2__elabb ();
1253 -- void (*ea[eee]) () = {
1256 -- unitname1___elab[b,s],
1257 -- unitname2___elab[b,s],
1259 -- unitnamen___elab[b,s]};
1261 -- __gnat_SDP_Table_Build (&st, nnn, &ea, eee);
1264 for A in ALIs.First .. ALIs.Last loop
1265 if not ALIs.Table (A).Interface
1266 and then ALIs.Table (A).Unit_Exception_Table
1270 Set_String (" extern void *__gnat_");
1271 Get_Name_String (Units.Table (ALIs.Table (A).First_Unit).Uname);
1273 Set_String ("__SDP");
1275 Write_Statement_Buffer;
1281 -- Happens with "gnatmake -a -f -gnatL ..."
1288 Set_String (" void **st[");
1290 Set_String ("] = {");
1291 Write_Statement_Buffer;
1294 for A in ALIs.First .. ALIs.Last loop
1295 if not ALIs.Table (A).Interface
1296 and then ALIs.Table (A).Unit_Exception_Table
1300 Set_String (" &__gnat_");
1301 Get_Name_String (Units.Table (ALIs.Table (A).First_Unit).Uname);
1303 Set_String ("__SDP");
1311 Write_Statement_Buffer;
1316 for E in Elab_Order.First .. Elab_Order.Last loop
1317 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1319 if Units.Table (Elab_Order.Table (E)).No_Elab then
1323 Set_String (" extern void ");
1325 Set_String ("___elab");
1326 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1327 Set_String (" ();");
1328 Write_Statement_Buffer;
1333 Set_String (" void (*ea[");
1334 Set_Int (Num_Elab_Calls + 2);
1335 Set_String ("]) () = {");
1336 Write_Statement_Buffer;
1338 WBI (" " & Ada_Init_Name.all & ",");
1340 if not Cumulative_Restrictions.Set (No_Finalization) then
1341 Set_String (" system__standard_library__adafinal");
1344 for E in Elab_Order.First .. Elab_Order.Last loop
1345 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1347 if Units.Table (Elab_Order.Table (E)).No_Elab then
1352 Write_Statement_Buffer;
1355 Set_String ("___elab");
1356 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1361 Write_Statement_Buffer;
1365 Set_String (" __gnat_SDP_Table_Build (&st, ");
1367 Set_String (", ea, ");
1368 Set_Int (Num_Elab_Calls + 2);
1370 Write_Statement_Buffer;
1371 end Gen_Exception_Table_C;
1377 procedure Gen_Main_Ada is
1381 if Exit_Status_Supported_On_Target then
1382 Set_String (" function ");
1384 Set_String (" procedure ");
1387 Set_String (Get_Main_Name);
1389 if Command_Line_Args_On_Target then
1390 Write_Statement_Buffer;
1391 WBI (" (argc : Integer;");
1392 WBI (" argv : System.Address;");
1393 WBI (" envp : System.Address)");
1395 if Exit_Status_Supported_On_Target then
1396 WBI (" return Integer");
1402 if Exit_Status_Supported_On_Target then
1403 Set_String (" return Integer is");
1408 Write_Statement_Buffer;
1411 -- Initialize and Finalize
1413 if not Cumulative_Restrictions.Set (No_Finalization) then
1414 WBI (" procedure initialize;");
1415 WBI (" pragma Import (C, initialize, ""__gnat_initialize"");");
1417 WBI (" procedure finalize;");
1418 WBI (" pragma Import (C, finalize, ""__gnat_finalize"");");
1422 -- Deal with declarations for main program case
1424 if not No_Main_Subprogram then
1426 -- To call the main program, we declare it using a pragma Import
1427 -- Ada with the right link name.
1429 -- It might seem more obvious to "with" the main program, and call
1430 -- it in the normal Ada manner. We do not do this for three reasons:
1432 -- 1. It is more efficient not to recompile the main program
1433 -- 2. We are not entitled to assume the source is accessible
1434 -- 3. We don't know what options to use to compile it
1436 -- It is really reason 3 that is most critical (indeed we used
1437 -- to generate the "with", but several regression tests failed).
1441 if ALIs.Table (ALIs.First).Main_Program = Func then
1442 WBI (" Result : Integer;");
1444 WBI (" function Ada_Main_Program return Integer;");
1447 WBI (" procedure Ada_Main_Program;");
1450 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1451 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1452 Set_Main_Program_Name;
1453 Set_String (""");");
1455 Write_Statement_Buffer;
1459 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1460 -- not referenced elsewhere in the generated program, but is needed
1461 -- by the debugger (that's why it is generated in the first place).
1462 -- The reference stops Ada_Main_Program_Name from being optimized
1463 -- away by smart linkers, such as the AiX linker.
1465 if Bind_Main_Program then
1467 (" Ensure_Reference : System.Address := " &
1468 "Ada_Main_Program_Name'Address;");
1474 -- Acquire command line arguments if present on target
1476 if Command_Line_Args_On_Target then
1477 WBI (" gnat_argc := argc;");
1478 WBI (" gnat_argv := argv;");
1479 WBI (" gnat_envp := envp;");
1482 -- If configurable run time and no command line args, then nothing
1483 -- needs to be done since the gnat_argc/argv/envp variables are
1484 -- suppressed in this case.
1486 elsif Configurable_Run_Time_On_Target then
1489 -- Otherwise set dummy values (to be filled in by some other unit?)
1492 WBI (" gnat_argc := 0;");
1493 WBI (" gnat_argv := System.Null_Address;");
1494 WBI (" gnat_envp := System.Null_Address;");
1497 if not Cumulative_Restrictions.Set (No_Finalization) then
1498 WBI (" Initialize;");
1501 WBI (" " & Ada_Init_Name.all & ";");
1503 if not No_Main_Subprogram then
1504 WBI (" Break_Start;");
1506 if ALIs.Table (ALIs.First).Main_Program = Proc then
1507 WBI (" Ada_Main_Program;");
1509 WBI (" Result := Ada_Main_Program;");
1513 -- Adafinal call is skipped if no finalization
1515 if not Cumulative_Restrictions.Set (No_Finalization) then
1517 -- If compiling for the JVM, we directly call Adafinal because
1518 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1520 if Hostparm.Java_VM then
1521 WBI (" System.Standard_Library.Adafinal;");
1523 WBI (" Do_Finalize;");
1527 -- Finalize is only called if we have a run time
1529 if not Cumulative_Restrictions.Set (No_Finalization) then
1535 if Exit_Status_Supported_On_Target then
1536 if No_Main_Subprogram
1537 or else ALIs.Table (ALIs.First).Main_Program = Proc
1539 WBI (" return (gnat_exit_status);");
1541 WBI (" return (Result);");
1552 procedure Gen_Main_C is
1554 if Exit_Status_Supported_On_Target then
1555 Set_String ("int ");
1557 Set_String ("void ");
1560 Set_String (Get_Main_Name);
1562 -- Generate command line args in prototype if present on target
1564 if Command_Line_Args_On_Target then
1565 Write_Statement_Buffer (" (int argc, char **argv, char **envp)");
1567 -- Case of no command line arguments on target
1570 Write_Statement_Buffer (" ()");
1575 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1576 -- is not referenced elsewhere in the generated program, but is
1577 -- needed by the debugger (that's why it is generated in the first
1578 -- place). The reference stops Ada_Main_Program_Name from being
1579 -- optimized away by smart linkers, such as the AiX linker.
1581 if Bind_Main_Program then
1582 WBI (" char *ensure_reference __attribute__ ((__unused__)) = " &
1583 "__gnat_ada_main_program_name;");
1587 -- If main program is a function, generate result variable
1589 if ALIs.Table (ALIs.First).Main_Program = Func then
1590 WBI (" int result;");
1593 -- Set command line argument values from parameters if command line
1594 -- arguments are present on target
1596 if Command_Line_Args_On_Target then
1597 WBI (" gnat_argc = argc;");
1598 WBI (" gnat_argv = argv;");
1599 WBI (" gnat_envp = envp;");
1602 -- If configurable run-time, then nothing to do, since in this case
1603 -- the gnat_argc/argv/envp variables are entirely suppressed.
1605 elsif Configurable_Run_Time_On_Target then
1608 -- if no command line arguments on target, set dummy values
1611 WBI (" int result;");
1612 WBI (" gnat_argc = 0;");
1613 WBI (" gnat_argv = 0;");
1614 WBI (" gnat_envp = 0;");
1617 -- The __gnat_initialize routine is used only if we have a run-time
1619 if not Suppress_Standard_Library_On_Target then
1621 (" __gnat_initialize ();");
1624 WBI (" " & Ada_Init_Name.all & " ();");
1626 if not No_Main_Subprogram then
1627 WBI (" __gnat_break_start ();");
1630 -- Output main program name
1632 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1634 -- Main program is procedure case
1636 if ALIs.Table (ALIs.First).Main_Program = Proc then
1638 Set_Main_Program_Name;
1639 Set_String (" ();");
1640 Write_Statement_Buffer;
1642 -- Main program is function case
1644 else -- ALIs.Table (ALIs_First).Main_Program = Func
1645 Set_String (" result = ");
1646 Set_Main_Program_Name;
1647 Set_String (" ();");
1648 Write_Statement_Buffer;
1653 -- Call adafinal if finalization active
1655 if not Cumulative_Restrictions.Set (No_Finalization) then
1657 WBI (" system__standard_library__adafinal ();");
1660 -- The finalize routine is used only if we have a run-time
1662 if not Suppress_Standard_Library_On_Target then
1663 WBI (" __gnat_finalize ();");
1666 -- Case of main program is a function, so the value it returns
1667 -- is the exit status in this case.
1669 if ALIs.Table (ALIs.First).Main_Program = Func then
1670 if Exit_Status_Supported_On_Target then
1672 -- VMS must use Posix exit routine in order to get the effect
1673 -- of a Unix compatible setting of the program exit status.
1674 -- For all other systems, we use the standard exit routine.
1676 if OpenVMS_On_Target then
1677 WBI (" __posix_exit (result);");
1679 WBI (" exit (result);");
1683 -- Case of main program is a procedure, in which case the exit
1684 -- status is whatever was set by a Set_Exit call most recently
1687 if Exit_Status_Supported_On_Target then
1689 -- VMS must use Posix exit routine in order to get the effect
1690 -- of a Unix compatible setting of the program exit status.
1691 -- For all other systems, we use the standard exit routine.
1693 if OpenVMS_On_Target then
1694 WBI (" __posix_exit (gnat_exit_status);");
1696 WBI (" exit (gnat_exit_status);");
1704 ------------------------------
1705 -- Gen_Object_Files_Options --
1706 ------------------------------
1708 procedure Gen_Object_Files_Options is
1710 -- This keeps track of the position in the sorted set of entries
1711 -- in the Linker_Options table of where the first entry from an
1712 -- internal file appears.
1714 procedure Write_Linker_Option;
1715 -- Write binder info linker option.
1717 -------------------------
1718 -- Write_Linker_Option --
1719 -------------------------
1721 procedure Write_Linker_Option is
1726 -- Loop through string, breaking at null's
1729 while Start < Name_Len loop
1731 -- Find null ending this section
1734 while Name_Buffer (Stop) /= ASCII.NUL
1735 and then Stop <= Name_Len loop
1739 -- Process section if non-null
1741 if Stop > Start then
1742 if Output_Linker_Option_List then
1743 Write_Str (Name_Buffer (Start .. Stop - 1));
1747 (" -- ", "", Name_Buffer (Start .. Stop - 1));
1752 end Write_Linker_Option;
1754 -- Start of processing for Gen_Object_Files_Options
1758 Write_Info_Ada_C ("-- ", "/* ", " BEGIN Object file/option list");
1760 for E in Elab_Order.First .. Elab_Order.Last loop
1762 -- If not spec that has an associated body, then generate a
1763 -- comment giving the name of the corresponding object file.
1765 if (not Units.Table (Elab_Order.Table (E)).Interface)
1766 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1770 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1772 -- If the presence of an object file is necessary or if it
1773 -- exists, then use it.
1775 if not Hostparm.Exclude_Missing_Objects
1776 or else GNAT.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1778 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1779 if Output_Object_List then
1780 Write_Str (Name_Buffer (1 .. Name_Len));
1784 -- Don't link with the shared library on VMS if an internal
1785 -- filename object is seen. Multiply defined symbols will
1789 and then Is_Internal_File_Name
1791 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
1793 -- Special case for g-trasym.obj, which is not included
1796 Get_Name_String (ALIs.Table
1797 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
1799 if Name_Buffer (1 .. 8) /= "g-trasym" then
1800 Opt.Shared_Libgnat := False;
1807 -- Add a "-Ldir" for each directory in the object path
1809 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1811 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1814 Add_Str_To_Name_Buffer ("-L");
1815 Add_Str_To_Name_Buffer (Dir.all);
1816 Write_Linker_Option;
1820 -- Sort linker options
1822 -- This sort accomplishes two important purposes:
1824 -- a) All application files are sorted to the front, and all
1825 -- GNAT internal files are sorted to the end. This results
1826 -- in a well defined dividing line between the two sets of
1827 -- files, for the purpose of inserting certain standard
1828 -- library references into the linker arguments list.
1830 -- b) Given two different units, we sort the linker options so
1831 -- that those from a unit earlier in the elaboration order
1832 -- comes later in the list. This is a heuristic designed
1833 -- to create a more friendly order of linker options when
1834 -- the operations appear in separate units. The idea is that
1835 -- if unit A must be elaborated before unit B, then it is
1836 -- more likely that B references libraries included by A,
1837 -- than vice versa, so we want the libraries included by
1838 -- A to come after the libraries included by B.
1840 -- These two criteria are implemented by function Lt_Linker_Option.
1841 -- Note that a special case of b) is that specs are elaborated before
1842 -- bodies, so linker options from specs come after linker options
1843 -- for bodies, and again, the assumption is that libraries used by
1844 -- the body are more likely to reference libraries used by the spec,
1848 (Linker_Options.Last,
1849 Move_Linker_Option'Access,
1850 Lt_Linker_Option'Access);
1852 -- Write user linker options, i.e. the set of linker options that
1853 -- come from all files other than GNAT internal files, Lgnat is
1854 -- left set to point to the first entry from a GNAT internal file,
1855 -- or past the end of the entriers if there are no internal files.
1857 Lgnat := Linker_Options.Last + 1;
1859 for J in 1 .. Linker_Options.Last loop
1860 if not Linker_Options.Table (J).Internal_File then
1861 Get_Name_String (Linker_Options.Table (J).Name);
1862 Write_Linker_Option;
1869 -- Now we insert standard linker options that must appear after the
1870 -- entries from user files, and before the entries from GNAT run-time
1871 -- files. The reason for this decision is that libraries referenced
1872 -- by internal routines may reference these standard library entries.
1874 if not Opt.No_Stdlib then
1877 if Opt.Shared_Libgnat then
1878 Add_Str_To_Name_Buffer ("-shared");
1880 Add_Str_To_Name_Buffer ("-static");
1883 -- Write directly to avoid -K output (why???)
1885 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1887 if With_DECGNAT then
1889 Add_Str_To_Name_Buffer ("-ldecgnat");
1890 Write_Linker_Option;
1896 if Opt.Shared_Libgnat then
1897 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1899 Add_Str_To_Name_Buffer ("-lgnarl");
1902 Write_Linker_Option;
1907 if Opt.Shared_Libgnat then
1908 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1910 Add_Str_To_Name_Buffer ("-lgnat");
1913 Write_Linker_Option;
1916 -- Write linker options from all internal files
1918 for J in Lgnat .. Linker_Options.Last loop
1919 Get_Name_String (Linker_Options.Table (J).Name);
1920 Write_Linker_Option;
1923 if Ada_Bind_File then
1924 WBI ("-- END Object file/option list ");
1926 WBI (" END Object file/option list */");
1928 end Gen_Object_Files_Options;
1930 ---------------------
1931 -- Gen_Output_File --
1932 ---------------------
1934 procedure Gen_Output_File (Filename : String) is
1935 Is_Public_Version : constant Boolean := Get_Gnat_Build_Type = Public;
1938 -- Acquire settings for Interrupt_State pragmas
1940 Set_IS_Pragma_Table;
1942 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1943 -- JGNAT only supports Ada code, and the main program is already
1944 -- generated by the compiler.
1946 if Hostparm.Java_VM then
1947 Ada_Bind_File := True;
1948 Bind_Main_Program := False;
1951 -- Override time slice value if -T switch is set
1953 if Time_Slice_Set then
1954 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
1957 -- Count number of elaboration calls
1959 for E in Elab_Order.First .. Elab_Order.Last loop
1960 if Units.Table (Elab_Order.Table (E)).No_Elab then
1963 Num_Elab_Calls := Num_Elab_Calls + 1;
1967 -- Get the time stamp of the former bind for public version warning
1969 if Is_Public_Version then
1970 Record_Time_From_Last_Bind;
1973 -- Generate output file in appropriate language
1975 if Ada_Bind_File then
1976 Gen_Output_File_Ada (Filename);
1978 Gen_Output_File_C (Filename);
1981 -- Periodically issue a warning when the public version is used on
1984 if Is_Public_Version then
1985 Public_Version_Warning;
1987 end Gen_Output_File;
1989 -------------------------
1990 -- Gen_Output_File_Ada --
1991 -------------------------
1993 procedure Gen_Output_File_Ada (Filename : String) is
1996 -- Name of generated bind file (spec)
1999 -- Name of generated bind file (body)
2001 Ada_Main : constant String := Get_Ada_Main_Name;
2002 -- Name to be used for generated Ada main program. See the body of
2003 -- function Get_Ada_Main_Name for details on the form of the name.
2006 -- Create spec first
2008 Create_Binder_Output (Filename, 's', Bfiles);
2010 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2011 -- then we need to make sure that the binder program is compiled with
2012 -- the same restriction, so that no exception tables are generated.
2014 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2015 WBI ("pragma Restrictions (No_Exception_Handlers);");
2018 -- Generate with of System so we can reference System.Address
2020 WBI ("with System;");
2022 -- Generate with of System.Initialize_Scalars if active
2024 if Initialize_Scalars_Used then
2025 WBI ("with System.Scalar_Values;");
2028 -- Generate with of System.Secondary_Stack if active
2030 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2031 WBI ("with System.Secondary_Stack;");
2034 Resolve_Binder_Options;
2036 if not Suppress_Standard_Library_On_Target then
2038 -- Usually, adafinal is called using a pragma Import C. Since
2039 -- Import C doesn't have the same semantics for JGNAT, we use
2042 if Hostparm.Java_VM then
2043 WBI ("with System.Standard_Library;");
2047 WBI ("package " & Ada_Main & " is");
2048 WBI (" pragma Warnings (Off);");
2050 -- Main program case
2052 if Bind_Main_Program then
2054 -- Generate argc/argv stuff unless suppressed
2056 if Command_Line_Args_On_Target
2057 or not Configurable_Run_Time_On_Target
2060 WBI (" gnat_argc : Integer;");
2061 WBI (" gnat_argv : System.Address;");
2062 WBI (" gnat_envp : System.Address;");
2064 -- If the standard library is not suppressed, these variables are
2065 -- in the runtime data area for easy access from the runtime
2067 if not Suppress_Standard_Library_On_Target then
2069 WBI (" pragma Import (C, gnat_argc);");
2070 WBI (" pragma Import (C, gnat_argv);");
2071 WBI (" pragma Import (C, gnat_envp);");
2075 -- Define exit status. Again in normal mode, this is in the
2076 -- run-time library, and is initialized there, but in the
2077 -- configurable runtime case, the variable is declared and
2078 -- initialized in this file.
2082 if Configurable_Run_Time_Mode then
2083 if Exit_Status_Supported_On_Target then
2084 WBI (" gnat_exit_status : Integer := 0;");
2087 WBI (" gnat_exit_status : Integer;");
2088 WBI (" pragma Import (C, gnat_exit_status);");
2092 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2093 -- the main program. Otherwise, it can lead under some circumstances
2094 -- to a symbol duplication during the link (for instance when a
2095 -- C program uses 2 Ada libraries)
2097 if Bind_Main_Program then
2099 WBI (" GNAT_Version : constant String :=");
2100 WBI (" ""GNAT Version: " &
2101 Gnat_Version_String & """;");
2102 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2105 Set_String (" Ada_Main_Program_Name : constant String := """);
2106 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2107 Set_Main_Program_Name;
2108 Set_String (""" & Ascii.NUL;");
2109 Write_Statement_Buffer;
2112 (" pragma Export (C, Ada_Main_Program_Name, " &
2113 """__gnat_ada_main_program_name"");");
2116 -- No need to generate a finalization routine if finalization
2117 -- is restricted, since there is nothing to do in this case.
2119 if not Cumulative_Restrictions.Set (No_Finalization) then
2121 WBI (" procedure " & Ada_Final_Name.all & ";");
2122 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2123 Ada_Final_Name.all & """);");
2127 WBI (" procedure " & Ada_Init_Name.all & ";");
2128 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2129 Ada_Init_Name.all & """);");
2131 if Bind_Main_Program then
2133 -- If we have the standard library, then Break_Start is defined
2134 -- there, but when the standard library is suppressed, Break_Start
2138 WBI (" procedure Break_Start;");
2140 if Suppress_Standard_Library_On_Target then
2141 WBI (" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2143 WBI (" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2148 if Exit_Status_Supported_On_Target then
2149 Set_String (" function ");
2151 Set_String (" procedure ");
2154 Set_String (Get_Main_Name);
2156 -- Generate argument list if present
2158 if Command_Line_Args_On_Target then
2159 Write_Statement_Buffer;
2160 WBI (" (argc : Integer;");
2161 WBI (" argv : System.Address;");
2163 (" envp : System.Address)");
2165 if Exit_Status_Supported_On_Target then
2166 Write_Statement_Buffer;
2167 WBI (" return Integer;");
2169 Write_Statement_Buffer (";");
2173 if Exit_Status_Supported_On_Target then
2174 Write_Statement_Buffer (" return Integer;");
2176 Write_Statement_Buffer (";");
2180 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2181 Get_Main_Name & """);");
2190 WBI ("end " & Ada_Main & ";");
2191 Close_Binder_Output;
2193 -- Prepare to write body
2195 Create_Binder_Output (Filename, 'b', Bfileb);
2197 -- Output Source_File_Name pragmas which look like
2199 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2200 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2202 -- where sss/bbb are the spec/body file names respectively
2204 Get_Name_String (Bfiles);
2205 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2207 WBI ("pragma Source_File_Name (" &
2209 ", Spec_File_Name => """ &
2210 Name_Buffer (1 .. Name_Len + 3));
2212 Get_Name_String (Bfileb);
2213 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2215 WBI ("pragma Source_File_Name (" &
2217 ", Body_File_Name => """ &
2218 Name_Buffer (1 .. Name_Len + 3));
2221 WBI ("package body " & Ada_Main & " is");
2222 WBI (" pragma Warnings (Off);");
2224 -- Import the finalization procedure only if finalization active
2226 if not Cumulative_Restrictions.Set (No_Finalization) then
2228 -- In the Java case, pragma Import C cannot be used, so the
2229 -- standard Ada constructs will be used instead.
2231 if not Hostparm.Java_VM then
2233 WBI (" procedure Do_Finalize;");
2235 (" pragma Import (C, Do_Finalize, " &
2236 """system__standard_library__adafinal"");");
2243 -- No need to generate a finalization routine if no finalization
2245 if not Cumulative_Restrictions.Set (No_Finalization) then
2249 if Bind_Main_Program then
2251 -- When suppressing the standard library then generate dummy body
2254 if Suppress_Standard_Library_On_Target then
2256 WBI (" procedure Break_Start is");
2265 -- Output object file list and the Ada body is complete
2267 Gen_Object_Files_Options;
2270 WBI ("end " & Ada_Main & ";");
2272 Close_Binder_Output;
2273 end Gen_Output_File_Ada;
2275 -----------------------
2276 -- Gen_Output_File_C --
2277 -----------------------
2279 procedure Gen_Output_File_C (Filename : String) is
2282 -- Name of generated bind file
2285 Create_Binder_Output (Filename, 'c', Bfile);
2287 Resolve_Binder_Options;
2289 WBI ("extern void __gnat_set_globals");
2290 WBI (" (int, int, char, char, char, char,");
2291 WBI (" const char *, const char *,");
2292 WBI (" int, int, int, int);");
2293 WBI ("extern void " & Ada_Final_Name.all & " (void);");
2294 WBI ("extern void " & Ada_Init_Name.all & " (void);");
2295 WBI ("extern void system__standard_library__adafinal (void);");
2297 if not No_Main_Subprogram then
2298 Set_String ("extern ");
2300 if Exit_Status_Supported_On_Target then
2303 Set_String ("void");
2306 Set_String (" main ");
2308 if Command_Line_Args_On_Target then
2309 Write_Statement_Buffer ("(int, char **, char **);");
2311 Write_Statement_Buffer ("(void);");
2314 if OpenVMS_On_Target then
2315 WBI ("extern void __posix_exit (int);");
2317 WBI ("extern void exit (int);");
2320 WBI ("extern void __gnat_break_start (void);");
2321 Set_String ("extern ");
2323 if ALIs.Table (ALIs.First).Main_Program = Proc then
2324 Set_String ("void ");
2326 Set_String ("int ");
2329 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2330 Set_Main_Program_Name;
2331 Set_String (" (void);");
2332 Write_Statement_Buffer;
2335 if not Suppress_Standard_Library_On_Target then
2336 WBI ("extern void __gnat_initialize (void);");
2337 WBI ("extern void __gnat_finalize (void);");
2338 WBI ("extern void __gnat_install_handler (void);");
2345 -- Imported variable used to track elaboration/finalization phase.
2346 -- Used only when we have a runtime.
2348 if not Suppress_Standard_Library_On_Target then
2349 WBI ("extern int __gnat_handler_installed;");
2353 -- Write argv/argc exit status stuff if main program case
2355 if Bind_Main_Program then
2357 -- First deal with argc/argv/envp. In the normal case they
2358 -- are in the run-time library.
2360 if not Configurable_Run_Time_On_Target then
2361 WBI ("extern int gnat_argc;");
2362 WBI ("extern char **gnat_argv;");
2363 WBI ("extern char **gnat_envp;");
2364 WBI ("extern int gnat_exit_status;");
2366 -- If configurable run time and no command line args, then the
2367 -- generation of these variables is entirely suppressed.
2369 elsif not Command_Line_Args_On_Target then
2372 -- Otherwise, in the configurable run-time case they are right in
2376 WBI ("int gnat_argc;");
2377 WBI ("char **gnat_argv;");
2378 WBI ("char **gnat_envp;");
2379 WBI ("int gnat_exit_status = 0;");
2382 -- Similarly deal with exit status
2383 -- are in the run-time library.
2385 if not Configurable_Run_Time_On_Target then
2386 WBI ("extern int gnat_exit_status;");
2388 -- If configurable run time and no exit status on target, then
2389 -- the generation of this variables is entirely suppressed.
2391 elsif not Exit_Status_Supported_On_Target then
2394 -- Otherwise, in the configurable run-time case this variable is
2395 -- right in the binder file, and initialized to zero there.
2398 WBI ("int gnat_exit_status = 0;");
2404 -- When suppressing the standard library, the __gnat_break_start
2405 -- routine (for the debugger to get initial control) is defined in
2408 if Suppress_Standard_Library_On_Target then
2410 WBI ("void __gnat_break_start () {}");
2413 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2414 -- only for the main program. Otherwise, it can lead under some
2415 -- circumstances to a symbol duplication during the link (for instance
2416 -- when a C program uses 2 Ada libraries)
2418 if Bind_Main_Program then
2420 WBI ("char __gnat_version[] = ""GNAT Version: " &
2421 Gnat_Version_String & """;");
2423 Set_String ("char __gnat_ada_main_program_name[] = """);
2424 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2425 Set_Main_Program_Name;
2427 Write_Statement_Buffer;
2430 -- Generate the adafinal routine. In no runtime mode, this is
2431 -- not needed, since there is no finalization to do.
2433 if not Cumulative_Restrictions.Set (No_Finalization) then
2439 -- Main is only present for Ada main case
2441 if Bind_Main_Program then
2445 -- Generate versions, elaboration order, list of object files
2449 Gen_Object_Files_Options;
2451 -- C binder output is complete
2453 Close_Binder_Output;
2454 end Gen_Output_File_C;
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 can not 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 can not 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 Hostparm.OpenVMS 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.Table'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;