Add hppa-openbsd target
[official-gcc.git] / gcc / ada / switch-b.adb
blob356e49854f19a1eed6a924b6849afe50c4dc79b3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S W I T C H - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 with Debug; use Debug;
29 with Osint; use Osint;
30 with Opt; use Opt;
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 Ptr : Integer := Switch_Chars'First;
42 Max : Integer := Switch_Chars'Last;
43 C : Character := ' ';
45 begin
46 -- Skip past the initial character (must be the switch character)
48 if Ptr = Max then
49 raise Bad_Switch;
50 else
51 Ptr := Ptr + 1;
52 end if;
54 -- A little check, "gnat" at the start of a switch is not allowed
55 -- except for the compiler
57 if Switch_Chars'Last >= Ptr + 3
58 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
59 then
60 Osint.Fail ("invalid switch: """, Switch_Chars, """"
61 & " (gnat not needed here)");
63 end if;
65 -- Loop to scan through switches given in switch string
67 while Ptr <= Max loop
68 C := Switch_Chars (Ptr);
70 case C is
72 -- Processing for A switch
74 when 'A' =>
75 Ptr := Ptr + 1;
77 Ada_Bind_File := True;
79 -- Processing for b switch
81 when 'b' =>
82 Ptr := Ptr + 1;
83 Brief_Output := True;
85 -- Processing for c switch
87 when 'c' =>
88 Ptr := Ptr + 1;
90 Check_Only := True;
92 -- Processing for C switch
94 when 'C' =>
95 Ptr := Ptr + 1;
97 Ada_Bind_File := False;
99 -- Processing for d switch
101 when 'd' =>
103 -- Note: for the debug switch, the remaining characters in this
104 -- switch field must all be debug flags, since all valid switch
105 -- characters are also valid debug characters. This switch is not
106 -- documented on purpose because it is only used by the
107 -- implementors.
109 -- Loop to scan out debug flags
111 while Ptr < Max loop
112 Ptr := Ptr + 1;
113 C := Switch_Chars (Ptr);
114 exit when C = ASCII.NUL or else C = '/' or else C = '-';
116 if C in '1' .. '9' or else
117 C in 'a' .. 'z' or else
118 C in 'A' .. 'Z'
119 then
120 Set_Debug_Flag (C);
121 else
122 raise Bad_Switch;
123 end if;
124 end loop;
126 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
127 -- is for backwards compatibility with old versions and usage.
129 if Debug_Flag_XX then
130 Zero_Cost_Exceptions_Set := True;
131 Zero_Cost_Exceptions_Val := True;
132 end if;
134 return;
136 -- Processing for e switch
138 when 'e' =>
139 Ptr := Ptr + 1;
140 Elab_Dependency_Output := True;
142 -- Processing for E switch
144 when 'E' =>
145 Ptr := Ptr + 1;
146 Exception_Tracebacks := True;
148 -- Processing for f switch
150 when 'f' =>
151 Ptr := Ptr + 1;
152 Force_RM_Elaboration_Order := True;
154 -- Processing for g switch
156 when 'g' =>
157 Ptr := Ptr + 1;
159 if Ptr <= Max then
160 C := Switch_Chars (Ptr);
162 if C in '0' .. '3' then
163 Debugger_Level :=
164 Character'Pos
165 (Switch_Chars (Ptr)) - Character'Pos ('0');
166 Ptr := Ptr + 1;
167 end if;
169 else
170 Debugger_Level := 2;
171 end if;
173 -- Processing for h switch
175 when 'h' =>
176 Ptr := Ptr + 1;
177 Usage_Requested := True;
179 -- Processing for i switch
181 when 'i' =>
182 if Ptr = Max then
183 raise Bad_Switch;
184 end if;
186 Ptr := Ptr + 1;
187 C := Switch_Chars (Ptr);
189 if C in '1' .. '5'
190 or else C = '8'
191 or else C = 'p'
192 or else C = 'f'
193 or else C = 'n'
194 or else C = 'w'
195 then
196 Identifier_Character_Set := C;
197 Ptr := Ptr + 1;
198 else
199 raise Bad_Switch;
200 end if;
202 -- Processing for K switch
204 when 'K' =>
205 Ptr := Ptr + 1;
206 Output_Linker_Option_List := True;
208 -- Processing for l switch
210 when 'l' =>
211 Ptr := Ptr + 1;
212 Elab_Order_Output := True;
214 -- Processing for m switch
216 when 'm' =>
217 Ptr := Ptr + 1;
218 Scan_Pos (Switch_Chars, Max, Ptr, Maximum_Errors);
220 -- Processing for n switch
222 when 'n' =>
223 Ptr := Ptr + 1;
224 Bind_Main_Program := False;
226 -- Note: The -L option of the binder also implies -n, so
227 -- any change here must also be reflected in the processing
228 -- for -L that is found in Gnatbind.Scan_Bind_Arg.
230 -- Processing for o switch
232 when 'o' =>
233 Ptr := Ptr + 1;
235 if Output_File_Name_Present then
236 raise Too_Many_Output_Files;
238 else
239 Output_File_Name_Present := True;
240 end if;
242 -- Processing for O switch
244 when 'O' =>
245 Ptr := Ptr + 1;
246 Output_Object_List := True;
248 -- Processing for p switch
250 when 'p' =>
251 Ptr := Ptr + 1;
252 Pessimistic_Elab_Order := True;
254 -- Processing for q switch
256 when 'q' =>
257 Ptr := Ptr + 1;
258 Quiet_Output := True;
260 -- Processing for r switch
262 when 'r' =>
263 Ptr := Ptr + 1;
264 List_Restrictions := True;
266 -- Processing for s switch
268 when 's' =>
269 Ptr := Ptr + 1;
270 All_Sources := True;
271 Check_Source_Files := True;
273 -- Processing for t switch
275 when 't' =>
276 Ptr := Ptr + 1;
277 Tolerate_Consistency_Errors := True;
279 -- Processing for T switch
281 when 'T' =>
282 Ptr := Ptr + 1;
283 Time_Slice_Set := True;
284 Scan_Nat (Switch_Chars, Max, Ptr, Time_Slice_Value);
286 -- Processing for v switch
288 when 'v' =>
289 Ptr := Ptr + 1;
290 Verbose_Mode := True;
292 -- Processing for w switch
294 when 'w' =>
296 -- For the binder we only allow suppress/error cases
298 Ptr := Ptr + 1;
300 case Switch_Chars (Ptr) is
302 when 'e' =>
303 Warning_Mode := Treat_As_Error;
305 when 's' =>
306 Warning_Mode := Suppress;
308 when others =>
309 raise Bad_Switch;
310 end case;
312 Ptr := Ptr + 1;
314 -- Processing for W switch
316 when 'W' =>
317 Ptr := Ptr + 1;
319 for J in WC_Encoding_Method loop
320 if Switch_Chars (Ptr) = WC_Encoding_Letters (J) then
321 Wide_Character_Encoding_Method := J;
322 exit;
324 elsif J = WC_Encoding_Method'Last then
325 raise Bad_Switch;
326 end if;
327 end loop;
329 Upper_Half_Encoding :=
330 Wide_Character_Encoding_Method in
331 WC_Upper_Half_Encoding_Method;
333 Ptr := Ptr + 1;
335 -- Processing for x switch
337 when 'x' =>
338 Ptr := Ptr + 1;
339 All_Sources := False;
340 Check_Source_Files := False;
342 -- Processing for z switch
344 when 'z' =>
345 Ptr := Ptr + 1;
346 No_Main_Subprogram := True;
348 -- Ignore extra switch character
350 when '/' =>
351 Ptr := Ptr + 1;
353 -- Ignore '-' extra switch caracter, only if it isn't followed by
354 -- 'RTS'. If it is, then we must process the 'RTS' switch
356 when '-' =>
358 if Ptr + 3 <= Max and then
359 Switch_Chars (Ptr + 1 .. Ptr + 3) = "RTS"
360 then
361 Ptr := Ptr + 1;
363 if Switch_Chars (Ptr + 3) /= '=' or else
364 (Switch_Chars (Ptr + 3) = '='
365 and then Ptr + 4 > Max)
366 then
367 Osint.Fail ("missing path for --RTS");
368 else
370 -- valid --RTS switch
371 Opt.No_Stdinc := True;
372 Opt.RTS_Switch := True;
374 declare
375 Src_Path_Name : String_Ptr := Get_RTS_Search_Dir
376 (Switch_Chars (Ptr + 4 .. Switch_Chars'Last), Include);
377 Lib_Path_Name : String_Ptr := Get_RTS_Search_Dir
378 (Switch_Chars (Ptr + 4 .. Switch_Chars'Last), Objects);
379 begin
380 if Src_Path_Name /= null and then
381 Lib_Path_Name /= null
382 then
383 Add_Search_Dirs (Src_Path_Name, Include);
384 Add_Search_Dirs (Lib_Path_Name, Objects);
385 -- we can exit as there can not be another switch
386 -- after --RTS
387 exit;
388 elsif Src_Path_Name = null
389 and Lib_Path_Name = null then
390 Osint.Fail ("RTS path not valid: missing " &
391 "adainclude and adalib directories");
392 elsif Src_Path_Name = null then
393 Osint.Fail ("RTS path not valid: missing " &
394 "adainclude directory");
395 elsif Lib_Path_Name = null then
396 Osint.Fail ("RTS path not valid: missing " &
397 "adalib directory");
398 end if;
399 end;
400 end if;
402 else
403 Ptr := Ptr + 1;
404 end if;
406 -- Anything else is an error (illegal switch character)
408 when others =>
409 raise Bad_Switch;
410 end case;
411 end loop;
413 exception
414 when Bad_Switch =>
415 Osint.Fail ("invalid switch: ", (1 => C));
417 when Bad_Switch_Value =>
418 Osint.Fail ("numeric value too big for switch: ", (1 => C));
420 when Missing_Switch_Value =>
421 Osint.Fail ("missing numeric value for switch: ", (1 => C));
423 when Too_Many_Output_Files =>
424 Osint.Fail ("duplicate -o switch");
425 end Scan_Binder_Switches;
427 end Switch.B;