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