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_Optional_Filename
return String_Ptr
;
45 -- If current character is '=', return a newly allocated string that
46 -- contains the remainder of the current switch (after the '='), else
49 function Get_Stack_Size
(S
: Character) return Int
;
50 -- Used for -d and -D to scan stack size including handling k/m. S is
51 -- set to 'd' or 'D' to indicate the switch being scanned.
53 ---------------------------
54 -- Get_Optional_Filename --
55 ---------------------------
57 function Get_Optional_Filename
return String_Ptr
is
61 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
63 Bad_Switch
(Switch_Chars
);
65 Result
:= new String'(Switch_Chars (Ptr + 1 .. Max));
72 end Get_Optional_Filename;
78 function Get_Stack_Size (S : Character) return Int is
82 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
84 -- In the following code, we enable overflow checking since the
85 -- multiplication by K or M may cause overflow, which is an error.
88 pragma Unsuppress (Overflow_Check);
91 -- Check for additional character 'k
' (for kilobytes) or 'm
' (for
92 -- Megabytes), but only if we have not reached the end of the
93 -- switch string. Note that if this appears before the end of the
94 -- string we will get an error when we test to make sure that the
95 -- string is exhausted (at the end of the case).
98 if Switch_Chars (Ptr) = 'k
' then
99 Result := Result * 1024;
102 elsif Switch_Chars (Ptr) = 'm
' then
103 Result := Result * (1024 * 1024);
109 when Constraint_Error =>
110 Osint.Fail ("numeric value out of range for switch: " & S);
116 -- Start of processing for Scan_Binder_Switches
119 -- Skip past the initial character (must be the switch character)
122 Bad_Switch (Switch_Chars);
127 -- A little check, "gnat" at the start of a switch is not allowed except
130 if Switch_Chars'Last >= Ptr + 3
131 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
133 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
134 & " (gnat not needed here)");
137 -- Loop to scan through switches given in switch string
140 C := Switch_Chars (Ptr);
144 -- Processing for a switch
148 Use_Pragma_Linker_Constructor := True;
150 -- Processing for A switch
154 Output_ALI_List := True;
155 ALI_List_Filename := Get_Optional_Filename;
157 -- Processing for b switch
161 Brief_Output := True;
163 -- Processing for c switch
169 -- Processing for C switch
173 Ada_Bind_File := False;
175 Write_Line ("warning: gnatbind switch -C is obsolescent");
177 -- Processing for d switch
182 Bad_Switch (Switch_Chars);
186 C := Switch_Chars (Ptr);
188 -- Case where character after -d is a digit (default stack size)
190 if C in '0' .. '9' then
192 -- In this case, we process the default primary stack size
194 Default_Stack_Size := Get_Stack_Size ('d
');
196 -- Case where character after -d is not digit (debug flags)
199 -- Note: for the debug switch, the remaining characters in this
200 -- switch field must all be debug flags, since all valid switch
201 -- characters are also valid debug characters. This switch is
202 -- not documented on purpose because it is only used by the
205 -- Loop to scan out debug flags
208 C := Switch_Chars (Ptr);
210 if C in 'a
' .. 'z
' or else C in 'A
' .. 'Z
' then
213 Bad_Switch (Switch_Chars);
221 -- Processing for D switch
225 Bad_Switch (Switch_Chars);
229 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
231 -- Processing for e switch
235 Elab_Dependency_Output := True;
237 -- Processing for E switch
241 Exception_Tracebacks := True;
243 -- Processing for F switch
247 Force_Checking_Of_Elaboration_Flags := True;
249 -- Processing for g switch
255 C := Switch_Chars (Ptr);
257 if C in '0' .. '3' then
260 (Switch_Chars (Ptr)) - Character'Pos ('0');
268 -- Processing for h switch
272 Usage_Requested := True;
274 -- Processing for H switch
278 Bad_Switch (Switch_Chars);
282 Scan_Nat (Switch_Chars, Max, Ptr, Heap_Size, C);
284 if Heap_Size /= 32 and then Heap_Size /= 64 then
285 Bad_Switch (Switch_Chars);
288 -- Processing for i switch
292 Bad_Switch (Switch_Chars);
296 C := Switch_Chars (Ptr);
305 Identifier_Character_Set := C;
308 Bad_Switch (Switch_Chars);
311 -- Processing for K switch
315 Output_Linker_Option_List := True;
317 -- Processing for l switch
321 Elab_Order_Output := True;
323 -- Processing for m switch
327 Bad_Switch (Switch_Chars);
331 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
333 -- Processing for n switch
337 Bind_Main_Program := False;
339 -- Note: The -L option of the binder also implies -n, so
340 -- any change here must also be reflected in the processing
341 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
343 -- Processing for o switch
348 if Output_File_Name_Present then
349 Osint.Fail ("duplicate -o switch");
351 Output_File_Name_Present := True;
354 -- Processing for O switch
358 Output_Object_List := True;
359 Object_List_Filename := Get_Optional_Filename;
361 -- Processing for p switch
365 Pessimistic_Elab_Order := True;
367 -- Processing for q switch
371 Quiet_Output := True;
373 -- Processing for r switch
377 List_Restrictions := True;
379 -- Processing for R switch
383 List_Closure := True;
385 -- Processing for s switch
390 Check_Source_Files := True;
392 -- Processing for t switch
396 Tolerate_Consistency_Errors := True;
398 -- Processing for T switch
402 Bad_Switch (Switch_Chars);
406 Time_Slice_Set := True;
407 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
408 Time_Slice_Value := Time_Slice_Value * 1_000;
410 -- Processing for u switch
414 Bad_Switch (Switch_Chars);
418 Dynamic_Stack_Measurement := True;
423 Dynamic_Stack_Measurement_Array_Size,
426 -- Processing for v switch
430 Verbose_Mode := True;
432 -- Processing for w switch
436 Bad_Switch (Switch_Chars);
439 -- For the binder we only allow suppress/error cases
443 case Switch_Chars (Ptr) is
445 Warning_Mode := Treat_As_Error;
448 Warning_Mode := Suppress;
451 Bad_Switch (Switch_Chars);
456 -- Processing for W switch
462 Bad_Switch (Switch_Chars);
466 Wide_Character_Encoding_Method :=
467 Get_WC_Encoding_Method (Switch_Chars (Ptr));
469 when Constraint_Error =>
470 Bad_Switch (Switch_Chars);
473 Wide_Character_Encoding_Method_Specified := True;
475 Upper_Half_Encoding :=
476 Wide_Character_Encoding_Method in WC_Upper_Half_Encoding_Method;
480 -- Processing for x switch
484 All_Sources := False;
485 Check_Source_Files := False;
487 -- Processing for X switch
491 Bad_Switch (Switch_Chars);
495 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
497 -- Processing for y switch
501 Leap_Seconds_Support := True;
503 -- Processing for z switch
507 No_Main_Subprogram := True;
509 -- Processing for Z switch
513 Zero_Formatting := True;
515 -- Processing for --RTS
519 if Ptr + 4 <= Max and then
520 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
524 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
525 Osint.Fail ("missing path for --RTS");
528 -- Valid --RTS switch
530 Opt.No_Stdinc := True;
531 Opt.RTS_Switch := True;
534 Src_Path_Name : constant String_Ptr :=
537 (Ptr + 1 .. Switch_Chars'Last),
539 Lib_Path_Name : constant String_Ptr :=
542 (Ptr + 1 .. Switch_Chars'Last),
546 if Src_Path_Name /= null and then
547 Lib_Path_Name /= null
549 -- Set the RTS_*_Path_Name variables, so that the
550 -- correct directories will be set when a subsequent
551 -- call Osint.Add_Default_Search_Dirs is made.
553 RTS_Src_Path_Name := Src_Path_Name;
554 RTS_Lib_Path_Name := Lib_Path_Name;
558 elsif Src_Path_Name = null
559 and then Lib_Path_Name = null
561 Osint.Fail ("RTS path not valid: missing " &
562 "adainclude and adalib directories");
563 elsif Src_Path_Name = null then
564 Osint.Fail ("RTS path not valid: missing " &
565 "adainclude directory");
566 elsif Lib_Path_Name = null then
567 Osint.Fail ("RTS path not valid: missing " &
574 Bad_Switch (Switch_Chars);
577 -- Anything else is an error (illegal switch character)
580 Bad_Switch (Switch_Chars);
584 Bad_Switch (Switch_Chars);
587 end Scan_Binder_Switches;