2015-09-28 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / ada / opt.adb
blob64680968a61ddba59d537fdec42d7918275fc86b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O P T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2015, 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 ------------------------------------------------------------------------------
32 with Gnatvsn; use Gnatvsn;
33 with System; use System;
34 with Tree_IO; use Tree_IO;
36 package body Opt is
38 SU : constant := Storage_Unit;
39 -- Shorthand for System.Storage_Unit
41 ----------------------------------
42 -- Register_Opt_Config_Switches --
43 ----------------------------------
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 Default_SSO_Config := Default_SSO;
56 Dynamic_Elaboration_Checks_Config := Dynamic_Elaboration_Checks;
57 Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
58 Extensions_Allowed_Config := Extensions_Allowed;
59 External_Name_Exp_Casing_Config := External_Name_Exp_Casing;
60 External_Name_Imp_Casing_Config := External_Name_Imp_Casing;
61 Fast_Math_Config := Fast_Math;
62 Initialize_Scalars_Config := Initialize_Scalars;
63 Optimize_Alignment_Config := Optimize_Alignment;
64 Persistent_BSS_Mode_Config := Persistent_BSS_Mode;
65 Polling_Required_Config := Polling_Required;
66 Prefix_Exception_Messages_Config := Prefix_Exception_Messages;
67 SPARK_Mode_Config := SPARK_Mode;
68 SPARK_Mode_Pragma_Config := SPARK_Mode_Pragma;
69 Uneval_Old_Config := Uneval_Old;
70 Use_VADS_Size_Config := Use_VADS_Size;
71 Warnings_As_Errors_Count_Config := Warnings_As_Errors_Count;
73 -- Reset the indication that Optimize_Alignment was set locally, since
74 -- if we had a pragma in the config file, it would set this flag True,
75 -- but that's not a local setting.
77 Optimize_Alignment_Local := False;
78 end Register_Opt_Config_Switches;
80 ---------------------------------
81 -- Restore_Opt_Config_Switches --
82 ---------------------------------
84 procedure Restore_Opt_Config_Switches (Save : Config_Switches_Type) is
85 begin
86 Ada_Version := Save.Ada_Version;
87 Ada_Version_Pragma := Save.Ada_Version_Pragma;
88 Ada_Version_Explicit := Save.Ada_Version_Explicit;
89 Assertions_Enabled := Save.Assertions_Enabled;
90 Assume_No_Invalid_Values := Save.Assume_No_Invalid_Values;
91 Check_Float_Overflow := Save.Check_Float_Overflow;
92 Check_Policy_List := Save.Check_Policy_List;
93 Default_Pool := Save.Default_Pool;
94 Default_SSO := Save.Default_SSO;
95 Dynamic_Elaboration_Checks := Save.Dynamic_Elaboration_Checks;
96 Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
97 Extensions_Allowed := Save.Extensions_Allowed;
98 External_Name_Exp_Casing := Save.External_Name_Exp_Casing;
99 External_Name_Imp_Casing := Save.External_Name_Imp_Casing;
100 Fast_Math := Save.Fast_Math;
101 Initialize_Scalars := Save.Initialize_Scalars;
102 Optimize_Alignment := Save.Optimize_Alignment;
103 Optimize_Alignment_Local := Save.Optimize_Alignment_Local;
104 Persistent_BSS_Mode := Save.Persistent_BSS_Mode;
105 Polling_Required := Save.Polling_Required;
106 Prefix_Exception_Messages := Save.Prefix_Exception_Messages;
107 SPARK_Mode := Save.SPARK_Mode;
108 SPARK_Mode_Pragma := Save.SPARK_Mode_Pragma;
109 Uneval_Old := Save.Uneval_Old;
110 Use_VADS_Size := Save.Use_VADS_Size;
111 Warnings_As_Errors_Count := Save.Warnings_As_Errors_Count;
113 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
114 -- Normalize_Scalars is not saved/restored because after set to True its
115 -- value is never changed. That is, if a compilation unit has pragma
116 -- Normalize_Scalars then it forces that value for all with'ed units.
118 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
119 end Restore_Opt_Config_Switches;
121 ------------------------------
122 -- Save_Opt_Config_Switches --
123 ------------------------------
125 procedure Save_Opt_Config_Switches (Save : out Config_Switches_Type) is
126 begin
127 Save.Ada_Version := Ada_Version;
128 Save.Ada_Version_Pragma := Ada_Version_Pragma;
129 Save.Ada_Version_Explicit := Ada_Version_Explicit;
130 Save.Assertions_Enabled := Assertions_Enabled;
131 Save.Assume_No_Invalid_Values := Assume_No_Invalid_Values;
132 Save.Check_Float_Overflow := Check_Float_Overflow;
133 Save.Check_Policy_List := Check_Policy_List;
134 Save.Default_Pool := Default_Pool;
135 Save.Default_SSO := Default_SSO;
136 Save.Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks;
137 Save.Exception_Locations_Suppressed := Exception_Locations_Suppressed;
138 Save.Extensions_Allowed := Extensions_Allowed;
139 Save.External_Name_Exp_Casing := External_Name_Exp_Casing;
140 Save.External_Name_Imp_Casing := External_Name_Imp_Casing;
141 Save.Fast_Math := Fast_Math;
142 Save.Initialize_Scalars := Initialize_Scalars;
143 Save.Optimize_Alignment := Optimize_Alignment;
144 Save.Optimize_Alignment_Local := Optimize_Alignment_Local;
145 Save.Persistent_BSS_Mode := Persistent_BSS_Mode;
146 Save.Polling_Required := Polling_Required;
147 Save.Prefix_Exception_Messages := Prefix_Exception_Messages;
148 Save.SPARK_Mode := SPARK_Mode;
149 Save.SPARK_Mode_Pragma := SPARK_Mode_Pragma;
150 Save.Uneval_Old := Uneval_Old;
151 Save.Use_VADS_Size := Use_VADS_Size;
152 Save.Warnings_As_Errors_Count := Warnings_As_Errors_Count;
153 end Save_Opt_Config_Switches;
155 -----------------------------
156 -- Set_Opt_Config_Switches --
157 -----------------------------
159 procedure Set_Opt_Config_Switches
160 (Internal_Unit : Boolean;
161 Main_Unit : Boolean)
163 begin
164 -- Case of internal unit
166 if Internal_Unit then
168 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
169 -- since the whole point of this is that it still properly indicates
170 -- the configuration setting even in a run time unit.
172 Ada_Version := Ada_Version_Runtime;
173 Ada_Version_Pragma := Empty;
174 Default_SSO := ' ';
175 Dynamic_Elaboration_Checks := False;
176 Extensions_Allowed := True;
177 External_Name_Exp_Casing := As_Is;
178 External_Name_Imp_Casing := Lowercase;
179 Optimize_Alignment := 'O';
180 Persistent_BSS_Mode := False;
181 Prefix_Exception_Messages := True;
182 Uneval_Old := 'E';
183 Use_VADS_Size := False;
184 Optimize_Alignment_Local := True;
186 -- Note: we do not need to worry about Warnings_As_Errors_Count since
187 -- we do not expect to get any warnings from compiling such a unit.
189 -- For an internal unit, assertions/debug pragmas are off unless this
190 -- is the main unit and they were explicitly enabled, or unless the
191 -- main unit was compiled in GNAT mode. We also make sure we do not
192 -- assume that values are necessarily valid and that SPARK_Mode is
193 -- set to its configuration value.
195 if Main_Unit then
196 Assertions_Enabled := Assertions_Enabled_Config;
197 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
198 Check_Policy_List := Check_Policy_List_Config;
199 SPARK_Mode := SPARK_Mode_Config;
200 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
201 else
202 if GNAT_Mode_Config then
203 Assertions_Enabled := Assertions_Enabled_Config;
204 else
205 Assertions_Enabled := False;
206 end if;
207 Assume_No_Invalid_Values := False;
208 Check_Policy_List := Empty;
209 SPARK_Mode := None;
210 SPARK_Mode_Pragma := Empty;
211 end if;
213 -- Case of non-internal unit
215 else
216 Ada_Version := Ada_Version_Config;
217 Ada_Version_Pragma := Ada_Version_Pragma_Config;
218 Ada_Version_Explicit := Ada_Version_Explicit_Config;
219 Assertions_Enabled := Assertions_Enabled_Config;
220 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
221 Check_Float_Overflow := Check_Float_Overflow_Config;
222 Check_Policy_List := Check_Policy_List_Config;
223 Default_SSO := Default_SSO_Config;
224 Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
225 Extensions_Allowed := Extensions_Allowed_Config;
226 External_Name_Exp_Casing := External_Name_Exp_Casing_Config;
227 External_Name_Imp_Casing := External_Name_Imp_Casing_Config;
228 Fast_Math := Fast_Math_Config;
229 Initialize_Scalars := Initialize_Scalars_Config;
230 Optimize_Alignment := Optimize_Alignment_Config;
231 Optimize_Alignment_Local := False;
232 Persistent_BSS_Mode := Persistent_BSS_Mode_Config;
233 Prefix_Exception_Messages := Prefix_Exception_Messages_Config;
234 SPARK_Mode := SPARK_Mode_Config;
235 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
236 Uneval_Old := Uneval_Old_Config;
237 Use_VADS_Size := Use_VADS_Size_Config;
238 Warnings_As_Errors_Count := Warnings_As_Errors_Count_Config;
240 -- Update consistently the value of Init_Or_Norm_Scalars. The value
241 -- of Normalize_Scalars is not saved/restored because once set to
242 -- True its value is never changed. That is, if a compilation unit
243 -- has pragma Normalize_Scalars then it forces that value for all
244 -- with'ed units.
246 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
247 end if;
249 -- Values set for all units
251 Default_Pool := Default_Pool_Config;
252 Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
253 Fast_Math := Fast_Math_Config;
254 Optimize_Alignment := Optimize_Alignment_Config;
255 Polling_Required := Polling_Required_Config;
256 end Set_Opt_Config_Switches;
258 ---------------
259 -- Tree_Read --
260 ---------------
262 procedure Tree_Read is
263 Tree_Version_String_Len : Nat;
264 Ada_Version_Config_Val : Nat;
265 Ada_Version_Explicit_Config_Val : Nat;
266 Assertions_Enabled_Config_Val : Nat;
268 begin
269 Tree_Read_Int (Tree_ASIS_Version_Number);
271 Tree_Read_Bool (Address_Is_Private);
272 Tree_Read_Bool (Brief_Output);
273 Tree_Read_Bool (GNAT_Mode);
274 Tree_Read_Char (Identifier_Character_Set);
275 Tree_Read_Bool (Ignore_Rep_Clauses);
276 Tree_Read_Bool (Ignore_Style_Checks_Pragmas);
277 Tree_Read_Int (Maximum_File_Name_Length);
278 Tree_Read_Data (Suppress_Options'Address,
279 (Suppress_Options'Size + SU - 1) / SU);
280 Tree_Read_Bool (Verbose_Mode);
281 Tree_Read_Data (Warning_Mode'Address,
282 (Warning_Mode'Size + SU - 1) / SU);
283 Tree_Read_Int (Ada_Version_Config_Val);
284 Tree_Read_Int (Ada_Version_Explicit_Config_Val);
285 Tree_Read_Int (Assertions_Enabled_Config_Val);
286 Tree_Read_Bool (All_Errors_Mode);
287 Tree_Read_Bool (Assertions_Enabled);
288 Tree_Read_Bool (Check_Float_Overflow);
289 Tree_Read_Int (Int (Check_Policy_List));
290 Tree_Read_Int (Int (Default_Pool));
291 Tree_Read_Bool (Full_List);
293 Ada_Version_Config :=
294 Ada_Version_Type'Val (Ada_Version_Config_Val);
295 Ada_Version_Explicit_Config :=
296 Ada_Version_Type'Val (Ada_Version_Explicit_Config_Val);
297 Assertions_Enabled_Config :=
298 Boolean'Val (Assertions_Enabled_Config_Val);
300 -- Read version string: we have to get the length first
302 Tree_Read_Int (Tree_Version_String_Len);
304 declare
305 Tmp : String (1 .. Integer (Tree_Version_String_Len));
306 begin
307 Tree_Read_Data
308 (Tmp'Address, Tree_Version_String_Len);
309 System.Strings.Free (Tree_Version_String);
310 Free (Tree_Version_String);
311 Tree_Version_String := new String'(Tmp);
312 end;
314 Tree_Read_Data (Distribution_Stub_Mode'Address,
315 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
316 Tree_Read_Bool (Inline_Active);
317 Tree_Read_Bool (Inline_Processing_Required);
318 Tree_Read_Bool (List_Units);
319 Tree_Read_Int (Multiple_Unit_Index);
320 Tree_Read_Bool (Configurable_Run_Time_Mode);
321 Tree_Read_Data (Operating_Mode'Address,
322 (Operating_Mode'Size + SU - 1) / Storage_Unit);
323 Tree_Read_Bool (Suppress_Checks);
324 Tree_Read_Bool (Try_Semantics);
325 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
326 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
327 Tree_Read_Bool (Upper_Half_Encoding);
328 Tree_Read_Bool (Force_ALI_Tree_File);
329 end Tree_Read;
331 ----------------
332 -- Tree_Write --
333 ----------------
335 procedure Tree_Write is
336 Version_String : String := Gnat_Version_String;
338 begin
339 Tree_Write_Int (ASIS_Version_Number);
341 Tree_Write_Bool (Address_Is_Private);
342 Tree_Write_Bool (Brief_Output);
343 Tree_Write_Bool (GNAT_Mode);
344 Tree_Write_Char (Identifier_Character_Set);
345 Tree_Write_Bool (Ignore_Rep_Clauses);
346 Tree_Write_Bool (Ignore_Style_Checks_Pragmas);
347 Tree_Write_Int (Maximum_File_Name_Length);
348 Tree_Write_Data (Suppress_Options'Address,
349 (Suppress_Options'Size + SU - 1) / SU);
350 Tree_Write_Bool (Verbose_Mode);
351 Tree_Write_Data (Warning_Mode'Address,
352 (Warning_Mode'Size + SU - 1) / Storage_Unit);
353 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
354 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
355 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
356 Tree_Write_Bool (All_Errors_Mode);
357 Tree_Write_Bool (Assertions_Enabled);
358 Tree_Write_Bool (Check_Float_Overflow);
359 Tree_Write_Int (Int (Check_Policy_List));
360 Tree_Write_Int (Int (Default_Pool));
361 Tree_Write_Bool (Full_List);
362 Tree_Write_Int (Int (Version_String'Length));
363 Tree_Write_Data (Version_String'Address, Version_String'Length);
364 Tree_Write_Data (Distribution_Stub_Mode'Address,
365 (Distribution_Stub_Mode'Size + SU - 1) / SU);
366 Tree_Write_Bool (Inline_Active);
367 Tree_Write_Bool (Inline_Processing_Required);
368 Tree_Write_Bool (List_Units);
369 Tree_Write_Int (Multiple_Unit_Index);
370 Tree_Write_Bool (Configurable_Run_Time_Mode);
371 Tree_Write_Data (Operating_Mode'Address,
372 (Operating_Mode'Size + SU - 1) / SU);
373 Tree_Write_Bool (Suppress_Checks);
374 Tree_Write_Bool (Try_Semantics);
375 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
376 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
377 Tree_Write_Bool (Upper_Half_Encoding);
378 Tree_Write_Bool (Force_ALI_Tree_File);
379 end Tree_Write;
381 end Opt;