Merge from mainline
[official-gcc.git] / gcc / ada / switch-b.adb
blobee8ac6a2512c81bfdcb3062921fdb9bb7d26350e
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 function Get_Stack_Size (S : Character) return Int;
45 -- Used for -d and -D to scan stack size including handling k/m.
46 -- S is set to 'd' or 'D' to indicate the switch being scanned.
48 --------------------
49 -- Get_Stack_Size --
50 --------------------
52 function Get_Stack_Size (S : Character) return Int is
53 Result : Int;
55 begin
56 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
58 -- In the following code, we enable overflow checking since the
59 -- multiplication by K or M may cause overflow, which is an error.
61 declare
62 pragma Unsuppress (Overflow_Check);
64 begin
65 -- Check for additional character 'k' (for kilobytes) or 'm'
66 -- (for Megabytes), but only if we have not reached the end
67 -- of the switch string. Note that if this appears before the
68 -- end of the string we will get an error when we test to make
69 -- sure that the string is exhausted (at the end of the case).
71 if Ptr <= Max then
72 if Switch_Chars (Ptr) = 'k' then
73 Result := Result * 1024;
74 Ptr := Ptr + 1;
76 elsif Switch_Chars (Ptr) = 'm' then
77 Result := Result * (1024 * 1024);
78 Ptr := Ptr + 1;
79 end if;
80 end if;
82 exception
83 when Constraint_Error =>
84 Osint.Fail
85 ("numeric value out of range for switch: ", (1 => S));
86 end;
88 return Result;
89 end Get_Stack_Size;
91 -- Start of processing for Scan_Binder_Switches
93 begin
94 -- Skip past the initial character (must be the switch character)
96 if Ptr = Max then
97 Bad_Switch (Switch_Chars);
98 else
99 Ptr := Ptr + 1;
100 end if;
102 -- A little check, "gnat" at the start of a switch is not allowed
103 -- except for the compiler
105 if Switch_Chars'Last >= Ptr + 3
106 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
107 then
108 Osint.Fail ("invalid switch: """, Switch_Chars, """"
109 & " (gnat not needed here)");
110 end if;
112 -- Loop to scan through switches given in switch string
114 Check_Switch : begin
115 C := Switch_Chars (Ptr);
117 case C is
119 -- Processing for a switch
121 when 'a' =>
122 Ptr := Ptr + 1;
123 Use_Pragma_Linker_Constructor := True;
125 -- Processing for A switch
127 when 'A' =>
128 Ptr := Ptr + 1;
129 Ada_Bind_File := True;
131 -- Processing for b switch
133 when 'b' =>
134 Ptr := Ptr + 1;
135 Brief_Output := True;
137 -- Processing for c switch
139 when 'c' =>
140 Ptr := Ptr + 1;
142 Check_Only := True;
144 -- Processing for C switch
146 when 'C' =>
147 Ptr := Ptr + 1;
149 Ada_Bind_File := False;
151 -- Processing for d switch
153 when 'd' =>
155 if Ptr = Max then
156 Bad_Switch (Switch_Chars);
157 end if;
159 Ptr := Ptr + 1;
160 C := Switch_Chars (Ptr);
162 -- Case where character after -d is a digit (default stack size)
164 if C in '0' .. '9' then
166 -- In this case, we process the default primary stack size
168 Default_Stack_Size := Get_Stack_Size ('d');
170 -- Case where character after -d is not digit (debug flags)
172 else
173 -- Note: for the debug switch, the remaining characters in this
174 -- switch field must all be debug flags, since all valid switch
175 -- characters are also valid debug characters. This switch is
176 -- not documented on purpose because it is only used by the
177 -- implementors.
179 -- Loop to scan out debug flags
181 loop
182 C := Switch_Chars (Ptr);
184 if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
185 Set_Debug_Flag (C);
186 else
187 Bad_Switch (Switch_Chars);
188 end if;
190 Ptr := Ptr + 1;
191 exit when Ptr > Max;
192 end loop;
193 end if;
195 -- Processing for D switch
197 when 'D' =>
198 if Ptr = Max then
199 Bad_Switch (Switch_Chars);
200 end if;
202 Ptr := Ptr + 1;
203 Default_Sec_Stack_Size := Get_Stack_Size ('D');
205 -- Processing for e switch
207 when 'e' =>
208 Ptr := Ptr + 1;
209 Elab_Dependency_Output := True;
211 -- Processing for E switch
213 when 'E' =>
214 Ptr := Ptr + 1;
215 Exception_Tracebacks := True;
217 -- Processing for F switch
219 when 'F' =>
220 Ptr := Ptr + 1;
221 Force_Checking_Of_Elaboration_Flags := True;
223 -- Processing for g switch
225 when 'g' =>
226 Ptr := Ptr + 1;
228 if Ptr <= Max then
229 C := Switch_Chars (Ptr);
231 if C in '0' .. '3' then
232 Debugger_Level :=
233 Character'Pos
234 (Switch_Chars (Ptr)) - Character'Pos ('0');
235 Ptr := Ptr + 1;
236 end if;
238 else
239 Debugger_Level := 2;
240 end if;
242 -- Processing for h switch
244 when 'h' =>
245 Ptr := Ptr + 1;
246 Usage_Requested := True;
248 -- Processing for i switch
250 when 'i' =>
251 if Ptr = Max then
252 Bad_Switch (Switch_Chars);
253 end if;
255 Ptr := Ptr + 1;
256 C := Switch_Chars (Ptr);
258 if C in '1' .. '5'
259 or else C = '8'
260 or else C = 'p'
261 or else C = 'f'
262 or else C = 'n'
263 or else C = 'w'
264 then
265 Identifier_Character_Set := C;
266 Ptr := Ptr + 1;
267 else
268 Bad_Switch (Switch_Chars);
269 end if;
271 -- Processing for K switch
273 when 'K' =>
274 Ptr := Ptr + 1;
275 Output_Linker_Option_List := True;
277 -- Processing for l switch
279 when 'l' =>
280 Ptr := Ptr + 1;
281 Elab_Order_Output := True;
283 -- Processing for m switch
285 when 'm' =>
286 if Ptr = Max then
287 Bad_Switch (Switch_Chars);
288 end if;
290 Ptr := Ptr + 1;
291 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
293 -- Processing for n switch
295 when 'n' =>
296 Ptr := Ptr + 1;
297 Bind_Main_Program := False;
299 -- Note: The -L option of the binder also implies -n, so
300 -- any change here must also be reflected in the processing
301 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
303 -- Processing for o switch
305 when 'o' =>
306 Ptr := Ptr + 1;
308 if Output_File_Name_Present then
309 Osint.Fail ("duplicate -o switch");
311 else
312 Output_File_Name_Present := True;
313 end if;
315 -- Processing for O switch
317 when 'O' =>
318 Ptr := Ptr + 1;
319 Output_Object_List := True;
321 -- Processing for p switch
323 when 'p' =>
324 Ptr := Ptr + 1;
325 Pessimistic_Elab_Order := True;
327 -- Processing for q switch
329 when 'q' =>
330 Ptr := Ptr + 1;
331 Quiet_Output := True;
333 -- Processing for r switch
335 when 'r' =>
336 Ptr := Ptr + 1;
337 List_Restrictions := True;
339 -- Processing for s switch
341 when 's' =>
342 Ptr := Ptr + 1;
343 All_Sources := True;
344 Check_Source_Files := True;
346 -- Processing for t switch
348 when 't' =>
349 Ptr := Ptr + 1;
350 Tolerate_Consistency_Errors := True;
352 -- Processing for T switch
354 when 'T' =>
355 if Ptr = Max then
356 Bad_Switch (Switch_Chars);
357 end if;
359 Ptr := Ptr + 1;
360 Time_Slice_Set := True;
361 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
362 Time_Slice_Value := Time_Slice_Value * 1_000;
364 -- Processing for u switch
366 when 'u' =>
367 if Ptr = Max then
368 Bad_Switch (Switch_Chars);
369 end if;
371 Ptr := Ptr + 1;
372 Dynamic_Stack_Measurement := True;
373 Scan_Nat
374 (Switch_Chars,
375 Max,
376 Ptr,
377 Dynamic_Stack_Measurement_Array_Size,
380 -- Processing for v switch
382 when 'v' =>
383 Ptr := Ptr + 1;
384 Verbose_Mode := True;
386 -- Processing for w switch
388 when 'w' =>
389 if Ptr = Max then
390 Bad_Switch (Switch_Chars);
391 end if;
393 -- For the binder we only allow suppress/error cases
395 Ptr := Ptr + 1;
397 case Switch_Chars (Ptr) is
399 when 'e' =>
400 Warning_Mode := Treat_As_Error;
402 when 's' =>
403 Warning_Mode := Suppress;
405 when others =>
406 Bad_Switch (Switch_Chars);
407 end case;
409 Ptr := Ptr + 1;
411 -- Processing for W switch
413 when 'W' =>
414 if Ptr = Max then
415 Bad_Switch (Switch_Chars);
416 end if;
418 Ptr := Ptr + 1;
420 for J in WC_Encoding_Method loop
421 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
422 Wide_Character_Encoding_Method := J;
423 exit;
425 elsif J = WC_Encoding_Method'Last then
426 Bad_Switch (Switch_Chars);
427 end if;
428 end loop;
430 Upper_Half_Encoding :=
431 Wide_Character_Encoding_Method in
432 WC_Upper_Half_Encoding_Method;
434 Ptr := Ptr + 1;
436 -- Processing for x switch
438 when 'x' =>
439 Ptr := Ptr + 1;
440 All_Sources := False;
441 Check_Source_Files := False;
443 -- Processing for X switch
445 when 'X' =>
446 if Ptr = Max then
447 Bad_Switch (Switch_Chars);
448 end if;
450 Ptr := Ptr + 1;
451 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
453 -- Processing for z switch
455 when 'z' =>
456 Ptr := Ptr + 1;
457 No_Main_Subprogram := True;
459 -- Processing for --RTS
461 when '-' =>
463 if Ptr + 4 <= Max and then
464 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
465 then
466 Ptr := Ptr + 4;
468 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
469 Osint.Fail ("missing path for --RTS");
471 else
472 -- valid --RTS switch
474 Opt.No_Stdinc := True;
475 Opt.RTS_Switch := True;
477 declare
478 Src_Path_Name : constant String_Ptr :=
479 Get_RTS_Search_Dir
480 (Switch_Chars
481 (Ptr + 1 .. Switch_Chars'Last),
482 Include);
483 Lib_Path_Name : constant String_Ptr :=
484 Get_RTS_Search_Dir
485 (Switch_Chars
486 (Ptr + 1 .. Switch_Chars'Last),
487 Objects);
489 begin
490 if Src_Path_Name /= null and then
491 Lib_Path_Name /= null
492 then
493 -- Set the RTS_*_Path_Name variables, so that the
494 -- correct directories will be set when
495 -- Osint.Add_Default_Search_Dirs will be called later.
497 RTS_Src_Path_Name := Src_Path_Name;
498 RTS_Lib_Path_Name := Lib_Path_Name;
500 Ptr := Max + 1;
502 elsif Src_Path_Name = null
503 and then Lib_Path_Name = null
504 then
505 Osint.Fail ("RTS path not valid: missing " &
506 "adainclude and adalib directories");
507 elsif Src_Path_Name = null then
508 Osint.Fail ("RTS path not valid: missing " &
509 "adainclude directory");
510 elsif Lib_Path_Name = null then
511 Osint.Fail ("RTS path not valid: missing " &
512 "adalib directory");
513 end if;
514 end;
515 end if;
517 else
518 Bad_Switch (Switch_Chars);
519 end if;
521 -- Anything else is an error (illegal switch character)
523 when others =>
524 Bad_Switch (Switch_Chars);
525 end case;
527 if Ptr <= Max then
528 Bad_Switch (Switch_Chars);
529 end if;
530 end Check_Switch;
531 end Scan_Binder_Switches;
533 end Switch.B;