1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 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 Types
; use Types
;
41 with Sdefault
; use Sdefault
;
43 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
45 package body Bindgen
is
47 Statement_Buffer
: String (1 .. 1000);
48 -- Buffer used for constructing output statements
51 -- Last location in Statement_Buffer currently set
53 With_DECGNAT
: Boolean := False;
54 -- Flag which indicates whether the program uses the DECGNAT library
55 -- (presence of the unit System.Aux_DEC.DECLIB)
57 With_GNARL
: Boolean := False;
58 -- Flag which indicates whether the program uses the GNARL library
59 -- (presence of the unit System.OS_Interface)
61 Num_Elab_Calls
: Nat
:= 0;
62 -- Number of generated calls to elaboration routines
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
69 -- Convenient shorthand used throughout
71 procedure Resolve_Binder_Options
;
72 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
73 -- since it tests for a package named "dec" which might cause a conflict
74 -- on non-VMS systems.
76 procedure Gen_Adainit_Ada
;
77 -- Generates the Adainit procedure (Ada code case)
79 procedure Gen_Adainit_C
;
80 -- Generates the Adainit procedure (C code case)
82 procedure Gen_Adafinal_Ada
;
83 -- Generate the Adafinal procedure (Ada code case)
85 procedure Gen_Adafinal_C
;
86 -- Generate the Adafinal procedure (C code case)
88 procedure Gen_Elab_Calls_Ada
;
89 -- Generate sequence of elaboration calls (Ada code case)
91 procedure Gen_Elab_Calls_C
;
92 -- Generate sequence of elaboration calls (C code case)
94 procedure Gen_Elab_Order_Ada
;
95 -- Generate comments showing elaboration order chosen (Ada case)
97 procedure Gen_Elab_Order_C
;
98 -- Generate comments showing elaboration order chosen (C case)
100 procedure Gen_Elab_Defs_C
;
101 -- Generate sequence of definitions for elaboration routines (C code case)
103 procedure Gen_Exception_Table_Ada
;
104 -- Generate binder exception table (Ada code case). This consists of
105 -- declarations followed by a begin followed by a call. If zero cost
106 -- exceptions are not active, then only the begin is generated.
108 procedure Gen_Exception_Table_C
;
109 -- Generate binder exception table (C code case). This has no effect
110 -- if zero cost exceptions are not active, otherwise it generates a
111 -- set of declarations followed by a call.
113 procedure Gen_Main_Ada
;
114 -- Generate procedure main (Ada code case)
116 procedure Gen_Main_C
;
117 -- Generate main() procedure (C code case)
119 procedure Gen_Object_Files_Options
;
120 -- Output comments containing a list of the full names of the object
121 -- files to be linked and the list of linker options supplied by
122 -- Linker_Options pragmas in the source. (C and Ada code case)
124 procedure Gen_Output_File_Ada
(Filename
: String);
125 -- Generate output file (Ada code case)
127 procedure Gen_Output_File_C
(Filename
: String);
128 -- Generate output file (C code case)
130 procedure Gen_Scalar_Values
;
131 -- Generates scalar initialization values for -Snn. A single procedure
132 -- handles both the Ada and C cases, since there is much common code.
134 procedure Gen_Versions_Ada
;
135 -- Output series of definitions for unit versions (Ada code case)
137 procedure Gen_Versions_C
;
138 -- Output series of definitions for unit versions (C code case)
140 function Get_Ada_Main_Name
return String;
141 -- This function is used in the Ada main output case to compute a usable
142 -- name for the generated main program. The normal main program name is
143 -- Ada_Main, but this won't work if the user has a unit with this name.
144 -- This function tries Ada_Main first, and if there is such a clash, then
145 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
147 function Get_Main_Name
return String;
148 -- This function is used in the Ada main output case to compute the
149 -- correct external main program. It is "main" by default, except on
150 -- VxWorks where it is the name of the Ada main name without the "_ada".
151 -- the -Mname binder option overrides the default with name.
153 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean;
154 -- Compare linker options, when sorting, first according to
155 -- Is_Internal_File (internal files come later) and then by
156 -- elaboration order position (latest to earliest).
158 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
159 -- Move routine for sorting linker options
161 procedure Set_Char
(C
: Character);
162 -- Set given character in Statement_Buffer at the Last + 1 position
163 -- and increment Last by one to reflect the stored character.
165 procedure Set_Int
(N
: Int
);
166 -- Set given value in decimal in Statement_Buffer with no spaces
167 -- starting at the Last + 1 position, and updating Last past the value.
168 -- A minus sign is output for a negative value.
170 procedure Set_Main_Program_Name
;
171 -- Given the main program name in Name_Buffer (length in Name_Len)
172 -- generate the name of the routine to be used in the call. The name
173 -- is generated starting at Last + 1, and Last is updated past it.
175 procedure Set_Name_Buffer
;
176 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer.
178 procedure Set_String
(S
: String);
179 -- Sets characters of given string in Statement_Buffer, starting at the
180 -- Last + 1 position, and updating last past the string value.
182 procedure Set_Unit_Name
;
183 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
184 -- starting at the Last + 1 position, and updating last past the value.
185 -- changing periods to double underscores, and updating Last appropriately.
187 procedure Set_Unit_Number
(U
: Unit_Id
);
188 -- Sets unit number (first unit is 1, leading zeroes output to line
189 -- up all output unit numbers nicely as required by the value, and
190 -- by the total number of units.
192 procedure Tab_To
(N
: Natural);
193 -- If Last is greater than or equal to N, no effect, otherwise store
194 -- blanks in Statement_Buffer bumping Last, until Last = N.
196 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String);
197 -- For C code case, write C & Common, for Ada case write Ada & Common
198 -- to current binder output file using Write_Binder_Info.
200 procedure Write_Statement_Buffer
;
201 -- Write out contents of statement buffer up to Last, and reset Last to 0
203 procedure Write_Statement_Buffer
(S
: String);
204 -- First writes its argument (using Set_String (S)), then writes out the
205 -- contents of statement buffer up to Last, and reset Last to 0
207 ----------------------
208 -- Gen_Adafinal_Ada --
209 ----------------------
211 procedure Gen_Adafinal_Ada
is
214 WBI
(" procedure " & Ada_Final_Name
.all & " is");
217 -- If compiling for the JVM, we directly call Adafinal because
218 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
220 if Hostparm
.Java_VM
then
221 WBI
(" System.Standard_Library.Adafinal;");
223 WBI
(" Do_Finalize;");
226 WBI
(" end " & Ada_Final_Name
.all & ";");
227 end Gen_Adafinal_Ada
;
233 procedure Gen_Adafinal_C
is
235 WBI
("void " & Ada_Final_Name
.all & " (void)");
237 WBI
(" system__standard_library__adafinal ();");
242 ---------------------
243 -- Gen_Adainit_Ada --
244 ---------------------
246 procedure Gen_Adainit_Ada
is
247 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
250 WBI
(" procedure " & Ada_Init_Name
.all & " is");
252 -- Generate externals for elaboration entities
254 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
256 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
257 U
: Unit_Record
renames Units
.Table
(Unum
);
260 if U
.Set_Elab_Entity
then
263 Set_Unit_Number
(Unum
);
264 Set_String
(" : Boolean; pragma Import (Ada, ");
266 Set_Unit_Number
(Unum
);
268 Get_Name_String
(U
.Uname
);
270 -- In the case of JGNAT we need to emit an Import name
271 -- that includes the class name (using '$' separators
272 -- in the case of a child unit name).
274 if Hostparm
.Java_VM
then
275 for J
in 1 .. Name_Len
- 2 loop
276 if Name_Buffer
(J
) /= '.' then
277 Set_Char
(Name_Buffer
(J
));
285 -- If the unit name is very long, then split the
286 -- Import link name across lines using "&" (occurs
287 -- in some C2 tests).
289 if 2 * Name_Len
+ 60 > Hostparm
.Max_Line_Length
then
291 Write_Statement_Buffer
;
297 Set_String
("_E"");");
298 Write_Statement_Buffer
;
303 Write_Statement_Buffer
;
305 -- Case of No_Run_Time mode. The only global variable that might
306 -- be needed (by the Ravenscar profile) is the priority of the
307 -- environment. Also no exception tables are needed.
309 if No_Run_Time_Specified
then
310 if Main_Priority
/= No_Main_Priority
then
311 WBI
(" Main_Priority : Integer;");
312 WBI
(" pragma Import (C, Main_Priority," &
313 " ""__gl_main_priority"");");
319 if Main_Priority
/= No_Main_Priority
then
320 Set_String
(" Main_Priority := ");
321 Set_Int
(Main_Priority
);
323 Write_Statement_Buffer
;
329 -- Normal case (not No_Run_Time mode). The global values are
330 -- assigned using the runtime routine Set_Globals (we have to use
331 -- the routine call, rather than define the globals in the binder
332 -- file to deal with cross-library calls in some systems.
335 -- Generate restrictions string
337 Set_String
(" Restrictions : constant String :=");
338 Write_Statement_Buffer
;
341 for J
in Restrictions
'Range loop
342 Set_Char
(Restrictions
(J
));
346 Write_Statement_Buffer
;
349 WBI
(" procedure Set_Globals");
350 WBI
(" (Main_Priority : Integer;");
351 WBI
(" Time_Slice_Value : Integer;");
352 WBI
(" WC_Encoding : Character;");
353 WBI
(" Locking_Policy : Character;");
354 WBI
(" Queuing_Policy : Character;");
355 WBI
(" Task_Dispatching_Policy : Character;");
356 WBI
(" Restrictions : System.Address;");
357 WBI
(" Unreserve_All_Interrupts : Integer;");
358 WBI
(" Exception_Tracebacks : Integer;");
359 WBI
(" Zero_Cost_Exceptions : Integer);");
360 WBI
(" pragma Import (C, Set_Globals, ""__gnat_set_globals"");");
362 -- Import entry point for elaboration time signal handler
363 -- installation, and indication of whether it's been called
367 WBI
(" procedure Install_Handler;");
368 WBI
(" pragma Import (C, Install_Handler, " &
369 """__gnat_install_handler"");");
371 WBI
(" Handler_Installed : Integer;");
372 WBI
(" pragma Import (C, Handler_Installed, " &
373 """__gnat_handler_installed"");");
375 -- Generate exception table
377 Gen_Exception_Table_Ada
;
379 -- Generate the call to Set_Globals
381 WBI
(" Set_Globals");
383 Set_String
(" (Main_Priority => ");
384 Set_Int
(Main_Priority
);
386 Write_Statement_Buffer
;
388 Set_String
(" Time_Slice_Value => ");
390 if Task_Dispatching_Policy_Specified
= 'F'
391 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
395 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
399 Write_Statement_Buffer
;
401 Set_String
(" WC_Encoding => '");
402 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
404 Write_Statement_Buffer
;
406 Set_String
(" Locking_Policy => '");
407 Set_Char
(Locking_Policy_Specified
);
409 Write_Statement_Buffer
;
411 Set_String
(" Queuing_Policy => '");
412 Set_Char
(Queuing_Policy_Specified
);
414 Write_Statement_Buffer
;
416 Set_String
(" Task_Dispatching_Policy => '");
417 Set_Char
(Task_Dispatching_Policy_Specified
);
419 Write_Statement_Buffer
;
421 WBI
(" Restrictions => Restrictions'Address,");
423 Set_String
(" Unreserve_All_Interrupts => ");
425 if Unreserve_All_Interrupts_Specified
then
432 Write_Statement_Buffer
;
434 Set_String
(" Exception_Tracebacks => ");
436 if Exception_Tracebacks
then
443 Write_Statement_Buffer
;
445 Set_String
(" Zero_Cost_Exceptions => ");
447 if Zero_Cost_Exceptions_Specified
then
454 Write_Statement_Buffer
;
456 -- Generate call to Install_Handler
458 WBI
(" if Handler_Installed = 0 then");
459 WBI
(" Install_Handler;");
465 WBI
(" end " & Ada_Init_Name
.all & ";");
472 procedure Gen_Adainit_C
is
473 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
476 WBI
("void " & Ada_Init_Name
.all & " (void)");
479 -- Generate externals for elaboration entities
481 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
483 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
484 U
: Unit_Record
renames Units
.Table
(Unum
);
487 if U
.Set_Elab_Entity
then
488 Set_String
(" extern char ");
489 Get_Name_String
(U
.Uname
);
492 Write_Statement_Buffer
;
497 Write_Statement_Buffer
;
501 if No_Run_Time_Specified
then
503 -- Case of No_Run_Time mode. Set __gl_main_priority if needed
504 -- for the Ravenscar profile.
506 if Main_Priority
/= No_Main_Priority
then
507 Set_String
(" extern int __gl_main_priority = ");
508 Set_Int
(Main_Priority
);
510 Write_Statement_Buffer
;
513 -- Normal case (run time present)
516 -- Generate definition for restrictions string
518 Set_String
(" const char *restrictions = """);
520 for J
in Restrictions
'Range loop
521 Set_Char
(Restrictions
(J
));
525 Write_Statement_Buffer
;
527 -- Code for normal case (not in No_Run_Time mode)
529 Gen_Exception_Table_C
;
531 -- Generate call to set the runtime global variables defined in
532 -- a-init.c. We define the varables in a-init.c, rather than in
533 -- the binder generated file itself to avoid undefined externals
534 -- when the runtime is linked as a shareable image library.
536 -- We call the routine from inside adainit() because this works for
537 -- both programs with and without binder generated "main" functions.
539 WBI
(" __gnat_set_globals (");
542 Set_Int
(Main_Priority
);
545 Set_String
("/* Main_Priority */");
546 Write_Statement_Buffer
;
550 if Task_Dispatching_Policy
= 'F'
551 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
555 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
560 Set_String
("/* Time_Slice_Value */");
561 Write_Statement_Buffer
;
564 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
567 Set_String
("/* WC_Encoding */");
568 Write_Statement_Buffer
;
571 Set_Char
(Locking_Policy_Specified
);
574 Set_String
("/* Locking_Policy */");
575 Write_Statement_Buffer
;
578 Set_Char
(Queuing_Policy_Specified
);
581 Set_String
("/* Queuing_Policy */");
582 Write_Statement_Buffer
;
585 Set_Char
(Task_Dispatching_Policy_Specified
);
588 Set_String
("/* Tasking_Dispatching_Policy */");
589 Write_Statement_Buffer
;
592 Set_String
("restrictions");
595 Set_String
("/* Restrictions */");
596 Write_Statement_Buffer
;
599 Set_Int
(Boolean'Pos (Unreserve_All_Interrupts_Specified
));
602 Set_String
("/* Unreserve_All_Interrupts */");
603 Write_Statement_Buffer
;
606 Set_Int
(Boolean'Pos (Exception_Tracebacks
));
609 Set_String
("/* Exception_Tracebacks */");
610 Write_Statement_Buffer
;
613 Set_Int
(Boolean'Pos (Zero_Cost_Exceptions_Specified
));
616 Set_String
("/* Zero_Cost_Exceptions */");
617 Write_Statement_Buffer
;
619 -- Install elaboration time signal handler
621 WBI
(" if (__gnat_handler_installed == 0)");
623 WBI
(" __gnat_install_handler ();");
632 ------------------------
633 -- Gen_Elab_Calls_Ada --
634 ------------------------
636 procedure Gen_Elab_Calls_Ada
is
639 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
641 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
642 U
: Unit_Record
renames Units
.Table
(Unum
);
645 -- This is the unit number of the spec that corresponds to
646 -- this entry. It is the same as Unum except when the body
647 -- and spec are different and we are currently processing
648 -- the body, in which case it is the spec (Unum + 1).
651 if U
.Utype
= Is_Body
then
652 Unum_Spec
:= Unum
+ 1;
657 -- Case of no elaboration code
661 -- The only case in which we have to do something is if
662 -- this is a body, with a separate spec, where the separate
663 -- spec has an elaboration entity defined.
665 -- In that case, this is where we set the elaboration entity
666 -- to True, we do not need to test if this has already been
667 -- done, since it is quicker to set the flag than to test it.
670 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
673 Set_Unit_Number
(Unum_Spec
);
674 Set_String
(" := True;");
675 Write_Statement_Buffer
;
678 -- Here if elaboration code is present. We generate:
680 -- if not uname_E then
681 -- uname'elab_[spec|body];
685 -- The uname_E assignment is skipped if this is a separate spec,
686 -- since the assignment will be done when we process the body.
689 Set_String
(" if not E");
690 Set_Unit_Number
(Unum_Spec
);
691 Set_String
(" then");
692 Write_Statement_Buffer
;
695 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
697 if Name_Buffer
(Name_Len
) = 's' then
698 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_spec";
700 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_body";
703 Name_Len
:= Name_Len
+ 8;
704 Set_Casing
(U
.Icasing
);
707 Write_Statement_Buffer
;
709 if U
.Utype
/= Is_Spec
then
711 Set_Unit_Number
(Unum_Spec
);
712 Set_String
(" := True;");
713 Write_Statement_Buffer
;
721 end Gen_Elab_Calls_Ada
;
723 ----------------------
724 -- Gen_Elab_Calls_C --
725 ----------------------
727 procedure Gen_Elab_Calls_C
is
730 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
732 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
733 U
: Unit_Record
renames Units
.Table
(Unum
);
736 -- This is the unit number of the spec that corresponds to
737 -- this entry. It is the same as Unum except when the body
738 -- and spec are different and we are currently processing
739 -- the body, in which case it is the spec (Unum + 1).
742 if U
.Utype
= Is_Body
then
743 Unum_Spec
:= Unum
+ 1;
748 -- Case of no elaboration code
752 -- The only case in which we have to do something is if
753 -- this is a body, with a separate spec, where the separate
754 -- spec has an elaboration entity defined.
756 -- In that case, this is where we set the elaboration entity
757 -- to True, we do not need to test if this has already been
758 -- done, since it is quicker to set the flag than to test it.
761 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
764 Get_Name_String
(U
.Uname
);
766 Set_String
("_E = 1;");
767 Write_Statement_Buffer
;
770 -- Here if elaboration code is present. We generate:
772 -- if (uname_E == 0) {
773 -- uname__elab[s|b] ();
777 -- The uname_E assignment is skipped if this is a separate spec,
778 -- since the assignment will be done when we process the body.
781 Set_String
(" if (");
782 Get_Name_String
(U
.Uname
);
784 Set_String
("_E == 0) {");
785 Write_Statement_Buffer
;
789 Set_String
("___elab");
790 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
792 Write_Statement_Buffer
;
794 if U
.Utype
/= Is_Spec
then
797 Set_String
("_E++;");
798 Write_Statement_Buffer
;
806 end Gen_Elab_Calls_C
;
808 ----------------------
809 -- Gen_Elab_Defs_C --
810 ----------------------
812 procedure Gen_Elab_Defs_C
is
814 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
816 -- Generate declaration of elaboration procedure if elaboration
817 -- needed. Note that passive units are always excluded.
819 if not Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
820 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
821 Set_String
("extern void ");
823 Set_String
("___elab");
824 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
825 Set_String
(" (void);");
826 Write_Statement_Buffer
;
834 ------------------------
835 -- Gen_Elab_Order_Ada --
836 ------------------------
838 procedure Gen_Elab_Order_Ada
is
841 WBI
(" -- BEGIN ELABORATION ORDER");
843 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
845 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
847 Write_Statement_Buffer
;
850 WBI
(" -- END ELABORATION ORDER");
851 end Gen_Elab_Order_Ada
;
853 ----------------------
854 -- Gen_Elab_Order_C --
855 ----------------------
857 procedure Gen_Elab_Order_C
is
860 WBI
("/* BEGIN ELABORATION ORDER");
862 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
863 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
865 Write_Statement_Buffer
;
868 WBI
(" END ELABORATION ORDER */");
869 end Gen_Elab_Order_C
;
871 -----------------------------
872 -- Gen_Exception_Table_Ada --
873 -----------------------------
875 procedure Gen_Exception_Table_Ada
is
877 Last
: ALI_Id
:= No_ALI_Id
;
880 if not Zero_Cost_Exceptions_Specified
then
885 -- The code we generate looks like
887 -- procedure SDP_Table_Build
888 -- (SDP_Addresses : System.Address;
889 -- SDP_Count : Natural;
890 -- Elab_Addresses : System.Address;
891 -- Elab_Addr_Count : Natural);
892 -- pragma Import (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
894 -- ST : aliased constant array (1 .. nnn) of System.Address := (
895 -- unit_name_1'UET_Address,
896 -- unit_name_2'UET_Address,
898 -- unit_name_3'UET_Address,
900 -- EA : aliased constant array (1 .. eee) of System.Address := (
901 -- adainit'Code_Address,
902 -- adafinal'Code_Address,
903 -- unit_name'elab[spec|body]'Code_Address,
904 -- unit_name'elab[spec|body]'Code_Address,
905 -- unit_name'elab[spec|body]'Code_Address,
906 -- unit_name'elab[spec|body]'Code_Address);
909 -- SDP_Table_Build (ST'Address, nnn, EA'Address, eee);
912 for A
in ALIs
.First
.. ALIs
.Last
loop
913 if ALIs
.Table
(A
).Unit_Exception_Table
then
921 -- Happens with "gnatmake -a -f -gnatL ..."
928 WBI
(" procedure SDP_Table_Build");
929 WBI
(" (SDP_Addresses : System.Address;");
930 WBI
(" SDP_Count : Natural;");
931 WBI
(" Elab_Addresses : System.Address;");
932 WBI
(" Elab_Addr_Count : Natural);");
934 "pragma Import (C, SDP_Table_Build, ""__gnat_SDP_Table_Build"");");
937 Set_String
(" ST : aliased constant array (1 .. ");
939 Set_String
(") of System.Address := (");
942 Set_String
("1 => A1);");
943 Write_Statement_Buffer
;
946 Write_Statement_Buffer
;
948 for A
in ALIs
.First
.. ALIs
.Last
loop
949 if ALIs
.Table
(A
).Unit_Exception_Table
then
950 Get_Decoded_Name_String_With_Brackets
951 (Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
952 Set_Casing
(Mixed_Case
);
954 Set_String
(Name_Buffer
(1 .. Name_Len
- 2));
955 Set_String
("'UET_Address");
963 Write_Statement_Buffer
;
969 Set_String
(" EA : aliased constant array (1 .. ");
970 Set_Int
(Num_Elab_Calls
+ 2);
971 Set_String
(") of System.Address := (");
972 Write_Statement_Buffer
;
973 WBI
(" " & Ada_Init_Name
.all & "'Code_Address,");
975 -- If compiling for the JVM, we directly reference Adafinal because
976 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
978 if Hostparm
.Java_VM
then
979 Set_String
(" System.Standard_Library.Adafinal'Code_Address");
981 Set_String
(" Do_Finalize'Code_Address");
984 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
985 Get_Decoded_Name_String_With_Brackets
986 (Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
988 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
993 Write_Statement_Buffer
;
996 if Name_Buffer
(Name_Len
) = 's' then
997 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
998 "'elab_spec'code_address";
1000 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
1001 "'elab_body'code_address";
1004 Name_Len
:= Name_Len
+ 21;
1005 Set_Casing
(Units
.Table
(Elab_Order
.Table
(E
)).Icasing
);
1011 Write_Statement_Buffer
;
1016 Set_String
(" SDP_Table_Build (ST'Address, ");
1018 Set_String
(", EA'Address, ");
1019 Set_Int
(Num_Elab_Calls
+ 2);
1021 Write_Statement_Buffer
;
1022 end Gen_Exception_Table_Ada
;
1024 ---------------------------
1025 -- Gen_Exception_Table_C --
1026 ---------------------------
1028 procedure Gen_Exception_Table_C
is
1033 if not Zero_Cost_Exceptions_Specified
then
1037 -- The code we generate looks like
1039 -- extern void *__gnat_unitname1__SDP;
1040 -- extern void *__gnat_unitname2__SDP;
1043 -- void **st[nnn] = {
1044 -- &__gnat_unitname1__SDP,
1045 -- &__gnat_unitname2__SDP,
1047 -- &__gnat_unitnamen__SDP};
1049 -- extern void unitname1__elabb ();
1050 -- extern void unitname2__elabb ();
1053 -- void (*ea[eee]) () = {
1056 -- unitname1___elab[b,s],
1057 -- unitname2___elab[b,s],
1059 -- unitnamen___elab[b,s]};
1061 -- __gnat_SDP_Table_Build (&st, nnn, &ea, eee);
1064 for A
in ALIs
.First
.. ALIs
.Last
loop
1065 if ALIs
.Table
(A
).Unit_Exception_Table
then
1068 Set_String
(" extern void *__gnat_");
1069 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1071 Set_String
("__SDP");
1073 Write_Statement_Buffer
;
1079 -- Happens with "gnatmake -a -f -gnatL ..."
1086 Set_String
(" void **st[");
1088 Set_String
("] = {");
1089 Write_Statement_Buffer
;
1092 for A
in ALIs
.First
.. ALIs
.Last
loop
1093 if ALIs
.Table
(A
).Unit_Exception_Table
then
1096 Set_String
(" &__gnat_");
1097 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1099 Set_String
("__SDP");
1107 Write_Statement_Buffer
;
1112 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1113 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1115 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1119 Set_String
(" extern void ");
1121 Set_String
("___elab");
1122 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1123 Set_String
(" ();");
1124 Write_Statement_Buffer
;
1129 Set_String
(" void (*ea[");
1130 Set_Int
(Num_Elab_Calls
+ 2);
1131 Set_String
("]) () = {");
1132 Write_Statement_Buffer
;
1134 WBI
(" " & Ada_Init_Name
.all & ",");
1135 Set_String
(" system__standard_library__adafinal");
1137 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1138 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1140 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1145 Write_Statement_Buffer
;
1148 Set_String
("___elab");
1149 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1154 Write_Statement_Buffer
;
1158 Set_String
(" __gnat_SDP_Table_Build (&st, ");
1160 Set_String
(", ea, ");
1161 Set_Int
(Num_Elab_Calls
+ 2);
1163 Write_Statement_Buffer
;
1164 end Gen_Exception_Table_C
;
1170 procedure Gen_Main_Ada
is
1171 Target
: constant String_Ptr
:= Target_Name
;
1172 VxWorks_Target
: constant Boolean :=
1173 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1174 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1178 Set_String
(" function ");
1179 Set_String
(Get_Main_Name
);
1181 if VxWorks_Target
then
1182 Set_String
(" return Integer is");
1183 Write_Statement_Buffer
;
1186 Write_Statement_Buffer
;
1187 WBI
(" (argc : Integer;");
1188 WBI
(" argv : System.Address;");
1189 WBI
(" envp : System.Address)");
1190 WBI
(" return Integer");
1194 -- Initialize and Finalize are not used in No_Run_Time mode
1196 if not No_Run_Time_Specified
then
1197 WBI
(" procedure initialize;");
1198 WBI
(" pragma Import (C, initialize, ""__gnat_initialize"");");
1200 WBI
(" procedure finalize;");
1201 WBI
(" pragma Import (C, finalize, ""__gnat_finalize"");");
1205 -- Deal with declarations for main program case
1207 if not No_Main_Subprogram
then
1209 -- To call the main program, we declare it using a pragma Import
1210 -- Ada with the right link name.
1212 -- It might seem more obvious to "with" the main program, and call
1213 -- it in the normal Ada manner. We do not do this for three reasons:
1215 -- 1. It is more efficient not to recompile the main program
1216 -- 2. We are not entitled to assume the source is accessible
1217 -- 3. We don't know what options to use to compile it
1219 -- It is really reason 3 that is most critical (indeed we used
1220 -- to generate the "with", but several regression tests failed).
1224 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1225 WBI
(" Result : Integer;");
1227 WBI
(" function Ada_Main_Program return Integer;");
1230 WBI
(" procedure Ada_Main_Program;");
1233 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1234 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1235 Set_Main_Program_Name
;
1236 Set_String
(""");");
1238 Write_Statement_Buffer
;
1242 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1243 -- not referenced elsewhere in the generated program, but is needed
1244 -- by the debugger (that's why it is generated in the first place).
1245 -- The reference stops Ada_Main_Program_Name from being optimized
1246 -- away by smart linkers, such as the AiX linker.
1249 (" Ensure_Reference : System.Address := " &
1250 "Ada_Main_Program_Name'Address;");
1255 -- On VxWorks, there are no command line arguments
1257 if VxWorks_Target
then
1258 WBI
(" gnat_argc := 0;");
1259 WBI
(" gnat_argv := System.Null_Address;");
1260 WBI
(" gnat_envp := System.Null_Address;");
1262 -- Normal case of command line arguments present
1265 WBI
(" gnat_argc := argc;");
1266 WBI
(" gnat_argv := argv;");
1267 WBI
(" gnat_envp := envp;");
1271 if not No_Run_Time_Specified
then
1272 WBI
(" Initialize;");
1275 WBI
(" " & Ada_Init_Name
.all & ";");
1277 if not No_Main_Subprogram
then
1278 WBI
(" Break_Start;");
1280 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1281 WBI
(" Ada_Main_Program;");
1283 WBI
(" Result := Ada_Main_Program;");
1287 -- Adafinal is only called if we have a run time
1289 if not No_Run_Time_Specified
then
1291 -- If compiling for the JVM, we directly call Adafinal because
1292 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1294 if Hostparm
.Java_VM
then
1295 WBI
(" System.Standard_Library.Adafinal;");
1297 WBI
(" Do_Finalize;");
1301 -- Finalize is only called if we have a run time
1303 if not No_Run_Time_Specified
then
1309 if No_Main_Subprogram
1310 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1312 WBI
(" return (gnat_exit_status);");
1314 WBI
(" return (Result);");
1324 procedure Gen_Main_C
is
1325 Target
: constant String_Ptr
:= Target_Name
;
1326 VxWorks_Target
: constant Boolean :=
1327 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1328 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1331 Set_String
("int ");
1332 Set_String
(Get_Main_Name
);
1334 -- On VxWorks, there are no command line arguments
1336 if VxWorks_Target
then
1339 -- Normal case with command line arguments present
1342 Set_String
(" (int argc, char **argv, char **envp)");
1345 Write_Statement_Buffer
;
1347 -- VxWorks doesn't have the notion of argc/argv
1349 if VxWorks_Target
then
1351 WBI
(" int result;");
1352 WBI
(" gnat_argc = 0;");
1353 WBI
(" gnat_argv = 0;");
1354 WBI
(" gnat_envp = 0;");
1356 -- Normal case of arguments present
1361 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1362 -- is not referenced elsewhere in the generated program, but is
1363 -- needed by the debugger (that's why it is generated in the first
1364 -- place). The reference stops Ada_Main_Program_Name from being
1365 -- optimized away by smart linkers, such as the AiX linker.
1368 (" char *ensure_reference __attribute__ ((__unused__)) = " &
1369 "__gnat_ada_main_program_name;");
1372 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1373 WBI
(" int result;");
1376 WBI
(" gnat_argc = argc;");
1377 WBI
(" gnat_argv = argv;");
1378 WBI
(" gnat_envp = envp;");
1382 -- The __gnat_initialize routine is used only if we have a run-time
1384 if not No_Run_Time_Specified
then
1386 (" __gnat_initialize ();");
1389 WBI
(" " & Ada_Init_Name
.all & " ();");
1391 if not No_Main_Subprogram
then
1393 WBI
(" __gnat_break_start ();");
1396 -- Output main program name
1398 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1400 -- Main program is procedure case
1402 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1404 Set_Main_Program_Name
;
1405 Set_String
(" ();");
1406 Write_Statement_Buffer
;
1408 -- Main program is function case
1410 else -- ALIs.Table (ALIs_First).Main_Program = Func
1411 Set_String
(" result = ");
1412 Set_Main_Program_Name
;
1413 Set_String
(" ();");
1414 Write_Statement_Buffer
;
1419 -- Adafinal is called only when we have a run-time
1421 if not No_Run_Time_Specified
then
1423 WBI
(" system__standard_library__adafinal ();");
1426 -- The finalize routine is used only if we have a run-time
1428 if not No_Run_Time_Specified
then
1429 WBI
(" __gnat_finalize ();");
1432 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1434 if Hostparm
.OpenVMS
then
1436 -- VMS must use the Posix exit routine in order to get an
1437 -- Unix compatible exit status.
1439 WBI
(" __posix_exit (result);");
1442 WBI
(" exit (result);");
1447 if Hostparm
.OpenVMS
then
1448 -- VMS must use the Posix exit routine in order to get an
1449 -- Unix compatible exit status.
1450 WBI
(" __posix_exit (gnat_exit_status);");
1452 WBI
(" exit (gnat_exit_status);");
1459 ------------------------------
1460 -- Gen_Object_Files_Options --
1461 ------------------------------
1463 procedure Gen_Object_Files_Options
is
1465 -- This keeps track of the position in the sorted set of entries
1466 -- in the Linker_Options table of where the first entry from an
1467 -- internal file appears.
1469 procedure Write_Linker_Option
;
1470 -- Write binder info linker option.
1472 -------------------------
1473 -- Write_Linker_Option --
1474 -------------------------
1476 procedure Write_Linker_Option
is
1481 -- Loop through string, breaking at null's
1484 while Start
< Name_Len
loop
1486 -- Find null ending this section
1489 while Name_Buffer
(Stop
) /= ASCII
.NUL
1490 and then Stop
<= Name_Len
loop
1494 -- Process section if non-null
1496 if Stop
> Start
then
1497 if Output_Linker_Option_List
then
1498 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1502 (" -- ", "", Name_Buffer
(Start
.. Stop
- 1));
1507 end Write_Linker_Option
;
1509 -- Start of processing for Gen_Object_Files_Options
1513 Write_Info_Ada_C
("--", "/*", " BEGIN Object file/option list");
1515 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1517 -- If not spec that has an associated body, then generate a
1518 -- comment giving the name of the corresponding object file.
1520 if Units
.Table
(Elab_Order
.Table
(E
)).Utype
/= Is_Spec
then
1523 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Ofile_Full_Name
);
1525 -- If the presence of an object file is necessary or if it
1526 -- exists, then use it.
1528 if not Hostparm
.Exclude_Missing_Objects
1530 GNAT
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
1532 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1533 if Output_Object_List
then
1534 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1538 -- Don't link with the shared library on VMS if an internal
1539 -- filename object is seen. Multiply defined symbols will
1543 and then Is_Internal_File_Name
1545 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Sfile
)
1547 Opt
.Shared_Libgnat
:= False;
1554 -- Add a "-Ldir" for each directory in the object path. We skip this
1555 -- in No_Run_Time mode, where we want more precise control of exactly
1556 -- what goes into the resulting object file
1558 if not No_Run_Time_Specified
then
1559 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
1561 Dir
: String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
1565 Add_Str_To_Name_Buffer
("-L");
1566 Add_Str_To_Name_Buffer
(Dir
.all);
1567 Write_Linker_Option
;
1572 -- Sort linker options
1574 -- This sort accomplishes two important purposes:
1576 -- a) All application files are sorted to the front, and all
1577 -- GNAT internal files are sorted to the end. This results
1578 -- in a well defined dividing line between the two sets of
1579 -- files, for the purpose of inserting certain standard
1580 -- library references into the linker arguments list.
1582 -- b) Given two different units, we sort the linker options so
1583 -- that those from a unit earlier in the elaboration order
1584 -- comes later in the list. This is a heuristic designed
1585 -- to create a more friendly order of linker options when
1586 -- the operations appear in separate units. The idea is that
1587 -- if unit A must be elaborated before unit B, then it is
1588 -- more likely that B references libraries included by A,
1589 -- than vice versa, so we want the libraries included by
1590 -- A to come after the libraries included by B.
1592 -- These two criteria are implemented by function Lt_Linker_Option.
1593 -- Note that a special case of b) is that specs are elaborated before
1594 -- bodies, so linker options from specs come after linker options
1595 -- for bodies, and again, the assumption is that libraries used by
1596 -- the body are more likely to reference libraries used by the spec,
1600 (Linker_Options
.Last
,
1601 Move_Linker_Option
'Access,
1602 Lt_Linker_Option
'Access);
1604 -- Write user linker options, i.e. the set of linker options that
1605 -- come from all files other than GNAT internal files, Lgnat is
1606 -- left set to point to the first entry from a GNAT internal file,
1607 -- or past the end of the entriers if there are no internal files.
1609 Lgnat
:= Linker_Options
.Last
+ 1;
1611 for J
in 1 .. Linker_Options
.Last
loop
1612 if not Linker_Options
.Table
(J
).Internal_File
then
1613 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1614 Write_Linker_Option
;
1621 -- Now we insert standard linker options that must appear after the
1622 -- entries from user files, and before the entries from GNAT run-time
1623 -- files. The reason for this decision is that libraries referenced
1624 -- by internal routines may reference these standard library entries.
1626 if not (No_Run_Time_Specified
or else Opt
.No_Stdlib
) then
1629 if Opt
.Shared_Libgnat
then
1630 Add_Str_To_Name_Buffer
("-shared");
1632 Add_Str_To_Name_Buffer
("-static");
1635 -- Write directly to avoid -K output (why???)
1637 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1639 if With_DECGNAT
then
1641 Add_Str_To_Name_Buffer
("-ldecgnat");
1642 Write_Linker_Option
;
1647 Add_Str_To_Name_Buffer
("-lgnarl");
1648 Write_Linker_Option
;
1652 Add_Str_To_Name_Buffer
("-lgnat");
1653 Write_Linker_Option
;
1656 -- Write linker options from all internal files
1658 for J
in Lgnat
.. Linker_Options
.Last
loop
1659 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1660 Write_Linker_Option
;
1663 if Ada_Bind_File
then
1664 WBI
("-- END Object file/option list ");
1666 WBI
(" END Object file/option list */");
1669 end Gen_Object_Files_Options
;
1671 ---------------------
1672 -- Gen_Output_File --
1673 ---------------------
1675 procedure Gen_Output_File
(Filename
: String) is
1678 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1679 -- JGNAT only supports Ada code, and the main program is already
1680 -- generated by the compiler.
1682 if Hostparm
.Java_VM
then
1683 Ada_Bind_File
:= True;
1684 Bind_Main_Program
:= False;
1687 -- Override time slice value if -T switch is set
1689 if Time_Slice_Set
then
1690 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
1693 -- Count number of elaboration calls
1695 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1696 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1699 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
1703 -- Generate output file in appropriate language
1705 if Ada_Bind_File
then
1706 Gen_Output_File_Ada
(Filename
);
1708 Gen_Output_File_C
(Filename
);
1711 end Gen_Output_File
;
1713 -------------------------
1714 -- Gen_Output_File_Ada --
1715 -------------------------
1717 procedure Gen_Output_File_Ada
(Filename
: String) is
1720 -- Name of generated bind file (spec)
1723 -- Name of generated bind file (body)
1725 Ada_Main
: constant String := Get_Ada_Main_Name
;
1726 -- Name to be used for generated Ada main program. See the body of
1727 -- function Get_Ada_Main_Name for details on the form of the name.
1729 Target
: constant String_Ptr
:= Target_Name
;
1730 VxWorks_Target
: constant Boolean :=
1731 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
1732 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
1735 -- Create spec first
1737 Create_Binder_Output
(Filename
, 's', Bfiles
);
1739 if No_Run_Time_Specified
then
1740 WBI
("pragma No_Run_Time;");
1743 -- Generate with of System so we can reference System.Address, note
1744 -- that such a reference is safe even in No_Run_Time mode, since we
1745 -- do not need any run-time code for such a reference, and we output
1746 -- a pragma No_Run_Time for this compilation above.
1748 WBI
("with System;");
1750 -- Generate with of System.Initialize_Scalars if active
1752 if Initialize_Scalars_Used
then
1753 WBI
("with System.Scalar_Values;");
1756 Resolve_Binder_Options
;
1758 if not No_Run_Time_Specified
then
1760 -- Usually, adafinal is called using a pragma Import C. Since
1761 -- Import C doesn't have the same semantics for JGNAT, we use
1764 if Hostparm
.Java_VM
then
1765 WBI
("with System.Standard_Library;");
1769 WBI
("package " & Ada_Main
& " is");
1771 -- Main program case
1773 if Bind_Main_Program
then
1775 -- Generate argc/argv stuff
1778 WBI
(" gnat_argc : Integer;");
1779 WBI
(" gnat_argv : System.Address;");
1780 WBI
(" gnat_envp : System.Address;");
1782 -- If we have a run time present, these variables are in the
1783 -- runtime data area for easy access from the runtime
1785 if not No_Run_Time_Specified
then
1787 WBI
(" pragma Import (C, gnat_argc);");
1788 WBI
(" pragma Import (C, gnat_argv);");
1789 WBI
(" pragma Import (C, gnat_envp);");
1792 -- Define exit status. Again in normal mode, this is in the
1793 -- run-time library, and is initialized there, but in the no
1794 -- run time case, the variable is here and initialized here.
1798 if No_Run_Time_Specified
then
1799 WBI
(" gnat_exit_status : Integer := 0;");
1801 WBI
(" gnat_exit_status : Integer;");
1802 WBI
(" pragma Import (C, gnat_exit_status);");
1806 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
1807 -- the main program. Otherwise, it can lead under some circumstances
1808 -- to a symbol duplication during the link (for instance when a
1809 -- C program uses 2 Ada libraries)
1811 if Bind_Main_Program
then
1813 WBI
(" GNAT_Version : constant String :=");
1814 WBI
(" ""GNAT Version: " &
1815 Gnat_Version_String
& """;");
1816 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
1819 Set_String
(" Ada_Main_Program_Name : constant String := """);
1820 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1821 Set_Main_Program_Name
;
1822 Set_String
(""" & Ascii.NUL;");
1823 Write_Statement_Buffer
;
1826 (" pragma Export (C, Ada_Main_Program_Name, " &
1827 """__gnat_ada_main_program_name"");");
1830 -- No need to generate a finalization routine if there is no
1831 -- runtime, since there is nothing to do in this case.
1833 if not No_Run_Time_Specified
then
1835 WBI
(" procedure " & Ada_Final_Name
.all & ";");
1836 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
1837 Ada_Final_Name
.all & """);");
1841 WBI
(" procedure " & Ada_Init_Name
.all & ";");
1842 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
1843 Ada_Init_Name
.all & """);");
1845 if Bind_Main_Program
then
1847 -- If we have a run time, then Break_Start is defined there, but
1848 -- if there is no run-time, Break_Start is defined in this file.
1851 WBI
(" procedure Break_Start;");
1853 if No_Run_Time_Specified
then
1854 WBI
(" pragma Export (C, Break_Start, ""__gnat_break_start"");");
1856 WBI
(" pragma Import (C, Break_Start, ""__gnat_break_start"");");
1860 WBI
(" function " & Get_Main_Name
);
1862 -- Generate argument list (except on VxWorks, where none is present)
1864 if not VxWorks_Target
then
1865 WBI
(" (argc : Integer;");
1866 WBI
(" argv : System.Address;");
1867 WBI
(" envp : System.Address)");
1870 WBI
(" return Integer;");
1871 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
1872 Get_Main_Name
& """);");
1875 if Initialize_Scalars_Used
then
1885 WBI
("end " & Ada_Main
& ";");
1886 Close_Binder_Output
;
1888 -- Prepare to write body
1890 Create_Binder_Output
(Filename
, 'b', Bfileb
);
1892 -- Output Source_File_Name pragmas which look like
1894 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
1895 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
1897 -- where sss/bbb are the spec/body file names respectively
1899 Get_Name_String
(Bfiles
);
1900 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1902 WBI
("pragma Source_File_Name (" &
1904 ", Spec_File_Name => """ &
1905 Name_Buffer
(1 .. Name_Len
+ 3));
1907 Get_Name_String
(Bfileb
);
1908 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1910 WBI
("pragma Source_File_Name (" &
1912 ", Body_File_Name => """ &
1913 Name_Buffer
(1 .. Name_Len
+ 3));
1916 WBI
("package body " & Ada_Main
& " is");
1918 -- Import the finalization procedure only if there is a runtime.
1920 if not No_Run_Time_Specified
then
1922 -- In the Java case, pragma Import C cannot be used, so the
1923 -- standard Ada constructs will be used instead.
1925 if not Hostparm
.Java_VM
then
1927 WBI
(" procedure Do_Finalize;");
1929 (" pragma Import (C, Do_Finalize, " &
1930 """system__standard_library__adafinal"");");
1937 -- No need to generate a finalization routine if there is no
1938 -- runtime, since there is nothing to do in this case.
1940 if not No_Run_Time_Specified
then
1944 if Bind_Main_Program
then
1946 -- In No_Run_Time mode, generate dummy body for Break_Start
1948 if No_Run_Time_Specified
then
1950 WBI
(" procedure Break_Start is");
1959 -- Output object file list and the Ada body is complete
1961 Gen_Object_Files_Options
;
1964 WBI
("end " & Ada_Main
& ";");
1966 Close_Binder_Output
;
1967 end Gen_Output_File_Ada
;
1969 -----------------------
1970 -- Gen_Output_File_C --
1971 -----------------------
1973 procedure Gen_Output_File_C
(Filename
: String) is
1976 -- Name of generated bind file
1979 Create_Binder_Output
(Filename
, 'c', Bfile
);
1981 Resolve_Binder_Options
;
1983 WBI
("extern void __gnat_set_globals (int, int, int, int, int, int,");
1984 WBI
(" const char *, int, int, int);");
1985 WBI
("extern void " & Ada_Final_Name
.all & " (void);");
1986 WBI
("extern void " & Ada_Init_Name
.all & " (void);");
1988 WBI
("extern void system__standard_library__adafinal (void);");
1990 if not No_Main_Subprogram
then
1991 WBI
("extern int main (int, char **, char **);");
1992 if Hostparm
.OpenVMS
then
1993 WBI
("extern void __posix_exit (int);");
1995 WBI
("extern void exit (int);");
1998 WBI
("extern void __gnat_break_start (void);");
1999 Set_String
("extern ");
2001 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2002 Set_String
("void ");
2004 Set_String
("int ");
2007 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2008 Set_Main_Program_Name
;
2009 Set_String
(" (void);");
2010 Write_Statement_Buffer
;
2013 if not No_Run_Time_Specified
then
2014 WBI
("extern void __gnat_initialize (void);");
2015 WBI
("extern void __gnat_finalize (void);");
2016 WBI
("extern void __gnat_install_handler (void);");
2023 -- Imported variable used to track elaboration/finalization phase.
2024 -- Used only when we have a runtime.
2026 if not No_Run_Time_Specified
then
2027 WBI
("extern int __gnat_handler_installed;");
2031 -- Write argv/argc stuff if main program case
2033 if Bind_Main_Program
then
2035 -- In the normal case, these are in the runtime library
2037 if not No_Run_Time_Specified
then
2038 WBI
("extern int gnat_argc;");
2039 WBI
("extern char **gnat_argv;");
2040 WBI
("extern char **gnat_envp;");
2041 WBI
("extern int gnat_exit_status;");
2043 -- In the No_Run_Time case, they are right in the binder file
2044 -- and we initialize gnat_exit_status in the declaration.
2047 WBI
("int gnat_argc;");
2048 WBI
("char **gnat_argv;");
2049 WBI
("char **gnat_envp;");
2050 WBI
("int gnat_exit_status = 0;");
2056 -- In no run-time mode, the __gnat_break_start routine (for the
2057 -- debugger to get initial control) is defined in this file.
2059 if No_Run_Time_Specified
then
2061 WBI
("void __gnat_break_start () {}");
2064 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2065 -- only for the main program. Otherwise, it can lead under some
2066 -- circumstances to a symbol duplication during the link (for instance
2067 -- when a C program uses 2 Ada libraries)
2069 if Bind_Main_Program
then
2071 WBI
("char __gnat_version[] = ""GNAT Version: " &
2072 Gnat_Version_String
& """;");
2074 Set_String
("char __gnat_ada_main_program_name[] = """);
2075 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2076 Set_Main_Program_Name
;
2078 Write_Statement_Buffer
;
2081 -- Generate the adafinal routine. In no runtime mode, this is
2082 -- not needed, since there is no finalization to do.
2084 if not No_Run_Time_Specified
then
2090 -- Main is only present for Ada main case
2092 if Bind_Main_Program
then
2096 -- Scalar values, versions and object files needed in both cases
2098 if Initialize_Scalars_Used
then
2104 Gen_Object_Files_Options
;
2106 -- C binder output is complete
2108 Close_Binder_Output
;
2109 end Gen_Output_File_C
;
2111 -----------------------
2112 -- Gen_Scalar_Values --
2113 -----------------------
2115 procedure Gen_Scalar_Values
is
2117 -- Strings to hold hex values of initialization constants. Note that
2118 -- we store these strings in big endian order, but they are actually
2119 -- used to initialize integer values, so the actual generated data
2120 -- will automaticaly have the right endianess.
2122 IS_Is1
: String (1 .. 2);
2123 IS_Is2
: String (1 .. 4);
2124 IS_Is4
: String (1 .. 8);
2125 IS_Is8
: String (1 .. 16);
2126 IS_Iu1
: String (1 .. 2);
2127 IS_Iu2
: String (1 .. 4);
2128 IS_Iu4
: String (1 .. 8);
2129 IS_Iu8
: String (1 .. 16);
2130 IS_Isf
: String (1 .. 8);
2131 IS_Ifl
: String (1 .. 8);
2132 IS_Ilf
: String (1 .. 16);
2134 -- The string for Long_Long_Float is special. This is used only on the
2135 -- ia32 with 80-bit extended float (stored in 96 bits by gcc). The
2136 -- value here is represented little-endian, since that's the only way
2137 -- it is ever generated (this is not used on big-endian machines.
2139 IS_Ill
: String (1 .. 24);
2142 -- -Sin (invalid values)
2144 if Opt
.Initialize_Scalars_Mode
= 'I' then
2147 IS_Is4
:= "80000000";
2148 IS_Is8
:= "8000000000000000";
2151 IS_Iu4
:= "FFFFFFFF";
2152 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2156 IS_Ill
:= "00000000000000C0FFFF0000";
2158 -- -Slo (low values)
2160 elsif Opt
.Initialize_Scalars_Mode
= 'L' then
2163 IS_Is4
:= "80000000";
2164 IS_Is8
:= "8000000000000000";
2167 IS_Iu4
:= "00000000";
2168 IS_Iu8
:= "0000000000000000";
2169 IS_Isf
:= "FF800000";
2171 IS_Ilf
:= "FFF0000000000000";
2172 IS_Ill
:= "0000000000000080FFFF0000";
2174 -- -Shi (high values)
2176 elsif Opt
.Initialize_Scalars_Mode
= 'H' then
2179 IS_Is4
:= "7FFFFFFF";
2180 IS_Is8
:= "7FFFFFFFFFFFFFFF";
2183 IS_Iu4
:= "FFFFFFFF";
2184 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2185 IS_Isf
:= "7F800000";
2187 IS_Ilf
:= "7FF0000000000000";
2188 IS_Ill
:= "0000000000000080FF7F0000";
2192 else pragma Assert
(Opt
.Initialize_Scalars_Mode
= 'X');
2193 IS_Is1
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2194 IS_Is2
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2195 IS_Is2
(3 .. 4) := Opt
.Initialize_Scalars_Val
;
2197 for J
in 1 .. 4 loop
2198 IS_Is4
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2201 for J
in 1 .. 8 loop
2202 IS_Is8
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2214 for J
in 1 .. 12 loop
2215 IS_Ill
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2219 -- Generate output, Ada case
2221 if Ada_Bind_File
then
2224 Set_String
(" IS_Is1 : constant System.Scalar_Values.Byte1 := 16#");
2225 Set_String
(IS_Is1
);
2226 Write_Statement_Buffer
("#;");
2228 Set_String
(" IS_Is2 : constant System.Scalar_Values.Byte2 := 16#");
2229 Set_String
(IS_Is2
);
2230 Write_Statement_Buffer
("#;");
2232 Set_String
(" IS_Is4 : constant System.Scalar_Values.Byte4 := 16#");
2233 Set_String
(IS_Is4
);
2234 Write_Statement_Buffer
("#;");
2236 Set_String
(" IS_Is8 : constant System.Scalar_Values.Byte8 := 16#");
2237 Set_String
(IS_Is8
);
2238 Write_Statement_Buffer
("#;");
2240 Set_String
(" IS_Iu1 : constant System.Scalar_Values.Byte1 := 16#");
2241 Set_String
(IS_Iu1
);
2242 Write_Statement_Buffer
("#;");
2244 Set_String
(" IS_Iu2 : constant System.Scalar_Values.Byte2 := 16#");
2245 Set_String
(IS_Iu2
);
2246 Write_Statement_Buffer
("#;");
2248 Set_String
(" IS_Iu4 : constant System.Scalar_Values.Byte4 := 16#");
2249 Set_String
(IS_Iu4
);
2250 Write_Statement_Buffer
("#;");
2252 Set_String
(" IS_Iu8 : constant System.Scalar_Values.Byte8 := 16#");
2253 Set_String
(IS_Iu8
);
2254 Write_Statement_Buffer
("#;");
2256 Set_String
(" IS_Isf : constant System.Scalar_Values.Byte4 := 16#");
2257 Set_String
(IS_Isf
);
2258 Write_Statement_Buffer
("#;");
2260 Set_String
(" IS_Ifl : constant System.Scalar_Values.Byte4 := 16#");
2261 Set_String
(IS_Ifl
);
2262 Write_Statement_Buffer
("#;");
2264 Set_String
(" IS_Ilf : constant System.Scalar_Values.Byte8 := 16#");
2265 Set_String
(IS_Ilf
);
2266 Write_Statement_Buffer
("#;");
2268 -- Special case of Long_Long_Float. This is a 10-byte value used
2269 -- only on the x86. We could omit it for other architectures, but
2270 -- we don't easily have that kind of target specialization in the
2271 -- binder, and it's only 10 bytes, and only if -Sxx is used. Note
2272 -- that for architectures where Long_Long_Float is the same as
2273 -- Long_Float, the expander uses the Long_Float constant for the
2274 -- initializations of Long_Long_Float values.
2276 WBI
(" IS_Ill : constant array (1 .. 12) of");
2277 WBI
(" System.Scalar_Values.Byte1 := (");
2280 for J
in 1 .. 6 loop
2281 Set_String
(" 16#");
2282 Set_Char
(IS_Ill
(2 * J
- 1));
2283 Set_Char
(IS_Ill
(2 * J
));
2287 Write_Statement_Buffer
;
2290 for J
in 7 .. 12 loop
2291 Set_String
(" 16#");
2292 Set_Char
(IS_Ill
(2 * J
- 1));
2293 Set_Char
(IS_Ill
(2 * J
));
2302 Write_Statement_Buffer
;
2304 -- Output export statements to export to System.Scalar_Values
2308 WBI
(" pragma Export (Ada, IS_Is1, ""__gnat_Is1"");");
2309 WBI
(" pragma Export (Ada, IS_Is2, ""__gnat_Is2"");");
2310 WBI
(" pragma Export (Ada, IS_Is4, ""__gnat_Is4"");");
2311 WBI
(" pragma Export (Ada, IS_Is8, ""__gnat_Is8"");");
2312 WBI
(" pragma Export (Ada, IS_Iu1, ""__gnat_Iu1"");");
2313 WBI
(" pragma Export (Ada, IS_Iu2, ""__gnat_Iu2"");");
2314 WBI
(" pragma Export (Ada, IS_Iu4, ""__gnat_Iu4"");");
2315 WBI
(" pragma Export (Ada, IS_Iu8, ""__gnat_Iu8"");");
2316 WBI
(" pragma Export (Ada, IS_Isf, ""__gnat_Isf"");");
2317 WBI
(" pragma Export (Ada, IS_Ifl, ""__gnat_Ifl"");");
2318 WBI
(" pragma Export (Ada, IS_Ilf, ""__gnat_Ilf"");");
2319 WBI
(" pragma Export (Ada, IS_Ill, ""__gnat_Ill"");");
2321 -- Generate output C case
2324 -- The lines we generate in this case are of the form
2325 -- typ __gnat_I?? = 0x??;
2326 -- where typ is appropriate to the length
2330 Set_String
("unsigned char __gnat_Is1 = 0x");
2331 Set_String
(IS_Is1
);
2332 Write_Statement_Buffer
(";");
2334 Set_String
("unsigned short __gnat_Is2 = 0x");
2335 Set_String
(IS_Is2
);
2336 Write_Statement_Buffer
(";");
2338 Set_String
("unsigned __gnat_Is4 = 0x");
2339 Set_String
(IS_Is4
);
2340 Write_Statement_Buffer
(";");
2342 Set_String
("long long unsigned __gnat_Is8 = 0x");
2343 Set_String
(IS_Is8
);
2344 Write_Statement_Buffer
("LL;");
2346 Set_String
("unsigned char __gnat_Iu1 = 0x");
2347 Set_String
(IS_Is1
);
2348 Write_Statement_Buffer
(";");
2350 Set_String
("unsigned short __gnat_Iu2 = 0x");
2351 Set_String
(IS_Is2
);
2352 Write_Statement_Buffer
(";");
2354 Set_String
("unsigned __gnat_Iu4 = 0x");
2355 Set_String
(IS_Is4
);
2356 Write_Statement_Buffer
(";");
2358 Set_String
("long long unsigned __gnat_Iu8 = 0x");
2359 Set_String
(IS_Is8
);
2360 Write_Statement_Buffer
("LL;");
2362 Set_String
("unsigned __gnat_Isf = 0x");
2363 Set_String
(IS_Isf
);
2364 Write_Statement_Buffer
(";");
2366 Set_String
("unsigned __gnat_Ifl = 0x");
2367 Set_String
(IS_Ifl
);
2368 Write_Statement_Buffer
(";");
2370 Set_String
("long long unsigned __gnat_Ilf = 0x");
2371 Set_String
(IS_Ilf
);
2372 Write_Statement_Buffer
("LL;");
2374 -- For Long_Long_Float, we generate
2375 -- char __gnat_Ill[12] = {0x??, 0x??, 0x??, 0x??, 0x??, 0x??,
2376 -- 0x??, 0x??, 0x??, 0x??, 0x??, 0x??);
2378 Set_String
("unsigned char __gnat_Ill[12] = {");
2380 for J
in 1 .. 6 loop
2382 Set_Char
(IS_Ill
(2 * J
- 1));
2383 Set_Char
(IS_Ill
(2 * J
));
2387 Write_Statement_Buffer
;
2390 for J
in 7 .. 12 loop
2392 Set_Char
(IS_Ill
(2 * J
- 1));
2393 Set_Char
(IS_Ill
(2 * J
));
2402 Write_Statement_Buffer
;
2404 end Gen_Scalar_Values
;
2406 ----------------------
2407 -- Gen_Versions_Ada --
2408 ----------------------
2410 -- This routine generates two sets of lines. The first set has the form:
2412 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2414 -- The second set has the form
2416 -- pragma Export (C, unnnnn, unam);
2418 -- for each unit, where unam is the unit name suffixed by either B or
2419 -- S for body or spec, with dots replaced by double underscores, and
2420 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2422 procedure Gen_Versions_Ada
is
2423 Ubuf
: String (1 .. 6) := "u00000";
2425 procedure Increment_Ubuf
;
2426 -- Little procedure to increment the serial number
2428 procedure Increment_Ubuf
is
2430 for J
in reverse Ubuf
'Range loop
2431 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2432 exit when Ubuf
(J
) <= '9';
2437 -- Start of processing for Gen_Versions_Ada
2440 if Bind_For_Library
then
2442 -- When building libraries, the version number of each unit can
2443 -- not be computed, since the binder does not know the full list
2444 -- of units. Therefore, the 'Version and 'Body_Version
2445 -- attributes can not supported in this case.
2452 WBI
(" type Version_32 is mod 2 ** 32;");
2453 for U
in Units
.First
.. Units
.Last
loop
2455 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2456 Units
.Table
(U
).Version
& "#;");
2462 for U
in Units
.First
.. Units
.Last
loop
2464 Set_String
(" pragma Export (C, ");
2466 Set_String
(", """);
2468 Get_Name_String
(Units
.Table
(U
).Uname
);
2470 for K
in 1 .. Name_Len
loop
2471 if Name_Buffer
(K
) = '.' then
2475 elsif Name_Buffer
(K
) = '%' then
2479 Set_Char
(Name_Buffer
(K
));
2483 if Name_Buffer
(Name_Len
) = 's' then
2489 Set_String
(""");");
2490 Write_Statement_Buffer
;
2493 end Gen_Versions_Ada
;
2495 --------------------
2496 -- Gen_Versions_C --
2497 --------------------
2499 -- This routine generates a line of the form:
2501 -- unsigned unam = 0xhhhhhhhh;
2503 -- for each unit, where unam is the unit name suffixed by either B or
2504 -- S for body or spec, with dots replaced by double underscores.
2506 procedure Gen_Versions_C
is
2508 if Bind_For_Library
then
2510 -- When building libraries, the version number of each unit can
2511 -- not be computed, since the binder does not know the full list
2512 -- of units. Therefore, the 'Version and 'Body_Version
2513 -- attributes can not supported.
2518 for U
in Units
.First
.. Units
.Last
loop
2519 Set_String
("unsigned ");
2521 Get_Name_String
(Units
.Table
(U
).Uname
);
2523 for K
in 1 .. Name_Len
loop
2524 if Name_Buffer
(K
) = '.' then
2527 elsif Name_Buffer
(K
) = '%' then
2531 Set_Char
(Name_Buffer
(K
));
2535 if Name_Buffer
(Name_Len
) = 's' then
2541 Set_String
(" = 0x");
2542 Set_String
(Units
.Table
(U
).Version
);
2544 Write_Statement_Buffer
;
2549 -----------------------
2550 -- Get_Ada_Main_Name --
2551 -----------------------
2553 function Get_Ada_Main_Name
return String is
2554 Suffix
: constant String := "_00";
2555 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
2556 Opt
.Ada_Main_Name
.all & Suffix
;
2560 -- The main program generated by JGNAT expects a package called
2561 -- ada_<main procedure>.
2563 if Hostparm
.Java_VM
then
2564 -- Get main program name
2566 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2570 return "ada_" & Name_Buffer
(1 .. Name_Len
- 2);
2573 -- This loop tries the following possibilities in order
2579 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2580 -- it is set to 'ada_main'.
2582 for J
in 0 .. 99 loop
2584 Nlen
:= Name
'Length - Suffix
'Length;
2586 Nlen
:= Name
'Length;
2587 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
2588 Name
(Name
'Last - 1) :=
2589 Character'Val (J
/ 10 + Character'Pos ('0'));
2592 for K
in ALIs
.First
.. ALIs
.Last
loop
2593 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
2595 -- Get unit name, removing %b or %e at end
2597 Get_Name_String
(Units
.Table
(L
).Uname
);
2598 Name_Len
:= Name_Len
- 2;
2600 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
2606 return Name
(1 .. Nlen
);
2612 -- If we fall through, just use a peculiar unlikely name
2614 return ("Qwertyuiop");
2615 end Get_Ada_Main_Name
;
2621 function Get_Main_Name
return String is
2622 Target
: constant String_Ptr
:= Target_Name
;
2623 VxWorks_Target
: constant Boolean :=
2624 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/"
2625 or else Target
(Target
'Last - 9 .. Target
'Last) = "vxworksae/";
2628 -- Explicit name given with -M switch
2630 if Bind_Alternate_Main_Name
then
2631 return Alternate_Main_Name
.all;
2633 -- Case of main program name to be used directly
2635 elsif VxWorks_Target
then
2637 -- Get main program name
2639 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2641 -- If this is a child name, return only the name of the child,
2642 -- since we can't have dots in a nested program name. Note that
2643 -- we do not include the %b at the end of the unit name.
2645 for J
in reverse 1 .. Name_Len
- 2 loop
2646 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
2647 return Name_Buffer
(J
.. Name_Len
- 2);
2651 raise Program_Error
; -- impossible exit
2653 -- Case where "main" is to be used as default
2660 ----------------------
2661 -- Lt_Linker_Option --
2662 ----------------------
2664 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean is
2666 -- Sort internal files last
2668 if Linker_Options
.Table
(Op1
).Internal_File
2670 Linker_Options
.Table
(Op2
).Internal_File
2672 -- Note: following test uses False < True
2674 return Linker_Options
.Table
(Op1
).Internal_File
2676 Linker_Options
.Table
(Op2
).Internal_File
;
2678 -- If both internal or both non-internal, sort according to the
2679 -- elaboration position. A unit that is elaborated later should
2680 -- come earlier in the linker options list.
2683 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
2685 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
2688 end Lt_Linker_Option
;
2690 ------------------------
2691 -- Move_Linker_Option --
2692 ------------------------
2694 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
2696 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
2697 end Move_Linker_Option
;
2699 ----------------------------
2700 -- Resolve_Binder_Options --
2701 ----------------------------
2703 procedure Resolve_Binder_Options
is
2705 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2706 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
2708 -- The procedure of looking for specific packages and setting
2709 -- flags is very wrong, but there isn't a good alternative at
2712 if Name_Buffer
(1 .. 19) = "system.os_interface" then
2716 if Hostparm
.OpenVMS
and then Name_Buffer
(1 .. 3) = "dec" then
2717 With_DECGNAT
:= True;
2720 end Resolve_Binder_Options
;
2726 procedure Set_Char
(C
: Character) is
2729 Statement_Buffer
(Last
) := C
;
2736 procedure Set_Int
(N
: Int
) is
2748 Statement_Buffer
(Last
) :=
2749 Character'Val (N
mod 10 + Character'Pos ('0'));
2753 ---------------------------
2754 -- Set_Main_Program_Name --
2755 ---------------------------
2757 procedure Set_Main_Program_Name
is
2759 -- Note that name has %b on the end which we ignore
2761 -- First we output the initial _ada_ since we know that the main
2762 -- program is a library level subprogram.
2764 Set_String
("_ada_");
2766 -- Copy name, changing dots to double underscores
2768 for J
in 1 .. Name_Len
- 2 loop
2769 if Name_Buffer
(J
) = '.' then
2772 Set_Char
(Name_Buffer
(J
));
2775 end Set_Main_Program_Name
;
2777 ---------------------
2778 -- Set_Name_Buffer --
2779 ---------------------
2781 procedure Set_Name_Buffer
is
2783 for J
in 1 .. Name_Len
loop
2784 Set_Char
(Name_Buffer
(J
));
2786 end Set_Name_Buffer
;
2792 procedure Set_String
(S
: String) is
2794 Statement_Buffer
(Last
+ 1 .. Last
+ S
'Length) := S
;
2795 Last
:= Last
+ S
'Length;
2802 procedure Set_Unit_Name
is
2804 for J
in 1 .. Name_Len
- 2 loop
2805 if Name_Buffer
(J
) /= '.' then
2806 Set_Char
(Name_Buffer
(J
));
2813 ---------------------
2814 -- Set_Unit_Number --
2815 ---------------------
2817 procedure Set_Unit_Number
(U
: Unit_Id
) is
2818 Num_Units
: constant Nat
:= Nat
(Units
.Table
'Last) - Nat
(Unit_Id
'First);
2819 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
2822 if Num_Units
>= 10 and then Unum
< 10 then
2826 if Num_Units
>= 100 and then Unum
< 100 then
2831 end Set_Unit_Number
;
2837 procedure Tab_To
(N
: Natural) is
2844 ----------------------
2845 -- Write_Info_Ada_C --
2846 ----------------------
2848 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String) is
2850 if Ada_Bind_File
then
2852 S
: String (1 .. Ada
'Length + Common
'Length);
2855 S
(1 .. Ada
'Length) := Ada
;
2856 S
(Ada
'Length + 1 .. S
'Length) := Common
;
2862 S
: String (1 .. C
'Length + Common
'Length);
2865 S
(1 .. C
'Length) := C
;
2866 S
(C
'Length + 1 .. S
'Length) := Common
;
2870 end Write_Info_Ada_C
;
2872 ----------------------------
2873 -- Write_Statement_Buffer --
2874 ----------------------------
2876 procedure Write_Statement_Buffer
is
2878 WBI
(Statement_Buffer
(1 .. Last
));
2880 end Write_Statement_Buffer
;
2882 procedure Write_Statement_Buffer
(S
: String) is
2885 Write_Statement_Buffer
;
2886 end Write_Statement_Buffer
;