1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2015, 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 ------------------------------------------------------------------------------
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_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
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 d switch
174 Bad_Switch (Switch_Chars);
178 C := Switch_Chars (Ptr);
180 -- Case where character after -d is a digit (default stack size)
182 if C in '0' .. '9' then
184 -- In this case, we process the default primary stack size
186 Default_Stack_Size := Get_Stack_Size ('d
');
188 -- Case where character after -d is not digit (debug flags)
191 -- Note: for the debug switch, the remaining characters in this
192 -- switch field must all be debug flags, since all valid switch
193 -- characters are also valid debug characters. This switch is
194 -- not documented on purpose because it is only used by the
197 -- Loop to scan out debug flags
200 C := Switch_Chars (Ptr);
202 if C in 'a
' .. 'z
' or else C in 'A
' .. 'Z
' then
205 Bad_Switch (Switch_Chars);
213 -- Processing for D switch
217 Bad_Switch (Switch_Chars);
221 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
223 -- Processing for e switch
227 Elab_Dependency_Output := True;
229 -- Processing for E switch
233 -- -E is equivalent to -Ea (see below)
235 Exception_Tracebacks := True;
239 case Switch_Chars (Ptr) is
241 -- -Ea sets Exception_Tracebacks
245 -- -Es sets both Exception_Tracebacks and
246 -- Exception_Tracebacks_Symbolic.
248 when 's
' => Exception_Tracebacks_Symbolic := True;
249 when others => Bad_Switch (Switch_Chars);
255 -- Processing for F switch
259 Force_Checking_Of_Elaboration_Flags := True;
261 -- Processing for g switch
267 C := Switch_Chars (Ptr);
269 if C in '0' .. '3' then
272 (Switch_Chars (Ptr)) - Character'Pos ('0');
280 -- Processing for h switch
284 Usage_Requested := True;
286 -- Processing for i switch
290 Bad_Switch (Switch_Chars);
294 C := Switch_Chars (Ptr);
303 Identifier_Character_Set := C;
306 Bad_Switch (Switch_Chars);
309 -- Processing for K switch
313 Output_Linker_Option_List := True;
315 -- Processing for l switch
319 Elab_Order_Output := True;
321 -- Processing for m switch
325 Bad_Switch (Switch_Chars);
329 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Messages, C);
331 -- Processing for n switch
335 Bind_Main_Program := False;
337 -- Note: The -L option of the binder also implies -n, so
338 -- any change here must also be reflected in the processing
339 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
341 -- Processing for o switch
346 if Output_File_Name_Present then
347 Osint.Fail ("duplicate -o switch");
349 Output_File_Name_Present := True;
352 -- Processing for O switch
356 Output_Object_List := True;
357 Object_List_Filename := Get_Optional_Filename;
359 -- Processing for p switch
363 Pessimistic_Elab_Order := True;
365 -- Processing for P switch
369 CodePeer_Mode := True;
371 -- Processing for q switch
375 Quiet_Output := True;
377 -- Processing for r switch
381 List_Restrictions := True;
383 -- Processing for R switch
387 List_Closure := True;
389 if Ptr <= Max and then Switch_Chars (Ptr) = 'a
' then
391 List_Closure_All := True;
394 -- Processing for s switch
399 Check_Source_Files := True;
401 -- Processing for t switch
405 Tolerate_Consistency_Errors := True;
407 -- Processing for T switch
411 Bad_Switch (Switch_Chars);
415 Time_Slice_Set := True;
416 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value, C);
417 Time_Slice_Value := Time_Slice_Value * 1_000;
419 -- Processing for u switch
423 Bad_Switch (Switch_Chars);
427 Dynamic_Stack_Measurement := True;
432 Dynamic_Stack_Measurement_Array_Size,
435 -- Processing for v switch
439 Verbose_Mode := True;
441 -- Processing for V switch
449 while Eq <= Max and then Switch_Chars (Eq) /= '=' loop
452 if Eq = Ptr or else Eq = Max then
453 Bad_Switch (Switch_Chars);
456 (Key => Switch_Chars (Ptr .. Eq - 1),
457 Value => Switch_Chars (Eq + 1 .. Max));
461 -- Processing for w switch
465 Bad_Switch (Switch_Chars);
468 -- For the binder we only allow suppress/error cases
472 case Switch_Chars (Ptr) is
474 Warning_Mode := Treat_As_Error;
477 Warning_Mode := Suppress;
480 Bad_Switch (Switch_Chars);
485 -- Processing for W switch
491 Bad_Switch (Switch_Chars);
495 Wide_Character_Encoding_Method :=
496 Get_WC_Encoding_Method (Switch_Chars (Ptr));
498 when Constraint_Error =>
499 Bad_Switch (Switch_Chars);
502 Wide_Character_Encoding_Method_Specified := True;
504 Upper_Half_Encoding :=
505 Wide_Character_Encoding_Method in WC_Upper_Half_Encoding_Method;
509 -- Processing for x switch
513 All_Sources := False;
514 Check_Source_Files := False;
516 -- Processing for X switch
520 Bad_Switch (Switch_Chars);
524 Scan_Pos (Switch_Chars, Max, Ptr, Default_Exit_Status, C);
526 -- Processing for y switch
530 Leap_Seconds_Support := True;
532 -- Processing for z switch
536 No_Main_Subprogram := True;
538 -- Processing for Z switch
542 Zero_Formatting := True;
544 -- Processing for --RTS
548 if Ptr + 4 <= Max and then
549 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
553 if Switch_Chars (Ptr) /= '=' or else Ptr = Max then
554 Osint.Fail ("missing path for --RTS");
557 -- Valid --RTS switch
559 Opt.No_Stdinc := True;
560 Opt.RTS_Switch := True;
563 Src_Path_Name : constant String_Ptr :=
565 (Switch_Chars (Ptr + 1 .. Max),
567 Lib_Path_Name : constant String_Ptr :=
569 (Switch_Chars (Ptr + 1 .. Max),
573 if Src_Path_Name /= null and then
574 Lib_Path_Name /= null
576 -- Set the RTS_*_Path_Name variables, so that the
577 -- correct directories will be set when a subsequent
578 -- call Osint.Add_Default_Search_Dirs is made.
580 RTS_Src_Path_Name := Src_Path_Name;
581 RTS_Lib_Path_Name := Lib_Path_Name;
585 elsif Src_Path_Name = null
586 and then Lib_Path_Name = null
589 ("RTS path not valid: missing adainclude and "
590 & "adalib directories");
591 elsif Src_Path_Name = null then
593 ("RTS path not valid: missing adainclude directory");
594 elsif Lib_Path_Name = null then
596 ("RTS path not valid: missing adalib directory");
602 Bad_Switch (Switch_Chars);
605 -- Anything else is an error (illegal switch character)
608 Bad_Switch (Switch_Chars);
612 Bad_Switch (Switch_Chars);
615 end Scan_Binder_Switches;