Properly regenerate gcc/configure.
[official-gcc.git] / gcc / ada / back_end.adb
blob3e535547db632d8072e285e14f81e3488beed421
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- B A C K _ E N D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Elists; use Elists;
29 with Errout; use Errout;
30 with Lib; use Lib;
31 with Osint; use Osint;
32 with Opt; use Opt;
33 with Osint.C; use Osint.C;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
36 with Stand; use Stand;
37 with Sinput; use Sinput;
38 with Stringt; use Stringt;
39 with Switch; use Switch;
40 with Switch.C; use Switch.C;
41 with System; use System;
42 with Types; use Types;
44 with System.OS_Lib; use System.OS_Lib;
46 package body Back_End is
48 type Arg_Array is array (Nat) of Big_String_Ptr;
49 type Arg_Array_Ptr is access Arg_Array;
50 -- Types to access compiler arguments
52 flag_stack_check : Int;
53 pragma Import (C, flag_stack_check);
54 -- Indicates if stack checking is enabled, imported from misc.c
56 save_argc : Nat;
57 pragma Import (C, save_argc);
58 -- Saved value of argc (number of arguments), imported from misc.c
60 save_argv : Arg_Array_Ptr;
61 pragma Import (C, save_argv);
62 -- Saved value of argv (argument pointers), imported from misc.c
64 function Len_Arg (Arg : Pos) return Nat;
65 -- Determine length of argument number Arg on original gnat1 command line
67 -------------------
68 -- Call_Back_End --
69 -------------------
71 procedure Call_Back_End (Mode : Back_End_Mode_Type) is
73 -- The Source_File_Record type has a lot of components that are
74 -- meaningless to the back end, so a new record type is created
75 -- here to contain the needed information for each file.
77 type File_Info_Type is record
78 File_Name : File_Name_Type;
79 Instance : Instance_Id;
80 Num_Source_Lines : Nat;
81 end record;
83 File_Info_Array : array (1 .. Last_Source_File) of File_Info_Type;
85 procedure gigi
86 (gnat_root : Int;
87 max_gnat_node : Int;
88 number_name : Nat;
89 nodes_ptr : Address;
90 flags_ptr : Address;
92 next_node_ptr : Address;
93 prev_node_ptr : Address;
94 elists_ptr : Address;
95 elmts_ptr : Address;
97 strings_ptr : Address;
98 string_chars_ptr : Address;
99 list_headers_ptr : Address;
100 number_file : Nat;
102 file_info_ptr : Address;
103 gigi_standard_boolean : Entity_Id;
104 gigi_standard_integer : Entity_Id;
105 gigi_standard_character : Entity_Id;
106 gigi_standard_long_long_float : Entity_Id;
107 gigi_standard_exception_type : Entity_Id;
108 gigi_operating_mode : Back_End_Mode_Type);
110 pragma Import (C, gigi);
112 begin
113 -- Skip call if in -gnatdH mode
115 if Debug_Flag_HH then
116 return;
117 end if;
119 -- The back end needs to know the maximum line number that can appear
120 -- in a Sloc, in other words the maximum logical line number.
122 for J in 1 .. Last_Source_File loop
123 File_Info_Array (J).File_Name := Full_Debug_Name (J);
124 File_Info_Array (J).Instance := Instance (J);
125 File_Info_Array (J).Num_Source_Lines :=
126 Nat (Physical_To_Logical (Last_Source_Line (J), J));
127 end loop;
129 -- Deal with case of generating SCIL, we should not be here unless
130 -- debugging CodePeer mode in GNAT.
132 if Generate_SCIL then
133 Error_Msg_N ("'S'C'I'L generation not available", Cunit (Main_Unit));
135 if CodePeer_Mode
136 or else (Mode /= Generate_Object
137 and then not Back_Annotate_Rep_Info)
138 then
139 return;
140 end if;
141 end if;
143 -- We should be here in GNATprove mode only when debugging GNAT. Do not
144 -- call gigi in that case, as it is not prepared to handle the special
145 -- form of the tree obtained in GNATprove mode.
147 if GNATprove_Mode then
148 return;
149 end if;
151 -- The actual call to the back end
153 gigi
154 (gnat_root => Int (Cunit (Main_Unit)),
155 max_gnat_node => Int (Last_Node_Id - First_Node_Id + 1),
156 number_name => Name_Entries_Count,
157 nodes_ptr => Nodes_Address,
158 flags_ptr => Flags_Address,
160 next_node_ptr => Next_Node_Address,
161 prev_node_ptr => Prev_Node_Address,
162 elists_ptr => Elists_Address,
163 elmts_ptr => Elmts_Address,
165 strings_ptr => Strings_Address,
166 string_chars_ptr => String_Chars_Address,
167 list_headers_ptr => Lists_Address,
168 number_file => Num_Source_Files,
170 file_info_ptr => File_Info_Array'Address,
171 gigi_standard_boolean => Standard_Boolean,
172 gigi_standard_integer => Standard_Integer,
173 gigi_standard_character => Standard_Character,
174 gigi_standard_long_long_float => Standard_Long_Long_Float,
175 gigi_standard_exception_type => Standard_Exception_Type,
176 gigi_operating_mode => Mode);
177 end Call_Back_End;
179 -------------------------------
180 -- Gen_Or_Update_Object_File --
181 -------------------------------
183 procedure Gen_Or_Update_Object_File is
184 begin
185 null;
186 end Gen_Or_Update_Object_File;
188 -------------
189 -- Len_Arg --
190 -------------
192 function Len_Arg (Arg : Pos) return Nat is
193 begin
194 for J in 1 .. Nat'Last loop
195 if save_argv (Arg).all (Natural (J)) = ASCII.NUL then
196 return J - 1;
197 end if;
198 end loop;
200 raise Program_Error;
201 end Len_Arg;
203 -----------------------------
204 -- Scan_Compiler_Arguments --
205 -----------------------------
207 procedure Scan_Compiler_Arguments is
208 Next_Arg : Positive;
209 -- Next argument to be scanned
211 Output_File_Name_Seen : Boolean := False;
212 -- Set to True after having scanned file_name for switch "-gnatO file"
214 procedure Scan_Back_End_Switches (Switch_Chars : String);
215 -- Procedure to scan out switches stored in Switch_Chars. The first
216 -- character is known to be a valid switch character, and there are no
217 -- blanks or other switch terminator characters in the string, so the
218 -- entire string should consist of valid switch characters, except that
219 -- an optional terminating NUL character is allowed.
221 -- Back end switches have already been checked and processed by GCC in
222 -- toplev.c, so no errors can occur and control will always return. The
223 -- switches must still be scanned to skip "-o" or internal GCC switches
224 -- with their argument.
226 ----------------------------
227 -- Scan_Back_End_Switches --
228 ----------------------------
230 procedure Scan_Back_End_Switches (Switch_Chars : String) is
231 First : constant Positive := Switch_Chars'First + 1;
232 Last : constant Natural := Switch_Last (Switch_Chars);
234 begin
235 -- Skip -o or internal GCC switches together with their argument
237 if Switch_Chars (First .. Last) = "o"
238 or else Is_Internal_GCC_Switch (Switch_Chars)
239 then
240 Next_Arg := Next_Arg + 1;
242 -- Do not record -quiet switch
244 elsif Switch_Chars (First .. Last) = "quiet" then
245 null;
247 -- Store any other GCC switches. Also do special processing for some
248 -- specific switches that the Ada front-end knows about.
250 else
251 Store_Compilation_Switch (Switch_Chars);
253 -- Back end switch -fno-inline also sets the Suppress_All_Inlining
254 -- front end flag to entirely inhibit all inlining.
256 if Switch_Chars (First .. Last) = "fno-inline" then
257 Opt.Suppress_All_Inlining := True;
259 -- Back end switch -fpreserve-control-flow also sets the front end
260 -- flag that inhibits improper control flow transformations.
262 elsif Switch_Chars (First .. Last) = "fpreserve-control-flow" then
263 Opt.Suppress_Control_Flow_Optimizations := True;
265 -- Back end switch -fdump-scos, which exists primarily for C, is
266 -- also accepted for Ada as a synonym of -gnateS.
268 elsif Switch_Chars (First .. Last) = "fdump-scos" then
269 Opt.Generate_SCO := True;
270 Opt.Generate_SCO_Instance_Table := True;
271 end if;
272 end if;
273 end Scan_Back_End_Switches;
275 -- Local variables
277 Arg_Count : constant Natural := Natural (save_argc - 1);
278 Args : Argument_List (1 .. Arg_Count);
280 -- Start of processing for Scan_Compiler_Arguments
282 begin
283 -- Acquire stack checking mode directly from GCC. The reason we do this
284 -- is to make sure that the indication of stack checking being enabled
285 -- is the same in the front end and the back end. This status obtained
286 -- from gcc is affected by more than just the switch -fstack-check.
288 Opt.Stack_Checking_Enabled := (flag_stack_check /= 0);
290 -- Put the arguments in Args
292 for Arg in Pos range 1 .. save_argc - 1 loop
293 declare
294 Argv_Ptr : constant Big_String_Ptr := save_argv (Arg);
295 Argv_Len : constant Nat := Len_Arg (Arg);
296 Argv : constant String :=
297 Argv_Ptr (1 .. Natural (Argv_Len));
298 begin
299 Args (Positive (Arg)) := new String'(Argv);
300 end;
301 end loop;
303 -- Loop through command line arguments, storing them for later access
305 Next_Arg := 1;
306 while Next_Arg <= Args'Last loop
307 Look_At_Arg : declare
308 Argv : constant String := Args (Next_Arg).all;
310 begin
311 -- If the previous switch has set the Output_File_Name_Present
312 -- flag (that is we have seen a -gnatO), then the next argument
313 -- is the name of the output object file.
315 if Output_File_Name_Present and then not Output_File_Name_Seen then
316 if Is_Switch (Argv) then
317 Fail ("Object file name missing after -gnatO");
318 else
319 Set_Output_Object_File_Name (Argv);
320 Output_File_Name_Seen := True;
321 end if;
323 -- If the previous switch has set the Search_Directory_Present
324 -- flag (that is if we have just seen -I), then the next argument
325 -- is a search directory path.
327 elsif Search_Directory_Present then
328 if Is_Switch (Argv) then
329 Fail ("search directory missing after -I");
330 else
331 Add_Src_Search_Dir (Argv);
332 Search_Directory_Present := False;
333 end if;
335 -- If not a switch, must be a file name
337 elsif not Is_Switch (Argv) then
338 Add_File (Argv);
340 -- We must recognize -nostdinc to suppress visibility on the
341 -- standard GNAT RTL sources. This is also a gcc switch.
343 elsif Argv (Argv'First + 1 .. Argv'Last) = "nostdinc" then
344 Opt.No_Stdinc := True;
345 Scan_Back_End_Switches (Argv);
347 -- We must recognize -nostdlib to suppress visibility on the
348 -- standard GNAT RTL objects.
350 elsif Argv (Argv'First + 1 .. Argv'Last) = "nostdlib" then
351 Opt.No_Stdlib := True;
353 elsif Is_Front_End_Switch (Argv) then
354 Scan_Front_End_Switches (Argv, Args, Next_Arg);
356 -- All non-front-end switches are back-end switches
358 else
359 Scan_Back_End_Switches (Argv);
360 end if;
361 end Look_At_Arg;
363 Next_Arg := Next_Arg + 1;
364 end loop;
365 end Scan_Compiler_Arguments;
367 end Back_End;