Reverting merge from trunk
[official-gcc.git] / gcc / ada / opt.adb
blob9f1f2d84a80552124b688f398a9edfaca35d7f82
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O P T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, 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 -- Full_Expander_Active --
43 --------------------------
45 function Full_Expander_Active return Boolean is
46 begin
47 return Expander_Active and not SPARK_Mode;
48 end Full_Expander_Active;
50 ----------------------------------
51 -- Register_Opt_Config_Switches --
52 ----------------------------------
54 procedure Register_Opt_Config_Switches is
55 begin
56 Ada_Version_Config := Ada_Version;
57 Ada_Version_Pragma_Config := Ada_Version_Pragma;
58 Ada_Version_Explicit_Config := Ada_Version_Explicit;
59 Assertions_Enabled_Config := Assertions_Enabled;
60 Assume_No_Invalid_Values_Config := Assume_No_Invalid_Values;
61 Check_Float_Overflow_Config := Check_Float_Overflow;
62 Check_Policy_List_Config := Check_Policy_List;
63 Default_Pool_Config := Default_Pool;
64 Dynamic_Elaboration_Checks_Config := Dynamic_Elaboration_Checks;
65 Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
66 Extensions_Allowed_Config := Extensions_Allowed;
67 External_Name_Exp_Casing_Config := External_Name_Exp_Casing;
68 External_Name_Imp_Casing_Config := External_Name_Imp_Casing;
69 Fast_Math_Config := Fast_Math;
70 Initialize_Scalars_Config := Initialize_Scalars;
71 Optimize_Alignment_Config := Optimize_Alignment;
72 Persistent_BSS_Mode_Config := Persistent_BSS_Mode;
73 Polling_Required_Config := Polling_Required;
74 Short_Descriptors_Config := Short_Descriptors;
75 Use_VADS_Size_Config := Use_VADS_Size;
77 -- Reset the indication that Optimize_Alignment was set locally, since
78 -- if we had a pragma in the config file, it would set this flag True,
79 -- but that's not a local setting.
81 Optimize_Alignment_Local := False;
82 end Register_Opt_Config_Switches;
84 ---------------------------------
85 -- Restore_Opt_Config_Switches --
86 ---------------------------------
88 procedure Restore_Opt_Config_Switches (Save : Config_Switches_Type) is
89 begin
90 Ada_Version := Save.Ada_Version;
91 Ada_Version_Pragma := Save.Ada_Version_Pragma;
92 Ada_Version_Explicit := Save.Ada_Version_Explicit;
93 Assertions_Enabled := Save.Assertions_Enabled;
94 Assume_No_Invalid_Values := Save.Assume_No_Invalid_Values;
95 Check_Float_Overflow := Save.Check_Float_Overflow;
96 Check_Policy_List := Save.Check_Policy_List;
97 Default_Pool := Save.Default_Pool;
98 Dynamic_Elaboration_Checks := Save.Dynamic_Elaboration_Checks;
99 Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
100 Extensions_Allowed := Save.Extensions_Allowed;
101 External_Name_Exp_Casing := Save.External_Name_Exp_Casing;
102 External_Name_Imp_Casing := Save.External_Name_Imp_Casing;
103 Fast_Math := Save.Fast_Math;
104 Initialize_Scalars := Save.Initialize_Scalars;
105 Optimize_Alignment := Save.Optimize_Alignment;
106 Optimize_Alignment_Local := Save.Optimize_Alignment_Local;
107 Persistent_BSS_Mode := Save.Persistent_BSS_Mode;
108 Polling_Required := Save.Polling_Required;
109 Short_Descriptors := Save.Short_Descriptors;
110 Use_VADS_Size := Save.Use_VADS_Size;
112 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
113 -- Normalize_Scalars is not saved/restored because after set to True its
114 -- value is never changed. That is, if a compilation unit has pragma
115 -- Normalize_Scalars then it forces that value for all with'ed units.
117 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
118 end Restore_Opt_Config_Switches;
120 ------------------------------
121 -- Save_Opt_Config_Switches --
122 ------------------------------
124 procedure Save_Opt_Config_Switches (Save : out Config_Switches_Type) is
125 begin
126 Save.Ada_Version := Ada_Version;
127 Save.Ada_Version_Pragma := Ada_Version_Pragma;
128 Save.Ada_Version_Explicit := Ada_Version_Explicit;
129 Save.Assertions_Enabled := Assertions_Enabled;
130 Save.Assume_No_Invalid_Values := Assume_No_Invalid_Values;
131 Save.Check_Float_Overflow := Check_Float_Overflow;
132 Save.Check_Policy_List := Check_Policy_List;
133 Save.Default_Pool := Default_Pool;
134 Save.Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks;
135 Save.Exception_Locations_Suppressed := Exception_Locations_Suppressed;
136 Save.Extensions_Allowed := Extensions_Allowed;
137 Save.External_Name_Exp_Casing := External_Name_Exp_Casing;
138 Save.External_Name_Imp_Casing := External_Name_Imp_Casing;
139 Save.Fast_Math := Fast_Math;
140 Save.Initialize_Scalars := Initialize_Scalars;
141 Save.Optimize_Alignment := Optimize_Alignment;
142 Save.Optimize_Alignment_Local := Optimize_Alignment_Local;
143 Save.Persistent_BSS_Mode := Persistent_BSS_Mode;
144 Save.Polling_Required := Polling_Required;
145 Save.Short_Descriptors := Short_Descriptors;
146 Save.Use_VADS_Size := Use_VADS_Size;
147 end Save_Opt_Config_Switches;
149 -----------------------------
150 -- Set_Opt_Config_Switches --
151 -----------------------------
153 procedure Set_Opt_Config_Switches
154 (Internal_Unit : Boolean;
155 Main_Unit : Boolean)
157 begin
158 -- Case of internal unit
160 if Internal_Unit then
162 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
163 -- since the whole point of this is that it still properly indicates
164 -- the configuration setting even in a run time unit.
166 Ada_Version := Ada_Version_Runtime;
167 Ada_Version_Pragma := Empty;
168 Dynamic_Elaboration_Checks := False;
169 Extensions_Allowed := True;
170 External_Name_Exp_Casing := As_Is;
171 External_Name_Imp_Casing := Lowercase;
172 Optimize_Alignment := 'O';
173 Persistent_BSS_Mode := False;
174 Use_VADS_Size := False;
175 Optimize_Alignment_Local := True;
177 -- For an internal unit, assertions/debug pragmas are off unless this
178 -- is the main unit and they were explicitly enabled. We also make
179 -- sure we do not assume that values are necessarily valid.
181 if Main_Unit then
182 Assertions_Enabled := Assertions_Enabled_Config;
183 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
184 Check_Policy_List := Check_Policy_List_Config;
185 else
186 Assertions_Enabled := False;
187 Assume_No_Invalid_Values := False;
188 Check_Policy_List := Empty;
189 end if;
191 -- Case of non-internal unit
193 else
194 Ada_Version := Ada_Version_Config;
195 Ada_Version_Pragma := Ada_Version_Pragma_Config;
196 Ada_Version_Explicit := Ada_Version_Explicit_Config;
197 Assertions_Enabled := Assertions_Enabled_Config;
198 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
199 Check_Float_Overflow := Check_Float_Overflow_Config;
200 Check_Policy_List := Check_Policy_List_Config;
201 Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
202 Extensions_Allowed := Extensions_Allowed_Config;
203 External_Name_Exp_Casing := External_Name_Exp_Casing_Config;
204 External_Name_Imp_Casing := External_Name_Imp_Casing_Config;
205 Fast_Math := Fast_Math_Config;
206 Initialize_Scalars := Initialize_Scalars_Config;
207 Optimize_Alignment := Optimize_Alignment_Config;
208 Optimize_Alignment_Local := False;
209 Persistent_BSS_Mode := Persistent_BSS_Mode_Config;
210 Use_VADS_Size := Use_VADS_Size_Config;
212 -- Update consistently the value of Init_Or_Norm_Scalars. The value
213 -- of Normalize_Scalars is not saved/restored because once set to
214 -- True its value is never changed. That is, if a compilation unit
215 -- has pragma Normalize_Scalars then it forces that value for all
216 -- with'ed units.
218 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
219 end if;
221 Default_Pool := Default_Pool_Config;
222 Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
223 Fast_Math := Fast_Math_Config;
224 Optimize_Alignment := Optimize_Alignment_Config;
225 Polling_Required := Polling_Required_Config;
226 Short_Descriptors := Short_Descriptors_Config;
227 end Set_Opt_Config_Switches;
229 ---------------
230 -- Tree_Read --
231 ---------------
233 procedure Tree_Read is
234 Tree_Version_String_Len : Nat;
235 Ada_Version_Config_Val : Nat;
236 Ada_Version_Explicit_Config_Val : Nat;
237 Assertions_Enabled_Config_Val : Nat;
239 begin
240 Tree_Read_Int (Tree_ASIS_Version_Number);
241 Tree_Read_Bool (Brief_Output);
242 Tree_Read_Bool (GNAT_Mode);
243 Tree_Read_Char (Identifier_Character_Set);
244 Tree_Read_Int (Maximum_File_Name_Length);
245 Tree_Read_Data (Suppress_Options'Address,
246 (Suppress_Options'Size + SU - 1) / SU);
247 Tree_Read_Bool (Verbose_Mode);
248 Tree_Read_Data (Warning_Mode'Address,
249 (Warning_Mode'Size + SU - 1) / SU);
250 Tree_Read_Int (Ada_Version_Config_Val);
251 Tree_Read_Int (Ada_Version_Explicit_Config_Val);
252 Tree_Read_Int (Assertions_Enabled_Config_Val);
253 Tree_Read_Bool (All_Errors_Mode);
254 Tree_Read_Bool (Assertions_Enabled);
255 Tree_Read_Bool (Check_Float_Overflow);
256 Tree_Read_Int (Int (Check_Policy_List));
257 Tree_Read_Int (Int (Default_Pool));
258 Tree_Read_Bool (Full_List);
260 Ada_Version_Config :=
261 Ada_Version_Type'Val (Ada_Version_Config_Val);
262 Ada_Version_Explicit_Config :=
263 Ada_Version_Type'Val (Ada_Version_Explicit_Config_Val);
264 Assertions_Enabled_Config :=
265 Boolean'Val (Assertions_Enabled_Config_Val);
267 -- Read version string: we have to get the length first
269 Tree_Read_Int (Tree_Version_String_Len);
271 declare
272 Tmp : String (1 .. Integer (Tree_Version_String_Len));
273 begin
274 Tree_Read_Data
275 (Tmp'Address, Tree_Version_String_Len);
276 System.Strings.Free (Tree_Version_String);
277 Free (Tree_Version_String);
278 Tree_Version_String := new String'(Tmp);
279 end;
281 Tree_Read_Data (Distribution_Stub_Mode'Address,
282 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
283 Tree_Read_Bool (Inline_Active);
284 Tree_Read_Bool (Inline_Processing_Required);
285 Tree_Read_Bool (List_Units);
286 Tree_Read_Bool (Configurable_Run_Time_Mode);
287 Tree_Read_Data (Operating_Mode'Address,
288 (Operating_Mode'Size + SU - 1) / Storage_Unit);
289 Tree_Read_Bool (Suppress_Checks);
290 Tree_Read_Bool (Try_Semantics);
291 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
292 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
293 Tree_Read_Bool (Upper_Half_Encoding);
294 Tree_Read_Bool (Force_ALI_Tree_File);
295 end Tree_Read;
297 ----------------
298 -- Tree_Write --
299 ----------------
301 procedure Tree_Write is
302 Version_String : String := Gnat_Version_String;
304 begin
305 Tree_Write_Int (ASIS_Version_Number);
306 Tree_Write_Bool (Brief_Output);
307 Tree_Write_Bool (GNAT_Mode);
308 Tree_Write_Char (Identifier_Character_Set);
309 Tree_Write_Int (Maximum_File_Name_Length);
310 Tree_Write_Data (Suppress_Options'Address,
311 (Suppress_Options'Size + SU - 1) / SU);
312 Tree_Write_Bool (Verbose_Mode);
313 Tree_Write_Data (Warning_Mode'Address,
314 (Warning_Mode'Size + SU - 1) / Storage_Unit);
315 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
316 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
317 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
318 Tree_Write_Bool (All_Errors_Mode);
319 Tree_Write_Bool (Assertions_Enabled);
320 Tree_Write_Bool (Check_Float_Overflow);
321 Tree_Write_Int (Int (Check_Policy_List));
322 Tree_Write_Int (Int (Default_Pool));
323 Tree_Write_Bool (Full_List);
324 Tree_Write_Int (Int (Version_String'Length));
325 Tree_Write_Data (Version_String'Address, Version_String'Length);
326 Tree_Write_Data (Distribution_Stub_Mode'Address,
327 (Distribution_Stub_Mode'Size + SU - 1) / SU);
328 Tree_Write_Bool (Inline_Active);
329 Tree_Write_Bool (Inline_Processing_Required);
330 Tree_Write_Bool (List_Units);
331 Tree_Write_Bool (Configurable_Run_Time_Mode);
332 Tree_Write_Data (Operating_Mode'Address,
333 (Operating_Mode'Size + SU - 1) / SU);
334 Tree_Write_Bool (Suppress_Checks);
335 Tree_Write_Bool (Try_Semantics);
336 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
337 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
338 Tree_Write_Bool (Upper_Half_Encoding);
339 Tree_Write_Bool (Force_ALI_Tree_File);
340 end Tree_Write;
342 end Opt;