1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
29 with Binde
; use Binde
;
30 with Butil
; use Butil
;
31 with Casing
; use Casing
;
32 with Fname
; use Fname
;
33 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
34 with Gnatvsn
; use Gnatvsn
;
36 with Namet
; use Namet
;
38 with Osint
; use Osint
;
39 with Osint
.B
; use Osint
.B
;
40 with Output
; use Output
;
41 with Types
; use Types
;
42 with Sdefault
; use Sdefault
;
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 System.Aux_DEC.DECLIB)
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 -- Local Subprograms --
67 -----------------------
69 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
70 -- Convenient shorthand used throughout
72 procedure Resolve_Binder_Options
;
73 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
74 -- since it tests for a package named "dec" which might cause a conflict
75 -- on non-VMS systems.
77 procedure Gen_Adainit_Ada
;
78 -- Generates the Adainit procedure (Ada code case)
80 procedure Gen_Adainit_C
;
81 -- Generates the Adainit procedure (C code case)
83 procedure Gen_Adafinal_Ada
;
84 -- Generate the Adafinal procedure (Ada code case)
86 procedure Gen_Adafinal_C
;
87 -- Generate the Adafinal procedure (C code case)
89 procedure Gen_Elab_Calls_Ada
;
90 -- Generate sequence of elaboration calls (Ada code case)
92 procedure Gen_Elab_Calls_C
;
93 -- Generate sequence of elaboration calls (C code case)
95 procedure Gen_Elab_Order_Ada
;
96 -- Generate comments showing elaboration order chosen (Ada case)
98 procedure Gen_Elab_Order_C
;
99 -- Generate comments showing elaboration order chosen (C case)
101 procedure Gen_Elab_Defs_C
;
102 -- Generate sequence of definitions for elaboration routines (C code case)
104 procedure Gen_Exception_Table_Ada
;
105 -- Generate binder exception table (Ada code case). This consists of
106 -- declarations followed by a begin followed by a call. If zero cost
107 -- exceptions are not active, then only the begin is generated.
109 procedure Gen_Exception_Table_C
;
110 -- Generate binder exception table (C code case). This has no effect
111 -- if zero cost exceptions are not active, otherwise it generates a
112 -- set of declarations followed by a call.
114 procedure Gen_Main_Ada
;
115 -- Generate procedure main (Ada code case)
117 procedure Gen_Main_C
;
118 -- Generate main() procedure (C code case)
120 procedure Gen_Object_Files_Options
;
121 -- Output comments containing a list of the full names of the object
122 -- files to be linked and the list of linker options supplied by
123 -- Linker_Options pragmas in the source. (C and Ada code case)
125 procedure Gen_Output_File_Ada
(Filename
: String);
126 -- Generate output file (Ada code case)
128 procedure Gen_Output_File_C
(Filename
: String);
129 -- Generate output file (C code case)
131 procedure Gen_Scalar_Values
;
132 -- Generates scalar initialization values for -Snn. A single procedure
133 -- handles both the Ada and C cases, since there is much common code.
135 procedure Gen_Versions_Ada
;
136 -- Output series of definitions for unit versions (Ada code case)
138 procedure Gen_Versions_C
;
139 -- Output series of definitions for unit versions (C code case)
141 function Get_Ada_Main_Name
return String;
142 -- This function is used in the Ada main output case to compute a usable
143 -- name for the generated main program. The normal main program name is
144 -- Ada_Main, but this won't work if the user has a unit with this name.
145 -- This function tries Ada_Main first, and if there is such a clash, then
146 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
148 function Get_Main_Name
return String;
149 -- This function is used in the Ada main output case to compute the
150 -- correct external main program. It is "main" by default, except on
151 -- VxWorks where it is the name of the Ada main name without the "_ada".
152 -- the -Mname binder option overrides the default with name.
154 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean;
155 -- Compare linker options, when sorting, first according to
156 -- Is_Internal_File (internal files come later) and then by
157 -- elaboration order position (latest to earliest).
159 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
160 -- Move routine for sorting linker options
162 procedure Public_Version_Warning
;
163 -- Emit a warning concerning the use of the Public version under
164 -- certain circumstances. See details in body.
166 procedure Set_Char
(C
: Character);
167 -- Set given character in Statement_Buffer at the Last + 1 position
168 -- and increment Last by one to reflect the stored character.
170 procedure Set_Int
(N
: Int
);
171 -- Set given value in decimal in Statement_Buffer with no spaces
172 -- starting at the Last + 1 position, and updating Last past the value.
173 -- A minus sign is output for a negative value.
175 procedure Set_Main_Program_Name
;
176 -- Given the main program name in Name_Buffer (length in Name_Len)
177 -- generate the name of the routine to be used in the call. The name
178 -- is generated starting at Last + 1, and Last is updated past it.
180 procedure Set_Name_Buffer
;
181 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer.
183 procedure Set_String
(S
: String);
184 -- Sets characters of given string in Statement_Buffer, starting at the
185 -- Last + 1 position, and updating last past the string value.
187 procedure Set_Unit_Name
;
188 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
189 -- starting at the Last + 1 position, and updating last past the value.
190 -- changing periods to double underscores, and updating Last appropriately.
192 procedure Set_Unit_Number
(U
: Unit_Id
);
193 -- Sets unit number (first unit is 1, leading zeroes output to line
194 -- up all output unit numbers nicely as required by the value, and
195 -- by the total number of units.
197 procedure Tab_To
(N
: Natural);
198 -- If Last is greater than or equal to N, no effect, otherwise store
199 -- blanks in Statement_Buffer bumping Last, until Last = N.
201 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String);
202 -- For C code case, write C & Common, for Ada case write Ada & Common
203 -- to current binder output file using Write_Binder_Info.
205 procedure Write_Statement_Buffer
;
206 -- Write out contents of statement buffer up to Last, and reset Last to 0
208 procedure Write_Statement_Buffer
(S
: String);
209 -- First writes its argument (using Set_String (S)), then writes out the
210 -- contents of statement buffer up to Last, and reset Last to 0
212 ----------------------
213 -- Gen_Adafinal_Ada --
214 ----------------------
216 procedure Gen_Adafinal_Ada
is
219 WBI
(" procedure " & Ada_Final_Name
.all & " is");
222 -- If compiling for the JVM, we directly call Adafinal because
223 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
225 if Hostparm
.Java_VM
then
226 WBI
(" System.Standard_Library.Adafinal;");
228 WBI
(" Do_Finalize;");
231 WBI
(" end " & Ada_Final_Name
.all & ";");
232 end Gen_Adafinal_Ada
;
238 procedure Gen_Adafinal_C
is
240 WBI
("void " & Ada_Final_Name
.all & " () {");
241 WBI
(" system__standard_library__adafinal ();");
246 ---------------------
247 -- Gen_Adainit_Ada --
248 ---------------------
250 procedure Gen_Adainit_Ada
is
251 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
254 WBI
(" procedure " & Ada_Init_Name
.all & " is");
256 -- Generate externals for elaboration entities
258 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
260 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
261 U
: Unit_Record
renames Units
.Table
(Unum
);
264 if U
.Set_Elab_Entity
then
267 Set_Unit_Number
(Unum
);
268 Set_String
(" : Boolean; pragma Import (Ada, ");
270 Set_Unit_Number
(Unum
);
272 Get_Name_String
(U
.Uname
);
274 -- In the case of JGNAT we need to emit an Import name
275 -- that includes the class name (using '$' separators
276 -- in the case of a child unit name).
278 if Hostparm
.Java_VM
then
279 for J
in 1 .. Name_Len
- 2 loop
280 if Name_Buffer
(J
) /= '.' then
281 Set_Char
(Name_Buffer
(J
));
289 -- If the unit name is very long, then split the
290 -- Import link name across lines using "&" (occurs
291 -- in some C2 tests).
293 if 2 * Name_Len
+ 60 > Hostparm
.Max_Line_Length
then
295 Write_Statement_Buffer
;
301 Set_String
("_E"");");
302 Write_Statement_Buffer
;
307 Write_Statement_Buffer
;
309 -- Case of No_Run_Time mode. The only global variable that might
310 -- be needed (by the Ravenscar profile) is the priority of the
311 -- environment. Also no exception tables are needed.
313 if No_Run_Time_Specified
then
314 if Main_Priority
/= No_Main_Priority
then
315 WBI
(" Main_Priority : Integer;");
316 WBI
(" pragma Import (C, Main_Priority," &
317 " ""__gl_main_priority"");");
323 if Main_Priority
/= No_Main_Priority
then
324 Set_String
(" Main_Priority := ");
325 Set_Int
(Main_Priority
);
327 Write_Statement_Buffer
;
333 -- Normal case (not No_Run_Time mode). The global values are
334 -- assigned using the runtime routine Set_Globals (we have to use
335 -- the routine call, rather than define the globals in the binder
336 -- file to deal with cross-library calls in some systems.
339 -- Generate restrictions string
341 Set_String
(" Restrictions : constant String :=");
342 Write_Statement_Buffer
;
345 for J
in Restrictions
'Range loop
346 Set_Char
(Restrictions
(J
));
350 Write_Statement_Buffer
;
353 WBI
(" procedure Set_Globals");
354 WBI
(" (Main_Priority : Integer;");
355 WBI
(" Time_Slice_Value : Integer;");
356 WBI
(" WC_Encoding : Character;");
357 WBI
(" Locking_Policy : Character;");
358 WBI
(" Queuing_Policy : Character;");
359 WBI
(" Task_Dispatching_Policy : Character;");
360 WBI
(" Restrictions : System.Address;");
361 WBI
(" Unreserve_All_Interrupts : Integer;");
362 WBI
(" Exception_Tracebacks : Integer;");
363 WBI
(" Zero_Cost_Exceptions : Integer);");
364 WBI
(" pragma Import (C, Set_Globals, ""__gnat_set_globals"");");
366 -- Import entry point for elaboration time signal handler
367 -- installation, and indication of whether it's been called
371 WBI
(" procedure Install_Handler;");
372 WBI
(" pragma Import (C, Install_Handler, " &
373 """__gnat_install_handler"");");
375 WBI
(" Handler_Installed : Integer;");
376 WBI
(" pragma Import (C, Handler_Installed, " &
377 """__gnat_handler_installed"");");
379 -- Generate exception table
381 Gen_Exception_Table_Ada
;
383 -- Generate the call to Set_Globals
385 WBI
(" Set_Globals");
387 Set_String
(" (Main_Priority => ");
388 Set_Int
(Main_Priority
);
390 Write_Statement_Buffer
;
392 Set_String
(" Time_Slice_Value => ");
394 if Task_Dispatching_Policy_Specified
= 'F'
395 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
399 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
403 Write_Statement_Buffer
;
405 Set_String
(" WC_Encoding => '");
406 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
408 Write_Statement_Buffer
;
410 Set_String
(" Locking_Policy => '");
411 Set_Char
(Locking_Policy_Specified
);
413 Write_Statement_Buffer
;
415 Set_String
(" Queuing_Policy => '");
416 Set_Char
(Queuing_Policy_Specified
);
418 Write_Statement_Buffer
;
420 Set_String
(" Task_Dispatching_Policy => '");
421 Set_Char
(Task_Dispatching_Policy_Specified
);
423 Write_Statement_Buffer
;
425 WBI
(" Restrictions => Restrictions'Address,");
427 Set_String
(" Unreserve_All_Interrupts => ");
429 if Unreserve_All_Interrupts_Specified
then
436 Write_Statement_Buffer
;
438 Set_String
(" Exception_Tracebacks => ");
440 if Exception_Tracebacks
then
447 Write_Statement_Buffer
;
449 Set_String
(" Zero_Cost_Exceptions => ");
451 if Zero_Cost_Exceptions_Specified
then
458 Write_Statement_Buffer
;
460 -- Generate call to Install_Handler
462 WBI
(" if Handler_Installed = 0 then");
463 WBI
(" Install_Handler;");
469 WBI
(" end " & Ada_Init_Name
.all & ";");
476 procedure Gen_Adainit_C
is
477 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
480 WBI
("void " & Ada_Init_Name
.all & " ()");
483 -- Generate externals for elaboration entities
485 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
487 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
488 U
: Unit_Record
renames Units
.Table
(Unum
);
491 if U
.Set_Elab_Entity
then
492 Set_String
(" extern char ");
493 Get_Name_String
(U
.Uname
);
496 Write_Statement_Buffer
;
501 Write_Statement_Buffer
;
505 if No_Run_Time_Specified
then
507 -- Case of No_Run_Time mode. Set __gl_main_priority if needed
508 -- for the Ravenscar profile.
510 if Main_Priority
/= No_Main_Priority
then
511 Set_String
(" extern int __gl_main_priority = ");
512 Set_Int
(Main_Priority
);
514 Write_Statement_Buffer
;
517 -- Normal case (run time present)
520 -- Generate definition for restrictions string
522 Set_String
(" const char *restrictions = """);
524 for J
in Restrictions
'Range loop
525 Set_Char
(Restrictions
(J
));
529 Write_Statement_Buffer
;
531 -- Code for normal case (not in No_Run_Time mode)
533 Gen_Exception_Table_C
;
535 -- Generate call to set the runtime global variables defined in
536 -- a-init.c. We define the varables in a-init.c, rather than in
537 -- the binder generated file itself to avoid undefined externals
538 -- when the runtime is linked as a shareable image library.
540 -- We call the routine from inside adainit() because this works for
541 -- both programs with and without binder generated "main" functions.
543 WBI
(" __gnat_set_globals (");
546 Set_Int
(Main_Priority
);
549 Set_String
("/* Main_Priority */");
550 Write_Statement_Buffer
;
554 if Task_Dispatching_Policy
= 'F'
555 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
559 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
564 Set_String
("/* Time_Slice_Value */");
565 Write_Statement_Buffer
;
568 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
571 Set_String
("/* WC_Encoding */");
572 Write_Statement_Buffer
;
575 Set_Char
(Locking_Policy_Specified
);
578 Set_String
("/* Locking_Policy */");
579 Write_Statement_Buffer
;
582 Set_Char
(Queuing_Policy_Specified
);
585 Set_String
("/* Queuing_Policy */");
586 Write_Statement_Buffer
;
589 Set_Char
(Task_Dispatching_Policy_Specified
);
592 Set_String
("/* Tasking_Dispatching_Policy */");
593 Write_Statement_Buffer
;
596 Set_String
("restrictions");
599 Set_String
("/* Restrictions */");
600 Write_Statement_Buffer
;
603 Set_Int
(Boolean'Pos (Unreserve_All_Interrupts_Specified
));
606 Set_String
("/* Unreserve_All_Interrupts */");
607 Write_Statement_Buffer
;
610 Set_Int
(Boolean'Pos (Exception_Tracebacks
));
613 Set_String
("/* Exception_Tracebacks */");
614 Write_Statement_Buffer
;
617 Set_Int
(Boolean'Pos (Zero_Cost_Exceptions_Specified
));
620 Set_String
("/* Zero_Cost_Exceptions */");
621 Write_Statement_Buffer
;
623 -- Install elaboration time signal handler
625 WBI
(" if (__gnat_handler_installed == 0)");
627 WBI
(" __gnat_install_handler ();");
636 ------------------------
637 -- Gen_Elab_Calls_Ada --
638 ------------------------
640 procedure Gen_Elab_Calls_Ada
is
643 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
645 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
646 U
: Unit_Record
renames Units
.Table
(Unum
);
649 -- This is the unit number of the spec that corresponds to
650 -- this entry. It is the same as Unum except when the body
651 -- and spec are different and we are currently processing
652 -- the body, in which case it is the spec (Unum + 1).
655 if U
.Utype
= Is_Body
then
656 Unum_Spec
:= Unum
+ 1;
661 -- Case of no elaboration code
665 -- The only case in which we have to do something is if
666 -- this is a body, with a separate spec, where the separate
667 -- spec has an elaboration entity defined.
669 -- In that case, this is where we set the elaboration entity
670 -- to True, we do not need to test if this has already been
671 -- done, since it is quicker to set the flag than to test it.
674 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
677 Set_Unit_Number
(Unum_Spec
);
678 Set_String
(" := True;");
679 Write_Statement_Buffer
;
682 -- Here if elaboration code is present. We generate:
684 -- if not uname_E then
685 -- uname'elab_[spec|body];
689 -- The uname_E assignment is skipped if this is a separate spec,
690 -- since the assignment will be done when we process the body.
693 Set_String
(" if not E");
694 Set_Unit_Number
(Unum_Spec
);
695 Set_String
(" then");
696 Write_Statement_Buffer
;
699 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
701 if Name_Buffer
(Name_Len
) = 's' then
702 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_spec";
704 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_body";
707 Name_Len
:= Name_Len
+ 8;
708 Set_Casing
(U
.Icasing
);
711 Write_Statement_Buffer
;
713 if U
.Utype
/= Is_Spec
then
715 Set_Unit_Number
(Unum_Spec
);
716 Set_String
(" := True;");
717 Write_Statement_Buffer
;
725 end Gen_Elab_Calls_Ada
;
727 ----------------------
728 -- Gen_Elab_Calls_C --
729 ----------------------
731 procedure Gen_Elab_Calls_C
is
734 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
736 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
737 U
: Unit_Record
renames Units
.Table
(Unum
);
740 -- This is the unit number of the spec that corresponds to
741 -- this entry. It is the same as Unum except when the body
742 -- and spec are different and we are currently processing
743 -- the body, in which case it is the spec (Unum + 1).
746 if U
.Utype
= Is_Body
then
747 Unum_Spec
:= Unum
+ 1;
752 -- Case of no elaboration code
756 -- The only case in which we have to do something is if
757 -- this is a body, with a separate spec, where the separate
758 -- spec has an elaboration entity defined.
760 -- In that case, this is where we set the elaboration entity
761 -- to True, we do not need to test if this has already been
762 -- done, since it is quicker to set the flag than to test it.
765 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
768 Get_Name_String
(U
.Uname
);
770 Set_String
("_E = 1;");
771 Write_Statement_Buffer
;
774 -- Here if elaboration code is present. We generate:
776 -- if (uname_E == 0) {
777 -- uname__elab[s|b] ();
781 -- The uname_E assignment is skipped if this is a separate spec,
782 -- since the assignment will be done when we process the body.
785 Set_String
(" if (");
786 Get_Name_String
(U
.Uname
);
788 Set_String
("_E == 0) {");
789 Write_Statement_Buffer
;
793 Set_String
("___elab");
794 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
796 Write_Statement_Buffer
;
798 if U
.Utype
/= Is_Spec
then
801 Set_String
("_E++;");
802 Write_Statement_Buffer
;
810 end Gen_Elab_Calls_C
;
812 ----------------------
813 -- Gen_Elab_Defs_C --
814 ----------------------
816 procedure Gen_Elab_Defs_C
is
818 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
820 -- Generate declaration of elaboration procedure if elaboration
821 -- needed. Note that passive units are always excluded.
823 if not Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
824 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
825 Set_String
("extern void ");
827 Set_String
("___elab");
828 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
829 Set_String
(" PARAMS ((void));");
830 Write_Statement_Buffer
;
838 ------------------------
839 -- Gen_Elab_Order_Ada --
840 ------------------------
842 procedure Gen_Elab_Order_Ada
is
845 WBI
(" -- BEGIN ELABORATION ORDER");
847 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
849 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
851 Write_Statement_Buffer
;
854 WBI
(" -- END ELABORATION ORDER");
855 end Gen_Elab_Order_Ada
;
857 ----------------------
858 -- Gen_Elab_Order_C --
859 ----------------------
861 procedure Gen_Elab_Order_C
is
864 WBI
("/* BEGIN ELABORATION ORDER");
866 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
867 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
869 Write_Statement_Buffer
;
872 WBI
(" END ELABORATION ORDER */");
873 end Gen_Elab_Order_C
;
875 -----------------------------
876 -- Gen_Exception_Table_Ada --
877 -----------------------------
879 procedure Gen_Exception_Table_Ada
is
881 Last
: ALI_Id
:= No_ALI_Id
;
884 if not Zero_Cost_Exceptions_Specified
then
889 -- The code we generate looks like
891 -- procedure SDP_Table_Build
892 -- (SDP_Addresses : System.Address;
893 -- SDP_Count : Natural;
894 -- Elab_Addresses : System.Address;
895 -- Elab_Addr_Count : Natural);
896 -- pragma Import (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
898 -- ST : aliased constant array (1 .. nnn) of System.Address := (
899 -- unit_name_1'UET_Address,
900 -- unit_name_2'UET_Address,
902 -- unit_name_3'UET_Address,
904 -- EA : aliased constant array (1 .. eee) of System.Address := (
905 -- adainit'Code_Address,
906 -- adafinal'Code_Address,
907 -- unit_name'elab[spec|body]'Code_Address,
908 -- unit_name'elab[spec|body]'Code_Address,
909 -- unit_name'elab[spec|body]'Code_Address,
910 -- unit_name'elab[spec|body]'Code_Address);
913 -- SDP_Table_Build (ST'Address, nnn, EA'Address, eee);
916 for A
in ALIs
.First
.. ALIs
.Last
loop
917 if ALIs
.Table
(A
).Unit_Exception_Table
then
925 -- Happens with "gnatmake -a -f -gnatL ..."
932 WBI
(" procedure SDP_Table_Build");
933 WBI
(" (SDP_Addresses : System.Address;");
934 WBI
(" SDP_Count : Natural;");
935 WBI
(" Elab_Addresses : System.Address;");
936 WBI
(" Elab_Addr_Count : Natural);");
938 "pragma Import (C, SDP_Table_Build, ""__gnat_SDP_Table_Build"");");
941 Set_String
(" ST : aliased constant array (1 .. ");
943 Set_String
(") of System.Address := (");
946 Set_String
("1 => A1);");
947 Write_Statement_Buffer
;
950 Write_Statement_Buffer
;
952 for A
in ALIs
.First
.. ALIs
.Last
loop
953 if ALIs
.Table
(A
).Unit_Exception_Table
then
954 Get_Decoded_Name_String_With_Brackets
955 (Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
956 Set_Casing
(Mixed_Case
);
958 Set_String
(Name_Buffer
(1 .. Name_Len
- 2));
959 Set_String
("'UET_Address");
967 Write_Statement_Buffer
;
973 Set_String
(" EA : aliased constant array (1 .. ");
974 Set_Int
(Num_Elab_Calls
+ 2);
975 Set_String
(") of System.Address := (");
976 Write_Statement_Buffer
;
977 WBI
(" " & Ada_Init_Name
.all & "'Code_Address,");
979 -- If compiling for the JVM, we directly reference Adafinal because
980 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
982 if Hostparm
.Java_VM
then
983 Set_String
(" System.Standard_Library.Adafinal'Code_Address");
985 Set_String
(" Do_Finalize'Code_Address");
988 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
989 Get_Decoded_Name_String_With_Brackets
990 (Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
992 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
997 Write_Statement_Buffer
;
1000 if Name_Buffer
(Name_Len
) = 's' then
1001 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
1002 "'elab_spec'code_address";
1004 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
1005 "'elab_body'code_address";
1008 Name_Len
:= Name_Len
+ 21;
1009 Set_Casing
(Units
.Table
(Elab_Order
.Table
(E
)).Icasing
);
1015 Write_Statement_Buffer
;
1020 Set_String
(" SDP_Table_Build (ST'Address, ");
1022 Set_String
(", EA'Address, ");
1023 Set_Int
(Num_Elab_Calls
+ 2);
1025 Write_Statement_Buffer
;
1026 end Gen_Exception_Table_Ada
;
1028 ---------------------------
1029 -- Gen_Exception_Table_C --
1030 ---------------------------
1032 procedure Gen_Exception_Table_C
is
1037 if not Zero_Cost_Exceptions_Specified
then
1041 -- The code we generate looks like
1043 -- extern void *__gnat_unitname1__SDP;
1044 -- extern void *__gnat_unitname2__SDP;
1047 -- void **st[nnn] = {
1048 -- &__gnat_unitname1__SDP,
1049 -- &__gnat_unitname2__SDP,
1051 -- &__gnat_unitnamen__SDP};
1053 -- extern void unitname1__elabb ();
1054 -- extern void unitname2__elabb ();
1057 -- void (*ea[eee]) () = {
1060 -- unitname1___elab[b,s],
1061 -- unitname2___elab[b,s],
1063 -- unitnamen___elab[b,s]};
1065 -- __gnat_SDP_Table_Build (&st, nnn, &ea, eee);
1068 for A
in ALIs
.First
.. ALIs
.Last
loop
1069 if ALIs
.Table
(A
).Unit_Exception_Table
then
1072 Set_String
(" extern void *__gnat_");
1073 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1075 Set_String
("__SDP");
1077 Write_Statement_Buffer
;
1083 -- Happens with "gnatmake -a -f -gnatL ..."
1090 Set_String
(" void **st[");
1092 Set_String
("] = {");
1093 Write_Statement_Buffer
;
1096 for A
in ALIs
.First
.. ALIs
.Last
loop
1097 if ALIs
.Table
(A
).Unit_Exception_Table
then
1100 Set_String
(" &__gnat_");
1101 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1103 Set_String
("__SDP");
1111 Write_Statement_Buffer
;
1116 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1117 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1119 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1123 Set_String
(" extern void ");
1125 Set_String
("___elab");
1126 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1127 Set_String
(" ();");
1128 Write_Statement_Buffer
;
1133 Set_String
(" void (*ea[");
1134 Set_Int
(Num_Elab_Calls
+ 2);
1135 Set_String
("]) () = {");
1136 Write_Statement_Buffer
;
1138 WBI
(" " & Ada_Init_Name
.all & ",");
1139 Set_String
(" system__standard_library__adafinal");
1141 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1142 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1144 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1149 Write_Statement_Buffer
;
1152 Set_String
("___elab");
1153 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1158 Write_Statement_Buffer
;
1162 Set_String
(" __gnat_SDP_Table_Build (&st, ");
1164 Set_String
(", ea, ");
1165 Set_Int
(Num_Elab_Calls
+ 2);
1167 Write_Statement_Buffer
;
1168 end Gen_Exception_Table_C
;
1174 procedure Gen_Main_Ada
is
1175 Target
: constant String_Ptr
:= Target_Name
;
1176 VxWorks_Target
: constant Boolean :=
1177 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1178 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1182 Set_String
(" function ");
1183 Set_String
(Get_Main_Name
);
1185 if VxWorks_Target
then
1186 Set_String
(" return Integer is");
1187 Write_Statement_Buffer
;
1190 Write_Statement_Buffer
;
1191 WBI
(" (argc : Integer;");
1192 WBI
(" argv : System.Address;");
1193 WBI
(" envp : System.Address)");
1194 WBI
(" return Integer");
1198 -- Initialize and Finalize are not used in No_Run_Time mode
1200 if not No_Run_Time_Specified
then
1201 WBI
(" procedure initialize;");
1202 WBI
(" pragma Import (C, initialize, ""__gnat_initialize"");");
1204 WBI
(" procedure finalize;");
1205 WBI
(" pragma Import (C, finalize, ""__gnat_finalize"");");
1209 -- Deal with declarations for main program case
1211 if not No_Main_Subprogram
then
1213 -- To call the main program, we declare it using a pragma Import
1214 -- Ada with the right link name.
1216 -- It might seem more obvious to "with" the main program, and call
1217 -- it in the normal Ada manner. We do not do this for three reasons:
1219 -- 1. It is more efficient not to recompile the main program
1220 -- 2. We are not entitled to assume the source is accessible
1221 -- 3. We don't know what options to use to compile it
1223 -- It is really reason 3 that is most critical (indeed we used
1224 -- to generate the "with", but several regression tests failed).
1228 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1229 WBI
(" Result : Integer;");
1231 WBI
(" function Ada_Main_Program return Integer;");
1234 WBI
(" procedure Ada_Main_Program;");
1237 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1238 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1239 Set_Main_Program_Name
;
1240 Set_String
(""");");
1242 Write_Statement_Buffer
;
1246 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1247 -- not referenced elsewhere in the generated program, but is needed
1248 -- by the debugger (that's why it is generated in the first place).
1249 -- The reference stops Ada_Main_Program_Name from being optimized
1250 -- away by smart linkers, such as the AiX linker.
1252 if Bind_Main_Program
then
1254 (" Ensure_Reference : System.Address := " &
1255 "Ada_Main_Program_Name'Address;");
1261 -- On VxWorks, there are no command line arguments
1263 if VxWorks_Target
then
1264 WBI
(" gnat_argc := 0;");
1265 WBI
(" gnat_argv := System.Null_Address;");
1266 WBI
(" gnat_envp := System.Null_Address;");
1268 -- Normal case of command line arguments present
1271 WBI
(" gnat_argc := argc;");
1272 WBI
(" gnat_argv := argv;");
1273 WBI
(" gnat_envp := envp;");
1277 if not No_Run_Time_Specified
then
1278 WBI
(" Initialize;");
1281 WBI
(" " & Ada_Init_Name
.all & ";");
1283 if not No_Main_Subprogram
then
1284 WBI
(" Break_Start;");
1286 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1287 WBI
(" Ada_Main_Program;");
1289 WBI
(" Result := Ada_Main_Program;");
1293 -- Adafinal is only called if we have a run time
1295 if not No_Run_Time_Specified
then
1297 -- If compiling for the JVM, we directly call Adafinal because
1298 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1300 if Hostparm
.Java_VM
then
1301 WBI
(" System.Standard_Library.Adafinal;");
1303 WBI
(" Do_Finalize;");
1307 -- Finalize is only called if we have a run time
1309 if not No_Run_Time_Specified
then
1315 if No_Main_Subprogram
1316 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1318 WBI
(" return (gnat_exit_status);");
1320 WBI
(" return (Result);");
1330 procedure Gen_Main_C
is
1331 Target
: constant String_Ptr
:= Target_Name
;
1332 VxWorks_Target
: constant Boolean :=
1333 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1334 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1337 Set_String
("int ");
1338 Set_String
(Get_Main_Name
);
1340 -- On VxWorks, there are no command line arguments
1342 if VxWorks_Target
then
1345 -- Normal case with command line arguments present
1348 Set_String
(" (argc, argv, envp)");
1351 Write_Statement_Buffer
;
1353 -- VxWorks doesn't have the notion of argc/argv
1355 if VxWorks_Target
then
1357 WBI
(" int result;");
1358 WBI
(" gnat_argc = 0;");
1359 WBI
(" gnat_argv = 0;");
1360 WBI
(" gnat_envp = 0;");
1362 -- Normal case of arguments present
1366 WBI
(" char **argv;");
1367 WBI
(" char **envp;");
1370 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1371 -- is not referenced elsewhere in the generated program, but is
1372 -- needed by the debugger (that's why it is generated in the first
1373 -- place). The reference stops Ada_Main_Program_Name from being
1374 -- optimized away by smart linkers, such as the AiX linker.
1376 if Bind_Main_Program
then
1377 WBI
(" char *ensure_reference = __gnat_ada_main_program_name;");
1381 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1382 WBI
(" int result;");
1385 WBI
(" gnat_argc = argc;");
1386 WBI
(" gnat_argv = argv;");
1387 WBI
(" gnat_envp = envp;");
1391 -- The __gnat_initialize routine is used only if we have a run-time
1393 if not No_Run_Time_Specified
then
1395 (" __gnat_initialize ();");
1398 WBI
(" " & Ada_Init_Name
.all & " ();");
1400 if not No_Main_Subprogram
then
1402 WBI
(" __gnat_break_start ();");
1405 -- Output main program name
1407 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1409 -- Main program is procedure case
1411 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1413 Set_Main_Program_Name
;
1414 Set_String
(" ();");
1415 Write_Statement_Buffer
;
1417 -- Main program is function case
1419 else -- ALIs.Table (ALIs_First).Main_Program = Func
1420 Set_String
(" result = ");
1421 Set_Main_Program_Name
;
1422 Set_String
(" ();");
1423 Write_Statement_Buffer
;
1428 -- Adafinal is called only when we have a run-time
1430 if not No_Run_Time_Specified
then
1432 WBI
(" system__standard_library__adafinal ();");
1435 -- The finalize routine is used only if we have a run-time
1437 if not No_Run_Time_Specified
then
1438 WBI
(" __gnat_finalize ();");
1441 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1443 if Hostparm
.OpenVMS
then
1445 -- VMS must use the Posix exit routine in order to get an
1446 -- Unix compatible exit status.
1448 WBI
(" __posix_exit (result);");
1451 WBI
(" exit (result);");
1456 if Hostparm
.OpenVMS
then
1457 -- VMS must use the Posix exit routine in order to get an
1458 -- Unix compatible exit status.
1459 WBI
(" __posix_exit (gnat_exit_status);");
1461 WBI
(" exit (gnat_exit_status);");
1468 ------------------------------
1469 -- Gen_Object_Files_Options --
1470 ------------------------------
1472 procedure Gen_Object_Files_Options
is
1474 -- This keeps track of the position in the sorted set of entries
1475 -- in the Linker_Options table of where the first entry from an
1476 -- internal file appears.
1478 procedure Write_Linker_Option
;
1479 -- Write binder info linker option.
1481 -------------------------
1482 -- Write_Linker_Option --
1483 -------------------------
1485 procedure Write_Linker_Option
is
1490 -- Loop through string, breaking at null's
1493 while Start
< Name_Len
loop
1495 -- Find null ending this section
1498 while Name_Buffer
(Stop
) /= ASCII
.NUL
1499 and then Stop
<= Name_Len
loop
1503 -- Process section if non-null
1505 if Stop
> Start
then
1506 if Output_Linker_Option_List
then
1507 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1511 (" -- ", "", Name_Buffer
(Start
.. Stop
- 1));
1516 end Write_Linker_Option
;
1518 -- Start of processing for Gen_Object_Files_Options
1522 Write_Info_Ada_C
("--", "/*", " BEGIN Object file/option list");
1524 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1526 -- If not spec that has an associated body, then generate a
1527 -- comment giving the name of the corresponding object file.
1529 if Units
.Table
(Elab_Order
.Table
(E
)).Utype
/= Is_Spec
then
1532 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Ofile_Full_Name
);
1534 -- If the presence of an object file is necessary or if it
1535 -- exists, then use it.
1537 if not Hostparm
.Exclude_Missing_Objects
1539 GNAT
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
1541 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1542 if Output_Object_List
then
1543 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1547 -- Don't link with the shared library on VMS if an internal
1548 -- filename object is seen. Multiply defined symbols will
1552 and then Is_Internal_File_Name
1554 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Sfile
)
1556 Opt
.Shared_Libgnat
:= False;
1563 -- Add a "-Ldir" for each directory in the object path. We skip this
1564 -- in No_Run_Time mode, where we want more precise control of exactly
1565 -- what goes into the resulting object file
1567 if not No_Run_Time_Specified
then
1568 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
1570 Dir
: String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
1574 Add_Str_To_Name_Buffer
("-L");
1575 Add_Str_To_Name_Buffer
(Dir
.all);
1576 Write_Linker_Option
;
1581 -- Sort linker options
1583 -- This sort accomplishes two important purposes:
1585 -- a) All application files are sorted to the front, and all
1586 -- GNAT internal files are sorted to the end. This results
1587 -- in a well defined dividing line between the two sets of
1588 -- files, for the purpose of inserting certain standard
1589 -- library references into the linker arguments list.
1591 -- b) Given two different units, we sort the linker options so
1592 -- that those from a unit earlier in the elaboration order
1593 -- comes later in the list. This is a heuristic designed
1594 -- to create a more friendly order of linker options when
1595 -- the operations appear in separate units. The idea is that
1596 -- if unit A must be elaborated before unit B, then it is
1597 -- more likely that B references libraries included by A,
1598 -- than vice versa, so we want the libraries included by
1599 -- A to come after the libraries included by B.
1601 -- These two criteria are implemented by function Lt_Linker_Option.
1602 -- Note that a special case of b) is that specs are elaborated before
1603 -- bodies, so linker options from specs come after linker options
1604 -- for bodies, and again, the assumption is that libraries used by
1605 -- the body are more likely to reference libraries used by the spec,
1609 (Linker_Options
.Last
,
1610 Move_Linker_Option
'Access,
1611 Lt_Linker_Option
'Access);
1613 -- Write user linker options, i.e. the set of linker options that
1614 -- come from all files other than GNAT internal files, Lgnat is
1615 -- left set to point to the first entry from a GNAT internal file,
1616 -- or past the end of the entriers if there are no internal files.
1618 Lgnat
:= Linker_Options
.Last
+ 1;
1620 for J
in 1 .. Linker_Options
.Last
loop
1621 if not Linker_Options
.Table
(J
).Internal_File
then
1622 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1623 Write_Linker_Option
;
1630 -- Now we insert standard linker options that must appear after the
1631 -- entries from user files, and before the entries from GNAT run-time
1632 -- files. The reason for this decision is that libraries referenced
1633 -- by internal routines may reference these standard library entries.
1635 if not (No_Run_Time_Specified
or else Opt
.No_Stdlib
) then
1638 if Opt
.Shared_Libgnat
then
1639 Add_Str_To_Name_Buffer
("-shared");
1641 Add_Str_To_Name_Buffer
("-static");
1644 -- Write directly to avoid -K output (why???)
1646 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1648 if With_DECGNAT
then
1650 Add_Str_To_Name_Buffer
("-ldecgnat");
1651 Write_Linker_Option
;
1656 Add_Str_To_Name_Buffer
("-lgnarl");
1657 Write_Linker_Option
;
1661 Add_Str_To_Name_Buffer
("-lgnat");
1662 Write_Linker_Option
;
1665 -- Write linker options from all internal files
1667 for J
in Lgnat
.. Linker_Options
.Last
loop
1668 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1669 Write_Linker_Option
;
1672 if Ada_Bind_File
then
1673 WBI
("-- END Object file/option list ");
1675 WBI
(" END Object file/option list */");
1678 end Gen_Object_Files_Options
;
1680 ---------------------
1681 -- Gen_Output_File --
1682 ---------------------
1684 procedure Gen_Output_File
(Filename
: String) is
1685 Public_Version
: constant Boolean := Gnat_Version_Type
= "PUBLIC ";
1686 -- Set true if this is the public version of GNAT
1689 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1690 -- JGNAT only supports Ada code, and the main program is already
1691 -- generated by the compiler.
1693 if Hostparm
.Java_VM
then
1694 Ada_Bind_File
:= True;
1695 Bind_Main_Program
:= False;
1698 -- Override time slice value if -T switch is set
1700 if Time_Slice_Set
then
1701 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
1704 -- Count number of elaboration calls
1706 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1707 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1710 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
1714 -- Get the time stamp of the former bind for public version warning
1716 if Public_Version
then
1717 Record_Time_From_Last_Bind
;
1720 -- Generate output file in appropriate language
1722 if Ada_Bind_File
then
1723 Gen_Output_File_Ada
(Filename
);
1725 Gen_Output_File_C
(Filename
);
1728 -- Periodically issue a warning when the public version is used on
1731 if Public_Version
then
1732 Public_Version_Warning
;
1734 end Gen_Output_File
;
1736 -------------------------
1737 -- Gen_Output_File_Ada --
1738 -------------------------
1740 procedure Gen_Output_File_Ada
(Filename
: String) is
1743 -- Name of generated bind file (spec)
1746 -- Name of generated bind file (body)
1748 Ada_Main
: constant String := Get_Ada_Main_Name
;
1749 -- Name to be used for generated Ada main program. See the body of
1750 -- function Get_Ada_Main_Name for details on the form of the name.
1752 Target
: constant String_Ptr
:= Target_Name
;
1753 VxWorks_Target
: constant Boolean :=
1754 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1755 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1758 -- Create spec first
1760 Create_Binder_Output
(Filename
, 's', Bfiles
);
1762 if No_Run_Time_Specified
then
1763 WBI
("pragma No_Run_Time;");
1766 -- Generate with of System so we can reference System.Address, note
1767 -- that such a reference is safe even in No_Run_Time mode, since we
1768 -- do not need any run-time code for such a reference, and we output
1769 -- a pragma No_Run_Time for this compilation above.
1771 WBI
("with System;");
1773 -- Generate with of System.Initialize_Scalars if active
1775 if Initialize_Scalars_Used
then
1776 WBI
("with System.Scalar_Values;");
1779 Resolve_Binder_Options
;
1781 if not No_Run_Time_Specified
then
1783 -- Usually, adafinal is called using a pragma Import C. Since
1784 -- Import C doesn't have the same semantics for JGNAT, we use
1787 if Hostparm
.Java_VM
then
1788 WBI
("with System.Standard_Library;");
1792 WBI
("package " & Ada_Main
& " is");
1794 -- Main program case
1796 if Bind_Main_Program
then
1798 -- Generate argc/argv stuff
1801 WBI
(" gnat_argc : Integer;");
1802 WBI
(" gnat_argv : System.Address;");
1803 WBI
(" gnat_envp : System.Address;");
1805 -- If we have a run time present, these variables are in the
1806 -- runtime data area for easy access from the runtime
1808 if not No_Run_Time_Specified
then
1810 WBI
(" pragma Import (C, gnat_argc);");
1811 WBI
(" pragma Import (C, gnat_argv);");
1812 WBI
(" pragma Import (C, gnat_envp);");
1815 -- Define exit status. Again in normal mode, this is in the
1816 -- run-time library, and is initialized there, but in the no
1817 -- run time case, the variable is here and initialized here.
1821 if No_Run_Time_Specified
then
1822 WBI
(" gnat_exit_status : Integer := 0;");
1824 WBI
(" gnat_exit_status : Integer;");
1825 WBI
(" pragma Import (C, gnat_exit_status);");
1829 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
1830 -- the main program. Otherwise, it can lead under some circumstances
1831 -- to a symbol duplication during the link (for instance when a
1832 -- C program uses 2 Ada libraries)
1834 if Bind_Main_Program
then
1836 WBI
(" GNAT_Version : constant String :=");
1837 WBI
(" ""GNAT Version: " &
1838 Gnat_Version_String
& """;");
1839 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
1842 Set_String
(" Ada_Main_Program_Name : constant String := """);
1843 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1844 Set_Main_Program_Name
;
1845 Set_String
(""" & Ascii.NUL;");
1846 Write_Statement_Buffer
;
1849 (" pragma Export (C, Ada_Main_Program_Name, " &
1850 """__gnat_ada_main_program_name"");");
1853 -- No need to generate a finalization routine if there is no
1854 -- runtime, since there is nothing to do in this case.
1856 if not No_Run_Time_Specified
then
1858 WBI
(" procedure " & Ada_Final_Name
.all & ";");
1859 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
1860 Ada_Final_Name
.all & """);");
1864 WBI
(" procedure " & Ada_Init_Name
.all & ";");
1865 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
1866 Ada_Init_Name
.all & """);");
1868 if Bind_Main_Program
then
1870 -- If we have a run time, then Break_Start is defined there, but
1871 -- if there is no run-time, Break_Start is defined in this file.
1874 WBI
(" procedure Break_Start;");
1876 if No_Run_Time_Specified
then
1877 WBI
(" pragma Export (C, Break_Start, ""__gnat_break_start"");");
1879 WBI
(" pragma Import (C, Break_Start, ""__gnat_break_start"");");
1883 WBI
(" function " & Get_Main_Name
);
1885 -- Generate argument list (except on VxWorks, where none is present)
1887 if not VxWorks_Target
then
1888 WBI
(" (argc : Integer;");
1889 WBI
(" argv : System.Address;");
1890 WBI
(" envp : System.Address)");
1893 WBI
(" return Integer;");
1894 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
1895 Get_Main_Name
& """);");
1898 if Initialize_Scalars_Used
then
1908 WBI
("end " & Ada_Main
& ";");
1909 Close_Binder_Output
;
1911 -- Prepare to write body
1913 Create_Binder_Output
(Filename
, 'b', Bfileb
);
1915 -- Output Source_File_Name pragmas which look like
1917 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
1918 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
1920 -- where sss/bbb are the spec/body file names respectively
1922 Get_Name_String
(Bfiles
);
1923 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1925 WBI
("pragma Source_File_Name (" &
1927 ", Spec_File_Name => """ &
1928 Name_Buffer
(1 .. Name_Len
+ 3));
1930 Get_Name_String
(Bfileb
);
1931 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1933 WBI
("pragma Source_File_Name (" &
1935 ", Body_File_Name => """ &
1936 Name_Buffer
(1 .. Name_Len
+ 3));
1939 WBI
("package body " & Ada_Main
& " is");
1941 -- Import the finalization procedure only if there is a runtime.
1943 if not No_Run_Time_Specified
then
1945 -- In the Java case, pragma Import C cannot be used, so the
1946 -- standard Ada constructs will be used instead.
1948 if not Hostparm
.Java_VM
then
1950 WBI
(" procedure Do_Finalize;");
1952 (" pragma Import (C, Do_Finalize, " &
1953 """system__standard_library__adafinal"");");
1960 -- No need to generate a finalization routine if there is no
1961 -- runtime, since there is nothing to do in this case.
1963 if not No_Run_Time_Specified
then
1967 if Bind_Main_Program
then
1969 -- In No_Run_Time mode, generate dummy body for Break_Start
1971 if No_Run_Time_Specified
then
1973 WBI
(" procedure Break_Start is");
1982 -- Output object file list and the Ada body is complete
1984 Gen_Object_Files_Options
;
1987 WBI
("end " & Ada_Main
& ";");
1989 Close_Binder_Output
;
1990 end Gen_Output_File_Ada
;
1992 -----------------------
1993 -- Gen_Output_File_C --
1994 -----------------------
1996 procedure Gen_Output_File_C
(Filename
: String) is
1999 -- Name of generated bind file
2002 Create_Binder_Output
(Filename
, 'c', Bfile
);
2004 Resolve_Binder_Options
;
2006 WBI
("#ifdef __STDC__");
2007 WBI
("#define PARAMS(paramlist) paramlist");
2009 WBI
("#define PARAMS(paramlist) ()");
2013 WBI
("extern void __gnat_set_globals ");
2014 WBI
(" PARAMS ((int, int, int, int, int, int, const char *,");
2015 WBI
(" int, int, int));");
2016 WBI
("extern void " & Ada_Final_Name
.all & " PARAMS ((void));");
2017 WBI
("extern void " & Ada_Init_Name
.all & " PARAMS ((void));");
2019 WBI
("extern void system__standard_library__adafinal PARAMS ((void));");
2021 if not No_Main_Subprogram
then
2022 WBI
("extern int main PARAMS ((int, char **, char **));");
2023 if Hostparm
.OpenVMS
then
2024 WBI
("extern void __posix_exit PARAMS ((int));");
2026 WBI
("extern void exit PARAMS ((int));");
2029 WBI
("extern void __gnat_break_start PARAMS ((void));");
2030 Set_String
("extern ");
2032 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2033 Set_String
("void ");
2035 Set_String
("int ");
2038 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2039 Set_Main_Program_Name
;
2040 Set_String
(" PARAMS ((void));");
2041 Write_Statement_Buffer
;
2044 if not No_Run_Time_Specified
then
2045 WBI
("extern void __gnat_initialize PARAMS ((void));");
2046 WBI
("extern void __gnat_finalize PARAMS ((void));");
2047 WBI
("extern void __gnat_install_handler PARAMS ((void));");
2054 -- Imported variable used to track elaboration/finalization phase.
2055 -- Used only when we have a runtime.
2057 if not No_Run_Time_Specified
then
2058 WBI
("extern int __gnat_handler_installed;");
2062 -- Write argv/argc stuff if main program case
2064 if Bind_Main_Program
then
2066 -- In the normal case, these are in the runtime library
2068 if not No_Run_Time_Specified
then
2069 WBI
("extern int gnat_argc;");
2070 WBI
("extern char **gnat_argv;");
2071 WBI
("extern char **gnat_envp;");
2072 WBI
("extern int gnat_exit_status;");
2074 -- In the No_Run_Time case, they are right in the binder file
2075 -- and we initialize gnat_exit_status in the declaration.
2078 WBI
("int gnat_argc;");
2079 WBI
("char **gnat_argv;");
2080 WBI
("char **gnat_envp;");
2081 WBI
("int gnat_exit_status = 0;");
2087 -- In no run-time mode, the __gnat_break_start routine (for the
2088 -- debugger to get initial control) is defined in this file.
2090 if No_Run_Time_Specified
then
2092 WBI
("void __gnat_break_start () {}");
2095 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2096 -- only for the main program. Otherwise, it can lead under some
2097 -- circumstances to a symbol duplication during the link (for instance
2098 -- when a C program uses 2 Ada libraries)
2100 if Bind_Main_Program
then
2102 WBI
("char __gnat_version[] = ""GNAT Version: " &
2103 Gnat_Version_String
& """;");
2105 Set_String
("char __gnat_ada_main_program_name[] = """);
2106 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2107 Set_Main_Program_Name
;
2109 Write_Statement_Buffer
;
2112 -- Generate the adafinal routine. In no runtime mode, this is
2113 -- not needed, since there is no finalization to do.
2115 if not No_Run_Time_Specified
then
2121 -- Main is only present for Ada main case
2123 if Bind_Main_Program
then
2127 -- Scalar values, versions and object files needed in both cases
2129 if Initialize_Scalars_Used
then
2135 Gen_Object_Files_Options
;
2137 -- C binder output is complete
2139 Close_Binder_Output
;
2140 end Gen_Output_File_C
;
2142 -----------------------
2143 -- Gen_Scalar_Values --
2144 -----------------------
2146 procedure Gen_Scalar_Values
is
2148 -- Strings to hold hex values of initialization constants. Note that
2149 -- we store these strings in big endian order, but they are actually
2150 -- used to initialize integer values, so the actual generated data
2151 -- will automaticaly have the right endianess.
2153 IS_Is1
: String (1 .. 2);
2154 IS_Is2
: String (1 .. 4);
2155 IS_Is4
: String (1 .. 8);
2156 IS_Is8
: String (1 .. 16);
2157 IS_Iu1
: String (1 .. 2);
2158 IS_Iu2
: String (1 .. 4);
2159 IS_Iu4
: String (1 .. 8);
2160 IS_Iu8
: String (1 .. 16);
2161 IS_Isf
: String (1 .. 8);
2162 IS_Ifl
: String (1 .. 8);
2163 IS_Ilf
: String (1 .. 16);
2165 -- The string for Long_Long_Float is special. This is used only on the
2166 -- ia32 with 80-bit extended float (stored in 96 bits by gcc). The
2167 -- value here is represented little-endian, since that's the only way
2168 -- it is ever generated (this is not used on big-endian machines.
2170 IS_Ill
: String (1 .. 24);
2173 -- -Sin (invalid values)
2175 if Opt
.Initialize_Scalars_Mode
= 'I' then
2178 IS_Is4
:= "80000000";
2179 IS_Is8
:= "8000000000000000";
2182 IS_Iu4
:= "FFFFFFFF";
2183 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2187 IS_Ill
:= "00000000000000C0FFFF0000";
2189 -- -Slo (low values)
2191 elsif Opt
.Initialize_Scalars_Mode
= 'L' then
2194 IS_Is4
:= "80000000";
2195 IS_Is8
:= "8000000000000000";
2198 IS_Iu4
:= "00000000";
2199 IS_Iu8
:= "0000000000000000";
2200 IS_Isf
:= "FF800000";
2202 IS_Ilf
:= "FFF0000000000000";
2203 IS_Ill
:= "0000000000000080FFFF0000";
2205 -- -Shi (high values)
2207 elsif Opt
.Initialize_Scalars_Mode
= 'H' then
2210 IS_Is4
:= "7FFFFFFF";
2211 IS_Is8
:= "7FFFFFFFFFFFFFFF";
2214 IS_Iu4
:= "FFFFFFFF";
2215 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2216 IS_Isf
:= "7F800000";
2218 IS_Ilf
:= "7FF0000000000000";
2219 IS_Ill
:= "0000000000000080FF7F0000";
2223 else pragma Assert
(Opt
.Initialize_Scalars_Mode
= 'X');
2224 IS_Is1
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2225 IS_Is2
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2226 IS_Is2
(3 .. 4) := Opt
.Initialize_Scalars_Val
;
2228 for J
in 1 .. 4 loop
2229 IS_Is4
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2232 for J
in 1 .. 8 loop
2233 IS_Is8
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2245 for J
in 1 .. 12 loop
2246 IS_Ill
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2250 -- Generate output, Ada case
2252 if Ada_Bind_File
then
2255 Set_String
(" IS_Is1 : constant System.Scalar_Values.Byte1 := 16#");
2256 Set_String
(IS_Is1
);
2257 Write_Statement_Buffer
("#;");
2259 Set_String
(" IS_Is2 : constant System.Scalar_Values.Byte2 := 16#");
2260 Set_String
(IS_Is2
);
2261 Write_Statement_Buffer
("#;");
2263 Set_String
(" IS_Is4 : constant System.Scalar_Values.Byte4 := 16#");
2264 Set_String
(IS_Is4
);
2265 Write_Statement_Buffer
("#;");
2267 Set_String
(" IS_Is8 : constant System.Scalar_Values.Byte8 := 16#");
2268 Set_String
(IS_Is8
);
2269 Write_Statement_Buffer
("#;");
2271 Set_String
(" IS_Iu1 : constant System.Scalar_Values.Byte1 := 16#");
2272 Set_String
(IS_Iu1
);
2273 Write_Statement_Buffer
("#;");
2275 Set_String
(" IS_Iu2 : constant System.Scalar_Values.Byte2 := 16#");
2276 Set_String
(IS_Iu2
);
2277 Write_Statement_Buffer
("#;");
2279 Set_String
(" IS_Iu4 : constant System.Scalar_Values.Byte4 := 16#");
2280 Set_String
(IS_Iu4
);
2281 Write_Statement_Buffer
("#;");
2283 Set_String
(" IS_Iu8 : constant System.Scalar_Values.Byte8 := 16#");
2284 Set_String
(IS_Iu8
);
2285 Write_Statement_Buffer
("#;");
2287 Set_String
(" IS_Isf : constant System.Scalar_Values.Byte4 := 16#");
2288 Set_String
(IS_Isf
);
2289 Write_Statement_Buffer
("#;");
2291 Set_String
(" IS_Ifl : constant System.Scalar_Values.Byte4 := 16#");
2292 Set_String
(IS_Ifl
);
2293 Write_Statement_Buffer
("#;");
2295 Set_String
(" IS_Ilf : constant System.Scalar_Values.Byte8 := 16#");
2296 Set_String
(IS_Ilf
);
2297 Write_Statement_Buffer
("#;");
2299 -- Special case of Long_Long_Float. This is a 10-byte value used
2300 -- only on the x86. We could omit it for other architectures, but
2301 -- we don't easily have that kind of target specialization in the
2302 -- binder, and it's only 10 bytes, and only if -Sxx is used. Note
2303 -- that for architectures where Long_Long_Float is the same as
2304 -- Long_Float, the expander uses the Long_Float constant for the
2305 -- initializations of Long_Long_Float values.
2307 WBI
(" IS_Ill : constant array (1 .. 12) of");
2308 WBI
(" System.Scalar_Values.Byte1 := (");
2311 for J
in 1 .. 6 loop
2312 Set_String
(" 16#");
2313 Set_Char
(IS_Ill
(2 * J
- 1));
2314 Set_Char
(IS_Ill
(2 * J
));
2318 Write_Statement_Buffer
;
2321 for J
in 7 .. 12 loop
2322 Set_String
(" 16#");
2323 Set_Char
(IS_Ill
(2 * J
- 1));
2324 Set_Char
(IS_Ill
(2 * J
));
2333 Write_Statement_Buffer
;
2335 -- Output export statements to export to System.Scalar_Values
2339 WBI
(" pragma Export (Ada, IS_Is1, ""__gnat_Is1"");");
2340 WBI
(" pragma Export (Ada, IS_Is2, ""__gnat_Is2"");");
2341 WBI
(" pragma Export (Ada, IS_Is4, ""__gnat_Is4"");");
2342 WBI
(" pragma Export (Ada, IS_Is8, ""__gnat_Is8"");");
2343 WBI
(" pragma Export (Ada, IS_Iu1, ""__gnat_Iu1"");");
2344 WBI
(" pragma Export (Ada, IS_Iu2, ""__gnat_Iu2"");");
2345 WBI
(" pragma Export (Ada, IS_Iu4, ""__gnat_Iu4"");");
2346 WBI
(" pragma Export (Ada, IS_Iu8, ""__gnat_Iu8"");");
2347 WBI
(" pragma Export (Ada, IS_Isf, ""__gnat_Isf"");");
2348 WBI
(" pragma Export (Ada, IS_Ifl, ""__gnat_Ifl"");");
2349 WBI
(" pragma Export (Ada, IS_Ilf, ""__gnat_Ilf"");");
2350 WBI
(" pragma Export (Ada, IS_Ill, ""__gnat_Ill"");");
2352 -- Generate output C case
2355 -- The lines we generate in this case are of the form
2356 -- typ __gnat_I?? = 0x??;
2357 -- where typ is appropriate to the length
2361 Set_String
("unsigned char __gnat_Is1 = 0x");
2362 Set_String
(IS_Is1
);
2363 Write_Statement_Buffer
(";");
2365 Set_String
("unsigned short __gnat_Is2 = 0x");
2366 Set_String
(IS_Is2
);
2367 Write_Statement_Buffer
(";");
2369 Set_String
("unsigned __gnat_Is4 = 0x");
2370 Set_String
(IS_Is4
);
2371 Write_Statement_Buffer
(";");
2373 Set_String
("long long unsigned __gnat_Is8 = 0x");
2374 Set_String
(IS_Is8
);
2375 Write_Statement_Buffer
("LL;");
2377 Set_String
("unsigned char __gnat_Iu1 = 0x");
2378 Set_String
(IS_Is1
);
2379 Write_Statement_Buffer
(";");
2381 Set_String
("unsigned short __gnat_Iu2 = 0x");
2382 Set_String
(IS_Is2
);
2383 Write_Statement_Buffer
(";");
2385 Set_String
("unsigned __gnat_Iu4 = 0x");
2386 Set_String
(IS_Is4
);
2387 Write_Statement_Buffer
(";");
2389 Set_String
("long long unsigned __gnat_Iu8 = 0x");
2390 Set_String
(IS_Is8
);
2391 Write_Statement_Buffer
("LL;");
2393 Set_String
("unsigned __gnat_Isf = 0x");
2394 Set_String
(IS_Isf
);
2395 Write_Statement_Buffer
(";");
2397 Set_String
("unsigned __gnat_Ifl = 0x");
2398 Set_String
(IS_Ifl
);
2399 Write_Statement_Buffer
(";");
2401 Set_String
("long long unsigned __gnat_Ilf = 0x");
2402 Set_String
(IS_Ilf
);
2403 Write_Statement_Buffer
("LL;");
2405 -- For Long_Long_Float, we generate
2406 -- char __gnat_Ill[12] = {0x??, 0x??, 0x??, 0x??, 0x??, 0x??,
2407 -- 0x??, 0x??, 0x??, 0x??, 0x??, 0x??);
2409 Set_String
("unsigned char __gnat_Ill[12] = {");
2411 for J
in 1 .. 6 loop
2413 Set_Char
(IS_Ill
(2 * J
- 1));
2414 Set_Char
(IS_Ill
(2 * J
));
2418 Write_Statement_Buffer
;
2421 for J
in 7 .. 12 loop
2423 Set_Char
(IS_Ill
(2 * J
- 1));
2424 Set_Char
(IS_Ill
(2 * J
));
2433 Write_Statement_Buffer
;
2435 end Gen_Scalar_Values
;
2437 ----------------------
2438 -- Gen_Versions_Ada --
2439 ----------------------
2441 -- This routine generates two sets of lines. The first set has the form:
2443 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2445 -- The second set has the form
2447 -- pragma Export (C, unnnnn, unam);
2449 -- for each unit, where unam is the unit name suffixed by either B or
2450 -- S for body or spec, with dots replaced by double underscores, and
2451 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2453 procedure Gen_Versions_Ada
is
2454 Ubuf
: String (1 .. 6) := "u00000";
2456 procedure Increment_Ubuf
;
2457 -- Little procedure to increment the serial number
2459 procedure Increment_Ubuf
is
2461 for J
in reverse Ubuf
'Range loop
2462 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2463 exit when Ubuf
(J
) <= '9';
2468 -- Start of processing for Gen_Versions_Ada
2471 if Bind_For_Library
then
2473 -- When building libraries, the version number of each unit can
2474 -- not be computed, since the binder does not know the full list
2475 -- of units. Therefore, the 'Version and 'Body_Version
2476 -- attributes can not supported in this case.
2483 WBI
(" type Version_32 is mod 2 ** 32;");
2484 for U
in Units
.First
.. Units
.Last
loop
2486 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2487 Units
.Table
(U
).Version
& "#;");
2493 for U
in Units
.First
.. Units
.Last
loop
2495 Set_String
(" pragma Export (C, ");
2497 Set_String
(", """);
2499 Get_Name_String
(Units
.Table
(U
).Uname
);
2501 for K
in 1 .. Name_Len
loop
2502 if Name_Buffer
(K
) = '.' then
2506 elsif Name_Buffer
(K
) = '%' then
2510 Set_Char
(Name_Buffer
(K
));
2514 if Name_Buffer
(Name_Len
) = 's' then
2520 Set_String
(""");");
2521 Write_Statement_Buffer
;
2524 end Gen_Versions_Ada
;
2526 --------------------
2527 -- Gen_Versions_C --
2528 --------------------
2530 -- This routine generates a line of the form:
2532 -- unsigned unam = 0xhhhhhhhh;
2534 -- for each unit, where unam is the unit name suffixed by either B or
2535 -- S for body or spec, with dots replaced by double underscores.
2537 procedure Gen_Versions_C
is
2539 if Bind_For_Library
then
2541 -- When building libraries, the version number of each unit can
2542 -- not be computed, since the binder does not know the full list
2543 -- of units. Therefore, the 'Version and 'Body_Version
2544 -- attributes can not supported.
2549 for U
in Units
.First
.. Units
.Last
loop
2550 Set_String
("unsigned ");
2552 Get_Name_String
(Units
.Table
(U
).Uname
);
2554 for K
in 1 .. Name_Len
loop
2555 if Name_Buffer
(K
) = '.' then
2558 elsif Name_Buffer
(K
) = '%' then
2562 Set_Char
(Name_Buffer
(K
));
2566 if Name_Buffer
(Name_Len
) = 's' then
2572 Set_String
(" = 0x");
2573 Set_String
(Units
.Table
(U
).Version
);
2575 Write_Statement_Buffer
;
2580 -----------------------
2581 -- Get_Ada_Main_Name --
2582 -----------------------
2584 function Get_Ada_Main_Name
return String is
2585 Suffix
: constant String := "_00";
2586 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
2587 Opt
.Ada_Main_Name
.all & Suffix
;
2591 -- The main program generated by JGNAT expects a package called
2592 -- ada_<main procedure>.
2594 if Hostparm
.Java_VM
then
2595 -- Get main program name
2597 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2601 return "ada_" & Name_Buffer
(1 .. Name_Len
- 2);
2604 -- This loop tries the following possibilities in order
2610 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2611 -- it is set to 'ada_main'.
2613 for J
in 0 .. 99 loop
2615 Nlen
:= Name
'Length - Suffix
'Length;
2617 Nlen
:= Name
'Length;
2618 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
2619 Name
(Name
'Last - 1) :=
2620 Character'Val (J
/ 10 + Character'Pos ('0'));
2623 for K
in ALIs
.First
.. ALIs
.Last
loop
2624 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
2626 -- Get unit name, removing %b or %e at end
2628 Get_Name_String
(Units
.Table
(L
).Uname
);
2629 Name_Len
:= Name_Len
- 2;
2631 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
2637 return Name
(1 .. Nlen
);
2643 -- If we fall through, just use a peculiar unlikely name
2645 return ("Qwertyuiop");
2646 end Get_Ada_Main_Name
;
2652 function Get_Main_Name
return String is
2653 Target
: constant String_Ptr
:= Target_Name
;
2654 VxWorks_Target
: constant Boolean :=
2655 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
2656 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
2659 -- Explicit name given with -M switch
2661 if Bind_Alternate_Main_Name
then
2662 return Alternate_Main_Name
.all;
2664 -- Case of main program name to be used directly
2666 elsif VxWorks_Target
then
2668 -- Get main program name
2670 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2672 -- If this is a child name, return only the name of the child,
2673 -- since we can't have dots in a nested program name. Note that
2674 -- we do not include the %b at the end of the unit name.
2676 for J
in reverse 1 .. Name_Len
- 2 loop
2677 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
2678 return Name_Buffer
(J
.. Name_Len
- 2);
2682 raise Program_Error
; -- impossible exit
2684 -- Case where "main" is to be used as default
2691 ----------------------
2692 -- Lt_Linker_Option --
2693 ----------------------
2695 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean is
2697 -- Sort internal files last
2699 if Linker_Options
.Table
(Op1
).Internal_File
2701 Linker_Options
.Table
(Op2
).Internal_File
2703 -- Note: following test uses False < True
2705 return Linker_Options
.Table
(Op1
).Internal_File
2707 Linker_Options
.Table
(Op2
).Internal_File
;
2709 -- If both internal or both non-internal, sort according to the
2710 -- elaboration position. A unit that is elaborated later should
2711 -- come earlier in the linker options list.
2714 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
2716 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
2719 end Lt_Linker_Option
;
2721 ------------------------
2722 -- Move_Linker_Option --
2723 ------------------------
2725 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
2727 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
2728 end Move_Linker_Option
;
2730 ----------------------------
2731 -- Public_Version_Warning --
2732 ----------------------------
2734 procedure Public_Version_Warning
is
2736 Time
: Int
:= Time_From_Last_Bind
;
2738 -- Constants to help defining periods
2740 Hour
: constant := 60;
2741 Day
: constant := 24 * Hour
;
2743 Never
: constant := Integer'Last;
2744 -- Special value indicating no warnings should be given
2746 -- Constants defining when the warning is issued. Programs with more
2747 -- than Large Units will issue a warning every Period_Large amount of
2748 -- time. Smaller programs will generate a warning every Period_Small
2751 Large
: constant := 20;
2752 -- Threshold for considering a program small or large
2754 Period_Large
: constant := Day
;
2755 -- Periodic warning time for large programs
2757 Period_Small
: constant := Never
;
2758 -- Periodic warning time for small programs
2763 -- Compute the number of units that are not GNAT internal files
2766 for A
in ALIs
.First
.. ALIs
.Last
loop
2767 if not Is_Internal_File_Name
(ALIs
.Table
(A
).Sfile
) then
2768 Nb_Unit
:= Nb_Unit
+ 1;
2772 -- Do not emit the message if the last message was emitted in the
2773 -- specified period taking into account the number of units.
2775 if Nb_Unit
< Large
and then Time
<= Period_Small
then
2778 elsif Time
<= Period_Large
then
2783 Write_Str
("IMPORTANT NOTICE:");
2785 Write_Str
(" This version of GNAT is unsupported"
2786 & " and comes with absolutely no warranty.");
2788 Write_Str
(" If you intend to evaluate or use GNAT for building "
2789 & "commercial applications,");
2791 Write_Str
(" please consult http://www.gnat.com/ for information");
2793 Write_Str
(" on the GNAT Professional product line.");
2796 end Public_Version_Warning
;
2798 ----------------------------
2799 -- Resolve_Binder_Options --
2800 ----------------------------
2802 procedure Resolve_Binder_Options
is
2804 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2805 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
2807 -- The procedure of looking for specific packages and setting
2808 -- flags is very wrong, but there isn't a good alternative at
2811 if Name_Buffer
(1 .. 19) = "system.os_interface" then
2815 if Hostparm
.OpenVMS
and then Name_Buffer
(1 .. 3) = "dec" then
2816 With_DECGNAT
:= True;
2819 end Resolve_Binder_Options
;
2825 procedure Set_Char
(C
: Character) is
2828 Statement_Buffer
(Last
) := C
;
2835 procedure Set_Int
(N
: Int
) is
2847 Statement_Buffer
(Last
) :=
2848 Character'Val (N
mod 10 + Character'Pos ('0'));
2852 ---------------------------
2853 -- Set_Main_Program_Name --
2854 ---------------------------
2856 procedure Set_Main_Program_Name
is
2858 -- Note that name has %b on the end which we ignore
2860 -- First we output the initial _ada_ since we know that the main
2861 -- program is a library level subprogram.
2863 Set_String
("_ada_");
2865 -- Copy name, changing dots to double underscores
2867 for J
in 1 .. Name_Len
- 2 loop
2868 if Name_Buffer
(J
) = '.' then
2871 Set_Char
(Name_Buffer
(J
));
2874 end Set_Main_Program_Name
;
2876 ---------------------
2877 -- Set_Name_Buffer --
2878 ---------------------
2880 procedure Set_Name_Buffer
is
2882 for J
in 1 .. Name_Len
loop
2883 Set_Char
(Name_Buffer
(J
));
2885 end Set_Name_Buffer
;
2891 procedure Set_String
(S
: String) is
2893 Statement_Buffer
(Last
+ 1 .. Last
+ S
'Length) := S
;
2894 Last
:= Last
+ S
'Length;
2901 procedure Set_Unit_Name
is
2903 for J
in 1 .. Name_Len
- 2 loop
2904 if Name_Buffer
(J
) /= '.' then
2905 Set_Char
(Name_Buffer
(J
));
2912 ---------------------
2913 -- Set_Unit_Number --
2914 ---------------------
2916 procedure Set_Unit_Number
(U
: Unit_Id
) is
2917 Num_Units
: constant Nat
:= Nat
(Units
.Table
'Last) - Nat
(Unit_Id
'First);
2918 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
2921 if Num_Units
>= 10 and then Unum
< 10 then
2925 if Num_Units
>= 100 and then Unum
< 100 then
2930 end Set_Unit_Number
;
2936 procedure Tab_To
(N
: Natural) is
2943 ----------------------
2944 -- Write_Info_Ada_C --
2945 ----------------------
2947 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String) is
2949 if Ada_Bind_File
then
2951 S
: String (1 .. Ada
'Length + Common
'Length);
2954 S
(1 .. Ada
'Length) := Ada
;
2955 S
(Ada
'Length + 1 .. S
'Length) := Common
;
2961 S
: String (1 .. C
'Length + Common
'Length);
2964 S
(1 .. C
'Length) := C
;
2965 S
(C
'Length + 1 .. S
'Length) := Common
;
2969 end Write_Info_Ada_C
;
2971 ----------------------------
2972 -- Write_Statement_Buffer --
2973 ----------------------------
2975 procedure Write_Statement_Buffer
is
2977 WBI
(Statement_Buffer
(1 .. Last
));
2979 end Write_Statement_Buffer
;
2981 procedure Write_Statement_Buffer
(S
: String) is
2984 Write_Statement_Buffer
;
2985 end Write_Statement_Buffer
;