1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2022, 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 procedure Scan_Debug_Switches
;
55 -- Scan out debug switches
57 ---------------------------
58 -- Get_Optional_Filename --
59 ---------------------------
61 function Get_Optional_Filename
return String_Ptr
is
65 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = '=' then
67 Bad_Switch
(Switch_Chars
);
69 Result
:= new String'(Switch_Chars (Ptr + 1 .. Max));
76 end Get_Optional_Filename;
82 function Get_Stack_Size (S : Character) return Int is
86 Scan_Pos (Switch_Chars, Max, Ptr, Result, S);
88 -- In the following code, we enable overflow checking since the
89 -- multiplication by K or M may cause overflow, which is an error.
92 pragma Unsuppress (Overflow_Check);
95 -- Check for additional character 'k
' (for kilobytes) or 'm
' (for
96 -- Megabytes), but only if we have not reached the end of the
97 -- switch string. Note that if this appears before the end of the
98 -- string we will get an error when we test to make sure that the
99 -- string is exhausted (at the end of the case).
102 if Switch_Chars (Ptr) = 'k
' then
103 Result := Result * 1024;
106 elsif Switch_Chars (Ptr) = 'm
' then
107 Result := Result * (1024 * 1024);
113 when Constraint_Error =>
114 Osint.Fail ("numeric value out of range for switch: " & S);
120 -------------------------
121 -- Scan_Debug_Switches --
122 -------------------------
124 procedure Scan_Debug_Switches is
125 Dot : Boolean := False;
126 Underscore : Boolean := False;
129 while Ptr <= Max loop
130 C := Switch_Chars (Ptr);
132 -- Binder debug flags come in the following forms:
142 -- Note that the processing of switch -d aleady takes care of the
143 -- case where the first flag is a digit (default stack size).
145 if C in '1' .. '9' or else
146 C in 'a
' .. 'z
' or else
153 Set_Dotted_Debug_Flag (C);
159 elsif Underscore then
160 Set_Underscored_Debug_Flag (C);
161 if Debug_Flag_Underscore_C then
162 Enable_CUDA_Expansion := True;
180 Bad_Switch (Switch_Chars);
185 end Scan_Debug_Switches;
187 -- Start of processing for Scan_Binder_Switches
190 -- Skip past the initial character (must be the switch character)
193 Bad_Switch (Switch_Chars);
198 -- A little check, "gnat" at the start of a switch is not allowed except
202 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
204 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
205 & " (gnat not needed here)");
208 -- Loop to scan through switches given in switch string
211 C := Switch_Chars (Ptr);
215 -- Processing for a switch
219 Use_Pragma_Linker_Constructor := True;
221 -- Processing for A switch
225 Output_ALI_List := True;
226 ALI_List_Filename := Get_Optional_Filename;
228 -- Processing for b switch
232 Brief_Output := True;
234 -- Processing for c switch
240 -- Processing for d switch
244 Bad_Switch (Switch_Chars);
248 C := Switch_Chars (Ptr);
250 -- Case where character after -d is a digit (default stack size)
252 if C in '0' .. '9' then
254 -- In this case, we process the default primary stack size
256 Default_Stack_Size := Get_Stack_Size ('d
');
258 -- Case where character after -d is not digit (debug flags)
264 -- Processing for D switch
268 Bad_Switch (Switch_Chars);
272 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
274 -- Processing for e switch
278 Elab_Dependency_Output := True;
280 -- Processing for E switch
284 -- -E is equivalent to -Ea (see below)
286 Exception_Tracebacks := True;
290 case Switch_Chars (Ptr) is
292 -- -Ea sets Exception_Tracebacks
296 -- -Es sets both Exception_Tracebacks and
297 -- Exception_Tracebacks_Symbolic.
299 when 's
' => Exception_Tracebacks_Symbolic := True;
300 when others => Bad_Switch (Switch_Chars);
306 -- Processing for f switch
310 Bad_Switch (Switch_Chars);
313 Force_Elab_Order_File :=
314 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
318 if not Is_Regular_File
(Force_Elab_Order_File
.all) then
319 Osint
.Fail
(Force_Elab_Order_File
.all & ": file not found");
322 -- Processing for F switch
326 Force_Checking_Of_Elaboration_Flags
:= True;
328 -- Processing for g switch
334 C
:= Switch_Chars
(Ptr
);
336 if C
in '0' .. '3' then
339 (Switch_Chars
(Ptr
)) - Character'Pos ('0');
347 -- Processing for G switch
351 Generate_C_Code
:= True;
353 -- Processing for h switch
357 Usage_Requested
:= True;
359 -- Processing for H switch
363 Legacy_Elaboration_Order
:= True;
365 -- Processing for i switch
369 Bad_Switch
(Switch_Chars
);
373 C
:= Switch_Chars
(Ptr
);
375 if C
in '1' .. '5' |
'9' |
'p' |
'8' |
'f' |
'n' |
'w' then
376 Identifier_Character_Set
:= C
;
379 Bad_Switch
(Switch_Chars
);
382 -- Processing for K switch
386 Output_Linker_Option_List
:= True;
388 -- Processing for l switch
392 Elab_Order_Output
:= True;
394 -- Processing for m switch
398 Bad_Switch
(Switch_Chars
);
402 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
404 -- Processing for n switch
408 Bind_Main_Program
:= False;
410 -- Note: The -L option of the binder also implies -n, so
411 -- any change here must also be reflected in the processing
412 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
414 -- Processing for o switch
419 if Output_File_Name_Present
then
420 Osint
.Fail
("duplicate -o switch");
422 Output_File_Name_Present
:= True;
425 -- Processing for O switch
429 Output_Object_List
:= True;
430 Object_List_Filename
:= Get_Optional_Filename
;
432 -- Processing for p switch
436 Pessimistic_Elab_Order
:= True;
438 -- Processing for P switch
442 CodePeer_Mode
:= True;
444 -- Processing for q switch
448 Quiet_Output
:= True;
450 -- Processing for Q switch
454 Bad_Switch
(Switch_Chars
);
459 (Switch_Chars
, Max
, Ptr
,
460 Quantity_Of_Default_Size_Sec_Stacks
, C
);
462 -- Processing for r switch
466 List_Restrictions
:= True;
468 -- Processing for R switch
472 List_Closure
:= True;
474 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = 'a' then
476 List_Closure_All
:= True;
479 -- Processing for s switch
484 Check_Source_Files
:= True;
486 -- Processing for t switch
490 Tolerate_Consistency_Errors
:= True;
492 -- Processing for T switch
496 Bad_Switch
(Switch_Chars
);
500 Time_Slice_Set
:= True;
501 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Time_Slice_Value
, C
);
502 Time_Slice_Value
:= Time_Slice_Value
* 1_000
;
504 -- Processing for u switch
508 Bad_Switch
(Switch_Chars
);
512 Dynamic_Stack_Measurement
:= True;
517 Dynamic_Stack_Measurement_Array_Size
,
520 -- Processing for v switch
524 Verbose_Mode
:= True;
526 -- Processing for V switch
534 while Eq
<= Max
and then Switch_Chars
(Eq
) /= '=' loop
537 if Eq
= Ptr
or else Eq
= Max
then
538 Bad_Switch
(Switch_Chars
);
541 (Key
=> Switch_Chars
(Ptr
.. Eq
- 1),
542 Value
=> Switch_Chars
(Eq
+ 1 .. Max
));
546 -- Processing for w switch
550 Bad_Switch
(Switch_Chars
);
553 -- For the binder we only allow suppress/error cases
557 case Switch_Chars
(Ptr
) is
559 Warning_Mode
:= Treat_As_Error
;
562 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
565 Warning_Mode
:= Suppress
;
568 Bad_Switch
(Switch_Chars
);
573 -- Processing for W switch
579 Bad_Switch
(Switch_Chars
);
583 Wide_Character_Encoding_Method
:=
584 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
586 when Constraint_Error
=>
587 Bad_Switch
(Switch_Chars
);
590 Wide_Character_Encoding_Method_Specified
:= True;
592 Upper_Half_Encoding
:=
593 Wide_Character_Encoding_Method
in WC_Upper_Half_Encoding_Method
;
597 -- Processing for x switch
601 All_Sources
:= False;
602 Check_Source_Files
:= False;
604 -- Processing for X switch
608 Bad_Switch
(Switch_Chars
);
612 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Default_Exit_Status
, C
);
614 -- Processing for y switch
618 Leap_Seconds_Support
:= True;
620 -- Processing for z switch
624 No_Main_Subprogram
:= True;
626 -- Processing for Z switch
630 Zero_Formatting
:= True;
632 -- Processing for --RTS
636 if Ptr
+ 4 <= Max
and then
637 Switch_Chars
(Ptr
+ 1 .. Ptr
+ 3) = "RTS"
641 if Switch_Chars
(Ptr
) /= '=' or else Ptr
= Max
then
642 Osint
.Fail
("missing path for --RTS");
645 -- Valid --RTS switch
647 Opt
.No_Stdinc
:= True;
648 Opt
.RTS_Switch
:= True;
651 Src_Path_Name
: constant String_Ptr
:=
653 (Switch_Chars
(Ptr
+ 1 .. Max
),
655 Lib_Path_Name
: constant String_Ptr
:=
657 (Switch_Chars
(Ptr
+ 1 .. Max
),
661 if Src_Path_Name
/= null and then
662 Lib_Path_Name
/= null
664 -- Set the RTS_*_Path_Name variables, so that the
665 -- correct directories will be set when a subsequent
666 -- call Osint.Add_Default_Search_Dirs is made.
668 RTS_Src_Path_Name
:= Src_Path_Name
;
669 RTS_Lib_Path_Name
:= Lib_Path_Name
;
673 elsif Src_Path_Name
= null
674 and then Lib_Path_Name
= null
677 ("RTS path not valid: missing adainclude and "
678 & "adalib directories");
679 elsif Src_Path_Name
= null then
681 ("RTS path not valid: missing adainclude directory");
682 elsif Lib_Path_Name
= null then
684 ("RTS path not valid: missing adalib directory");
690 Bad_Switch
(Switch_Chars
);
693 -- Anything else is an error (illegal switch character)
696 Bad_Switch
(Switch_Chars
);
700 Bad_Switch
(Switch_Chars
);
703 end Scan_Binder_Switches
;