1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2020, 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);
177 Bad_Switch (Switch_Chars);
182 end Scan_Debug_Switches;
184 -- Start of processing for Scan_Binder_Switches
187 -- Skip past the initial character (must be the switch character)
190 Bad_Switch (Switch_Chars);
195 -- A little check, "gnat" at the start of a switch is not allowed except
199 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
201 Osint.Fail ("invalid switch: """ & Switch_Chars & """"
202 & " (gnat not needed here)");
205 -- Loop to scan through switches given in switch string
208 C := Switch_Chars (Ptr);
212 -- Processing for a switch
216 Use_Pragma_Linker_Constructor := True;
218 -- Processing for A switch
222 Output_ALI_List := True;
223 ALI_List_Filename := Get_Optional_Filename;
225 -- Processing for b switch
229 Brief_Output := True;
231 -- Processing for c switch
237 -- Processing for d switch
241 Bad_Switch (Switch_Chars);
245 C := Switch_Chars (Ptr);
247 -- Case where character after -d is a digit (default stack size)
249 if C in '0' .. '9' then
251 -- In this case, we process the default primary stack size
253 Default_Stack_Size := Get_Stack_Size ('d
');
255 -- Case where character after -d is not digit (debug flags)
261 -- Processing for D switch
265 Bad_Switch (Switch_Chars);
269 Default_Sec_Stack_Size := Get_Stack_Size ('D
');
271 -- Processing for e switch
275 Elab_Dependency_Output := True;
277 -- Processing for E switch
281 -- -E is equivalent to -Ea (see below)
283 Exception_Tracebacks := True;
287 case Switch_Chars (Ptr) is
289 -- -Ea sets Exception_Tracebacks
293 -- -Es sets both Exception_Tracebacks and
294 -- Exception_Tracebacks_Symbolic.
296 when 's
' => Exception_Tracebacks_Symbolic := True;
297 when others => Bad_Switch (Switch_Chars);
303 -- Processing for f switch
307 Bad_Switch (Switch_Chars);
310 Force_Elab_Order_File :=
311 new String'(Switch_Chars
(Ptr
+ 1 .. Max
));
315 if not Is_Read_Accessible_File
(Force_Elab_Order_File
.all) then
316 Osint
.Fail
(Force_Elab_Order_File
.all & ": file not found");
319 -- Processing for F switch
323 Force_Checking_Of_Elaboration_Flags
:= True;
325 -- Processing for g switch
331 C
:= Switch_Chars
(Ptr
);
333 if C
in '0' .. '3' then
336 (Switch_Chars
(Ptr
)) - Character'Pos ('0');
344 -- Processing for G switch
348 Generate_C_Code
:= True;
350 -- Processing for h switch
354 Usage_Requested
:= True;
356 -- Processing for H switch
360 Legacy_Elaboration_Order
:= True;
362 -- Processing for i switch
366 Bad_Switch
(Switch_Chars
);
370 C
:= Switch_Chars
(Ptr
);
379 Identifier_Character_Set
:= C
;
382 Bad_Switch
(Switch_Chars
);
385 -- Processing for K switch
389 Output_Linker_Option_List
:= True;
391 -- Processing for l switch
395 Elab_Order_Output
:= True;
397 -- Processing for m switch
401 Bad_Switch
(Switch_Chars
);
405 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Messages
, C
);
407 -- Processing for n switch
411 Bind_Main_Program
:= False;
413 -- Note: The -L option of the binder also implies -n, so
414 -- any change here must also be reflected in the processing
415 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
417 -- Processing for o switch
422 if Output_File_Name_Present
then
423 Osint
.Fail
("duplicate -o switch");
425 Output_File_Name_Present
:= True;
428 -- Processing for O switch
432 Output_Object_List
:= True;
433 Object_List_Filename
:= Get_Optional_Filename
;
435 -- Processing for p switch
439 Pessimistic_Elab_Order
:= True;
441 -- Processing for P switch
445 CodePeer_Mode
:= True;
447 -- Processing for q switch
451 Quiet_Output
:= True;
453 -- Processing for Q switch
457 Bad_Switch
(Switch_Chars
);
462 (Switch_Chars
, Max
, Ptr
,
463 Quantity_Of_Default_Size_Sec_Stacks
, C
);
465 -- Processing for r switch
469 List_Restrictions
:= True;
471 -- Processing for R switch
475 List_Closure
:= True;
477 if Ptr
<= Max
and then Switch_Chars
(Ptr
) = 'a' then
479 List_Closure_All
:= True;
482 -- Processing for s switch
487 Check_Source_Files
:= True;
489 -- Processing for t switch
493 Tolerate_Consistency_Errors
:= True;
495 -- Processing for T switch
499 Bad_Switch
(Switch_Chars
);
503 Time_Slice_Set
:= True;
504 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Time_Slice_Value
, C
);
505 Time_Slice_Value
:= Time_Slice_Value
* 1_000
;
507 -- Processing for u switch
511 Bad_Switch
(Switch_Chars
);
515 Dynamic_Stack_Measurement
:= True;
520 Dynamic_Stack_Measurement_Array_Size
,
523 -- Processing for v switch
527 Verbose_Mode
:= True;
529 -- Processing for V switch
537 while Eq
<= Max
and then Switch_Chars
(Eq
) /= '=' loop
540 if Eq
= Ptr
or else Eq
= Max
then
541 Bad_Switch
(Switch_Chars
);
544 (Key
=> Switch_Chars
(Ptr
.. Eq
- 1),
545 Value
=> Switch_Chars
(Eq
+ 1 .. Max
));
549 -- Processing for w switch
553 Bad_Switch
(Switch_Chars
);
556 -- For the binder we only allow suppress/error cases
560 case Switch_Chars
(Ptr
) is
562 Warning_Mode
:= Treat_As_Error
;
565 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
568 Warning_Mode
:= Suppress
;
571 Bad_Switch
(Switch_Chars
);
576 -- Processing for W switch
582 Bad_Switch
(Switch_Chars
);
586 Wide_Character_Encoding_Method
:=
587 Get_WC_Encoding_Method
(Switch_Chars
(Ptr
));
589 when Constraint_Error
=>
590 Bad_Switch
(Switch_Chars
);
593 Wide_Character_Encoding_Method_Specified
:= True;
595 Upper_Half_Encoding
:=
596 Wide_Character_Encoding_Method
in WC_Upper_Half_Encoding_Method
;
600 -- Processing for x switch
604 All_Sources
:= False;
605 Check_Source_Files
:= False;
607 -- Processing for X switch
611 Bad_Switch
(Switch_Chars
);
615 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Default_Exit_Status
, C
);
617 -- Processing for y switch
621 Leap_Seconds_Support
:= True;
623 -- Processing for z switch
627 No_Main_Subprogram
:= True;
629 -- Processing for Z switch
633 Zero_Formatting
:= True;
635 -- Processing for --RTS
639 if Ptr
+ 4 <= Max
and then
640 Switch_Chars
(Ptr
+ 1 .. Ptr
+ 3) = "RTS"
644 if Switch_Chars
(Ptr
) /= '=' or else Ptr
= Max
then
645 Osint
.Fail
("missing path for --RTS");
648 -- Valid --RTS switch
650 Opt
.No_Stdinc
:= True;
651 Opt
.RTS_Switch
:= True;
654 Src_Path_Name
: constant String_Ptr
:=
656 (Switch_Chars
(Ptr
+ 1 .. Max
),
658 Lib_Path_Name
: constant String_Ptr
:=
660 (Switch_Chars
(Ptr
+ 1 .. Max
),
664 if Src_Path_Name
/= null and then
665 Lib_Path_Name
/= null
667 -- Set the RTS_*_Path_Name variables, so that the
668 -- correct directories will be set when a subsequent
669 -- call Osint.Add_Default_Search_Dirs is made.
671 RTS_Src_Path_Name
:= Src_Path_Name
;
672 RTS_Lib_Path_Name
:= Lib_Path_Name
;
676 elsif Src_Path_Name
= null
677 and then Lib_Path_Name
= null
680 ("RTS path not valid: missing adainclude and "
681 & "adalib directories");
682 elsif Src_Path_Name
= null then
684 ("RTS path not valid: missing adainclude directory");
685 elsif Lib_Path_Name
= null then
687 ("RTS path not valid: missing adalib directory");
693 Bad_Switch
(Switch_Chars
);
696 -- Anything else is an error (illegal switch character)
699 Bad_Switch
(Switch_Chars
);
703 Bad_Switch
(Switch_Chars
);
706 end Scan_Binder_Switches
;