1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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_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 Use_VADS_Size_Config
:= Use_VADS_Size
;
66 -- Reset the indication that Optimize_Alignment was set locally, since
67 -- if we had a pragma in the config file, it would set this flag True,
68 -- but that's not a local setting.
70 Optimize_Alignment_Local
:= False;
71 end Register_Opt_Config_Switches
;
73 ---------------------------------
74 -- Restore_Opt_Config_Switches --
75 ---------------------------------
77 procedure Restore_Opt_Config_Switches
(Save
: Config_Switches_Type
) is
79 Ada_Version
:= Save
.Ada_Version
;
80 Ada_Version_Explicit
:= Save
.Ada_Version_Explicit
;
81 Assertions_Enabled
:= Save
.Assertions_Enabled
;
82 Assume_No_Invalid_Values
:= Save
.Assume_No_Invalid_Values
;
83 Check_Policy_List
:= Save
.Check_Policy_List
;
84 Debug_Pragmas_Enabled
:= Save
.Debug_Pragmas_Enabled
;
85 Dynamic_Elaboration_Checks
:= Save
.Dynamic_Elaboration_Checks
;
86 Exception_Locations_Suppressed
:= Save
.Exception_Locations_Suppressed
;
87 Extensions_Allowed
:= Save
.Extensions_Allowed
;
88 External_Name_Exp_Casing
:= Save
.External_Name_Exp_Casing
;
89 External_Name_Imp_Casing
:= Save
.External_Name_Imp_Casing
;
90 Fast_Math
:= Save
.Fast_Math
;
91 Init_Or_Norm_Scalars
:= Save
.Init_Or_Norm_Scalars
;
92 Initialize_Scalars
:= Save
.Initialize_Scalars
;
93 Optimize_Alignment
:= Save
.Optimize_Alignment
;
94 Optimize_Alignment_Local
:= Save
.Optimize_Alignment_Local
;
95 Persistent_BSS_Mode
:= Save
.Persistent_BSS_Mode
;
96 Polling_Required
:= Save
.Polling_Required
;
97 Use_VADS_Size
:= Save
.Use_VADS_Size
;
98 end Restore_Opt_Config_Switches
;
100 ------------------------------
101 -- Save_Opt_Config_Switches --
102 ------------------------------
104 procedure Save_Opt_Config_Switches
(Save
: out Config_Switches_Type
) is
106 Save
.Ada_Version
:= Ada_Version
;
107 Save
.Ada_Version_Explicit
:= Ada_Version_Explicit
;
108 Save
.Assertions_Enabled
:= Assertions_Enabled
;
109 Save
.Assume_No_Invalid_Values
:= Assume_No_Invalid_Values
;
110 Save
.Check_Policy_List
:= Check_Policy_List
;
111 Save
.Debug_Pragmas_Enabled
:= Debug_Pragmas_Enabled
;
112 Save
.Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks
;
113 Save
.Exception_Locations_Suppressed
:= Exception_Locations_Suppressed
;
114 Save
.Extensions_Allowed
:= Extensions_Allowed
;
115 Save
.External_Name_Exp_Casing
:= External_Name_Exp_Casing
;
116 Save
.External_Name_Imp_Casing
:= External_Name_Imp_Casing
;
117 Save
.Fast_Math
:= Fast_Math
;
118 Save
.Init_Or_Norm_Scalars
:= Init_Or_Norm_Scalars
;
119 Save
.Initialize_Scalars
:= Initialize_Scalars
;
120 Save
.Optimize_Alignment
:= Optimize_Alignment
;
121 Save
.Optimize_Alignment_Local
:= Optimize_Alignment_Local
;
122 Save
.Persistent_BSS_Mode
:= Persistent_BSS_Mode
;
123 Save
.Polling_Required
:= Polling_Required
;
124 Save
.Use_VADS_Size
:= Use_VADS_Size
;
125 end Save_Opt_Config_Switches
;
127 -----------------------------
128 -- Set_Opt_Config_Switches --
129 -----------------------------
131 procedure Set_Opt_Config_Switches
132 (Internal_Unit
: Boolean;
136 -- Case of internal unit
138 if Internal_Unit
then
140 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
141 -- since the whole point of this is that it still properly indicates
142 -- the configuration setting even in a run time unit.
144 Ada_Version
:= Ada_Version_Runtime
;
145 Dynamic_Elaboration_Checks
:= False;
146 Extensions_Allowed
:= True;
147 External_Name_Exp_Casing
:= As_Is
;
148 External_Name_Imp_Casing
:= Lowercase
;
149 Optimize_Alignment
:= 'O';
150 Persistent_BSS_Mode
:= False;
151 Use_VADS_Size
:= False;
152 Optimize_Alignment_Local
:= True;
154 -- For an internal unit, assertions/debug pragmas are off unless this
155 -- is the main unit and they were explicitly enabled. We also make
156 -- sure we do not assume that values are necessarily valid.
159 Assertions_Enabled
:= Assertions_Enabled_Config
;
160 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
161 Debug_Pragmas_Enabled
:= Debug_Pragmas_Enabled_Config
;
162 Check_Policy_List
:= Check_Policy_List_Config
;
164 Assertions_Enabled
:= False;
165 Assume_No_Invalid_Values
:= False;
166 Debug_Pragmas_Enabled
:= False;
167 Check_Policy_List
:= Empty
;
170 -- Case of non-internal unit
173 Ada_Version
:= Ada_Version_Config
;
174 Ada_Version_Explicit
:= Ada_Version_Explicit_Config
;
175 Assertions_Enabled
:= Assertions_Enabled_Config
;
176 Assume_No_Invalid_Values
:= Assume_No_Invalid_Values_Config
;
177 Check_Policy_List
:= Check_Policy_List_Config
;
178 Debug_Pragmas_Enabled
:= Debug_Pragmas_Enabled_Config
;
179 Dynamic_Elaboration_Checks
:= Dynamic_Elaboration_Checks_Config
;
180 Extensions_Allowed
:= Extensions_Allowed_Config
;
181 External_Name_Exp_Casing
:= External_Name_Exp_Casing_Config
;
182 External_Name_Imp_Casing
:= External_Name_Imp_Casing_Config
;
183 Fast_Math
:= Fast_Math_Config
;
184 Init_Or_Norm_Scalars
:= Init_Or_Norm_Scalars_Config
;
185 Initialize_Scalars
:= Initialize_Scalars_Config
;
186 Optimize_Alignment
:= Optimize_Alignment_Config
;
187 Optimize_Alignment_Local
:= False;
188 Persistent_BSS_Mode
:= Persistent_BSS_Mode_Config
;
189 Use_VADS_Size
:= Use_VADS_Size_Config
;
192 Exception_Locations_Suppressed
:= Exception_Locations_Suppressed_Config
;
193 Fast_Math
:= Fast_Math_Config
;
194 Optimize_Alignment
:= Optimize_Alignment_Config
;
195 Polling_Required
:= Polling_Required_Config
;
196 end Set_Opt_Config_Switches
;
202 procedure Tree_Read
is
203 Tree_Version_String_Len
: Nat
;
204 Ada_Version_Config_Val
: Nat
;
205 Ada_Version_Explicit_Config_Val
: Nat
;
206 Assertions_Enabled_Config_Val
: Nat
;
209 Tree_Read_Int
(Tree_ASIS_Version_Number
);
210 Tree_Read_Bool
(Brief_Output
);
211 Tree_Read_Bool
(GNAT_Mode
);
212 Tree_Read_Char
(Identifier_Character_Set
);
213 Tree_Read_Int
(Maximum_File_Name_Length
);
214 Tree_Read_Data
(Suppress_Options
'Address,
215 (Suppress_Options
'Size + SU
- 1) / SU
);
216 Tree_Read_Bool
(Verbose_Mode
);
217 Tree_Read_Data
(Warning_Mode
'Address,
218 (Warning_Mode
'Size + SU
- 1) / SU
);
219 Tree_Read_Int
(Ada_Version_Config_Val
);
220 Tree_Read_Int
(Ada_Version_Explicit_Config_Val
);
221 Tree_Read_Int
(Assertions_Enabled_Config_Val
);
222 Tree_Read_Bool
(All_Errors_Mode
);
223 Tree_Read_Bool
(Assertions_Enabled
);
224 Tree_Read_Int
(Int
(Check_Policy_List
));
225 Tree_Read_Bool
(Debug_Pragmas_Enabled
);
226 Tree_Read_Bool
(Enable_Overflow_Checks
);
227 Tree_Read_Bool
(Full_List
);
229 Ada_Version_Config
:=
230 Ada_Version_Type
'Val (Ada_Version_Config_Val
);
231 Ada_Version_Explicit_Config
:=
232 Ada_Version_Type
'Val (Ada_Version_Explicit_Config_Val
);
233 Assertions_Enabled_Config
:=
234 Boolean'Val (Assertions_Enabled_Config_Val
);
236 -- Read version string: we have to get the length first
238 Tree_Read_Int
(Tree_Version_String_Len
);
241 Tmp
: String (1 .. Integer (Tree_Version_String_Len
));
244 (Tmp
'Address, Tree_Version_String_Len
);
245 System
.Strings
.Free
(Tree_Version_String
);
246 Free
(Tree_Version_String
);
247 Tree_Version_String
:= new String'(Tmp);
250 Tree_Read_Data (Distribution_Stub_Mode'Address,
251 (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
252 Tree_Read_Bool (Inline_Active);
253 Tree_Read_Bool (Inline_Processing_Required);
254 Tree_Read_Bool (List_Units);
255 Tree_Read_Bool (Configurable_Run_Time_Mode);
256 Tree_Read_Data (Operating_Mode'Address,
257 (Operating_Mode'Size + SU - 1) / Storage_Unit);
258 Tree_Read_Bool (Suppress_Checks);
259 Tree_Read_Bool (Try_Semantics);
260 Tree_Read_Data (Wide_Character_Encoding_Method'Address,
261 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
262 Tree_Read_Bool (Upper_Half_Encoding);
263 Tree_Read_Bool (Force_ALI_Tree_File);
270 procedure Tree_Write is
271 Version_String : String := Gnat_Version_String;
274 Tree_Write_Int (ASIS_Version_Number);
275 Tree_Write_Bool (Brief_Output);
276 Tree_Write_Bool (GNAT_Mode);
277 Tree_Write_Char (Identifier_Character_Set);
278 Tree_Write_Int (Maximum_File_Name_Length);
279 Tree_Write_Data (Suppress_Options'Address,
280 (Suppress_Options'Size + SU - 1) / SU);
281 Tree_Write_Bool (Verbose_Mode);
282 Tree_Write_Data (Warning_Mode'Address,
283 (Warning_Mode'Size + SU - 1) / Storage_Unit);
284 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Config));
285 Tree_Write_Int (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
286 Tree_Write_Int (Boolean'Pos (Assertions_Enabled_Config));
287 Tree_Write_Bool (All_Errors_Mode);
288 Tree_Write_Bool (Assertions_Enabled);
289 Tree_Write_Int (Int (Check_Policy_List));
290 Tree_Write_Bool (Debug_Pragmas_Enabled);
291 Tree_Write_Bool (Enable_Overflow_Checks);
292 Tree_Write_Bool (Full_List);
293 Tree_Write_Int (Int (Version_String'Length));
294 Tree_Write_Data (Version_String'Address, Version_String'Length);
295 Tree_Write_Data (Distribution_Stub_Mode'Address,
296 (Distribution_Stub_Mode'Size + SU - 1) / SU);
297 Tree_Write_Bool (Inline_Active);
298 Tree_Write_Bool (Inline_Processing_Required);
299 Tree_Write_Bool (List_Units);
300 Tree_Write_Bool (Configurable_Run_Time_Mode);
301 Tree_Write_Data (Operating_Mode'Address,
302 (Operating_Mode'Size + SU - 1) / SU);
303 Tree_Write_Bool (Suppress_Checks);
304 Tree_Write_Bool (Try_Semantics);
305 Tree_Write_Data (Wide_Character_Encoding_Method'Address,
306 (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
307 Tree_Write_Bool (Upper_Half_Encoding);
308 Tree_Write_Bool (Force_ALI_Tree_File);