1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2006, 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 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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Debug; use Debug;
28 with Osint; use Osint;
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 =>
85 ("numeric value out of range for switch: ", (1 => S));
91 -- Start of processing for Scan_Binder_Switches
94 -- Skip past the initial character (must be the switch character)
97 Bad_Switch (Switch_Chars);
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"
108 Osint.Fail ("invalid switch: """, Switch_Chars, """"
109 & " (gnat not needed here)");
112 -- Loop to scan through switches given in switch string
115 C := Switch_Chars (Ptr);
119 -- Processing for a switch
123 Use_Pragma_Linker_Constructor := True;
125 -- Processing for A switch
129 Ada_Bind_File := True;
131 -- Processing for b switch
135 Brief_Output := True;
137 -- Processing for c switch
144 -- Processing for C switch
149 Ada_Bind_File := False;
151 -- Processing for d switch
156 Bad_Switch (Switch_Chars);
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)
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
179 -- Loop to scan out debug flags
182 C := Switch_Chars (Ptr);
184 if C in 'a' .. 'z' or else C in 'A' .. 'Z' then
187 Bad_Switch (Switch_Chars);
195 -- Processing for D switch
199 Bad_Switch (Switch_Chars);
203 Default_Sec_Stack_Size := Get_Stack_Size ('D');
205 -- Processing for e switch
209 Elab_Dependency_Output := True;
211 -- Processing for E switch
215 Exception_Tracebacks := True;
217 -- Processing for F switch
221 Force_Checking_Of_Elaboration_Flags := True;
223 -- Processing for g switch
229 C := Switch_Chars (Ptr);
231 if C in '0' .. '3' then
234 (Switch_Chars (Ptr)) - Character'Pos ('0');
242 -- Processing for h switch
246 Usage_Requested := True;
248 -- Processing for i switch
252 Bad_Switch (Switch_Chars);
256 C := Switch_Chars (Ptr);
265 Identifier_Character_Set := C;
268 Bad_Switch (Switch_Chars);
271 -- Processing for K switch
275 Output_Linker_Option_List := True;
277 -- Processing for l switch
281 Elab_Order_Output := True;
283 -- Processing for m switch
287 Bad_Switch (Switch_Chars);
291 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors, C);
293 -- Processing for n switch
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
308 if Output_File_Name_Present then
309 Osint.Fail ("duplicate -o switch");
312 Output_File_Name_Present := True;
315 -- Processing for O switch
319 Output_Object_List := True;
321 -- Processing for p switch
325 Pessimistic_Elab_Order := True;
327 -- Processing for q switch
331 Quiet_Output := True;
333 -- Processing for r switch
337 List_Restrictions := True;
339 -- Processing for R switch
344 List_Closure := True;
346 -- Processing for s switch
351 Check_Source_Files := True;
353 -- Processing for t switch
357 Tolerate_Consistency_Errors := True;
359 -- Processing for T switch
363 Bad_Switch (Switch_Chars);
367 Time_Slice_Set := True;
368 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
369 Time_Slice_Value := Time_Slice_Value * 1_000;
371 -- Processing for u switch
375 Bad_Switch (Switch_Chars);
379 Dynamic_Stack_Measurement := True;
384 Dynamic_Stack_Measurement_Array_Size,
387 -- Processing for v switch
391 Verbose_Mode := True;
393 -- Processing for w switch
397 Bad_Switch (Switch_Chars);
400 -- For the binder we only allow suppress/error cases
404 case Switch_Chars (Ptr) is
407 Warning_Mode := Treat_As_Error;
410 Warning_Mode := Suppress;
413 Bad_Switch (Switch_Chars);
418 -- Processing for W switch
422 Bad_Switch (Switch_Chars);
427 for J in WC_Encoding_Method loop
428 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
429 Wide_Character_Encoding_Method := J;
432 elsif J = WC_Encoding_Method'Last then
433 Bad_Switch (Switch_Chars);
437 Upper_Half_Encoding :=
438 Wide_Character_Encoding_Method in
439 WC_Upper_Half_Encoding_Method;
443 -- Processing for x switch
447 All_Sources := False;
448 Check_Source_Files := False;
450 -- Processing for X switch
454 Bad_Switch (Switch_Chars);
458 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
460 -- Processing for z switch
464 No_Main_Subprogram := True;
466 -- Processing for Z switch
470 Zero_Formatting := True;
472 -- Processing for --RTS
476 if Ptr + 4 <= Max and then
477 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
481 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
482 Osint.Fail ("missing path for --RTS");
485 -- valid --RTS switch
487 Opt.No_Stdinc := True;
488 Opt.RTS_Switch := True;
491 Src_Path_Name : constant String_Ptr :=
494 (Ptr + 1 .. Switch_Chars'Last),
496 Lib_Path_Name : constant String_Ptr :=
499 (Ptr + 1 .. Switch_Chars'Last),
503 if Src_Path_Name /= null and then
504 Lib_Path_Name /= null
506 -- Set the RTS_*_Path_Name variables, so that the
507 -- correct directories will be set when
508 -- Osint.Add_Default_Search_Dirs will be called later.
510 RTS_Src_Path_Name := Src_Path_Name;
511 RTS_Lib_Path_Name := Lib_Path_Name;
515 elsif Src_Path_Name = null
516 and then Lib_Path_Name = null
518 Osint.Fail ("RTS path not valid: missing " &
519 "adainclude and adalib directories");
520 elsif Src_Path_Name = null then
521 Osint.Fail ("RTS path not valid: missing " &
522 "adainclude directory");
523 elsif Lib_Path_Name = null then
524 Osint.Fail ("RTS path not valid: missing " &
531 Bad_Switch (Switch_Chars);
534 -- Anything else is an error (illegal switch character)
537 Bad_Switch (Switch_Chars);
541 Bad_Switch (Switch_Chars);
544 end Scan_Binder_Switches;