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