1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Back_End
; use Back_End
;
31 with Debug
; use Debug
;
33 with Errout
; use Errout
;
36 with Fname
; use Fname
;
37 with Fname
.UF
; use Fname
.UF
;
39 with Ghost
; use Ghost
;
40 with Gnatvsn
; use Gnatvsn
;
43 with Lib
.Writ
; use Lib
.Writ
;
45 with Namet
; use Namet
;
48 with Osint
; use Osint
;
49 with Osint
.C
; use Osint
.C
;
50 with Output
; use Output
;
56 with Rident
; use Rident
;
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
;
75 with Stylesw
; use Stylesw
;
76 with Targparm
; use Targparm
;
78 with Treepr
; use Treepr
;
80 with Types
; use Types
;
82 with Uname
; use Uname
;
85 with Validsw
; use Validsw
;
86 with Warnsw
; use Warnsw
;
88 with System
.Assertions
;
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
140 ("warning: run-time library may be configured incorrectly");
142 ("warning: (SPARK analysis requires support for " & Kind
& ')');
143 end SPARK_Library_Warning
;
145 -- Start of processing for Adjust_Global_Switches
149 -- -gnatd_U disables prepending error messages with "error:"
151 if Debug_Flag_Underscore_UU
then
152 Unique_Error_Tag
:= False;
155 -- -gnatd.M enables Relaxed_RM_Semantics
157 if Debug_Flag_Dot_MM
then
158 Relaxed_RM_Semantics
:= True;
161 -- -gnatd.1 enables unnesting of subprograms
163 if Debug_Flag_Dot_1
then
164 Unnest_Subprogram_Mode
:= True;
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;
174 -- -gnatd_A disables generation of ALI files
176 if Debug_Flag_Underscore_AA
then
177 Disable_ALI_File
:= True;
180 -- Set all flags required when generating C code
182 if Generate_C_Code
then
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;
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;
210 -- -gnatdJ sets Include_Subprogram_In_Messages, adding the related
211 -- subprogram as part of the error and warning messages.
213 if Debug_Flag_JJ
then
214 Include_Subprogram_In_Messages
:= True;
217 -- Disable CodePeer_Mode in Check_Syntax, since we need front-end
220 if Operating_Mode
= Check_Syntax
then
221 CodePeer_Mode
:= False;
224 -- SCIL mode needs to disable front-end inlining since the generated
225 -- trees (in particular order and consistency between specs compiled
226 -- as part of a main unit or as part of a with-clause) are causing
229 if Generate_SCIL
then
230 Front_End_Inlining
:= False;
233 -- Tune settings for optimal SCIL generation in CodePeer mode
235 if CodePeer_Mode
then
237 -- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
238 -- compatible with CodePeer mode.
240 GNATprove_Mode
:= False;
241 Debug_Flag_Dot_FF
:= False;
243 -- Turn off length expansion. CodePeer has its own mechanism to
244 -- handle length attribute.
246 Debug_Flag_Dot_PP
:= True;
248 -- Turn off C tree generation, not compatible with CodePeer mode. We
249 -- do not expect this to happen in normal use, since both modes are
250 -- enabled by special tools, but it is useful to turn off these flags
251 -- this way when we are doing CodePeer tests on existing test suites
252 -- that may have -gnateg set, to avoid the need for special casing.
254 Modify_Tree_For_C
:= False;
255 Transform_Function_Array
:= False;
256 Generate_C_Code
:= False;
257 Unnest_Subprogram_Mode
:= False;
259 -- Turn off inlining, confuses CodePeer output and gains nothing
261 Front_End_Inlining
:= False;
262 Inline_Active
:= False;
264 -- Disable front-end optimizations, to keep the tree as close to the
265 -- source code as possible, and also to avoid inconsistencies between
266 -- trees when using different optimization switches.
268 Optimization_Level
:= 0;
270 -- Enable some restrictions systematically to simplify the generated
271 -- code (and ease analysis). Note that restriction checks are also
272 -- disabled in CodePeer mode, see Restrict.Check_Restriction, and
273 -- user specified Restrictions pragmas are ignored, see
274 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
276 Restrict
.Restrictions
.Set
(No_Exception_Registration
) := True;
277 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
278 Restrict
.Restrictions
.Set
(No_Task_Hierarchy
) := True;
279 Restrict
.Restrictions
.Set
(No_Abort_Statements
) := True;
280 Restrict
.Restrictions
.Set
(Max_Asynchronous_Select_Nesting
) := True;
281 Restrict
.Restrictions
.Value
(Max_Asynchronous_Select_Nesting
) := 0;
283 -- Enable pragma Ignore_Pragma (Global) to support legacy code. As a
284 -- consequence, Refined_Global pragma should be ignored as well, as
285 -- it is only allowed on a body when pragma Global is given for the
288 Set_Name_Table_Boolean3
(Name_Global
, True);
289 Set_Name_Table_Boolean3
(Name_Refined_Global
, True);
291 -- Suppress division by zero checks since they are handled
292 -- implicitly by CodePeer.
294 -- Turn off dynamic elaboration checks: generates inconsistencies in
295 -- trees between specs compiled as part of a main unit or as part of
298 -- Turn off alignment checks: these cannot be proved statically by
299 -- CodePeer and generate false positives.
301 -- Enable all other language checks
303 Suppress_Options
.Suppress
:=
304 (Alignment_Check
=> True,
305 Division_Check
=> True,
306 Elaboration_Check
=> True,
309 -- Need to enable dynamic elaboration checks to disable strict
310 -- static checking performed by gnatbind. We are at the same time
311 -- suppressing actual compile time elaboration checks to simplify
312 -- the generated code.
314 Dynamic_Elaboration_Checks
:= True;
316 -- Set STRICT mode for overflow checks if not set explicitly. This
317 -- prevents suppressing of overflow checks by default, in code down
320 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
321 Suppress_Options
.Overflow_Mode_General
:= Strict
;
322 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
325 -- CodePeer handles division and overflow checks directly, based on
326 -- the marks set by the frontend, hence no special expansion should
327 -- be performed in the frontend for division and overflow checks.
329 Backend_Divide_Checks_On_Target
:= True;
330 Backend_Overflow_Checks_On_Target
:= True;
332 -- Kill debug of generated code, since it messes up sloc values
334 Debug_Generated_Code
:= False;
336 -- Ditto for -gnateG which interacts badly with handling of pragma
337 -- Annotate in gnat2scil.
339 Generate_Processed_File
:= False;
341 -- Disable Exception_Extra_Info (-gnateE) which generates more
342 -- complex trees with no added value, and may confuse CodePeer.
344 Exception_Extra_Info
:= False;
346 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
347 -- to support source navigation.
351 -- Set operating mode to Generate_Code to benefit from full front-end
352 -- expansion (e.g. generics).
354 Operating_Mode
:= Generate_Code
;
356 -- We need SCIL generation of course
358 Generate_SCIL
:= True;
360 -- Enable assertions, since they give CodePeer valuable extra info
362 Assertions_Enabled
:= True;
364 -- Set normal RM validity checking and checking of copies (to catch
365 -- e.g. wrong values used in unchecked conversions).
366 -- All other validity checking is turned off, since this can generate
367 -- very complex trees that only confuse CodePeer and do not bring
368 -- enough useful info.
370 Reset_Validity_Check_Options
;
371 Set_Validity_Check_Options
("dc");
372 Check_Validity_Of_Parameters
:= False;
374 -- Turn off style check options and ignore any style check pragmas
375 -- since we are not interested in any front-end warnings when we are
376 -- getting CodePeer output.
378 Reset_Style_Check_Options
;
379 Ignore_Style_Checks_Pragmas
:= True;
381 -- Always perform semantics and generate ali files in CodePeer mode,
382 -- so that a gnatmake -c -k will proceed further when possible.
384 Force_ALI_File
:= True;
385 Try_Semantics
:= True;
387 -- Make the Ada front end more liberal so that the compiler will
388 -- allow illegal code that is allowed by other compilers. CodePeer
389 -- is in the business of finding problems, not enforcing rules.
390 -- This is useful when using CodePeer mode with other compilers.
392 Relaxed_RM_Semantics
:= True;
394 if Generate_CodePeer_Messages
then
396 -- We do want to emit GNAT warnings when using -gnateC. But,
397 -- in CodePeer mode, warnings about memory representation are not
398 -- meaningful, thus, suppress them.
400 Warn_On_Biased_Representation
:= False; -- -gnatw.b
401 Warn_On_Unrepped_Components
:= False; -- -gnatw.c
402 Warn_On_Record_Holes
:= False; -- -gnatw.h
403 Warn_On_Unchecked_Conversion
:= False; -- -gnatwz
404 Warn_On_Size_Alignment
:= False; -- -gnatw.z
405 Warn_On_Questionable_Layout
:= False; -- -gnatw.q
406 Warn_On_Overridden_Size
:= False; -- -gnatw.s
407 Warn_On_Reverse_Bit_Order
:= False; -- -gnatw.v
411 -- Suppress compiler warnings by default when generating SCIL for
412 -- CodePeer, except when combined with -gnateC where we do want to
413 -- emit GNAT warnings.
415 Warning_Mode
:= Suppress
;
418 -- Disable all simple value propagation. This is an optimization
419 -- which is valuable for code optimization, and also for generation
420 -- of compiler warnings, but these are being turned off by default,
421 -- and CodePeer generates better messages (referencing original
422 -- variables) this way.
423 -- Do this only if -gnatws is set (the default with -gnatcC), so that
424 -- if warnings are enabled, we'll get better messages from GNAT.
426 if Warning_Mode
= Suppress
then
427 Debug_Flag_MM
:= True;
430 -- The implementation of 'Value that uses a perfect hash function
431 -- is significantly more complex and harder to initialize than the
432 -- old implementation. Deactivate it for CodePeer.
434 Debug_Flag_Underscore_H
:= True;
437 -- Enable some individual switches that are implied by relaxed RM
440 if Relaxed_RM_Semantics
then
441 Opt
.Allow_Integer_Address
:= True;
442 Overriding_Renamings
:= True;
443 Treat_Categorization_Errors_As_Warnings
:= True;
446 -- Enable GNATprove_Mode when using -gnatd.F switch
448 if Debug_Flag_Dot_FF
then
449 GNATprove_Mode
:= True;
452 -- GNATprove_Mode is also activated by default in the gnat2why
455 if GNATprove_Mode
then
457 -- Turn off CodePeer mode (which can be set via e.g. -gnatC or
458 -- -gnateC), not compatible with GNATprove mode.
460 CodePeer_Mode
:= False;
461 Generate_SCIL
:= False;
463 -- Turn off C tree generation, not compatible with GNATprove mode. We
464 -- do not expect this to happen in normal use, since both modes are
465 -- enabled by special tools, but it is useful to turn off these flags
466 -- this way when we are doing GNATprove tests on existing test suites
467 -- that may have -gnateg set, to avoid the need for special casing.
469 Modify_Tree_For_C
:= False;
470 Transform_Function_Array
:= False;
471 Generate_C_Code
:= False;
472 Unnest_Subprogram_Mode
:= False;
474 -- Turn off inlining, which would confuse formal verification output
477 Front_End_Inlining
:= False;
478 Inline_Active
:= False;
480 -- Issue warnings for failure to inline subprograms, as otherwise
481 -- expected in GNATprove mode for the local subprograms without
484 Ineffective_Inline_Warnings
:= True;
486 -- Do not issue warnings for possible propagation of exception.
487 -- GNATprove already issues messages about possible exceptions.
489 No_Warn_On_Non_Local_Exception
:= True;
490 Warn_On_Non_Local_Exception
:= False;
492 -- Disable front-end optimizations, to keep the tree as close to the
493 -- source code as possible, and also to avoid inconsistencies between
494 -- trees when using different optimization switches.
496 Optimization_Level
:= 0;
498 -- Enable some restrictions systematically to simplify the generated
499 -- code (and ease analysis).
501 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
503 -- Note: at this point we used to suppress various checks, but that
504 -- is not what we want. We need the semantic processing for these
505 -- checks (which will set flags like Do_Overflow_Check, showing the
506 -- points at which potential checks are required semantically). We
507 -- don't want the expansion associated with these checks, but that
508 -- happens anyway because this expansion is simply not done in the
509 -- SPARK version of the expander.
511 -- On the contrary, we need to enable explicitly all language checks,
512 -- as they may have been suppressed by the use of switch -gnatp.
514 Suppress_Options
.Suppress
:= (others => False);
516 -- Detect overflow on unconstrained floating-point types, such as
517 -- the predefined types Float, Long_Float and Long_Long_Float from
518 -- package Standard. Not necessary if float overflows are checked
519 -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
520 -- will be set in any case.
522 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
524 -- Set STRICT mode for overflow checks if not set explicitly. This
525 -- prevents suppressing of overflow checks by default, in code down
528 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
529 Suppress_Options
.Overflow_Mode_General
:= Strict
;
530 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
533 -- Kill debug of generated code, since it messes up sloc values
535 Debug_Generated_Code
:= False;
537 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
538 -- as it is needed for computing effects of subprograms in the formal
539 -- verification backend.
543 -- Set operating mode to Check_Semantics, but a light front-end
544 -- expansion is still performed.
546 Operating_Mode
:= Check_Semantics
;
548 -- Enable assertions, since they give valuable extra information for
549 -- formal verification.
551 Assertions_Enabled
:= True;
553 -- Disable validity checks, since it generates code raising
554 -- exceptions for invalid data, which confuses GNATprove. Invalid
555 -- data is directly detected by GNATprove's flow analysis.
557 Validity_Checks_On
:= False;
558 Check_Validity_Of_Parameters
:= False;
560 -- Turn off style checks and compiler warnings in GNATprove except:
561 -- - elaboration warnings, which turn into errors on SPARK code
562 -- - suspicious contracts, which are useful for SPARK code
564 Reset_Style_Check_Options
;
566 ((Warnings_Package
.Elab_Warnings
=> True,
567 Warnings_Package
.Warn_On_Suspicious_Contract
=> True,
570 -- Suppress the generation of name tables for enumerations, which are
571 -- not needed for formal verification, and fall outside the SPARK
572 -- subset (use of pointers).
574 Global_Discard_Names
:= True;
576 -- Suppress the expansion of tagged types and dispatching calls,
577 -- which lead to the generation of non-SPARK code (use of pointers),
578 -- which is more complex to formally verify than the original source.
580 Tagged_Type_Expansion
:= False;
582 -- Force the use of "error:" prefix for error messages
584 Unique_Error_Tag
:= True;
586 -- Detect that the runtime library support for floating-point numbers
587 -- may not be compatible with SPARK analysis of IEEE-754 floats.
589 if Denorm_On_Target
= False then
590 SPARK_Library_Warning
("float subnormals");
592 elsif Machine_Rounds_On_Target
= False then
593 SPARK_Library_Warning
("float rounding");
595 elsif Signed_Zeros_On_Target
= False then
596 SPARK_Library_Warning
("signed zeros");
600 -- Set Configurable_Run_Time mode if system.ads flag set or if the
601 -- special debug flag -gnatdY is set.
603 if Targparm
.Configurable_Run_Time_On_Target
or Debug_Flag_YY
then
604 Configurable_Run_Time_Mode
:= True;
607 -- Set -gnatRm mode if debug flag A set
609 if Debug_Flag_AA
then
610 Back_Annotate_Rep_Info
:= True;
611 List_Representation_Info
:= 1;
612 List_Representation_Info_Mechanisms
:= True;
615 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
617 if Debug_Flag_Dot_A
then
618 Ttypes
.Target_Strict_Alignment
:= True;
621 -- Disable static allocation of dispatch tables if -gnatd.t is enabled.
622 -- The front end's layout phase currently treats types that have
623 -- discriminant-dependent arrays as not being static even when a
624 -- discriminant constraint on the type is static, and this leads to
625 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
627 if Debug_Flag_Dot_T
then
628 Building_Static_Dispatch_Tables
:= False;
631 -- Flip endian mode if -gnatd8 set
634 Ttypes
.Bytes_Big_Endian
:= not Ttypes
.Bytes_Big_Endian
;
637 -- Set and check exception mechanism. This is only meaningful when
640 if Operating_Mode
= Generate_Code
then
641 if Targparm
.ZCX_By_Default_On_Target
then
642 Exception_Mechanism
:= Back_End_ZCX
;
644 Exception_Mechanism
:= Back_End_SJLJ
;
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
656 -- Otherwise set overflow mode defaults
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
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
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
694 Suppress_Options
.Overflow_Mode_General
:= Strict
;
695 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
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;
715 -- Return slot support is disabled if -gnatd_r is specified
717 if Debug_Flag_Underscore_R
then
718 Back_End_Return_Slot
:= False;
721 -- If the inlining level has not been set by the user, compute it from
722 -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
724 if Inline_Level
= 0 then
725 if Optimization_Level
< 3 then
732 -- Treat -gnatn as equivalent to -gnatN for non-GCC targets
734 if Inline_Active
and not Front_End_Inlining
then
736 -- We really should have a tag for this, what if we added a new
737 -- back end some day, it would not be true for this test, but it
738 -- would be non-GCC, so this is a bit troublesome ???
740 Front_End_Inlining
:= Generate_C_Code
;
743 -- Set back-end inlining indication
747 -- No back-end inlining available on C generation
751 -- No back-end inlining in GNATprove mode, since it just confuses
752 -- the formal verification process.
754 and then not GNATprove_Mode
756 -- No back-end inlining if front-end inlining explicitly enabled.
757 -- Done to minimize the output differences to customers still using
758 -- this deprecated switch; in addition, this behavior reduces the
759 -- output differences in old tests.
761 and then not Front_End_Inlining
763 -- Back-end inlining is disabled if debug flag .z is set
765 and then not Debug_Flag_Dot_Z
;
767 -- Output warning if -gnateE specified and cannot be supported
769 if Exception_Extra_Info
770 and then Restrict
.No_Exception_Handlers_Set
774 ("warning: extra exception information (-gnateE) was specified");
777 ("warning: this capability is not available in this configuration");
782 -- Enable or disable the support for 128-bit types. It is automatically
783 -- enabled if the back end supports them, unless -gnatd.H is specified.
785 Enable_128bit_Types
:= Ttypes
.Standard_Long_Long_Long_Integer_Size
= 128;
787 if Enable_128bit_Types
and then Debug_Flag_Dot_HH
then
788 Enable_128bit_Types
:= False;
790 Ttypes
.Standard_Long_Long_Long_Integer_Size
:=
791 Ttypes
.Standard_Long_Long_Integer_Size
;
792 Ttypes
.System_Max_Integer_Size
:=
793 Ttypes
.Standard_Long_Long_Integer_Size
;
794 Ttypes
.System_Max_Binary_Modulus_Power
:=
795 Ttypes
.Standard_Long_Long_Integer_Size
;
798 -- Forcefully use a 32-bit Duration with only 32-bit integer types
800 if Ttypes
.System_Max_Integer_Size
< 64 then
801 Targparm
.Duration_32_Bits_On_Target
:= True;
804 -- Finally capture adjusted value of Suppress_Options as the initial
805 -- value for Scope_Suppress, which will be modified as we move from
806 -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
808 Sem
.Scope_Suppress
:= Opt
.Suppress_Options
;
809 end Adjust_Global_Switches
;
815 procedure Check_Bad_Body
(Unit_Node
: Node_Id
; Unit_Kind
: Node_Kind
) is
816 Fname
: File_Name_Type
;
818 procedure Bad_Body_Error
(Msg
: String);
819 -- Issue message for bad body found
825 procedure Bad_Body_Error
(Msg
: String) is
827 Error_Msg_N
(Msg
, Unit_Node
);
828 Error_Msg_File_1
:= Fname
;
829 Error_Msg_N
("remove incorrect body in file{!", Unit_Node
);
834 Sname
: Unit_Name_Type
;
835 Src_Ind
: Source_File_Index
;
837 -- Start of processing for Check_Bad_Body
840 -- Nothing to do if we are only checking syntax, because we don't know
841 -- enough to know if we require or forbid a body in this case.
843 if Operating_Mode
= Check_Syntax
then
847 -- Check for body not allowed
849 if (Unit_Kind
= N_Package_Declaration
850 and then not Body_Required
(Unit_Node
))
851 or else (Unit_Kind
= N_Generic_Package_Declaration
852 and then not Body_Required
(Unit_Node
))
853 or else Unit_Kind
= N_Package_Renaming_Declaration
854 or else Unit_Kind
= N_Subprogram_Renaming_Declaration
855 or else Nkind
(Original_Node
(Unit
(Unit_Node
)))
856 in N_Generic_Instantiation
858 Sname
:= Unit_Name
(Main_Unit
);
860 -- If we do not already have a body name, then get the body name
862 if not Is_Body_Name
(Sname
) then
863 Sname
:= Get_Body_Name
(Sname
);
866 Fname
:= Get_File_Name
(Sname
, Subunit
=> False);
867 Src_Ind
:= Load_Source_File
(Fname
);
869 -- Case where body is present and it is not a subunit. Exclude the
870 -- subunit case, because it has nothing to do with the package we are
871 -- compiling. It is illegal for a child unit and a subunit with the
872 -- same expanded name (RM 10.2(9)) to appear together in a partition,
873 -- but there is nothing to stop a compilation environment from having
874 -- both, and the test here simply allows that. If there is an attempt
875 -- to include both in a partition, this is diagnosed at bind time. In
876 -- Ada 83 mode this is not a warning case.
878 -- Note that in general we do not give the message if the file in
879 -- question does not look like a body. This includes weird cases,
880 -- but in particular means that if the file is just a No_Body pragma,
881 -- then we won't give the message (that's the whole point of this
882 -- pragma, to be used this way and to cause the body file to be
883 -- ignored in this context).
885 if Src_Ind
> No_Source_File
886 and then Source_File_Is_Body
(Src_Ind
)
888 Errout
.Finalize
(Last_Call
=> False);
890 Error_Msg_Unit_1
:= Sname
;
892 -- Ada 83 case of a package body being ignored. This is not an
893 -- error as far as the Ada 83 RM is concerned, but it is almost
894 -- certainly not what is wanted so output a warning. Give this
895 -- message only if there were no errors, since otherwise it may
896 -- be incorrect (we may have misinterpreted a junk spec as not
897 -- needing a body when it really does).
899 if Unit_Kind
= N_Package_Declaration
900 and then Ada_Version
= Ada_83
901 and then Operating_Mode
= Generate_Code
902 and then Distribution_Stub_Mode
/= Generate_Caller_Stub_Body
903 and then not Compilation_Errors
906 ("package $$ does not require a body??", Unit_Node
);
907 Error_Msg_File_1
:= Fname
;
908 Error_Msg_N
("body in file{ will be ignored??", Unit_Node
);
910 -- Ada 95 cases of a body file present when no body is
911 -- permitted. This we consider to be an error.
914 -- For generic instantiations, we never allow a body
916 if Nkind
(Original_Node
(Unit
(Unit_Node
))) in
917 N_Generic_Instantiation
920 ("generic instantiation for $$ does not allow a body");
922 -- A library unit that is a renaming never allows a body
924 elsif Unit_Kind
in N_Renaming_Declaration
then
926 ("renaming declaration for $$ does not allow a body!");
928 -- Remaining cases are packages and generic packages. Here
929 -- we only do the test if there are no previous errors,
930 -- because if there are errors, they may lead us to
931 -- incorrectly believe that a package does not allow a
932 -- body when in fact it does.
934 elsif not Compilation_Errors
then
935 if Unit_Kind
= N_Package_Declaration
then
937 ("package $$ does not allow a body!");
939 elsif Unit_Kind
= N_Generic_Package_Declaration
then
941 ("generic package $$ does not allow a body!");
954 procedure Check_Rep_Info
is
956 if List_Representation_Info
/= 0
957 or else List_Representation_Info_Mechanisms
962 ("cannot generate representation information, no code generated");
969 ----------------------------------------
970 -- Post_Compilation_Validation_Checks --
971 ----------------------------------------
973 procedure Post_Compilation_Validation_Checks
is
975 -- Validate alignment check warnings. In some cases we generate warnings
976 -- about possible alignment errors because we don't know the alignment
977 -- that will be chosen by the back end. This routine is in charge of
978 -- getting rid of those warnings if we can tell they are not needed.
980 Checks
.Validate_Alignment_Check_Warnings
;
982 -- Validate compile time warnings and errors (using the values for size
983 -- and alignment annotated by the backend where possible). We need to
984 -- unlock temporarily these tables to reanalyze their expression.
990 Sem_Prag
.Validate_Compile_Time_Warning_Errors
;
996 -- Validate unchecked conversions (using the values for size and
997 -- alignment annotated by the backend where possible).
999 Sem_Ch13
.Validate_Unchecked_Conversions
;
1001 -- Validate address clauses (again using alignment values annotated
1002 -- by the backend where possible).
1004 Sem_Ch13
.Validate_Address_Clauses
;
1005 end Post_Compilation_Validation_Checks
;
1007 -----------------------------------
1008 -- Read_JSON_Files_For_Repinfo --
1009 -----------------------------------
1011 procedure Read_JSON_Files_For_Repinfo
is
1013 -- This is the same loop construct as in Repinfo.List_Rep_Info
1015 for U
in Main_Unit
.. Last_Unit
loop
1016 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1018 Nam
: constant String :=
1020 (File_Name
(Source_Index
(U
))) & ".json";
1021 Namid
: constant File_Name_Type
:= Name_Enter
(Nam
);
1022 Index
: constant Source_File_Index
:= Load_Config_File
(Namid
);
1025 if Index
= No_Source_File
then
1026 Write_Str
("cannot locate ");
1028 raise Unrecoverable_Error
;
1031 Repinfo
.Input
.Read_JSON_Stream
(Source_Text
(Index
).all, Nam
);
1033 when Repinfo
.Input
.Invalid_JSON_Stream
=>
1034 raise Unrecoverable_Error
;
1038 end Read_JSON_Files_For_Repinfo
;
1042 Back_End_Mode
: Back_End
.Back_End_Mode_Type
;
1043 Ecode
: Exit_Code_Type
;
1045 Main_Unit_Kind
: Node_Kind
;
1046 -- Kind of main compilation unit node
1048 Main_Unit_Node
: Node_Id
;
1049 -- Compilation unit node for main unit
1051 -- Start of processing for Gnat1drv
1054 -- This inner block is set up to catch assertion errors and constraint
1055 -- errors. Since the code for handling these errors can cause another
1056 -- exception to be raised (namely Unrecoverable_Error), we need two
1057 -- nested blocks, so that the outer one handles unrecoverable error.
1060 -- Initialize all packages. For the most part, these initialization
1061 -- calls can be made in any order. Exceptions are as follows:
1063 -- Lib.Initialize needs to be called before Scan_Compiler_Arguments,
1064 -- because it initializes a table filled by Scan_Compiler_Arguments.
1069 Lib
.Xref
.Initialize
;
1070 Scan_Compiler_Arguments
;
1071 Osint
.Add_Default_Search_Dirs
;
1088 Sem_Ch12
.Initialize
;
1089 Sem_Ch13
.Initialize
;
1090 Sem_Elim
.Initialize
;
1091 Sem_Eval
.Initialize
;
1092 Sem_Type
.Init_Interp_Tables
;
1094 -- Capture compilation date and time
1096 Opt
.Compilation_Time
:= System
.OS_Lib
.Current_Time_String
;
1098 -- Get the target parameters only when -gnats is not used, to avoid
1099 -- failing when there is no default runtime.
1101 if Operating_Mode
/= Check_Syntax
then
1103 -- Acquire target parameters from system.ads (package System source)
1105 Targparm_Acquire
: declare
1107 S
: Source_File_Index
;
1111 Name_Buffer
(1 .. 10) := "system.ads";
1114 S
:= Load_Source_File
(N
);
1116 -- Failed to read system.ads, fatal error
1118 if S
= No_Source_File
then
1120 ("fatal error, run-time library not installed correctly");
1121 Write_Line
("cannot locate file system.ads");
1122 raise Unrecoverable_Error
;
1124 elsif S
= No_Access_To_Source_File
then
1126 ("fatal error, run-time library not installed correctly");
1127 Write_Line
("no read access for file system.ads");
1128 raise Unrecoverable_Error
;
1130 -- Read system.ads successfully, remember its source index
1133 System_Source_File_Index
:= S
;
1136 -- Call to get target parameters. Note that the actual interface
1137 -- routines are in Tbuild. They can't be in this procedure because
1138 -- of accessibility issues.
1140 Targparm
.Get_Target_Parameters
1141 (System_Text
=> Source_Text
(S
),
1142 Source_First
=> Source_First
(S
),
1143 Source_Last
=> Source_Last
(S
),
1144 Make_Id
=> Tbuild
.Make_Id
'Access,
1145 Make_SC
=> Tbuild
.Make_SC
'Access,
1146 Set_NOD
=> Tbuild
.Set_NOD
'Access,
1147 Set_NSA
=> Tbuild
.Set_NSA
'Access,
1148 Set_NUA
=> Tbuild
.Set_NUA
'Access,
1149 Set_NUP
=> Tbuild
.Set_NUP
'Access);
1151 -- Acquire configuration pragma information from Targparm
1153 Restrict
.Restrictions
:= Targparm
.Restrictions_On_Target
;
1154 end Targparm_Acquire
;
1157 -- Perform various adjustments and settings of global switches
1159 Adjust_Global_Switches
;
1161 -- Output copyright notice if full list mode unless we have a list
1162 -- file, in which case we defer this so that it is output in the file.
1164 if (Verbose_Mode
or else (Full_List
and then Full_List_File_Name
= null))
1166 -- Debug flag gnatd7 suppresses this copyright notice
1168 and then not Debug_Flag_7
1171 Write_Str
("GNAT ");
1172 Write_Str
(Gnat_Version_String
);
1174 Write_Str
("Copyright 1992-" & Current_Year
1175 & ", Free Software Foundation, Inc.");
1179 -- Check we do not have more than one source file, this happens only in
1180 -- the case where the driver is called directly, it cannot happen when
1181 -- gnat1 is invoked from gcc in the normal case.
1183 if Osint
.Number_Of_Files
/= 1 then
1185 -- In GNATprove mode, gcc is not called, so we may end up with
1186 -- switches wrongly interpreted as source file names when they are
1187 -- written by mistake without a starting hyphen. Issue a specific
1188 -- error message but do not print the internal 'usage' message.
1190 if GNATprove_Mode
then
1192 ("one of the following is not a valid switch or source file "
1194 Osint
.Dump_Command_Line_Source_File_Names
;
1200 Osint
.Fail
("you must provide one source file");
1202 elsif Usage_Requested
then
1206 -- Generate target dependent output file if requested
1208 if Target_Dependent_Info_Write_Name
/= null then
1209 Set_Targ
.Write_Target_Dependent_Values
;
1212 -- Call the front end
1214 Original_Operating_Mode
:= Operating_Mode
;
1217 -- Exit with errors if the main source could not be parsed
1219 if Sinput
.Main_Source_File
<= No_Source_File
then
1220 Errout
.Finalize
(Last_Call
=> True);
1221 Errout
.Output_Messages
;
1222 Exit_Program
(E_Errors
);
1225 Main_Unit_Node
:= Cunit
(Main_Unit
);
1226 Main_Unit_Kind
:= Nkind
(Unit
(Main_Unit_Node
));
1228 Check_Bad_Body
(Main_Unit_Node
, Main_Unit_Kind
);
1230 -- In CodePeer mode we always delete old SCIL files before regenerating
1231 -- new ones, in case of e.g. errors, and also to remove obsolete scilx
1232 -- files generated by CodePeer itself.
1234 if CodePeer_Mode
then
1235 Comperr
.Delete_SCIL_Files
;
1238 -- Ditto for old C files before regenerating new ones
1240 if Generate_C_Code
then
1245 -- Exit if compilation errors detected
1247 Errout
.Finalize
(Last_Call
=> False);
1249 if Compilation_Errors
then
1251 Errout
.Finalize
(Last_Call
=> True);
1252 Errout
.Output_Messages
;
1255 -- Generate ALI file if specially requested
1257 if Opt
.Force_ALI_File
then
1258 Write_ALI
(Object
=> False);
1261 Exit_Program
(E_Errors
);
1264 -- Case of no code required to be generated, exit indicating no error
1266 if Original_Operating_Mode
= Check_Syntax
then
1268 Errout
.Finalize
(Last_Call
=> True);
1269 Errout
.Output_Messages
;
1273 -- Use a goto instead of calling Exit_Program so that finalization
1276 goto End_Of_Program
;
1278 elsif Original_Operating_Mode
= Check_Semantics
then
1279 Back_End_Mode
:= Declarations_Only
;
1281 -- All remaining cases are cases in which the user requested that code
1282 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1283 -- can in fact satisfy this request.
1285 -- Cannot generate code if someone has turned off code generation for
1286 -- any reason at all. We will try to figure out a reason below.
1288 elsif Operating_Mode
/= Generate_Code
then
1289 Back_End_Mode
:= Skip
;
1291 -- We can generate code for a subprogram body unless there were missing
1292 -- subunits. Note that we always generate code for all generic units (a
1293 -- change from some previous versions of GNAT).
1295 elsif Main_Unit_Kind
= N_Subprogram_Body
1296 and then not Subunits_Missing
1298 Back_End_Mode
:= Generate_Object
;
1300 -- We can generate code for a package body unless there are subunits
1301 -- missing (note that we always generate code for generic units, which
1302 -- is a change from some earlier versions of GNAT).
1304 elsif Main_Unit_Kind
= N_Package_Body
and then not Subunits_Missing
then
1305 Back_End_Mode
:= Generate_Object
;
1307 -- We can generate code for a package declaration or a subprogram
1308 -- declaration only if it does not required a body.
1310 elsif Main_Unit_Kind
in N_Package_Declaration | N_Subprogram_Declaration
1312 (not Body_Required
(Main_Unit_Node
)
1313 or else Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
1315 Back_End_Mode
:= Generate_Object
;
1317 -- We can generate code for a generic package declaration of a generic
1318 -- subprogram declaration only if does not require a body.
1320 elsif Main_Unit_Kind
in
1321 N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration
1322 and then not Body_Required
(Main_Unit_Node
)
1324 Back_End_Mode
:= Generate_Object
;
1326 -- Compilation units that are renamings do not require bodies, so we can
1327 -- generate code for them.
1329 elsif Main_Unit_Kind
in N_Package_Renaming_Declaration |
1330 N_Subprogram_Renaming_Declaration
1332 Back_End_Mode
:= Generate_Object
;
1334 -- Compilation units that are generic renamings do not require bodies
1335 -- so we can generate code for them.
1337 elsif Main_Unit_Kind
in N_Generic_Renaming_Declaration
then
1338 Back_End_Mode
:= Generate_Object
;
1340 -- It is not an error to analyze in CodePeer mode a spec which requires
1341 -- a body, in order to generate SCIL for this spec.
1343 elsif CodePeer_Mode
then
1344 Back_End_Mode
:= Generate_Object
;
1346 -- Differentiate use of -gnatceg to generate a C header from an Ada spec
1347 -- to the CCG case (standard.h found) where C code generation should
1348 -- only be performed on full units.
1350 elsif Generate_C_Code
then
1352 Name_Buffer
(1 .. Name_Len
) := "standard.h";
1354 if Find_File
(Name_Find
, Osint
.Source
, Full_Name
=> True) = No_File
1356 Back_End_Mode
:= Generate_Object
;
1358 Back_End_Mode
:= Skip
;
1361 -- It is not an error to analyze in GNATprove mode a spec which requires
1362 -- a body, when the body is not available. During frame condition
1363 -- generation, the corresponding ALI file is generated. During
1364 -- analysis, the spec is analyzed.
1366 elsif GNATprove_Mode
then
1367 Back_End_Mode
:= Declarations_Only
;
1369 -- In all other cases (specs which have bodies, generics, and bodies
1370 -- where subunits are missing), we cannot generate code and we generate
1371 -- a warning message. Note that generic instantiations are gone at this
1372 -- stage since they have been replaced by their instances.
1375 Back_End_Mode
:= Skip
;
1378 -- Ensure that we properly register a dependency on system.ads, since
1379 -- even if we do not semantically depend on this, Targparm has read
1380 -- system parameters from the system.ads file.
1382 Lib
.Writ
.Ensure_System_Dependency
;
1384 -- Add dependencies, if any, on preprocessing data file and on
1385 -- preprocessing definition file(s).
1387 Prepcomp
.Add_Dependencies
;
1389 -- At this stage Back_End_Mode is set to indicate if the backend should
1390 -- be called to generate code. If it is Skip, then code generation has
1391 -- been turned off, even though code was requested by the original
1392 -- command. This is not an error from the user point of view, but it is
1393 -- an error from the point of view of the gcc driver, so we must exit
1394 -- with an error status.
1396 -- We generate an informative message (from the gcc point of view, it
1397 -- is an error message, but from the users point of view this is not an
1398 -- error, just a consequence of compiling something that cannot
1401 if Back_End_Mode
= Skip
then
1403 -- An ignored Ghost unit is rewritten into a null statement. Do
1404 -- not emit any errors related to code generation because the
1405 -- unit does not exist.
1407 if Is_Ignored_Ghost_Unit
(Main_Unit_Node
) then
1409 -- Exit the gnat driver with success, otherwise external builders
1410 -- such as gnatmake and gprbuild will treat the compilation of an
1411 -- ignored Ghost unit as a failure. Be sure we produce an empty
1412 -- object file for the unit.
1415 Back_End
.Gen_Or_Update_Object_File
;
1417 -- Otherwise the unit is missing a crucial piece that prevents code
1424 Write_Str
("cannot generate code for file ");
1425 Write_Name
(Unit_File_Name
(Main_Unit
));
1427 if Subunits_Missing
then
1428 Write_Str
(" (missing subunits)");
1431 -- Force generation of ALI file, for backward compatibility
1433 Opt
.Force_ALI_File
:= True;
1435 elsif Main_Unit_Kind
= N_Subunit
then
1436 Write_Str
(" (subunit)");
1439 -- Do not generate an ALI file in this case, because it would
1440 -- become obsolete when the parent is compiled, and thus
1441 -- confuse some tools.
1443 elsif Main_Unit_Kind
= N_Subprogram_Declaration
then
1444 Write_Str
(" (subprogram spec)");
1447 -- Generic package body in GNAT implementation mode
1449 elsif Main_Unit_Kind
= N_Package_Body
and then GNAT_Mode
then
1450 Write_Str
(" (predefined generic)");
1453 -- Force generation of ALI file, for backward compatibility
1455 Opt
.Force_ALI_File
:= True;
1457 -- Only other case is a package spec
1460 Write_Str
(" (package spec)");
1465 Set_Standard_Output
;
1467 Post_Compilation_Validation_Checks
;
1468 Errout
.Finalize
(Last_Call
=> True);
1469 Errout
.Output_Messages
;
1472 -- Generate ALI file if specially requested, or for missing subunits,
1473 -- subunits or predefined generic. For ignored ghost code, the object
1474 -- file IS generated, so Object should be True, and since the object
1475 -- file is generated, we need to generate the ALI file. We never want
1476 -- an object file without an ALI file.
1478 if Is_Ignored_Ghost_Unit
(Main_Unit_Node
)
1479 or else Opt
.Force_ALI_File
1481 Write_ALI
(Object
=> Is_Ignored_Ghost_Unit
(Main_Unit_Node
));
1487 if Ecode
/= E_Success
then
1488 -- If we cannot generate code, exit the driver with an appropriate
1489 -- status indicator.
1491 Exit_Program
(Ecode
);
1494 -- Otherwise use a goto so that finalization occurs normally and
1495 -- for instance any late processing in the GCC code can be
1498 goto End_Of_Program
;
1502 -- In -gnatc mode we only do annotation if -gnatR is also set, or if
1503 -- -gnatwz is enabled (default setting) and there is an unchecked
1504 -- conversion that involves a type whose size is not statically known,
1505 -- as indicated by Back_Annotate_Rep_Info being set to True.
1507 -- We don't call for annotations on a subunit, because to process those
1508 -- the back end requires that the parent(s) be properly compiled.
1510 -- Annotation is suppressed for targets where front-end layout is
1511 -- enabled, because the front end determines representations.
1513 -- A special back end is always called in CodePeer and GNATprove modes,
1514 -- unless this is a subunit.
1516 if Back_End_Mode
= Declarations_Only
1518 (not (Back_Annotate_Rep_Info
or Generate_SCIL
or GNATprove_Mode
)
1519 or else Main_Unit_Kind
= N_Subunit
)
1521 Post_Compilation_Validation_Checks
;
1522 Errout
.Finalize
(Last_Call
=> True);
1523 Errout
.Output_Messages
;
1524 Write_ALI
(Object
=> False);
1528 if not (Generate_SCIL
or GNATprove_Mode
) then
1535 if GNATprove_Mode
then
1537 -- In GNATprove mode we're writing the ALI much earlier than usual
1538 -- as flow analysis needs the file present in order to append its
1539 -- own globals to it.
1541 -- Note: In GNATprove mode, an "object" file is always generated as
1542 -- the result of calling gnat1 or gnat2why, although this is not the
1543 -- same as the object file produced for compilation.
1545 Write_ALI
(Object
=> True);
1548 -- Some back ends (for instance Gigi) are known to rely on SCOs for code
1549 -- generation. Make sure they are available.
1551 if Generate_SCO
then
1552 Par_SCO
.SCO_Record_Filtered
;
1555 -- If -gnatd_j is specified, exercise the JSON parser of Repinfo
1557 if Debug_Flag_Underscore_J
then
1558 Read_JSON_Files_For_Repinfo
;
1561 -- Back end needs to explicitly unlock tables it needs to touch
1575 -- Here we call the back end to generate the output code
1577 Generating_Code
:= True;
1578 Back_End
.Call_Back_End
(Back_End_Mode
);
1580 -- Once the backend is complete, we unlock the names table. This call
1581 -- allows a few extra entries, needed for example for the file name
1582 -- for the library file output.
1586 -- Generate the call-graph output of dispatching calls
1588 Exp_CG
.Generate_CG_Output
;
1590 -- Perform post compilation validation checks
1592 Post_Compilation_Validation_Checks
;
1594 -- Now we complete output of errors, rep info and the tree info. These
1595 -- are delayed till now, since it is perfectly possible for gigi to
1596 -- generate errors, modify the tree (in particular by setting flags
1597 -- indicating that elaboration is required, and also to back annotate
1598 -- representation information for List_Rep_Info).
1600 Errout
.Finalize
(Last_Call
=> True);
1601 Errout
.Output_Messages
;
1603 -- Back annotation of representation info is not done in CodePeer and
1606 if not (Generate_SCIL
or GNATprove_Mode
) then
1607 Repinfo
.List_Rep_Info
(Ttypes
.Bytes_Big_Endian
);
1610 Inline
.List_Inlining_Info
;
1612 -- Only write the library if the backend did not generate any error
1613 -- messages. Otherwise signal errors to the driver program so that
1614 -- there will be no attempt to generate an object file.
1616 if Compilation_Errors
then
1618 Exit_Program
(E_Errors
);
1621 if not GNATprove_Mode
then
1622 Write_ALI
(Object
=> (Back_End_Mode
= Generate_Object
));
1625 if not Compilation_Errors
then
1627 -- In case of ada backends, we need to make sure that the generated
1628 -- object file has a timestamp greater than the ALI file. We do this
1629 -- to make gnatmake happy when checking the ALI and obj timestamps,
1630 -- where it expects the object file being written after the ali file.
1632 -- Gnatmake's assumption is true for gcc platforms where the gcc
1633 -- wrapper needs to call the assembler after calling gnat1, but is
1634 -- not true for ada backends, where the object files are created
1635 -- directly by gnat1 (so are created before the ali file).
1637 Back_End
.Gen_Or_Update_Object_File
;
1640 -- Generate tree after writing the ALI file, since Write_ALI may in
1641 -- fact result in further tree decoration from the original tree file.
1642 -- Note that we dump the tree just before generating it, so that the
1643 -- dump will exactly reflect what is written out.
1647 -- Finalize name table and we are all done
1652 -- Handle fatal internal compiler errors
1654 when Rtsfind
.RE_Not_Available
=>
1655 Comperr
.Compiler_Abort
("RE_Not_Available");
1657 when System
.Assertions
.Assert_Failure
=>
1658 Comperr
.Compiler_Abort
("Assert_Failure");
1660 when Constraint_Error
=>
1661 Comperr
.Compiler_Abort
("Constraint_Error");
1663 when Program_Error
=>
1664 Comperr
.Compiler_Abort
("Program_Error");
1666 -- Assume this is a bug. If it is real, the message will in any case
1667 -- say Storage_Error, giving a strong hint.
1669 when Storage_Error
=>
1670 Comperr
.Compiler_Abort
("Storage_Error");
1672 when Unrecoverable_Error
=>
1676 Comperr
.Compiler_Abort
("exception");
1681 if Debug_Flag_Dot_AA
then
1682 Atree
.Print_Statistics
;
1685 -- The outer exception handler handles an unrecoverable error
1688 when Unrecoverable_Error
=>
1689 Errout
.Finalize
(Last_Call
=> True);
1690 Errout
.Output_Messages
;
1693 Write_Str
("compilation abandoned");
1696 Set_Standard_Output
;
1699 Exit_Program
(E_Errors
);