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