1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- $Revision: 1.5.10.1 $
11 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 ------------------------------------------------------------------------------
30 with Binde
; use Binde
;
31 with Butil
; use Butil
;
32 with Casing
; use Casing
;
33 with Fname
; use Fname
;
34 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
35 with Gnatvsn
; use Gnatvsn
;
37 with Namet
; use Namet
;
39 with Osint
; use Osint
;
40 with Output
; use Output
;
41 with Types
; use Types
;
42 with Sdefault
; use Sdefault
;
43 with System
; use System
;
45 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
47 package body Bindgen
is
49 Statement_Buffer
: String (1 .. 1000);
50 -- Buffer used for constructing output statements
53 -- Last location in Statement_Buffer currently set
55 With_DECGNAT
: Boolean := False;
56 -- Flag which indicates whether the program uses the DECGNAT library
57 -- (presence of the unit System.Aux_DEC.DECLIB)
59 With_GNARL
: Boolean := False;
60 -- Flag which indicates whether the program uses the GNARL library
61 -- (presence of the unit System.OS_Interface)
63 Num_Elab_Calls
: Nat
:= 0;
64 -- Number of generated calls to elaboration routines
66 subtype chars_ptr
is Address
;
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure WBI
(Info
: String) renames Osint
.Write_Binder_Info
;
73 -- Convenient shorthand used throughout
75 function ABE_Boolean_Required
(U
: Unit_Id
) return Boolean;
76 -- Given a unit id value U, determines if the corresponding unit requires
77 -- an access-before-elaboration check variable, i.e. it is a non-predefined
78 -- body for which no pragma Elaborate, Elaborate_All or Elaborate_Body is
79 -- present, and thus could require ABE checks.
81 procedure Resolve_Binder_Options
;
82 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
83 -- since it tests for a package named "dec" which might cause a conflict
84 -- on non-VMS systems.
86 procedure Gen_Adainit_Ada
;
87 -- Generates the Adainit procedure (Ada code case)
89 procedure Gen_Adainit_C
;
90 -- Generates the Adainit procedure (C code case)
92 procedure Gen_Adafinal_Ada
;
93 -- Generate the Adafinal procedure (Ada code case)
95 procedure Gen_Adafinal_C
;
96 -- Generate the Adafinal procedure (C code case)
98 procedure Gen_Elab_Calls_Ada
;
99 -- Generate sequence of elaboration calls (Ada code case)
101 procedure Gen_Elab_Calls_C
;
102 -- Generate sequence of elaboration calls (C code case)
104 procedure Gen_Elab_Order_Ada
;
105 -- Generate comments showing elaboration order chosen (Ada case)
107 procedure Gen_Elab_Order_C
;
108 -- Generate comments showing elaboration order chosen (C case)
110 procedure Gen_Elab_Defs_C
;
111 -- Generate sequence of definitions for elaboration routines (C code case)
113 procedure Gen_Exception_Table_Ada
;
114 -- Generate binder exception table (Ada code case). This consists of
115 -- declarations followed by a begin followed by a call. If zero cost
116 -- exceptions are not active, then only the begin is generated.
118 procedure Gen_Exception_Table_C
;
119 -- Generate binder exception table (C code case). This has no effect
120 -- if zero cost exceptions are not active, otherwise it generates a
121 -- set of declarations followed by a call.
123 procedure Gen_Main_Ada
;
124 -- Generate procedure main (Ada code case)
126 procedure Gen_Main_C
;
127 -- Generate main() procedure (C code case)
129 procedure Gen_Object_Files_Options
;
130 -- Output comments containing a list of the full names of the object
131 -- files to be linked and the list of linker options supplied by
132 -- Linker_Options pragmas in the source. (C and Ada code case)
134 procedure Gen_Output_File_Ada
(Filename
: String);
135 -- Generate output file (Ada code case)
137 procedure Gen_Output_File_C
(Filename
: String);
138 -- Generate output file (C code case)
140 procedure Gen_Scalar_Values
;
141 -- Generates scalar initialization values for -Snn. A single procedure
142 -- handles both the Ada and C cases, since there is much common code.
144 procedure Gen_Versions_Ada
;
145 -- Output series of definitions for unit versions (Ada code case)
147 procedure Gen_Versions_C
;
148 -- Output series of definitions for unit versions (C code case)
150 function Get_Ada_Main_Name
return String;
151 -- This function is used in the Ada main output case to compute a usable
152 -- name for the generated main program. The normal main program name is
153 -- Ada_Main, but this won't work if the user has a unit with this name.
154 -- This function tries Ada_Main first, and if there is such a clash, then
155 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
157 function Get_Main_Name
return String;
158 -- This function is used in the Ada main output case to compute the
159 -- correct external main program. It is "main" by default, except on
160 -- VxWorks where it is the name of the Ada main name without the "_ada".
161 -- the -Mname binder option overrides the default with name.
163 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean;
164 -- Compare linker options, when sorting, first according to
165 -- Is_Internal_File (internal files come later) and then by elaboration
166 -- order position (latest to earliest) except its not possible to
167 -- distinguish between a linker option in the spec and one in the body.
169 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
170 -- Move routine for sorting linker options
172 procedure Set_Char
(C
: Character);
173 -- Set given character in Statement_Buffer at the Last + 1 position
174 -- and increment Last by one to reflect the stored character.
176 procedure Set_Int
(N
: Int
);
177 -- Set given value in decimal in Statement_Buffer with no spaces
178 -- starting at the Last + 1 position, and updating Last past the value.
179 -- A minus sign is output for a negative value.
181 procedure Set_Main_Program_Name
;
182 -- Given the main program name in Name_Buffer (length in Name_Len)
183 -- generate the name of the routine to be used in the call. The name
184 -- is generated starting at Last + 1, and Last is updated past it.
186 procedure Set_Name_Buffer
;
187 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer.
189 procedure Set_String
(S
: String);
190 -- Sets characters of given string in Statement_Buffer, starting at the
191 -- Last + 1 position, and updating last past the string value.
193 procedure Set_Unit_Name
;
194 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
195 -- starting at the Last + 1 position, and updating last past the value.
196 -- changing periods to double underscores, and updating Last appropriately.
198 procedure Set_Unit_Number
(U
: Unit_Id
);
199 -- Sets unit number (first unit is 1, leading zeroes output to line
200 -- up all output unit numbers nicely as required by the value, and
201 -- by the total number of units.
203 procedure Tab_To
(N
: Natural);
204 -- If Last is greater than or equal to N, no effect, otherwise store
205 -- blanks in Statement_Buffer bumping Last, until Last = N.
207 function Value
(chars
: chars_ptr
) return String;
208 -- Return C NUL-terminated string at chars as an Ada string
210 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String);
211 -- For C code case, write C & Common, for Ada case write Ada & Common
212 -- to current binder output file using Write_Binder_Info.
214 procedure Write_Statement_Buffer
;
215 -- Write out contents of statement buffer up to Last, and reset Last to 0
217 procedure Write_Statement_Buffer
(S
: String);
218 -- First writes its argument (using Set_String (S)), then writes out the
219 -- contents of statement buffer up to Last, and reset Last to 0
221 --------------------------
222 -- ABE_Boolean_Required --
223 --------------------------
225 function ABE_Boolean_Required
(U
: Unit_Id
) return Boolean is
226 Typ
: constant Unit_Type
:= Units
.Table
(U
).Utype
;
230 if Typ
/= Is_Body
then
236 return (not Units
.Table
(Unit
).Pure
)
238 (not Units
.Table
(Unit
).Preelab
)
240 (not Units
.Table
(Unit
).Elaborate_Body
)
242 (not Units
.Table
(Unit
).Predefined
);
244 end ABE_Boolean_Required
;
246 ----------------------
247 -- Gen_Adafinal_Ada --
248 ----------------------
250 procedure Gen_Adafinal_Ada
is
253 WBI
(" procedure " & Ada_Final_Name
.all & " is");
256 -- If compiling for the JVM, we directly call Adafinal because
257 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
259 if Hostparm
.Java_VM
then
260 WBI
(" System.Standard_Library.Adafinal;");
262 WBI
(" Do_Finalize;");
265 WBI
(" end " & Ada_Final_Name
.all & ";");
266 end Gen_Adafinal_Ada
;
272 procedure Gen_Adafinal_C
is
274 WBI
("void " & Ada_Final_Name
.all & " () {");
275 WBI
(" system__standard_library__adafinal ();");
280 ---------------------
281 -- Gen_Adainit_Ada --
282 ---------------------
284 procedure Gen_Adainit_Ada
is
285 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
287 WBI
(" procedure " & Ada_Init_Name
.all & " is");
289 -- Generate externals for elaboration entities
291 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
293 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
294 U
: Unit_Record
renames Units
.Table
(Unum
);
297 if U
.Set_Elab_Entity
then
300 Set_Unit_Number
(Unum
);
301 Set_String
(" : Boolean; pragma Import (Ada, ");
303 Set_Unit_Number
(Unum
);
305 Get_Name_String
(U
.Uname
);
307 -- In the case of JGNAT we need to emit an Import name
308 -- that includes the class name (using '$' separators
309 -- in the case of a child unit name).
311 if Hostparm
.Java_VM
then
312 for J
in 1 .. Name_Len
- 2 loop
313 if Name_Buffer
(J
) /= '.' then
314 Set_Char
(Name_Buffer
(J
));
322 -- If the unit name is very long, then split the
323 -- Import link name across lines using "&" (occurs
324 -- in some C2 tests).
326 if 2 * Name_Len
+ 60 > Hostparm
.Max_Line_Length
then
328 Write_Statement_Buffer
;
334 Set_String
("_E"");");
335 Write_Statement_Buffer
;
340 Write_Statement_Buffer
;
342 -- Normal case (not No_Run_Time mode). The global values are
343 -- assigned using the runtime routine Set_Globals (we have to use
344 -- the routine call, rather than define the globals in the binder
345 -- file to deal with cross-library calls in some systems.
347 if No_Run_Time_Specified
then
349 -- Case of No_Run_Time mode. The only global variable that might
350 -- be needed (by the Ravenscar profile) is the priority of the
351 -- environment. Also no exception tables are needed.
353 if Main_Priority
/= No_Main_Priority
then
354 WBI
(" Main_Priority : Integer;");
355 WBI
(" pragma Import (C, Main_Priority," &
356 " ""__gl_main_priority"");");
362 if Main_Priority
/= No_Main_Priority
then
363 Set_String
(" Main_Priority := ");
364 Set_Int
(Main_Priority
);
366 Write_Statement_Buffer
;
374 WBI
(" procedure Set_Globals");
375 WBI
(" (Main_Priority : Integer;");
376 WBI
(" Time_Slice_Value : Integer;");
377 WBI
(" WC_Encoding : Character;");
378 WBI
(" Locking_Policy : Character;");
379 WBI
(" Queuing_Policy : Character;");
380 WBI
(" Task_Dispatching_Policy : Character;");
381 WBI
(" Adafinal : System.Address;");
382 WBI
(" Unreserve_All_Interrupts : Integer;");
383 WBI
(" Exception_Tracebacks : Integer);");
384 WBI
(" pragma Import (C, Set_Globals, ""__gnat_set_globals"");");
387 -- Import entry point for elaboration time signal handler
388 -- installation, and indication of whether it's been called
391 WBI
(" procedure Install_Handler;");
392 WBI
(" pragma Import (C, Install_Handler, " &
393 """__gnat_install_handler"");");
395 WBI
(" Handler_Installed : Integer;");
396 WBI
(" pragma Import (C, Handler_Installed, " &
397 """__gnat_handler_installed"");");
399 -- Generate exception table
401 Gen_Exception_Table_Ada
;
403 -- Generate the call to Set_Globals
405 WBI
(" Set_Globals");
407 Set_String
(" (Main_Priority => ");
408 Set_Int
(Main_Priority
);
410 Write_Statement_Buffer
;
412 Set_String
(" Time_Slice_Value => ");
414 if Task_Dispatching_Policy_Specified
= 'F'
415 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
419 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
423 Write_Statement_Buffer
;
425 Set_String
(" WC_Encoding => '");
426 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
428 Write_Statement_Buffer
;
430 Set_String
(" Locking_Policy => '");
431 Set_Char
(Locking_Policy_Specified
);
433 Write_Statement_Buffer
;
435 Set_String
(" Queuing_Policy => '");
436 Set_Char
(Queuing_Policy_Specified
);
438 Write_Statement_Buffer
;
440 Set_String
(" Task_Dispatching_Policy => '");
441 Set_Char
(Task_Dispatching_Policy_Specified
);
443 Write_Statement_Buffer
;
445 WBI
(" Adafinal => System.Null_Address,");
447 Set_String
(" Unreserve_All_Interrupts => ");
449 if Unreserve_All_Interrupts_Specified
then
456 Write_Statement_Buffer
;
458 Set_String
(" Exception_Tracebacks => ");
460 if Exception_Tracebacks
then
467 Write_Statement_Buffer
;
469 -- Generate call to Install_Handler
471 WBI
(" if Handler_Installed = 0 then");
472 WBI
(" Install_Handler;");
478 WBI
(" end " & Ada_Init_Name
.all & ";");
485 procedure Gen_Adainit_C
is
486 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
488 WBI
("void " & Ada_Init_Name
.all & " ()");
491 -- Generate externals for elaboration entities
493 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
495 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
496 U
: Unit_Record
renames Units
.Table
(Unum
);
499 if U
.Set_Elab_Entity
then
500 Set_String
(" extern char ");
501 Get_Name_String
(U
.Uname
);
504 Write_Statement_Buffer
;
509 Write_Statement_Buffer
;
511 if No_Run_Time_Specified
then
513 -- Case of No_Run_Time mode. Set __gl_main_priority if needed
514 -- for the Ravenscar profile.
516 if Main_Priority
/= No_Main_Priority
then
517 Set_String
(" extern int __gl_main_priority = ");
518 Set_Int
(Main_Priority
);
520 Write_Statement_Buffer
;
524 -- Code for normal case (not in No_Run_Time mode)
526 Gen_Exception_Table_C
;
528 -- Generate call to set the runtime global variables defined in
529 -- a-init.c. We define the varables in a-init.c, rather than in
530 -- the binder generated file itself to avoid undefined externals
531 -- when the runtime is linked as a shareable image library.
533 -- We call the routine from inside adainit() because this works for
534 -- both programs with and without binder generated "main" functions.
536 WBI
(" __gnat_set_globals (");
539 Set_Int
(Main_Priority
);
542 Set_String
("/* Main_Priority */");
543 Write_Statement_Buffer
;
547 if Task_Dispatching_Policy
= 'F'
548 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
552 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
557 Set_String
("/* Time_Slice_Value */");
558 Write_Statement_Buffer
;
561 Set_Char
(ALIs
.Table
(ALIs
.First
).WC_Encoding
);
564 Set_String
("/* WC_Encoding */");
565 Write_Statement_Buffer
;
568 Set_Char
(Locking_Policy_Specified
);
571 Set_String
("/* Locking_Policy */");
572 Write_Statement_Buffer
;
575 Set_Char
(Queuing_Policy_Specified
);
578 Set_String
("/* Queuing_Policy */");
579 Write_Statement_Buffer
;
582 Set_Char
(Task_Dispatching_Policy_Specified
);
585 Set_String
("/* Tasking_Dispatching_Policy */");
586 Write_Statement_Buffer
;
591 Set_String
("/* Finalization routine address, not used anymore */");
592 Write_Statement_Buffer
;
595 Set_Int
(Boolean'Pos (Unreserve_All_Interrupts_Specified
));
598 Set_String
("/* Unreserve_All_Interrupts */");
599 Write_Statement_Buffer
;
602 Set_Int
(Boolean'Pos (Exception_Tracebacks
));
605 Set_String
("/* Exception_Tracebacks */");
606 Write_Statement_Buffer
;
608 -- Install elaboration time signal handler
609 WBI
(" if (__gnat_handler_installed == 0)");
611 WBI
(" __gnat_install_handler ();");
620 ------------------------
621 -- Gen_Elab_Calls_Ada --
622 ------------------------
624 procedure Gen_Elab_Calls_Ada
is
627 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
629 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
630 U
: Unit_Record
renames Units
.Table
(Unum
);
633 -- This is the unit number of the spec that corresponds to
634 -- this entry. It is the same as Unum except when the body
635 -- and spec are different and we are currently processing
636 -- the body, in which case it is the spec (Unum + 1).
638 procedure Set_Elab_Entity
;
639 -- Set name of elaboration entity flag
641 procedure Set_Elab_Entity
is
643 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
644 Name_Len
:= Name_Len
- 2;
645 Set_Casing
(U
.Icasing
);
650 if U
.Utype
= Is_Body
then
651 Unum_Spec
:= Unum
+ 1;
656 -- Case of no elaboration code
660 -- The only case in which we have to do something is if
661 -- this is a body, with a separate spec, where the separate
662 -- spec has an elaboration entity defined.
664 -- In that case, this is where we set the elaboration entity
665 -- to True, we do not need to test if this has already been
666 -- done, since it is quicker to set the flag than to test it.
669 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
672 Set_Unit_Number
(Unum_Spec
);
673 Set_String
(" := True;");
674 Write_Statement_Buffer
;
677 -- Here if elaboration code is present. We generate:
679 -- if not uname_E then
680 -- uname'elab_[spec|body];
684 -- The uname_E assignment is skipped if this is a separate spec,
685 -- since the assignment will be done when we process the body.
688 Set_String
(" if not E");
689 Set_Unit_Number
(Unum_Spec
);
690 Set_String
(" then");
691 Write_Statement_Buffer
;
694 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
696 if Name_Buffer
(Name_Len
) = 's' then
697 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_spec";
699 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) := "'elab_body";
702 Name_Len
:= Name_Len
+ 8;
703 Set_Casing
(U
.Icasing
);
706 Write_Statement_Buffer
;
708 if U
.Utype
/= Is_Spec
then
710 Set_Unit_Number
(Unum_Spec
);
711 Set_String
(" := True;");
712 Write_Statement_Buffer
;
720 end Gen_Elab_Calls_Ada
;
722 ----------------------
723 -- Gen_Elab_Calls_C --
724 ----------------------
726 procedure Gen_Elab_Calls_C
is
729 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
731 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
732 U
: Unit_Record
renames Units
.Table
(Unum
);
735 -- This is the unit number of the spec that corresponds to
736 -- this entry. It is the same as Unum except when the body
737 -- and spec are different and we are currently processing
738 -- the body, in which case it is the spec (Unum + 1).
741 if U
.Utype
= Is_Body
then
742 Unum_Spec
:= Unum
+ 1;
747 -- Case of no elaboration code
751 -- The only case in which we have to do something is if
752 -- this is a body, with a separate spec, where the separate
753 -- spec has an elaboration entity defined.
755 -- In that case, this is where we set the elaboration entity
756 -- to True, we do not need to test if this has already been
757 -- done, since it is quicker to set the flag than to test it.
760 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
763 Get_Name_String
(U
.Uname
);
765 Set_String
("_E = 1;");
766 Write_Statement_Buffer
;
769 -- Here if elaboration code is present. We generate:
771 -- if (uname_E == 0) {
772 -- uname__elab[s|b] ();
776 -- The uname_E assignment is skipped if this is a separate spec,
777 -- since the assignment will be done when we process the body.
780 Set_String
(" if (");
781 Get_Name_String
(U
.Uname
);
783 Set_String
("_E == 0) {");
784 Write_Statement_Buffer
;
788 Set_String
("___elab");
789 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
791 Write_Statement_Buffer
;
793 if U
.Utype
/= Is_Spec
then
796 Set_String
("_E++;");
797 Write_Statement_Buffer
;
805 end Gen_Elab_Calls_C
;
807 ----------------------
808 -- Gen_Elab_Defs_C --
809 ----------------------
811 procedure Gen_Elab_Defs_C
is
813 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
815 -- Generate declaration of elaboration procedure if elaboration
816 -- needed. Note that passive units are always excluded.
818 if not Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
819 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
820 Set_String
("extern void ");
822 Set_String
("___elab");
823 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
824 Set_String
(" PARAMS ((void));");
825 Write_Statement_Buffer
;
833 ------------------------
834 -- Gen_Elab_Order_Ada --
835 ------------------------
837 procedure Gen_Elab_Order_Ada
is
840 WBI
(" -- BEGIN ELABORATION ORDER");
842 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
844 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
846 Write_Statement_Buffer
;
849 WBI
(" -- END ELABORATION ORDER");
850 end Gen_Elab_Order_Ada
;
852 ----------------------
853 -- Gen_Elab_Order_C --
854 ----------------------
856 procedure Gen_Elab_Order_C
is
859 WBI
("/* BEGIN ELABORATION ORDER");
861 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
862 Get_Unit_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
864 Write_Statement_Buffer
;
867 WBI
(" END ELABORATION ORDER */");
868 end Gen_Elab_Order_C
;
870 -----------------------------
871 -- Gen_Exception_Table_Ada --
872 -----------------------------
874 procedure Gen_Exception_Table_Ada
is
876 Last
: ALI_Id
:= No_ALI_Id
;
879 if not Zero_Cost_Exceptions_Specified
then
884 -- The code we generate looks like
886 -- procedure SDP_Table_Build
887 -- (SDP_Addresses : System.Address;
888 -- SDP_Count : Natural;
889 -- Elab_Addresses : System.Address;
890 -- Elab_Addr_Count : Natural);
891 -- pragma Import (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
893 -- ST : aliased constant array (1 .. nnn) of System.Address := (
894 -- unit_name_1'UET_Address,
895 -- unit_name_2'UET_Address,
897 -- unit_name_3'UET_Address,
899 -- EA : aliased constant array (1 .. eee) of System.Address := (
900 -- adainit'Code_Address,
901 -- adafinal'Code_Address,
902 -- unit_name'elab[spec|body]'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);
908 -- SDP_Table_Build (ST'Address, nnn, EA'Address, eee);
911 for A
in ALIs
.First
.. ALIs
.Last
loop
912 if ALIs
.Table
(A
).Unit_Exception_Table
then
920 -- Happens with "gnatmake -a -f -gnatL ..."
927 WBI
(" procedure SDP_Table_Build");
928 WBI
(" (SDP_Addresses : System.Address;");
929 WBI
(" SDP_Count : Natural;");
930 WBI
(" Elab_Addresses : System.Address;");
931 WBI
(" Elab_Addr_Count : Natural);");
933 "pragma Import (C, SDP_Table_Build, ""__gnat_SDP_Table_Build"");");
936 Set_String
(" ST : aliased constant array (1 .. ");
938 Set_String
(") of System.Address := (");
941 Set_String
("1 => A1);");
942 Write_Statement_Buffer
;
945 Write_Statement_Buffer
;
947 for A
in ALIs
.First
.. ALIs
.Last
loop
948 if ALIs
.Table
(A
).Unit_Exception_Table
then
949 Get_Decoded_Name_String_With_Brackets
950 (Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
951 Set_Casing
(Mixed_Case
);
953 Set_String
(Name_Buffer
(1 .. Name_Len
- 2));
954 Set_String
("'UET_Address");
962 Write_Statement_Buffer
;
968 Set_String
(" EA : aliased constant array (1 .. ");
969 Set_Int
(Num_Elab_Calls
+ 2);
970 Set_String
(") of System.Address := (");
971 Write_Statement_Buffer
;
972 WBI
(" " & Ada_Init_Name
.all & "'Code_Address,");
974 -- If compiling for the JVM, we directly reference Adafinal because
975 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
977 if Hostparm
.Java_VM
then
978 Set_String
(" System.Standard_Library.Adafinal'Code_Address");
980 Set_String
(" Do_Finalize'Code_Address");
983 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
984 Get_Decoded_Name_String_With_Brackets
985 (Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
987 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
992 Write_Statement_Buffer
;
995 if Name_Buffer
(Name_Len
) = 's' then
996 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
997 "'elab_spec'code_address";
999 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 21) :=
1000 "'elab_body'code_address";
1003 Name_Len
:= Name_Len
+ 21;
1004 Set_Casing
(Units
.Table
(Elab_Order
.Table
(E
)).Icasing
);
1010 Write_Statement_Buffer
;
1015 Set_String
(" SDP_Table_Build (ST'Address, ");
1017 Set_String
(", EA'Address, ");
1018 Set_Int
(Num_Elab_Calls
+ 2);
1020 Write_Statement_Buffer
;
1021 end Gen_Exception_Table_Ada
;
1023 ---------------------------
1024 -- Gen_Exception_Table_C --
1025 ---------------------------
1027 procedure Gen_Exception_Table_C
is
1032 if not Zero_Cost_Exceptions_Specified
then
1036 -- The code we generate looks like
1038 -- extern void *__gnat_unitname1__SDP;
1039 -- extern void *__gnat_unitname2__SDP;
1042 -- void **st[nnn] = {
1043 -- &__gnat_unitname1__SDP,
1044 -- &__gnat_unitname2__SDP,
1046 -- &__gnat_unitnamen__SDP};
1048 -- extern void unitname1__elabb ();
1049 -- extern void unitname2__elabb ();
1052 -- void (*ea[eee]) () = {
1055 -- unitname1___elab[b,s],
1056 -- unitname2___elab[b,s],
1058 -- unitnamen___elab[b,s]};
1060 -- __gnat_SDP_Table_Build (&st, nnn, &ea, eee);
1063 for A
in ALIs
.First
.. ALIs
.Last
loop
1064 if ALIs
.Table
(A
).Unit_Exception_Table
then
1067 Set_String
(" extern void *__gnat_");
1068 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1070 Set_String
("__SDP");
1072 Write_Statement_Buffer
;
1078 -- Happens with "gnatmake -a -f -gnatL ..."
1085 Set_String
(" void **st[");
1087 Set_String
("] = {");
1088 Write_Statement_Buffer
;
1091 for A
in ALIs
.First
.. ALIs
.Last
loop
1092 if ALIs
.Table
(A
).Unit_Exception_Table
then
1095 Set_String
(" &__gnat_");
1096 Get_Name_String
(Units
.Table
(ALIs
.Table
(A
).First_Unit
).Uname
);
1098 Set_String
("__SDP");
1106 Write_Statement_Buffer
;
1111 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1112 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1114 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1118 Set_String
(" extern void ");
1120 Set_String
("___elab");
1121 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1122 Set_String
(" ();");
1123 Write_Statement_Buffer
;
1128 Set_String
(" void (*ea[");
1129 Set_Int
(Num_Elab_Calls
+ 2);
1130 Set_String
("]) () = {");
1131 Write_Statement_Buffer
;
1133 WBI
(" " & Ada_Init_Name
.all & ",");
1134 Set_String
(" system__standard_library__adafinal");
1136 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1137 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1139 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1144 Write_Statement_Buffer
;
1147 Set_String
("___elab");
1148 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1153 Write_Statement_Buffer
;
1157 Set_String
(" __gnat_SDP_Table_Build (&st, ");
1159 Set_String
(", ea, ");
1160 Set_Int
(Num_Elab_Calls
+ 2);
1162 Write_Statement_Buffer
;
1163 end Gen_Exception_Table_C
;
1169 procedure Gen_Main_Ada
is
1170 Target
: constant String_Ptr
:= Target_Name
;
1171 VxWorks_Target
: constant Boolean :=
1172 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/";
1176 Set_String
(" function ");
1177 Set_String
(Get_Main_Name
);
1179 if VxWorks_Target
then
1180 Set_String
(" return Integer is");
1181 Write_Statement_Buffer
;
1184 Write_Statement_Buffer
;
1185 WBI
(" (argc : Integer;");
1186 WBI
(" argv : System.Address;");
1187 WBI
(" envp : System.Address)");
1188 WBI
(" return Integer");
1192 -- Initialize and Finalize are not used in No_Run_Time mode
1194 if not No_Run_Time_Specified
then
1195 WBI
(" procedure initialize;");
1196 WBI
(" pragma Import (C, initialize, ""__gnat_initialize"");");
1198 WBI
(" procedure finalize;");
1199 WBI
(" pragma Import (C, finalize, ""__gnat_finalize"");");
1203 -- Deal with declarations for main program case
1205 if not No_Main_Subprogram
then
1207 -- To call the main program, we declare it using a pragma Import
1208 -- Ada with the right link name.
1210 -- It might seem more obvious to "with" the main program, and call
1211 -- it in the normal Ada manner. We do not do this for three reasons:
1213 -- 1. It is more efficient not to recompile the main program
1214 -- 2. We are not entitled to assume the source is accessible
1215 -- 3. We don't know what options to use to compile it
1217 -- It is really reason 3 that is most critical (indeed we used
1218 -- to generate the "with", but several regression tests failed).
1222 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1223 WBI
(" Result : Integer;");
1225 WBI
(" function Ada_Main_Program return Integer;");
1228 WBI
(" procedure Ada_Main_Program;");
1231 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1232 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1233 Set_Main_Program_Name
;
1234 Set_String
(""");");
1236 Write_Statement_Buffer
;
1242 -- On VxWorks, there are no command line arguments
1244 if VxWorks_Target
then
1245 WBI
(" gnat_argc := 0;");
1246 WBI
(" gnat_argv := System.Null_Address;");
1247 WBI
(" gnat_envp := System.Null_Address;");
1249 -- Normal case of command line arguments present
1252 WBI
(" gnat_argc := argc;");
1253 WBI
(" gnat_argv := argv;");
1254 WBI
(" gnat_envp := envp;");
1258 if not No_Run_Time_Specified
then
1259 WBI
(" Initialize;");
1262 WBI
(" " & Ada_Init_Name
.all & ";");
1264 if not No_Main_Subprogram
then
1265 WBI
(" Break_Start;");
1267 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1268 WBI
(" Ada_Main_Program;");
1270 WBI
(" Result := Ada_Main_Program;");
1274 -- Adafinal is only called if we have a run time
1276 if not No_Run_Time_Specified
then
1278 -- If compiling for the JVM, we directly call Adafinal because
1279 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1281 if Hostparm
.Java_VM
then
1282 WBI
(" System.Standard_Library.Adafinal;");
1284 WBI
(" Do_Finalize;");
1288 -- Finalize is only called if we have a run time
1290 if not No_Run_Time_Specified
then
1296 if No_Main_Subprogram
1297 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1299 WBI
(" return (gnat_exit_status);");
1301 WBI
(" return (Result);");
1311 procedure Gen_Main_C
is
1312 Target
: constant String_Ptr
:= Target_Name
;
1313 VxWorks_Target
: constant Boolean :=
1314 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/";
1317 Set_String
("int ");
1318 Set_String
(Get_Main_Name
);
1320 -- On VxWorks, there are no command line arguments
1322 if VxWorks_Target
then
1325 -- Normal case with command line arguments present
1328 Set_String
(" (argc, argv, envp)");
1331 Write_Statement_Buffer
;
1333 -- VxWorks doesn't have the notion of argc/argv
1335 if VxWorks_Target
then
1337 WBI
(" int result;");
1338 WBI
(" gnat_argc = 0;");
1339 WBI
(" gnat_argv = 0;");
1340 WBI
(" gnat_envp = 0;");
1342 -- Normal case of arguments present
1346 WBI
(" char **argv;");
1347 WBI
(" char **envp;");
1350 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1351 WBI
(" int result;");
1354 WBI
(" gnat_argc = argc;");
1355 WBI
(" gnat_argv = argv;");
1356 WBI
(" gnat_envp = envp;");
1360 -- The __gnat_initialize routine is used only if we have a run-time
1362 if not No_Run_Time_Specified
then
1364 (" __gnat_initialize ();");
1367 WBI
(" " & Ada_Init_Name
.all & " ();");
1369 if not No_Main_Subprogram
then
1371 WBI
(" __gnat_break_start ();");
1374 -- Output main program name
1376 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1378 -- Main program is procedure case
1380 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1382 Set_Main_Program_Name
;
1383 Set_String
(" ();");
1384 Write_Statement_Buffer
;
1386 -- Main program is function case
1388 else -- ALIs.Table (ALIs_First).Main_Program = Func
1389 Set_String
(" result = ");
1390 Set_Main_Program_Name
;
1391 Set_String
(" ();");
1392 Write_Statement_Buffer
;
1397 -- Adafinal is called only when we have a run-time
1399 if not No_Run_Time_Specified
then
1401 WBI
(" system__standard_library__adafinal ();");
1404 -- The finalize routine is used only if we have a run-time
1406 if not No_Run_Time_Specified
then
1407 WBI
(" __gnat_finalize ();");
1410 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1412 if Hostparm
.OpenVMS
then
1414 -- VMS must use the Posix exit routine in order to get an
1415 -- Unix compatible exit status.
1417 WBI
(" __posix_exit (result);");
1420 WBI
(" exit (result);");
1425 if Hostparm
.OpenVMS
then
1426 -- VMS must use the Posix exit routine in order to get an
1427 -- Unix compatible exit status.
1428 WBI
(" __posix_exit (gnat_exit_status);");
1430 WBI
(" exit (gnat_exit_status);");
1437 ------------------------------
1438 -- Gen_Object_Files_Options --
1439 ------------------------------
1441 procedure Gen_Object_Files_Options
is
1444 procedure Write_Linker_Option
;
1445 -- Write binder info linker option.
1447 -------------------------
1448 -- Write_Linker_Option --
1449 -------------------------
1451 procedure Write_Linker_Option
is
1456 -- Loop through string, breaking at null's
1459 while Start
< Name_Len
loop
1461 -- Find null ending this section
1464 while Name_Buffer
(Stop
) /= ASCII
.NUL
1465 and then Stop
<= Name_Len
loop
1469 -- Process section if non-null
1471 if Stop
> Start
then
1472 if Output_Linker_Option_List
then
1473 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1477 (" -- ", "", Name_Buffer
(Start
.. Stop
- 1));
1482 end Write_Linker_Option
;
1484 -- Start of processing for Gen_Object_Files_Options
1488 Write_Info_Ada_C
("--", "/*", " BEGIN Object file/option list");
1490 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1492 -- If not spec that has an associated body, then generate a
1493 -- comment giving the name of the corresponding object file.
1495 if Units
.Table
(Elab_Order
.Table
(E
)).Utype
/= Is_Spec
then
1498 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Ofile_Full_Name
);
1500 -- If the presence of an object file is necessary or if it
1501 -- exists, then use it.
1503 if not Hostparm
.Exclude_Missing_Objects
1505 GNAT
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
1507 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1508 if Output_Object_List
then
1509 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1513 -- Don't link with the shared library on VMS if an internal
1514 -- filename object is seen. Multiply defined symbols will
1518 and then Is_Internal_File_Name
1520 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Sfile
)
1522 Opt
.Shared_Libgnat
:= False;
1529 -- Add a "-Ldir" for each directory in the object path. We skip this
1530 -- in No_Run_Time mode, where we want more precise control of exactly
1531 -- what goes into the resulting object file
1533 if not No_Run_Time_Specified
then
1534 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
1536 Dir
: String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
1540 Add_Str_To_Name_Buffer
("-L");
1541 Add_Str_To_Name_Buffer
(Dir
.all);
1542 Write_Linker_Option
;
1547 -- Sort linker options
1549 Sort
(Linker_Options
.Last
, Move_Linker_Option
'Access,
1550 Lt_Linker_Option
'Access);
1552 -- Write user linker options
1554 Lgnat
:= Linker_Options
.Last
+ 1;
1556 for J
in 1 .. Linker_Options
.Last
loop
1557 if not Linker_Options
.Table
(J
).Internal_File
then
1558 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1559 Write_Linker_Option
;
1566 if not (No_Run_Time_Specified
or else Opt
.No_Stdlib
) then
1570 if Opt
.Shared_Libgnat
then
1571 Add_Str_To_Name_Buffer
("-shared");
1573 Add_Str_To_Name_Buffer
("-static");
1576 -- Write directly to avoid -K output.
1578 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1580 if With_DECGNAT
then
1582 Add_Str_To_Name_Buffer
("-ldecgnat");
1583 Write_Linker_Option
;
1588 Add_Str_To_Name_Buffer
("-lgnarl");
1589 Write_Linker_Option
;
1593 Add_Str_To_Name_Buffer
("-lgnat");
1594 Write_Linker_Option
;
1598 -- Write internal linker options
1600 for J
in Lgnat
.. Linker_Options
.Last
loop
1601 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1602 Write_Linker_Option
;
1605 if Ada_Bind_File
then
1606 WBI
("-- END Object file/option list ");
1608 WBI
(" END Object file/option list */");
1611 end Gen_Object_Files_Options
;
1613 ---------------------
1614 -- Gen_Output_File --
1615 ---------------------
1617 procedure Gen_Output_File
(Filename
: String) is
1619 -- Start of processing for Gen_Output_File
1622 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1623 -- JGNAT only supports Ada code, and the main program is already
1624 -- generated by the compiler.
1626 if Hostparm
.Java_VM
then
1627 Ada_Bind_File
:= True;
1628 Bind_Main_Program
:= False;
1631 -- Override time slice value if -T switch is set
1633 if Time_Slice_Set
then
1634 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
1637 -- Count number of elaboration calls
1639 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1640 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1643 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
1647 -- Generate output file in appropriate language
1649 if Ada_Bind_File
then
1650 Gen_Output_File_Ada
(Filename
);
1652 Gen_Output_File_C
(Filename
);
1655 end Gen_Output_File
;
1657 -------------------------
1658 -- Gen_Output_File_Ada --
1659 -------------------------
1661 procedure Gen_Output_File_Ada
(Filename
: String) is
1664 -- Name of generated bind file (spec)
1667 -- Name of generated bind file (body)
1669 Ada_Main
: constant String := Get_Ada_Main_Name
;
1670 -- Name to be used for generated Ada main program. See the body of
1671 -- function Get_Ada_Main_Name for details on the form of the name.
1673 Target
: constant String_Ptr
:= Target_Name
;
1674 VxWorks_Target
: constant Boolean :=
1675 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/";
1678 -- Create spec first
1680 Create_Binder_Output
(Filename
, 's', Bfiles
);
1682 if No_Run_Time_Specified
then
1683 WBI
("pragma No_Run_Time;");
1686 -- Generate with of System so we can reference System.Address, note
1687 -- that such a reference is safe even in No_Run_Time mode, since we
1688 -- do not need any run-time code for such a reference, and we output
1689 -- a pragma No_Run_Time for this compilation above.
1691 WBI
("with System;");
1693 -- Generate with of System.Initialize_Scalars if active
1695 if Initialize_Scalars_Used
then
1696 WBI
("with System.Scalar_Values;");
1699 Resolve_Binder_Options
;
1701 if not No_Run_Time_Specified
then
1703 -- Usually, adafinal is called using a pragma Import C. Since
1704 -- Import C doesn't have the same semantics for JGNAT, we use
1707 if Hostparm
.Java_VM
then
1708 WBI
("with System.Standard_Library;");
1712 WBI
("package " & Ada_Main
& " is");
1714 -- Main program case
1716 if Bind_Main_Program
then
1718 -- Generate argc/argv stuff
1721 WBI
(" gnat_argc : Integer;");
1722 WBI
(" gnat_argv : System.Address;");
1723 WBI
(" gnat_envp : System.Address;");
1725 -- If we have a run time present, these variables are in the
1726 -- runtime data area for easy access from the runtime
1728 if not No_Run_Time_Specified
then
1730 WBI
(" pragma Import (C, gnat_argc);");
1731 WBI
(" pragma Import (C, gnat_argv);");
1732 WBI
(" pragma Import (C, gnat_envp);");
1735 -- Define exit status. Again in normal mode, this is in the
1736 -- run-time library, and is initialized there, but in the no
1737 -- run time case, the variable is here and initialized here.
1741 if No_Run_Time_Specified
then
1742 WBI
(" gnat_exit_status : Integer := 0;");
1744 WBI
(" gnat_exit_status : Integer;");
1745 WBI
(" pragma Import (C, gnat_exit_status);");
1749 -- Generate the GNAT_Version and Ada_Main_Program_name info only for
1750 -- the main program. Otherwise, it can lead under some circumstances
1751 -- to a symbol duplication during the link (for instance when a
1752 -- C program uses 2 Ada libraries)
1754 if Bind_Main_Program
then
1756 WBI
(" GNAT_Version : constant String :=");
1757 WBI
(" ""GNAT Version: " &
1758 Gnat_Version_String
& """;");
1759 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
1762 Set_String
(" Ada_Main_Program_Name : constant String := """);
1763 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1764 Set_Main_Program_Name
;
1765 Set_String
(""" & Ascii.NUL;");
1766 Write_Statement_Buffer
;
1769 (" pragma Export (C, Ada_Main_Program_Name, " &
1770 """__gnat_ada_main_program_name"");");
1773 -- No need to generate a finalization routine if there is no
1774 -- runtime, since there is nothing to do in this case.
1776 if not No_Run_Time_Specified
then
1778 WBI
(" procedure " & Ada_Final_Name
.all & ";");
1779 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
1780 Ada_Final_Name
.all & """);");
1784 WBI
(" procedure " & Ada_Init_Name
.all & ";");
1785 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
1786 Ada_Init_Name
.all & """);");
1788 if Bind_Main_Program
then
1790 -- If we have a run time, then Break_Start is defined there, but
1791 -- if there is no run-time, Break_Start is defined in this file.
1794 WBI
(" procedure Break_Start;");
1796 if No_Run_Time_Specified
then
1797 WBI
(" pragma Export (C, Break_Start, ""__gnat_break_start"");");
1799 WBI
(" pragma Import (C, Break_Start, ""__gnat_break_start"");");
1803 WBI
(" function " & Get_Main_Name
);
1805 -- Generate argument list (except on VxWorks, where none is present)
1807 if not VxWorks_Target
then
1808 WBI
(" (argc : Integer;");
1809 WBI
(" argv : System.Address;");
1810 WBI
(" envp : System.Address)");
1813 WBI
(" return Integer;");
1814 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
1815 Get_Main_Name
& """);");
1818 if Initialize_Scalars_Used
then
1828 WBI
("end " & Ada_Main
& ";");
1829 Close_Binder_Output
;
1831 -- Prepare to write body
1833 Create_Binder_Output
(Filename
, 'b', Bfileb
);
1835 -- Output Source_File_Name pragmas which look like
1837 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
1838 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
1840 -- where sss/bbb are the spec/body file names respectively
1842 Get_Name_String
(Bfiles
);
1843 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1845 WBI
("pragma Source_File_Name (" &
1847 ", Spec_File_Name => """ &
1848 Name_Buffer
(1 .. Name_Len
+ 3));
1850 Get_Name_String
(Bfileb
);
1851 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
1853 WBI
("pragma Source_File_Name (" &
1855 ", Body_File_Name => """ &
1856 Name_Buffer
(1 .. Name_Len
+ 3));
1859 WBI
("package body " & Ada_Main
& " is");
1861 -- Import the finalization procedure only if there is a runtime.
1863 if not No_Run_Time_Specified
then
1865 -- In the Java case, pragma Import C cannot be used, so the
1866 -- standard Ada constructs will be used instead.
1868 if not Hostparm
.Java_VM
then
1870 WBI
(" procedure Do_Finalize;");
1872 (" pragma Import (C, Do_Finalize, " &
1873 """system__standard_library__adafinal"");");
1880 -- No need to generate a finalization routine if there is no
1881 -- runtime, since there is nothing to do in this case.
1883 if not No_Run_Time_Specified
then
1887 if Bind_Main_Program
then
1889 -- In No_Run_Time mode, generate dummy body for Break_Start
1891 if No_Run_Time_Specified
then
1893 WBI
(" procedure Break_Start is");
1902 -- Output object file list and the Ada body is complete
1904 Gen_Object_Files_Options
;
1907 WBI
("end " & Ada_Main
& ";");
1909 Close_Binder_Output
;
1910 end Gen_Output_File_Ada
;
1912 -----------------------
1913 -- Gen_Output_File_C --
1914 -----------------------
1916 procedure Gen_Output_File_C
(Filename
: String) is
1919 -- Name of generated bind file
1922 Create_Binder_Output
(Filename
, 'c', Bfile
);
1924 Resolve_Binder_Options
;
1926 WBI
("#ifdef __STDC__");
1927 WBI
("#define PARAMS(paramlist) paramlist");
1929 WBI
("#define PARAMS(paramlist) ()");
1933 WBI
("extern void __gnat_set_globals ");
1934 WBI
(" PARAMS ((int, int, int, int, int, int, ");
1935 WBI
(" void (*) PARAMS ((void)), int, int));");
1936 WBI
("extern void " & Ada_Final_Name
.all & " PARAMS ((void));");
1937 WBI
("extern void " & Ada_Init_Name
.all & " PARAMS ((void));");
1939 WBI
("extern void system__standard_library__adafinal PARAMS ((void));");
1941 if not No_Main_Subprogram
then
1942 WBI
("extern int main PARAMS ((int, char **, char **));");
1943 if Hostparm
.OpenVMS
then
1944 WBI
("extern void __posix_exit PARAMS ((int));");
1946 WBI
("extern void exit PARAMS ((int));");
1949 WBI
("extern void __gnat_break_start PARAMS ((void));");
1950 Set_String
("extern ");
1952 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1953 Set_String
("void ");
1955 Set_String
("int ");
1958 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1959 Set_Main_Program_Name
;
1960 Set_String
(" PARAMS ((void));");
1961 Write_Statement_Buffer
;
1964 if not No_Run_Time_Specified
then
1965 WBI
("extern void __gnat_initialize PARAMS ((void));");
1966 WBI
("extern void __gnat_finalize PARAMS ((void));");
1967 WBI
("extern void __gnat_install_handler PARAMS ((void));");
1974 -- Imported variable used to track elaboration/finalization phase.
1975 -- Used only when we have a runtime.
1977 if not No_Run_Time_Specified
then
1978 WBI
("extern int __gnat_handler_installed;");
1982 -- Write argv/argc stuff if main program case
1984 if Bind_Main_Program
then
1986 -- In the normal case, these are in the runtime library
1988 if not No_Run_Time_Specified
then
1989 WBI
("extern int gnat_argc;");
1990 WBI
("extern char **gnat_argv;");
1991 WBI
("extern char **gnat_envp;");
1992 WBI
("extern int gnat_exit_status;");
1994 -- In the No_Run_Time case, they are right in the binder file
1995 -- and we initialize gnat_exit_status in the declaration.
1998 WBI
("int gnat_argc;");
1999 WBI
("char **gnat_argv;");
2000 WBI
("char **gnat_envp;");
2001 WBI
("int gnat_exit_status = 0;");
2007 -- In no run-time mode, the __gnat_break_start routine (for the
2008 -- debugger to get initial control) is defined in this file.
2010 if No_Run_Time_Specified
then
2012 WBI
("void __gnat_break_start () {}");
2015 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2016 -- only for the main program. Otherwise, it can lead under some
2017 -- circumstances to a symbol duplication during the link (for instance
2018 -- when a C program uses 2 Ada libraries)
2020 if Bind_Main_Program
then
2022 WBI
("char __gnat_version[] = ""GNAT Version: " &
2023 Gnat_Version_String
& """;");
2025 Set_String
("char __gnat_ada_main_program_name[] = """);
2026 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2027 Set_Main_Program_Name
;
2029 Write_Statement_Buffer
;
2032 -- Generate the adafinal routine. In no runtime mode, this is
2033 -- not needed, since there is no finalization to do.
2035 if not No_Run_Time_Specified
then
2041 -- Main is only present for Ada main case
2043 if Bind_Main_Program
then
2047 -- Scalar values, versions and object files needed in both cases
2049 if Initialize_Scalars_Used
then
2055 Gen_Object_Files_Options
;
2057 -- C binder output is complete
2059 Close_Binder_Output
;
2060 end Gen_Output_File_C
;
2062 -----------------------
2063 -- Gen_Scalar_Values --
2064 -----------------------
2066 procedure Gen_Scalar_Values
is
2068 -- Strings to hold hex values of initialization constants. Note that
2069 -- we store these strings in big endian order, but they are actually
2070 -- used to initialize integer values, so the actual generated data
2071 -- will automaticaly have the right endianess.
2073 IS_Is1
: String (1 .. 2);
2074 IS_Is2
: String (1 .. 4);
2075 IS_Is4
: String (1 .. 8);
2076 IS_Is8
: String (1 .. 16);
2077 IS_Iu1
: String (1 .. 2);
2078 IS_Iu2
: String (1 .. 4);
2079 IS_Iu4
: String (1 .. 8);
2080 IS_Iu8
: String (1 .. 16);
2081 IS_Isf
: String (1 .. 8);
2082 IS_Ifl
: String (1 .. 8);
2083 IS_Ilf
: String (1 .. 16);
2085 -- The string for Long_Long_Float is special. This is used only on the
2086 -- ia32 with 80-bit extended float (stored in 96 bits by gcc). The
2087 -- value here is represented little-endian, since that's the only way
2088 -- it is ever generated (this is not used on big-endian machines.
2090 IS_Ill
: String (1 .. 24);
2093 -- -Sin (invalid values)
2095 if Opt
.Initialize_Scalars_Mode
= 'I' then
2098 IS_Is4
:= "80000000";
2099 IS_Is8
:= "8000000000000000";
2102 IS_Iu4
:= "FFFFFFFF";
2103 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2107 IS_Ill
:= "00000000000000C0FFFF0000";
2109 -- -Slo (low values)
2111 elsif Opt
.Initialize_Scalars_Mode
= 'L' then
2114 IS_Is4
:= "80000000";
2115 IS_Is8
:= "8000000000000000";
2118 IS_Iu4
:= "00000000";
2119 IS_Iu8
:= "0000000000000000";
2120 IS_Isf
:= "FF800000";
2122 IS_Ilf
:= "FFF0000000000000";
2123 IS_Ill
:= "0000000000000080FFFF0000";
2125 -- -Shi (high values)
2127 elsif Opt
.Initialize_Scalars_Mode
= 'H' then
2130 IS_Is4
:= "7FFFFFFF";
2131 IS_Is8
:= "7FFFFFFFFFFFFFFF";
2134 IS_Iu4
:= "FFFFFFFF";
2135 IS_Iu8
:= "FFFFFFFFFFFFFFFF";
2136 IS_Isf
:= "7F800000";
2138 IS_Ilf
:= "7FF0000000000000";
2139 IS_Ill
:= "0000000000000080FF7F0000";
2143 else pragma Assert
(Opt
.Initialize_Scalars_Mode
= 'X');
2144 IS_Is1
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2145 IS_Is2
(1 .. 2) := Opt
.Initialize_Scalars_Val
;
2146 IS_Is2
(3 .. 4) := Opt
.Initialize_Scalars_Val
;
2148 for J
in 1 .. 4 loop
2149 IS_Is4
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2152 for J
in 1 .. 8 loop
2153 IS_Is8
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2165 for J
in 1 .. 12 loop
2166 IS_Ill
(2 * J
- 1 .. 2 * J
) := Opt
.Initialize_Scalars_Val
;
2170 -- Generate output, Ada case
2172 if Ada_Bind_File
then
2175 Set_String
(" IS_Is1 : constant System.Scalar_Values.Byte1 := 16#");
2176 Set_String
(IS_Is1
);
2177 Write_Statement_Buffer
("#;");
2179 Set_String
(" IS_Is2 : constant System.Scalar_Values.Byte2 := 16#");
2180 Set_String
(IS_Is2
);
2181 Write_Statement_Buffer
("#;");
2183 Set_String
(" IS_Is4 : constant System.Scalar_Values.Byte4 := 16#");
2184 Set_String
(IS_Is4
);
2185 Write_Statement_Buffer
("#;");
2187 Set_String
(" IS_Is8 : constant System.Scalar_Values.Byte8 := 16#");
2188 Set_String
(IS_Is8
);
2189 Write_Statement_Buffer
("#;");
2191 Set_String
(" IS_Iu1 : constant System.Scalar_Values.Byte1 := 16#");
2192 Set_String
(IS_Iu1
);
2193 Write_Statement_Buffer
("#;");
2195 Set_String
(" IS_Iu2 : constant System.Scalar_Values.Byte2 := 16#");
2196 Set_String
(IS_Iu2
);
2197 Write_Statement_Buffer
("#;");
2199 Set_String
(" IS_Iu4 : constant System.Scalar_Values.Byte4 := 16#");
2200 Set_String
(IS_Iu4
);
2201 Write_Statement_Buffer
("#;");
2203 Set_String
(" IS_Iu8 : constant System.Scalar_Values.Byte8 := 16#");
2204 Set_String
(IS_Iu8
);
2205 Write_Statement_Buffer
("#;");
2207 Set_String
(" IS_Isf : constant System.Scalar_Values.Byte4 := 16#");
2208 Set_String
(IS_Isf
);
2209 Write_Statement_Buffer
("#;");
2211 Set_String
(" IS_Ifl : constant System.Scalar_Values.Byte4 := 16#");
2212 Set_String
(IS_Ifl
);
2213 Write_Statement_Buffer
("#;");
2215 Set_String
(" IS_Ilf : constant System.Scalar_Values.Byte8 := 16#");
2216 Set_String
(IS_Ilf
);
2217 Write_Statement_Buffer
("#;");
2219 -- Special case of Long_Long_Float. This is a 10-byte value used
2220 -- only on the x86. We could omit it for other architectures, but
2221 -- we don't easily have that kind of target specialization in the
2222 -- binder, and it's only 10 bytes, and only if -Sxx is used. Note
2223 -- that for architectures where Long_Long_Float is the same as
2224 -- Long_Float, the expander uses the Long_Float constant for the
2225 -- initializations of Long_Long_Float values.
2227 WBI
(" IS_Ill : constant array (1 .. 12) of");
2228 WBI
(" System.Scalar_Values.Byte1 := (");
2231 for J
in 1 .. 6 loop
2232 Set_String
(" 16#");
2233 Set_Char
(IS_Ill
(2 * J
- 1));
2234 Set_Char
(IS_Ill
(2 * J
));
2238 Write_Statement_Buffer
;
2241 for J
in 7 .. 12 loop
2242 Set_String
(" 16#");
2243 Set_Char
(IS_Ill
(2 * J
- 1));
2244 Set_Char
(IS_Ill
(2 * J
));
2253 Write_Statement_Buffer
;
2255 -- Output export statements to export to System.Scalar_Values
2259 WBI
(" pragma Export (Ada, IS_Is1, ""__gnat_Is1"");");
2260 WBI
(" pragma Export (Ada, IS_Is2, ""__gnat_Is2"");");
2261 WBI
(" pragma Export (Ada, IS_Is4, ""__gnat_Is4"");");
2262 WBI
(" pragma Export (Ada, IS_Is8, ""__gnat_Is8"");");
2263 WBI
(" pragma Export (Ada, IS_Iu1, ""__gnat_Iu1"");");
2264 WBI
(" pragma Export (Ada, IS_Iu2, ""__gnat_Iu2"");");
2265 WBI
(" pragma Export (Ada, IS_Iu4, ""__gnat_Iu4"");");
2266 WBI
(" pragma Export (Ada, IS_Iu8, ""__gnat_Iu8"");");
2267 WBI
(" pragma Export (Ada, IS_Isf, ""__gnat_Isf"");");
2268 WBI
(" pragma Export (Ada, IS_Ifl, ""__gnat_Ifl"");");
2269 WBI
(" pragma Export (Ada, IS_Ilf, ""__gnat_Ilf"");");
2270 WBI
(" pragma Export (Ada, IS_Ill, ""__gnat_Ill"");");
2272 -- Generate output C case
2275 -- The lines we generate in this case are of the form
2276 -- typ __gnat_I?? = 0x??;
2277 -- where typ is appropriate to the length
2281 Set_String
("unsigned char __gnat_Is1 = 0x");
2282 Set_String
(IS_Is1
);
2283 Write_Statement_Buffer
(";");
2285 Set_String
("unsigned short __gnat_Is2 = 0x");
2286 Set_String
(IS_Is2
);
2287 Write_Statement_Buffer
(";");
2289 Set_String
("unsigned __gnat_Is4 = 0x");
2290 Set_String
(IS_Is4
);
2291 Write_Statement_Buffer
(";");
2293 Set_String
("long long unsigned __gnat_Is8 = 0x");
2294 Set_String
(IS_Is8
);
2295 Write_Statement_Buffer
("LL;");
2297 Set_String
("unsigned char __gnat_Iu1 = 0x");
2298 Set_String
(IS_Is1
);
2299 Write_Statement_Buffer
(";");
2301 Set_String
("unsigned short __gnat_Iu2 = 0x");
2302 Set_String
(IS_Is2
);
2303 Write_Statement_Buffer
(";");
2305 Set_String
("unsigned __gnat_Iu4 = 0x");
2306 Set_String
(IS_Is4
);
2307 Write_Statement_Buffer
(";");
2309 Set_String
("long long unsigned __gnat_Iu8 = 0x");
2310 Set_String
(IS_Is8
);
2311 Write_Statement_Buffer
("LL;");
2313 Set_String
("unsigned __gnat_Isf = 0x");
2314 Set_String
(IS_Isf
);
2315 Write_Statement_Buffer
(";");
2317 Set_String
("unsigned __gnat_Ifl = 0x");
2318 Set_String
(IS_Ifl
);
2319 Write_Statement_Buffer
(";");
2321 Set_String
("long long unsigned __gnat_Ilf = 0x");
2322 Set_String
(IS_Ilf
);
2323 Write_Statement_Buffer
("LL;");
2325 -- For Long_Long_Float, we generate
2326 -- char __gnat_Ill[12] = {0x??, 0x??, 0x??, 0x??, 0x??, 0x??,
2327 -- 0x??, 0x??, 0x??, 0x??, 0x??, 0x??);
2329 Set_String
("unsigned char __gnat_Ill[12] = {");
2331 for J
in 1 .. 6 loop
2333 Set_Char
(IS_Ill
(2 * J
- 1));
2334 Set_Char
(IS_Ill
(2 * J
));
2338 Write_Statement_Buffer
;
2341 for J
in 7 .. 12 loop
2343 Set_Char
(IS_Ill
(2 * J
- 1));
2344 Set_Char
(IS_Ill
(2 * J
));
2353 Write_Statement_Buffer
;
2355 end Gen_Scalar_Values
;
2357 ----------------------
2358 -- Gen_Versions_Ada --
2359 ----------------------
2361 -- This routine generates two sets of lines. The first set has the form:
2363 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2365 -- The second set has the form
2367 -- pragma Export (C, unnnnn, unam);
2369 -- for each unit, where unam is the unit name suffixed by either B or
2370 -- S for body or spec, with dots replaced by double underscores, and
2371 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2373 procedure Gen_Versions_Ada
is
2374 Ubuf
: String (1 .. 6) := "u00000";
2376 procedure Increment_Ubuf
;
2377 -- Little procedure to increment the serial number
2379 procedure Increment_Ubuf
is
2381 for J
in reverse Ubuf
'Range loop
2382 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2383 exit when Ubuf
(J
) <= '9';
2388 -- Start of processing for Gen_Versions_Ada
2391 if Bind_For_Library
then
2393 -- When building libraries, the version number of each unit can
2394 -- not be computed, since the binder does not know the full list
2395 -- of units. Therefore, the 'Version and 'Body_Version
2396 -- attributes can not supported in this case.
2403 WBI
(" type Version_32 is mod 2 ** 32;");
2404 for U
in Units
.First
.. Units
.Last
loop
2406 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2407 Units
.Table
(U
).Version
& "#;");
2413 for U
in Units
.First
.. Units
.Last
loop
2415 Set_String
(" pragma Export (C, ");
2417 Set_String
(", """);
2419 Get_Name_String
(Units
.Table
(U
).Uname
);
2421 for K
in 1 .. Name_Len
loop
2422 if Name_Buffer
(K
) = '.' then
2426 elsif Name_Buffer
(K
) = '%' then
2430 Set_Char
(Name_Buffer
(K
));
2434 if Name_Buffer
(Name_Len
) = 's' then
2440 Set_String
(""");");
2441 Write_Statement_Buffer
;
2444 end Gen_Versions_Ada
;
2446 --------------------
2447 -- Gen_Versions_C --
2448 --------------------
2450 -- This routine generates a line of the form:
2452 -- unsigned unam = 0xhhhhhhhh;
2454 -- for each unit, where unam is the unit name suffixed by either B or
2455 -- S for body or spec, with dots replaced by double underscores.
2457 procedure Gen_Versions_C
is
2459 if Bind_For_Library
then
2461 -- When building libraries, the version number of each unit can
2462 -- not be computed, since the binder does not know the full list
2463 -- of units. Therefore, the 'Version and 'Body_Version
2464 -- attributes can not supported.
2469 for U
in Units
.First
.. Units
.Last
loop
2470 Set_String
("unsigned ");
2472 Get_Name_String
(Units
.Table
(U
).Uname
);
2474 for K
in 1 .. Name_Len
loop
2475 if Name_Buffer
(K
) = '.' then
2478 elsif Name_Buffer
(K
) = '%' then
2482 Set_Char
(Name_Buffer
(K
));
2486 if Name_Buffer
(Name_Len
) = 's' then
2492 Set_String
(" = 0x");
2493 Set_String
(Units
.Table
(U
).Version
);
2495 Write_Statement_Buffer
;
2500 -----------------------
2501 -- Get_Ada_Main_Name --
2502 -----------------------
2504 function Get_Ada_Main_Name
return String is
2505 Suffix
: constant String := "_00";
2506 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
2507 Opt
.Ada_Main_Name
.all & Suffix
;
2511 -- The main program generated by JGNAT expects a package called
2512 -- ada_<main procedure>.
2514 if Hostparm
.Java_VM
then
2515 -- Get main program name
2517 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2521 return "ada_" & Name_Buffer
(1 .. Name_Len
- 2);
2524 -- This loop tries the following possibilities in order
2530 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2531 -- it is set to 'ada_main'.
2533 for J
in 0 .. 99 loop
2535 Nlen
:= Name
'Length - Suffix
'Length;
2537 Nlen
:= Name
'Length;
2538 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
2539 Name
(Name
'Last - 1) :=
2540 Character'Val (J
/ 10 + Character'Pos ('0'));
2543 for K
in ALIs
.First
.. ALIs
.Last
loop
2544 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
2546 -- Get unit name, removing %b or %e at end
2548 Get_Name_String
(Units
.Table
(L
).Uname
);
2549 Name_Len
:= Name_Len
- 2;
2551 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
2557 return Name
(1 .. Nlen
);
2563 -- If we fall through, just use a peculiar unlikely name
2565 return ("Qwertyuiop");
2566 end Get_Ada_Main_Name
;
2572 function Get_Main_Name
return String is
2573 Target
: constant String_Ptr
:= Target_Name
;
2574 VxWorks_Target
: constant Boolean :=
2575 Target
(Target
'Last - 7 .. Target
'Last) = "vxworks/";
2578 -- Explicit name given with -M switch
2580 if Bind_Alternate_Main_Name
then
2581 return Alternate_Main_Name
.all;
2583 -- Case of main program name to be used directly
2585 elsif VxWorks_Target
then
2587 -- Get main program name
2589 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2591 -- If this is a child name, return only the name of the child,
2592 -- since we can't have dots in a nested program name. Note that
2593 -- we do not include the %b at the end of the unit name.
2595 for J
in reverse 1 .. Name_Len
- 3 loop
2596 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
2597 return Name_Buffer
(J
.. Name_Len
- 2);
2601 raise Program_Error
; -- impossible exit
2603 -- Case where "main" is to be used as default
2610 ----------------------
2611 -- Lt_Linker_Option --
2612 ----------------------
2614 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean is
2616 if Linker_Options
.Table
(Op1
).Internal_File
2618 Linker_Options
.Table
(Op2
).Internal_File
2620 return Linker_Options
.Table
(Op1
).Internal_File
2622 Linker_Options
.Table
(Op2
).Internal_File
;
2624 if Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
2626 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
2628 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
2630 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
2633 return Linker_Options
.Table
(Op1
).Original_Pos
2635 Linker_Options
.Table
(Op2
).Original_Pos
;
2638 end Lt_Linker_Option
;
2640 ------------------------
2641 -- Move_Linker_Option --
2642 ------------------------
2644 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
2646 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
2647 end Move_Linker_Option
;
2649 ----------------------------
2650 -- Resolve_Binder_Options --
2651 ----------------------------
2653 procedure Resolve_Binder_Options
is
2655 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2656 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
2658 -- The procedure of looking for specific packages and setting
2659 -- flags is very wrong, but there isn't a good alternative at
2662 if Name_Buffer
(1 .. 19) = "system.os_interface" then
2666 if Hostparm
.OpenVMS
and then Name_Buffer
(1 .. 3) = "dec" then
2667 With_DECGNAT
:= True;
2670 end Resolve_Binder_Options
;
2676 procedure Set_Char
(C
: Character) is
2679 Statement_Buffer
(Last
) := C
;
2686 procedure Set_Int
(N
: Int
) is
2698 Statement_Buffer
(Last
) :=
2699 Character'Val (N
mod 10 + Character'Pos ('0'));
2703 ---------------------------
2704 -- Set_Main_Program_Name --
2705 ---------------------------
2707 procedure Set_Main_Program_Name
is
2709 -- Note that name has %b on the end which we ignore
2711 -- First we output the initial _ada_ since we know that the main
2712 -- program is a library level subprogram.
2714 Set_String
("_ada_");
2716 -- Copy name, changing dots to double underscores
2718 for J
in 1 .. Name_Len
- 2 loop
2719 if Name_Buffer
(J
) = '.' then
2722 Set_Char
(Name_Buffer
(J
));
2725 end Set_Main_Program_Name
;
2727 ---------------------
2728 -- Set_Name_Buffer --
2729 ---------------------
2731 procedure Set_Name_Buffer
is
2733 for J
in 1 .. Name_Len
loop
2734 Set_Char
(Name_Buffer
(J
));
2736 end Set_Name_Buffer
;
2742 procedure Set_String
(S
: String) is
2744 Statement_Buffer
(Last
+ 1 .. Last
+ S
'Length) := S
;
2745 Last
:= Last
+ S
'Length;
2752 procedure Set_Unit_Name
is
2754 for J
in 1 .. Name_Len
- 2 loop
2755 if Name_Buffer
(J
) /= '.' then
2756 Set_Char
(Name_Buffer
(J
));
2763 ---------------------
2764 -- Set_Unit_Number --
2765 ---------------------
2767 procedure Set_Unit_Number
(U
: Unit_Id
) is
2768 Num_Units
: constant Nat
:= Nat
(Units
.Table
'Last) - Nat
(Unit_Id
'First);
2769 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
2772 if Num_Units
>= 10 and then Unum
< 10 then
2776 if Num_Units
>= 100 and then Unum
< 100 then
2781 end Set_Unit_Number
;
2787 procedure Tab_To
(N
: Natural) is
2798 function Value
(chars
: chars_ptr
) return String is
2799 function Strlen
(chars
: chars_ptr
) return Natural;
2800 pragma Import
(C
, Strlen
);
2803 if chars
= Null_Address
then
2808 subtype Result_Type
is String (1 .. Strlen
(chars
));
2810 Result
: Result_Type
;
2811 for Result
'Address use chars
;
2819 ----------------------
2820 -- Write_Info_Ada_C --
2821 ----------------------
2823 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String) is
2825 if Ada_Bind_File
then
2827 S
: String (1 .. Ada
'Length + Common
'Length);
2830 S
(1 .. Ada
'Length) := Ada
;
2831 S
(Ada
'Length + 1 .. S
'Length) := Common
;
2837 S
: String (1 .. C
'Length + Common
'Length);
2840 S
(1 .. C
'Length) := C
;
2841 S
(C
'Length + 1 .. S
'Length) := Common
;
2845 end Write_Info_Ada_C
;
2847 ----------------------------
2848 -- Write_Statement_Buffer --
2849 ----------------------------
2851 procedure Write_Statement_Buffer
is
2853 WBI
(Statement_Buffer
(1 .. Last
));
2855 end Write_Statement_Buffer
;
2857 procedure Write_Statement_Buffer
(S
: String) is
2860 Write_Statement_Buffer
;
2861 end Write_Statement_Buffer
;