1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Gnatvsn
; use Gnatvsn
;
33 with System
; use System
;
34 with Tree_IO
; use Tree_IO
;
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
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
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
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;
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
;
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;
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. We also make
191 -- sure we do not assume that values are necessarily valid and that
192 -- SPARK_Mode is set to its configuration value.
195 Assertions_Enabled
:= Assertions_Enabled_Config
;
196 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
197 Check_Policy_List
:= Check_Policy_List_Config
;
198 SPARK_Mode
:= SPARK_Mode_Config
;
199 SPARK_Mode_Pragma
:= SPARK_Mode_Pragma_Config
;
201 Assertions_Enabled
:= False;
202 Assume_No_Invalid_Values
:= False;
203 Check_Policy_List
:= Empty
;
205 SPARK_Mode_Pragma
:= Empty
;
208 -- Case of non-internal unit
211 Ada_Version
:= Ada_Version_Config
;
212 Ada_Version_Pragma
:= Ada_Version_Pragma_Config
;
213 Ada_Version_Explicit
:= Ada_Version_Explicit_Config
;
214 Assertions_Enabled
:= Assertions_Enabled_Config
;
215 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
216 Check_Float_Overflow
:= Check_Float_Overflow_Config
;
217 Check_Policy_List
:= Check_Policy_List_Config
;
218 Default_SSO
:= Default_SSO_Config
;
219 Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks_Config
;
220 Extensions_Allowed
:= Extensions_Allowed_Config
;
221 External_Name_Exp_Casing
:= External_Name_Exp_Casing_Config
;
222 External_Name_Imp_Casing
:= External_Name_Imp_Casing_Config
;
223 Fast_Math
:= Fast_Math_Config
;
224 Initialize_Scalars
:= Initialize_Scalars_Config
;
225 Optimize_Alignment
:= Optimize_Alignment_Config
;
226 Optimize_Alignment_Local
:= False;
227 Persistent_BSS_Mode
:= Persistent_BSS_Mode_Config
;
228 Prefix_Exception_Messages
:= Prefix_Exception_Messages_Config
;
229 SPARK_Mode
:= SPARK_Mode_Config
;
230 SPARK_Mode_Pragma
:= SPARK_Mode_Pragma_Config
;
231 Uneval_Old
:= Uneval_Old_Config
;
232 Use_VADS_Size
:= Use_VADS_Size_Config
;
233 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count_Config
;
235 -- Update consistently the value of Init_Or_Norm_Scalars. The value
236 -- of Normalize_Scalars is not saved/restored because once set to
237 -- True its value is never changed. That is, if a compilation unit
238 -- has pragma Normalize_Scalars then it forces that value for all
241 Init_Or_Norm_Scalars
:= Initialize_Scalars
or Normalize_Scalars
;
244 -- Values set for all units
246 Default_Pool
:= Default_Pool_Config
;
247 Exception_Locations_Suppressed
:= Exception_Locations_Suppressed_Config
;
248 Fast_Math
:= Fast_Math_Config
;
249 Optimize_Alignment
:= Optimize_Alignment_Config
;
250 Polling_Required
:= Polling_Required_Config
;
251 end Set_Opt_Config_Switches
;
257 procedure Tree_Read
is
258 Tree_Version_String_Len
: Nat
;
259 Ada_Version_Config_Val
: Nat
;
260 Ada_Version_Explicit_Config_Val
: Nat
;
261 Assertions_Enabled_Config_Val
: Nat
;
264 Tree_Read_Int
(Tree_ASIS_Version_Number
);
266 Tree_Read_Bool
(Address_Is_Private
);
267 Tree_Read_Bool
(Brief_Output
);
268 Tree_Read_Bool
(GNAT_Mode
);
269 Tree_Read_Char
(Identifier_Character_Set
);
270 Tree_Read_Bool
(Ignore_Rep_Clauses
);
271 Tree_Read_Bool
(Ignore_Style_Checks_Pragmas
);
272 Tree_Read_Int
(Maximum_File_Name_Length
);
273 Tree_Read_Data
(Suppress_Options
'Address,
274 (Suppress_Options
'Size + SU
- 1) / SU
);
275 Tree_Read_Bool
(Verbose_Mode
);
276 Tree_Read_Data
(Warning_Mode
'Address,
277 (Warning_Mode
'Size + SU
- 1) / SU
);
278 Tree_Read_Int
(Ada_Version_Config_Val
);
279 Tree_Read_Int
(Ada_Version_Explicit_Config_Val
);
280 Tree_Read_Int
(Assertions_Enabled_Config_Val
);
281 Tree_Read_Bool
(All_Errors_Mode
);
282 Tree_Read_Bool
(Assertions_Enabled
);
283 Tree_Read_Bool
(Check_Float_Overflow
);
284 Tree_Read_Int
(Int
(Check_Policy_List
));
285 Tree_Read_Int
(Int
(Default_Pool
));
286 Tree_Read_Bool
(Full_List
);
288 Ada_Version_Config
:=
289 Ada_Version_Type
'Val (Ada_Version_Config_Val
);
290 Ada_Version_Explicit_Config
:=
291 Ada_Version_Type
'Val (Ada_Version_Explicit_Config_Val
);
292 Assertions_Enabled_Config
:=
293 Boolean'Val (Assertions_Enabled_Config_Val
);
295 -- Read version string: we have to get the length first
297 Tree_Read_Int
(Tree_Version_String_Len
);
300 Tmp
: String (1 .. Integer (Tree_Version_String_Len
));
303 (Tmp
'Address, Tree_Version_String_Len
);
304 System
.Strings
.Free
(Tree_Version_String
);
305 Free
(Tree_Version_String
);
306 Tree_Version_String
:= new String'(Tmp);
309 Tree_Read_Data (Distribution_Stub_Mode'Address,
310 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
311 Tree_Read_Bool (Inline_Active);
312 Tree_Read_Bool (Inline_Processing_Required);
313 Tree_Read_Bool (List_Units);
314 Tree_Read_Int (Multiple_Unit_Index);
315 Tree_Read_Bool (Configurable_Run_Time_Mode);
316 Tree_Read_Data (Operating_Mode'Address,
317 (Operating_Mode'Size + SU - 1) / Storage_Unit);
318 Tree_Read_Bool (Suppress_Checks);
319 Tree_Read_Bool (Try_Semantics);
320 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
321 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
322 Tree_Read_Bool (Upper_Half_Encoding);
323 Tree_Read_Bool (Force_ALI_Tree_File);
330 procedure Tree_Write is
331 Version_String : String := Gnat_Version_String;
334 Tree_Write_Int (ASIS_Version_Number);
336 Tree_Write_Bool (Address_Is_Private);
337 Tree_Write_Bool (Brief_Output);
338 Tree_Write_Bool (GNAT_Mode);
339 Tree_Write_Char (Identifier_Character_Set);
340 Tree_Write_Bool (Ignore_Rep_Clauses);
341 Tree_Write_Bool (Ignore_Style_Checks_Pragmas);
342 Tree_Write_Int (Maximum_File_Name_Length);
343 Tree_Write_Data (Suppress_Options'Address,
344 (Suppress_Options'Size + SU - 1) / SU);
345 Tree_Write_Bool (Verbose_Mode);
346 Tree_Write_Data (Warning_Mode'Address,
347 (Warning_Mode'Size + SU - 1) / Storage_Unit);
348 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
349 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
350 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
351 Tree_Write_Bool (All_Errors_Mode);
352 Tree_Write_Bool (Assertions_Enabled);
353 Tree_Write_Bool (Check_Float_Overflow);
354 Tree_Write_Int (Int (Check_Policy_List));
355 Tree_Write_Int (Int (Default_Pool));
356 Tree_Write_Bool (Full_List);
357 Tree_Write_Int (Int (Version_String'Length));
358 Tree_Write_Data (Version_String'Address, Version_String'Length);
359 Tree_Write_Data (Distribution_Stub_Mode'Address,
360 (Distribution_Stub_Mode'Size + SU - 1) / SU);
361 Tree_Write_Bool (Inline_Active);
362 Tree_Write_Bool (Inline_Processing_Required);
363 Tree_Write_Bool (List_Units);
364 Tree_Write_Int (Multiple_Unit_Index);
365 Tree_Write_Bool (Configurable_Run_Time_Mode);
366 Tree_Write_Data (Operating_Mode'Address,
367 (Operating_Mode'Size + SU - 1) / SU);
368 Tree_Write_Bool (Suppress_Checks);
369 Tree_Write_Bool (Try_Semantics);
370 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
371 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
372 Tree_Write_Bool (Upper_Half_Encoding);
373 Tree_Write_Bool (Force_ALI_Tree_File);