1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2018, 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
.OS_Lib
; use System
.OS_Lib
;
32 with System
.WCh_Con
; use System
.WCh_Con
;
34 package body Switch
.B
is
36 --------------------------
37 -- Scan_Binder_Switches --
38 --------------------------
40 procedure Scan_Binder_Switches
(Switch_Chars
: String) is
41 Max
: constant Integer := Switch_Chars
'Last;
42 Ptr
: Integer := Switch_Chars
'First;
45 function Get_Optional_Filename
return String_Ptr
;
46 -- If current character is '=', return a newly allocated string that
47 -- contains the remainder of the current switch (after the '='), else
50 function Get_Stack_Size
(S
: Character) return Int
;
51 -- Used for -d and -D to scan stack size including handling k/m. S is
52 -- set to 'd' or 'D' to indicate the switch being scanned.
54 ---------------------------
55 -- Get_Optional_Filename --
56 ---------------------------
58 function Get_Optional_Filename
return String_Ptr
is
62 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
64 Bad_Switch
(Switch_Chars
);
66 Result
:= new String'(Switch_Chars (Ptr + 1 .. Max));
73 end Get_Optional_Filename;
79 function Get_Stack_Size (S : Character) return Int is
83 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
85 -- In the following code, we enable overflow checking since the
86 -- multiplication by K or M may cause overflow, which is an error.
89 pragma Unsuppress (Overflow_Check);
92 -- Check for additional character 'k
' (for kilobytes) or 'm
' (for
93 -- Megabytes), but only if we have not reached the end of the
94 -- switch string. Note that if this appears before the end of the
95 -- string we will get an error when we test to make sure that the
96 -- string is exhausted (at the end of the case).
99 if Switch_Chars (Ptr) = 'k
' then
100 Result := Result * 1024;
103 elsif Switch_Chars (Ptr) = 'm
' then
104 Result := Result * (1024 * 1024);
110 when Constraint_Error =>
111 Osint.Fail ("numeric value out of range for switch: " & S);
117 -- Start of processing for Scan_Binder_Switches
120 -- Skip past the initial character (must be the switch character)
123 Bad_Switch (Switch_Chars);
128 -- A little check, "gnat" at the start of a switch is not allowed except
132 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
134 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
135 & " (gnat not needed here)");
138 -- Loop to scan through switches given in switch string
141 C := Switch_Chars (Ptr);
145 -- Processing for a switch
149 Use_Pragma_Linker_Constructor := True;
151 -- Processing for A switch
155 Output_ALI_List := True;
156 ALI_List_Filename := Get_Optional_Filename;
158 -- Processing for b switch
162 Brief_Output := True;
164 -- Processing for c switch
170 -- Processing for d switch
175 Bad_Switch (Switch_Chars);
179 C := Switch_Chars (Ptr);
181 -- Case where character after -d is a digit (default stack size)
183 if C in '0' .. '9' then
185 -- In this case, we process the default primary stack size
187 Default_Stack_Size := Get_Stack_Size ('d
');
189 -- Case where character after -d is not digit (debug flags)
192 -- Note: for the debug switch, the remaining characters in this
193 -- switch field must all be debug flags, since all valid switch
194 -- characters are also valid debug characters. This switch is
195 -- not documented on purpose because it is only used by the
198 -- Loop to scan out debug flags
201 C := Switch_Chars (Ptr);
203 if C in 'a
' .. 'z
' or else C in 'A
' .. 'Z
' then
206 Bad_Switch (Switch_Chars);
214 -- Processing for D switch
218 Bad_Switch (Switch_Chars);
222 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
224 -- Processing for e switch
228 Elab_Dependency_Output := True;
230 -- Processing for E switch
234 -- -E is equivalent to -Ea (see below)
236 Exception_Tracebacks := True;
240 case Switch_Chars (Ptr) is
242 -- -Ea sets Exception_Tracebacks
246 -- -Es sets both Exception_Tracebacks and
247 -- Exception_Tracebacks_Symbolic.
249 when 's
' => Exception_Tracebacks_Symbolic := True;
250 when others => Bad_Switch (Switch_Chars);
256 -- Processing for f switch
260 Bad_Switch (Switch_Chars);
263 Force_Elab_Order_File :=
264 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
268 if not Is_Read_Accessible_File
(Force_Elab_Order_File
.all) then
269 Osint
.Fail
(Force_Elab_Order_File
.all & ": file not found");
272 -- Processing for F switch
276 Force_Checking_Of_Elaboration_Flags
:= True;
278 -- Processing for g switch
284 C
:= Switch_Chars
(Ptr
);
286 if C
in '0' .. '3' then
289 (Switch_Chars
(Ptr
)) - Character'Pos ('0');
297 -- Processing for h switch
301 Usage_Requested
:= True;
303 -- Processing for i switch
307 Bad_Switch
(Switch_Chars
);
311 C
:= Switch_Chars
(Ptr
);
320 Identifier_Character_Set
:= C
;
323 Bad_Switch
(Switch_Chars
);
326 -- Processing for K switch
330 Output_Linker_Option_List
:= True;
332 -- Processing for l switch
336 Elab_Order_Output
:= True;
338 -- Processing for m switch
342 Bad_Switch
(Switch_Chars
);
346 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
348 -- Processing for n switch
352 Bind_Main_Program
:= False;
354 -- Note: The -L option of the binder also implies -n, so
355 -- any change here must also be reflected in the processing
356 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
358 -- Processing for o switch
363 if Output_File_Name_Present
then
364 Osint
.Fail
("duplicate -o switch");
366 Output_File_Name_Present
:= True;
369 -- Processing for O switch
373 Output_Object_List
:= True;
374 Object_List_Filename
:= Get_Optional_Filename
;
376 -- Processing for p switch
380 Pessimistic_Elab_Order
:= True;
382 -- Processing for P switch
386 CodePeer_Mode
:= True;
388 -- Processing for q switch
392 Quiet_Output
:= True;
394 -- Processing for Q switch
398 Bad_Switch
(Switch_Chars
);
403 (Switch_Chars
, Max
, Ptr
,
404 Quantity_Of_Default_Size_Sec_Stacks
, C
);
406 -- Processing for r switch
410 List_Restrictions
:= True;
412 -- Processing for R switch
416 List_Closure
:= True;
418 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = 'a' then
420 List_Closure_All
:= True;
423 -- Processing for s switch
428 Check_Source_Files
:= True;
430 -- Processing for t switch
434 Tolerate_Consistency_Errors
:= True;
436 -- Processing for T switch
440 Bad_Switch
(Switch_Chars
);
444 Time_Slice_Set
:= True;
445 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Time_Slice_Value
, C
);
446 Time_Slice_Value
:= Time_Slice_Value
* 1_000
;
448 -- Processing for u switch
452 Bad_Switch
(Switch_Chars
);
456 Dynamic_Stack_Measurement
:= True;
461 Dynamic_Stack_Measurement_Array_Size
,
464 -- Processing for v switch
468 Verbose_Mode
:= True;
470 -- Processing for V switch
478 while Eq
<= Max
and then Switch_Chars
(Eq
) /= '=' loop
481 if Eq
= Ptr
or else Eq
= Max
then
482 Bad_Switch
(Switch_Chars
);
485 (Key
=> Switch_Chars
(Ptr
.. Eq
- 1),
486 Value
=> Switch_Chars
(Eq
+ 1 .. Max
));
490 -- Processing for w switch
494 Bad_Switch
(Switch_Chars
);
497 -- For the binder we only allow suppress/error cases
501 case Switch_Chars
(Ptr
) is
503 Warning_Mode
:= Treat_As_Error
;
506 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
509 Warning_Mode
:= Suppress
;
512 Bad_Switch
(Switch_Chars
);
517 -- Processing for W switch
523 Bad_Switch
(Switch_Chars
);
527 Wide_Character_Encoding_Method
:=
528 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
530 when Constraint_Error
=>
531 Bad_Switch
(Switch_Chars
);
534 Wide_Character_Encoding_Method_Specified
:= True;
536 Upper_Half_Encoding
:=
537 Wide_Character_Encoding_Method
in WC_Upper_Half_Encoding_Method
;
541 -- Processing for x switch
545 All_Sources
:= False;
546 Check_Source_Files
:= False;
548 -- Processing for X switch
552 Bad_Switch
(Switch_Chars
);
556 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Default_Exit_Status
, C
);
558 -- Processing for y switch
562 Leap_Seconds_Support
:= True;
564 -- Processing for z switch
568 No_Main_Subprogram
:= True;
570 -- Processing for Z switch
574 Zero_Formatting
:= True;
576 -- Processing for --RTS
580 if Ptr
+ 4 <= Max
and then
581 Switch_Chars
(Ptr
+ 1 .. Ptr
+ 3) = "RTS"
585 if Switch_Chars
(Ptr
) /= '=' or else Ptr
= Max
then
586 Osint
.Fail
("missing path for --RTS");
589 -- Valid --RTS switch
591 Opt
.No_Stdinc
:= True;
592 Opt
.RTS_Switch
:= True;
595 Src_Path_Name
: constant String_Ptr
:=
597 (Switch_Chars
(Ptr
+ 1 .. Max
),
599 Lib_Path_Name
: constant String_Ptr
:=
601 (Switch_Chars
(Ptr
+ 1 .. Max
),
605 if Src_Path_Name
/= null and then
606 Lib_Path_Name
/= null
608 -- Set the RTS_*_Path_Name variables, so that the
609 -- correct directories will be set when a subsequent
610 -- call Osint.Add_Default_Search_Dirs is made.
612 RTS_Src_Path_Name
:= Src_Path_Name
;
613 RTS_Lib_Path_Name
:= Lib_Path_Name
;
617 elsif Src_Path_Name
= null
618 and then Lib_Path_Name
= null
621 ("RTS path not valid: missing adainclude and "
622 & "adalib directories");
623 elsif Src_Path_Name
= null then
625 ("RTS path not valid: missing adainclude directory");
626 elsif Lib_Path_Name
= null then
628 ("RTS path not valid: missing adalib directory");
634 Bad_Switch
(Switch_Chars
);
637 -- Anything else is an error (illegal switch character)
640 Bad_Switch
(Switch_Chars
);
644 Bad_Switch
(Switch_Chars
);
647 end Scan_Binder_Switches
;