1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2005 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;
45 -- Skip past the initial character (must be the switch character)
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"
59 Osint.Fail ("invalid switch: """, Switch_Chars, """"
60 & " (gnat not needed here)");
63 -- Loop to scan through switches given in switch string
66 C := Switch_Chars (Ptr);
70 -- Processing for a switch
74 Use_Pragma_Linker_Constructor := True;
76 -- Processing for A switch
80 Ada_Bind_File := True;
82 -- Processing for b switch
88 -- Processing for c switch
95 -- Processing for C switch
100 Ada_Bind_File := False;
102 -- Processing for d switch
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
112 -- Loop to scan out debug flags
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
129 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
130 -- is for backwards compatibility with old versions and usage.
132 if Debug_Flag_XX then
133 Zero_Cost_Exceptions_Set := True;
134 Zero_Cost_Exceptions_Val := True;
139 -- Processing for D switch
143 Scan_Pos (Switch_Chars, Max, Ptr, Default_Sec_Stack_Size);
145 -- Processing for e switch
149 Elab_Dependency_Output := True;
151 -- Processing for E switch
155 Exception_Tracebacks := True;
157 -- Processing for F switch
161 Force_Checking_Of_Elaboration_Flags := True;
163 -- Processing for g switch
169 C := Switch_Chars (Ptr);
171 if C in '0' .. '3' then
174 (Switch_Chars (Ptr)) - Character'Pos ('0');
182 -- Processing for h switch
186 Usage_Requested := True;
188 -- Processing for i switch
196 C := Switch_Chars (Ptr);
205 Identifier_Character_Set := C;
211 -- Processing for K switch
215 Output_Linker_Option_List := True;
217 -- Processing for l switch
221 Elab_Order_Output := True;
223 -- Processing for m switch
227 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
229 -- Processing for n switch
233 Bind_Main_Program := False;
235 -- Note: The -L option of the binder also implies -n, so
236 -- any change here must also be reflected in the processing
237 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
239 -- Processing for o switch
244 if Output_File_Name_Present then
245 raise Too_Many_Output_Files;
248 Output_File_Name_Present := True;
251 -- Processing for O switch
255 Output_Object_List := True;
257 -- Processing for p switch
261 Pessimistic_Elab_Order := True;
263 -- Processing for q switch
267 Quiet_Output := True;
269 -- Processing for r switch
273 List_Restrictions := True;
275 -- Processing for s switch
280 Check_Source_Files := True;
282 -- Processing for t switch
286 Tolerate_Consistency_Errors := True;
288 -- Processing for T switch
292 Time_Slice_Set := True;
293 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
294 Time_Slice_Value := Time_Slice_Value * 1_000;
296 -- Processing for v switch
300 Verbose_Mode := True;
302 -- Processing for w switch
306 -- For the binder we only allow suppress/error cases
310 case Switch_Chars (Ptr) is
313 Warning_Mode := Treat_As_Error;
316 Warning_Mode := Suppress;
324 -- Processing for W switch
329 for J in WC_Encoding_Method loop
330 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
331 Wide_Character_Encoding_Method := J;
334 elsif J = WC_Encoding_Method'Last then
339 Upper_Half_Encoding :=
340 Wide_Character_Encoding_Method in
341 WC_Upper_Half_Encoding_Method;
345 -- Processing for x switch
349 All_Sources := False;
350 Check_Source_Files := False;
352 -- Processing for X switch
356 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status);
358 -- Processing for z switch
362 No_Main_Subprogram := True;
364 -- Ignore extra switch character
369 -- Ignore '-' extra switch caracter, only if it isn't followed by
370 -- 'RTS'. If it is, then we must process the 'RTS' switch
374 if Ptr + 3 <= Max and then
375 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
379 if Switch_Chars (Ptr + 3) /= '=' or else
380 (Switch_Chars (Ptr + 3) = '='
381 and then Ptr + 4 > Max)
383 Osint.Fail ("missing path for --RTS");
386 -- valid --RTS switch
387 Opt.No_Stdinc := True;
388 Opt.RTS_Switch := True;
391 Src_Path_Name : constant String_Ptr :=
394 (Ptr + 4 .. Switch_Chars'Last),
396 Lib_Path_Name : constant String_Ptr :=
399 (Ptr + 4 .. Switch_Chars'Last),
403 if Src_Path_Name /= null and then
404 Lib_Path_Name /= null
406 -- Set the RTS_*_Path_Name variables, so that the
407 -- correct directories will be set when
408 -- Osint.Add_Default_Search_Dirs will be called later.
410 RTS_Src_Path_Name := Src_Path_Name;
411 RTS_Lib_Path_Name := Lib_Path_Name;
413 -- We can exit as there can not be another switch
418 elsif Src_Path_Name = null
419 and then Lib_Path_Name = null
421 Osint.Fail ("RTS path not valid: missing " &
422 "adainclude and adalib directories");
423 elsif Src_Path_Name = null then
424 Osint.Fail ("RTS path not valid: missing " &
425 "adainclude directory");
426 elsif Lib_Path_Name = null then
427 Osint.Fail ("RTS path not valid: missing " &
437 -- Anything else is an error (illegal switch character)
446 Osint.Fail ("invalid switch: ", (1 => C));
448 when Bad_Switch_Value =>
449 Osint.Fail ("numeric value out of range for switch: ", (1 => C));
451 when Missing_Switch_Value =>
452 Osint.Fail ("missing numeric value for switch: ", (1 => C));
454 when Too_Many_Output_Files =>
455 Osint.Fail ("duplicate -o switch");
456 end Scan_Binder_Switches;