Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / ada / opt.adb
blob445349ac8c17874d5369ecc44accab36435374d1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O P T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2010, 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_Explicit_Config := Ada_Version_Explicit;
49 Assertions_Enabled_Config := Assertions_Enabled;
50 Assume_No_Invalid_Values_Config := Assume_No_Invalid_Values;
51 Check_Policy_List_Config := Check_Policy_List;
52 Debug_Pragmas_Enabled_Config := Debug_Pragmas_Enabled;
53 Dynamic_Elaboration_Checks_Config := Dynamic_Elaboration_Checks;
54 Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
55 Extensions_Allowed_Config := Extensions_Allowed;
56 External_Name_Exp_Casing_Config := External_Name_Exp_Casing;
57 External_Name_Imp_Casing_Config := External_Name_Imp_Casing;
58 Fast_Math_Config := Fast_Math;
59 Init_Or_Norm_Scalars_Config := Init_Or_Norm_Scalars;
60 Initialize_Scalars_Config := Initialize_Scalars;
61 Optimize_Alignment_Config := Optimize_Alignment;
62 Persistent_BSS_Mode_Config := Persistent_BSS_Mode;
63 Polling_Required_Config := Polling_Required;
64 Short_Descriptors_Config := Short_Descriptors;
65 Use_VADS_Size_Config := Use_VADS_Size;
67 -- Reset the indication that Optimize_Alignment was set locally, since
68 -- if we had a pragma in the config file, it would set this flag True,
69 -- but that's not a local setting.
71 Optimize_Alignment_Local := False;
72 end Register_Opt_Config_Switches;
74 ---------------------------------
75 -- Restore_Opt_Config_Switches --
76 ---------------------------------
78 procedure Restore_Opt_Config_Switches (Save : Config_Switches_Type) is
79 begin
80 Ada_Version := Save.Ada_Version;
81 Ada_Version_Explicit := Save.Ada_Version_Explicit;
82 Assertions_Enabled := Save.Assertions_Enabled;
83 Assume_No_Invalid_Values := Save.Assume_No_Invalid_Values;
84 Check_Policy_List := Save.Check_Policy_List;
85 Debug_Pragmas_Enabled := Save.Debug_Pragmas_Enabled;
86 Dynamic_Elaboration_Checks := Save.Dynamic_Elaboration_Checks;
87 Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
88 Extensions_Allowed := Save.Extensions_Allowed;
89 External_Name_Exp_Casing := Save.External_Name_Exp_Casing;
90 External_Name_Imp_Casing := Save.External_Name_Imp_Casing;
91 Fast_Math := Save.Fast_Math;
92 Init_Or_Norm_Scalars := Save.Init_Or_Norm_Scalars;
93 Initialize_Scalars := Save.Initialize_Scalars;
94 Optimize_Alignment := Save.Optimize_Alignment;
95 Optimize_Alignment_Local := Save.Optimize_Alignment_Local;
96 Persistent_BSS_Mode := Save.Persistent_BSS_Mode;
97 Polling_Required := Save.Polling_Required;
98 Short_Descriptors := Save.Short_Descriptors;
99 Use_VADS_Size := Save.Use_VADS_Size;
100 end Restore_Opt_Config_Switches;
102 ------------------------------
103 -- Save_Opt_Config_Switches --
104 ------------------------------
106 procedure Save_Opt_Config_Switches (Save : out Config_Switches_Type) is
107 begin
108 Save.Ada_Version := Ada_Version;
109 Save.Ada_Version_Explicit := Ada_Version_Explicit;
110 Save.Assertions_Enabled := Assertions_Enabled;
111 Save.Assume_No_Invalid_Values := Assume_No_Invalid_Values;
112 Save.Check_Policy_List := Check_Policy_List;
113 Save.Debug_Pragmas_Enabled := Debug_Pragmas_Enabled;
114 Save.Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks;
115 Save.Exception_Locations_Suppressed := Exception_Locations_Suppressed;
116 Save.Extensions_Allowed := Extensions_Allowed;
117 Save.External_Name_Exp_Casing := External_Name_Exp_Casing;
118 Save.External_Name_Imp_Casing := External_Name_Imp_Casing;
119 Save.Fast_Math := Fast_Math;
120 Save.Init_Or_Norm_Scalars := Init_Or_Norm_Scalars;
121 Save.Initialize_Scalars := Initialize_Scalars;
122 Save.Optimize_Alignment := Optimize_Alignment;
123 Save.Optimize_Alignment_Local := Optimize_Alignment_Local;
124 Save.Persistent_BSS_Mode := Persistent_BSS_Mode;
125 Save.Polling_Required := Polling_Required;
126 Save.Short_Descriptors := Short_Descriptors;
127 Save.Use_VADS_Size := Use_VADS_Size;
128 end Save_Opt_Config_Switches;
130 -----------------------------
131 -- Set_Opt_Config_Switches --
132 -----------------------------
134 procedure Set_Opt_Config_Switches
135 (Internal_Unit : Boolean;
136 Main_Unit : Boolean)
138 begin
139 -- Case of internal unit
141 if Internal_Unit then
143 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
144 -- since the whole point of this is that it still properly indicates
145 -- the configuration setting even in a run time unit.
147 Ada_Version := Ada_Version_Runtime;
148 Dynamic_Elaboration_Checks := False;
149 Extensions_Allowed := True;
150 External_Name_Exp_Casing := As_Is;
151 External_Name_Imp_Casing := Lowercase;
152 Optimize_Alignment := 'O';
153 Persistent_BSS_Mode := False;
154 Use_VADS_Size := False;
155 Optimize_Alignment_Local := True;
157 -- For an internal unit, assertions/debug pragmas are off unless this
158 -- is the main unit and they were explicitly enabled. We also make
159 -- sure we do not assume that values are necessarily valid.
161 if Main_Unit then
162 Assertions_Enabled := Assertions_Enabled_Config;
163 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
164 Debug_Pragmas_Enabled := Debug_Pragmas_Enabled_Config;
165 Check_Policy_List := Check_Policy_List_Config;
166 else
167 Assertions_Enabled := False;
168 Assume_No_Invalid_Values := False;
169 Debug_Pragmas_Enabled := False;
170 Check_Policy_List := Empty;
171 end if;
173 -- Case of non-internal unit
175 else
176 Ada_Version := Ada_Version_Config;
177 Ada_Version_Explicit := Ada_Version_Explicit_Config;
178 Assertions_Enabled := Assertions_Enabled_Config;
179 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
180 Check_Policy_List := Check_Policy_List_Config;
181 Debug_Pragmas_Enabled := Debug_Pragmas_Enabled_Config;
182 Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
183 Extensions_Allowed := Extensions_Allowed_Config;
184 External_Name_Exp_Casing := External_Name_Exp_Casing_Config;
185 External_Name_Imp_Casing := External_Name_Imp_Casing_Config;
186 Fast_Math := Fast_Math_Config;
187 Init_Or_Norm_Scalars := Init_Or_Norm_Scalars_Config;
188 Initialize_Scalars := Initialize_Scalars_Config;
189 Optimize_Alignment := Optimize_Alignment_Config;
190 Optimize_Alignment_Local := False;
191 Persistent_BSS_Mode := Persistent_BSS_Mode_Config;
192 Use_VADS_Size := Use_VADS_Size_Config;
193 end if;
195 Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
196 Fast_Math := Fast_Math_Config;
197 Optimize_Alignment := Optimize_Alignment_Config;
198 Polling_Required := Polling_Required_Config;
199 Short_Descriptors := Short_Descriptors_Config;
200 end Set_Opt_Config_Switches;
202 ---------------
203 -- Tree_Read --
204 ---------------
206 procedure Tree_Read is
207 Tree_Version_String_Len : Nat;
208 Ada_Version_Config_Val : Nat;
209 Ada_Version_Explicit_Config_Val : Nat;
210 Assertions_Enabled_Config_Val : Nat;
212 begin
213 Tree_Read_Int (Tree_ASIS_Version_Number);
214 Tree_Read_Bool (Brief_Output);
215 Tree_Read_Bool (GNAT_Mode);
216 Tree_Read_Char (Identifier_Character_Set);
217 Tree_Read_Int (Maximum_File_Name_Length);
218 Tree_Read_Data (Suppress_Options'Address,
219 (Suppress_Options'Size + SU - 1) / SU);
220 Tree_Read_Bool (Verbose_Mode);
221 Tree_Read_Data (Warning_Mode'Address,
222 (Warning_Mode'Size + SU - 1) / SU);
223 Tree_Read_Int (Ada_Version_Config_Val);
224 Tree_Read_Int (Ada_Version_Explicit_Config_Val);
225 Tree_Read_Int (Assertions_Enabled_Config_Val);
226 Tree_Read_Bool (All_Errors_Mode);
227 Tree_Read_Bool (Assertions_Enabled);
228 Tree_Read_Int (Int (Check_Policy_List));
229 Tree_Read_Bool (Debug_Pragmas_Enabled);
230 Tree_Read_Bool (Enable_Overflow_Checks);
231 Tree_Read_Bool (Full_List);
233 Ada_Version_Config :=
234 Ada_Version_Type'Val (Ada_Version_Config_Val);
235 Ada_Version_Explicit_Config :=
236 Ada_Version_Type'Val (Ada_Version_Explicit_Config_Val);
237 Assertions_Enabled_Config :=
238 Boolean'Val (Assertions_Enabled_Config_Val);
240 -- Read version string: we have to get the length first
242 Tree_Read_Int (Tree_Version_String_Len);
244 declare
245 Tmp : String (1 .. Integer (Tree_Version_String_Len));
246 begin
247 Tree_Read_Data
248 (Tmp'Address, Tree_Version_String_Len);
249 System.Strings.Free (Tree_Version_String);
250 Free (Tree_Version_String);
251 Tree_Version_String := new String'(Tmp);
252 end;
254 Tree_Read_Data (Distribution_Stub_Mode'Address,
255 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
256 Tree_Read_Bool (Inline_Active);
257 Tree_Read_Bool (Inline_Processing_Required);
258 Tree_Read_Bool (List_Units);
259 Tree_Read_Bool (Configurable_Run_Time_Mode);
260 Tree_Read_Data (Operating_Mode'Address,
261 (Operating_Mode'Size + SU - 1) / Storage_Unit);
262 Tree_Read_Bool (Suppress_Checks);
263 Tree_Read_Bool (Try_Semantics);
264 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
265 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
266 Tree_Read_Bool (Upper_Half_Encoding);
267 Tree_Read_Bool (Force_ALI_Tree_File);
268 end Tree_Read;
270 ----------------
271 -- Tree_Write --
272 ----------------
274 procedure Tree_Write is
275 Version_String : String := Gnat_Version_String;
277 begin
278 Tree_Write_Int (ASIS_Version_Number);
279 Tree_Write_Bool (Brief_Output);
280 Tree_Write_Bool (GNAT_Mode);
281 Tree_Write_Char (Identifier_Character_Set);
282 Tree_Write_Int (Maximum_File_Name_Length);
283 Tree_Write_Data (Suppress_Options'Address,
284 (Suppress_Options'Size + SU - 1) / SU);
285 Tree_Write_Bool (Verbose_Mode);
286 Tree_Write_Data (Warning_Mode'Address,
287 (Warning_Mode'Size + SU - 1) / Storage_Unit);
288 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
289 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
290 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
291 Tree_Write_Bool (All_Errors_Mode);
292 Tree_Write_Bool (Assertions_Enabled);
293 Tree_Write_Int (Int (Check_Policy_List));
294 Tree_Write_Bool (Debug_Pragmas_Enabled);
295 Tree_Write_Bool (Enable_Overflow_Checks);
296 Tree_Write_Bool (Full_List);
297 Tree_Write_Int (Int (Version_String'Length));
298 Tree_Write_Data (Version_String'Address, Version_String'Length);
299 Tree_Write_Data (Distribution_Stub_Mode'Address,
300 (Distribution_Stub_Mode'Size + SU - 1) / SU);
301 Tree_Write_Bool (Inline_Active);
302 Tree_Write_Bool (Inline_Processing_Required);
303 Tree_Write_Bool (List_Units);
304 Tree_Write_Bool (Configurable_Run_Time_Mode);
305 Tree_Write_Data (Operating_Mode'Address,
306 (Operating_Mode'Size + SU - 1) / SU);
307 Tree_Write_Bool (Suppress_Checks);
308 Tree_Write_Bool (Try_Semantics);
309 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
310 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
311 Tree_Write_Bool (Upper_Half_Encoding);
312 Tree_Write_Bool (Force_ALI_Tree_File);
313 end Tree_Write;
315 end Opt;