annotate gcc/ada/adabkend.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A B K E N D --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2001-2019, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 ------------------------------------------------------------------------------
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 -- This is the version of the Back_End package for back ends written in Ada
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 with Atree; use Atree;
kono
parents:
diff changeset
26 with Debug;
kono
parents:
diff changeset
27 with Lib;
kono
parents:
diff changeset
28 with Opt; use Opt;
kono
parents:
diff changeset
29 with Output; use Output;
kono
parents:
diff changeset
30 with Osint; use Osint;
kono
parents:
diff changeset
31 with Osint.C; use Osint.C;
kono
parents:
diff changeset
32 with Switch.C; use Switch.C;
kono
parents:
diff changeset
33 with Types; use Types;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 with System.OS_Lib; use System.OS_Lib;
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 package body Adabkend is
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 use Switch;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 -------------------
kono
parents:
diff changeset
42 -- Call_Back_End --
kono
parents:
diff changeset
43 -------------------
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 procedure Call_Back_End is
kono
parents:
diff changeset
46 begin
kono
parents:
diff changeset
47 if (Opt.Verbose_Mode or Opt.Full_List)
kono
parents:
diff changeset
48 and then not Debug.Debug_Flag_7
kono
parents:
diff changeset
49 then
kono
parents:
diff changeset
50 Write_Eol;
kono
parents:
diff changeset
51 Write_Str (Product_Name);
kono
parents:
diff changeset
52 Write_Str (", Copyright ");
kono
parents:
diff changeset
53 Write_Str (Copyright_Years);
kono
parents:
diff changeset
54 Write_Str (" Ada Core Technologies, Inc.");
kono
parents:
diff changeset
55 Write_Str (" (http://www.adacore.com)");
kono
parents:
diff changeset
56 Write_Eol;
kono
parents:
diff changeset
57 Write_Eol;
kono
parents:
diff changeset
58 end if;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 -- The front end leaves the Current_Error_Node at a location that is
kono
parents:
diff changeset
61 -- meaningless and confusing when emitting bug boxes from the back end.
kono
parents:
diff changeset
62 -- Reset the global variable in order to emit "No source file position
kono
parents:
diff changeset
63 -- information available" messages on back end crashes.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 Current_Error_Node := Empty;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 Driver (Lib.Cunit (Types.Main_Unit));
kono
parents:
diff changeset
68 end Call_Back_End;
kono
parents:
diff changeset
69
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 -----------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 -- Scan_Compiler_Arguments --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72 -----------------------------
111
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure Scan_Compiler_Arguments is
kono
parents:
diff changeset
75 Output_File_Name_Seen : Boolean := False;
kono
parents:
diff changeset
76 -- Set to True after having scanned the file_name for switch
kono
parents:
diff changeset
77 -- "-gnatO file_name"
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 Argument_Count : constant Integer := Arg_Count - 1;
kono
parents:
diff changeset
80 -- Number of arguments (excluding program name)
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 Args : Argument_List (1 .. Argument_Count);
kono
parents:
diff changeset
83 Next_Arg : Positive := 1;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Scan_Back_End_Switches (Switch_Chars : String);
kono
parents:
diff changeset
86 -- Procedure to scan out switches stored in Switch_Chars. The first
kono
parents:
diff changeset
87 -- character is known to be a valid switch character, and there are no
kono
parents:
diff changeset
88 -- blanks or other switch terminator characters in the string, so the
kono
parents:
diff changeset
89 -- entire string should consist of valid switch characters, except that
kono
parents:
diff changeset
90 -- an optional terminating NUL character is allowed.
kono
parents:
diff changeset
91 --
kono
parents:
diff changeset
92 -- If the switch is not valid, control will not return. The switches
kono
parents:
diff changeset
93 -- must still be scanned to skip the "-o" arguments, or internal GCC
kono
parents:
diff changeset
94 -- switches, which may be safely ignored by other back ends.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 ----------------------------
kono
parents:
diff changeset
97 -- Scan_Back_End_Switches --
kono
parents:
diff changeset
98 ----------------------------
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Scan_Back_End_Switches (Switch_Chars : String) is
kono
parents:
diff changeset
101 First : constant Positive := Switch_Chars'First + 1;
kono
parents:
diff changeset
102 Last : constant Natural := Switch_Last (Switch_Chars);
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 begin
kono
parents:
diff changeset
105 -- Process any back end switches, returning if the switch does not
kono
parents:
diff changeset
106 -- affect code generation or falling through if it does, so the
kono
parents:
diff changeset
107 -- switch will get stored.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 -- Skip -o, -G or internal GCC switches together with their argument.
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 if Switch_Chars (First .. Last) = "o"
kono
parents:
diff changeset
112 or else Switch_Chars (First .. Last) = "G"
kono
parents:
diff changeset
113 or else Is_Internal_GCC_Switch (Switch_Chars)
kono
parents:
diff changeset
114 then
kono
parents:
diff changeset
115 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
116 return; -- ignore this switch
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 -- Set optimization indicators appropriately. In gcc-based GNAT this
kono
parents:
diff changeset
119 -- is picked up from imported variables set by the gcc driver, but
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
120 -- for compilers with non-gcc back ends we do it here to allow use of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
121 -- these switches by the front end. Allowed optimization switches are
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
122 -- -Os (optimize for size), -O[0123], -O (same as -O1), -Ofast
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
123 -- (disregard strict standards compliance), and -Og (optimize
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
124 -- debugging experience).
111
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 elsif Switch_Chars (First) = 'O' then
kono
parents:
diff changeset
127 if First = Last then
kono
parents:
diff changeset
128 Optimization_Level := 1;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 elsif Last - First = 1 then
kono
parents:
diff changeset
131 if Switch_Chars (Last) = 's' then
kono
parents:
diff changeset
132 Optimize_Size := 1;
kono
parents:
diff changeset
133 Optimization_Level := 2; -- Consistent with gcc setting
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 elsif Switch_Chars (Last) in '0' .. '3' then
kono
parents:
diff changeset
136 Optimization_Level :=
kono
parents:
diff changeset
137 Character'Pos (Switch_Chars (Last)) - Character'Pos ('0');
kono
parents:
diff changeset
138
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
139 -- Switch -Og is between -O0 and -O1 in GCC. Consider it like
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
140 -- -O0 for other back ends.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
141
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
142 elsif Switch_Chars (Last) = 'g' then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
143 Optimization_Level := 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
144
111
kono
parents:
diff changeset
145 else
kono
parents:
diff changeset
146 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
147 end if;
kono
parents:
diff changeset
148
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
149 -- Switch -Ofast enables -O3
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
150
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
151 elsif Switch_Chars (First + 1 .. Last) = "fast" then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
152 Optimization_Level := 3;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
153
111
kono
parents:
diff changeset
154 else
kono
parents:
diff changeset
155 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
156 end if;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 elsif Switch_Chars (First .. Last) = "quiet" then
kono
parents:
diff changeset
159 return; -- ignore this switch
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 elsif Switch_Chars (First .. Last) = "c" then
kono
parents:
diff changeset
162 return; -- ignore this switch
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 -- The -x switch and its language name argument will generally be
kono
parents:
diff changeset
165 -- ignored by non-gcc back ends. In any case, we save the switch and
kono
parents:
diff changeset
166 -- argument in the compilation switches.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 elsif Switch_Chars (First .. Last) = "x" then
kono
parents:
diff changeset
169 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
170 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 declare
kono
parents:
diff changeset
173 Argv : constant String := Args (Next_Arg).all;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 begin
kono
parents:
diff changeset
176 if Is_Switch (Argv) then
kono
parents:
diff changeset
177 Fail ("language name missing after -x");
kono
parents:
diff changeset
178 else
kono
parents:
diff changeset
179 Lib.Store_Compilation_Switch (Argv);
kono
parents:
diff changeset
180 end if;
kono
parents:
diff changeset
181 end;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 return;
kono
parents:
diff changeset
184
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
185 -- Special check, the back-end switch -fno-inline also sets the
111
kono
parents:
diff changeset
186 -- front end flags to entirely inhibit all inlining. So we store it
kono
parents:
diff changeset
187 -- and set the appropriate flags.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 elsif Switch_Chars (First .. Last) = "fno-inline" then
kono
parents:
diff changeset
190 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
191 Opt.Disable_FE_Inline := True;
kono
parents:
diff changeset
192 Opt.Disable_FE_Inline_Always := True;
kono
parents:
diff changeset
193 return;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 -- Similar processing for -fpreserve-control-flow
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 elsif Switch_Chars (First .. Last) = "fpreserve-control-flow" then
kono
parents:
diff changeset
198 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
199 Opt.Suppress_Control_Flow_Optimizations := True;
kono
parents:
diff changeset
200 return;
kono
parents:
diff changeset
201
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
202 -- Recognize -gxxx switches
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
203
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
204 elsif Switch_Chars (First) = 'g' then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
205 Debugger_Level := 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
206
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
207 if First < Last then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
208 case Switch_Chars (First + 1) is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
209 when '0' =>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
210 Debugger_Level := 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
211 when '1' =>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
212 Debugger_Level := 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
213 when '2' =>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
214 Debugger_Level := 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
215 when '3' =>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
216 Debugger_Level := 3;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
217 when others =>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
218 null;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
219 end case;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
220 end if;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
221
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
222 -- Ignore all other back-end switches
111
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 elsif Is_Back_End_Switch (Switch_Chars) then
kono
parents:
diff changeset
225 null;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 -- Give error for junk switch
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 else
kono
parents:
diff changeset
230 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
231 end if;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 -- Store any other GCC switches
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
236 end Scan_Back_End_Switches;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Start of processing for Scan_Compiler_Args
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 begin
kono
parents:
diff changeset
241 -- Put all the arguments in argument list Args
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 for Arg in 1 .. Argument_Count loop
kono
parents:
diff changeset
244 declare
kono
parents:
diff changeset
245 Argv : String (1 .. Len_Arg (Arg));
kono
parents:
diff changeset
246 begin
kono
parents:
diff changeset
247 Fill_Arg (Argv'Address, Arg);
kono
parents:
diff changeset
248 Args (Arg) := new String'(Argv);
kono
parents:
diff changeset
249 end;
kono
parents:
diff changeset
250 end loop;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- Loop through command line arguments, storing them for later access
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 while Next_Arg <= Argument_Count loop
kono
parents:
diff changeset
255 Look_At_Arg : declare
kono
parents:
diff changeset
256 Argv : constant String := Args (Next_Arg).all;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 begin
kono
parents:
diff changeset
259 if Argv'Length = 0 then
kono
parents:
diff changeset
260 Fail ("Empty argument");
kono
parents:
diff changeset
261 end if;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 -- If the previous switch has set the Output_File_Name_Present
kono
parents:
diff changeset
264 -- flag (that is we have seen a -gnatO), then the next argument
kono
parents:
diff changeset
265 -- is the name of the output object file.
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 if Opt.Output_File_Name_Present
kono
parents:
diff changeset
268 and then not Output_File_Name_Seen
kono
parents:
diff changeset
269 then
kono
parents:
diff changeset
270 if Is_Switch (Argv) then
kono
parents:
diff changeset
271 Fail ("Object file name missing after -gnatO");
kono
parents:
diff changeset
272 else
kono
parents:
diff changeset
273 Set_Output_Object_File_Name (Argv);
kono
parents:
diff changeset
274 Output_File_Name_Seen := True;
kono
parents:
diff changeset
275 end if;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 -- If the previous switch has set the Search_Directory_Present
kono
parents:
diff changeset
278 -- flag (that is if we have just seen -I), then the next
kono
parents:
diff changeset
279 -- argument is a search directory path.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 elsif Search_Directory_Present then
kono
parents:
diff changeset
282 if Is_Switch (Argv) then
kono
parents:
diff changeset
283 Fail ("search directory missing after -I");
kono
parents:
diff changeset
284 else
kono
parents:
diff changeset
285 Add_Src_Search_Dir (Argv);
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 -- Add directory to lib search so that back end can take as
kono
parents:
diff changeset
288 -- input ALI files if needed. Otherwise this won't have any
kono
parents:
diff changeset
289 -- impact on the compiler.
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 Add_Lib_Search_Dir (Argv);
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 Search_Directory_Present := False;
kono
parents:
diff changeset
294 end if;
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 -- If not a switch, must be a file name
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 elsif not Is_Switch (Argv) then
kono
parents:
diff changeset
299 Add_File (Argv);
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 -- We must recognize -nostdinc to suppress visibility on the
kono
parents:
diff changeset
302 -- standard GNAT RTL sources.
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 elsif Argv (Argv'First + 1 .. Argv'Last) = "nostdinc" then
kono
parents:
diff changeset
305 Opt.No_Stdinc := True;
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 -- Front end switch
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 elsif Is_Front_End_Switch (Argv) then
kono
parents:
diff changeset
310 Scan_Front_End_Switches (Argv, Args, Next_Arg);
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 -- All non-front-end switches are back-end switches
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 else
kono
parents:
diff changeset
315 Scan_Back_End_Switches (Argv);
kono
parents:
diff changeset
316 end if;
kono
parents:
diff changeset
317 end Look_At_Arg;
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
320 end loop;
kono
parents:
diff changeset
321 end Scan_Compiler_Arguments;
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 end Adabkend;