1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Sinput
; use Sinput
;
70 with Sinput
.L
; use Sinput
.L
;
71 with Snames
; use Snames
;
72 with Sprint
; use Sprint
;
74 with Stylesw
; use Stylesw
;
75 with Targparm
; use Targparm
;
77 with Treepr
; use Treepr
;
79 with Types
; use Types
;
81 with Uname
; use Uname
;
84 with Validsw
; use Validsw
;
85 with Warnsw
; use Warnsw
;
87 with System
.Assertions
;
95 procedure Adjust_Global_Switches
;
96 -- There are various interactions between front-end switch settings,
97 -- including debug switch settings and target dependent parameters.
98 -- This procedure takes care of properly handling these interactions.
99 -- We do it after scanning out all the switches, so that we are not
100 -- depending on the order in which switches appear.
102 procedure Check_Bad_Body
(Unit_Node
: Node_Id
; Unit_Kind
: Node_Kind
);
103 -- Called to check whether a unit described by its compilation unit node
104 -- and kind has a bad body.
106 procedure Check_Rep_Info
;
107 -- Called when we are not generating code, to check if -gnatR was requested
108 -- and if so, explain that we will not be honoring the request.
110 procedure Post_Compilation_Validation_Checks
;
111 -- This procedure performs various validation checks that have to be left
112 -- to the end of the compilation process, after generating code but before
113 -- issuing error messages. In particular, these checks generally require
114 -- the information provided by the back end in back annotation of declared
115 -- entities (e.g. actual size and alignment values chosen by the back end).
117 procedure Read_JSON_Files_For_Repinfo
;
118 -- This procedure exercises the JSON parser of Repinfo by reading back the
119 -- JSON files generated by -gnatRjs in a previous compilation session. It
120 -- is intended to make sure that the JSON generator and the JSON parser are
121 -- kept synchronized when the JSON format evolves.
123 ----------------------------
124 -- Adjust_Global_Switches --
125 ----------------------------
127 procedure Adjust_Global_Switches
is
128 procedure SPARK_Library_Warning
(Kind
: String);
129 -- Issue a warning in GNATprove mode if the run-time library does not
130 -- fully support IEEE-754 floating-point semantics.
132 ---------------------------
133 -- SPARK_Library_Warning --
134 ---------------------------
136 procedure SPARK_Library_Warning
(Kind
: String) is
139 ("warning: run-time library may be configured incorrectly");
141 ("warning: (SPARK analysis requires support for " & Kind
& ')');
142 end SPARK_Library_Warning
;
144 -- Start of processing for Adjust_Global_Switches
147 -- Define pragma GNAT_Annotate as an alias of pragma Annotate, to be
148 -- able to work around bootstrap limitations with the old syntax of
149 -- pragma Annotate, and use pragma GNAT_Annotate in compiler sources
152 Map_Pragma_Name
(From
=> Name_Gnat_Annotate
, To
=> Name_Annotate
);
154 -- -gnatd.M enables Relaxed_RM_Semantics
156 if Debug_Flag_Dot_MM
then
157 Relaxed_RM_Semantics
:= True;
160 -- -gnatd.1 enables unnesting of subprograms
162 if Debug_Flag_Dot_1
then
163 Unnest_Subprogram_Mode
:= True;
166 -- -gnatd.u enables special C expansion mode
168 if Debug_Flag_Dot_U
then
169 Modify_Tree_For_C
:= True;
170 Transform_Function_Array
:= True;
173 -- -gnatd_A disables generation of ALI files
175 if Debug_Flag_Underscore_AA
then
176 Disable_ALI_File
:= True;
179 -- Set all flags required when generating C code
181 if Generate_C_Code
then
182 Modify_Tree_For_C
:= True;
183 Transform_Function_Array
:= True;
184 Unnest_Subprogram_Mode
:= True;
185 Building_Static_Dispatch_Tables
:= False;
186 Minimize_Expression_With_Actions
:= True;
187 Expand_Nonbinary_Modular_Ops
:= True;
189 -- Set operating mode to Generate_Code to benefit from full front-end
190 -- expansion (e.g. generics).
192 Operating_Mode
:= Generate_Code
;
194 -- Suppress alignment checks since we do not have access to alignment
195 -- info on the target.
197 Suppress_Options
.Suppress
(Alignment_Check
) := False;
200 -- -gnatd.E sets Error_To_Warning mode, causing selected error messages
201 -- to be treated as warnings instead of errors.
203 if Debug_Flag_Dot_EE
then
204 Error_To_Warning
:= True;
207 -- -gnatdJ sets Include_Subprogram_In_Messages, adding the related
208 -- subprogram as part of the error and warning messages.
210 if Debug_Flag_JJ
then
211 Include_Subprogram_In_Messages
:= True;
214 -- Disable CodePeer_Mode in Check_Syntax, since we need front-end
217 if Operating_Mode
= Check_Syntax
then
218 CodePeer_Mode
:= False;
221 -- SCIL mode needs to disable front-end inlining since the generated
222 -- trees (in particular order and consistency between specs compiled
223 -- as part of a main unit or as part of a with-clause) are causing
226 if Generate_SCIL
then
227 Front_End_Inlining
:= False;
230 -- Tune settings for optimal SCIL generation in CodePeer mode
232 if CodePeer_Mode
then
234 -- Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
235 -- compatible with CodePeer mode.
237 GNATprove_Mode
:= False;
238 Debug_Flag_Dot_FF
:= False;
240 -- Turn off length expansion. CodePeer has its own mechanism to
241 -- handle length attribute.
243 Debug_Flag_Dot_PP
:= True;
245 -- Turn off C tree generation, not compatible with CodePeer mode. We
246 -- do not expect this to happen in normal use, since both modes are
247 -- enabled by special tools, but it is useful to turn off these flags
248 -- this way when we are doing CodePeer tests on existing test suites
249 -- that may have -gnateg set, to avoid the need for special casing.
251 Modify_Tree_For_C
:= False;
252 Transform_Function_Array
:= False;
253 Generate_C_Code
:= False;
254 Unnest_Subprogram_Mode
:= False;
256 -- Turn off inlining, confuses CodePeer output and gains nothing
258 Front_End_Inlining
:= False;
259 Inline_Active
:= False;
261 -- Disable front-end optimizations, to keep the tree as close to the
262 -- source code as possible, and also to avoid inconsistencies between
263 -- trees when using different optimization switches.
265 Optimization_Level
:= 0;
267 -- Enable some restrictions systematically to simplify the generated
268 -- code (and ease analysis). Note that restriction checks are also
269 -- disabled in CodePeer mode, see Restrict.Check_Restriction, and
270 -- user specified Restrictions pragmas are ignored, see
271 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
273 Restrict
.Restrictions
.Set
(No_Exception_Registration
) := True;
274 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
275 Restrict
.Restrictions
.Set
(No_Task_Hierarchy
) := True;
276 Restrict
.Restrictions
.Set
(No_Abort_Statements
) := True;
277 Restrict
.Restrictions
.Set
(Max_Asynchronous_Select_Nesting
) := True;
278 Restrict
.Restrictions
.Value
(Max_Asynchronous_Select_Nesting
) := 0;
280 -- Enable pragma Ignore_Pragma (Global) to support legacy code. As a
281 -- consequence, Refined_Global pragma should be ignored as well, as
282 -- it is only allowed on a body when pragma Global is given for the
285 Set_Name_Table_Boolean3
(Name_Global
, True);
286 Set_Name_Table_Boolean3
(Name_Refined_Global
, True);
288 -- Suppress division by zero checks since they are handled
289 -- implicitly by CodePeer.
291 -- Turn off dynamic elaboration checks: generates inconsistencies in
292 -- trees between specs compiled as part of a main unit or as part of
295 -- Turn off alignment checks: these cannot be proved statically by
296 -- CodePeer and generate false positives.
298 -- Enable all other language checks
300 Suppress_Options
.Suppress
:=
301 (Alignment_Check
=> True,
302 Division_Check
=> True,
303 Elaboration_Check
=> True,
306 -- Need to enable dynamic elaboration checks to disable strict
307 -- static checking performed by gnatbind. We are at the same time
308 -- suppressing actual compile time elaboration checks to simplify
309 -- the generated code.
311 Dynamic_Elaboration_Checks
:= True;
313 -- Set STRICT mode for overflow checks if not set explicitly. This
314 -- prevents suppressing of overflow checks by default, in code down
317 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
318 Suppress_Options
.Overflow_Mode_General
:= Strict
;
319 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
322 -- CodePeer handles division and overflow checks directly, based on
323 -- the marks set by the frontend, hence no special expansion should
324 -- be performed in the frontend for division and overflow checks.
326 Backend_Divide_Checks_On_Target
:= True;
327 Backend_Overflow_Checks_On_Target
:= True;
329 -- Kill debug of generated code, since it messes up sloc values
331 Debug_Generated_Code
:= False;
333 -- Ditto for -gnateG which interacts badly with handling of pragma
334 -- Annotate in gnat2scil.
336 Generate_Processed_File
:= False;
338 -- Disable Exception_Extra_Info (-gnateE) which generates more
339 -- complex trees with no added value, and may confuse CodePeer.
341 Exception_Extra_Info
:= False;
343 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
344 -- to support source navigation.
348 -- Set operating mode to Generate_Code to benefit from full front-end
349 -- expansion (e.g. generics).
351 Operating_Mode
:= Generate_Code
;
353 -- We need SCIL generation of course
355 Generate_SCIL
:= True;
357 -- Enable assertions, since they give CodePeer valuable extra info
359 Assertions_Enabled
:= True;
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
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
;
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;
428 -- Enable some individual switches that are implied by relaxed RM
431 if Relaxed_RM_Semantics
then
432 Opt
.Allow_Integer_Address
:= True;
433 Overriding_Renamings
:= True;
434 Treat_Categorization_Errors_As_Warnings
:= True;
437 -- Enable GNATprove_Mode when using -gnatd.F switch
439 if Debug_Flag_Dot_FF
then
440 GNATprove_Mode
:= True;
443 -- GNATprove_Mode is also activated by default in the gnat2why
446 if GNATprove_Mode
then
448 -- Turn off CodePeer mode (which can be set via e.g. -gnatC or
449 -- -gnateC), not compatible with GNATprove mode.
451 CodePeer_Mode
:= False;
452 Generate_SCIL
:= False;
454 -- Turn off C tree generation, not compatible with GNATprove mode. We
455 -- do not expect this to happen in normal use, since both modes are
456 -- enabled by special tools, but it is useful to turn off these flags
457 -- this way when we are doing GNATprove tests on existing test suites
458 -- that may have -gnateg set, to avoid the need for special casing.
460 Modify_Tree_For_C
:= False;
461 Transform_Function_Array
:= False;
462 Generate_C_Code
:= False;
463 Unnest_Subprogram_Mode
:= False;
465 -- Turn off inlining, which would confuse formal verification output
468 Front_End_Inlining
:= False;
469 Inline_Active
:= False;
471 -- Issue warnings for failure to inline subprograms, as otherwise
472 -- expected in GNATprove mode for the local subprograms without
475 Ineffective_Inline_Warnings
:= True;
477 -- Do not issue warnings for possible propagation of exception.
478 -- GNATprove already issues messages about possible exceptions.
480 No_Warn_On_Non_Local_Exception
:= True;
481 Warn_On_Non_Local_Exception
:= False;
483 -- Disable front-end optimizations, to keep the tree as close to the
484 -- source code as possible, and also to avoid inconsistencies between
485 -- trees when using different optimization switches.
487 Optimization_Level
:= 0;
489 -- Enable some restrictions systematically to simplify the generated
490 -- code (and ease analysis).
492 Restrict
.Restrictions
.Set
(No_Initialize_Scalars
) := True;
494 -- Note: at this point we used to suppress various checks, but that
495 -- is not what we want. We need the semantic processing for these
496 -- checks (which will set flags like Do_Overflow_Check, showing the
497 -- points at which potential checks are required semantically). We
498 -- don't want the expansion associated with these checks, but that
499 -- happens anyway because this expansion is simply not done in the
500 -- SPARK version of the expander.
502 -- On the contrary, we need to enable explicitly all language checks,
503 -- as they may have been suppressed by the use of switch -gnatp.
505 Suppress_Options
.Suppress
:= (others => False);
507 -- Detect overflow on unconstrained floating-point types, such as
508 -- the predefined types Float, Long_Float and Long_Long_Float from
509 -- package Standard. Not necessary if float overflows are checked
510 -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
511 -- will be set in any case.
513 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
515 -- Set STRICT mode for overflow checks if not set explicitly. This
516 -- prevents suppressing of overflow checks by default, in code down
519 if Suppress_Options
.Overflow_Mode_General
= Not_Set
then
520 Suppress_Options
.Overflow_Mode_General
:= Strict
;
521 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
524 -- Kill debug of generated code, since it messes up sloc values
526 Debug_Generated_Code
:= False;
528 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
529 -- as it is needed for computing effects of subprograms in the formal
530 -- verification backend.
534 -- Set operating mode to Check_Semantics, but a light front-end
535 -- expansion is still performed.
537 Operating_Mode
:= Check_Semantics
;
539 -- Enable assertions, since they give valuable extra information for
540 -- formal verification.
542 Assertions_Enabled
:= True;
544 -- Disable validity checks, since it generates code raising
545 -- exceptions for invalid data, which confuses GNATprove. Invalid
546 -- data is directly detected by GNATprove's flow analysis.
548 Validity_Checks_On
:= False;
549 Check_Validity_Of_Parameters
:= False;
551 -- Turn off style check options since we are not interested in any
552 -- front-end warnings when we are getting SPARK output.
554 Reset_Style_Check_Options
;
556 -- Suppress the generation of name tables for enumerations, which are
557 -- not needed for formal verification, and fall outside the SPARK
558 -- subset (use of pointers).
560 Global_Discard_Names
:= True;
562 -- Suppress the expansion of tagged types and dispatching calls,
563 -- which lead to the generation of non-SPARK code (use of pointers),
564 -- which is more complex to formally verify than the original source.
566 Tagged_Type_Expansion
:= False;
568 -- Detect that the runtime library support for floating-point numbers
569 -- may not be compatible with SPARK analysis of IEEE-754 floats.
571 if Denorm_On_Target
= False then
572 SPARK_Library_Warning
("float subnormals");
574 elsif Machine_Rounds_On_Target
= False then
575 SPARK_Library_Warning
("float rounding");
577 elsif Signed_Zeros_On_Target
= False then
578 SPARK_Library_Warning
("signed zeros");
582 -- Set Configurable_Run_Time mode if system.ads flag set or if the
583 -- special debug flag -gnatdY is set.
585 if Targparm
.Configurable_Run_Time_On_Target
or Debug_Flag_YY
then
586 Configurable_Run_Time_Mode
:= True;
589 -- Set -gnatRm mode if debug flag A set
591 if Debug_Flag_AA
then
592 Back_Annotate_Rep_Info
:= True;
593 List_Representation_Info
:= 1;
594 List_Representation_Info_Mechanisms
:= True;
597 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
599 if Debug_Flag_Dot_A
then
600 Ttypes
.Target_Strict_Alignment
:= True;
603 -- Increase size of allocated entities if debug flag -gnatd.N is set
605 if Debug_Flag_Dot_NN
then
606 Atree
.Num_Extension_Nodes
:= Atree
.Num_Extension_Nodes
+ 1;
609 -- Disable static allocation of dispatch tables if -gnatd.t is enabled.
610 -- The front end's layout phase currently treats types that have
611 -- discriminant-dependent arrays as not being static even when a
612 -- discriminant constraint on the type is static, and this leads to
613 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
615 if Debug_Flag_Dot_T
then
616 Building_Static_Dispatch_Tables
:= False;
619 -- Flip endian mode if -gnatd8 set
622 Ttypes
.Bytes_Big_Endian
:= not Ttypes
.Bytes_Big_Endian
;
625 -- Set and check exception mechanism. This is only meaningful when
626 -- compiling, and in particular not meaningful for special modes used
627 -- for program analysis rather than compilation: CodePeer mode and
630 if Operating_Mode
= Generate_Code
631 and then not (CodePeer_Mode
or GNATprove_Mode
)
633 case Targparm
.Frontend_Exceptions_On_Target
is
635 case Targparm
.ZCX_By_Default_On_Target
is
638 ("Run-time library configured incorrectly");
640 ("(requesting support for Frontend ZCX exceptions)");
641 raise Unrecoverable_Error
;
644 Exception_Mechanism
:= Front_End_SJLJ
;
648 case Targparm
.ZCX_By_Default_On_Target
is
650 Exception_Mechanism
:= Back_End_ZCX
;
652 Exception_Mechanism
:= Back_End_SJLJ
;
657 -- Set proper status for overflow check mechanism
659 -- If already set (by -gnato or above in SPARK or CodePeer mode) then we
660 -- have nothing to do.
662 if Opt
.Suppress_Options
.Overflow_Mode_General
/= Not_Set
then
665 -- Otherwise set overflow mode defaults
668 -- Overflow checks are on by default (Suppress set False) except in
669 -- GNAT_Mode, where we want them off by default (we are not ready to
670 -- enable overflow checks in the compiler yet, for one thing the case
671 -- of 64-bit checks needs System.Arith_64 which is not a compiler
672 -- unit and it is a pain to try to include it in the compiler.
674 Suppress_Options
.Suppress
(Overflow_Check
) := GNAT_Mode
;
676 -- Set appropriate default overflow handling mode. Note: at present
677 -- we set STRICT in all three of the following cases. They are
678 -- separated because in the future we may make different choices.
680 -- By default set STRICT mode if -gnatg in effect
683 Suppress_Options
.Overflow_Mode_General
:= Strict
;
684 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
686 -- If we have backend divide and overflow checks, then by default
687 -- overflow checks are STRICT. Historically this code used to also
688 -- activate overflow checks, although no target currently has these
689 -- flags set, so this was dead code anyway.
691 elsif Targparm
.Backend_Divide_Checks_On_Target
693 Targparm
.Backend_Overflow_Checks_On_Target
695 Suppress_Options
.Overflow_Mode_General
:= Strict
;
696 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
698 -- Otherwise for now, default is STRICT mode. This may change in the
699 -- future, but for now this is the compatible behavior with previous
703 Suppress_Options
.Overflow_Mode_General
:= Strict
;
704 Suppress_Options
.Overflow_Mode_Assertions
:= Strict
;
708 -- Set default for atomic synchronization. As this synchronization
709 -- between atomic accesses can be expensive, and not typically needed
710 -- on some targets, an optional target parameter can turn the option
711 -- off. Note Atomic Synchronization is implemented as check.
713 Suppress_Options
.Suppress
(Atomic_Synchronization
) :=
714 not Atomic_Sync_Default_On_Target
;
716 -- Set default for Alignment_Check, if we are on a machine with non-
717 -- strict alignment, then we suppress this check, since it is over-
718 -- zealous for such machines.
720 if not Ttypes
.Target_Strict_Alignment
then
721 Suppress_Options
.Suppress
(Alignment_Check
) := True;
724 -- Set switch indicating if back end can handle limited types, and
725 -- guarantee that no incorrect copies are made (e.g. in the context
726 -- of an if or case expression).
728 -- Debug flag -gnatd.L decisively sets usage on
730 if Debug_Flag_Dot_LL
then
731 Back_End_Handles_Limited_Types
:= True;
733 -- If no debug flag, usage off for SCIL cases
735 elsif Generate_SCIL
then
736 Back_End_Handles_Limited_Types
:= False;
738 -- Otherwise normal gcc back end, for now still turn flag off by
739 -- default, since there are unresolved problems in the front end.
742 Back_End_Handles_Limited_Types
:= False;
745 -- If the inlining level has not been set by the user, compute it from
746 -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
748 if Inline_Level
= 0 then
749 if Optimization_Level
< 3 then
756 -- Treat -gnatn as equivalent to -gnatN for non-GCC targets
758 if Inline_Active
and not Front_End_Inlining
then
760 -- We really should have a tag for this, what if we added a new
761 -- back end some day, it would not be true for this test, but it
762 -- would be non-GCC, so this is a bit troublesome ???
764 Front_End_Inlining
:= Generate_C_Code
;
767 -- Set back-end inlining indication
771 -- No back-end inlining available on C generation
775 -- No back-end inlining in GNATprove mode, since it just confuses
776 -- the formal verification process.
778 and then not GNATprove_Mode
780 -- No back-end inlining if front-end inlining explicitly enabled.
781 -- Done to minimize the output differences to customers still using
782 -- this deprecated switch; in addition, this behavior reduces the
783 -- output differences in old tests.
785 and then not Front_End_Inlining
787 -- Back-end inlining is disabled if debug flag .z is set
789 and then not Debug_Flag_Dot_Z
;
791 -- Output warning if -gnateE specified and cannot be supported
793 if Exception_Extra_Info
794 and then Restrict
.No_Exception_Handlers_Set
798 ("warning: extra exception information (-gnateE) was specified");
801 ("warning: this capability is not available in this configuration");
806 -- Enable or disable the support for 128-bit types. It is automatically
807 -- enabled if the back end supports them, unless -gnatd.H is specified.
809 Enable_128bit_Types
:= Ttypes
.Standard_Long_Long_Long_Integer_Size
= 128;
811 if Enable_128bit_Types
and then Debug_Flag_Dot_HH
then
812 Enable_128bit_Types
:= False;
814 Ttypes
.Standard_Long_Long_Long_Integer_Size
:=
815 Ttypes
.Standard_Long_Long_Integer_Size
;
816 Ttypes
.System_Max_Integer_Size
:=
817 Ttypes
.Standard_Long_Long_Integer_Size
;
818 Ttypes
.System_Max_Binary_Modulus_Power
:=
819 Ttypes
.Standard_Long_Long_Integer_Size
;
822 -- Finally capture adjusted value of Suppress_Options as the initial
823 -- value for Scope_Suppress, which will be modified as we move from
824 -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
826 Sem
.Scope_Suppress
:= Opt
.Suppress_Options
;
827 end Adjust_Global_Switches
;
833 procedure Check_Bad_Body
(Unit_Node
: Node_Id
; Unit_Kind
: Node_Kind
) is
834 Fname
: File_Name_Type
;
836 procedure Bad_Body_Error
(Msg
: String);
837 -- Issue message for bad body found
843 procedure Bad_Body_Error
(Msg
: String) is
845 Error_Msg_N
(Msg
, Unit_Node
);
846 Error_Msg_File_1
:= Fname
;
847 Error_Msg_N
("remove incorrect body in file{!", Unit_Node
);
852 Sname
: Unit_Name_Type
;
853 Src_Ind
: Source_File_Index
;
855 -- Start of processing for Check_Bad_Body
858 -- Nothing to do if we are only checking syntax, because we don't know
859 -- enough to know if we require or forbid a body in this case.
861 if Operating_Mode
= Check_Syntax
then
865 -- Check for body not allowed
867 if (Unit_Kind
= N_Package_Declaration
868 and then not Body_Required
(Unit_Node
))
869 or else (Unit_Kind
= N_Generic_Package_Declaration
870 and then not Body_Required
(Unit_Node
))
871 or else Unit_Kind
= N_Package_Renaming_Declaration
872 or else Unit_Kind
= N_Subprogram_Renaming_Declaration
873 or else Nkind
(Original_Node
(Unit
(Unit_Node
)))
874 in N_Generic_Instantiation
876 Sname
:= Unit_Name
(Main_Unit
);
878 -- If we do not already have a body name, then get the body name
880 if not Is_Body_Name
(Sname
) then
881 Sname
:= Get_Body_Name
(Sname
);
884 Fname
:= Get_File_Name
(Sname
, Subunit
=> False);
885 Src_Ind
:= Load_Source_File
(Fname
);
887 -- Case where body is present and it is not a subunit. Exclude the
888 -- subunit case, because it has nothing to do with the package we are
889 -- compiling. It is illegal for a child unit and a subunit with the
890 -- same expanded name (RM 10.2(9)) to appear together in a partition,
891 -- but there is nothing to stop a compilation environment from having
892 -- both, and the test here simply allows that. If there is an attempt
893 -- to include both in a partition, this is diagnosed at bind time. In
894 -- Ada 83 mode this is not a warning case.
896 -- Note that in general we do not give the message if the file in
897 -- question does not look like a body. This includes weird cases,
898 -- but in particular means that if the file is just a No_Body pragma,
899 -- then we won't give the message (that's the whole point of this
900 -- pragma, to be used this way and to cause the body file to be
901 -- ignored in this context).
903 if Src_Ind
> No_Source_File
904 and then Source_File_Is_Body
(Src_Ind
)
906 Errout
.Finalize
(Last_Call
=> False);
908 Error_Msg_Unit_1
:= Sname
;
910 -- Ada 83 case of a package body being ignored. This is not an
911 -- error as far as the Ada 83 RM is concerned, but it is almost
912 -- certainly not what is wanted so output a warning. Give this
913 -- message only if there were no errors, since otherwise it may
914 -- be incorrect (we may have misinterpreted a junk spec as not
915 -- needing a body when it really does).
917 if Unit_Kind
= N_Package_Declaration
918 and then Ada_Version
= Ada_83
919 and then Operating_Mode
= Generate_Code
920 and then Distribution_Stub_Mode
/= Generate_Caller_Stub_Body
921 and then not Compilation_Errors
924 ("package $$ does not require a body??", Unit_Node
);
925 Error_Msg_File_1
:= Fname
;
926 Error_Msg_N
("body in file{ will be ignored??", Unit_Node
);
928 -- Ada 95 cases of a body file present when no body is
929 -- permitted. This we consider to be an error.
932 -- For generic instantiations, we never allow a body
934 if Nkind
(Original_Node
(Unit
(Unit_Node
))) in
935 N_Generic_Instantiation
938 ("generic instantiation for $$ does not allow a body");
940 -- A library unit that is a renaming never allows a body
942 elsif Unit_Kind
in N_Renaming_Declaration
then
944 ("renaming declaration for $$ does not allow a body!");
946 -- Remaining cases are packages and generic packages. Here
947 -- we only do the test if there are no previous errors,
948 -- because if there are errors, they may lead us to
949 -- incorrectly believe that a package does not allow a
950 -- body when in fact it does.
952 elsif not Compilation_Errors
then
953 if Unit_Kind
= N_Package_Declaration
then
955 ("package $$ does not allow a body!");
957 elsif Unit_Kind
= N_Generic_Package_Declaration
then
959 ("generic package $$ does not allow a body!");
972 procedure Check_Rep_Info
is
974 if List_Representation_Info
/= 0
975 or else List_Representation_Info_Mechanisms
980 ("cannot generate representation information, no code generated");
987 ----------------------------------------
988 -- Post_Compilation_Validation_Checks --
989 ----------------------------------------
991 procedure Post_Compilation_Validation_Checks
is
993 -- Validate alignment check warnings. In some cases we generate warnings
994 -- about possible alignment errors because we don't know the alignment
995 -- that will be chosen by the back end. This routine is in charge of
996 -- getting rid of those warnings if we can tell they are not needed.
998 Checks
.Validate_Alignment_Check_Warnings
;
1000 -- Validate compile time warnings and errors (using the values for size
1001 -- and alignment annotated by the backend where possible). We need to
1002 -- unlock temporarily these tables to reanalyze their expression.
1008 Sem_Prag
.Validate_Compile_Time_Warning_Errors
;
1014 -- Validate unchecked conversions (using the values for size and
1015 -- alignment annotated by the backend where possible).
1017 Sem_Ch13
.Validate_Unchecked_Conversions
;
1019 -- Validate address clauses (again using alignment values annotated
1020 -- by the backend where possible).
1022 Sem_Ch13
.Validate_Address_Clauses
;
1023 end Post_Compilation_Validation_Checks
;
1025 -----------------------------------
1026 -- Read_JSON_Files_For_Repinfo --
1027 -----------------------------------
1029 procedure Read_JSON_Files_For_Repinfo
is
1031 -- This is the same loop construct as in Repinfo.List_Rep_Info
1033 for U
in Main_Unit
.. Last_Unit
loop
1034 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1036 Nam
: constant String :=
1038 (File_Name
(Source_Index
(U
))) & ".json";
1039 Namid
: constant File_Name_Type
:= Name_Enter
(Nam
);
1040 Index
: constant Source_File_Index
:= Load_Config_File
(Namid
);
1043 if Index
= No_Source_File
then
1044 Write_Str
("cannot locate ");
1046 raise Unrecoverable_Error
;
1049 Repinfo
.Input
.Read_JSON_Stream
(Source_Text
(Index
).all, Nam
);
1051 when Repinfo
.Input
.Invalid_JSON_Stream
=>
1052 raise Unrecoverable_Error
;
1056 end Read_JSON_Files_For_Repinfo
;
1060 Back_End_Mode
: Back_End
.Back_End_Mode_Type
;
1061 Ecode
: Exit_Code_Type
;
1063 Main_Unit_Kind
: Node_Kind
;
1064 -- Kind of main compilation unit node
1066 Main_Unit_Node
: Node_Id
;
1067 -- Compilation unit node for main unit
1069 -- Start of processing for Gnat1drv
1072 -- This inner block is set up to catch assertion errors and constraint
1073 -- errors. Since the code for handling these errors can cause another
1074 -- exception to be raised (namely Unrecoverable_Error), we need two
1075 -- nested blocks, so that the outer one handles unrecoverable error.
1078 -- Initialize all packages. For the most part, these initialization
1079 -- calls can be made in any order. Exceptions are as follows:
1081 -- Lib.Initialize needs to be called before Scan_Compiler_Arguments,
1082 -- because it initializes a table filled by Scan_Compiler_Arguments.
1084 -- Atree.Initialize needs to be called after Scan_Compiler_Arguments,
1085 -- because the value specified by the -gnaten switch is used by
1086 -- Atree.Initialize.
1091 Lib
.Xref
.Initialize
;
1092 Scan_Compiler_Arguments
;
1093 Osint
.Add_Default_Search_Dirs
;
1110 Sem_Ch12
.Initialize
;
1111 Sem_Ch13
.Initialize
;
1112 Sem_Elim
.Initialize
;
1113 Sem_Eval
.Initialize
;
1114 Sem_Type
.Init_Interp_Tables
;
1116 -- Capture compilation date and time
1118 Opt
.Compilation_Time
:= System
.OS_Lib
.Current_Time_String
;
1120 -- Get the target parameters only when -gnats is not used, to avoid
1121 -- failing when there is no default runtime.
1123 if Operating_Mode
/= Check_Syntax
then
1125 -- Acquire target parameters from system.ads (package System source)
1127 Targparm_Acquire
: declare
1129 S
: Source_File_Index
;
1133 Name_Buffer
(1 .. 10) := "system.ads";
1136 S
:= Load_Source_File
(N
);
1138 -- Failed to read system.ads, fatal error
1140 if S
= No_Source_File
then
1142 ("fatal error, run-time library not installed correctly");
1143 Write_Line
("cannot locate file system.ads");
1144 raise Unrecoverable_Error
;
1146 elsif S
= No_Access_To_Source_File
then
1148 ("fatal error, run-time library not installed correctly");
1149 Write_Line
("no read access for file system.ads");
1150 raise Unrecoverable_Error
;
1152 -- Read system.ads successfully, remember its source index
1155 System_Source_File_Index
:= S
;
1158 -- Call to get target parameters. Note that the actual interface
1159 -- routines are in Tbuild. They can't be in this procedure because
1160 -- of accessibility issues.
1162 Targparm
.Get_Target_Parameters
1163 (System_Text
=> Source_Text
(S
),
1164 Source_First
=> Source_First
(S
),
1165 Source_Last
=> Source_Last
(S
),
1166 Make_Id
=> Tbuild
.Make_Id
'Access,
1167 Make_SC
=> Tbuild
.Make_SC
'Access,
1168 Set_NOD
=> Tbuild
.Set_NOD
'Access,
1169 Set_NSA
=> Tbuild
.Set_NSA
'Access,
1170 Set_NUA
=> Tbuild
.Set_NUA
'Access,
1171 Set_NUP
=> Tbuild
.Set_NUP
'Access);
1173 -- Acquire configuration pragma information from Targparm
1175 Restrict
.Restrictions
:= Targparm
.Restrictions_On_Target
;
1176 end Targparm_Acquire
;
1179 -- Perform various adjustments and settings of global switches
1181 Adjust_Global_Switches
;
1183 -- Output copyright notice if full list mode unless we have a list
1184 -- file, in which case we defer this so that it is output in the file.
1186 if (Verbose_Mode
or else (Full_List
and then Full_List_File_Name
= null))
1188 -- Debug flag gnatd7 suppresses this copyright notice
1190 and then not Debug_Flag_7
1193 Write_Str
("GNAT ");
1194 Write_Str
(Gnat_Version_String
);
1196 Write_Str
("Copyright 1992-" & Current_Year
1197 & ", Free Software Foundation, Inc.");
1201 -- Check we do not have more than one source file, this happens only in
1202 -- the case where the driver is called directly, it cannot happen when
1203 -- gnat1 is invoked from gcc in the normal case.
1205 if Osint
.Number_Of_Files
/= 1 then
1207 -- In GNATprove mode, gcc is not called, so we may end up with
1208 -- switches wrongly interpreted as source file names when they are
1209 -- written by mistake without a starting hyphen. Issue a specific
1210 -- error message but do not print the internal 'usage' message.
1212 if GNATprove_Mode
then
1214 ("one of the following is not a valid switch or source file "
1216 Osint
.Dump_Command_Line_Source_File_Names
;
1222 Osint
.Fail
("you must provide one source file");
1224 elsif Usage_Requested
then
1228 -- Generate target dependent output file if requested
1230 if Target_Dependent_Info_Write_Name
/= null then
1231 Set_Targ
.Write_Target_Dependent_Values
;
1234 -- Call the front end
1236 Original_Operating_Mode
:= Operating_Mode
;
1239 -- Exit with errors if the main source could not be parsed
1241 if Sinput
.Main_Source_File
<= No_Source_File
then
1242 Errout
.Finalize
(Last_Call
=> True);
1243 Errout
.Output_Messages
;
1244 Exit_Program
(E_Errors
);
1247 Main_Unit_Node
:= Cunit
(Main_Unit
);
1248 Main_Unit_Kind
:= Nkind
(Unit
(Main_Unit_Node
));
1250 Check_Bad_Body
(Main_Unit_Node
, Main_Unit_Kind
);
1252 -- In CodePeer mode we always delete old SCIL files before regenerating
1253 -- new ones, in case of e.g. errors, and also to remove obsolete scilx
1254 -- files generated by CodePeer itself.
1256 if CodePeer_Mode
then
1257 Comperr
.Delete_SCIL_Files
;
1260 -- Ditto for old C files before regenerating new ones
1262 if Generate_C_Code
then
1267 -- Exit if compilation errors detected
1269 Errout
.Finalize
(Last_Call
=> False);
1271 if Compilation_Errors
then
1273 Post_Compilation_Validation_Checks
;
1274 Errout
.Finalize
(Last_Call
=> True);
1275 Errout
.Output_Messages
;
1278 -- Generate ALI file if specially requested
1280 if Opt
.Force_ALI_File
then
1281 Write_ALI
(Object
=> False);
1284 Exit_Program
(E_Errors
);
1287 -- Set Generate_Code on main unit and its spec. We do this even if are
1288 -- not generating code, since Lib-Writ uses this to determine which
1289 -- units get written in the ali file.
1291 Set_Generate_Code
(Main_Unit
);
1293 -- If we have a corresponding spec, and it comes from source or it is
1294 -- not a generated spec for a child subprogram body, then we need object
1295 -- code for the spec unit as well.
1297 if Nkind
(Unit
(Main_Unit_Node
)) in N_Unit_Body
1298 and then not Acts_As_Spec
(Main_Unit_Node
)
1300 if Nkind
(Unit
(Main_Unit_Node
)) = N_Subprogram_Body
1301 and then not Comes_From_Source
(Library_Unit
(Main_Unit_Node
))
1306 (Get_Cunit_Unit_Number
(Library_Unit
(Main_Unit_Node
)));
1310 -- Case of no code required to be generated, exit indicating no error
1312 if Original_Operating_Mode
= Check_Syntax
then
1314 Errout
.Finalize
(Last_Call
=> True);
1315 Errout
.Output_Messages
;
1319 -- Use a goto instead of calling Exit_Program so that finalization
1322 goto End_Of_Program
;
1324 elsif Original_Operating_Mode
= Check_Semantics
then
1325 Back_End_Mode
:= Declarations_Only
;
1327 -- All remaining cases are cases in which the user requested that code
1328 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1329 -- can in fact satisfy this request.
1331 -- Cannot generate code if someone has turned off code generation for
1332 -- any reason at all. We will try to figure out a reason below.
1334 elsif Operating_Mode
/= Generate_Code
then
1335 Back_End_Mode
:= Skip
;
1337 -- We can generate code for a subprogram body unless there were missing
1338 -- subunits. Note that we always generate code for all generic units (a
1339 -- change from some previous versions of GNAT).
1341 elsif Main_Unit_Kind
= N_Subprogram_Body
1342 and then not Subunits_Missing
1344 Back_End_Mode
:= Generate_Object
;
1346 -- We can generate code for a package body unless there are subunits
1347 -- missing (note that we always generate code for generic units, which
1348 -- is a change from some earlier versions of GNAT).
1350 elsif Main_Unit_Kind
= N_Package_Body
and then not Subunits_Missing
then
1351 Back_End_Mode
:= Generate_Object
;
1353 -- We can generate code for a package declaration or a subprogram
1354 -- declaration only if it does not required a body.
1356 elsif Main_Unit_Kind
in N_Package_Declaration | N_Subprogram_Declaration
1358 (not Body_Required
(Main_Unit_Node
)
1359 or else Distribution_Stub_Mode
= Generate_Caller_Stub_Body
)
1361 Back_End_Mode
:= Generate_Object
;
1363 -- We can generate code for a generic package declaration of a generic
1364 -- subprogram declaration only if does not require a body.
1366 elsif Main_Unit_Kind
in
1367 N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration
1368 and then not Body_Required
(Main_Unit_Node
)
1370 Back_End_Mode
:= Generate_Object
;
1372 -- Compilation units that are renamings do not require bodies, so we can
1373 -- generate code for them.
1375 elsif Main_Unit_Kind
in N_Package_Renaming_Declaration |
1376 N_Subprogram_Renaming_Declaration
1378 Back_End_Mode
:= Generate_Object
;
1380 -- Compilation units that are generic renamings do not require bodies
1381 -- so we can generate code for them.
1383 elsif Main_Unit_Kind
in N_Generic_Renaming_Declaration
then
1384 Back_End_Mode
:= Generate_Object
;
1386 -- It is not an error to analyze in CodePeer mode a spec which requires
1387 -- a body, in order to generate SCIL for this spec.
1389 elsif CodePeer_Mode
then
1390 Back_End_Mode
:= Generate_Object
;
1392 -- Differentiate use of -gnatceg to generate a C header from an Ada spec
1393 -- to the CCG case (standard.h found) where C code generation should
1394 -- only be performed on full units.
1396 elsif Generate_C_Code
then
1398 Name_Buffer
(1 .. Name_Len
) := "standard.h";
1400 if Find_File
(Name_Find
, Osint
.Source
, Full_Name
=> True) = No_File
1402 Back_End_Mode
:= Generate_Object
;
1404 Back_End_Mode
:= Skip
;
1407 -- It is not an error to analyze in GNATprove mode a spec which requires
1408 -- a body, when the body is not available. During frame condition
1409 -- generation, the corresponding ALI file is generated. During
1410 -- analysis, the spec is analyzed.
1412 elsif GNATprove_Mode
then
1413 Back_End_Mode
:= Declarations_Only
;
1415 -- In all other cases (specs which have bodies, generics, and bodies
1416 -- where subunits are missing), we cannot generate code and we generate
1417 -- a warning message. Note that generic instantiations are gone at this
1418 -- stage since they have been replaced by their instances.
1421 Back_End_Mode
:= Skip
;
1424 -- At this stage Back_End_Mode is set to indicate if the backend should
1425 -- be called to generate code. If it is Skip, then code generation has
1426 -- been turned off, even though code was requested by the original
1427 -- command. This is not an error from the user point of view, but it is
1428 -- an error from the point of view of the gcc driver, so we must exit
1429 -- with an error status.
1431 -- We generate an informative message (from the gcc point of view, it
1432 -- is an error message, but from the users point of view this is not an
1433 -- error, just a consequence of compiling something that cannot
1436 if Back_End_Mode
= Skip
then
1438 -- An ignored Ghost unit is rewritten into a null statement because
1439 -- it must not produce an ALI or object file. Do not emit any errors
1440 -- related to code generation because the unit does not exist.
1442 if Is_Ignored_Ghost_Unit
(Main_Unit_Node
) then
1444 -- Exit the gnat driver with success, otherwise external builders
1445 -- such as gnatmake and gprbuild will treat the compilation of an
1446 -- ignored Ghost unit as a failure. Note that this will produce
1447 -- an empty object file for the unit.
1451 -- Otherwise the unit is missing a crucial piece that prevents code
1458 Write_Str
("cannot generate code for file ");
1459 Write_Name
(Unit_File_Name
(Main_Unit
));
1461 if Subunits_Missing
then
1462 Write_Str
(" (missing subunits)");
1465 -- Force generation of ALI file, for backward compatibility
1467 Opt
.Force_ALI_File
:= True;
1469 elsif Main_Unit_Kind
= N_Subunit
then
1470 Write_Str
(" (subunit)");
1473 -- Do not generate an ALI file in this case, because it would
1474 -- become obsolete when the parent is compiled, and thus
1475 -- confuse tools such as gnatfind.
1477 elsif Main_Unit_Kind
= N_Subprogram_Declaration
then
1478 Write_Str
(" (subprogram spec)");
1481 -- Generic package body in GNAT implementation mode
1483 elsif Main_Unit_Kind
= N_Package_Body
and then GNAT_Mode
then
1484 Write_Str
(" (predefined generic)");
1487 -- Force generation of ALI file, for backward compatibility
1489 Opt
.Force_ALI_File
:= True;
1491 -- Only other case is a package spec
1494 Write_Str
(" (package spec)");
1499 Set_Standard_Output
;
1501 Post_Compilation_Validation_Checks
;
1502 Errout
.Finalize
(Last_Call
=> True);
1503 Errout
.Output_Messages
;
1506 -- Generate ALI file if specially requested, or for missing subunits,
1507 -- subunits or predefined generic. For ignored ghost code, the object
1508 -- file IS generated, so Object should be True, and since the object
1509 -- file is generated, we need to generate the ALI file. We never want
1510 -- an object file without an ALI file.
1512 if Is_Ignored_Ghost_Unit
(Main_Unit_Node
)
1513 or else Opt
.Force_ALI_File
1515 Write_ALI
(Object
=> Is_Ignored_Ghost_Unit
(Main_Unit_Node
));
1521 -- Exit the driver with an appropriate status indicator. This will
1522 -- generate an empty object file for ignored Ghost units, otherwise
1523 -- no object file will be generated.
1525 Exit_Program
(Ecode
);
1528 -- In -gnatc mode we only do annotation if -gnatR is also set, or if
1529 -- -gnatwz is enabled (default setting) and there is an unchecked
1530 -- conversion that involves a type whose size is not statically known,
1531 -- as indicated by Back_Annotate_Rep_Info being set to True.
1533 -- We don't call for annotations on a subunit, because to process those
1534 -- the back end requires that the parent(s) be properly compiled.
1536 -- Annotation is suppressed for targets where front-end layout is
1537 -- enabled, because the front end determines representations.
1539 -- A special back end is always called in CodePeer and GNATprove modes,
1540 -- unless this is a subunit.
1542 if Back_End_Mode
= Declarations_Only
1544 (not (Back_Annotate_Rep_Info
or Generate_SCIL
or GNATprove_Mode
)
1545 or else Main_Unit_Kind
= N_Subunit
)
1547 Post_Compilation_Validation_Checks
;
1548 Errout
.Finalize
(Last_Call
=> True);
1549 Errout
.Output_Messages
;
1550 Write_ALI
(Object
=> False);
1554 if not (Generate_SCIL
or GNATprove_Mode
) then
1561 -- Ensure that we properly register a dependency on system.ads, since
1562 -- even if we do not semantically depend on this, Targparm has read
1563 -- system parameters from the system.ads file.
1565 Lib
.Writ
.Ensure_System_Dependency
;
1567 -- Add dependencies, if any, on preprocessing data file and on
1568 -- preprocessing definition file(s).
1570 Prepcomp
.Add_Dependencies
;
1572 if GNATprove_Mode
then
1574 -- In GNATprove mode we're writing the ALI much earlier than usual
1575 -- as flow analysis needs the file present in order to append its
1576 -- own globals to it.
1578 -- Note: In GNATprove mode, an "object" file is always generated as
1579 -- the result of calling gnat1 or gnat2why, although this is not the
1580 -- same as the object file produced for compilation.
1582 Write_ALI
(Object
=> True);
1585 -- Some back ends (for instance Gigi) are known to rely on SCOs for code
1586 -- generation. Make sure they are available.
1588 if Generate_SCO
then
1589 Par_SCO
.SCO_Record_Filtered
;
1592 -- If -gnatd_j is specified, exercise the JSON parser of Repinfo
1594 if Debug_Flag_Underscore_J
then
1595 Read_JSON_Files_For_Repinfo
;
1598 -- Back end needs to explicitly unlock tables it needs to touch
1612 -- Here we call the back end to generate the output code
1614 Generating_Code
:= True;
1615 Back_End
.Call_Back_End
(Back_End_Mode
);
1617 -- Once the backend is complete, we unlock the names table. This call
1618 -- allows a few extra entries, needed for example for the file name
1619 -- for the library file output.
1623 -- Generate the call-graph output of dispatching calls
1625 Exp_CG
.Generate_CG_Output
;
1627 -- Perform post compilation validation checks
1629 Post_Compilation_Validation_Checks
;
1631 -- Now we complete output of errors, rep info and the tree info. These
1632 -- are delayed till now, since it is perfectly possible for gigi to
1633 -- generate errors, modify the tree (in particular by setting flags
1634 -- indicating that elaboration is required, and also to back annotate
1635 -- representation information for List_Rep_Info).
1637 Errout
.Finalize
(Last_Call
=> True);
1638 Errout
.Output_Messages
;
1639 Repinfo
.List_Rep_Info
(Ttypes
.Bytes_Big_Endian
);
1640 Inline
.List_Inlining_Info
;
1642 -- Only write the library if the backend did not generate any error
1643 -- messages. Otherwise signal errors to the driver program so that
1644 -- there will be no attempt to generate an object file.
1646 if Compilation_Errors
then
1648 Exit_Program
(E_Errors
);
1651 if not GNATprove_Mode
then
1652 Write_ALI
(Object
=> (Back_End_Mode
= Generate_Object
));
1655 if not Compilation_Errors
then
1657 -- In case of ada backends, we need to make sure that the generated
1658 -- object file has a timestamp greater than the ALI file. We do this
1659 -- to make gnatmake happy when checking the ALI and obj timestamps,
1660 -- where it expects the object file being written after the ali file.
1662 -- Gnatmake's assumption is true for gcc platforms where the gcc
1663 -- wrapper needs to call the assembler after calling gnat1, but is
1664 -- not true for ada backends, where the object files are created
1665 -- directly by gnat1 (so are created before the ali file).
1667 Back_End
.Gen_Or_Update_Object_File
;
1670 -- Generate tree after writing the ALI file, since Write_ALI may in
1671 -- fact result in further tree decoration from the original tree file.
1672 -- Note that we dump the tree just before generating it, so that the
1673 -- dump will exactly reflect what is written out.
1677 -- Finalize name table and we are all done
1682 -- Handle fatal internal compiler errors
1684 when Rtsfind
.RE_Not_Available
=>
1685 Comperr
.Compiler_Abort
("RE_Not_Available");
1687 when System
.Assertions
.Assert_Failure
=>
1688 Comperr
.Compiler_Abort
("Assert_Failure");
1690 when Constraint_Error
=>
1691 Comperr
.Compiler_Abort
("Constraint_Error");
1693 when Program_Error
=>
1694 Comperr
.Compiler_Abort
("Program_Error");
1696 -- Assume this is a bug. If it is real, the message will in any case
1697 -- say Storage_Error, giving a strong hint.
1699 when Storage_Error
=>
1700 Comperr
.Compiler_Abort
("Storage_Error");
1702 when Unrecoverable_Error
=>
1706 Comperr
.Compiler_Abort
("exception");
1711 if Debug_Flag_Dot_AA
then
1712 Atree
.Print_Statistics
;
1715 -- The outer exception handler handles an unrecoverable error
1718 when Unrecoverable_Error
=>
1719 Errout
.Finalize
(Last_Call
=> True);
1720 Errout
.Output_Messages
;
1723 Write_Str
("compilation abandoned");
1726 Set_Standard_Output
;
1729 Exit_Program
(E_Errors
);