1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, 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;
29 with Output; use Output;
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;
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.
52 function Get_Stack_Size (S : Character) return Int is
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.
62 pragma Unsuppress (Overflow_Check);
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).
72 if Switch_Chars (Ptr) = 'k' then
73 Result := Result * 1024;
76 elsif Switch_Chars (Ptr) = 'm' then
77 Result := Result * (1024 * 1024);
83 when Constraint_Error =>
84 Osint.Fail ("numeric value out of range for switch: " & S);
90 -- Start of processing for Scan_Binder_Switches
93 -- Skip past the initial character (must be the switch character)
96 Bad_Switch (Switch_Chars);
101 -- A little check, "gnat" at the start of a switch is not allowed
102 -- except for the compiler
104 if Switch_Chars'Last >= Ptr + 3
105 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
107 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
108 & " (gnat not needed here)");
111 -- Loop to scan through switches given in switch string
114 C := Switch_Chars (Ptr);
118 -- Processing for a switch
122 Use_Pragma_Linker_Constructor := True;
124 -- Processing for A switch
128 Ada_Bind_File := True;
130 -- Processing for b switch
134 Brief_Output := True;
136 -- Processing for c switch
143 -- Processing for C switch
148 Ada_Bind_File := False;
150 Write_Line ("warning: gnatbind switch -C is obsolescent");
152 -- Processing for d switch
157 Bad_Switch (Switch_Chars);
161 C := Switch_Chars (Ptr);
163 -- Case where character after -d is a digit (default stack size)
165 if C in '0' .. '9' then
167 -- In this case, we process the default primary stack size
169 Default_Stack_Size := Get_Stack_Size ('d');
171 -- Case where character after -d is not digit (debug flags)
174 -- Note: for the debug switch, the remaining characters in this
175 -- switch field must all be debug flags, since all valid switch
176 -- characters are also valid debug characters. This switch is
177 -- not documented on purpose because it is only used by the
180 -- Loop to scan out debug flags
183 C := Switch_Chars (Ptr);
185 if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
188 Bad_Switch (Switch_Chars);
196 -- Processing for D switch
200 Bad_Switch (Switch_Chars);
204 Default_Sec_Stack_Size := Get_Stack_Size ('D');
206 -- Processing for e switch
210 Elab_Dependency_Output := True;
212 -- Processing for E switch
216 Exception_Tracebacks := True;
218 -- Processing for F switch
222 Force_Checking_Of_Elaboration_Flags := True;
224 -- Processing for g switch
230 C := Switch_Chars (Ptr);
232 if C in '0' .. '3' then
235 (Switch_Chars (Ptr)) - Character'Pos ('0');
243 -- Processing for h switch
247 Usage_Requested := True;
249 -- Processing for i switch
253 Bad_Switch (Switch_Chars);
257 C := Switch_Chars (Ptr);
266 Identifier_Character_Set := C;
269 Bad_Switch (Switch_Chars);
272 -- Processing for K switch
276 Output_Linker_Option_List := True;
278 -- Processing for l switch
282 Elab_Order_Output := True;
284 -- Processing for m switch
288 Bad_Switch (Switch_Chars);
292 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
294 -- Processing for n switch
298 Bind_Main_Program := False;
300 -- Note: The -L option of the binder also implies -n, so
301 -- any change here must also be reflected in the processing
302 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
304 -- Processing for o switch
309 if Output_File_Name_Present then
310 Osint.Fail ("duplicate -o switch");
313 Output_File_Name_Present := True;
316 -- Processing for O switch
320 Output_Object_List := True;
322 -- Processing for p switch
326 Pessimistic_Elab_Order := True;
328 -- Processing for q switch
332 Quiet_Output := True;
334 -- Processing for r switch
338 List_Restrictions := True;
340 -- Processing for R switch
345 List_Closure := True;
347 -- Processing for s switch
352 Check_Source_Files := True;
354 -- Processing for t switch
358 Tolerate_Consistency_Errors := True;
360 -- Processing for T switch
364 Bad_Switch (Switch_Chars);
368 Time_Slice_Set := True;
369 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
370 Time_Slice_Value := Time_Slice_Value * 1_000;
372 -- Processing for u switch
376 Bad_Switch (Switch_Chars);
380 Dynamic_Stack_Measurement := True;
385 Dynamic_Stack_Measurement_Array_Size,
388 -- Processing for v switch
392 Verbose_Mode := True;
394 -- Processing for w switch
398 Bad_Switch (Switch_Chars);
401 -- For the binder we only allow suppress/error cases
405 case Switch_Chars (Ptr) is
408 Warning_Mode := Treat_As_Error;
411 Warning_Mode := Suppress;
414 Bad_Switch (Switch_Chars);
419 -- Processing for W switch
425 Bad_Switch (Switch_Chars);
429 Wide_Character_Encoding_Method :=
430 Get_WC_Encoding_Method (Switch_Chars (Ptr));
432 when Constraint_Error =>
433 Bad_Switch (Switch_Chars);
436 Wide_Character_Encoding_Method_Specified := True;
438 Upper_Half_Encoding :=
439 Wide_Character_Encoding_Method in
440 WC_Upper_Half_Encoding_Method;
444 -- Processing for x switch
448 All_Sources := False;
449 Check_Source_Files := False;
451 -- Processing for X switch
455 Bad_Switch (Switch_Chars);
459 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
461 -- Processing for y switch
465 Leap_Seconds_Support := True;
467 -- Processing for z switch
471 No_Main_Subprogram := True;
473 -- Processing for Z switch
477 Zero_Formatting := True;
479 -- Processing for --RTS
483 if Ptr + 4 <= Max and then
484 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
488 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
489 Osint.Fail ("missing path for --RTS");
492 -- valid --RTS switch
494 Opt.No_Stdinc := True;
495 Opt.RTS_Switch := True;
498 Src_Path_Name : constant String_Ptr :=
501 (Ptr + 1 .. Switch_Chars'Last),
503 Lib_Path_Name : constant String_Ptr :=
506 (Ptr + 1 .. Switch_Chars'Last),
510 if Src_Path_Name /= null and then
511 Lib_Path_Name /= null
513 -- Set the RTS_*_Path_Name variables, so that the
514 -- correct directories will be set when
515 -- Osint.Add_Default_Search_Dirs will be called later.
517 RTS_Src_Path_Name := Src_Path_Name;
518 RTS_Lib_Path_Name := Lib_Path_Name;
522 elsif Src_Path_Name = null
523 and then Lib_Path_Name = null
525 Osint.Fail ("RTS path not valid: missing " &
526 "adainclude and adalib directories");
527 elsif Src_Path_Name = null then
528 Osint.Fail ("RTS path not valid: missing " &
529 "adainclude directory");
530 elsif Lib_Path_Name = null then
531 Osint.Fail ("RTS path not valid: missing " &
538 Bad_Switch (Switch_Chars);
541 -- Anything else is an error (illegal switch character)
544 Bad_Switch (Switch_Chars);
548 Bad_Switch (Switch_Chars);
551 end Scan_Binder_Switches;