1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Debug
; use Debug
;
30 with Elists
; use Elists
;
32 with Osint
; use Osint
;
34 with Osint
; use Osint
;
35 with Osint
.C
; use Osint
.C
;
36 with Namet
; use Namet
;
37 with Nlists
; use Nlists
;
38 with Stand
; use Stand
;
39 with Sinput
; use Sinput
;
40 with Stringt
; use Stringt
;
41 with Switch
; use Switch
;
42 with Switch
.C
; use Switch
.C
;
43 with System
; use System
;
44 with Types
; use Types
;
46 package body Back_End
is
52 procedure Call_Back_End
(Mode
: Back_End_Mode_Type
) is
54 -- The File_Record type has a lot of components that are meaningless
55 -- to the back end, so a new record is created here to contain the
56 -- needed information for each file.
58 type Needed_File_Info_Type
is record
59 File_Name
: File_Name_Type
;
60 First_Sloc
: Source_Ptr
;
61 Last_Sloc
: Source_Ptr
;
62 Num_Source_Lines
: Nat
;
66 array (Main_Unit
.. Last_Unit
) of Needed_File_Info_Type
;
74 next_node_ptr
: Address
;
75 prev_node_ptr
: Address
;
79 strings_ptr
: Address
;
80 string_chars_ptr
: Address
;
81 list_headers_ptr
: Address
;
84 file_info_ptr
: Address
;
85 gigi_standard_integer
: Entity_Id
;
86 gigi_standard_long_long_float
: Entity_Id
;
87 gigi_standard_exception_type
: Entity_Id
;
88 gigi_operating_mode
: Back_End_Mode_Type
);
90 pragma Import
(C
, gigi
);
92 S
: Source_File_Index
;
95 -- Skip call if in -gnatdH mode
101 for J
in Main_Unit
.. Last_Unit
loop
102 S
:= Source_Index
(J
);
103 File_Info_Array
(J
).File_Name
:= File_Name
(S
);
104 File_Info_Array
(J
).First_Sloc
:= Source_Text
(S
)'First;
105 File_Info_Array
(J
).Last_Sloc
:= Source_Text
(S
)'Last;
106 File_Info_Array
(J
).Num_Source_Lines
:= Num_Source_Lines
(S
);
110 gnat_root
=> Int
(Cunit
(Main_Unit
)),
111 max_gnat_node
=> Int
(Last_Node_Id
- First_Node_Id
+ 1),
112 number_name
=> Name_Entries_Count
,
113 nodes_ptr
=> Nodes_Address
,
115 next_node_ptr
=> Next_Node_Address
,
116 prev_node_ptr
=> Prev_Node_Address
,
117 elists_ptr
=> Elists_Address
,
118 elmts_ptr
=> Elmts_Address
,
120 strings_ptr
=> Strings_Address
,
121 string_chars_ptr
=> String_Chars_Address
,
122 list_headers_ptr
=> Lists_Address
,
123 number_units
=> Num_Units
,
125 file_info_ptr
=> File_Info_Array
'Address,
126 gigi_standard_integer
=> Standard_Integer
,
127 gigi_standard_long_long_float
=> Standard_Long_Long_Float
,
128 gigi_standard_exception_type
=> Standard_Exception_Type
,
129 gigi_operating_mode
=> Mode
);
132 -----------------------------
133 -- Scan_Compiler_Arguments --
134 -----------------------------
136 procedure Scan_Compiler_Arguments
is
140 subtype Big_String
is String (Positive);
141 type BSP
is access Big_String
;
143 type Arg_Array
is array (Nat
) of BSP
;
144 type Arg_Array_Ptr
is access Arg_Array
;
146 -- Import flag_stack_check from toplev.c.
148 flag_stack_check
: Int
;
149 pragma Import
(C
, flag_stack_check
); -- Import from toplev.c
152 pragma Import
(C
, save_argc
); -- Import from toplev.c
154 save_argv
: Arg_Array_Ptr
;
155 pragma Import
(C
, save_argv
); -- Import from toplev.c
157 Output_File_Name_Seen
: Boolean := False;
158 -- Set to True after having scanned the file_name for
159 -- switch "-gnatO file_name"
163 function Len_Arg
(Arg
: Pos
) return Nat
;
164 -- Determine length of argument number Arg on the original
165 -- command line from gnat1
167 procedure Scan_Back_End_Switches
(Switch_Chars
: String);
168 -- Procedure to scan out switches stored in Switch_Chars. The first
169 -- character is known to be a valid switch character, and there are no
170 -- blanks or other switch terminator characters in the string, so the
171 -- entire string should consist of valid switch characters, except that
172 -- an optional terminating NUL character is allowed.
174 -- Back end switches have already been checked and processed by GCC
175 -- in toplev.c, so no errors can occur and control will always return.
176 -- The switches must still be scanned to skip the arguments of the
177 -- "-o" or the (undocumented) "-dumpbase" switch, by incrementing
178 -- the Next_Arg variable. The "-dumpbase" switch is used to set the
179 -- basename for GCC dumpfiles.
185 function Len_Arg
(Arg
: Pos
) return Nat
is
187 for J
in 1 .. Nat
'Last loop
188 if save_argv
(Arg
).all (Natural (J
)) = ASCII
.NUL
then
196 ----------------------------
197 -- Scan_Back_End_Switches --
198 ----------------------------
200 procedure Scan_Back_End_Switches
(Switch_Chars
: String) is
201 First
: constant Positive := Switch_Chars
'First + 1;
202 Last
: Natural := Switch_Chars
'Last;
206 and then Switch_Chars
(Last
) = ASCII
.NUL
211 -- For dumpbase and o, skip following argument and do not
212 -- store either the switch or the following argument
214 if Switch_Chars
(First
.. Last
) = "o"
215 or else Switch_Chars
(First
.. Last
) = "dumpbase"
218 Next_Arg
:= Next_Arg
+ 1;
220 -- Do not record -quiet switch
222 elsif Switch_Chars
(First
.. Last
) = "quiet" then
226 -- Store any other GCC switches
228 Store_Compilation_Switch
(Switch_Chars
);
230 end Scan_Back_End_Switches
;
232 -- Start of processing for Scan_Compiler_Arguments
235 -- Acquire stack checking mode directly from GCC
237 Opt
.Stack_Checking_Enabled
:= (flag_stack_check
/= 0);
239 -- Loop through command line arguments, storing them for later access
241 while Next_Arg
< save_argc
loop
243 Look_At_Arg
: declare
244 Argv_Ptr
: constant BSP
:= save_argv
(Next_Arg
);
245 Argv_Len
: constant Nat
:= Len_Arg
(Next_Arg
);
246 Argv
: String := Argv_Ptr
(1 .. Natural (Argv_Len
));
249 -- If the previous switch has set the Output_File_Name_Present
250 -- flag (that is we have seen a -gnatO), then the next argument
251 -- is the name of the output object file.
253 if Output_File_Name_Present
254 and then not Output_File_Name_Seen
256 if Is_Switch
(Argv
) then
257 Fail
("Object file name missing after -gnatO");
260 Set_Output_Object_File_Name
(Argv
);
261 Output_File_Name_Seen
:= True;
264 elsif not Is_Switch
(Argv
) then -- must be a file name
267 -- We must recognize -nostdinc to suppress visibility on the
268 -- standard GNAT RTL sources. This is also a gcc switch.
270 elsif Argv
(Argv
'First + 1 .. Argv
'Last) = "nostdinc" then
271 Opt
.No_Stdinc
:= True;
272 Scan_Back_End_Switches
(Argv
);
274 elsif Is_Front_End_Switch
(Argv
) then
275 Scan_Front_End_Switches
(Argv
);
277 -- All non-front-end switches are back-end switches
280 Scan_Back_End_Switches
(Argv
);
284 Next_Arg
:= Next_Arg
+ 1;
286 end Scan_Compiler_Arguments
;