annotate gcc/ada/switch.adb @ 138:fc828634a951

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:17:14 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S W I T C H --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Osint; use Osint;
kono
parents:
diff changeset
27 with Output; use Output;
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 package body Switch is
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 ----------------
kono
parents:
diff changeset
32 -- Bad_Switch --
kono
parents:
diff changeset
33 ----------------
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 procedure Bad_Switch (Switch : Character) is
kono
parents:
diff changeset
36 begin
kono
parents:
diff changeset
37 Osint.Fail ("invalid switch: " & Switch);
kono
parents:
diff changeset
38 end Bad_Switch;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 procedure Bad_Switch (Switch : String) is
kono
parents:
diff changeset
41 begin
kono
parents:
diff changeset
42 Osint.Fail ("invalid switch: " & Switch);
kono
parents:
diff changeset
43 end Bad_Switch;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 ------------------------------
kono
parents:
diff changeset
46 -- Check_Version_And_Help_G --
kono
parents:
diff changeset
47 ------------------------------
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 procedure Check_Version_And_Help_G
kono
parents:
diff changeset
50 (Tool_Name : String;
kono
parents:
diff changeset
51 Initial_Year : String;
kono
parents:
diff changeset
52 Version_String : String := Gnatvsn.Gnat_Version_String)
kono
parents:
diff changeset
53 is
kono
parents:
diff changeset
54 Version_Switch_Present : Boolean := False;
kono
parents:
diff changeset
55 Help_Switch_Present : Boolean := False;
kono
parents:
diff changeset
56 Next_Arg : Natural;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 begin
kono
parents:
diff changeset
59 -- First check for --version or --help
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Next_Arg := 1;
kono
parents:
diff changeset
62 while Next_Arg < Arg_Count loop
kono
parents:
diff changeset
63 declare
kono
parents:
diff changeset
64 Next_Argv : String (1 .. Len_Arg (Next_Arg));
kono
parents:
diff changeset
65 begin
kono
parents:
diff changeset
66 Fill_Arg (Next_Argv'Address, Next_Arg);
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 if Next_Argv = Version_Switch then
kono
parents:
diff changeset
69 Version_Switch_Present := True;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 elsif Next_Argv = Help_Switch then
kono
parents:
diff changeset
72 Help_Switch_Present := True;
kono
parents:
diff changeset
73 end if;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 Next_Arg := Next_Arg + 1;
kono
parents:
diff changeset
76 end;
kono
parents:
diff changeset
77 end loop;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- If --version was used, display version and exit
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 if Version_Switch_Present then
kono
parents:
diff changeset
82 Set_Standard_Output;
kono
parents:
diff changeset
83 Display_Version (Tool_Name, Initial_Year, Version_String);
kono
parents:
diff changeset
84 Write_Str (Gnatvsn.Gnat_Free_Software);
kono
parents:
diff changeset
85 Write_Eol;
kono
parents:
diff changeset
86 Write_Eol;
kono
parents:
diff changeset
87 Exit_Program (E_Success);
kono
parents:
diff changeset
88 end if;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 -- If --help was used, display help and exit
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 if Help_Switch_Present then
kono
parents:
diff changeset
93 Set_Standard_Output;
kono
parents:
diff changeset
94 Usage;
kono
parents:
diff changeset
95 Write_Eol;
kono
parents:
diff changeset
96 Write_Line ("Report bugs to report@adacore.com");
kono
parents:
diff changeset
97 Exit_Program (E_Success);
kono
parents:
diff changeset
98 end if;
kono
parents:
diff changeset
99 end Check_Version_And_Help_G;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 ------------------------------------
kono
parents:
diff changeset
102 -- Display_Usage_Version_And_Help --
kono
parents:
diff changeset
103 ------------------------------------
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 procedure Display_Usage_Version_And_Help is
kono
parents:
diff changeset
106 begin
kono
parents:
diff changeset
107 Write_Str (" --version Display version and exit");
kono
parents:
diff changeset
108 Write_Eol;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 Write_Str (" --help Display usage and exit");
kono
parents:
diff changeset
111 Write_Eol;
kono
parents:
diff changeset
112 Write_Eol;
kono
parents:
diff changeset
113 end Display_Usage_Version_And_Help;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 ---------------------
kono
parents:
diff changeset
116 -- Display_Version --
kono
parents:
diff changeset
117 ---------------------
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 procedure Display_Version
kono
parents:
diff changeset
120 (Tool_Name : String;
kono
parents:
diff changeset
121 Initial_Year : String;
kono
parents:
diff changeset
122 Version_String : String := Gnatvsn.Gnat_Version_String)
kono
parents:
diff changeset
123 is
kono
parents:
diff changeset
124 begin
kono
parents:
diff changeset
125 Write_Str (Tool_Name);
kono
parents:
diff changeset
126 Write_Char (' ');
kono
parents:
diff changeset
127 Write_Str (Version_String);
kono
parents:
diff changeset
128 Write_Eol;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 Write_Str ("Copyright (C) ");
kono
parents:
diff changeset
131 Write_Str (Initial_Year);
kono
parents:
diff changeset
132 Write_Char ('-');
kono
parents:
diff changeset
133 Write_Str (Gnatvsn.Current_Year);
kono
parents:
diff changeset
134 Write_Str (", ");
kono
parents:
diff changeset
135 Write_Str (Gnatvsn.Copyright_Holder);
kono
parents:
diff changeset
136 Write_Eol;
kono
parents:
diff changeset
137 end Display_Version;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 -------------------------
kono
parents:
diff changeset
140 -- Is_Front_End_Switch --
kono
parents:
diff changeset
141 -------------------------
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
kono
parents:
diff changeset
144 Ptr : constant Positive := Switch_Chars'First;
kono
parents:
diff changeset
145 begin
kono
parents:
diff changeset
146 return Is_Switch (Switch_Chars)
kono
parents:
diff changeset
147 and then
kono
parents:
diff changeset
148 (Switch_Chars (Ptr + 1) = 'I'
kono
parents:
diff changeset
149 or else (Switch_Chars'Length >= 5
kono
parents:
diff changeset
150 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
kono
parents:
diff changeset
151 or else (Switch_Chars'Length >= 5
kono
parents:
diff changeset
152 and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
kono
parents:
diff changeset
153 end Is_Front_End_Switch;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 ----------------------------
kono
parents:
diff changeset
156 -- Is_Internal_GCC_Switch --
kono
parents:
diff changeset
157 ----------------------------
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 function Is_Internal_GCC_Switch (Switch_Chars : String) return Boolean is
kono
parents:
diff changeset
160 First : constant Natural := Switch_Chars'First + 1;
kono
parents:
diff changeset
161 Last : constant Natural := Switch_Last (Switch_Chars);
kono
parents:
diff changeset
162 begin
kono
parents:
diff changeset
163 return Is_Switch (Switch_Chars)
kono
parents:
diff changeset
164 and then
kono
parents:
diff changeset
165 (Switch_Chars (First .. Last) = "-param" or else
kono
parents:
diff changeset
166 Switch_Chars (First .. Last) = "dumpbase" or else
kono
parents:
diff changeset
167 Switch_Chars (First .. Last) = "auxbase-strip" or else
kono
parents:
diff changeset
168 Switch_Chars (First .. Last) = "auxbase");
kono
parents:
diff changeset
169 end Is_Internal_GCC_Switch;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 ---------------
kono
parents:
diff changeset
172 -- Is_Switch --
kono
parents:
diff changeset
173 ---------------
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 function Is_Switch (Switch_Chars : String) return Boolean is
kono
parents:
diff changeset
176 begin
kono
parents:
diff changeset
177 return Switch_Chars'Length > 1
kono
parents:
diff changeset
178 and then Switch_Chars (Switch_Chars'First) = '-';
kono
parents:
diff changeset
179 end Is_Switch;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 -----------------
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 -- Switch_Last --
111
kono
parents:
diff changeset
183 -----------------
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 function Switch_Last (Switch_Chars : String) return Natural is
kono
parents:
diff changeset
186 Last : constant Natural := Switch_Chars'Last;
kono
parents:
diff changeset
187 begin
kono
parents:
diff changeset
188 if Last >= Switch_Chars'First
kono
parents:
diff changeset
189 and then Switch_Chars (Last) = ASCII.NUL
kono
parents:
diff changeset
190 then
kono
parents:
diff changeset
191 return Last - 1;
kono
parents:
diff changeset
192 else
kono
parents:
diff changeset
193 return Last;
kono
parents:
diff changeset
194 end if;
kono
parents:
diff changeset
195 end Switch_Last;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 -----------------
kono
parents:
diff changeset
198 -- Nat_Present --
kono
parents:
diff changeset
199 -----------------
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 function Nat_Present
kono
parents:
diff changeset
202 (Switch_Chars : String;
kono
parents:
diff changeset
203 Max : Integer;
kono
parents:
diff changeset
204 Ptr : Integer) return Boolean
kono
parents:
diff changeset
205 is
kono
parents:
diff changeset
206 begin
kono
parents:
diff changeset
207 return (Ptr <= Max
kono
parents:
diff changeset
208 and then Switch_Chars (Ptr) in '0' .. '9')
kono
parents:
diff changeset
209 or else
kono
parents:
diff changeset
210 (Ptr < Max
kono
parents:
diff changeset
211 and then Switch_Chars (Ptr) = '='
kono
parents:
diff changeset
212 and then Switch_Chars (Ptr + 1) in '0' .. '9');
kono
parents:
diff changeset
213 end Nat_Present;
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 --------------
kono
parents:
diff changeset
216 -- Scan_Nat --
kono
parents:
diff changeset
217 --------------
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 procedure Scan_Nat
kono
parents:
diff changeset
220 (Switch_Chars : String;
kono
parents:
diff changeset
221 Max : Integer;
kono
parents:
diff changeset
222 Ptr : in out Integer;
kono
parents:
diff changeset
223 Result : out Nat;
kono
parents:
diff changeset
224 Switch : Character)
kono
parents:
diff changeset
225 is
kono
parents:
diff changeset
226 begin
kono
parents:
diff changeset
227 Result := 0;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if not Nat_Present (Switch_Chars, Max, Ptr) then
kono
parents:
diff changeset
230 Osint.Fail ("missing numeric value for switch: " & Switch);
kono
parents:
diff changeset
231 end if;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 if Switch_Chars (Ptr) = '=' then
kono
parents:
diff changeset
234 Ptr := Ptr + 1;
kono
parents:
diff changeset
235 end if;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
kono
parents:
diff changeset
238 Result :=
kono
parents:
diff changeset
239 Result * 10 +
kono
parents:
diff changeset
240 Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
kono
parents:
diff changeset
241 Ptr := Ptr + 1;
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 if Result > Switch_Max_Value then
kono
parents:
diff changeset
244 Osint.Fail ("numeric value out of range for switch: " & Switch);
kono
parents:
diff changeset
245 end if;
kono
parents:
diff changeset
246 end loop;
kono
parents:
diff changeset
247 end Scan_Nat;
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 --------------
kono
parents:
diff changeset
250 -- Scan_Pos --
kono
parents:
diff changeset
251 --------------
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 procedure Scan_Pos
kono
parents:
diff changeset
254 (Switch_Chars : String;
kono
parents:
diff changeset
255 Max : Integer;
kono
parents:
diff changeset
256 Ptr : in out Integer;
kono
parents:
diff changeset
257 Result : out Pos;
kono
parents:
diff changeset
258 Switch : Character)
kono
parents:
diff changeset
259 is
kono
parents:
diff changeset
260 Temp : Nat;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 begin
kono
parents:
diff changeset
263 Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch);
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 if Temp = 0 then
kono
parents:
diff changeset
266 Osint.Fail ("numeric value out of range for switch: " & Switch);
kono
parents:
diff changeset
267 end if;
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 Result := Temp;
kono
parents:
diff changeset
270 end Scan_Pos;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 end Switch;