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 -- Full_Expander_Active --
43 --------------------------
45 function Full_Expander_Active
return Boolean is
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
56 Ada_Version_Config
:= Ada_Version
;
57 Ada_Version_Explicit_Config
:= Ada_Version_Explicit
;
58 Assertions_Enabled_Config
:= Assertions_Enabled
;
59 Assume_No_Invalid_Values_Config
:= Assume_No_Invalid_Values
;
60 Check_Float_Overflow_Config
:= Check_Float_Overflow
;
61 Check_Policy_List_Config
:= Check_Policy_List
;
62 Default_Pool_Config
:= Default_Pool
;
63 Dynamic_Elaboration_Checks_Config
:= Dynamic_Elaboration_Checks
;
64 Exception_Locations_Suppressed_Config
:= Exception_Locations_Suppressed
;
65 Extensions_Allowed_Config
:= Extensions_Allowed
;
66 External_Name_Exp_Casing_Config
:= External_Name_Exp_Casing
;
67 External_Name_Imp_Casing_Config
:= External_Name_Imp_Casing
;
68 Fast_Math_Config
:= Fast_Math
;
69 Initialize_Scalars_Config
:= Initialize_Scalars
;
70 Optimize_Alignment_Config
:= Optimize_Alignment
;
71 Persistent_BSS_Mode_Config
:= Persistent_BSS_Mode
;
72 Polling_Required_Config
:= Polling_Required
;
73 Short_Descriptors_Config
:= Short_Descriptors
;
74 Use_VADS_Size_Config
:= Use_VADS_Size
;
76 -- Reset the indication that Optimize_Alignment was set locally, since
77 -- if we had a pragma in the config file, it would set this flag True,
78 -- but that's not a local setting.
80 Optimize_Alignment_Local
:= False;
81 end Register_Opt_Config_Switches
;
83 ---------------------------------
84 -- Restore_Opt_Config_Switches --
85 ---------------------------------
87 procedure Restore_Opt_Config_Switches
(Save
: Config_Switches_Type
) is
89 Ada_Version
:= Save
.Ada_Version
;
90 Ada_Version_Explicit
:= Save
.Ada_Version_Explicit
;
91 Assertions_Enabled
:= Save
.Assertions_Enabled
;
92 Assume_No_Invalid_Values
:= Save
.Assume_No_Invalid_Values
;
93 Check_Float_Overflow
:= Save
.Check_Float_Overflow
;
94 Check_Policy_List
:= Save
.Check_Policy_List
;
95 Default_Pool
:= Save
.Default_Pool
;
96 Dynamic_Elaboration_Checks
:= Save
.Dynamic_Elaboration_Checks
;
97 Exception_Locations_Suppressed
:= Save
.Exception_Locations_Suppressed
;
98 Extensions_Allowed
:= Save
.Extensions_Allowed
;
99 External_Name_Exp_Casing
:= Save
.External_Name_Exp_Casing
;
100 External_Name_Imp_Casing
:= Save
.External_Name_Imp_Casing
;
101 Fast_Math
:= Save
.Fast_Math
;
102 Initialize_Scalars
:= Save
.Initialize_Scalars
;
103 Optimize_Alignment
:= Save
.Optimize_Alignment
;
104 Optimize_Alignment_Local
:= Save
.Optimize_Alignment_Local
;
105 Persistent_BSS_Mode
:= Save
.Persistent_BSS_Mode
;
106 Polling_Required
:= Save
.Polling_Required
;
107 Short_Descriptors
:= Save
.Short_Descriptors
;
108 Use_VADS_Size
:= Save
.Use_VADS_Size
;
110 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
111 -- Normalize_Scalars is not saved/restored because after set to True its
112 -- value is never changed. That is, if a compilation unit has pragma
113 -- Normalize_Scalars then it forces that value for all with'ed units.
115 Init_Or_Norm_Scalars
:= Initialize_Scalars
or Normalize_Scalars
;
116 end Restore_Opt_Config_Switches
;
118 ------------------------------
119 -- Save_Opt_Config_Switches --
120 ------------------------------
122 procedure Save_Opt_Config_Switches
(Save
: out Config_Switches_Type
) is
124 Save
.Ada_Version
:= Ada_Version
;
125 Save
.Ada_Version_Explicit
:= Ada_Version_Explicit
;
126 Save
.Assertions_Enabled
:= Assertions_Enabled
;
127 Save
.Assume_No_Invalid_Values
:= Assume_No_Invalid_Values
;
128 Save
.Check_Float_Overflow
:= Check_Float_Overflow
;
129 Save
.Check_Policy_List
:= Check_Policy_List
;
130 Save
.Default_Pool
:= Default_Pool
;
131 Save
.Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks
;
132 Save
.Exception_Locations_Suppressed
:= Exception_Locations_Suppressed
;
133 Save
.Extensions_Allowed
:= Extensions_Allowed
;
134 Save
.External_Name_Exp_Casing
:= External_Name_Exp_Casing
;
135 Save
.External_Name_Imp_Casing
:= External_Name_Imp_Casing
;
136 Save
.Fast_Math
:= Fast_Math
;
137 Save
.Initialize_Scalars
:= Initialize_Scalars
;
138 Save
.Optimize_Alignment
:= Optimize_Alignment
;
139 Save
.Optimize_Alignment_Local
:= Optimize_Alignment_Local
;
140 Save
.Persistent_BSS_Mode
:= Persistent_BSS_Mode
;
141 Save
.Polling_Required
:= Polling_Required
;
142 Save
.Short_Descriptors
:= Short_Descriptors
;
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 Dynamic_Elaboration_Checks
:= False;
165 Extensions_Allowed
:= True;
166 External_Name_Exp_Casing
:= As_Is
;
167 External_Name_Imp_Casing
:= Lowercase
;
168 Optimize_Alignment
:= 'O';
169 Persistent_BSS_Mode
:= False;
170 Use_VADS_Size
:= False;
171 Optimize_Alignment_Local
:= True;
173 -- For an internal unit, assertions/debug pragmas are off unless this
174 -- is the main unit and they were explicitly enabled. We also make
175 -- sure we do not assume that values are necessarily valid.
178 Assertions_Enabled
:= Assertions_Enabled_Config
;
179 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
180 Check_Policy_List
:= Check_Policy_List_Config
;
182 Assertions_Enabled
:= False;
183 Assume_No_Invalid_Values
:= False;
184 Check_Policy_List
:= Empty
;
187 -- Case of non-internal unit
190 Ada_Version
:= Ada_Version_Config
;
191 Ada_Version_Explicit
:= Ada_Version_Explicit_Config
;
192 Assertions_Enabled
:= Assertions_Enabled_Config
;
193 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
194 Check_Float_Overflow
:= Check_Float_Overflow_Config
;
195 Check_Policy_List
:= Check_Policy_List_Config
;
196 Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks_Config
;
197 Extensions_Allowed
:= Extensions_Allowed_Config
;
198 External_Name_Exp_Casing
:= External_Name_Exp_Casing_Config
;
199 External_Name_Imp_Casing
:= External_Name_Imp_Casing_Config
;
200 Fast_Math
:= Fast_Math_Config
;
201 Initialize_Scalars
:= Initialize_Scalars_Config
;
202 Optimize_Alignment
:= Optimize_Alignment_Config
;
203 Optimize_Alignment_Local
:= False;
204 Persistent_BSS_Mode
:= Persistent_BSS_Mode_Config
;
205 Use_VADS_Size
:= Use_VADS_Size_Config
;
207 -- Update consistently the value of Init_Or_Norm_Scalars. The value
208 -- of Normalize_Scalars is not saved/restored because once set to
209 -- True its value is never changed. That is, if a compilation unit
210 -- has pragma Normalize_Scalars then it forces that value for all
213 Init_Or_Norm_Scalars
:= Initialize_Scalars
or Normalize_Scalars
;
216 Default_Pool
:= Default_Pool_Config
;
217 Exception_Locations_Suppressed
:= Exception_Locations_Suppressed_Config
;
218 Fast_Math
:= Fast_Math_Config
;
219 Optimize_Alignment
:= Optimize_Alignment_Config
;
220 Polling_Required
:= Polling_Required_Config
;
221 Short_Descriptors
:= Short_Descriptors_Config
;
222 end Set_Opt_Config_Switches
;
228 procedure Tree_Read
is
229 Tree_Version_String_Len
: Nat
;
230 Ada_Version_Config_Val
: Nat
;
231 Ada_Version_Explicit_Config_Val
: Nat
;
232 Assertions_Enabled_Config_Val
: Nat
;
235 Tree_Read_Int
(Tree_ASIS_Version_Number
);
236 Tree_Read_Bool
(Brief_Output
);
237 Tree_Read_Bool
(GNAT_Mode
);
238 Tree_Read_Char
(Identifier_Character_Set
);
239 Tree_Read_Int
(Maximum_File_Name_Length
);
240 Tree_Read_Data
(Suppress_Options
'Address,
241 (Suppress_Options
'Size + SU
- 1) / SU
);
242 Tree_Read_Bool
(Verbose_Mode
);
243 Tree_Read_Data
(Warning_Mode
'Address,
244 (Warning_Mode
'Size + SU
- 1) / SU
);
245 Tree_Read_Int
(Ada_Version_Config_Val
);
246 Tree_Read_Int
(Ada_Version_Explicit_Config_Val
);
247 Tree_Read_Int
(Assertions_Enabled_Config_Val
);
248 Tree_Read_Bool
(All_Errors_Mode
);
249 Tree_Read_Bool
(Assertions_Enabled
);
250 Tree_Read_Bool
(Check_Float_Overflow
);
251 Tree_Read_Int
(Int
(Check_Policy_List
));
252 Tree_Read_Int
(Int
(Default_Pool
));
253 Tree_Read_Bool
(Full_List
);
255 Ada_Version_Config
:=
256 Ada_Version_Type
'Val (Ada_Version_Config_Val
);
257 Ada_Version_Explicit_Config
:=
258 Ada_Version_Type
'Val (Ada_Version_Explicit_Config_Val
);
259 Assertions_Enabled_Config
:=
260 Boolean'Val (Assertions_Enabled_Config_Val
);
262 -- Read version string: we have to get the length first
264 Tree_Read_Int
(Tree_Version_String_Len
);
267 Tmp
: String (1 .. Integer (Tree_Version_String_Len
));
270 (Tmp
'Address, Tree_Version_String_Len
);
271 System
.Strings
.Free
(Tree_Version_String
);
272 Free
(Tree_Version_String
);
273 Tree_Version_String
:= new String'(Tmp);
276 Tree_Read_Data (Distribution_Stub_Mode'Address,
277 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
278 Tree_Read_Bool (Inline_Active);
279 Tree_Read_Bool (Inline_Processing_Required);
280 Tree_Read_Bool (List_Units);
281 Tree_Read_Bool (Configurable_Run_Time_Mode);
282 Tree_Read_Data (Operating_Mode'Address,
283 (Operating_Mode'Size + SU - 1) / Storage_Unit);
284 Tree_Read_Bool (Suppress_Checks);
285 Tree_Read_Bool (Try_Semantics);
286 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
287 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
288 Tree_Read_Bool (Upper_Half_Encoding);
289 Tree_Read_Bool (Force_ALI_Tree_File);
296 procedure Tree_Write is
297 Version_String : String := Gnat_Version_String;
300 Tree_Write_Int (ASIS_Version_Number);
301 Tree_Write_Bool (Brief_Output);
302 Tree_Write_Bool (GNAT_Mode);
303 Tree_Write_Char (Identifier_Character_Set);
304 Tree_Write_Int (Maximum_File_Name_Length);
305 Tree_Write_Data (Suppress_Options'Address,
306 (Suppress_Options'Size + SU - 1) / SU);
307 Tree_Write_Bool (Verbose_Mode);
308 Tree_Write_Data (Warning_Mode'Address,
309 (Warning_Mode'Size + SU - 1) / Storage_Unit);
310 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
311 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
312 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
313 Tree_Write_Bool (All_Errors_Mode);
314 Tree_Write_Bool (Assertions_Enabled);
315 Tree_Write_Bool (Check_Float_Overflow);
316 Tree_Write_Int (Int (Check_Policy_List));
317 Tree_Write_Int (Int (Default_Pool));
318 Tree_Write_Bool (Full_List);
319 Tree_Write_Int (Int (Version_String'Length));
320 Tree_Write_Data (Version_String'Address, Version_String'Length);
321 Tree_Write_Data (Distribution_Stub_Mode'Address,
322 (Distribution_Stub_Mode'Size + SU - 1) / SU);
323 Tree_Write_Bool (Inline_Active);
324 Tree_Write_Bool (Inline_Processing_Required);
325 Tree_Write_Bool (List_Units);
326 Tree_Write_Bool (Configurable_Run_Time_Mode);
327 Tree_Write_Data (Operating_Mode'Address,
328 (Operating_Mode'Size + SU - 1) / SU);
329 Tree_Write_Bool (Suppress_Checks);
330 Tree_Write_Bool (Try_Semantics);
331 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
332 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
333 Tree_Write_Bool (Upper_Half_Encoding);
334 Tree_Write_Bool (Force_ALI_Tree_File);