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