1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Dynamic_Elaboration_Checks_Config
:= Dynamic_Elaboration_Checks
;
56 Exception_Locations_Suppressed_Config
:= Exception_Locations_Suppressed
;
57 Extensions_Allowed_Config
:= Extensions_Allowed
;
58 External_Name_Exp_Casing_Config
:= External_Name_Exp_Casing
;
59 External_Name_Imp_Casing_Config
:= External_Name_Imp_Casing
;
60 Fast_Math_Config
:= Fast_Math
;
61 Initialize_Scalars_Config
:= Initialize_Scalars
;
62 Optimize_Alignment_Config
:= Optimize_Alignment
;
63 Persistent_BSS_Mode_Config
:= Persistent_BSS_Mode
;
64 Polling_Required_Config
:= Polling_Required
;
65 Short_Descriptors_Config
:= Short_Descriptors
;
66 SPARK_Mode_Config
:= SPARK_Mode
;
67 SPARK_Mode_Pragma_Config
:= SPARK_Mode_Pragma
;
68 Use_VADS_Size_Config
:= Use_VADS_Size
;
70 -- Reset the indication that Optimize_Alignment was set locally, since
71 -- if we had a pragma in the config file, it would set this flag True,
72 -- but that's not a local setting.
74 Optimize_Alignment_Local
:= False;
75 end Register_Opt_Config_Switches
;
77 ---------------------------------
78 -- Restore_Opt_Config_Switches --
79 ---------------------------------
81 procedure Restore_Opt_Config_Switches
(Save
: Config_Switches_Type
) is
83 Ada_Version
:= Save
.Ada_Version
;
84 Ada_Version_Pragma
:= Save
.Ada_Version_Pragma
;
85 Ada_Version_Explicit
:= Save
.Ada_Version_Explicit
;
86 Assertions_Enabled
:= Save
.Assertions_Enabled
;
87 Assume_No_Invalid_Values
:= Save
.Assume_No_Invalid_Values
;
88 Check_Float_Overflow
:= Save
.Check_Float_Overflow
;
89 Check_Policy_List
:= Save
.Check_Policy_List
;
90 Default_Pool
:= Save
.Default_Pool
;
91 Dynamic_Elaboration_Checks
:= Save
.Dynamic_Elaboration_Checks
;
92 Exception_Locations_Suppressed
:= Save
.Exception_Locations_Suppressed
;
93 Extensions_Allowed
:= Save
.Extensions_Allowed
;
94 External_Name_Exp_Casing
:= Save
.External_Name_Exp_Casing
;
95 External_Name_Imp_Casing
:= Save
.External_Name_Imp_Casing
;
96 Fast_Math
:= Save
.Fast_Math
;
97 Initialize_Scalars
:= Save
.Initialize_Scalars
;
98 Optimize_Alignment
:= Save
.Optimize_Alignment
;
99 Optimize_Alignment_Local
:= Save
.Optimize_Alignment_Local
;
100 Persistent_BSS_Mode
:= Save
.Persistent_BSS_Mode
;
101 Polling_Required
:= Save
.Polling_Required
;
102 Short_Descriptors
:= Save
.Short_Descriptors
;
103 SPARK_Mode
:= Save
.SPARK_Mode
;
104 SPARK_Mode_Pragma
:= Save
.SPARK_Mode_Pragma
;
105 Use_VADS_Size
:= Save
.Use_VADS_Size
;
107 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
108 -- Normalize_Scalars is not saved/restored because after set to True its
109 -- value is never changed. That is, if a compilation unit has pragma
110 -- Normalize_Scalars then it forces that value for all with'ed units.
112 Init_Or_Norm_Scalars
:= Initialize_Scalars
or Normalize_Scalars
;
113 end Restore_Opt_Config_Switches
;
115 ------------------------------
116 -- Save_Opt_Config_Switches --
117 ------------------------------
119 procedure Save_Opt_Config_Switches
(Save
: out Config_Switches_Type
) is
121 Save
.Ada_Version
:= Ada_Version
;
122 Save
.Ada_Version_Pragma
:= Ada_Version_Pragma
;
123 Save
.Ada_Version_Explicit
:= Ada_Version_Explicit
;
124 Save
.Assertions_Enabled
:= Assertions_Enabled
;
125 Save
.Assume_No_Invalid_Values
:= Assume_No_Invalid_Values
;
126 Save
.Check_Float_Overflow
:= Check_Float_Overflow
;
127 Save
.Check_Policy_List
:= Check_Policy_List
;
128 Save
.Default_Pool
:= Default_Pool
;
129 Save
.Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks
;
130 Save
.Exception_Locations_Suppressed
:= Exception_Locations_Suppressed
;
131 Save
.Extensions_Allowed
:= Extensions_Allowed
;
132 Save
.External_Name_Exp_Casing
:= External_Name_Exp_Casing
;
133 Save
.External_Name_Imp_Casing
:= External_Name_Imp_Casing
;
134 Save
.Fast_Math
:= Fast_Math
;
135 Save
.Initialize_Scalars
:= Initialize_Scalars
;
136 Save
.Optimize_Alignment
:= Optimize_Alignment
;
137 Save
.Optimize_Alignment_Local
:= Optimize_Alignment_Local
;
138 Save
.Persistent_BSS_Mode
:= Persistent_BSS_Mode
;
139 Save
.Polling_Required
:= Polling_Required
;
140 Save
.Short_Descriptors
:= Short_Descriptors
;
141 Save
.SPARK_Mode
:= SPARK_Mode
;
142 Save
.SPARK_Mode_Pragma
:= SPARK_Mode_Pragma
;
143 Save
.Use_VADS_Size
:= Use_VADS_Size
;
144 end Save_Opt_Config_Switches
;
146 -----------------------------
147 -- Set_Opt_Config_Switches --
148 -----------------------------
150 procedure Set_Opt_Config_Switches
151 (Internal_Unit
: Boolean;
155 -- Case of internal unit
157 if Internal_Unit
then
159 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
160 -- since the whole point of this is that it still properly indicates
161 -- the configuration setting even in a run time unit.
163 Ada_Version
:= Ada_Version_Runtime
;
164 Ada_Version_Pragma
:= Empty
;
165 Dynamic_Elaboration_Checks
:= False;
166 Extensions_Allowed
:= True;
167 External_Name_Exp_Casing
:= As_Is
;
168 External_Name_Imp_Casing
:= Lowercase
;
169 Optimize_Alignment
:= 'O';
170 Persistent_BSS_Mode
:= False;
171 Use_VADS_Size
:= False;
172 Optimize_Alignment_Local
:= True;
174 -- For an internal unit, assertions/debug pragmas are off unless this
175 -- is the main unit and they were explicitly enabled. We also make
176 -- sure we do not assume that values are necessarily valid and that
177 -- SPARK_Mode is set to its configuration value.
180 Assertions_Enabled
:= Assertions_Enabled_Config
;
181 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
182 Check_Policy_List
:= Check_Policy_List_Config
;
183 SPARK_Mode
:= SPARK_Mode_Config
;
184 SPARK_Mode_Pragma
:= SPARK_Mode_Pragma_Config
;
186 Assertions_Enabled
:= False;
187 Assume_No_Invalid_Values
:= False;
188 Check_Policy_List
:= Empty
;
190 SPARK_Mode_Pragma
:= Empty
;
193 -- Case of non-internal unit
196 Ada_Version
:= Ada_Version_Config
;
197 Ada_Version_Pragma
:= Ada_Version_Pragma_Config
;
198 Ada_Version_Explicit
:= Ada_Version_Explicit_Config
;
199 Assertions_Enabled
:= Assertions_Enabled_Config
;
200 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
201 Check_Float_Overflow
:= Check_Float_Overflow_Config
;
202 Check_Policy_List
:= Check_Policy_List_Config
;
203 Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks_Config
;
204 Extensions_Allowed
:= Extensions_Allowed_Config
;
205 External_Name_Exp_Casing
:= External_Name_Exp_Casing_Config
;
206 External_Name_Imp_Casing
:= External_Name_Imp_Casing_Config
;
207 Fast_Math
:= Fast_Math_Config
;
208 Initialize_Scalars
:= Initialize_Scalars_Config
;
209 Optimize_Alignment
:= Optimize_Alignment_Config
;
210 Optimize_Alignment_Local
:= False;
211 Persistent_BSS_Mode
:= Persistent_BSS_Mode_Config
;
212 SPARK_Mode
:= SPARK_Mode_Config
;
213 SPARK_Mode_Pragma
:= SPARK_Mode_Pragma_Config
;
214 Use_VADS_Size
:= Use_VADS_Size_Config
;
216 -- Update consistently the value of Init_Or_Norm_Scalars. The value
217 -- of Normalize_Scalars is not saved/restored because once set to
218 -- True its value is never changed. That is, if a compilation unit
219 -- has pragma Normalize_Scalars then it forces that value for all
222 Init_Or_Norm_Scalars
:= Initialize_Scalars
or Normalize_Scalars
;
225 Default_Pool
:= Default_Pool_Config
;
226 Exception_Locations_Suppressed
:= Exception_Locations_Suppressed_Config
;
227 Fast_Math
:= Fast_Math_Config
;
228 Optimize_Alignment
:= Optimize_Alignment_Config
;
229 Polling_Required
:= Polling_Required_Config
;
230 Short_Descriptors
:= Short_Descriptors_Config
;
231 end Set_Opt_Config_Switches
;
237 procedure Tree_Read
is
238 Tree_Version_String_Len
: Nat
;
239 Ada_Version_Config_Val
: Nat
;
240 Ada_Version_Explicit_Config_Val
: Nat
;
241 Assertions_Enabled_Config_Val
: Nat
;
244 Tree_Read_Int
(Tree_ASIS_Version_Number
);
245 Tree_Read_Bool
(Brief_Output
);
246 Tree_Read_Bool
(GNAT_Mode
);
247 Tree_Read_Char
(Identifier_Character_Set
);
248 Tree_Read_Int
(Maximum_File_Name_Length
);
249 Tree_Read_Data
(Suppress_Options
'Address,
250 (Suppress_Options
'Size + SU
- 1) / SU
);
251 Tree_Read_Bool
(Verbose_Mode
);
252 Tree_Read_Data
(Warning_Mode
'Address,
253 (Warning_Mode
'Size + SU
- 1) / SU
);
254 Tree_Read_Int
(Ada_Version_Config_Val
);
255 Tree_Read_Int
(Ada_Version_Explicit_Config_Val
);
256 Tree_Read_Int
(Assertions_Enabled_Config_Val
);
257 Tree_Read_Bool
(All_Errors_Mode
);
258 Tree_Read_Bool
(Assertions_Enabled
);
259 Tree_Read_Bool
(Check_Float_Overflow
);
260 Tree_Read_Int
(Int
(Check_Policy_List
));
261 Tree_Read_Int
(Int
(Default_Pool
));
262 Tree_Read_Bool
(Full_List
);
264 Ada_Version_Config
:=
265 Ada_Version_Type
'Val (Ada_Version_Config_Val
);
266 Ada_Version_Explicit_Config
:=
267 Ada_Version_Type
'Val (Ada_Version_Explicit_Config_Val
);
268 Assertions_Enabled_Config
:=
269 Boolean'Val (Assertions_Enabled_Config_Val
);
271 -- Read version string: we have to get the length first
273 Tree_Read_Int
(Tree_Version_String_Len
);
276 Tmp
: String (1 .. Integer (Tree_Version_String_Len
));
279 (Tmp
'Address, Tree_Version_String_Len
);
280 System
.Strings
.Free
(Tree_Version_String
);
281 Free
(Tree_Version_String
);
282 Tree_Version_String
:= new String'(Tmp);
285 Tree_Read_Data (Distribution_Stub_Mode'Address,
286 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
287 Tree_Read_Bool (Inline_Active);
288 Tree_Read_Bool (Inline_Processing_Required);
289 Tree_Read_Bool (List_Units);
290 Tree_Read_Bool (Configurable_Run_Time_Mode);
291 Tree_Read_Data (Operating_Mode'Address,
292 (Operating_Mode'Size + SU - 1) / Storage_Unit);
293 Tree_Read_Bool (Suppress_Checks);
294 Tree_Read_Bool (Try_Semantics);
295 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
296 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
297 Tree_Read_Bool (Upper_Half_Encoding);
298 Tree_Read_Bool (Force_ALI_Tree_File);
305 procedure Tree_Write is
306 Version_String : String := Gnat_Version_String;
309 Tree_Write_Int (ASIS_Version_Number);
310 Tree_Write_Bool (Brief_Output);
311 Tree_Write_Bool (GNAT_Mode);
312 Tree_Write_Char (Identifier_Character_Set);
313 Tree_Write_Int (Maximum_File_Name_Length);
314 Tree_Write_Data (Suppress_Options'Address,
315 (Suppress_Options'Size + SU - 1) / SU);
316 Tree_Write_Bool (Verbose_Mode);
317 Tree_Write_Data (Warning_Mode'Address,
318 (Warning_Mode'Size + SU - 1) / Storage_Unit);
319 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
320 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
321 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
322 Tree_Write_Bool (All_Errors_Mode);
323 Tree_Write_Bool (Assertions_Enabled);
324 Tree_Write_Bool (Check_Float_Overflow);
325 Tree_Write_Int (Int (Check_Policy_List));
326 Tree_Write_Int (Int (Default_Pool));
327 Tree_Write_Bool (Full_List);
328 Tree_Write_Int (Int (Version_String'Length));
329 Tree_Write_Data (Version_String'Address, Version_String'Length);
330 Tree_Write_Data (Distribution_Stub_Mode'Address,
331 (Distribution_Stub_Mode'Size + SU - 1) / SU);
332 Tree_Write_Bool (Inline_Active);
333 Tree_Write_Bool (Inline_Processing_Required);
334 Tree_Write_Bool (List_Units);
335 Tree_Write_Bool (Configurable_Run_Time_Mode);
336 Tree_Write_Data (Operating_Mode'Address,
337 (Operating_Mode'Size + SU - 1) / SU);
338 Tree_Write_Bool (Suppress_Checks);
339 Tree_Write_Bool (Try_Semantics);
340 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
341 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
342 Tree_Write_Bool (Upper_Half_Encoding);
343 Tree_Write_Bool (Force_ALI_Tree_File);