68944c7cc3cf2a313b60c51dd83853178f930177
[gcc.git] / gcc / ada / opt.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O P T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Gnatvsn; use Gnatvsn;
33 with System; use System;
34 with Tree_IO; use Tree_IO;
35
36 package body Opt is
37
38 SU : constant := Storage_Unit;
39 -- Shorthand for System.Storage_Unit
40
41 ----------------------------------
42 -- Register_Opt_Config_Switches --
43 ----------------------------------
44
45 procedure Register_Opt_Config_Switches is
46 begin
47 Ada_Version_Config := Ada_Version;
48 Ada_Version_Pragma_Config := Ada_Version_Pragma;
49 Ada_Version_Explicit_Config := Ada_Version_Explicit;
50 Assertions_Enabled_Config := Assertions_Enabled;
51 Assume_No_Invalid_Values_Config := Assume_No_Invalid_Values;
52 Check_Float_Overflow_Config := Check_Float_Overflow;
53 Check_Policy_List_Config := Check_Policy_List;
54 Default_Pool_Config := Default_Pool;
55 Dynamic_Elaboration_Checks_Config := Dynamic_Elaboration_Checks;
56 Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
57 Extensions_Allowed_Config := Extensions_Allowed;
58 External_Name_Exp_Casing_Config := External_Name_Exp_Casing;
59 External_Name_Imp_Casing_Config := External_Name_Imp_Casing;
60 Fast_Math_Config := Fast_Math;
61 Initialize_Scalars_Config := Initialize_Scalars;
62 Optimize_Alignment_Config := Optimize_Alignment;
63 Persistent_BSS_Mode_Config := Persistent_BSS_Mode;
64 Polling_Required_Config := Polling_Required;
65 Short_Descriptors_Config := Short_Descriptors;
66 SPARK_Mode_Config := SPARK_Mode;
67 SPARK_Mode_Pragma_Config := SPARK_Mode_Pragma;
68 Uneval_Old_Config := Uneval_Old;
69 Use_VADS_Size_Config := Use_VADS_Size;
70 Warnings_As_Errors_Count_Config := Warnings_As_Errors_Count;
71
72 -- Reset the indication that Optimize_Alignment was set locally, since
73 -- if we had a pragma in the config file, it would set this flag True,
74 -- but that's not a local setting.
75
76 Optimize_Alignment_Local := False;
77 end Register_Opt_Config_Switches;
78
79 ---------------------------------
80 -- Restore_Opt_Config_Switches --
81 ---------------------------------
82
83 procedure Restore_Opt_Config_Switches (Save : Config_Switches_Type) is
84 begin
85 Ada_Version := Save.Ada_Version;
86 Ada_Version_Pragma := Save.Ada_Version_Pragma;
87 Ada_Version_Explicit := Save.Ada_Version_Explicit;
88 Assertions_Enabled := Save.Assertions_Enabled;
89 Assume_No_Invalid_Values := Save.Assume_No_Invalid_Values;
90 Check_Float_Overflow := Save.Check_Float_Overflow;
91 Check_Policy_List := Save.Check_Policy_List;
92 Default_Pool := Save.Default_Pool;
93 Dynamic_Elaboration_Checks := Save.Dynamic_Elaboration_Checks;
94 Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
95 Extensions_Allowed := Save.Extensions_Allowed;
96 External_Name_Exp_Casing := Save.External_Name_Exp_Casing;
97 External_Name_Imp_Casing := Save.External_Name_Imp_Casing;
98 Fast_Math := Save.Fast_Math;
99 Initialize_Scalars := Save.Initialize_Scalars;
100 Optimize_Alignment := Save.Optimize_Alignment;
101 Optimize_Alignment_Local := Save.Optimize_Alignment_Local;
102 Persistent_BSS_Mode := Save.Persistent_BSS_Mode;
103 Polling_Required := Save.Polling_Required;
104 Short_Descriptors := Save.Short_Descriptors;
105 SPARK_Mode := Save.SPARK_Mode;
106 SPARK_Mode_Pragma := Save.SPARK_Mode_Pragma;
107 Uneval_Old := Save.Uneval_Old;
108 Use_VADS_Size := Save.Use_VADS_Size;
109 Warnings_As_Errors_Count := Save.Warnings_As_Errors_Count;
110
111 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
112 -- Normalize_Scalars is not saved/restored because after set to True its
113 -- value is never changed. That is, if a compilation unit has pragma
114 -- Normalize_Scalars then it forces that value for all with'ed units.
115
116 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
117 end Restore_Opt_Config_Switches;
118
119 ------------------------------
120 -- Save_Opt_Config_Switches --
121 ------------------------------
122
123 procedure Save_Opt_Config_Switches (Save : out Config_Switches_Type) is
124 begin
125 Save.Ada_Version := Ada_Version;
126 Save.Ada_Version_Pragma := Ada_Version_Pragma;
127 Save.Ada_Version_Explicit := Ada_Version_Explicit;
128 Save.Assertions_Enabled := Assertions_Enabled;
129 Save.Assume_No_Invalid_Values := Assume_No_Invalid_Values;
130 Save.Check_Float_Overflow := Check_Float_Overflow;
131 Save.Check_Policy_List := Check_Policy_List;
132 Save.Default_Pool := Default_Pool;
133 Save.Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks;
134 Save.Exception_Locations_Suppressed := Exception_Locations_Suppressed;
135 Save.Extensions_Allowed := Extensions_Allowed;
136 Save.External_Name_Exp_Casing := External_Name_Exp_Casing;
137 Save.External_Name_Imp_Casing := External_Name_Imp_Casing;
138 Save.Fast_Math := Fast_Math;
139 Save.Initialize_Scalars := Initialize_Scalars;
140 Save.Optimize_Alignment := Optimize_Alignment;
141 Save.Optimize_Alignment_Local := Optimize_Alignment_Local;
142 Save.Persistent_BSS_Mode := Persistent_BSS_Mode;
143 Save.Polling_Required := Polling_Required;
144 Save.Short_Descriptors := Short_Descriptors;
145 Save.SPARK_Mode := SPARK_Mode;
146 Save.SPARK_Mode_Pragma := SPARK_Mode_Pragma;
147 Save.Uneval_Old := Uneval_Old;
148 Save.Use_VADS_Size := Use_VADS_Size;
149 Save.Warnings_As_Errors_Count := Warnings_As_Errors_Count;
150 end Save_Opt_Config_Switches;
151
152 -----------------------------
153 -- Set_Opt_Config_Switches --
154 -----------------------------
155
156 procedure Set_Opt_Config_Switches
157 (Internal_Unit : Boolean;
158 Main_Unit : Boolean)
159 is
160 begin
161 -- Case of internal unit
162
163 if Internal_Unit then
164
165 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
166 -- since the whole point of this is that it still properly indicates
167 -- the configuration setting even in a run time unit.
168
169 Ada_Version := Ada_Version_Runtime;
170 Ada_Version_Pragma := Empty;
171 Dynamic_Elaboration_Checks := False;
172 Extensions_Allowed := True;
173 External_Name_Exp_Casing := As_Is;
174 External_Name_Imp_Casing := Lowercase;
175 Optimize_Alignment := 'O';
176 Persistent_BSS_Mode := False;
177 Uneval_Old := 'E';
178 Use_VADS_Size := False;
179 Optimize_Alignment_Local := True;
180
181 -- Note: we do not need to worry about Warnings_As_Errors_Count since
182 -- we do not expect to get any warnings from compiling such a unit.
183
184 -- For an internal unit, assertions/debug pragmas are off unless this
185 -- is the main unit and they were explicitly enabled. We also make
186 -- sure we do not assume that values are necessarily valid and that
187 -- SPARK_Mode is set to its configuration value.
188
189 if Main_Unit then
190 Assertions_Enabled := Assertions_Enabled_Config;
191 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
192 Check_Policy_List := Check_Policy_List_Config;
193 SPARK_Mode := SPARK_Mode_Config;
194 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
195 else
196 Assertions_Enabled := False;
197 Assume_No_Invalid_Values := False;
198 Check_Policy_List := Empty;
199 SPARK_Mode := None;
200 SPARK_Mode_Pragma := Empty;
201 end if;
202
203 -- Case of non-internal unit
204
205 else
206 Ada_Version := Ada_Version_Config;
207 Ada_Version_Pragma := Ada_Version_Pragma_Config;
208 Ada_Version_Explicit := Ada_Version_Explicit_Config;
209 Assertions_Enabled := Assertions_Enabled_Config;
210 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
211 Check_Float_Overflow := Check_Float_Overflow_Config;
212 Check_Policy_List := Check_Policy_List_Config;
213 Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
214 Extensions_Allowed := Extensions_Allowed_Config;
215 External_Name_Exp_Casing := External_Name_Exp_Casing_Config;
216 External_Name_Imp_Casing := External_Name_Imp_Casing_Config;
217 Fast_Math := Fast_Math_Config;
218 Initialize_Scalars := Initialize_Scalars_Config;
219 Optimize_Alignment := Optimize_Alignment_Config;
220 Optimize_Alignment_Local := False;
221 Persistent_BSS_Mode := Persistent_BSS_Mode_Config;
222 SPARK_Mode := SPARK_Mode_Config;
223 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
224 Uneval_Old := Uneval_Old_Config;
225 Use_VADS_Size := Use_VADS_Size_Config;
226 Warnings_As_Errors_Count := Warnings_As_Errors_Count_Config;
227
228 -- Update consistently the value of Init_Or_Norm_Scalars. The value
229 -- of Normalize_Scalars is not saved/restored because once set to
230 -- True its value is never changed. That is, if a compilation unit
231 -- has pragma Normalize_Scalars then it forces that value for all
232 -- with'ed units.
233
234 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
235 end if;
236
237 Default_Pool := Default_Pool_Config;
238 Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
239 Fast_Math := Fast_Math_Config;
240 Optimize_Alignment := Optimize_Alignment_Config;
241 Polling_Required := Polling_Required_Config;
242 Short_Descriptors := Short_Descriptors_Config;
243 end Set_Opt_Config_Switches;
244
245 ---------------
246 -- Tree_Read --
247 ---------------
248
249 procedure Tree_Read is
250 Tree_Version_String_Len : Nat;
251 Ada_Version_Config_Val : Nat;
252 Ada_Version_Explicit_Config_Val : Nat;
253 Assertions_Enabled_Config_Val : Nat;
254
255 begin
256 Tree_Read_Int (Tree_ASIS_Version_Number);
257
258 Tree_Read_Bool (Address_Is_Private);
259 Tree_Read_Bool (Brief_Output);
260 Tree_Read_Bool (GNAT_Mode);
261 Tree_Read_Char (Identifier_Character_Set);
262 Tree_Read_Bool (Ignore_Rep_Clauses);
263 Tree_Read_Bool (Ignore_Style_Checks_Pragmas);
264 Tree_Read_Int (Maximum_File_Name_Length);
265 Tree_Read_Data (Suppress_Options'Address,
266 (Suppress_Options'Size + SU - 1) / SU);
267 Tree_Read_Bool (Verbose_Mode);
268 Tree_Read_Data (Warning_Mode'Address,
269 (Warning_Mode'Size + SU - 1) / SU);
270 Tree_Read_Int (Ada_Version_Config_Val);
271 Tree_Read_Int (Ada_Version_Explicit_Config_Val);
272 Tree_Read_Int (Assertions_Enabled_Config_Val);
273 Tree_Read_Bool (All_Errors_Mode);
274 Tree_Read_Bool (Assertions_Enabled);
275 Tree_Read_Bool (Check_Float_Overflow);
276 Tree_Read_Int (Int (Check_Policy_List));
277 Tree_Read_Int (Int (Default_Pool));
278 Tree_Read_Bool (Full_List);
279
280 Ada_Version_Config :=
281 Ada_Version_Type'Val (Ada_Version_Config_Val);
282 Ada_Version_Explicit_Config :=
283 Ada_Version_Type'Val (Ada_Version_Explicit_Config_Val);
284 Assertions_Enabled_Config :=
285 Boolean'Val (Assertions_Enabled_Config_Val);
286
287 -- Read version string: we have to get the length first
288
289 Tree_Read_Int (Tree_Version_String_Len);
290
291 declare
292 Tmp : String (1 .. Integer (Tree_Version_String_Len));
293 begin
294 Tree_Read_Data
295 (Tmp'Address, Tree_Version_String_Len);
296 System.Strings.Free (Tree_Version_String);
297 Free (Tree_Version_String);
298 Tree_Version_String := new String'(Tmp);
299 end;
300
301 Tree_Read_Data (Distribution_Stub_Mode'Address,
302 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
303 Tree_Read_Bool (Inline_Active);
304 Tree_Read_Bool (Inline_Processing_Required);
305 Tree_Read_Bool (List_Units);
306 Tree_Read_Int (Multiple_Unit_Index);
307 Tree_Read_Bool (Configurable_Run_Time_Mode);
308 Tree_Read_Data (Operating_Mode'Address,
309 (Operating_Mode'Size + SU - 1) / Storage_Unit);
310 Tree_Read_Bool (Suppress_Checks);
311 Tree_Read_Bool (Try_Semantics);
312 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
313 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
314 Tree_Read_Bool (Upper_Half_Encoding);
315 Tree_Read_Bool (Force_ALI_Tree_File);
316 end Tree_Read;
317
318 ----------------
319 -- Tree_Write --
320 ----------------
321
322 procedure Tree_Write is
323 Version_String : String := Gnat_Version_String;
324
325 begin
326 Tree_Write_Int (ASIS_Version_Number);
327
328 Tree_Write_Bool (Address_Is_Private);
329 Tree_Write_Bool (Brief_Output);
330 Tree_Write_Bool (GNAT_Mode);
331 Tree_Write_Char (Identifier_Character_Set);
332 Tree_Write_Bool (Ignore_Rep_Clauses);
333 Tree_Write_Bool (Ignore_Style_Checks_Pragmas);
334 Tree_Write_Int (Maximum_File_Name_Length);
335 Tree_Write_Data (Suppress_Options'Address,
336 (Suppress_Options'Size + SU - 1) / SU);
337 Tree_Write_Bool (Verbose_Mode);
338 Tree_Write_Data (Warning_Mode'Address,
339 (Warning_Mode'Size + SU - 1) / Storage_Unit);
340 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
341 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
342 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
343 Tree_Write_Bool (All_Errors_Mode);
344 Tree_Write_Bool (Assertions_Enabled);
345 Tree_Write_Bool (Check_Float_Overflow);
346 Tree_Write_Int (Int (Check_Policy_List));
347 Tree_Write_Int (Int (Default_Pool));
348 Tree_Write_Bool (Full_List);
349 Tree_Write_Int (Int (Version_String'Length));
350 Tree_Write_Data (Version_String'Address, Version_String'Length);
351 Tree_Write_Data (Distribution_Stub_Mode'Address,
352 (Distribution_Stub_Mode'Size + SU - 1) / SU);
353 Tree_Write_Bool (Inline_Active);
354 Tree_Write_Bool (Inline_Processing_Required);
355 Tree_Write_Bool (List_Units);
356 Tree_Write_Int (Multiple_Unit_Index);
357 Tree_Write_Bool (Configurable_Run_Time_Mode);
358 Tree_Write_Data (Operating_Mode'Address,
359 (Operating_Mode'Size + SU - 1) / SU);
360 Tree_Write_Bool (Suppress_Checks);
361 Tree_Write_Bool (Try_Semantics);
362 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
363 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
364 Tree_Write_Bool (Upper_Half_Encoding);
365 Tree_Write_Bool (Force_ALI_Tree_File);
366 end Tree_Write;
367
368 end Opt;