annotate gcc/ada/adabkend.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2001-2018, 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
kono
parents:
diff changeset
120 -- for compilers with non-gcc back ends we do it here to allow use
kono
parents:
diff changeset
121 -- of these switches by the front end. Allowed optimization switches
kono
parents:
diff changeset
122 -- are -Os (optimize for size), -O[0123], and -O (same as -O1).
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 elsif Switch_Chars (First) = 'O' then
kono
parents:
diff changeset
125 if First = Last then
kono
parents:
diff changeset
126 Optimization_Level := 1;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 elsif Last - First = 1 then
kono
parents:
diff changeset
129 if Switch_Chars (Last) = 's' then
kono
parents:
diff changeset
130 Optimize_Size := 1;
kono
parents:
diff changeset
131 Optimization_Level := 2; -- Consistent with gcc setting
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 elsif Switch_Chars (Last) in '0' .. '3' then
kono
parents:
diff changeset
134 Optimization_Level :=
kono
parents:
diff changeset
135 Character'Pos (Switch_Chars (Last)) - Character'Pos ('0');
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 else
kono
parents:
diff changeset
138 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
139 end if;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 else
kono
parents:
diff changeset
142 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
143 end if;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 elsif Switch_Chars (First .. Last) = "quiet" then
kono
parents:
diff changeset
146 return; -- ignore this switch
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 elsif Switch_Chars (First .. Last) = "c" then
kono
parents:
diff changeset
149 return; -- ignore this switch
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 -- The -x switch and its language name argument will generally be
kono
parents:
diff changeset
152 -- ignored by non-gcc back ends. In any case, we save the switch and
kono
parents:
diff changeset
153 -- argument in the compilation switches.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 elsif Switch_Chars (First .. Last) = "x" then
kono
parents:
diff changeset
156 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
157 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 declare
kono
parents:
diff changeset
160 Argv : constant String := Args (Next_Arg).all;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163 if Is_Switch (Argv) then
kono
parents:
diff changeset
164 Fail ("language name missing after -x");
kono
parents:
diff changeset
165 else
kono
parents:
diff changeset
166 Lib.Store_Compilation_Switch (Argv);
kono
parents:
diff changeset
167 end if;
kono
parents:
diff changeset
168 end;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 return;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 -- Special check, the back end switch -fno-inline also sets the
kono
parents:
diff changeset
173 -- front end flags to entirely inhibit all inlining. So we store it
kono
parents:
diff changeset
174 -- and set the appropriate flags.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 elsif Switch_Chars (First .. Last) = "fno-inline" then
kono
parents:
diff changeset
177 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
178 Opt.Disable_FE_Inline := True;
kono
parents:
diff changeset
179 Opt.Disable_FE_Inline_Always := True;
kono
parents:
diff changeset
180 return;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 -- Similar processing for -fpreserve-control-flow
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 elsif Switch_Chars (First .. Last) = "fpreserve-control-flow" then
kono
parents:
diff changeset
185 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
186 Opt.Suppress_Control_Flow_Optimizations := True;
kono
parents:
diff changeset
187 return;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 -- Ignore all other back end switches
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 elsif Is_Back_End_Switch (Switch_Chars) then
kono
parents:
diff changeset
192 null;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 -- Give error for junk switch
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 else
kono
parents:
diff changeset
197 Fail ("invalid switch: " & Switch_Chars);
kono
parents:
diff changeset
198 end if;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 -- Store any other GCC switches
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 Lib.Store_Compilation_Switch (Switch_Chars);
kono
parents:
diff changeset
203 end Scan_Back_End_Switches;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 -- Start of processing for Scan_Compiler_Args
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 begin
kono
parents:
diff changeset
208 -- Put all the arguments in argument list Args
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 for Arg in 1 .. Argument_Count loop
kono
parents:
diff changeset
211 declare
kono
parents:
diff changeset
212 Argv : String (1 .. Len_Arg (Arg));
kono
parents:
diff changeset
213 begin
kono
parents:
diff changeset
214 Fill_Arg (Argv'Address, Arg);
kono
parents:
diff changeset
215 Args (Arg) := new String'(Argv);
kono
parents:
diff changeset
216 end;
kono
parents:
diff changeset
217 end loop;
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 -- Loop through command line arguments, storing them for later access
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 while Next_Arg <= Argument_Count loop
kono
parents:
diff changeset
222 Look_At_Arg : declare
kono
parents:
diff changeset
223 Argv : constant String := Args (Next_Arg).all;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 begin
kono
parents:
diff changeset
226 if Argv'Length = 0 then
kono
parents:
diff changeset
227 Fail ("Empty argument");
kono
parents:
diff changeset
228 end if;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 -- If the previous switch has set the Output_File_Name_Present
kono
parents:
diff changeset
231 -- flag (that is we have seen a -gnatO), then the next argument
kono
parents:
diff changeset
232 -- is the name of the output object file.
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 if Opt.Output_File_Name_Present
kono
parents:
diff changeset
235 and then not Output_File_Name_Seen
kono
parents:
diff changeset
236 then
kono
parents:
diff changeset
237 if Is_Switch (Argv) then
kono
parents:
diff changeset
238 Fail ("Object file name missing after -gnatO");
kono
parents:
diff changeset
239 else
kono
parents:
diff changeset
240 Set_Output_Object_File_Name (Argv);
kono
parents:
diff changeset
241 Output_File_Name_Seen := True;
kono
parents:
diff changeset
242 end if;
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 -- If the previous switch has set the Search_Directory_Present
kono
parents:
diff changeset
245 -- flag (that is if we have just seen -I), then the next
kono
parents:
diff changeset
246 -- argument is a search directory path.
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 elsif Search_Directory_Present then
kono
parents:
diff changeset
249 if Is_Switch (Argv) then
kono
parents:
diff changeset
250 Fail ("search directory missing after -I");
kono
parents:
diff changeset
251 else
kono
parents:
diff changeset
252 Add_Src_Search_Dir (Argv);
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 -- Add directory to lib search so that back end can take as
kono
parents:
diff changeset
255 -- input ALI files if needed. Otherwise this won't have any
kono
parents:
diff changeset
256 -- impact on the compiler.
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 Add_Lib_Search_Dir (Argv);
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 Search_Directory_Present := False;
kono
parents:
diff changeset
261 end if;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 -- If not a switch, must be a file name
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 elsif not Is_Switch (Argv) then
kono
parents:
diff changeset
266 Add_File (Argv);
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 -- We must recognize -nostdinc to suppress visibility on the
kono
parents:
diff changeset
269 -- standard GNAT RTL sources.
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 elsif Argv (Argv'First + 1 .. Argv'Last) = "nostdinc" then
kono
parents:
diff changeset
272 Opt.No_Stdinc := True;
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 -- Front end switch
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 elsif Is_Front_End_Switch (Argv) then
kono
parents:
diff changeset
277 Scan_Front_End_Switches (Argv, Args, Next_Arg);
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 -- All non-front-end switches are back-end switches
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 else
kono
parents:
diff changeset
282 Scan_Back_End_Switches (Argv);
kono
parents:
diff changeset
283 end if;
kono
parents:
diff changeset
284 end Look_At_Arg;
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
287 end loop;
kono
parents:
diff changeset
288 end Scan_Compiler_Arguments;
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 end Adabkend;