./:
[official-gcc.git] / gcc / ada / switch-b.adb
blobf5beb05c4703e38e1bd4276022d7c67288ac7ee4
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Debug; use Debug;
28 with Osint; use Osint;
29 with Opt; use Opt;
31 with System.WCh_Con; use System.WCh_Con;
33 package body Switch.B is
35 --------------------------
36 -- Scan_Binder_Switches --
37 --------------------------
39 procedure Scan_Binder_Switches (Switch_Chars : String) is
40 Max : constant Integer := Switch_Chars'Last;
41 Ptr : Integer := Switch_Chars'First;
42 C : Character := ' ';
44 begin
45 -- Skip past the initial character (must be the switch character)
47 if Ptr = Max then
48 Bad_Switch (C);
49 else
50 Ptr := Ptr + 1;
51 end if;
53 -- A little check, "gnat" at the start of a switch is not allowed
54 -- except for the compiler
56 if Switch_Chars'Last >= Ptr + 3
57 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
58 then
59 Osint.Fail ("invalid switch: """, Switch_Chars, """"
60 & " (gnat not needed here)");
61 end if;
63 -- Loop to scan through switches given in switch string
65 while Ptr <= Max loop
66 C := Switch_Chars (Ptr);
68 case C is
70 -- Processing for a switch
72 when 'a' =>
73 Ptr := Ptr + 1;
74 Use_Pragma_Linker_Constructor := True;
76 -- Processing for A switch
78 when 'A' =>
79 Ptr := Ptr + 1;
80 Ada_Bind_File := True;
82 -- Processing for b switch
84 when 'b' =>
85 Ptr := Ptr + 1;
86 Brief_Output := True;
88 -- Processing for c switch
90 when 'c' =>
91 Ptr := Ptr + 1;
93 Check_Only := True;
95 -- Processing for C switch
97 when 'C' =>
98 Ptr := Ptr + 1;
100 Ada_Bind_File := False;
102 -- Processing for d switch
104 when 'd' =>
106 -- Note: for the debug switch, the remaining characters in this
107 -- switch field must all be debug flags, since all valid switch
108 -- characters are also valid debug characters. This switch is not
109 -- documented on purpose because it is only used by the
110 -- implementors.
112 -- Loop to scan out debug flags
114 while Ptr < Max loop
115 Ptr := Ptr + 1;
116 C := Switch_Chars (Ptr);
117 exit when C = ASCII.NUL or else C = '/' or else C = '-';
119 if C in '1' .. '9' or else
120 C in 'a' .. 'z' or else
121 C in 'A' .. 'Z'
122 then
123 Set_Debug_Flag (C);
124 else
125 Bad_Switch (C);
126 end if;
127 end loop;
129 return;
131 -- Processing for D switch
133 when 'D' =>
134 Ptr := Ptr + 1;
135 Scan_Pos
136 (Switch_Chars, Max, Ptr, Default_Sec_Stack_Size, C);
138 -- Processing for e switch
140 when 'e' =>
141 Ptr := Ptr + 1;
142 Elab_Dependency_Output := True;
144 -- Processing for E switch
146 when 'E' =>
147 Ptr := Ptr + 1;
148 Exception_Tracebacks := True;
150 -- Processing for F switch
152 when 'F' =>
153 Ptr := Ptr + 1;
154 Force_Checking_Of_Elaboration_Flags := True;
156 -- Processing for g switch
158 when 'g' =>
159 Ptr := Ptr + 1;
161 if Ptr <= Max then
162 C := Switch_Chars (Ptr);
164 if C in '0' .. '3' then
165 Debugger_Level :=
166 Character'Pos
167 (Switch_Chars (Ptr)) - Character'Pos ('0');
168 Ptr := Ptr + 1;
169 end if;
171 else
172 Debugger_Level := 2;
173 end if;
175 -- Processing for h switch
177 when 'h' =>
178 Ptr := Ptr + 1;
179 Usage_Requested := True;
181 -- Processing for i switch
183 when 'i' =>
184 if Ptr = Max then
185 Bad_Switch (C);
186 end if;
188 Ptr := Ptr + 1;
189 C := Switch_Chars (Ptr);
191 if C in '1' .. '5'
192 or else C = '8'
193 or else C = 'p'
194 or else C = 'f'
195 or else C = 'n'
196 or else C = 'w'
197 then
198 Identifier_Character_Set := C;
199 Ptr := Ptr + 1;
200 else
201 Bad_Switch (C);
202 end if;
204 -- Processing for K switch
206 when 'K' =>
207 Ptr := Ptr + 1;
208 Output_Linker_Option_List := True;
210 -- Processing for l switch
212 when 'l' =>
213 Ptr := Ptr + 1;
214 Elab_Order_Output := True;
216 -- Processing for m switch
218 when 'm' =>
219 Ptr := Ptr + 1;
220 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
222 -- Processing for n switch
224 when 'n' =>
225 Ptr := Ptr + 1;
226 Bind_Main_Program := False;
228 -- Note: The -L option of the binder also implies -n, so
229 -- any change here must also be reflected in the processing
230 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
232 -- Processing for o switch
234 when 'o' =>
235 Ptr := Ptr + 1;
237 if Output_File_Name_Present then
238 Osint.Fail ("duplicate -o switch");
240 else
241 Output_File_Name_Present := True;
242 end if;
244 -- Processing for O switch
246 when 'O' =>
247 Ptr := Ptr + 1;
248 Output_Object_List := True;
250 -- Processing for p switch
252 when 'p' =>
253 Ptr := Ptr + 1;
254 Pessimistic_Elab_Order := True;
256 -- Processing for q switch
258 when 'q' =>
259 Ptr := Ptr + 1;
260 Quiet_Output := True;
262 -- Processing for r switch
264 when 'r' =>
265 Ptr := Ptr + 1;
266 List_Restrictions := True;
268 -- Processing for s switch
270 when 's' =>
271 Ptr := Ptr + 1;
272 All_Sources := True;
273 Check_Source_Files := True;
275 -- Processing for t switch
277 when 't' =>
278 Ptr := Ptr + 1;
279 Tolerate_Consistency_Errors := True;
281 -- Processing for T switch
283 when 'T' =>
284 Ptr := Ptr + 1;
285 Time_Slice_Set := True;
286 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
287 Time_Slice_Value := Time_Slice_Value * 1_000;
289 -- Processing for v switch
291 when 'v' =>
292 Ptr := Ptr + 1;
293 Verbose_Mode := True;
295 -- Processing for w switch
297 when 'w' =>
299 -- For the binder we only allow suppress/error cases
301 Ptr := Ptr + 1;
303 case Switch_Chars (Ptr) is
305 when 'e' =>
306 Warning_Mode := Treat_As_Error;
308 when 's' =>
309 Warning_Mode := Suppress;
311 when others =>
312 Bad_Switch (C);
313 end case;
315 Ptr := Ptr + 1;
317 -- Processing for W switch
319 when 'W' =>
320 Ptr := Ptr + 1;
322 for J in WC_Encoding_Method loop
323 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
324 Wide_Character_Encoding_Method := J;
325 exit;
327 elsif J = WC_Encoding_Method'Last then
328 Bad_Switch (C);
329 end if;
330 end loop;
332 Upper_Half_Encoding :=
333 Wide_Character_Encoding_Method in
334 WC_Upper_Half_Encoding_Method;
336 Ptr := Ptr + 1;
338 -- Processing for x switch
340 when 'x' =>
341 Ptr := Ptr + 1;
342 All_Sources := False;
343 Check_Source_Files := False;
345 -- Processing for X switch
347 when 'X' =>
348 Ptr := Ptr + 1;
349 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
351 -- Processing for z switch
353 when 'z' =>
354 Ptr := Ptr + 1;
355 No_Main_Subprogram := True;
357 -- Ignore extra switch character
359 when '/' =>
360 Ptr := Ptr + 1;
362 -- Ignore '-' extra switch caracter, only if it isn't followed by
363 -- 'RTS'. If it is, then we must process the 'RTS' switch
365 when '-' =>
367 if Ptr + 3 <= Max and then
368 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
369 then
370 Ptr := Ptr + 1;
372 if Switch_Chars (Ptr + 3) /= '=' or else
373 (Switch_Chars (Ptr + 3) = '='
374 and then Ptr + 4 > Max)
375 then
376 Osint.Fail ("missing path for --RTS");
377 else
379 -- valid --RTS switch
380 Opt.No_Stdinc := True;
381 Opt.RTS_Switch := True;
383 declare
384 Src_Path_Name : constant String_Ptr :=
385 Get_RTS_Search_Dir
386 (Switch_Chars
387 (Ptr + 4 .. Switch_Chars'Last),
388 Include);
389 Lib_Path_Name : constant String_Ptr :=
390 Get_RTS_Search_Dir
391 (Switch_Chars
392 (Ptr + 4 .. Switch_Chars'Last),
393 Objects);
395 begin
396 if Src_Path_Name /= null and then
397 Lib_Path_Name /= null
398 then
399 -- Set the RTS_*_Path_Name variables, so that the
400 -- correct directories will be set when
401 -- Osint.Add_Default_Search_Dirs will be called later.
403 RTS_Src_Path_Name := Src_Path_Name;
404 RTS_Lib_Path_Name := Lib_Path_Name;
406 -- We can exit as there cannot be another switch
407 -- after --RTS
409 exit;
411 elsif Src_Path_Name = null
412 and then Lib_Path_Name = null
413 then
414 Osint.Fail ("RTS path not valid: missing " &
415 "adainclude and adalib directories");
416 elsif Src_Path_Name = null then
417 Osint.Fail ("RTS path not valid: missing " &
418 "adainclude directory");
419 elsif Lib_Path_Name = null then
420 Osint.Fail ("RTS path not valid: missing " &
421 "adalib directory");
422 end if;
423 end;
424 end if;
426 else
427 Ptr := Ptr + 1;
428 end if;
430 -- Anything else is an error (illegal switch character)
432 when others =>
433 Bad_Switch (C);
434 end case;
435 end loop;
436 end Scan_Binder_Switches;
438 end Switch.B;