libstdc++: Fix find_last_set(simd_mask) to ignore padding bits
[official-gcc.git] / gcc / ada / gnat1drv.adb
blob9743dfd4c4c90a1174a8d55c8ad8647444d1787a
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-2024, 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;
54 with Repinfo.Input;
55 with Restrict;
56 with Rident; use Rident;
57 with Rtsfind;
58 with SCOs;
59 with Sem;
60 with Sem_Ch8;
61 with Sem_Ch12;
62 with Sem_Ch13;
63 with Sem_Elim;
64 with Sem_Eval;
65 with Sem_Prag;
66 with Sem_Type;
67 with Set_Targ;
68 with Sinfo; use Sinfo;
69 with Sinfo.Nodes; use Sinfo.Nodes;
70 with Sinput; use Sinput;
71 with Sinput.L; use Sinput.L;
72 with Snames; use Snames;
73 with Sprint; use Sprint;
74 with Stringt;
75 with Stylesw; use Stylesw;
76 with Targparm; use Targparm;
77 with Tbuild;
78 with Treepr; use Treepr;
79 with Ttypes;
80 with Types; use Types;
81 with Uintp;
82 with Uname; use Uname;
83 with Urealp;
84 with Usage;
85 with Validsw; use Validsw;
86 with Warnsw; use Warnsw;
88 with System.Assertions;
89 with System.OS_Lib;
91 --------------
92 -- Gnat1drv --
93 --------------
95 procedure Gnat1drv is
96 procedure Adjust_Global_Switches;
97 -- There are various interactions between front-end switch settings,
98 -- including debug switch settings and target dependent parameters.
99 -- This procedure takes care of properly handling these interactions.
100 -- We do it after scanning out all the switches, so that we are not
101 -- depending on the order in which switches appear.
103 procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind);
104 -- Called to check whether a unit described by its compilation unit node
105 -- and kind has a bad body.
107 procedure Check_Rep_Info;
108 -- Called when we are not generating code, to check if -gnatR was requested
109 -- and if so, explain that we will not be honoring the request.
111 procedure Post_Compilation_Validation_Checks;
112 -- This procedure performs various validation checks that have to be left
113 -- to the end of the compilation process, after generating code but before
114 -- issuing error messages. In particular, these checks generally require
115 -- the information provided by the back end in back annotation of declared
116 -- entities (e.g. actual size and alignment values chosen by the back end).
118 procedure Read_JSON_Files_For_Repinfo;
119 -- This procedure exercises the JSON parser of Repinfo by reading back the
120 -- JSON files generated by -gnatRjs in a previous compilation session. It
121 -- is intended to make sure that the JSON generator and the JSON parser are
122 -- kept synchronized when the JSON format evolves.
124 ----------------------------
125 -- Adjust_Global_Switches --
126 ----------------------------
128 procedure Adjust_Global_Switches is
129 procedure SPARK_Library_Warning (Kind : String);
130 -- Issue a warning in GNATprove mode if the run-time library does not
131 -- fully support IEEE-754 floating-point semantics.
133 ---------------------------
134 -- SPARK_Library_Warning --
135 ---------------------------
137 procedure SPARK_Library_Warning (Kind : String) is
138 begin
139 Write_Line
140 ("warning: run-time library may be configured incorrectly");
141 Write_Line
142 ("warning: (SPARK analysis requires support for " & Kind & ')');
143 end SPARK_Library_Warning;
145 -- Start of processing for Adjust_Global_Switches
147 begin
149 -- -gnatd_U disables prepending error messages with "error:"
151 if Debug_Flag_Underscore_UU then
152 Unique_Error_Tag := False;
153 end if;
155 -- -gnatd.M enables Relaxed_RM_Semantics
157 if Debug_Flag_Dot_MM then
158 Relaxed_RM_Semantics := True;
159 end if;
161 -- -gnatd.1 enables unnesting of subprograms
163 if Debug_Flag_Dot_1 then
164 Unnest_Subprogram_Mode := True;
165 end if;
167 -- -gnatd.u enables special C expansion mode
169 if Debug_Flag_Dot_U then
170 Modify_Tree_For_C := True;
171 Transform_Function_Array := True;
172 end if;
174 -- -gnatd_A disables generation of ALI files
176 if Debug_Flag_Underscore_AA then
177 Disable_ALI_File := True;
178 end if;
180 -- Set all flags required when generating C code
182 if Generate_C_Code then
183 CCG_Mode := True;
184 Modify_Tree_For_C := True;
185 Transform_Function_Array := True;
186 Unnest_Subprogram_Mode := True;
187 Building_Static_Dispatch_Tables := False;
188 Minimize_Expression_With_Actions := True;
189 Expand_Nonbinary_Modular_Ops := True;
190 Back_End_Return_Slot := False;
192 -- Set operating mode to Generate_Code to benefit from full front-end
193 -- expansion (e.g. generics).
195 Operating_Mode := Generate_Code;
197 -- Suppress alignment checks since we do not have access to alignment
198 -- info on the target.
200 Suppress_Options.Suppress (Alignment_Check) := False;
201 end if;
203 -- -gnatd.E sets Error_To_Warning mode, causing selected error messages
204 -- to be treated as warnings instead of errors.
206 if Debug_Flag_Dot_EE then
207 Error_To_Warning := True;
208 end if;
210 -- Disable CodePeer_Mode in Check_Syntax, since we need front-end
211 -- expansion.
213 if Operating_Mode = Check_Syntax then
214 CodePeer_Mode := False;
215 end if;
217 -- SCIL mode needs to disable front-end inlining since the generated
218 -- trees (in particular order and consistency between specs compiled
219 -- as part of a main unit or as part of a with-clause) are causing
220 -- troubles.
222 if Generate_SCIL then
223 Front_End_Inlining := False;
224 end if;
226 -- Tune settings for optimal SCIL generation in CodePeer mode
228 if CodePeer_Mode then
230 -- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
231 -- compatible with CodePeer mode.
233 GNATprove_Mode := False;
234 Debug_Flag_Dot_FF := False;
236 -- Turn off length expansion. CodePeer has its own mechanism to
237 -- handle length attribute.
239 Debug_Flag_Dot_PP := True;
241 -- Turn off C tree generation, not compatible with CodePeer mode. We
242 -- do not expect this to happen in normal use, since both modes are
243 -- enabled by special tools, but it is useful to turn off these flags
244 -- this way when we are doing CodePeer tests on existing test suites
245 -- that may have -gnateg set, to avoid the need for special casing.
247 Modify_Tree_For_C := False;
248 Transform_Function_Array := False;
249 Generate_C_Code := False;
250 Unnest_Subprogram_Mode := False;
252 -- Turn off inlining, confuses CodePeer output and gains nothing
254 Front_End_Inlining := False;
255 Inline_Active := False;
257 -- Disable front-end optimizations, to keep the tree as close to the
258 -- source code as possible, and also to avoid inconsistencies between
259 -- trees when using different optimization switches.
261 Optimization_Level := 0;
263 -- Enable some restrictions systematically to simplify the generated
264 -- code (and ease analysis). Note that restriction checks are also
265 -- disabled in CodePeer mode, see Restrict.Check_Restriction, and
266 -- user specified Restrictions pragmas are ignored, see
267 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
269 Restrict.Restrictions.Set (No_Exception_Registration) := True;
270 Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
271 Restrict.Restrictions.Set (No_Task_Hierarchy) := True;
272 Restrict.Restrictions.Set (No_Abort_Statements) := True;
273 Restrict.Restrictions.Set (Max_Asynchronous_Select_Nesting) := True;
274 Restrict.Restrictions.Value (Max_Asynchronous_Select_Nesting) := 0;
276 -- Enable pragma Ignore_Pragma (Global) to support legacy code. As a
277 -- consequence, Refined_Global pragma should be ignored as well, as
278 -- it is only allowed on a body when pragma Global is given for the
279 -- spec.
281 Set_Name_Table_Boolean3 (Name_Global, True);
282 Set_Name_Table_Boolean3 (Name_Refined_Global, True);
284 -- Suppress division by zero checks since they are handled
285 -- implicitly by CodePeer.
287 -- Turn off dynamic elaboration checks: generates inconsistencies in
288 -- trees between specs compiled as part of a main unit or as part of
289 -- a with-clause.
291 -- Turn off alignment checks: these cannot be proved statically by
292 -- CodePeer and generate false positives.
294 -- Enable all other language checks
296 Suppress_Options.Suppress :=
297 (Alignment_Check => True,
298 Division_Check => True,
299 Elaboration_Check => True,
300 others => False);
302 -- Need to enable dynamic elaboration checks to disable strict
303 -- static checking performed by gnatbind. We are at the same time
304 -- suppressing actual compile time elaboration checks to simplify
305 -- the generated code.
307 Dynamic_Elaboration_Checks := True;
309 -- Set STRICT mode for overflow checks if not set explicitly. This
310 -- prevents suppressing of overflow checks by default, in code down
311 -- below.
313 if Suppress_Options.Overflow_Mode_General = Not_Set then
314 Suppress_Options.Overflow_Mode_General := Strict;
315 Suppress_Options.Overflow_Mode_Assertions := Strict;
316 end if;
318 -- CodePeer handles division and overflow checks directly, based on
319 -- the marks set by the frontend, hence no special expansion should
320 -- be performed in the frontend for division and overflow checks.
322 Backend_Divide_Checks_On_Target := True;
323 Backend_Overflow_Checks_On_Target := True;
325 -- Kill debug of generated code, since it messes up sloc values
327 Debug_Generated_Code := False;
329 -- Ditto for -gnateG which interacts badly with handling of pragma
330 -- Annotate in gnat2scil.
332 Generate_Processed_File := False;
334 -- Disable Exception_Extra_Info (-gnateE) which generates more
335 -- complex trees with no added value, and may confuse CodePeer.
337 Exception_Extra_Info := False;
339 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
340 -- to support source navigation.
342 Xref_Active := True;
344 -- Set operating mode to Generate_Code to benefit from full front-end
345 -- expansion (e.g. generics).
347 Operating_Mode := Generate_Code;
349 -- We need SCIL generation of course
351 Generate_SCIL := True;
353 -- Enable assertions, since they give CodePeer valuable extra info;
354 -- however, when switch -gnatd_k is active, then keep assertions
355 -- disabled by default and only enable them when explicitly
356 -- requested by pragma Assertion_Policy, just like in ordinary
357 -- compilation.
359 Assertions_Enabled := not Debug_Flag_Underscore_K;
361 -- Set normal RM validity checking and checking of copies (to catch
362 -- e.g. wrong values used in unchecked conversions).
363 -- All other validity checking is turned off, since this can generate
364 -- very complex trees that only confuse CodePeer and do not bring
365 -- enough useful info.
367 Reset_Validity_Check_Options;
368 Set_Validity_Check_Options ("dc");
369 Check_Validity_Of_Parameters := False;
371 -- Turn off style check options and ignore any style check pragmas
372 -- since we are not interested in any front-end warnings when we are
373 -- getting CodePeer output.
375 Reset_Style_Check_Options;
376 Ignore_Style_Checks_Pragmas := True;
378 -- Always perform semantics and generate ali files in CodePeer mode,
379 -- so that a gnatmake -c -k will proceed further when possible.
381 Force_ALI_File := True;
382 Try_Semantics := True;
384 -- Make the Ada front end more liberal so that the compiler will
385 -- allow illegal code that is allowed by other compilers. CodePeer
386 -- is in the business of finding problems, not enforcing rules.
387 -- This is useful when using CodePeer mode with other compilers.
389 Relaxed_RM_Semantics := True;
391 if Generate_CodePeer_Messages then
393 -- We do want to emit GNAT warnings when using -gnateC. But,
394 -- in CodePeer mode, warnings about memory representation are not
395 -- meaningful, thus, suppress them.
397 Warn_On_Biased_Representation := False; -- -gnatw.b
398 Warn_On_Unrepped_Components := False; -- -gnatw.c
399 Warn_On_Record_Holes := False; -- -gnatw.h
400 Warn_On_Unchecked_Conversion := False; -- -gnatwz
401 Warn_On_Size_Alignment := False; -- -gnatw.z
402 Warn_On_Questionable_Layout := False; -- -gnatw.q
403 Warn_On_Overridden_Size := False; -- -gnatw.s
404 Warn_On_Reverse_Bit_Order := False; -- -gnatw.v
406 else
408 -- Suppress compiler warnings by default when generating SCIL for
409 -- CodePeer, except when combined with -gnateC where we do want to
410 -- emit GNAT warnings.
412 Warning_Mode := Suppress;
413 end if;
415 -- Disable all simple value propagation. This is an optimization
416 -- which is valuable for code optimization, and also for generation
417 -- of compiler warnings, but these are being turned off by default,
418 -- and CodePeer generates better messages (referencing original
419 -- variables) this way.
420 -- Do this only if -gnatws is set (the default with -gnatcC), so that
421 -- if warnings are enabled, we'll get better messages from GNAT.
423 if Warning_Mode = Suppress then
424 Debug_Flag_MM := True;
425 end if;
427 -- The implementation of 'Value that uses a perfect hash function
428 -- is significantly more complex and harder to initialize than the
429 -- old implementation. Deactivate it for CodePeer.
431 Debug_Flag_Underscore_H := True;
432 end if;
434 -- Enable some individual switches that are implied by relaxed RM
435 -- semantics mode.
437 if Relaxed_RM_Semantics then
438 Opt.Allow_Integer_Address := True;
439 Overriding_Renamings := True;
440 Treat_Categorization_Errors_As_Warnings := True;
441 end if;
443 -- Enable GNATprove_Mode when using -gnatd.F switch
445 if Debug_Flag_Dot_FF then
446 GNATprove_Mode := True;
447 end if;
449 -- GNATprove_Mode is also activated by default in the gnat2why
450 -- executable.
452 if GNATprove_Mode then
454 -- Turn off CodePeer mode (which can be set via e.g. -gnatC or
455 -- -gnateC), not compatible with GNATprove mode.
457 CodePeer_Mode := False;
458 Generate_SCIL := False;
460 -- Turn off C tree generation, not compatible with GNATprove mode. We
461 -- do not expect this to happen in normal use, since both modes are
462 -- enabled by special tools, but it is useful to turn off these flags
463 -- this way when we are doing GNATprove tests on existing test suites
464 -- that may have -gnateg set, to avoid the need for special casing.
466 Modify_Tree_For_C := False;
467 Transform_Function_Array := False;
468 Generate_C_Code := False;
469 Unnest_Subprogram_Mode := False;
471 -- Turn off inlining, which would confuse formal verification output
472 -- and gain nothing.
474 Front_End_Inlining := False;
475 Inline_Active := False;
477 -- Issue warnings for failure to inline subprograms, as otherwise
478 -- expected in GNATprove mode for the local subprograms without
479 -- contracts.
481 Ineffective_Inline_Warnings := True;
483 -- Do not issue warnings for possible propagation of exception.
484 -- GNATprove already issues messages about possible exceptions.
486 No_Warn_On_Non_Local_Exception := True;
487 Warn_On_Non_Local_Exception := False;
489 -- Disable front-end optimizations, to keep the tree as close to the
490 -- source code as possible, and also to avoid inconsistencies between
491 -- trees when using different optimization switches.
493 Optimization_Level := 0;
495 -- Enable some restrictions systematically to simplify the generated
496 -- code (and ease analysis).
498 Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
500 -- Note: at this point we used to suppress various checks, but that
501 -- is not what we want. We need the semantic processing for these
502 -- checks (which will set flags like Do_Overflow_Check, showing the
503 -- points at which potential checks are required semantically). We
504 -- don't want the expansion associated with these checks, but that
505 -- happens anyway because this expansion is simply not done in the
506 -- SPARK version of the expander.
508 -- On the contrary, we need to enable explicitly all language checks,
509 -- as they may have been suppressed by the use of switch -gnatp.
511 Suppress_Options.Suppress := (others => False);
513 -- Detect overflow on unconstrained floating-point types, such as
514 -- the predefined types Float, Long_Float and Long_Long_Float from
515 -- package Standard. Not necessary if float overflows are checked
516 -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
517 -- will be set in any case.
519 Check_Float_Overflow := not Machine_Overflows_On_Target;
521 -- Set STRICT mode for overflow checks if not set explicitly. This
522 -- prevents suppressing of overflow checks by default, in code down
523 -- below.
525 if Suppress_Options.Overflow_Mode_General = Not_Set then
526 Suppress_Options.Overflow_Mode_General := Strict;
527 Suppress_Options.Overflow_Mode_Assertions := Strict;
528 end if;
530 -- Kill debug of generated code, since it messes up sloc values
532 Debug_Generated_Code := False;
534 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
535 -- as it is needed for computing effects of subprograms in the formal
536 -- verification backend.
538 Xref_Active := True;
540 -- Set operating mode to Check_Semantics, but a light front-end
541 -- expansion is still performed.
543 Operating_Mode := Check_Semantics;
545 -- Enable assertions, since they give valuable extra information for
546 -- formal verification.
548 Assertions_Enabled := True;
550 -- Disable validity checks, since it generates code raising
551 -- exceptions for invalid data, which confuses GNATprove. Invalid
552 -- data is directly detected by GNATprove's flow analysis.
554 Validity_Checks_On := False;
555 Check_Validity_Of_Parameters := False;
557 -- Turn off style checks and compiler warnings in GNATprove except:
558 -- - elaboration warnings, which turn into errors on SPARK code
559 -- - suspicious contracts, which are useful for SPARK code
561 Reset_Style_Check_Options;
562 Restore_Warnings
563 ((Warnings_Package.Elab_Warnings => True,
564 Warnings_Package.Warn_On_Suspicious_Contract => True,
565 others => False));
567 -- Suppress the generation of name tables for enumerations, which are
568 -- not needed for formal verification, and fall outside the SPARK
569 -- subset (use of pointers).
571 Global_Discard_Names := True;
573 -- Suppress the expansion of tagged types and dispatching calls,
574 -- which lead to the generation of non-SPARK code (use of pointers),
575 -- which is more complex to formally verify than the original source.
577 Tagged_Type_Expansion := False;
579 -- Force the use of "error:" prefix for error messages
581 Unique_Error_Tag := True;
583 -- Detect that the runtime library support for floating-point numbers
584 -- may not be compatible with SPARK analysis of IEEE-754 floats.
586 if Denorm_On_Target = False then
587 SPARK_Library_Warning ("float subnormals");
589 elsif Machine_Rounds_On_Target = False then
590 SPARK_Library_Warning ("float rounding");
592 elsif Signed_Zeros_On_Target = False then
593 SPARK_Library_Warning ("signed zeros");
594 end if;
595 end if;
597 -- Set Configurable_Run_Time mode if system.ads flag set or if the
598 -- special debug flag -gnatdY is set.
600 if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
601 Configurable_Run_Time_Mode := True;
602 end if;
604 -- Set -gnatRm mode if debug flag A set
606 if Debug_Flag_AA then
607 Back_Annotate_Rep_Info := True;
608 List_Representation_Info := 1;
609 List_Representation_Info_Mechanisms := True;
610 end if;
612 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
614 if Debug_Flag_Dot_A then
615 Ttypes.Target_Strict_Alignment := True;
616 end if;
618 -- Disable static allocation of dispatch tables if -gnatd.t is enabled.
619 -- The front end's layout phase currently treats types that have
620 -- discriminant-dependent arrays as not being static even when a
621 -- discriminant constraint on the type is static, and this leads to
622 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
624 if Debug_Flag_Dot_T then
625 Building_Static_Dispatch_Tables := False;
626 end if;
628 -- Flip endian mode if -gnatd8 set
630 if Debug_Flag_8 then
631 Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
632 end if;
634 -- Set and check exception mechanism. This is only meaningful when
635 -- generating code.
637 if Operating_Mode = Generate_Code then
638 if Targparm.ZCX_By_Default_On_Target then
639 Exception_Mechanism := Back_End_ZCX;
640 else
641 Exception_Mechanism := Back_End_SJLJ;
642 end if;
643 end if;
645 -- Set proper status for overflow check mechanism
647 -- If already set (by -gnato or above in SPARK or CodePeer mode) then we
648 -- have nothing to do.
650 if Opt.Suppress_Options.Overflow_Mode_General /= Not_Set then
651 null;
653 -- Otherwise set overflow mode defaults
655 else
656 -- Overflow checks are on by default (Suppress set False) except in
657 -- GNAT_Mode, where we want them off by default (we are not ready to
658 -- enable overflow checks in the compiler yet, for one thing the case
659 -- of 64-bit checks needs System.Arith_64 which is not a compiler
660 -- unit and it is a pain to try to include it in the compiler.
662 Suppress_Options.Suppress (Overflow_Check) := GNAT_Mode;
664 -- Set appropriate default overflow handling mode. Note: at present
665 -- we set STRICT in all three of the following cases. They are
666 -- separated because in the future we may make different choices.
668 -- By default set STRICT mode if -gnatg in effect
670 if GNAT_Mode then
671 Suppress_Options.Overflow_Mode_General := Strict;
672 Suppress_Options.Overflow_Mode_Assertions := Strict;
674 -- If we have backend divide and overflow checks, then by default
675 -- overflow checks are STRICT. Historically this code used to also
676 -- activate overflow checks, although no target currently has these
677 -- flags set, so this was dead code anyway.
679 elsif Targparm.Backend_Divide_Checks_On_Target
681 Targparm.Backend_Overflow_Checks_On_Target
682 then
683 Suppress_Options.Overflow_Mode_General := Strict;
684 Suppress_Options.Overflow_Mode_Assertions := Strict;
686 -- Otherwise for now, default is STRICT mode. This may change in the
687 -- future, but for now this is the compatible behavior with previous
688 -- versions of GNAT.
690 else
691 Suppress_Options.Overflow_Mode_General := Strict;
692 Suppress_Options.Overflow_Mode_Assertions := Strict;
693 end if;
694 end if;
696 -- Set default for atomic synchronization. As this synchronization
697 -- between atomic accesses can be expensive, and not typically needed
698 -- on some targets, an optional target parameter can turn the option
699 -- off. Note Atomic Synchronization is implemented as check.
701 Suppress_Options.Suppress (Atomic_Synchronization) :=
702 not Atomic_Sync_Default_On_Target;
704 -- Set default for Alignment_Check, if we are on a machine with non-
705 -- strict alignment, then we suppress this check, since it is over-
706 -- zealous for such machines.
708 if not Ttypes.Target_Strict_Alignment then
709 Suppress_Options.Suppress (Alignment_Check) := True;
710 end if;
712 -- Return slot support is disabled if -gnatd_r is specified
714 if Debug_Flag_Underscore_R then
715 Back_End_Return_Slot := False;
716 end if;
718 -- If the inlining level has not been set by the user, compute it from
719 -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
721 if Inline_Level = 0 then
722 if Optimization_Level < 3 then
723 Inline_Level := 1;
724 else
725 Inline_Level := 2;
726 end if;
727 end if;
729 -- Treat -gnatn as equivalent to -gnatN for non-GCC targets
731 if Inline_Active and not Front_End_Inlining then
733 -- We really should have a tag for this, what if we added a new
734 -- back end some day, it would not be true for this test, but it
735 -- would be non-GCC, so this is a bit troublesome ???
737 Front_End_Inlining := Generate_C_Code;
738 end if;
740 -- Set back-end inlining indication
742 Back_End_Inlining :=
744 -- No back-end inlining available on C generation
746 not Generate_C_Code
748 -- No back-end inlining in GNATprove mode, since it just confuses
749 -- the formal verification process.
751 and then not GNATprove_Mode
753 -- No back-end inlining if front-end inlining explicitly enabled.
754 -- Done to minimize the output differences to customers still using
755 -- this deprecated switch; in addition, this behavior reduces the
756 -- output differences in old tests.
758 and then not Front_End_Inlining
760 -- Back-end inlining is disabled if debug flag .z is set
762 and then not Debug_Flag_Dot_Z;
764 -- Output warning if -gnateE specified and cannot be supported
766 if Exception_Extra_Info
767 and then Restrict.No_Exception_Handlers_Set
768 then
769 Set_Standard_Error;
770 Write_Str
771 ("warning: extra exception information (-gnateE) was specified");
772 Write_Eol;
773 Write_Str
774 ("warning: this capability is not available in this configuration");
775 Write_Eol;
776 Set_Standard_Output;
777 end if;
779 -- Enable or disable the support for 128-bit types. It is automatically
780 -- enabled if the back end supports them, unless -gnatd.H is specified.
782 Enable_128bit_Types := Ttypes.Standard_Long_Long_Long_Integer_Size = 128;
784 if Enable_128bit_Types and then Debug_Flag_Dot_HH then
785 Enable_128bit_Types := False;
787 Ttypes.Standard_Long_Long_Long_Integer_Size :=
788 Ttypes.Standard_Long_Long_Integer_Size;
789 Ttypes.System_Max_Integer_Size :=
790 Ttypes.Standard_Long_Long_Integer_Size;
791 Ttypes.System_Max_Binary_Modulus_Power :=
792 Ttypes.Standard_Long_Long_Integer_Size;
793 end if;
795 -- Forcefully use a 32-bit Duration with only 32-bit integer types
797 if Ttypes.System_Max_Integer_Size < 64 then
798 Targparm.Duration_32_Bits_On_Target := True;
799 end if;
801 -- Finally capture adjusted value of Suppress_Options as the initial
802 -- value for Scope_Suppress, which will be modified as we move from
803 -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
805 Sem.Scope_Suppress := Opt.Suppress_Options;
806 end Adjust_Global_Switches;
808 --------------------
809 -- Check_Bad_Body --
810 --------------------
812 procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind) is
813 Fname : File_Name_Type;
815 procedure Bad_Body_Error (Msg : String);
816 -- Issue message for bad body found
818 --------------------
819 -- Bad_Body_Error --
820 --------------------
822 procedure Bad_Body_Error (Msg : String) is
823 begin
824 Error_Msg_N (Msg, Unit_Node);
825 Error_Msg_File_1 := Fname;
826 Error_Msg_N ("remove incorrect body in file{!", Unit_Node);
827 end Bad_Body_Error;
829 -- Local variables
831 Sname : Unit_Name_Type;
832 Src_Ind : Source_File_Index;
834 -- Start of processing for Check_Bad_Body
836 begin
837 -- Nothing to do if we are only checking syntax, because we don't know
838 -- enough to know if we require or forbid a body in this case.
840 if Operating_Mode = Check_Syntax then
841 return;
842 end if;
844 -- Check for body not allowed
846 if (Unit_Kind = N_Package_Declaration
847 and then not Body_Required (Unit_Node))
848 or else (Unit_Kind = N_Generic_Package_Declaration
849 and then not Body_Required (Unit_Node))
850 or else Unit_Kind = N_Package_Renaming_Declaration
851 or else Unit_Kind = N_Subprogram_Renaming_Declaration
852 or else Nkind (Original_Node (Unit (Unit_Node)))
853 in N_Generic_Instantiation
854 then
855 Sname := Unit_Name (Main_Unit);
857 -- If we do not already have a body name, then get the body name
859 if not Is_Body_Name (Sname) then
860 Sname := Get_Body_Name (Sname);
861 end if;
863 Fname := Get_File_Name (Sname, Subunit => False);
864 Src_Ind := Load_Source_File (Fname);
866 -- Case where body is present and it is not a subunit. Exclude the
867 -- subunit case, because it has nothing to do with the package we are
868 -- compiling. It is illegal for a child unit and a subunit with the
869 -- same expanded name (RM 10.2(9)) to appear together in a partition,
870 -- but there is nothing to stop a compilation environment from having
871 -- both, and the test here simply allows that. If there is an attempt
872 -- to include both in a partition, this is diagnosed at bind time. In
873 -- Ada 83 mode this is not a warning case.
875 -- Note that in general we do not give the message if the file in
876 -- question does not look like a body. This includes weird cases,
877 -- but in particular means that if the file is just a No_Body pragma,
878 -- then we won't give the message (that's the whole point of this
879 -- pragma, to be used this way and to cause the body file to be
880 -- ignored in this context).
882 if Src_Ind > No_Source_File
883 and then Source_File_Is_Body (Src_Ind)
884 then
885 Errout.Finalize (Last_Call => False);
887 Error_Msg_Unit_1 := Sname;
889 -- Ada 83 case of a package body being ignored. This is not an
890 -- error as far as the Ada 83 RM is concerned, but it is almost
891 -- certainly not what is wanted so output a warning. Give this
892 -- message only if there were no errors, since otherwise it may
893 -- be incorrect (we may have misinterpreted a junk spec as not
894 -- needing a body when it really does).
896 if Unit_Kind = N_Package_Declaration
897 and then Ada_Version = Ada_83
898 and then Operating_Mode = Generate_Code
899 and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
900 and then not Compilation_Errors
901 then
902 Error_Msg_N
903 ("package $$ does not require a body??", Unit_Node);
904 Error_Msg_File_1 := Fname;
905 Error_Msg_N ("body in file{ will be ignored??", Unit_Node);
907 -- Ada 95 cases of a body file present when no body is
908 -- permitted. This we consider to be an error.
910 else
911 -- For generic instantiations, we never allow a body
913 if Nkind (Original_Node (Unit (Unit_Node))) in
914 N_Generic_Instantiation
915 then
916 Bad_Body_Error
917 ("generic instantiation for $$ does not allow a body");
919 -- A library unit that is a renaming never allows a body
921 elsif Unit_Kind in N_Renaming_Declaration then
922 Bad_Body_Error
923 ("renaming declaration for $$ does not allow a body!");
925 -- Remaining cases are packages and generic packages. Here
926 -- we only do the test if there are no previous errors,
927 -- because if there are errors, they may lead us to
928 -- incorrectly believe that a package does not allow a
929 -- body when in fact it does.
931 elsif not Compilation_Errors then
932 if Unit_Kind = N_Package_Declaration then
933 Bad_Body_Error
934 ("package $$ does not allow a body!");
936 elsif Unit_Kind = N_Generic_Package_Declaration then
937 Bad_Body_Error
938 ("generic package $$ does not allow a body!");
939 end if;
940 end if;
942 end if;
943 end if;
944 end if;
945 end Check_Bad_Body;
947 --------------------
948 -- Check_Rep_Info --
949 --------------------
951 procedure Check_Rep_Info is
952 begin
953 if List_Representation_Info /= 0
954 or else List_Representation_Info_Mechanisms
955 then
956 Set_Standard_Error;
957 Write_Eol;
958 Write_Str
959 ("cannot generate representation information, no code generated");
960 Write_Eol;
961 Write_Eol;
962 Set_Standard_Output;
963 end if;
964 end Check_Rep_Info;
966 ----------------------------------------
967 -- Post_Compilation_Validation_Checks --
968 ----------------------------------------
970 procedure Post_Compilation_Validation_Checks is
971 begin
972 -- Validate alignment check warnings. In some cases we generate warnings
973 -- about possible alignment errors because we don't know the alignment
974 -- that will be chosen by the back end. This routine is in charge of
975 -- getting rid of those warnings if we can tell they are not needed.
977 Checks.Validate_Alignment_Check_Warnings;
979 -- Validate compile time warnings and errors (using the values for size
980 -- and alignment annotated by the backend where possible). We need to
981 -- unlock temporarily these tables to reanalyze their expression.
983 Atree.Unlock;
984 Nlists.Unlock;
985 Elists.Unlock;
986 Sem.Unlock;
987 Sem_Prag.Validate_Compile_Time_Warning_Errors;
988 Sem.Lock;
989 Elists.Lock;
990 Nlists.Lock;
991 Atree.Lock;
993 -- Validate unchecked conversions (using the values for size and
994 -- alignment annotated by the backend where possible).
996 Sem_Ch13.Validate_Unchecked_Conversions;
998 -- Validate address clauses (again using alignment values annotated
999 -- by the backend where possible).
1001 Sem_Ch13.Validate_Address_Clauses;
1002 end Post_Compilation_Validation_Checks;
1004 -----------------------------------
1005 -- Read_JSON_Files_For_Repinfo --
1006 -----------------------------------
1008 procedure Read_JSON_Files_For_Repinfo is
1009 begin
1010 -- This is the same loop construct as in Repinfo.List_Rep_Info
1012 for U in Main_Unit .. Last_Unit loop
1013 if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
1014 declare
1015 Nam : constant String :=
1016 Get_Name_String
1017 (File_Name (Source_Index (U))) & ".json";
1018 Namid : constant File_Name_Type := Name_Enter (Nam);
1019 Index : constant Source_File_Index := Load_Config_File (Namid);
1021 begin
1022 if Index = No_Source_File then
1023 Write_Str ("cannot locate ");
1024 Write_Line (Nam);
1025 raise Unrecoverable_Error;
1026 end if;
1028 Repinfo.Input.Read_JSON_Stream (Source_Text (Index).all, Nam);
1029 exception
1030 when Repinfo.Input.Invalid_JSON_Stream =>
1031 raise Unrecoverable_Error;
1032 end;
1033 end if;
1034 end loop;
1035 end Read_JSON_Files_For_Repinfo;
1037 -- Local variables
1039 Back_End_Mode : Back_End.Back_End_Mode_Type;
1040 Ecode : Exit_Code_Type;
1042 Main_Unit_Kind : Node_Kind;
1043 -- Kind of main compilation unit node
1045 Main_Unit_Node : Node_Id;
1046 -- Compilation unit node for main unit
1048 -- Start of processing for Gnat1drv
1050 begin
1051 -- This inner block is set up to catch assertion errors and constraint
1052 -- errors. Since the code for handling these errors can cause another
1053 -- exception to be raised (namely Unrecoverable_Error), we need two
1054 -- nested blocks, so that the outer one handles unrecoverable error.
1056 begin
1057 -- Initialize all packages. For the most part, these initialization
1058 -- calls can be made in any order. Exceptions are as follows:
1060 -- Lib.Initialize needs to be called before Scan_Compiler_Arguments,
1061 -- because it initializes a table filled by Scan_Compiler_Arguments.
1063 Osint.Initialize;
1064 Fmap.Reset_Tables;
1065 Lib.Initialize;
1066 Lib.Xref.Initialize;
1067 Scan_Compiler_Arguments;
1068 Osint.Add_Default_Search_Dirs;
1069 Atree.Initialize;
1070 Nlists.Initialize;
1071 Sinput.Initialize;
1072 Sem.Initialize;
1073 Exp_CG.Initialize;
1074 Csets.Initialize;
1075 Uintp.Initialize;
1076 Urealp.Initialize;
1077 Errout.Initialize;
1078 SCOs.Initialize;
1079 Snames.Initialize;
1080 Stringt.Initialize;
1081 Ghost.Initialize;
1082 Inline.Initialize;
1083 Par_SCO.Initialize;
1084 Sem_Ch8.Initialize;
1085 Sem_Ch12.Initialize;
1086 Sem_Ch13.Initialize;
1087 Sem_Elim.Initialize;
1088 Sem_Eval.Initialize;
1089 Sem_Type.Init_Interp_Tables;
1091 -- Capture compilation date and time
1093 Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
1095 -- Get the target parameters only when -gnats is not used, to avoid
1096 -- failing when there is no default runtime.
1098 if Operating_Mode /= Check_Syntax then
1100 -- Acquire target parameters from system.ads (package System source)
1102 Targparm_Acquire : declare
1104 S : Source_File_Index;
1105 N : File_Name_Type;
1107 begin
1108 Name_Buffer (1 .. 10) := "system.ads";
1109 Name_Len := 10;
1110 N := Name_Find;
1111 S := Load_Source_File (N);
1113 -- Failed to read system.ads, fatal error
1115 if S = No_Source_File then
1116 Write_Line
1117 ("fatal error, run-time library not installed correctly");
1118 Write_Line ("cannot locate file system.ads");
1119 raise Unrecoverable_Error;
1121 elsif S = No_Access_To_Source_File then
1122 Write_Line
1123 ("fatal error, run-time library not installed correctly");
1124 Write_Line ("no read access for file system.ads");
1125 raise Unrecoverable_Error;
1127 -- Read system.ads successfully, remember its source index
1129 else
1130 System_Source_File_Index := S;
1131 end if;
1133 -- Call to get target parameters. Note that the actual interface
1134 -- routines are in Tbuild. They can't be in this procedure because
1135 -- of accessibility issues.
1137 Targparm.Get_Target_Parameters
1138 (System_Text => Source_Text (S),
1139 Source_First => Source_First (S),
1140 Source_Last => Source_Last (S),
1141 Make_Id => Tbuild.Make_Id'Access,
1142 Make_SC => Tbuild.Make_SC'Access,
1143 Set_NOD => Tbuild.Set_NOD'Access,
1144 Set_NSA => Tbuild.Set_NSA'Access,
1145 Set_NUA => Tbuild.Set_NUA'Access,
1146 Set_NUP => Tbuild.Set_NUP'Access);
1148 -- Acquire configuration pragma information from Targparm
1150 Restrict.Restrictions := Targparm.Restrictions_On_Target;
1151 end Targparm_Acquire;
1152 end if;
1154 -- Perform various adjustments and settings of global switches
1156 Adjust_Global_Switches;
1158 -- Output copyright notice if full list mode unless we have a list
1159 -- file, in which case we defer this so that it is output in the file.
1161 if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
1163 -- Debug flag gnatd7 suppresses this copyright notice
1165 and then not Debug_Flag_7
1166 then
1167 Write_Eol;
1168 Write_Str ("GNAT ");
1169 Write_Str (Gnat_Version_String);
1170 Write_Eol;
1171 Write_Str ("Copyright 1992-" & Current_Year
1172 & ", Free Software Foundation, Inc.");
1173 Write_Eol;
1174 end if;
1176 -- Check we do not have more than one source file, this happens only in
1177 -- the case where the driver is called directly, it cannot happen when
1178 -- gnat1 is invoked from gcc in the normal case.
1180 if Osint.Number_Of_Files /= 1 then
1182 -- In GNATprove mode, gcc is not called, so we may end up with
1183 -- switches wrongly interpreted as source file names when they are
1184 -- written by mistake without a starting hyphen. Issue a specific
1185 -- error message but do not print the internal 'usage' message.
1187 if GNATprove_Mode then
1188 Write_Str
1189 ("one of the following is not a valid switch or source file "
1190 & "name: ");
1191 Osint.Dump_Command_Line_Source_File_Names;
1192 else
1193 Usage;
1194 Write_Eol;
1195 end if;
1197 Osint.Fail ("you must provide one source file");
1199 elsif Usage_Requested then
1200 Usage;
1201 end if;
1203 -- Generate target dependent output file if requested
1205 if Target_Dependent_Info_Write_Name /= null then
1206 Set_Targ.Write_Target_Dependent_Values;
1207 end if;
1209 -- Call the front end
1211 Original_Operating_Mode := Operating_Mode;
1212 Frontend;
1214 -- Exit with errors if the main source could not be parsed
1216 if Sinput.Main_Source_File <= No_Source_File then
1217 Errout.Finalize (Last_Call => True);
1218 Errout.Output_Messages;
1219 Exit_Program (E_Errors);
1220 end if;
1222 Main_Unit_Node := Cunit (Main_Unit);
1223 Main_Unit_Kind := Nkind (Unit (Main_Unit_Node));
1225 Check_Bad_Body (Main_Unit_Node, Main_Unit_Kind);
1227 -- In CodePeer mode we always delete old SCIL files before regenerating
1228 -- new ones, in case of e.g. errors, and also to remove obsolete scilx
1229 -- files generated by CodePeer itself.
1231 if CodePeer_Mode then
1232 Comperr.Delete_SCIL_Files;
1233 end if;
1235 -- Ditto for old C files before regenerating new ones
1237 if Generate_C_Code then
1238 Delete_C_File;
1239 Delete_H_File;
1240 end if;
1242 -- Exit if compilation errors detected
1244 Errout.Finalize (Last_Call => False);
1246 if Compilation_Errors then
1247 Treepr.Tree_Dump;
1248 Errout.Finalize (Last_Call => True);
1249 Errout.Output_Messages;
1250 Namet.Finalize;
1252 -- Generate ALI file if specially requested
1254 if Opt.Force_ALI_File then
1255 Write_ALI (Object => False);
1256 end if;
1258 Exit_Program (E_Errors);
1259 end if;
1261 -- Case of no code required to be generated, exit indicating no error
1263 if Original_Operating_Mode = Check_Syntax then
1264 Treepr.Tree_Dump;
1265 Errout.Finalize (Last_Call => True);
1266 Errout.Output_Messages;
1267 Namet.Finalize;
1268 Check_Rep_Info;
1270 -- Use a goto instead of calling Exit_Program so that finalization
1271 -- occurs normally.
1273 goto End_Of_Program;
1275 elsif Original_Operating_Mode = Check_Semantics then
1276 Back_End_Mode := Declarations_Only;
1278 -- All remaining cases are cases in which the user requested that code
1279 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1280 -- can in fact satisfy this request.
1282 -- Cannot generate code if someone has turned off code generation for
1283 -- any reason at all. We will try to figure out a reason below.
1285 elsif Operating_Mode /= Generate_Code then
1286 Back_End_Mode := Skip;
1288 -- We can generate code for a subprogram body unless there were missing
1289 -- subunits. Note that we always generate code for all generic units (a
1290 -- change from some previous versions of GNAT).
1292 elsif Main_Unit_Kind = N_Subprogram_Body
1293 and then not Subunits_Missing
1294 then
1295 Back_End_Mode := Generate_Object;
1297 -- We can generate code for a package body unless there are subunits
1298 -- missing (note that we always generate code for generic units, which
1299 -- is a change from some earlier versions of GNAT).
1301 elsif Main_Unit_Kind = N_Package_Body and then not Subunits_Missing then
1302 Back_End_Mode := Generate_Object;
1304 -- We can generate code for a package declaration or a subprogram
1305 -- declaration only if it does not required a body.
1307 elsif Main_Unit_Kind in N_Package_Declaration | N_Subprogram_Declaration
1308 and then
1309 (not Body_Required (Main_Unit_Node)
1310 or else Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1311 then
1312 Back_End_Mode := Generate_Object;
1314 -- We can generate code for a generic package declaration of a generic
1315 -- subprogram declaration only if does not require a body.
1317 elsif Main_Unit_Kind in
1318 N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration
1319 and then not Body_Required (Main_Unit_Node)
1320 then
1321 Back_End_Mode := Generate_Object;
1323 -- Compilation units that are renamings do not require bodies, so we can
1324 -- generate code for them.
1326 elsif Main_Unit_Kind in N_Package_Renaming_Declaration |
1327 N_Subprogram_Renaming_Declaration
1328 then
1329 Back_End_Mode := Generate_Object;
1331 -- Compilation units that are generic renamings do not require bodies
1332 -- so we can generate code for them.
1334 elsif Main_Unit_Kind in N_Generic_Renaming_Declaration then
1335 Back_End_Mode := Generate_Object;
1337 -- It is not an error to analyze in CodePeer mode a spec which requires
1338 -- a body, in order to generate SCIL for this spec.
1340 elsif CodePeer_Mode then
1341 Back_End_Mode := Generate_Object;
1343 -- Differentiate use of -gnatceg to generate a C header from an Ada spec
1344 -- to the CCG case (standard.h found) where C code generation should
1345 -- only be performed on full units.
1347 elsif Generate_C_Code then
1348 Name_Len := 10;
1349 Name_Buffer (1 .. Name_Len) := "standard.h";
1351 if Find_File (Name_Find, Osint.Source, Full_Name => True) = No_File
1352 then
1353 Back_End_Mode := Generate_Object;
1354 else
1355 Back_End_Mode := Skip;
1356 end if;
1358 -- It is not an error to analyze in GNATprove mode a spec which requires
1359 -- a body, when the body is not available. During frame condition
1360 -- generation, the corresponding ALI file is generated. During
1361 -- analysis, the spec is analyzed.
1363 elsif GNATprove_Mode then
1364 Back_End_Mode := Declarations_Only;
1366 -- In all other cases (specs which have bodies, generics, and bodies
1367 -- where subunits are missing), we cannot generate code and we generate
1368 -- a warning message. Note that generic instantiations are gone at this
1369 -- stage since they have been replaced by their instances.
1371 else
1372 Back_End_Mode := Skip;
1373 end if;
1375 -- Ensure that we properly register a dependency on system.ads, since
1376 -- even if we do not semantically depend on this, Targparm has read
1377 -- system parameters from the system.ads file.
1379 Lib.Writ.Ensure_System_Dependency;
1381 -- Add dependencies, if any, on preprocessing data file and on
1382 -- preprocessing definition file(s).
1384 Prepcomp.Add_Dependencies;
1386 -- At this stage Back_End_Mode is set to indicate if the backend should
1387 -- be called to generate code. If it is Skip, then code generation has
1388 -- been turned off, even though code was requested by the original
1389 -- command. This is not an error from the user point of view, but it is
1390 -- an error from the point of view of the gcc driver, so we must exit
1391 -- with an error status.
1393 -- We generate an informative message (from the gcc point of view, it
1394 -- is an error message, but from the users point of view this is not an
1395 -- error, just a consequence of compiling something that cannot
1396 -- generate code).
1398 if Back_End_Mode = Skip then
1400 -- An ignored Ghost unit is rewritten into a null statement. Do
1401 -- not emit any errors related to code generation because the
1402 -- unit does not exist.
1404 if Is_Ignored_Ghost_Unit (Main_Unit_Node) then
1406 -- Exit the gnat driver with success, otherwise external builders
1407 -- such as gnatmake and gprbuild will treat the compilation of an
1408 -- ignored Ghost unit as a failure. Be sure we produce an empty
1409 -- object file for the unit.
1411 Ecode := E_Success;
1412 Back_End.Gen_Or_Update_Object_File;
1414 -- Otherwise the unit is missing a crucial piece that prevents code
1415 -- generation.
1417 else
1418 Ecode := E_No_Code;
1420 Set_Standard_Error;
1421 Write_Str ("cannot generate code for file ");
1422 Write_Name (Unit_File_Name (Main_Unit));
1424 if Subunits_Missing then
1425 Write_Str (" (missing subunits)");
1426 Write_Eol;
1428 -- Force generation of ALI file, for backward compatibility
1430 Opt.Force_ALI_File := True;
1432 elsif Main_Unit_Kind = N_Subunit then
1433 Write_Str (" (subunit)");
1434 Write_Eol;
1436 -- Do not generate an ALI file in this case, because it would
1437 -- become obsolete when the parent is compiled, and thus
1438 -- confuse some tools.
1440 elsif Main_Unit_Kind = N_Subprogram_Declaration then
1441 Write_Str (" (subprogram spec)");
1442 Write_Eol;
1444 -- Generic package body in GNAT implementation mode
1446 elsif Main_Unit_Kind = N_Package_Body and then GNAT_Mode then
1447 Write_Str (" (predefined generic)");
1448 Write_Eol;
1450 -- Force generation of ALI file, for backward compatibility
1452 Opt.Force_ALI_File := True;
1454 -- Only other case is a package spec
1456 else
1457 Write_Str (" (package spec)");
1458 Write_Eol;
1459 end if;
1460 end if;
1462 Set_Standard_Output;
1464 Post_Compilation_Validation_Checks;
1465 Errout.Finalize (Last_Call => True);
1466 Errout.Output_Messages;
1467 Treepr.Tree_Dump;
1469 -- Generate ALI file if specially requested, or for missing subunits,
1470 -- subunits or predefined generic. For ignored ghost code, the object
1471 -- file IS generated, so Object should be True, and since the object
1472 -- file is generated, we need to generate the ALI file. We never want
1473 -- an object file without an ALI file.
1475 if Is_Ignored_Ghost_Unit (Main_Unit_Node)
1476 or else Opt.Force_ALI_File
1477 then
1478 Write_ALI (Object => Is_Ignored_Ghost_Unit (Main_Unit_Node));
1479 end if;
1481 Namet.Finalize;
1482 Check_Rep_Info;
1484 if Ecode /= E_Success then
1485 -- If we cannot generate code, exit the driver with an appropriate
1486 -- status indicator.
1488 Exit_Program (Ecode);
1490 else
1491 -- Otherwise use a goto so that finalization occurs normally and
1492 -- for instance any late processing in the GCC code can be
1493 -- performed.
1495 goto End_Of_Program;
1496 end if;
1497 end if;
1499 -- In -gnatc mode we only do annotation if -gnatR is also set, or if
1500 -- -gnatwz is enabled (default setting) and there is an unchecked
1501 -- conversion that involves a type whose size is not statically known,
1502 -- as indicated by Back_Annotate_Rep_Info being set to True.
1504 -- We don't call for annotations on a subunit, because to process those
1505 -- the back end requires that the parent(s) be properly compiled.
1507 -- Annotation is suppressed for targets where front-end layout is
1508 -- enabled, because the front end determines representations.
1510 -- A special back end is always called in CodePeer and GNATprove modes,
1511 -- unless this is a subunit.
1513 if Back_End_Mode = Declarations_Only
1514 and then
1515 (not (Back_Annotate_Rep_Info or Generate_SCIL or GNATprove_Mode)
1516 or else Main_Unit_Kind = N_Subunit)
1517 then
1518 Post_Compilation_Validation_Checks;
1519 Errout.Finalize (Last_Call => True);
1520 Errout.Output_Messages;
1521 Write_ALI (Object => False);
1522 Tree_Dump;
1523 Namet.Finalize;
1525 if not (Generate_SCIL or GNATprove_Mode) then
1526 Check_Rep_Info;
1527 end if;
1529 pragma Annotate (Xcov, Dump_Buffers);
1531 return;
1532 end if;
1534 if GNATprove_Mode then
1536 -- In GNATprove mode we're writing the ALI much earlier than usual
1537 -- as flow analysis needs the file present in order to append its
1538 -- own globals to it.
1540 -- Note: In GNATprove mode, an "object" file is always generated as
1541 -- the result of calling gnat1 or gnat2why, although this is not the
1542 -- same as the object file produced for compilation.
1544 Write_ALI (Object => True);
1545 end if;
1547 -- Some back ends (for instance Gigi) are known to rely on SCOs for code
1548 -- generation. Make sure they are available.
1550 if Generate_SCO then
1551 Par_SCO.SCO_Record_Filtered;
1552 end if;
1554 -- If -gnatd_j is specified, exercise the JSON parser of Repinfo
1556 if Debug_Flag_Underscore_J then
1557 Read_JSON_Files_For_Repinfo;
1558 end if;
1560 -- Back end needs to explicitly unlock tables it needs to touch
1562 Atree.Lock;
1563 Elists.Lock;
1564 Fname.UF.Lock;
1565 Ghost.Lock;
1566 Inline.Lock;
1567 Lib.Lock;
1568 Namet.Lock;
1569 Nlists.Lock;
1570 Sem.Lock;
1571 Sinput.Lock;
1572 Stringt.Lock;
1574 -- Here we call the back end to generate the output code
1576 Generating_Code := True;
1577 Back_End.Call_Back_End (Back_End_Mode);
1579 -- Once the backend is complete, we unlock the names table. This call
1580 -- allows a few extra entries, needed for example for the file name
1581 -- for the library file output.
1583 Namet.Unlock;
1585 -- Generate the call-graph output of dispatching calls
1587 Exp_CG.Generate_CG_Output;
1589 -- Perform post compilation validation checks
1591 Post_Compilation_Validation_Checks;
1593 -- Now we complete output of errors, rep info and the tree info. These
1594 -- are delayed till now, since it is perfectly possible for gigi to
1595 -- generate errors, modify the tree (in particular by setting flags
1596 -- indicating that elaboration is required, and also to back annotate
1597 -- representation information for List_Rep_Info).
1599 Errout.Finalize (Last_Call => True);
1600 Errout.Output_Messages;
1602 -- Back annotation of representation info is not done in CodePeer and
1603 -- SPARK modes.
1605 if not (Generate_SCIL or GNATprove_Mode) then
1606 Repinfo.List_Rep_Info (Ttypes.Bytes_Big_Endian);
1607 end if;
1609 Inline.List_Inlining_Info;
1611 -- Only write the library if the backend did not generate any error
1612 -- messages. Otherwise signal errors to the driver program so that
1613 -- there will be no attempt to generate an object file.
1615 if Compilation_Errors then
1616 Treepr.Tree_Dump;
1617 Exit_Program (E_Errors);
1618 end if;
1620 if not GNATprove_Mode then
1621 Write_ALI (Object => (Back_End_Mode = Generate_Object));
1622 end if;
1624 if not Compilation_Errors then
1626 -- In case of ada backends, we need to make sure that the generated
1627 -- object file has a timestamp greater than the ALI file. We do this
1628 -- to make gnatmake happy when checking the ALI and obj timestamps,
1629 -- where it expects the object file being written after the ali file.
1631 -- Gnatmake's assumption is true for gcc platforms where the gcc
1632 -- wrapper needs to call the assembler after calling gnat1, but is
1633 -- not true for ada backends, where the object files are created
1634 -- directly by gnat1 (so are created before the ali file).
1636 Back_End.Gen_Or_Update_Object_File;
1637 end if;
1639 -- Generate tree after writing the ALI file, since Write_ALI may in
1640 -- fact result in further tree decoration from the original tree file.
1641 -- Note that we dump the tree just before generating it, so that the
1642 -- dump will exactly reflect what is written out.
1644 Treepr.Tree_Dump;
1646 -- Finalize name table and we are all done
1648 Namet.Finalize;
1650 exception
1651 -- Handle fatal internal compiler errors
1653 when Rtsfind.RE_Not_Available =>
1654 Comperr.Compiler_Abort ("RE_Not_Available");
1656 when System.Assertions.Assert_Failure =>
1657 Comperr.Compiler_Abort ("Assert_Failure");
1659 when Constraint_Error =>
1660 Comperr.Compiler_Abort ("Constraint_Error");
1662 when Program_Error =>
1663 Comperr.Compiler_Abort ("Program_Error");
1665 -- Assume this is a bug. If it is real, the message will in any case
1666 -- say Storage_Error, giving a strong hint.
1668 when Storage_Error =>
1669 Comperr.Compiler_Abort ("Storage_Error");
1671 when Unrecoverable_Error =>
1672 raise;
1674 when others =>
1675 Comperr.Compiler_Abort ("exception");
1676 end;
1678 <<End_Of_Program>>
1680 if Debug_Flag_Dot_AA then
1681 Atree.Print_Statistics;
1682 end if;
1684 pragma Annotate (Xcov, Dump_Buffers);
1686 -- The outer exception handler handles an unrecoverable error
1688 exception
1689 when Unrecoverable_Error =>
1690 Errout.Finalize (Last_Call => True);
1691 Errout.Output_Messages;
1693 Set_Standard_Error;
1694 Write_Str ("compilation abandoned");
1695 Write_Eol;
1697 Set_Standard_Output;
1698 Source_Dump;
1699 Tree_Dump;
1701 pragma Annotate (Xcov, Dump_Buffers);
1703 Exit_Program (E_Errors);
1705 end Gnat1drv;