1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
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. --
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). --
26 ------------------------------------------------------------------------------
28 with Debug; use Debug;
29 with Osint; use Osint;
33 package body Switch.M is
35 package Normalized_Switches is new Table.Table
36 (Table_Component_Type => String_Access,
37 Table_Index_Type => Integer,
40 Table_Increment => 100,
41 Table_Name => "Switch.C.Normalized_Switches");
42 -- This table is used to keep the normalized switches, so that they may be
43 -- reused for subsequent invocations of Normalize_Compiler_Switches with
46 Initial_Number_Of_Switches : constant := 10;
48 Global_Switches : Argument_List_Access := null;
49 -- Used by function Normalize_Compiler_Switches
51 ---------------------------------
52 -- Normalize_Compiler_Switches --
53 ---------------------------------
55 procedure Normalize_Compiler_Switches
56 (Switch_Chars : String;
57 Switches : in out Argument_List_Access;
60 Switch_Starts_With_Gnat : Boolean;
62 Ptr : Integer := Switch_Chars'First;
63 Max : constant Integer := Switch_Chars'Last;
66 First_Char : Integer := Ptr;
67 Storing : String := Switch_Chars;
68 First_Stored : Positive := Ptr + 1;
69 Last_Stored : Positive := First_Stored;
71 procedure Add_Switch_Component (S : String);
72 -- Add a new String_Access component in Switches. If a string equal
73 -- to S is already stored in the table Normalized_Switches, use it.
74 -- Other wise add a new component to the table.
76 --------------------------
77 -- Add_Switch_Component --
78 --------------------------
80 procedure Add_Switch_Component (S : String) is
82 -- If Switches is null, allocate a new array
84 if Switches = null then
85 Switches := new Argument_List (1 .. Initial_Number_Of_Switches);
87 -- otherwise, if Switches is full, extend it
89 elsif Last = Switches'Last then
91 New_Switches : Argument_List_Access := new Argument_List
92 (1 .. Switches'Length + Switches'Length);
94 New_Switches (1 .. Switches'Length) := Switches.all;
95 Last := Switches'Length;
96 Switches := New_Switches;
100 -- If this is the first switch, Last designates the first component
102 Last := Switches'First;
108 -- Look into the table Normalized_Switches for a similar string.
109 -- If one is found, put it at the added component, and return.
111 for Index in 1 .. Normalized_Switches.Last loop
112 if S = Normalized_Switches.Table (Index).all then
113 Switches (Last) := Normalized_Switches.Table (Index);
118 -- No string equal to S was found in the table Normalized_Switches.
119 -- Add a new component in the table.
121 Switches (Last) := new String'(S);
122 Normalized_Switches.Increment_Last;
123 Normalized_Switches.Table (Normalized_Switches.Last) :=
125 end Add_Switch_Component;
127 -- Start of processing for Normalize_Compiler_Switches
132 if Ptr = Max or else Switch_Chars (Ptr) /= '-' then
138 Switch_Starts_With_Gnat :=
139 Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
141 if Switch_Starts_With_Gnat then
146 while Ptr <= Max loop
148 C := Switch_Chars (Ptr);
150 -- Processing for a switch
152 case Switch_Starts_With_Gnat is
155 -- All switches that don't start with -gnat stay as is
157 Add_Switch_Component (Switch_Chars);
164 -- One-letter switches
166 when 'a' | 'A' | 'b' | 'c' | 'C' | 'D' | 'E' | 'f' |
167 'F' | 'g' | 'h' | 'H' | 'k' | 'l' | 'L' | 'n' | 'N' |
168 'o' | 'O' | 'p' | 'P' | 'q' | 'Q' | 'r' | 's' | 't' |
169 'u' | 'U' | 'v' | 'x' | 'X' | 'Z' =>
170 Storing (First_Stored) := C;
172 (Storing (Storing'First .. First_Stored));
175 -- One-letter switches followed by a positive number
178 Storing (First_Stored) := C;
179 Last_Stored := First_Stored;
184 or else Switch_Chars (Ptr) not in '0' .. '9';
185 Last_Stored := Last_Stored + 1;
186 Storing (Last_Stored) := Switch_Chars (Ptr);
190 (Storing (Storing'First .. Last_Stored));
193 Storing (First_Stored) := 'd';
197 C := Switch_Chars (Ptr);
198 exit when C = ASCII.NUL or else C = '/'
201 if C in '1' .. '9' or else
202 C in 'a' .. 'z' or else
205 Storing (First_Stored + 1) := C;
207 (Storing (Storing'First .. First_Stored + 1));
218 -- None of the -gnate switches (-gnatec and -gnatem)
219 -- need to be store in an ALI file.
224 Storing (First_Stored) := 'i';
233 C := Switch_Chars (Ptr);
242 Storing (First_Stored + 1) := C;
244 (Storing (Storing'First .. First_Stored + 1));
252 -- -gnatR may be followed by '0', '1', '2' or '3',
256 Last_Stored := First_Stored;
257 Storing (Last_Stored) := 'R';
261 and then Switch_Chars (Ptr) in '0' .. '9'
263 C := Switch_Chars (Ptr);
265 if C in '4' .. '9' then
270 Last_Stored := Last_Stored + 1;
271 Storing (Last_Stored) := C;
275 and then Switch_Chars (Ptr) = 's' then
276 Last_Stored := Last_Stored + 1;
277 Storing (Last_Stored) := 's';
284 (Storing (Storing'First .. Last_Stored));
288 when 'V' | 'w' | 'y' =>
289 Storing (First_Stored) := C;
295 (Storing (Storing'First .. First_Stored));
303 while Ptr <= Max loop
304 C := Switch_Chars (Ptr);
307 -- 'w' should be skipped in -gnatw
309 if C /= 'w' or else Storing (First_Stored) /= 'w' then
314 and then Storing (First_Stored) = 'y' then
315 Last_Stored := First_Stored + 1;
316 Storing (Last_Stored) := 'M';
318 while Ptr <= Max loop
319 C := Switch_Chars (Ptr);
320 exit when C not in '0' .. '9';
321 Last_Stored := Last_Stored + 1;
322 Storing (Last_Stored) := C;
326 -- If there is no digit after -gnatyM,
327 -- the switch is invalid.
329 if Last_Stored = First_Stored + 1 then
335 (Storing (Storing'First .. Last_Stored));
338 -- All other switches are -gnatxx
341 Storing (First_Stored + 1) := C;
343 (Storing (Storing'First .. First_Stored + 1));
348 -- Not a valid switch
358 end Normalize_Compiler_Switches;
360 function Normalize_Compiler_Switches
361 (Switch_Chars : String)
367 Normalize_Compiler_Switches (Switch_Chars, Global_Switches, Last);
370 return (1 .. 0 => null);
373 return Global_Switches (Global_Switches'First .. Last);
376 end Normalize_Compiler_Switches;
378 ------------------------
379 -- Scan_Make_Switches --
380 ------------------------
382 procedure Scan_Make_Switches (Switch_Chars : String) is
383 Ptr : Integer := Switch_Chars'First;
384 Max : Integer := Switch_Chars'Last;
385 C : Character := ' ';
388 -- Skip past the initial character (must be the switch character)
397 -- A little check, "gnat" at the start of a switch is not allowed
398 -- except for the compiler (where it was already removed)
400 if Switch_Chars'Length >= Ptr + 3
401 and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
404 ("invalid switch: """, Switch_Chars, """ (gnat not needed here)");
407 -- Loop to scan through switches given in switch string
409 while Ptr <= Max loop
410 C := Switch_Chars (Ptr);
412 -- Processing for a switch
418 Check_Readonly_Files := True;
420 -- Processing for b switch
426 -- Processing for c switch
430 Compile_Only := True;
432 -- Processing for C switch
436 Create_Mapping_File := True;
438 -- Processing for d switch
442 -- Note: for the debug switch, the remaining characters in this
443 -- switch field must all be debug flags, since all valid switch
444 -- characters are also valid debug characters. This switch is not
445 -- documented on purpose because it is only used by the
448 -- Loop to scan out debug flags
452 C := Switch_Chars (Ptr);
453 exit when C = ASCII.NUL or else C = '/' or else C = '-';
455 if C in '1' .. '9' or else
456 C in 'a' .. 'z' or else
465 -- Make sure Zero_Cost_Exceptions is set if gnatdX set. This
466 -- is for backwards compatibility with old versions and usage.
468 if Debug_Flag_XX then
469 Zero_Cost_Exceptions_Set := True;
470 Zero_Cost_Exceptions_Val := True;
475 -- Processing for f switch
479 Force_Compilations := True;
481 -- Processing for h switch
485 Usage_Requested := True;
487 -- Processing for i switch
491 In_Place_Mode := True;
493 -- Processing for j switch
501 Scan_Pos (Switch_Chars, Max, Ptr, Max_Proc);
502 Maximum_Processes := Positive (Max_Proc);
505 -- Processing for k switch
511 -- Processing for l switch
519 List_Dependencies := True;
521 -- Processing for n switch
525 Do_Not_Execute := True;
527 -- Processing for o switch
532 if Output_File_Name_Present then
533 raise Too_Many_Output_Files;
535 Output_File_Name_Present := True;
538 -- Processing for q switch
542 Quiet_Output := True;
544 -- Processing for s switch
548 Check_Switches := True;
550 -- Processing for v switch
554 Verbose_Mode := True;
556 -- Processing for z switch
560 No_Main_Subprogram := True;
562 -- Ignore extra switch character
567 -- Anything else is an error (illegal switch character)
577 Osint.Fail ("invalid switch: ", (1 => C));
579 when Bad_Switch_Value =>
580 Osint.Fail ("numeric value too big for switch: ", (1 => C));
582 when Missing_Switch_Value =>
583 Osint.Fail ("missing numeric value for switch: ", (1 => C));
585 when Too_Many_Output_Files =>
586 Osint.Fail ("duplicate -o switch");
588 end Scan_Make_Switches;