1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
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_Stack_Size
(S
: Character) return Int
;
45 -- Used for -d and -D to scan stack size including handling k/m.
46 -- S is set to 'd' or 'D' to indicate the switch being scanned.
52 function Get_Stack_Size
(S
: Character) return Int
is
56 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Result
, S
);
58 -- In the following code, we enable overflow checking since the
59 -- multiplication by K or M may cause overflow, which is an error.
62 pragma Unsuppress
(Overflow_Check
);
65 -- Check for additional character 'k' (for kilobytes) or 'm'
66 -- (for Megabytes), but only if we have not reached the end
67 -- of the switch string. Note that if this appears before the
68 -- end of the string we will get an error when we test to make
69 -- sure that the string is exhausted (at the end of the case).
72 if Switch_Chars
(Ptr
) = 'k' then
73 Result
:= Result
* 1024;
76 elsif Switch_Chars
(Ptr
) = 'm' then
77 Result
:= Result
* (1024 * 1024);
83 when Constraint_Error
=>
85 ("numeric value out of range for switch: ", (1 => S
));
91 -- Start of processing for Scan_Binder_Switches
94 -- Skip past the initial character (must be the switch character)
97 Bad_Switch
(Switch_Chars
);
102 -- A little check, "gnat" at the start of a switch is not allowed
103 -- except for the compiler
105 if Switch_Chars
'Last >= Ptr
+ 3
106 and then Switch_Chars
(Ptr
.. Ptr
+ 3) = "gnat"
108 Osint
.Fail
("invalid switch: """, Switch_Chars
, """"
109 & " (gnat not needed here)");
112 -- Loop to scan through switches given in switch string
115 C
:= Switch_Chars
(Ptr
);
119 -- Processing for a switch
123 Use_Pragma_Linker_Constructor
:= True;
125 -- Processing for A switch
129 Ada_Bind_File
:= True;
131 -- Processing for b switch
135 Brief_Output
:= True;
137 -- Processing for c switch
144 -- Processing for C switch
149 Ada_Bind_File
:= False;
151 -- Processing for d switch
156 Bad_Switch
(Switch_Chars
);
160 C
:= Switch_Chars
(Ptr
);
162 -- Case where character after -d is a digit (default stack size)
164 if C
in '0' .. '9' then
166 -- In this case, we process the default primary stack size
168 Default_Stack_Size
:= Get_Stack_Size
('d');
170 -- Case where character after -d is not digit (debug flags)
173 -- Note: for the debug switch, the remaining characters in this
174 -- switch field must all be debug flags, since all valid switch
175 -- characters are also valid debug characters. This switch is
176 -- not documented on purpose because it is only used by the
179 -- Loop to scan out debug flags
182 C
:= Switch_Chars
(Ptr
);
184 if C
in 'a' .. 'z' or else C
in 'A' .. 'Z' then
187 Bad_Switch
(Switch_Chars
);
195 -- Processing for D switch
199 Bad_Switch
(Switch_Chars
);
203 Default_Sec_Stack_Size
:= Get_Stack_Size
('D');
205 -- Processing for e switch
209 Elab_Dependency_Output
:= True;
211 -- Processing for E switch
215 Exception_Tracebacks
:= True;
217 -- Processing for F switch
221 Force_Checking_Of_Elaboration_Flags
:= True;
223 -- Processing for g switch
229 C
:= Switch_Chars
(Ptr
);
231 if C
in '0' .. '3' then
234 (Switch_Chars
(Ptr
)) - Character'Pos ('0');
242 -- Processing for h switch
246 Usage_Requested
:= True;
248 -- Processing for i switch
252 Bad_Switch
(Switch_Chars
);
256 C
:= Switch_Chars
(Ptr
);
265 Identifier_Character_Set
:= C
;
268 Bad_Switch
(Switch_Chars
);
271 -- Processing for K switch
275 Output_Linker_Option_List
:= True;
277 -- Processing for l switch
281 Elab_Order_Output
:= True;
283 -- Processing for m switch
287 Bad_Switch
(Switch_Chars
);
291 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Maximum_Errors
, C
);
293 -- Processing for n switch
297 Bind_Main_Program
:= False;
299 -- Note: The -L option of the binder also implies -n, so
300 -- any change here must also be reflected in the processing
301 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
303 -- Processing for o switch
308 if Output_File_Name_Present
then
309 Osint
.Fail
("duplicate -o switch");
312 Output_File_Name_Present
:= True;
315 -- Processing for O switch
319 Output_Object_List
:= True;
321 -- Processing for p switch
325 Pessimistic_Elab_Order
:= True;
327 -- Processing for q switch
331 Quiet_Output
:= True;
333 -- Processing for r switch
337 List_Restrictions
:= True;
339 -- Processing for s switch
344 Check_Source_Files
:= True;
346 -- Processing for t switch
350 Tolerate_Consistency_Errors
:= True;
352 -- Processing for T switch
356 Bad_Switch
(Switch_Chars
);
360 Time_Slice_Set
:= True;
361 Scan_Nat
(Switch_Chars
, Max
, Ptr
, Time_Slice_Value
, C
);
362 Time_Slice_Value
:= Time_Slice_Value
* 1_000
;
364 -- Processing for u switch
368 Bad_Switch
(Switch_Chars
);
372 Dynamic_Stack_Measurement
:= True;
377 Dynamic_Stack_Measurement_Array_Size
,
380 -- Processing for v switch
384 Verbose_Mode
:= True;
386 -- Processing for w switch
390 Bad_Switch
(Switch_Chars
);
393 -- For the binder we only allow suppress/error cases
397 case Switch_Chars
(Ptr
) is
400 Warning_Mode
:= Treat_As_Error
;
403 Warning_Mode
:= Suppress
;
406 Bad_Switch
(Switch_Chars
);
411 -- Processing for W switch
415 Bad_Switch
(Switch_Chars
);
420 for J
in WC_Encoding_Method
loop
421 if Switch_Chars
(Ptr
) = WC_Encoding_Letters
(J
) then
422 Wide_Character_Encoding_Method
:= J
;
425 elsif J
= WC_Encoding_Method
'Last then
426 Bad_Switch
(Switch_Chars
);
430 Upper_Half_Encoding
:=
431 Wide_Character_Encoding_Method
in
432 WC_Upper_Half_Encoding_Method
;
436 -- Processing for x switch
440 All_Sources
:= False;
441 Check_Source_Files
:= False;
443 -- Processing for X switch
447 Bad_Switch
(Switch_Chars
);
451 Scan_Pos
(Switch_Chars
, Max
, Ptr
, Default_Exit_Status
, C
);
453 -- Processing for z switch
457 No_Main_Subprogram
:= True;
459 -- Processing for --RTS
463 if Ptr
+ 4 <= Max
and then
464 Switch_Chars
(Ptr
+ 1 .. Ptr
+ 3) = "RTS"
468 if Switch_Chars
(Ptr
) /= '=' or else Ptr
= Max
then
469 Osint
.Fail
("missing path for --RTS");
472 -- valid --RTS switch
474 Opt
.No_Stdinc
:= True;
475 Opt
.RTS_Switch
:= True;
478 Src_Path_Name
: constant String_Ptr
:=
481 (Ptr
+ 1 .. Switch_Chars
'Last),
483 Lib_Path_Name
: constant String_Ptr
:=
486 (Ptr
+ 1 .. Switch_Chars
'Last),
490 if Src_Path_Name
/= null and then
491 Lib_Path_Name
/= null
493 -- Set the RTS_*_Path_Name variables, so that the
494 -- correct directories will be set when
495 -- Osint.Add_Default_Search_Dirs will be called later.
497 RTS_Src_Path_Name
:= Src_Path_Name
;
498 RTS_Lib_Path_Name
:= Lib_Path_Name
;
502 elsif Src_Path_Name
= null
503 and then Lib_Path_Name
= null
505 Osint
.Fail
("RTS path not valid: missing " &
506 "adainclude and adalib directories");
507 elsif Src_Path_Name
= null then
508 Osint
.Fail
("RTS path not valid: missing " &
509 "adainclude directory");
510 elsif Lib_Path_Name
= null then
511 Osint
.Fail
("RTS path not valid: missing " &
518 Bad_Switch
(Switch_Chars
);
521 -- Anything else is an error (illegal switch character)
524 Bad_Switch
(Switch_Chars
);
528 Bad_Switch
(Switch_Chars
);
531 end Scan_Binder_Switches
;