1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2007, 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_Stack_Size
(S
: Character) return Int
;
44 -- Used for -d and -D to scan stack size including handling k/m.
45 -- S is set to 'd' or 'D' to indicate the switch being scanned.
51 function Get_Stack_Size
(S
: Character) return Int
is
55 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Result
, S
);
57 -- In the following code, we enable overflow checking since the
58 -- multiplication by K or M may cause overflow, which is an error.
61 pragma Unsuppress
(Overflow_Check
);
64 -- Check for additional character 'k' (for kilobytes) or 'm'
65 -- (for Megabytes), but only if we have not reached the end
66 -- of the switch string. Note that if this appears before the
67 -- end of the string we will get an error when we test to make
68 -- sure that the string is exhausted (at the end of the case).
71 if Switch_Chars
(Ptr
) = 'k' then
72 Result
:= Result
* 1024;
75 elsif Switch_Chars
(Ptr
) = 'm' then
76 Result
:= Result
* (1024 * 1024);
82 when Constraint_Error
=>
84 ("numeric value out of range for switch: ", (1 => S
));
90 -- Start of processing for Scan_Binder_Switches
93 -- Skip past the initial character (must be the switch character)
96 Bad_Switch
(Switch_Chars
);
101 -- A little check, "gnat" at the start of a switch is not allowed
102 -- except for the compiler
104 if Switch_Chars
'Last >= Ptr
+ 3
105 and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "gnat"
107 Osint
.Fail
("invalid switch: """, Switch_Chars
, """"
108 & " (gnat not needed here)");
111 -- Loop to scan through switches given in switch string
114 C
:= Switch_Chars
(Ptr
);
118 -- Processing for a switch
122 Use_Pragma_Linker_Constructor
:= True;
124 -- Processing for A switch
128 Ada_Bind_File
:= True;
130 -- Processing for b switch
134 Brief_Output
:= True;
136 -- Processing for c switch
143 -- Processing for C switch
148 Ada_Bind_File
:= False;
150 -- Processing for d switch
155 Bad_Switch
(Switch_Chars
);
159 C
:= Switch_Chars
(Ptr
);
161 -- Case where character after -d is a digit (default stack size)
163 if C
in '0' .. '9' then
165 -- In this case, we process the default primary stack size
167 Default_Stack_Size
:= Get_Stack_Size
('d');
169 -- Case where character after -d is not digit (debug flags)
172 -- Note: for the debug switch, the remaining characters in this
173 -- switch field must all be debug flags, since all valid switch
174 -- characters are also valid debug characters. This switch is
175 -- not documented on purpose because it is only used by the
178 -- Loop to scan out debug flags
181 C
:= Switch_Chars
(Ptr
);
183 if C
in 'a' .. 'z' or else C
in 'A' .. 'Z' then
186 Bad_Switch
(Switch_Chars
);
194 -- Processing for D switch
198 Bad_Switch
(Switch_Chars
);
202 Default_Sec_Stack_Size
:= Get_Stack_Size
('D');
204 -- Processing for e switch
208 Elab_Dependency_Output
:= True;
210 -- Processing for E switch
214 Exception_Tracebacks
:= True;
216 -- Processing for F switch
220 Force_Checking_Of_Elaboration_Flags
:= True;
222 -- Processing for g switch
228 C
:= Switch_Chars
(Ptr
);
230 if C
in '0' .. '3' then
233 (Switch_Chars
(Ptr
)) - Character'Pos ('0');
241 -- Processing for h switch
245 Usage_Requested
:= True;
247 -- Processing for i switch
251 Bad_Switch
(Switch_Chars
);
255 C
:= Switch_Chars
(Ptr
);
264 Identifier_Character_Set
:= C
;
267 Bad_Switch
(Switch_Chars
);
270 -- Processing for K switch
274 Output_Linker_Option_List
:= True;
276 -- Processing for l switch
280 Elab_Order_Output
:= True;
282 -- Processing for m switch
286 Bad_Switch
(Switch_Chars
);
290 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Errors
, C
);
292 -- Processing for n switch
296 Bind_Main_Program
:= False;
298 -- Note: The -L option of the binder also implies -n, so
299 -- any change here must also be reflected in the processing
300 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
302 -- Processing for o switch
307 if Output_File_Name_Present
then
308 Osint
.Fail
("duplicate -o switch");
311 Output_File_Name_Present
:= True;
314 -- Processing for O switch
318 Output_Object_List
:= True;
320 -- Processing for p switch
324 Pessimistic_Elab_Order
:= True;
326 -- Processing for q switch
330 Quiet_Output
:= True;
332 -- Processing for r switch
336 List_Restrictions
:= True;
338 -- Processing for R switch
343 List_Closure
:= True;
345 -- Processing for s switch
350 Check_Source_Files
:= True;
352 -- Processing for t switch
356 Tolerate_Consistency_Errors
:= True;
358 -- Processing for T switch
362 Bad_Switch
(Switch_Chars
);
366 Time_Slice_Set
:= True;
367 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Time_Slice_Value
, C
);
368 Time_Slice_Value
:= Time_Slice_Value
* 1_000
;
370 -- Processing for u switch
374 Bad_Switch
(Switch_Chars
);
378 Dynamic_Stack_Measurement
:= True;
383 Dynamic_Stack_Measurement_Array_Size
,
386 -- Processing for v switch
390 Verbose_Mode
:= True;
392 -- Processing for w switch
396 Bad_Switch
(Switch_Chars
);
399 -- For the binder we only allow suppress/error cases
403 case Switch_Chars
(Ptr
) is
406 Warning_Mode
:= Treat_As_Error
;
409 Warning_Mode
:= Suppress
;
412 Bad_Switch
(Switch_Chars
);
417 -- Processing for W switch
421 Bad_Switch
(Switch_Chars
);
426 for J
in WC_Encoding_Method
loop
427 if Switch_Chars
(Ptr
) = WC_Encoding_Letters
(J
) then
428 Wide_Character_Encoding_Method
:= J
;
431 elsif J
= WC_Encoding_Method
'Last then
432 Bad_Switch
(Switch_Chars
);
436 Upper_Half_Encoding
:=
437 Wide_Character_Encoding_Method
in
438 WC_Upper_Half_Encoding_Method
;
442 -- Processing for x switch
446 All_Sources
:= False;
447 Check_Source_Files
:= False;
449 -- Processing for X switch
453 Bad_Switch
(Switch_Chars
);
457 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Default_Exit_Status
, C
);
459 -- Processing for y switch
463 Leap_Seconds_Support
:= True;
465 -- Processing for z switch
469 No_Main_Subprogram
:= True;
471 -- Processing for Z switch
475 Zero_Formatting
:= True;
477 -- Processing for --RTS
481 if Ptr
+ 4 <= Max
and then
482 Switch_Chars
(Ptr
+ 1 .. Ptr
+ 3) = "RTS"
486 if Switch_Chars
(Ptr
) /= '=' or else Ptr
= Max
then
487 Osint
.Fail
("missing path for --RTS");
490 -- valid --RTS switch
492 Opt
.No_Stdinc
:= True;
493 Opt
.RTS_Switch
:= True;
496 Src_Path_Name
: constant String_Ptr
:=
499 (Ptr
+ 1 .. Switch_Chars
'Last),
501 Lib_Path_Name
: constant String_Ptr
:=
504 (Ptr
+ 1 .. Switch_Chars
'Last),
508 if Src_Path_Name
/= null and then
509 Lib_Path_Name
/= null
511 -- Set the RTS_*_Path_Name variables, so that the
512 -- correct directories will be set when
513 -- Osint.Add_Default_Search_Dirs will be called later.
515 RTS_Src_Path_Name
:= Src_Path_Name
;
516 RTS_Lib_Path_Name
:= Lib_Path_Name
;
520 elsif Src_Path_Name
= null
521 and then Lib_Path_Name
= null
523 Osint
.Fail
("RTS path not valid: missing " &
524 "adainclude and adalib directories");
525 elsif Src_Path_Name
= null then
526 Osint
.Fail
("RTS path not valid: missing " &
527 "adainclude directory");
528 elsif Lib_Path_Name
= null then
529 Osint
.Fail
("RTS path not valid: missing " &
536 Bad_Switch
(Switch_Chars
);
539 -- Anything else is an error (illegal switch character)
542 Bad_Switch
(Switch_Chars
);
546 Bad_Switch
(Switch_Chars
);
549 end Scan_Binder_Switches
;