]>
Commit | Line | Data |
---|---|---|
83cce46b | 1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- G N A T 1 D R V -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
c918b5ca | 9 | -- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- |
83cce46b | 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- -- | |
80df182a | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
83cce46b | 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 -- | |
80df182a | 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. -- | |
83cce46b | 20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
e78e8c8e | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
83cce46b | 23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | with Atree; use Atree; | |
27 | with Back_End; use Back_End; | |
7b8fa048 | 28 | with Checks; |
83cce46b | 29 | with Comperr; |
30 | with Csets; use Csets; | |
31 | with Debug; use Debug; | |
32 | with Elists; | |
33 | with Errout; use Errout; | |
e00e091c | 34 | with Exp_CG; |
9dfe12ae | 35 | with Fmap; |
83cce46b | 36 | with Fname; use Fname; |
37 | with Fname.UF; use Fname.UF; | |
38 | with Frontend; | |
360b005f | 39 | with Ghost; |
83cce46b | 40 | with Gnatvsn; use Gnatvsn; |
83cce46b | 41 | with Inline; |
42 | with Lib; use Lib; | |
43 | with Lib.Writ; use Lib.Writ; | |
9dfe12ae | 44 | with Lib.Xref; |
83cce46b | 45 | with Namet; use Namet; |
46 | with Nlists; | |
47 | with Opt; use Opt; | |
48 | with Osint; use Osint; | |
49 | with Output; use Output; | |
11b376d2 | 50 | with Par_SCO; |
9dfe12ae | 51 | with Prepcomp; |
83cce46b | 52 | with Repinfo; use Repinfo; |
9dfe12ae | 53 | with Restrict; |
925c2ba1 | 54 | with Rident; use Rident; |
10084566 | 55 | with Rtsfind; |
a9958373 | 56 | with SCOs; |
83cce46b | 57 | with Sem; |
9dfe12ae | 58 | with Sem_Ch8; |
59 | with Sem_Ch12; | |
83cce46b | 60 | with Sem_Ch13; |
e7b2d6bc | 61 | with Sem_Elim; |
9dfe12ae | 62 | with Sem_Eval; |
63 | with Sem_Type; | |
cba2ae82 | 64 | with Set_Targ; |
83cce46b | 65 | with Sinfo; use Sinfo; |
66 | with Sinput.L; use Sinput.L; | |
67 | with Snames; | |
68 | with Sprint; use Sprint; | |
69 | with Stringt; | |
9af0ddc7 | 70 | with Stylesw; use Stylesw; |
10084566 | 71 | with Targparm; use Targparm; |
7cc02797 | 72 | with Tbuild; |
83cce46b | 73 | with Tree_Gen; |
74 | with Treepr; use Treepr; | |
75 | with Ttypes; | |
76 | with Types; use Types; | |
9dfe12ae | 77 | with Uintp; use Uintp; |
83cce46b | 78 | with Uname; use Uname; |
79 | with Urealp; | |
80 | with Usage; | |
9af0ddc7 | 81 | with Validsw; use Validsw; |
83cce46b | 82 | |
83 | with System.Assertions; | |
82b93248 | 84 | with System.OS_Lib; |
83cce46b | 85 | |
d10a989c | 86 | -------------- |
87 | -- Gnat1drv -- | |
88 | -------------- | |
89 | ||
83cce46b | 90 | procedure Gnat1drv is |
91 | Main_Unit_Node : Node_Id; | |
92 | -- Compilation unit node for main unit | |
93 | ||
83cce46b | 94 | Main_Kind : Node_Kind; |
0a90e223 | 95 | -- Kind of main compilation unit node |
83cce46b | 96 | |
83cce46b | 97 | Back_End_Mode : Back_End.Back_End_Mode_Type; |
98 | -- Record back end mode | |
99 | ||
749c967d | 100 | procedure Adjust_Global_Switches; |
101 | -- There are various interactions between front end switch settings, | |
102 | -- including debug switch settings and target dependent parameters. | |
103 | -- This procedure takes care of properly handling these interactions. | |
063ed58b | 104 | -- We do it after scanning out all the switches, so that we are not |
749c967d | 105 | -- depending on the order in which switches appear. |
106 | ||
10084566 | 107 | procedure Check_Bad_Body; |
108 | -- Called to check if the unit we are compiling has a bad body | |
109 | ||
110 | procedure Check_Rep_Info; | |
111 | -- Called when we are not generating code, to check if -gnatR was requested | |
112 | -- and if so, explain that we will not be honoring the request. | |
113 | ||
7b8fa048 | 114 | procedure Post_Compilation_Validation_Checks; |
115 | -- This procedure performs various validation checks that have to be left | |
116 | -- to the end of the compilation process, after generating code but before | |
117 | -- issuing error messages. In particular, these checks generally require | |
118 | -- the information provided by the back end in back annotation of declared | |
119 | -- entities (e.g. actual size and alignment values chosen by the back end). | |
120 | ||
749c967d | 121 | ---------------------------- |
122 | -- Adjust_Global_Switches -- | |
123 | ---------------------------- | |
124 | ||
125 | procedure Adjust_Global_Switches is | |
126 | begin | |
a9cd517c | 127 | -- -gnatd.M enables Relaxed_RM_Semantics |
9af0ddc7 | 128 | |
a9cd517c | 129 | if Debug_Flag_Dot_MM then |
130 | Relaxed_RM_Semantics := True; | |
9af0ddc7 | 131 | end if; |
749c967d | 132 | |
5542710d | 133 | -- -gnatd.V or -gnatd.u enables special C expansion mode |
27cc5512 | 134 | |
5542710d | 135 | if Debug_Flag_Dot_VV or Debug_Flag_Dot_U then |
27cc5512 | 136 | Modify_Tree_For_C := True; |
137 | end if; | |
138 | ||
ce9bfeb1 | 139 | -- -gnatd.E sets Error_To_Warning mode, causing selected error messages |
140 | -- to be treated as warnings instead of errors. | |
141 | ||
142 | if Debug_Flag_Dot_EE then | |
143 | Error_To_Warning := True; | |
144 | end if; | |
145 | ||
f005e79a | 146 | -- Disable CodePeer_Mode in Check_Syntax, since we need front-end |
147 | -- expansion. | |
148 | ||
149 | if Operating_Mode = Check_Syntax then | |
150 | CodePeer_Mode := False; | |
151 | end if; | |
152 | ||
749c967d | 153 | -- Set ASIS mode if -gnatt and -gnatc are set |
154 | ||
155 | if Operating_Mode = Check_Semantics and then Tree_Output then | |
156 | ASIS_Mode := True; | |
157 | ||
158 | -- Turn off inlining in ASIS mode, since ASIS cannot handle the extra | |
159 | -- information in the trees caused by inlining being active. | |
160 | ||
15a0a165 | 161 | -- More specifically, the tree seems to be malformed from the ASIS |
162 | -- point of view if -gnatc and -gnatn appear together??? | |
749c967d | 163 | |
164 | Inline_Active := False; | |
165 | ||
f005e79a | 166 | -- Turn off SCIL generation and CodePeer mode in semantics mode, |
167 | -- since SCIL requires front-end expansion. | |
9af0ddc7 | 168 | |
169 | Generate_SCIL := False; | |
f005e79a | 170 | CodePeer_Mode := False; |
9af0ddc7 | 171 | end if; |
172 | ||
173 | -- SCIL mode needs to disable front-end inlining since the generated | |
174 | -- trees (in particular order and consistency between specs compiled | |
175 | -- as part of a main unit or as part of a with-clause) are causing | |
176 | -- troubles. | |
749c967d | 177 | |
9af0ddc7 | 178 | if Generate_SCIL then |
179 | Front_End_Inlining := False; | |
749c967d | 180 | end if; |
181 | ||
64427fe6 | 182 | -- Tune settings for optimal SCIL generation in CodePeer mode |
9af0ddc7 | 183 | |
184 | if CodePeer_Mode then | |
185 | ||
fbf4d6ef | 186 | -- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not |
187 | -- compatible with CodePeer mode. | |
58c0ee52 | 188 | |
189 | GNATprove_Mode := False; | |
fbf4d6ef | 190 | Debug_Flag_Dot_FF := False; |
58c0ee52 | 191 | |
cf563f22 | 192 | -- Turn off inlining, confuses CodePeer output and gains nothing |
749c967d | 193 | |
749c967d | 194 | Front_End_Inlining := False; |
9af0ddc7 | 195 | Inline_Active := False; |
196 | ||
43e39b42 | 197 | -- Disable front-end optimizations, to keep the tree as close to the |
198 | -- source code as possible, and also to avoid inconsistencies between | |
199 | -- trees when using different optimization switches. | |
200 | ||
201 | Optimization_Level := 0; | |
202 | ||
925c2ba1 | 203 | -- Enable some restrictions systematically to simplify the generated |
204 | -- code (and ease analysis). Note that restriction checks are also | |
ee0d6223 | 205 | -- disabled in CodePeer mode, see Restrict.Check_Restriction, and |
206 | -- user specified Restrictions pragmas are ignored, see | |
207 | -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings. | |
4606d5a9 | 208 | |
ee0d6223 | 209 | Restrict.Restrictions.Set (No_Initialize_Scalars) := True; |
64427fe6 | 210 | Restrict.Restrictions.Set (No_Task_Hierarchy) := True; |
211 | Restrict.Restrictions.Set (No_Abort_Statements) := True; | |
212 | Restrict.Restrictions.Set (Max_Asynchronous_Select_Nesting) := True; | |
925c2ba1 | 213 | Restrict.Restrictions.Value (Max_Asynchronous_Select_Nesting) := 0; |
4606d5a9 | 214 | |
d757af67 | 215 | -- Suppress division by zero and access checks since they are handled |
216 | -- implicitly by CodePeer. | |
cd534f03 | 217 | |
218 | -- Turn off dynamic elaboration checks: generates inconsistencies in | |
9af0ddc7 | 219 | -- trees between specs compiled as part of a main unit or as part of |
220 | -- a with-clause. | |
221 | ||
2f1aac99 | 222 | -- Turn off alignment checks: these cannot be proved statically by |
223 | -- CodePeer and generate false positives. | |
224 | ||
cd534f03 | 225 | -- Enable all other language checks |
9af0ddc7 | 226 | |
0df9d43f | 227 | Suppress_Options.Suppress := |
228 | (Access_Check => True, | |
229 | Alignment_Check => True, | |
230 | Division_Check => True, | |
231 | Elaboration_Check => True, | |
232 | others => False); | |
fafc6b97 | 233 | |
cd534f03 | 234 | Dynamic_Elaboration_Checks := False; |
9af0ddc7 | 235 | |
c412fcee | 236 | -- Set STRICT mode for overflow checks if not set explicitly. This |
237 | -- prevents suppressing of overflow checks by default, in code down | |
238 | -- below. | |
d757af67 | 239 | |
db415383 | 240 | if Suppress_Options.Overflow_Mode_General = Not_Set then |
241 | Suppress_Options.Overflow_Mode_General := Strict; | |
242 | Suppress_Options.Overflow_Mode_Assertions := Strict; | |
d757af67 | 243 | end if; |
244 | ||
af25d38d | 245 | -- CodePeer handles division and overflow checks directly, based on |
246 | -- the marks set by the frontend, hence no special expansion should | |
247 | -- be performed in the frontend for division and overflow checks. | |
248 | ||
249 | Backend_Divide_Checks_On_Target := True; | |
250 | Backend_Overflow_Checks_On_Target := True; | |
251 | ||
9af0ddc7 | 252 | -- Kill debug of generated code, since it messes up sloc values |
253 | ||
254 | Debug_Generated_Code := False; | |
255 | ||
64427fe6 | 256 | -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD) |
cf563f22 | 257 | -- Do we really need to spend time generating xref in CodePeer |
9af0ddc7 | 258 | -- mode??? Consider setting Xref_Active to False. |
259 | ||
260 | Xref_Active := True; | |
261 | ||
262 | -- Polling mode forced off, since it generates confusing junk | |
263 | ||
264 | Polling_Required := False; | |
265 | ||
64427fe6 | 266 | -- Set operating mode to Generate_Code to benefit from full front-end |
267 | -- expansion (e.g. generics). | |
9af0ddc7 | 268 | |
34fd8639 | 269 | Operating_Mode := Generate_Code; |
9af0ddc7 | 270 | |
271 | -- We need SCIL generation of course | |
272 | ||
273 | Generate_SCIL := True; | |
274 | ||
51ea9c94 | 275 | -- Enable assertions, since they give CodePeer valuable extra info |
9af0ddc7 | 276 | |
ed3c9510 | 277 | Assertions_Enabled := True; |
9af0ddc7 | 278 | |
fa6a6949 | 279 | -- Disable all simple value propagation. This is an optimization |
280 | -- which is valuable for code optimization, and also for generation | |
281 | -- of compiler warnings, but these are being turned off by default, | |
282 | -- and CodePeer generates better messages (referencing original | |
283 | -- variables) this way. | |
284 | ||
9af0ddc7 | 285 | Debug_Flag_MM := True; |
286 | ||
287 | -- Set normal RM validity checking, and checking of IN OUT parameters | |
cf563f22 | 288 | -- (this might give CodePeer more useful checks to analyze, to be |
9af0ddc7 | 289 | -- confirmed???). All other validity checking is turned off, since |
cf563f22 | 290 | -- this can generate very complex trees that only confuse CodePeer |
9af0ddc7 | 291 | -- and do not bring enough useful info. |
292 | ||
293 | Reset_Validity_Check_Options; | |
294 | Validity_Check_Default := True; | |
295 | Validity_Check_In_Out_Params := True; | |
296 | Validity_Check_In_Params := True; | |
297 | ||
8fd43ddd | 298 | -- Turn off style check options and ignore any style check pragmas |
299 | -- since we are not interested in any front-end warnings when we are | |
300 | -- getting CodePeer output. | |
9af0ddc7 | 301 | |
302 | Reset_Style_Check_Options; | |
8fd43ddd | 303 | Ignore_Style_Checks_Pragmas := True; |
39a79c9e | 304 | |
305 | -- Always perform semantics and generate ali files in CodePeer mode, | |
306 | -- so that a gnatmake -c -k will proceed further when possible. | |
307 | ||
308 | Force_ALI_Tree_File := True; | |
309 | Try_Semantics := True; | |
a9cd517c | 310 | |
ce4da1ed | 311 | -- Make the Ada front-end more liberal so that the compiler will |
312 | -- allow illegal code that is allowed by other compilers. CodePeer | |
39a0c1d3 | 313 | -- is in the business of finding problems, not enforcing rules. |
ce4da1ed | 314 | -- This is useful when using CodePeer mode with other compilers. |
315 | ||
a9cd517c | 316 | Relaxed_RM_Semantics := True; |
317 | end if; | |
318 | ||
cf45b231 | 319 | -- Enable some individual switches that are implied by relaxed RM |
320 | -- semantics mode. | |
321 | ||
a9cd517c | 322 | if Relaxed_RM_Semantics then |
ab78ef7f | 323 | Opt.Allow_Integer_Address := True; |
a9cd517c | 324 | Overriding_Renamings := True; |
778ebf56 | 325 | Treat_Categorization_Errors_As_Warnings := True; |
749c967d | 326 | end if; |
327 | ||
c39cce40 | 328 | -- Enable GNATprove_Mode when using -gnatd.F switch |
67ff7f27 | 329 | |
175a6969 | 330 | if Debug_Flag_Dot_FF then |
c39cce40 | 331 | GNATprove_Mode := True; |
175a6969 | 332 | end if; |
333 | ||
c39cce40 | 334 | -- GNATprove_Mode is also activated by default in the gnat2why |
335 | -- executable. | |
175a6969 | 336 | |
c39cce40 | 337 | if GNATprove_Mode then |
c412fcee | 338 | |
c412fcee | 339 | -- Turn off inlining, which would confuse formal verification output |
340 | -- and gain nothing. | |
341 | ||
342 | Front_End_Inlining := False; | |
343 | Inline_Active := False; | |
344 | ||
72756019 | 345 | -- Issue warnings for failure to inline subprograms, as otherwise |
346 | -- expected in GNATprove mode for the local subprograms without | |
347 | -- contracts. | |
348 | ||
349 | Ineffective_Inline_Warnings := True; | |
350 | ||
c412fcee | 351 | -- Disable front-end optimizations, to keep the tree as close to the |
352 | -- source code as possible, and also to avoid inconsistencies between | |
353 | -- trees when using different optimization switches. | |
354 | ||
355 | Optimization_Level := 0; | |
356 | ||
357 | -- Enable some restrictions systematically to simplify the generated | |
358 | -- code (and ease analysis). Note that restriction checks are also | |
b4f636a7 | 359 | -- disabled in SPARK mode, see Restrict.Check_Restriction, and user |
c412fcee | 360 | -- specified Restrictions pragmas are ignored, see |
361 | -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings. | |
362 | ||
363 | Restrict.Restrictions.Set (No_Initialize_Scalars) := True; | |
364 | ||
365 | -- Note: at this point we used to suppress various checks, but that | |
366 | -- is not what we want. We need the semantic processing for these | |
367 | -- checks (which will set flags like Do_Overflow_Check, showing the | |
368 | -- points at which potential checks are required semantically). We | |
369 | -- don't want the expansion associated with these checks, but that | |
370 | -- happens anyway because this expansion is simply not done in the | |
b4f636a7 | 371 | -- SPARK version of the expander. |
c412fcee | 372 | |
0d4674f2 | 373 | -- On the contrary, we need to enable explicitly all language checks, |
9c7948d7 | 374 | -- as they may have been suppressed by the use of switch -gnatp. |
0d4674f2 | 375 | |
376 | Suppress_Options.Suppress := (others => False); | |
377 | ||
f5240217 | 378 | -- Turn off dynamic elaboration checks. SPARK mode depends on the |
379 | -- use of the static elaboration mode. | |
4098232e | 380 | |
c412fcee | 381 | Dynamic_Elaboration_Checks := False; |
382 | ||
efa86d10 | 383 | -- Detect overflow on unconstrained floating-point types, such as |
384 | -- the predefined types Float, Long_Float and Long_Long_Float from | |
22d3a5a3 | 385 | -- package Standard. Not necessary if float overflows are checked |
386 | -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags | |
387 | -- will be set in any case. | |
efa86d10 | 388 | |
22d3a5a3 | 389 | Check_Float_Overflow := not Machine_Overflows_On_Target; |
efa86d10 | 390 | |
c412fcee | 391 | -- Set STRICT mode for overflow checks if not set explicitly. This |
392 | -- prevents suppressing of overflow checks by default, in code down | |
393 | -- below. | |
394 | ||
db415383 | 395 | if Suppress_Options.Overflow_Mode_General = Not_Set then |
396 | Suppress_Options.Overflow_Mode_General := Strict; | |
397 | Suppress_Options.Overflow_Mode_Assertions := Strict; | |
c412fcee | 398 | end if; |
399 | ||
400 | -- Kill debug of generated code, since it messes up sloc values | |
401 | ||
402 | Debug_Generated_Code := False; | |
403 | ||
404 | -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD) | |
405 | -- as it is needed for computing effects of subprograms in the formal | |
406 | -- verification backend. | |
407 | ||
408 | Xref_Active := True; | |
409 | ||
410 | -- Polling mode forced off, since it generates confusing junk | |
411 | ||
412 | Polling_Required := False; | |
413 | ||
c39cce40 | 414 | -- Set operating mode to Check_Semantics, but a light front-end |
415 | -- expansion is still performed. | |
c412fcee | 416 | |
c39cce40 | 417 | Operating_Mode := Check_Semantics; |
c412fcee | 418 | |
51ea9c94 | 419 | -- Enable assertions, since they give valuable extra information for |
420 | -- formal verification. | |
c412fcee | 421 | |
51ea9c94 | 422 | Assertions_Enabled := True; |
c412fcee | 423 | |
021bbd2b | 424 | -- Disable validity checks, since it generates code raising |
425 | -- exceptions for invalid data, which confuses GNATprove. Invalid | |
426 | -- data is directly detected by GNATprove's flow analysis. | |
427 | ||
428 | Validity_Checks_On := False; | |
429 | ||
c412fcee | 430 | -- Turn off style check options since we are not interested in any |
b4f636a7 | 431 | -- front-end warnings when we are getting SPARK output. |
c412fcee | 432 | |
433 | Reset_Style_Check_Options; | |
434 | ||
c412fcee | 435 | -- Suppress the generation of name tables for enumerations, which are |
b4f636a7 | 436 | -- not needed for formal verification, and fall outside the SPARK |
c412fcee | 437 | -- subset (use of pointers). |
438 | ||
439 | Global_Discard_Names := True; | |
440 | ||
441 | -- Suppress the expansion of tagged types and dispatching calls, | |
b4f636a7 | 442 | -- which lead to the generation of non-SPARK code (use of pointers), |
c412fcee | 443 | -- which is more complex to formally verify than the original source. |
444 | ||
445 | Tagged_Type_Expansion := False; | |
446 | end if; | |
447 | ||
ed3c9510 | 448 | -- Set Configurable_Run_Time mode if system.ads flag set or if the |
449 | -- special debug flag -gnatdY is set. | |
749c967d | 450 | |
451 | if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then | |
452 | Configurable_Run_Time_Mode := True; | |
453 | end if; | |
454 | ||
455 | -- Set -gnatR3m mode if debug flag A set | |
456 | ||
457 | if Debug_Flag_AA then | |
458 | Back_Annotate_Rep_Info := True; | |
459 | List_Representation_Info := 1; | |
460 | List_Representation_Info_Mechanisms := True; | |
461 | end if; | |
462 | ||
463 | -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set | |
464 | ||
465 | if Debug_Flag_Dot_A then | |
466 | Ttypes.Target_Strict_Alignment := True; | |
467 | end if; | |
468 | ||
9b8df6be | 469 | -- Increase size of allocated entities if debug flag -gnatd.N is set |
470 | ||
471 | if Debug_Flag_Dot_NN then | |
472 | Atree.Num_Extension_Nodes := Atree.Num_Extension_Nodes + 1; | |
473 | end if; | |
474 | ||
749c967d | 475 | -- Disable static allocation of dispatch tables if -gnatd.t or if layout |
476 | -- is enabled. The front end's layout phase currently treats types that | |
477 | -- have discriminant-dependent arrays as not being static even when a | |
478 | -- discriminant constraint on the type is static, and this leads to | |
479 | -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ??? | |
480 | ||
481 | if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then | |
482 | Static_Dispatch_Tables := False; | |
483 | end if; | |
484 | ||
485 | -- Flip endian mode if -gnatd8 set | |
486 | ||
487 | if Debug_Flag_8 then | |
488 | Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian; | |
489 | end if; | |
490 | ||
749c967d | 491 | -- Activate front end layout if debug flag -gnatdF is set |
492 | ||
493 | if Debug_Flag_FF then | |
494 | Targparm.Frontend_Layout_On_Target := True; | |
495 | end if; | |
496 | ||
6fb3c314 | 497 | -- Set and check exception mechanism |
749c967d | 498 | |
499 | if Targparm.ZCX_By_Default_On_Target then | |
3580dc54 | 500 | Exception_Mechanism := Back_End_Exceptions; |
749c967d | 501 | end if; |
502 | ||
0df9d43f | 503 | -- Set proper status for overflow check mechanism |
9ea61fdd | 504 | |
b4f636a7 | 505 | -- If already set (by -gnato or above in SPARK or CodePeer mode) then we |
c412fcee | 506 | -- have nothing to do. |
724d2bd8 | 507 | |
db415383 | 508 | if Opt.Suppress_Options.Overflow_Mode_General /= Not_Set then |
724d2bd8 | 509 | null; |
510 | ||
0df9d43f | 511 | -- Otherwise set overflow mode defaults |
9ea61fdd | 512 | |
0df9d43f | 513 | else |
e14a3829 | 514 | -- Overflow checks are on by default (Suppress set False) except in |
515 | -- GNAT_Mode, where we want them off by default (we are not ready to | |
516 | -- enable overflow checks in the compiler yet, for one thing the case | |
517 | -- of 64-bit checks needs System.Arith_64 which is not a compiler | |
518 | -- unit and it is a pain to try to include it in the compiler. | |
b6a8f264 | 519 | |
e14a3829 | 520 | Suppress_Options.Suppress (Overflow_Check) := GNAT_Mode; |
b6a8f264 | 521 | |
0df9d43f | 522 | -- Set appropriate default overflow handling mode. Note: at present |
523 | -- we set STRICT in all three of the following cases. They are | |
524 | -- separated because in the future we may make different choices. | |
724d2bd8 | 525 | |
0df9d43f | 526 | -- By default set STRICT mode if -gnatg in effect |
724d2bd8 | 527 | |
0df9d43f | 528 | if GNAT_Mode then |
db415383 | 529 | Suppress_Options.Overflow_Mode_General := Strict; |
530 | Suppress_Options.Overflow_Mode_Assertions := Strict; | |
724d2bd8 | 531 | |
0df9d43f | 532 | -- If we have backend divide and overflow checks, then by default |
533 | -- overflow checks are STRICT. Historically this code used to also | |
534 | -- activate overflow checks, although no target currently has these | |
535 | -- flags set, so this was dead code anyway. | |
536 | ||
537 | elsif Targparm.Backend_Divide_Checks_On_Target | |
e14a3829 | 538 | and |
539 | Targparm.Backend_Overflow_Checks_On_Target | |
0df9d43f | 540 | then |
db415383 | 541 | Suppress_Options.Overflow_Mode_General := Strict; |
542 | Suppress_Options.Overflow_Mode_Assertions := Strict; | |
0df9d43f | 543 | |
544 | -- Otherwise for now, default is STRICT mode. This may change in the | |
545 | -- future, but for now this is the compatible behavior with previous | |
546 | -- versions of GNAT. | |
547 | ||
548 | else | |
db415383 | 549 | Suppress_Options.Overflow_Mode_General := Strict; |
550 | Suppress_Options.Overflow_Mode_Assertions := Strict; | |
0df9d43f | 551 | end if; |
749c967d | 552 | end if; |
06e076c6 | 553 | |
50cab70b | 554 | -- Set default for atomic synchronization. As this synchronization |
555 | -- between atomic accesses can be expensive, and not typically needed | |
556 | -- on some targets, an optional target parameter can turn the option | |
557 | -- off. Note Atomic Synchronization is implemented as check. | |
558 | ||
fafc6b97 | 559 | Suppress_Options.Suppress (Atomic_Synchronization) := |
5ea6a4ea | 560 | not Atomic_Sync_Default_On_Target; |
50cab70b | 561 | |
c9e3ee19 | 562 | -- Set switch indicating if back end can handle limited types, and |
563 | -- guarantee that no incorrect copies are made (e.g. in the context | |
92f1631f | 564 | -- of an if or case expression). |
c9e3ee19 | 565 | |
566 | -- Debug flag -gnatd.L decisively sets usage on | |
567 | ||
e977c0cf | 568 | if Debug_Flag_Dot_LL then |
c9e3ee19 | 569 | Back_End_Handles_Limited_Types := True; |
570 | ||
571 | -- If no debug flag, usage off for AAMP, VM, SCIL cases | |
572 | ||
573 | elsif AAMP_On_Target | |
574 | or else VM_Target /= No_VM | |
575 | or else Generate_SCIL | |
576 | then | |
577 | Back_End_Handles_Limited_Types := False; | |
578 | ||
1f4c5ad8 | 579 | -- Otherwise normal gcc back end, for now still turn flag off by |
d8428da5 | 580 | -- default, since there are unresolved problems in the front end. |
c9e3ee19 | 581 | |
582 | else | |
583 | Back_End_Handles_Limited_Types := False; | |
584 | end if; | |
9c714f97 | 585 | |
6a8773aa | 586 | -- If the inlining level has not been set by the user, compute it from |
587 | -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above. | |
588 | ||
589 | if Inline_Level = 0 then | |
590 | if Optimization_Level < 3 then | |
591 | Inline_Level := 1; | |
592 | else | |
593 | Inline_Level := 2; | |
594 | end if; | |
595 | end if; | |
724d2bd8 | 596 | |
b94a633e | 597 | -- Treat -gnatn as equivalent to -gnatN for non-GCC targets |
598 | ||
3ad60f63 | 599 | if Inline_Active and not Front_End_Inlining then |
600 | ||
601 | -- We really should have a tag for this, what if we added a new | |
602 | -- back end some day, it would not be true for this test, but it | |
603 | -- would be non-GCC, so this is a bit troublesome ??? | |
604 | ||
b94a633e | 605 | Front_End_Inlining := VM_Target /= No_VM or else AAMP_On_Target; |
606 | end if; | |
607 | ||
3296750c | 608 | -- Set back end inlining indication |
9fac98bb | 609 | |
610 | Back_End_Inlining := | |
3296750c | 611 | |
612 | -- No back end inlining available for VM targets | |
613 | ||
c918b5ca | 614 | VM_Target = No_VM |
3296750c | 615 | |
616 | -- No back end inlining available on AAMP | |
617 | ||
618 | and then not AAMP_On_Target | |
619 | ||
620 | -- No back end inlining in GNATprove mode, since it just confuses | |
621 | -- the formal verification process. | |
622 | ||
623 | and then not GNATprove_Mode | |
624 | ||
e173b833 | 625 | -- No back end inlining if front end inlining explicitly enabled. |
626 | -- Done to minimize the output differences to customers still using | |
627 | -- this deprecated switch; in addition, this behavior reduces the | |
628 | -- output differences in old tests. | |
3296750c | 629 | |
630 | and then not Front_End_Inlining | |
631 | ||
e173b833 | 632 | -- Back end inlining is disabled if debug flag .z is set |
3296750c | 633 | |
e173b833 | 634 | and then not Debug_Flag_Dot_Z; |
9fac98bb | 635 | |
ed3c9510 | 636 | -- Output warning if -gnateE specified and cannot be supported |
637 | ||
638 | if Exception_Extra_Info | |
639 | and then Restrict.No_Exception_Handlers_Set | |
640 | then | |
641 | Set_Standard_Error; | |
642 | Write_Str | |
643 | ("warning: extra exception information (-gnateE) was specified"); | |
644 | Write_Eol; | |
645 | Write_Str | |
646 | ("warning: this capability is not available in this configuration"); | |
647 | Write_Eol; | |
648 | Set_Standard_Output; | |
649 | end if; | |
650 | ||
724d2bd8 | 651 | -- Finally capture adjusted value of Suppress_Options as the initial |
652 | -- value for Scope_Suppress, which will be modified as we move from | |
653 | -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas). | |
654 | ||
655 | Sem.Scope_Suppress := Opt.Suppress_Options; | |
749c967d | 656 | end Adjust_Global_Switches; |
657 | ||
10084566 | 658 | -------------------- |
659 | -- Check_Bad_Body -- | |
660 | -------------------- | |
661 | ||
662 | procedure Check_Bad_Body is | |
663 | Sname : Unit_Name_Type; | |
664 | Src_Ind : Source_File_Index; | |
665 | Fname : File_Name_Type; | |
666 | ||
667 | procedure Bad_Body_Error (Msg : String); | |
668 | -- Issue message for bad body found | |
669 | ||
670 | -------------------- | |
671 | -- Bad_Body_Error -- | |
672 | -------------------- | |
673 | ||
674 | procedure Bad_Body_Error (Msg : String) is | |
675 | begin | |
676 | Error_Msg_N (Msg, Main_Unit_Node); | |
677 | Error_Msg_File_1 := Fname; | |
678 | Error_Msg_N ("remove incorrect body in file{!", Main_Unit_Node); | |
679 | end Bad_Body_Error; | |
680 | ||
64427fe6 | 681 | -- Start of processing for Check_Bad_Body |
10084566 | 682 | |
683 | begin | |
684 | -- Nothing to do if we are only checking syntax, because we don't know | |
685 | -- enough to know if we require or forbid a body in this case. | |
686 | ||
687 | if Operating_Mode = Check_Syntax then | |
688 | return; | |
689 | end if; | |
690 | ||
691 | -- Check for body not allowed | |
692 | ||
693 | if (Main_Kind = N_Package_Declaration | |
694 | and then not Body_Required (Main_Unit_Node)) | |
695 | or else (Main_Kind = N_Generic_Package_Declaration | |
696 | and then not Body_Required (Main_Unit_Node)) | |
697 | or else Main_Kind = N_Package_Renaming_Declaration | |
698 | or else Main_Kind = N_Subprogram_Renaming_Declaration | |
699 | or else Nkind (Original_Node (Unit (Main_Unit_Node))) | |
700 | in N_Generic_Instantiation | |
701 | then | |
702 | Sname := Unit_Name (Main_Unit); | |
703 | ||
704 | -- If we do not already have a body name, then get the body name | |
10084566 | 705 | |
706 | if not Is_Body_Name (Sname) then | |
707 | Sname := Get_Body_Name (Sname); | |
708 | end if; | |
709 | ||
710 | Fname := Get_File_Name (Sname, Subunit => False); | |
711 | Src_Ind := Load_Source_File (Fname); | |
712 | ||
69a5377d | 713 | -- Case where body is present and it is not a subunit. Exclude the |
714 | -- subunit case, because it has nothing to do with the package we are | |
715 | -- compiling. It is illegal for a child unit and a subunit with the | |
716 | -- same expanded name (RM 10.2(9)) to appear together in a partition, | |
717 | -- but there is nothing to stop a compilation environment from having | |
718 | -- both, and the test here simply allows that. If there is an attempt | |
719 | -- to include both in a partition, this is diagnosed at bind time. In | |
720 | -- Ada 83 mode this is not a warning case. | |
721 | ||
f37968de | 722 | -- Note that in general we do not give the message if the file in |
723 | -- question does not look like a body. This includes weird cases, | |
724 | -- but in particular means that if the file is just a No_Body pragma, | |
725 | -- then we won't give the message (that's the whole point of this | |
726 | -- pragma, to be used this way and to cause the body file to be | |
727 | -- ignored in this context). | |
10084566 | 728 | |
729 | if Src_Ind /= No_Source_File | |
f37968de | 730 | and then Source_File_Is_Body (Src_Ind) |
10084566 | 731 | then |
150564b2 | 732 | Errout.Finalize (Last_Call => False); |
10084566 | 733 | |
734 | Error_Msg_Unit_1 := Sname; | |
735 | ||
736 | -- Ada 83 case of a package body being ignored. This is not an | |
737 | -- error as far as the Ada 83 RM is concerned, but it is almost | |
738 | -- certainly not what is wanted so output a warning. Give this | |
739 | -- message only if there were no errors, since otherwise it may | |
740 | -- be incorrect (we may have misinterpreted a junk spec as not | |
741 | -- needing a body when it really does). | |
742 | ||
743 | if Main_Kind = N_Package_Declaration | |
744 | and then Ada_Version = Ada_83 | |
745 | and then Operating_Mode = Generate_Code | |
746 | and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body | |
747 | and then not Compilation_Errors | |
748 | then | |
749 | Error_Msg_N | |
cb97ae5c | 750 | ("package $$ does not require a body??", Main_Unit_Node); |
10084566 | 751 | Error_Msg_File_1 := Fname; |
cb97ae5c | 752 | Error_Msg_N ("body in file{ will be ignored??", Main_Unit_Node); |
10084566 | 753 | |
754 | -- Ada 95 cases of a body file present when no body is | |
755 | -- permitted. This we consider to be an error. | |
756 | ||
757 | else | |
758 | -- For generic instantiations, we never allow a body | |
759 | ||
f37968de | 760 | if Nkind (Original_Node (Unit (Main_Unit_Node))) in |
761 | N_Generic_Instantiation | |
10084566 | 762 | then |
763 | Bad_Body_Error | |
764 | ("generic instantiation for $$ does not allow a body"); | |
765 | ||
766 | -- A library unit that is a renaming never allows a body | |
767 | ||
768 | elsif Main_Kind in N_Renaming_Declaration then | |
769 | Bad_Body_Error | |
770 | ("renaming declaration for $$ does not allow a body!"); | |
771 | ||
772 | -- Remaining cases are packages and generic packages. Here | |
773 | -- we only do the test if there are no previous errors, | |
774 | -- because if there are errors, they may lead us to | |
39a0c1d3 | 775 | -- incorrectly believe that a package does not allow a |
776 | -- body when in fact it does. | |
10084566 | 777 | |
778 | elsif not Compilation_Errors then | |
779 | if Main_Kind = N_Package_Declaration then | |
780 | Bad_Body_Error | |
781 | ("package $$ does not allow a body!"); | |
782 | ||
783 | elsif Main_Kind = N_Generic_Package_Declaration then | |
784 | Bad_Body_Error | |
785 | ("generic package $$ does not allow a body!"); | |
786 | end if; | |
787 | end if; | |
788 | ||
789 | end if; | |
790 | end if; | |
791 | end if; | |
792 | end Check_Bad_Body; | |
793 | ||
ed195555 | 794 | -------------------- |
795 | -- Check_Rep_Info -- | |
796 | -------------------- | |
797 | ||
798 | procedure Check_Rep_Info is | |
799 | begin | |
800 | if List_Representation_Info /= 0 | |
801 | or else List_Representation_Info_Mechanisms | |
802 | then | |
803 | Set_Standard_Error; | |
804 | Write_Eol; | |
805 | Write_Str | |
806 | ("cannot generate representation information, no code generated"); | |
807 | Write_Eol; | |
808 | Write_Eol; | |
809 | Set_Standard_Output; | |
810 | end if; | |
811 | end Check_Rep_Info; | |
812 | ||
7b8fa048 | 813 | ---------------------------------------- |
814 | -- Post_Compilation_Validation_Checks -- | |
815 | ---------------------------------------- | |
816 | ||
817 | procedure Post_Compilation_Validation_Checks is | |
818 | begin | |
819 | -- Validate alignment check warnings. In some cases we generate warnings | |
820 | -- about possible alignment errors because we don't know the alignment | |
821 | -- that will be chosen by the back end. This routine is in charge of | |
822 | -- getting rid of those warnings if we can tell they are not needed. | |
823 | ||
824 | Checks.Validate_Alignment_Check_Warnings; | |
825 | ||
826 | -- Validate unchecked conversions (using the values for size and | |
827 | -- alignment annotated by the backend where possible). | |
828 | ||
829 | Sem_Ch13.Validate_Unchecked_Conversions; | |
830 | ||
831 | -- Validate address clauses (again using alignment values annotated | |
832 | -- by the backend where possible). | |
833 | ||
834 | Sem_Ch13.Validate_Address_Clauses; | |
835 | ||
dba38d2f | 836 | -- Validate independence pragmas (again using values annotated by the |
837 | -- back end for component layout where possible) but only for non-GCC | |
838 | -- back ends, as this is done a priori for GCC back ends. | |
839 | ||
840 | if VM_Target /= No_VM or else AAMP_On_Target then | |
841 | Sem_Ch13.Validate_Independence; | |
842 | end if; | |
7b8fa048 | 843 | |
7b8fa048 | 844 | end Post_Compilation_Validation_Checks; |
845 | ||
10084566 | 846 | -- Start of processing for Gnat1drv |
847 | ||
83cce46b | 848 | begin |
849 | -- This inner block is set up to catch assertion errors and constraint | |
850 | -- errors. Since the code for handling these errors can cause another | |
851 | -- exception to be raised (namely Unrecoverable_Error), we need two | |
852 | -- nested blocks, so that the outer one handles unrecoverable error. | |
853 | ||
854 | begin | |
11b376d2 | 855 | -- Initialize all packages. For the most part, these initialization |
856 | -- calls can be made in any order. Exceptions are as follows: | |
857 | ||
f15731c4 | 858 | -- Lib.Initialize need to be called before Scan_Compiler_Arguments, |
10084566 | 859 | -- because it initializes a table filled by Scan_Compiler_Arguments. |
f15731c4 | 860 | |
9dfe12ae | 861 | Osint.Initialize; |
862 | Fmap.Reset_Tables; | |
f15731c4 | 863 | Lib.Initialize; |
9dfe12ae | 864 | Lib.Xref.Initialize; |
83cce46b | 865 | Scan_Compiler_Arguments; |
866 | Osint.Add_Default_Search_Dirs; | |
d10a989c | 867 | Atree.Initialize; |
9dfe12ae | 868 | Nlists.Initialize; |
83cce46b | 869 | Sinput.Initialize; |
83cce46b | 870 | Sem.Initialize; |
e00e091c | 871 | Exp_CG.Initialize; |
83cce46b | 872 | Csets.Initialize; |
873 | Uintp.Initialize; | |
874 | Urealp.Initialize; | |
875 | Errout.Initialize; | |
a9958373 | 876 | SCOs.Initialize; |
83cce46b | 877 | Snames.Initialize; |
878 | Stringt.Initialize; | |
360b005f | 879 | Ghost.Initialize; |
83cce46b | 880 | Inline.Initialize; |
11b376d2 | 881 | Par_SCO.Initialize; |
9dfe12ae | 882 | Sem_Ch8.Initialize; |
883 | Sem_Ch12.Initialize; | |
83cce46b | 884 | Sem_Ch13.Initialize; |
e7b2d6bc | 885 | Sem_Elim.Initialize; |
9dfe12ae | 886 | Sem_Eval.Initialize; |
887 | Sem_Type.Init_Interp_Tables; | |
888 | ||
82b93248 | 889 | -- Capture compilation date and time |
890 | ||
891 | Opt.Compilation_Time := System.OS_Lib.Current_Time_String; | |
892 | ||
3b514396 | 893 | -- Get the target parameters only when -gnats is not used, to avoid |
894 | -- failing when there is no default runtime. | |
9dfe12ae | 895 | |
3b514396 | 896 | if Operating_Mode /= Check_Syntax then |
9dfe12ae | 897 | |
3b514396 | 898 | -- Acquire target parameters from system.ads (package System source) |
9dfe12ae | 899 | |
3b514396 | 900 | Targparm_Acquire : declare |
901 | use Sinput; | |
9dfe12ae | 902 | |
3b514396 | 903 | S : Source_File_Index; |
904 | N : File_Name_Type; | |
9dfe12ae | 905 | |
3b514396 | 906 | begin |
907 | Name_Buffer (1 .. 10) := "system.ads"; | |
908 | Name_Len := 10; | |
909 | N := Name_Find; | |
910 | S := Load_Source_File (N); | |
9dfe12ae | 911 | |
3b514396 | 912 | -- Failed to read system.ads, fatal error |
83cce46b | 913 | |
3b514396 | 914 | if S = No_Source_File then |
915 | Write_Line | |
916 | ("fatal error, run-time library not installed correctly"); | |
917 | Write_Line ("cannot locate file system.ads"); | |
918 | raise Unrecoverable_Error; | |
f15731c4 | 919 | |
3b514396 | 920 | -- Read system.ads successfully, remember its source index |
921 | ||
922 | else | |
923 | System_Source_File_Index := S; | |
924 | end if; | |
f15731c4 | 925 | |
3b514396 | 926 | Targparm.Get_Target_Parameters |
927 | (System_Text => Source_Text (S), | |
928 | Source_First => Source_First (S), | |
929 | Source_Last => Source_Last (S), | |
930 | Make_Id => Tbuild.Make_Id'Access, | |
931 | Make_SC => Tbuild.Make_SC'Access, | |
932 | Set_RND => Tbuild.Set_RND'Access); | |
933 | ||
934 | -- Acquire configuration pragma information from Targparm | |
935 | ||
936 | Restrict.Restrictions := Targparm.Restrictions_On_Target; | |
937 | end Targparm_Acquire; | |
938 | end if; | |
d10a989c | 939 | |
940 | -- Perform various adjustments and settings of global switches | |
9dfe12ae | 941 | |
749c967d | 942 | Adjust_Global_Switches; |
150564b2 | 943 | |
3a838102 | 944 | -- Output copyright notice if full list mode unless we have a list |
3b514396 | 945 | -- file, in which case we defer this so that it is output in the file. |
83cce46b | 946 | |
10084566 | 947 | if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null)) |
3b514396 | 948 | |
949 | -- Debug flag gnatd7 suppresses this copyright notice | |
950 | ||
3a838102 | 951 | and then not Debug_Flag_7 |
83cce46b | 952 | then |
953 | Write_Eol; | |
954 | Write_Str ("GNAT "); | |
f15731c4 | 955 | Write_Str (Gnat_Version_String); |
57335d69 | 956 | Write_Eol; |
64427fe6 | 957 | Write_Str ("Copyright 1992-" & Current_Year |
958 | & ", Free Software Foundation, Inc."); | |
f15731c4 | 959 | Write_Eol; |
83cce46b | 960 | end if; |
961 | ||
10084566 | 962 | -- Check we do not have more than one source file, this happens only in |
963 | -- the case where the driver is called directly, it cannot happen when | |
964 | -- gnat1 is invoked from gcc in the normal case. | |
83cce46b | 965 | |
966 | if Osint.Number_Of_Files /= 1 then | |
967 | Usage; | |
968 | Write_Eol; | |
969 | Osint.Fail ("you must provide one source file"); | |
970 | ||
971 | elsif Usage_Requested then | |
972 | Usage; | |
973 | end if; | |
974 | ||
cba2ae82 | 975 | -- Generate target dependent output file if requested |
976 | ||
5462ac01 | 977 | if Target_Dependent_Info_Write_Name /= null then |
cba2ae82 | 978 | Set_Targ.Write_Target_Dependent_Values; |
979 | end if; | |
980 | ||
981 | -- Call the front end | |
982 | ||
83cce46b | 983 | Original_Operating_Mode := Operating_Mode; |
984 | Frontend; | |
83cce46b | 985 | |
f957a8af | 986 | -- Exit with errors if the main source could not be parsed. |
afc48770 | 987 | |
10084566 | 988 | if Sinput.Main_Source_File = No_Source_File then |
150564b2 | 989 | Errout.Finalize (Last_Call => True); |
10084566 | 990 | Errout.Output_Messages; |
991 | Exit_Program (E_Errors); | |
83cce46b | 992 | end if; |
993 | ||
10084566 | 994 | Main_Unit_Node := Cunit (Main_Unit); |
995 | Main_Kind := Nkind (Unit (Main_Unit_Node)); | |
996 | Check_Bad_Body; | |
997 | ||
43d776b7 | 998 | -- In CodePeer mode we always delete old SCIL files before regenerating |
999 | -- new ones, in case of e.g. errors, and also to remove obsolete scilx | |
1000 | -- files generated by CodePeer itself. | |
1001 | ||
1002 | if CodePeer_Mode then | |
1003 | Comperr.Delete_SCIL_Files; | |
1004 | end if; | |
1005 | ||
83cce46b | 1006 | -- Exit if compilation errors detected |
1007 | ||
150564b2 | 1008 | Errout.Finalize (Last_Call => False); |
10084566 | 1009 | |
83cce46b | 1010 | if Compilation_Errors then |
1011 | Treepr.Tree_Dump; | |
7b8fa048 | 1012 | Post_Compilation_Validation_Checks; |
10084566 | 1013 | Errout.Output_Messages; |
83cce46b | 1014 | Namet.Finalize; |
1015 | ||
1016 | -- Generate ALI file if specially requested | |
1017 | ||
1018 | if Opt.Force_ALI_Tree_File then | |
1019 | Write_ALI (Object => False); | |
1020 | Tree_Gen; | |
1021 | end if; | |
1022 | ||
150564b2 | 1023 | Errout.Finalize (Last_Call => True); |
83cce46b | 1024 | Exit_Program (E_Errors); |
1025 | end if; | |
1026 | ||
57304b2b | 1027 | -- Set Generate_Code on main unit and its spec. We do this even if are |
1028 | -- not generating code, since Lib-Writ uses this to determine which | |
1029 | -- units get written in the ali file. | |
83cce46b | 1030 | |
1031 | Set_Generate_Code (Main_Unit); | |
1032 | ||
64427fe6 | 1033 | -- If we have a corresponding spec, and it comes from source or it is |
1034 | -- not a generated spec for a child subprogram body, then we need object | |
1035 | -- code for the spec unit as well. | |
83cce46b | 1036 | |
1037 | if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body | |
1038 | and then not Acts_As_Spec (Main_Unit_Node) | |
1039 | then | |
035e891d | 1040 | if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body |
db317bdb | 1041 | and then not Comes_From_Source (Library_Unit (Main_Unit_Node)) |
1042 | then | |
1043 | null; | |
1044 | else | |
1045 | Set_Generate_Code | |
1046 | (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node))); | |
1047 | end if; | |
83cce46b | 1048 | end if; |
1049 | ||
83cce46b | 1050 | -- Case of no code required to be generated, exit indicating no error |
1051 | ||
1052 | if Original_Operating_Mode = Check_Syntax then | |
1053 | Treepr.Tree_Dump; | |
150564b2 | 1054 | Errout.Finalize (Last_Call => True); |
10084566 | 1055 | Errout.Output_Messages; |
83cce46b | 1056 | Tree_Gen; |
1057 | Namet.Finalize; | |
10084566 | 1058 | Check_Rep_Info; |
8c9f4284 | 1059 | |
1060 | -- Use a goto instead of calling Exit_Program so that finalization | |
1061 | -- occurs normally. | |
1062 | ||
1063 | goto End_Of_Program; | |
83cce46b | 1064 | |
1065 | elsif Original_Operating_Mode = Check_Semantics then | |
1066 | Back_End_Mode := Declarations_Only; | |
1067 | ||
1068 | -- All remaining cases are cases in which the user requested that code | |
64427fe6 | 1069 | -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we |
1070 | -- can in fact satisfy this request. | |
83cce46b | 1071 | |
57304b2b | 1072 | -- Cannot generate code if someone has turned off code generation for |
1073 | -- any reason at all. We will try to figure out a reason below. | |
83cce46b | 1074 | |
1075 | elsif Operating_Mode /= Generate_Code then | |
1076 | Back_End_Mode := Skip; | |
1077 | ||
57304b2b | 1078 | -- We can generate code for a subprogram body unless there were missing |
1079 | -- subunits. Note that we always generate code for all generic units (a | |
1080 | -- change from some previous versions of GNAT). | |
83cce46b | 1081 | |
69a5377d | 1082 | elsif Main_Kind = N_Subprogram_Body and then not Subunits_Missing then |
83cce46b | 1083 | Back_End_Mode := Generate_Object; |
1084 | ||
9dfe12ae | 1085 | -- We can generate code for a package body unless there are subunits |
1086 | -- missing (note that we always generate code for generic units, which | |
1087 | -- is a change from some earlier versions of GNAT). | |
83cce46b | 1088 | |
69a5377d | 1089 | elsif Main_Kind = N_Package_Body and then not Subunits_Missing then |
83cce46b | 1090 | Back_End_Mode := Generate_Object; |
1091 | ||
1092 | -- We can generate code for a package declaration or a subprogram | |
1093 | -- declaration only if it does not required a body. | |
1094 | ||
64427fe6 | 1095 | elsif Nkind_In (Main_Kind, |
1096 | N_Package_Declaration, | |
1097 | N_Subprogram_Declaration) | |
83cce46b | 1098 | and then |
1099 | (not Body_Required (Main_Unit_Node) | |
1100 | or else | |
1101 | Distribution_Stub_Mode = Generate_Caller_Stub_Body) | |
1102 | then | |
1103 | Back_End_Mode := Generate_Object; | |
1104 | ||
1105 | -- We can generate code for a generic package declaration of a generic | |
9dfe12ae | 1106 | -- subprogram declaration only if does not require a body. |
83cce46b | 1107 | |
e8a30fc0 | 1108 | elsif Nkind_In (Main_Kind, N_Generic_Package_Declaration, |
1109 | N_Generic_Subprogram_Declaration) | |
83cce46b | 1110 | and then not Body_Required (Main_Unit_Node) |
83cce46b | 1111 | then |
1112 | Back_End_Mode := Generate_Object; | |
1113 | ||
64427fe6 | 1114 | -- Compilation units that are renamings do not require bodies, so we can |
1115 | -- generate code for them. | |
83cce46b | 1116 | |
e8a30fc0 | 1117 | elsif Nkind_In (Main_Kind, N_Package_Renaming_Declaration, |
1118 | N_Subprogram_Renaming_Declaration) | |
83cce46b | 1119 | then |
1120 | Back_End_Mode := Generate_Object; | |
1121 | ||
1122 | -- Compilation units that are generic renamings do not require bodies | |
9dfe12ae | 1123 | -- so we can generate code for them. |
83cce46b | 1124 | |
9dfe12ae | 1125 | elsif Main_Kind in N_Generic_Renaming_Declaration then |
83cce46b | 1126 | Back_End_Mode := Generate_Object; |
1127 | ||
6f0d10f7 | 1128 | -- It is not an error to analyze in CodePeer mode a spec which requires |
1129 | -- a body, in order to generate SCIL for this spec. | |
040277b1 | 1130 | |
6f0d10f7 | 1131 | elsif CodePeer_Mode then |
040277b1 | 1132 | Back_End_Mode := Generate_Object; |
1133 | ||
c39cce40 | 1134 | -- It is not an error to analyze in GNATprove mode a spec which requires |
1135 | -- a body, when the body is not available. During frame condition | |
6f0d10f7 | 1136 | -- generation, the corresponding ALI file is generated. During |
13fa5c6a | 1137 | -- analysis, the spec is analyzed. |
6f0d10f7 | 1138 | |
c39cce40 | 1139 | elsif GNATprove_Mode then |
1140 | Back_End_Mode := Declarations_Only; | |
6f0d10f7 | 1141 | |
83cce46b | 1142 | -- In all other cases (specs which have bodies, generics, and bodies |
1143 | -- where subunits are missing), we cannot generate code and we generate | |
1144 | -- a warning message. Note that generic instantiations are gone at this | |
1145 | -- stage since they have been replaced by their instances. | |
1146 | ||
1147 | else | |
1148 | Back_End_Mode := Skip; | |
1149 | end if; | |
1150 | ||
f38c8084 | 1151 | -- At this stage Back_End_Mode is set to indicate if the backend should |
1152 | -- be called to generate code. If it is Skip, then code generation has | |
1153 | -- been turned off, even though code was requested by the original | |
57304b2b | 1154 | -- command. This is not an error from the user point of view, but it is |
1155 | -- an error from the point of view of the gcc driver, so we must exit | |
1156 | -- with an error status. | |
83cce46b | 1157 | |
57304b2b | 1158 | -- We generate an informative message (from the gcc point of view, it |
1159 | -- is an error message, but from the users point of view this is not an | |
1160 | -- error, just a consequence of compiling something that cannot | |
1161 | -- generate code). | |
83cce46b | 1162 | |
1163 | if Back_End_Mode = Skip then | |
c65510c1 | 1164 | Set_Standard_Error; |
9dfe12ae | 1165 | Write_Str ("cannot generate code for "); |
83cce46b | 1166 | Write_Str ("file "); |
1167 | Write_Name (Unit_File_Name (Main_Unit)); | |
1168 | ||
1169 | if Subunits_Missing then | |
1170 | Write_Str (" (missing subunits)"); | |
9dfe12ae | 1171 | Write_Eol; |
83cce46b | 1172 | |
ebce244f | 1173 | -- Force generation of ALI file, for backward compatibility |
1174 | ||
1175 | Opt.Force_ALI_Tree_File := True; | |
1176 | ||
83cce46b | 1177 | elsif Main_Kind = N_Subunit then |
1178 | Write_Str (" (subunit)"); | |
9dfe12ae | 1179 | Write_Eol; |
83cce46b | 1180 | |
ebce244f | 1181 | -- Force generation of ALI file, for backward compatibility |
1182 | ||
1183 | Opt.Force_ALI_Tree_File := True; | |
1184 | ||
83cce46b | 1185 | elsif Main_Kind = N_Subprogram_Declaration then |
1186 | Write_Str (" (subprogram spec)"); | |
9dfe12ae | 1187 | Write_Eol; |
9dfe12ae | 1188 | |
1189 | -- Generic package body in GNAT implementation mode | |
1190 | ||
1191 | elsif Main_Kind = N_Package_Body and then GNAT_Mode then | |
1192 | Write_Str (" (predefined generic)"); | |
1193 | Write_Eol; | |
83cce46b | 1194 | |
ebce244f | 1195 | -- Force generation of ALI file, for backward compatibility |
1196 | ||
1197 | Opt.Force_ALI_Tree_File := True; | |
1198 | ||
83cce46b | 1199 | -- Only other case is a package spec |
1200 | ||
1201 | else | |
1202 | Write_Str (" (package spec)"); | |
9dfe12ae | 1203 | Write_Eol; |
9dfe12ae | 1204 | end if; |
1205 | ||
c65510c1 | 1206 | Set_Standard_Output; |
83cce46b | 1207 | |
7b8fa048 | 1208 | Post_Compilation_Validation_Checks; |
150564b2 | 1209 | Errout.Finalize (Last_Call => True); |
10084566 | 1210 | Errout.Output_Messages; |
83cce46b | 1211 | Treepr.Tree_Dump; |
1212 | Tree_Gen; | |
ebce244f | 1213 | |
1214 | -- Generate ALI file if specially requested, or for missing subunits, | |
1215 | -- subunits or predefined generic. | |
1216 | ||
1217 | if Opt.Force_ALI_Tree_File then | |
1218 | Write_ALI (Object => False); | |
1219 | end if; | |
1220 | ||
83cce46b | 1221 | Namet.Finalize; |
10084566 | 1222 | Check_Rep_Info; |
83cce46b | 1223 | |
1224 | -- Exit program with error indication, to kill object file | |
1225 | ||
1226 | Exit_Program (E_No_Code); | |
1227 | end if; | |
1228 | ||
69a5377d | 1229 | -- In -gnatc mode, we only do annotation if -gnatt or -gnatR is also set |
1230 | -- as indicated by Back_Annotate_Rep_Info being set to True. | |
83cce46b | 1231 | |
1232 | -- We don't call for annotations on a subunit, because to process those | |
1233 | -- the back-end requires that the parent(s) be properly compiled. | |
1234 | ||
750b3003 | 1235 | -- Annotation is suppressed for targets where front-end layout is |
1236 | -- enabled, because the front end determines representations. | |
1237 | ||
69a5377d | 1238 | -- Annotation is also suppressed in the case of compiling for a VM, |
1239 | -- since representations are largely symbolic there. | |
83cce46b | 1240 | |
1241 | if Back_End_Mode = Declarations_Only | |
4098232e | 1242 | and then |
1243 | (not (Back_Annotate_Rep_Info or Generate_SCIL or GNATprove_Mode) | |
1244 | or else Main_Kind = N_Subunit | |
839dc3be | 1245 | or else Frontend_Layout_On_Target |
1246 | or else VM_Target /= No_VM) | |
83cce46b | 1247 | then |
7b8fa048 | 1248 | Post_Compilation_Validation_Checks; |
150564b2 | 1249 | Errout.Finalize (Last_Call => True); |
10084566 | 1250 | Errout.Output_Messages; |
83cce46b | 1251 | Write_ALI (Object => False); |
1252 | Tree_Dump; | |
1253 | Tree_Gen; | |
1254 | Namet.Finalize; | |
10084566 | 1255 | Check_Rep_Info; |
83cce46b | 1256 | return; |
1257 | end if; | |
1258 | ||
57304b2b | 1259 | -- Ensure that we properly register a dependency on system.ads, since |
1260 | -- even if we do not semantically depend on this, Targparm has read | |
1261 | -- system parameters from the system.ads file. | |
83cce46b | 1262 | |
1263 | Lib.Writ.Ensure_System_Dependency; | |
1264 | ||
9dfe12ae | 1265 | -- Add dependencies, if any, on preprocessing data file and on |
1266 | -- preprocessing definition file(s). | |
1267 | ||
1268 | Prepcomp.Add_Dependencies; | |
1269 | ||
c8a2d809 | 1270 | -- In gnatprove mode we're writing the ALI much earlier than usual |
1271 | -- as flow analysis needs the file present in order to append its | |
1272 | -- own globals to it. | |
1273 | ||
1274 | if GNATprove_Mode then | |
1275 | ||
1276 | -- Note: In GNATprove mode, an "object" file is always generated as | |
1277 | -- the result of calling gnat1 or gnat2why, although this is not the | |
1278 | -- same as the object file produced for compilation. | |
1279 | ||
1280 | Write_ALI (Object => True); | |
1281 | end if; | |
1282 | ||
a79fe0a3 | 1283 | -- Some back ends (for instance Gigi) are known to rely on SCOs for code |
1284 | -- generation. Make sure they are available. | |
1285 | ||
1286 | if Generate_SCO then | |
1287 | Par_SCO.SCO_Record_Filtered; | |
1288 | end if; | |
1289 | ||
83cce46b | 1290 | -- Back end needs to explicitly unlock tables it needs to touch |
1291 | ||
1292 | Atree.Lock; | |
1293 | Elists.Lock; | |
1294 | Fname.UF.Lock; | |
360b005f | 1295 | Ghost.Lock; |
83cce46b | 1296 | Inline.Lock; |
1297 | Lib.Lock; | |
360b005f | 1298 | Namet.Lock; |
83cce46b | 1299 | Nlists.Lock; |
1300 | Sem.Lock; | |
1301 | Sinput.Lock; | |
83cce46b | 1302 | Stringt.Lock; |
1303 | ||
9dfe12ae | 1304 | -- Here we call the back end to generate the output code |
83cce46b | 1305 | |
10084566 | 1306 | Generating_Code := True; |
83cce46b | 1307 | Back_End.Call_Back_End (Back_End_Mode); |
1308 | ||
57304b2b | 1309 | -- Once the backend is complete, we unlock the names table. This call |
1310 | -- allows a few extra entries, needed for example for the file name for | |
1311 | -- the library file output. | |
83cce46b | 1312 | |
1313 | Namet.Unlock; | |
1314 | ||
e00e091c | 1315 | -- Generate the call-graph output of dispatching calls |
1316 | ||
1317 | Exp_CG.Generate_CG_Output; | |
1318 | ||
7b8fa048 | 1319 | -- Perform post compilation validation checks |
83f8f0a6 | 1320 | |
7b8fa048 | 1321 | Post_Compilation_Validation_Checks; |
7717ea00 | 1322 | |
57304b2b | 1323 | -- Now we complete output of errors, rep info and the tree info. These |
1324 | -- are delayed till now, since it is perfectly possible for gigi to | |
1325 | -- generate errors, modify the tree (in particular by setting flags | |
1326 | -- indicating that elaboration is required, and also to back annotate | |
1327 | -- representation information for List_Rep_Info. | |
83cce46b | 1328 | |
150564b2 | 1329 | Errout.Finalize (Last_Call => True); |
10084566 | 1330 | Errout.Output_Messages; |
3a993333 | 1331 | List_Rep_Info (Ttypes.Bytes_Big_Endian); |
fc615d5c | 1332 | Inline.List_Inlining_Info; |
83cce46b | 1333 | |
1334 | -- Only write the library if the backend did not generate any error | |
1335 | -- messages. Otherwise signal errors to the driver program so that | |
1336 | -- there will be no attempt to generate an object file. | |
1337 | ||
1338 | if Compilation_Errors then | |
1339 | Treepr.Tree_Dump; | |
1340 | Exit_Program (E_Errors); | |
1341 | end if; | |
1342 | ||
c8a2d809 | 1343 | if not GNATprove_Mode then |
1344 | Write_ALI (Object => (Back_End_Mode = Generate_Object)); | |
1345 | end if; | |
83cce46b | 1346 | |
8db090bd | 1347 | if not Compilation_Errors then |
0cafb066 | 1348 | |
8db090bd | 1349 | -- In case of ada backends, we need to make sure that the generated |
0cafb066 | 1350 | -- object file has a timestamp greater than the ALI file. We do this |
1351 | -- to make gnatmake happy when checking the ALI and obj timestamps, | |
1352 | -- where it expects the object file being written after the ali file. | |
1353 | ||
8db090bd | 1354 | -- Gnatmake's assumption is true for gcc platforms where the gcc |
1355 | -- wrapper needs to call the assembler after calling gnat1, but is | |
1356 | -- not true for ada backends, where the object files are created | |
1357 | -- directly by gnat1 (so are created before the ali file). | |
0cafb066 | 1358 | |
8db090bd | 1359 | Back_End.Gen_Or_Update_Object_File; |
1360 | end if; | |
1361 | ||
69a5377d | 1362 | -- Generate ASIS tree after writing the ALI file, since in ASIS mode, |
1363 | -- Write_ALI may in fact result in further tree decoration from the | |
1364 | -- original tree file. Note that we dump the tree just before generating | |
1365 | -- it, so that the dump will exactly reflect what is written out. | |
83cce46b | 1366 | |
1367 | Treepr.Tree_Dump; | |
1368 | Tree_Gen; | |
1369 | ||
1370 | -- Finalize name table and we are all done | |
1371 | ||
1372 | Namet.Finalize; | |
1373 | ||
1374 | exception | |
1375 | -- Handle fatal internal compiler errors | |
1376 | ||
10084566 | 1377 | when Rtsfind.RE_Not_Available => |
1378 | Comperr.Compiler_Abort ("RE_Not_Available"); | |
1379 | ||
83cce46b | 1380 | when System.Assertions.Assert_Failure => |
1381 | Comperr.Compiler_Abort ("Assert_Failure"); | |
1382 | ||
1383 | when Constraint_Error => | |
1384 | Comperr.Compiler_Abort ("Constraint_Error"); | |
1385 | ||
1386 | when Program_Error => | |
1387 | Comperr.Compiler_Abort ("Program_Error"); | |
1388 | ||
1389 | when Storage_Error => | |
1390 | ||
57304b2b | 1391 | -- Assume this is a bug. If it is real, the message will in any case |
39a0c1d3 | 1392 | -- say Storage_Error, giving a strong hint. |
83cce46b | 1393 | |
1394 | Comperr.Compiler_Abort ("Storage_Error"); | |
1395 | end; | |
1396 | ||
8c9f4284 | 1397 | <<End_Of_Program>> |
1398 | null; | |
1399 | ||
1400 | -- The outer exception handles an unrecoverable error | |
83cce46b | 1401 | |
1402 | exception | |
1403 | when Unrecoverable_Error => | |
150564b2 | 1404 | Errout.Finalize (Last_Call => True); |
10084566 | 1405 | Errout.Output_Messages; |
83cce46b | 1406 | |
1407 | Set_Standard_Error; | |
1408 | Write_Str ("compilation abandoned"); | |
1409 | Write_Eol; | |
1410 | ||
1411 | Set_Standard_Output; | |
1412 | Source_Dump; | |
1413 | Tree_Dump; | |
1414 | Exit_Program (E_Errors); | |
1415 | ||
1416 | end Gnat1drv; |