1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Debug; use Debug;
27 with Osint; use Osint;
30 with System.WCh_Con; use System.WCh_Con;
32 package body Switch.B is
34 --------------------------
35 -- Scan_Binder_Switches --
36 --------------------------
38 procedure Scan_Binder_Switches (Switch_Chars : String) is
39 Max : constant Integer := Switch_Chars'Last;
40 Ptr : Integer := Switch_Chars'First;
43 function Get_Stack_Size (S : Character) return Int;
44 -- Used for -d and -D to scan stack size including handling k/m.
45 -- S is set to 'd' or 'D' to indicate the switch being scanned.
51 function Get_Stack_Size (S : Character) return Int is
55 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
57 -- In the following code, we enable overflow checking since the
58 -- multiplication by K or M may cause overflow, which is an error.
61 pragma Unsuppress (Overflow_Check);
64 -- Check for additional character 'k' (for kilobytes) or 'm'
65 -- (for Megabytes), but only if we have not reached the end
66 -- of the switch string. Note that if this appears before the
67 -- end of the string we will get an error when we test to make
68 -- sure that the string is exhausted (at the end of the case).
71 if Switch_Chars (Ptr) = 'k' then
72 Result := Result * 1024;
75 elsif Switch_Chars (Ptr) = 'm' then
76 Result := Result * (1024 * 1024);
82 when Constraint_Error =>
83 Osint.Fail ("numeric value out of range for switch: " & S);
89 -- Start of processing for Scan_Binder_Switches
92 -- Skip past the initial character (must be the switch character)
95 Bad_Switch (Switch_Chars);
100 -- A little check, "gnat" at the start of a switch is not allowed
101 -- except for the compiler
103 if Switch_Chars'Last >= Ptr + 3
104 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
106 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
107 & " (gnat not needed here)");
110 -- Loop to scan through switches given in switch string
113 C := Switch_Chars (Ptr);
117 -- Processing for a switch
121 Use_Pragma_Linker_Constructor := True;
123 -- Processing for A switch
127 Ada_Bind_File := True;
129 -- Processing for b switch
133 Brief_Output := True;
135 -- Processing for c switch
142 -- Processing for C switch
147 Ada_Bind_File := False;
149 -- Processing for d switch
154 Bad_Switch (Switch_Chars);
158 C := Switch_Chars (Ptr);
160 -- Case where character after -d is a digit (default stack size)
162 if C in '0' .. '9' then
164 -- In this case, we process the default primary stack size
166 Default_Stack_Size := Get_Stack_Size ('d');
168 -- Case where character after -d is not digit (debug flags)
171 -- Note: for the debug switch, the remaining characters in this
172 -- switch field must all be debug flags, since all valid switch
173 -- characters are also valid debug characters. This switch is
174 -- not documented on purpose because it is only used by the
177 -- Loop to scan out debug flags
180 C := Switch_Chars (Ptr);
182 if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
185 Bad_Switch (Switch_Chars);
193 -- Processing for D switch
197 Bad_Switch (Switch_Chars);
201 Default_Sec_Stack_Size := Get_Stack_Size ('D');
203 -- Processing for e switch
207 Elab_Dependency_Output := True;
209 -- Processing for E switch
213 Exception_Tracebacks := True;
215 -- Processing for F switch
219 Force_Checking_Of_Elaboration_Flags := True;
221 -- Processing for g switch
227 C := Switch_Chars (Ptr);
229 if C in '0' .. '3' then
232 (Switch_Chars (Ptr)) - Character'Pos ('0');
240 -- Processing for h switch
244 Usage_Requested := True;
246 -- Processing for i switch
250 Bad_Switch (Switch_Chars);
254 C := Switch_Chars (Ptr);
263 Identifier_Character_Set := C;
266 Bad_Switch (Switch_Chars);
269 -- Processing for K switch
273 Output_Linker_Option_List := True;
275 -- Processing for l switch
279 Elab_Order_Output := True;
281 -- Processing for m switch
285 Bad_Switch (Switch_Chars);
289 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
291 -- Processing for n switch
295 Bind_Main_Program := False;
297 -- Note: The -L option of the binder also implies -n, so
298 -- any change here must also be reflected in the processing
299 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
301 -- Processing for o switch
306 if Output_File_Name_Present then
307 Osint.Fail ("duplicate -o switch");
310 Output_File_Name_Present := True;
313 -- Processing for O switch
317 Output_Object_List := True;
319 -- Processing for p switch
323 Pessimistic_Elab_Order := True;
325 -- Processing for q switch
329 Quiet_Output := True;
331 -- Processing for r switch
335 List_Restrictions := True;
337 -- Processing for R switch
342 List_Closure := True;
344 -- Processing for s switch
349 Check_Source_Files := True;
351 -- Processing for t switch
355 Tolerate_Consistency_Errors := True;
357 -- Processing for T switch
361 Bad_Switch (Switch_Chars);
365 Time_Slice_Set := True;
366 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
367 Time_Slice_Value := Time_Slice_Value * 1_000;
369 -- Processing for u switch
373 Bad_Switch (Switch_Chars);
377 Dynamic_Stack_Measurement := True;
382 Dynamic_Stack_Measurement_Array_Size,
385 -- Processing for v switch
389 Verbose_Mode := True;
391 -- Processing for w switch
395 Bad_Switch (Switch_Chars);
398 -- For the binder we only allow suppress/error cases
402 case Switch_Chars (Ptr) is
405 Warning_Mode := Treat_As_Error;
408 Warning_Mode := Suppress;
411 Bad_Switch (Switch_Chars);
416 -- Processing for W switch
422 Bad_Switch (Switch_Chars);
426 Wide_Character_Encoding_Method :=
427 Get_WC_Encoding_Method (Switch_Chars (Ptr));
429 when Constraint_Error =>
430 Bad_Switch (Switch_Chars);
433 Wide_Character_Encoding_Method_Specified := True;
435 Upper_Half_Encoding :=
436 Wide_Character_Encoding_Method in
437 WC_Upper_Half_Encoding_Method;
441 -- Processing for x switch
445 All_Sources := False;
446 Check_Source_Files := False;
448 -- Processing for X switch
452 Bad_Switch (Switch_Chars);
456 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
458 -- Processing for y switch
462 Leap_Seconds_Support := True;
464 -- Processing for z switch
468 No_Main_Subprogram := True;
470 -- Processing for Z switch
474 Zero_Formatting := True;
476 -- Processing for --RTS
480 if Ptr + 4 <= Max and then
481 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
485 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
486 Osint.Fail ("missing path for --RTS");
489 -- valid --RTS switch
491 Opt.No_Stdinc := True;
492 Opt.RTS_Switch := True;
495 Src_Path_Name : constant String_Ptr :=
498 (Ptr + 1 .. Switch_Chars'Last),
500 Lib_Path_Name : constant String_Ptr :=
503 (Ptr + 1 .. Switch_Chars'Last),
507 if Src_Path_Name /= null and then
508 Lib_Path_Name /= null
510 -- Set the RTS_*_Path_Name variables, so that the
511 -- correct directories will be set when
512 -- Osint.Add_Default_Search_Dirs will be called later.
514 RTS_Src_Path_Name := Src_Path_Name;
515 RTS_Lib_Path_Name := Lib_Path_Name;
519 elsif Src_Path_Name = null
520 and then Lib_Path_Name = null
522 Osint.Fail ("RTS path not valid: missing " &
523 "adainclude and adalib directories");
524 elsif Src_Path_Name = null then
525 Osint.Fail ("RTS path not valid: missing " &
526 "adainclude directory");
527 elsif Lib_Path_Name = null then
528 Osint.Fail ("RTS path not valid: missing " &
535 Bad_Switch (Switch_Chars);
538 -- Anything else is an error (illegal switch character)
541 Bad_Switch (Switch_Chars);
545 Bad_Switch (Switch_Chars);
548 end Scan_Binder_Switches;