Debian Codegraph @

gcc/ada/opt.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O P T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 package body Opt is
27
28 --------------------
29 -- SJLJ_Exceptions --
30 --------------------
31
32 function SJLJ_Exceptions return Boolean is
33 begin
34 return Exception_Mechanism = Back_End_SJLJ;
35 end SJLJ_Exceptions;
36
37 --------------------
38 -- ZCX_Exceptions --
39 --------------------
40
41 function ZCX_Exceptions return Boolean is
42 begin
43 return Exception_Mechanism = Back_End_ZCX;
44 end ZCX_Exceptions;
45
46 ------------------------------
47 -- Register_Config_Switches --
48 ------------------------------
49
50 procedure Register_Config_Switches is
51 begin
52 Ada_Version_Config := Ada_Version;
53 Ada_Version_Pragma_Config := Ada_Version_Pragma;
54 Ada_Version_Explicit_Config := Ada_Version_Explicit;
55 Assertions_Enabled_Config := Assertions_Enabled;
56 Assume_No_Invalid_Values_Config := Assume_No_Invalid_Values;
57 Check_Float_Overflow_Config := Check_Float_Overflow;
58 Check_Policy_List_Config := Check_Policy_List;
59 Default_Pool_Config := Default_Pool;
60 Default_SSO_Config := Default_SSO;
61 Dynamic_Elaboration_Checks_Config := Dynamic_Elaboration_Checks;
62 Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
63 External_Name_Exp_Casing_Config := External_Name_Exp_Casing;
64 External_Name_Imp_Casing_Config := External_Name_Imp_Casing;
65 Fast_Math_Config := Fast_Math;
66 Initialize_Scalars_Config := Initialize_Scalars;
67 No_Component_Reordering_Config := No_Component_Reordering;
68 Optimize_Alignment_Config := Optimize_Alignment;
69 Persistent_BSS_Mode_Config := Persistent_BSS_Mode;
70 Prefix_Exception_Messages_Config := Prefix_Exception_Messages;
71 SPARK_Mode_Config := SPARK_Mode;
72 SPARK_Mode_Pragma_Config := SPARK_Mode_Pragma;
73 Uneval_Old_Config := Uneval_Old;
74 Use_VADS_Size_Config := Use_VADS_Size;
75 Warnings_As_Errors_Count_Config := Warnings_As_Errors_Count;
76
77 -- Reset the indication that Optimize_Alignment was set locally, since
78 -- if we had a pragma in the config file, it would set this flag True,
79 -- but that's not a local setting.
80
81 Optimize_Alignment_Local := False;
82 end Register_Config_Switches;
83
84 -----------------------------
85 -- Restore_Config_Switches --
86 -----------------------------
87
88 procedure Restore_Config_Switches (Save : Config_Switches_Type) is
89 begin
90 Ada_Version := Save.Ada_Version;
91 Ada_Version_Pragma := Save.Ada_Version_Pragma;
92 Ada_Version_Explicit := Save.Ada_Version_Explicit;
93 Assertions_Enabled := Save.Assertions_Enabled;
94 Assume_No_Invalid_Values := Save.Assume_No_Invalid_Values;
95 Check_Float_Overflow := Save.Check_Float_Overflow;
96 Check_Policy_List := Save.Check_Policy_List;
97 Default_Pool := Save.Default_Pool;
98 Default_SSO := Save.Default_SSO;
99 Dynamic_Elaboration_Checks := Save.Dynamic_Elaboration_Checks;
100 Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
101 External_Name_Exp_Casing := Save.External_Name_Exp_Casing;
102 External_Name_Imp_Casing := Save.External_Name_Imp_Casing;
103 Fast_Math := Save.Fast_Math;
104 Initialize_Scalars := Save.Initialize_Scalars;
105 No_Component_Reordering := Save.No_Component_Reordering;
106 Optimize_Alignment := Save.Optimize_Alignment;
107 Optimize_Alignment_Local := Save.Optimize_Alignment_Local;
108 Persistent_BSS_Mode := Save.Persistent_BSS_Mode;
109 Prefix_Exception_Messages := Save.Prefix_Exception_Messages;
110 SPARK_Mode := Save.SPARK_Mode;
111 SPARK_Mode_Pragma := Save.SPARK_Mode_Pragma;
112 Uneval_Old := Save.Uneval_Old;
113 Use_VADS_Size := Save.Use_VADS_Size;
114 Warnings_As_Errors_Count := Save.Warnings_As_Errors_Count;
115
116 -- Update consistently the value of Init_Or_Norm_Scalars. The value of
117 -- Normalize_Scalars is not saved/restored because after set to True its
118 -- value is never changed. That is, if a compilation unit has pragma
119 -- Normalize_Scalars then it forces that value for all with'ed units.
120
121 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
122 end Restore_Config_Switches;
123
124 --------------------------
125 -- Save_Config_Switches --
126 --------------------------
127
128 function Save_Config_Switches return Config_Switches_Type is
129 begin
130 return
131 (Ada_Version => Ada_Version,
132 Ada_Version_Pragma => Ada_Version_Pragma,
133 Ada_Version_Explicit => Ada_Version_Explicit,
134 Assertions_Enabled => Assertions_Enabled,
135 Assume_No_Invalid_Values => Assume_No_Invalid_Values,
136 Check_Float_Overflow => Check_Float_Overflow,
137 Check_Policy_List => Check_Policy_List,
138 Default_Pool => Default_Pool,
139 Default_SSO => Default_SSO,
140 Dynamic_Elaboration_Checks => Dynamic_Elaboration_Checks,
141 Exception_Locations_Suppressed => Exception_Locations_Suppressed,
142 External_Name_Exp_Casing => External_Name_Exp_Casing,
143 External_Name_Imp_Casing => External_Name_Imp_Casing,
144 Fast_Math => Fast_Math,
145 Initialize_Scalars => Initialize_Scalars,
146 No_Component_Reordering => No_Component_Reordering,
147 Normalize_Scalars => Normalize_Scalars,
148 Optimize_Alignment => Optimize_Alignment,
149 Optimize_Alignment_Local => Optimize_Alignment_Local,
150 Persistent_BSS_Mode => Persistent_BSS_Mode,
151 Prefix_Exception_Messages => Prefix_Exception_Messages,
152 SPARK_Mode => SPARK_Mode,
153 SPARK_Mode_Pragma => SPARK_Mode_Pragma,
154 Uneval_Old => Uneval_Old,
155 Use_VADS_Size => Use_VADS_Size,
156 Warnings_As_Errors_Count => Warnings_As_Errors_Count);
157 end Save_Config_Switches;
158
159 -------------------------
160 -- Set_Config_Switches --
161 -------------------------
162
163 procedure Set_Config_Switches
164 (Internal_Unit : Boolean;
165 Main_Unit : Boolean)
166 is
167 begin
168 -- Case of internal unit
169
170 if Internal_Unit then
171
172 -- Set standard switches. Note we do NOT set Ada_Version_Explicit
173 -- since the whole point of this is that it still properly indicates
174 -- the configuration setting even in a run time unit.
175
176 Ada_Version := Ada_Version_Runtime;
177 Ada_Version_Pragma := Empty;
178 Default_SSO := ' ';
179 Dynamic_Elaboration_Checks := False;
180 External_Name_Exp_Casing := As_Is;
181 External_Name_Imp_Casing := Lowercase;
182 No_Component_Reordering := False;
183 Optimize_Alignment := 'O';
184 Optimize_Alignment_Local := True;
185 Persistent_BSS_Mode := False;
186 Prefix_Exception_Messages := True;
187 Uneval_Old := 'E';
188 Use_VADS_Size := False;
189
190 -- Note: we do not need to worry about Warnings_As_Errors_Count since
191 -- we do not expect to get any warnings from compiling such a unit.
192
193 -- For an internal unit, assertions/debug pragmas are off unless this
194 -- is the main unit and they were explicitly enabled, or unless the
195 -- main unit was compiled in GNAT mode. We also make sure we do not
196 -- assume that values are necessarily valid and that SPARK_Mode is
197 -- set to its configuration value.
198
199 if Main_Unit then
200 Assertions_Enabled := Assertions_Enabled_Config;
201 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
202 Check_Policy_List := Check_Policy_List_Config;
203 SPARK_Mode := SPARK_Mode_Config;
204 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
205
206 else
207 -- In GNATprove mode assertions should be always enabled, even
208 -- when analysing internal units.
209
210 if GNATprove_Mode then
211 pragma Assert (Assertions_Enabled);
212 null;
213
214 elsif GNAT_Mode_Config then
215 Assertions_Enabled := Assertions_Enabled_Config;
216 else
217 Assertions_Enabled := False;
218 end if;
219
220 Assume_No_Invalid_Values := False;
221 Check_Policy_List := Empty;
222 SPARK_Mode := None;
223 SPARK_Mode_Pragma := Empty;
224 end if;
225
226 -- Case of non-internal unit
227
228 else
229 Ada_Version := Ada_Version_Config;
230 Ada_Version_Pragma := Ada_Version_Pragma_Config;
231 Ada_Version_Explicit := Ada_Version_Explicit_Config;
232 Assertions_Enabled := Assertions_Enabled_Config;
233 Assume_No_Invalid_Values := Assume_No_Invalid_Values_Config;
234 Check_Float_Overflow := Check_Float_Overflow_Config;
235 Check_Policy_List := Check_Policy_List_Config;
236 Default_SSO := Default_SSO_Config;
237 Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
238 External_Name_Exp_Casing := External_Name_Exp_Casing_Config;
239 External_Name_Imp_Casing := External_Name_Imp_Casing_Config;
240 Fast_Math := Fast_Math_Config;
241 Initialize_Scalars := Initialize_Scalars_Config;
242 No_Component_Reordering := No_Component_Reordering_Config;
243 Optimize_Alignment := Optimize_Alignment_Config;
244 Optimize_Alignment_Local := False;
245 Persistent_BSS_Mode := Persistent_BSS_Mode_Config;
246 Prefix_Exception_Messages := Prefix_Exception_Messages_Config;
247 SPARK_Mode := SPARK_Mode_Config;
248 SPARK_Mode_Pragma := SPARK_Mode_Pragma_Config;
249 Uneval_Old := Uneval_Old_Config;
250 Use_VADS_Size := Use_VADS_Size_Config;
251 Warnings_As_Errors_Count := Warnings_As_Errors_Count_Config;
252
253 -- Update consistently the value of Init_Or_Norm_Scalars. The value
254 -- of Normalize_Scalars is not saved/restored because once set to
255 -- True its value is never changed. That is, if a compilation unit
256 -- has pragma Normalize_Scalars then it forces that value for all
257 -- with'ed units.
258
259 Init_Or_Norm_Scalars := Initialize_Scalars or Normalize_Scalars;
260 end if;
261
262 -- Values set for all units
263
264 Default_Pool := Default_Pool_Config;
265 Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
266 Fast_Math := Fast_Math_Config;
267 end Set_Config_Switches;
268
269 end Opt;