1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2011, 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_Optional_Filename
return String_Ptr
;
44 -- If current character is '=', return a newly allocated string that
45 -- contains the remainder of the current switch (after the '='), else
48 function Get_Stack_Size
(S
: Character) return Int
;
49 -- Used for -d and -D to scan stack size including handling k/m. S is
50 -- set to 'd' or 'D' to indicate the switch being scanned.
52 ---------------------------
53 -- Get_Optional_Filename --
54 ---------------------------
56 function Get_Optional_Filename
return String_Ptr
is
60 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
62 Bad_Switch
(Switch_Chars
);
64 Result
:= new String'(Switch_Chars (Ptr + 1 .. Max));
71 end Get_Optional_Filename;
77 function Get_Stack_Size (S : Character) return Int is
81 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
83 -- In the following code, we enable overflow checking since the
84 -- multiplication by K or M may cause overflow, which is an error.
87 pragma Unsuppress (Overflow_Check);
90 -- Check for additional character 'k
' (for kilobytes) or 'm
' (for
91 -- Megabytes), but only if we have not reached the end of the
92 -- switch string. Note that if this appears before the end of the
93 -- string we will get an error when we test to make sure that the
94 -- string is exhausted (at the end of the case).
97 if Switch_Chars (Ptr) = 'k
' then
98 Result := Result * 1024;
101 elsif Switch_Chars (Ptr) = 'm
' then
102 Result := Result * (1024 * 1024);
108 when Constraint_Error =>
109 Osint.Fail ("numeric value out of range for switch: " & S);
115 -- Start of processing for Scan_Binder_Switches
118 -- Skip past the initial character (must be the switch character)
121 Bad_Switch (Switch_Chars);
126 -- A little check, "gnat" at the start of a switch is not allowed except
129 if Switch_Chars'Last >= Ptr + 3
130 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
132 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
133 & " (gnat not needed here)");
136 -- Loop to scan through switches given in switch string
139 C := Switch_Chars (Ptr);
143 -- Processing for a switch
147 Use_Pragma_Linker_Constructor := True;
149 -- Processing for A switch
153 Output_ALI_List := True;
154 ALI_List_Filename := Get_Optional_Filename;
156 -- Processing for b switch
160 Brief_Output := True;
162 -- Processing for c switch
168 -- Processing for d switch
173 Bad_Switch (Switch_Chars);
177 C := Switch_Chars (Ptr);
179 -- Case where character after -d is a digit (default stack size)
181 if C in '0' .. '9' then
183 -- In this case, we process the default primary stack size
185 Default_Stack_Size := Get_Stack_Size ('d
');
187 -- Case where character after -d is not digit (debug flags)
190 -- Note: for the debug switch, the remaining characters in this
191 -- switch field must all be debug flags, since all valid switch
192 -- characters are also valid debug characters. This switch is
193 -- not documented on purpose because it is only used by the
196 -- Loop to scan out debug flags
199 C := Switch_Chars (Ptr);
201 if C in 'a
' .. 'z
' or else C in 'A
' .. 'Z
' then
204 Bad_Switch (Switch_Chars);
212 -- Processing for D switch
216 Bad_Switch (Switch_Chars);
220 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
222 -- Processing for e switch
226 Elab_Dependency_Output := True;
228 -- Processing for E switch
232 Exception_Tracebacks := True;
234 -- Processing for F switch
238 Force_Checking_Of_Elaboration_Flags := True;
240 -- Processing for g switch
246 C := Switch_Chars (Ptr);
248 if C in '0' .. '3' then
251 (Switch_Chars (Ptr)) - Character'Pos ('0');
259 -- Processing for h switch
263 Usage_Requested := True;
265 -- Processing for H switch
269 Bad_Switch (Switch_Chars);
273 Scan_Nat (Switch_Chars, Max, Ptr, Heap_Size, C);
275 if Heap_Size /= 32 and then Heap_Size /= 64 then
276 Bad_Switch (Switch_Chars);
279 -- Processing for i switch
283 Bad_Switch (Switch_Chars);
287 C := Switch_Chars (Ptr);
296 Identifier_Character_Set := C;
299 Bad_Switch (Switch_Chars);
302 -- Processing for K switch
306 Output_Linker_Option_List := True;
308 -- Processing for l switch
312 Elab_Order_Output := True;
314 -- Processing for m switch
318 Bad_Switch (Switch_Chars);
322 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
324 -- Processing for n switch
328 Bind_Main_Program := False;
330 -- Note: The -L option of the binder also implies -n, so
331 -- any change here must also be reflected in the processing
332 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
334 -- Processing for o switch
339 if Output_File_Name_Present then
340 Osint.Fail ("duplicate -o switch");
342 Output_File_Name_Present := True;
345 -- Processing for O switch
349 Output_Object_List := True;
350 Object_List_Filename := Get_Optional_Filename;
352 -- Processing for p switch
356 Pessimistic_Elab_Order := True;
358 -- Processing for P switch
362 CodePeer_Mode := True;
364 -- Processing for q switch
368 Quiet_Output := True;
370 -- Processing for r switch
374 List_Restrictions := True;
376 -- Processing for R switch
380 List_Closure := True;
382 -- Processing for s switch
387 Check_Source_Files := True;
389 -- Processing for t switch
393 Tolerate_Consistency_Errors := True;
395 -- Processing for T switch
399 Bad_Switch (Switch_Chars);
403 Time_Slice_Set := True;
404 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
405 Time_Slice_Value := Time_Slice_Value * 1_000;
407 -- Processing for u switch
411 Bad_Switch (Switch_Chars);
415 Dynamic_Stack_Measurement := True;
420 Dynamic_Stack_Measurement_Array_Size,
423 -- Processing for v switch
427 Verbose_Mode := True;
429 -- Processing for w switch
433 Bad_Switch (Switch_Chars);
436 -- For the binder we only allow suppress/error cases
440 case Switch_Chars (Ptr) is
442 Warning_Mode := Treat_As_Error;
445 Warning_Mode := Suppress;
448 Bad_Switch (Switch_Chars);
453 -- Processing for W switch
459 Bad_Switch (Switch_Chars);
463 Wide_Character_Encoding_Method :=
464 Get_WC_Encoding_Method (Switch_Chars (Ptr));
466 when Constraint_Error =>
467 Bad_Switch (Switch_Chars);
470 Wide_Character_Encoding_Method_Specified := True;
472 Upper_Half_Encoding :=
473 Wide_Character_Encoding_Method in WC_Upper_Half_Encoding_Method;
477 -- Processing for x switch
481 All_Sources := False;
482 Check_Source_Files := False;
484 -- Processing for X switch
488 Bad_Switch (Switch_Chars);
492 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
494 -- Processing for y switch
498 Leap_Seconds_Support := True;
500 -- Processing for z switch
504 No_Main_Subprogram := True;
506 -- Processing for Z switch
510 Zero_Formatting := True;
512 -- Processing for --RTS
516 if Ptr + 4 <= Max and then
517 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
521 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
522 Osint.Fail ("missing path for --RTS");
525 -- Valid --RTS switch
527 Opt.No_Stdinc := True;
528 Opt.RTS_Switch := True;
531 Src_Path_Name : constant String_Ptr :=
534 (Ptr + 1 .. Switch_Chars'Last),
536 Lib_Path_Name : constant String_Ptr :=
539 (Ptr + 1 .. Switch_Chars'Last),
543 if Src_Path_Name /= null and then
544 Lib_Path_Name /= null
546 -- Set the RTS_*_Path_Name variables, so that the
547 -- correct directories will be set when a subsequent
548 -- call Osint.Add_Default_Search_Dirs is made.
550 RTS_Src_Path_Name := Src_Path_Name;
551 RTS_Lib_Path_Name := Lib_Path_Name;
555 elsif Src_Path_Name = null
556 and then Lib_Path_Name = null
558 Osint.Fail ("RTS path not valid: missing " &
559 "adainclude and adalib directories");
560 elsif Src_Path_Name = null then
561 Osint.Fail ("RTS path not valid: missing " &
562 "adainclude directory");
563 elsif Lib_Path_Name = null then
564 Osint.Fail ("RTS path not valid: missing " &
571 Bad_Switch (Switch_Chars);
574 -- Anything else is an error (illegal switch character)
577 Bad_Switch (Switch_Chars);
581 Bad_Switch (Switch_Chars);
584 end Scan_Binder_Switches;