1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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;
29 with Csets; use Csets;
30 with Debug; use Debug;
32 with Errout; use Errout;
35 with Fname; use Fname;
36 with Fname.UF; use Fname.UF;
38 with Gnatvsn; use Gnatvsn;
42 with Lib.Writ; use Lib.Writ;
44 with Namet; use Namet;
47 with Osint; use Osint;
48 with Output; use Output;
51 with Repinfo; use Repinfo;
62 with Sinfo; use Sinfo;
63 with Sinput.L; use Sinput.L;
65 with Sprint; use Sprint;
67 with Stylesw; use Stylesw;
68 with Targparm; use Targparm;
70 with Treepr; use Treepr;
72 with Types; use Types;
73 with Uintp; use Uintp;
74 with Uname; use Uname;
77 with Validsw; use Validsw;
79 with System.Assertions;
82 Main_Unit_Node : Node_Id;
83 -- Compilation unit node for main unit
85 Main_Kind : Node_Kind;
86 -- Kind of main compilation unit node
88 Back_End_Mode : Back_End.Back_End_Mode_Type;
89 -- Record back end mode
91 procedure Adjust_Global_Switches;
92 -- There are various interactions between front end switch settings,
93 -- including debug switch settings and target dependent parameters.
94 -- This procedure takes care of properly handling these interactions.
95 -- We do it after scanning out all the switches, so that we are not
96 -- depending on the order in which switches appear.
98 procedure Check_Bad_Body;
99 -- Called to check if the unit we are compiling has a bad body
101 procedure Check_Rep_Info;
102 -- Called when we are not generating code, to check if -gnatR was requested
103 -- and if so, explain that we will not be honoring the request.
105 procedure Check_Library_Items;
106 -- For debugging -- checks the behavior of Walk_Library_Items
107 pragma Warnings (Off, Check_Library_Items);
108 -- In case the call below is commented out
110 ----------------------------
111 -- Adjust_Global_Switches --
112 ----------------------------
114 procedure Adjust_Global_Switches is
116 -- Debug flag -gnatd.I is a synonym for Generate_SCIL and requires code
120 and then Operating_Mode = Generate_Code
122 Generate_SCIL := True;
125 -- Set ASIS mode if -gnatt and -gnatc are set
127 if Operating_Mode = Check_Semantics and then Tree_Output then
130 -- Turn off inlining in ASIS mode, since ASIS cannot handle the extra
131 -- information in the trees caused by inlining being active.
133 -- More specifically, the tree seems to be malformed from the ASIS
134 -- point of view if -gnatc and -gnatn appear together???
136 Inline_Active := False;
138 -- Turn off SCIL generation in ASIS mode, since SCIL requires front-
141 Generate_SCIL := False;
144 -- SCIL mode needs to disable front-end inlining since the generated
145 -- trees (in particular order and consistency between specs compiled
146 -- as part of a main unit or as part of a with-clause) are causing
149 if Generate_SCIL then
150 Front_End_Inlining := False;
153 -- Tune settings for optimal SCIL generation in CodePeer_Mode
155 if CodePeer_Mode then
157 -- Turn off inlining, confuses CodePeer output and gains nothing
159 Front_End_Inlining := False;
160 Inline_Active := False;
162 -- Turn off ASIS mode: incompatible with front-end expansion
166 -- Disable front-end optimizations, to keep the tree as close to the
167 -- source code as possible, and also to avoid inconsistencies between
168 -- trees when using different optimization switches.
170 Optimization_Level := 0;
172 -- Disable specific expansions for Restrictions pragmas to avoid
173 -- tree inconsistencies between compilations with different pragmas
174 -- that will cause different SCIL files to be generated for the
177 Treat_Restrictions_As_Warnings := True;
179 -- Suppress overflow, division by zero and access checks since they
180 -- are handled implicitly by CodePeer.
182 -- Turn off dynamic elaboration checks: generates inconsistencies in
183 -- trees between specs compiled as part of a main unit or as part of
186 -- Turn off alignment checks: these cannot be proved statically by
187 -- CodePeer and generate false positives.
189 -- Enable all other language checks
192 (Access_Check => True,
193 Alignment_Check => True,
194 Division_Check => True,
195 Elaboration_Check => True,
196 Overflow_Check => True,
198 Enable_Overflow_Checks := False;
199 Dynamic_Elaboration_Checks := False;
201 -- Kill debug of generated code, since it messes up sloc values
203 Debug_Generated_Code := False;
205 -- Turn cross-referencing on in case it was disabled (by e.g. -gnatD)
206 -- Do we really need to spend time generating xref in CodePeer
207 -- mode??? Consider setting Xref_Active to False.
211 -- Polling mode forced off, since it generates confusing junk
213 Polling_Required := False;
215 -- Set operating mode to Generate_Code to benefit from full
216 -- front-end expansion (e.g. generics).
218 Operating_Mode := Generate_Code;
220 -- We need SCIL generation of course
222 Generate_SCIL := True;
224 -- Enable assertions and debug pragmas, since they give CodePeer
225 -- valuable extra information.
227 Assertions_Enabled := True;
228 Debug_Pragmas_Enabled := True;
230 -- Suppress compiler warnings, since what we are interested in here
231 -- is what CodePeer can find out. Also disable all simple value
232 -- propagation. This is an optimization which is valuable for code
233 -- optimization, and also for generation of compiler warnings, but
234 -- these are being turned off anyway, and CodePeer understands
235 -- things more clearly if references are not optimized in this way.
237 Warning_Mode := Suppress;
238 Debug_Flag_MM := True;
240 -- Set normal RM validity checking, and checking of IN OUT parameters
241 -- (this might give CodePeer more useful checks to analyze, to be
242 -- confirmed???). All other validity checking is turned off, since
243 -- this can generate very complex trees that only confuse CodePeer
244 -- and do not bring enough useful info.
246 Reset_Validity_Check_Options;
247 Validity_Check_Default := True;
248 Validity_Check_In_Out_Params := True;
249 Validity_Check_In_Params := True;
251 -- Turn off style check options since we are not interested in any
252 -- front-end warnings when we are getting CodePeer output.
254 Reset_Style_Check_Options;
257 -- Set Configurable_Run_Time mode if system.ads flag set
259 if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
260 Configurable_Run_Time_Mode := True;
263 -- Set -gnatR3m mode if debug flag A set
265 if Debug_Flag_AA then
266 Back_Annotate_Rep_Info := True;
267 List_Representation_Info := 1;
268 List_Representation_Info_Mechanisms := True;
271 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
273 if Debug_Flag_Dot_A then
274 Ttypes.Target_Strict_Alignment := True;
277 -- Disable static allocation of dispatch tables if -gnatd.t or if layout
278 -- is enabled. The front end's layout phase currently treats types that
279 -- have discriminant-dependent arrays as not being static even when a
280 -- discriminant constraint on the type is static, and this leads to
281 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
283 if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then
284 Static_Dispatch_Tables := False;
287 -- Flip endian mode if -gnatd8 set
290 Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
293 -- Deal with forcing OpenVMS switches True if debug flag M is set, but
294 -- record the setting of Targparm.Open_VMS_On_Target in True_VMS_Target
295 -- before doing this, so we know if we are in real OpenVMS or not!
297 Opt.True_VMS_Target := Targparm.OpenVMS_On_Target;
300 Targparm.OpenVMS_On_Target := True;
301 Hostparm.OpenVMS := True;
304 -- Activate front end layout if debug flag -gnatdF is set
306 if Debug_Flag_FF then
307 Targparm.Frontend_Layout_On_Target := True;
310 -- Set and check exception mechnism
312 if Targparm.ZCX_By_Default_On_Target then
313 if Targparm.GCC_ZCX_Support_On_Target then
314 Exception_Mechanism := Back_End_Exceptions;
316 Osint.Fail ("Zero Cost Exceptions not supported on this target");
320 -- Set proper status for overflow checks. We turn on overflow checks
321 -- if -gnatp was not specified, and either -gnato is set or the back
322 -- end takes care of overflow checks. Otherwise we suppress overflow
323 -- checks by default (since front end checks are expensive).
325 if not Opt.Suppress_Checks
326 and then (Opt.Enable_Overflow_Checks
328 (Targparm.Backend_Divide_Checks_On_Target
330 Targparm.Backend_Overflow_Checks_On_Target))
332 Suppress_Options (Overflow_Check) := False;
334 Suppress_Options (Overflow_Check) := True;
337 -- Set switch indicating if we can use N_Expression_With_Actions
339 -- Debug flag -gnatd.X decisively sets usage on
341 if Debug_Flag_Dot_XX then
342 Use_Expression_With_Actions := True;
344 -- Debug flag -gnatd.Y decisively sets usage off
346 elsif Debug_Flag_Dot_YY then
347 Use_Expression_With_Actions := False;
349 -- If no debug flags, usage off for SCIL
351 elsif Generate_SCIL then
352 Use_Expression_With_Actions := False;
354 -- Otherwise this feature is implemented, so we allow its use
357 Use_Expression_With_Actions := True;
360 -- Set switch indicating if back end can handle limited types, and
361 -- guarantee that no incorrect copies are made (e.g. in the context
362 -- of a conditional expression).
364 -- Debug flag -gnatd.L decisively sets usage on
366 if Debug_Flag_Dot_LL then
367 Back_End_Handles_Limited_Types := True;
369 -- If no debug flag, usage off for AAMP, VM, SCIL cases
372 or else VM_Target /= No_VM
373 or else Generate_SCIL
375 Back_End_Handles_Limited_Types := False;
377 -- Otherwise normal gcc back end, for now still turn flag off by
378 -- default, since there are unresolved problems in the front end.
381 Back_End_Handles_Limited_Types := False;
383 end Adjust_Global_Switches;
389 procedure Check_Bad_Body is
390 Sname : Unit_Name_Type;
391 Src_Ind : Source_File_Index;
392 Fname : File_Name_Type;
394 procedure Bad_Body_Error (Msg : String);
395 -- Issue message for bad body found
401 procedure Bad_Body_Error (Msg : String) is
403 Error_Msg_N (Msg, Main_Unit_Node);
404 Error_Msg_File_1 := Fname;
405 Error_Msg_N ("remove incorrect body in file{!", Main_Unit_Node);
408 -- Start of processing for Check_Bad_Body
411 -- Nothing to do if we are only checking syntax, because we don't know
412 -- enough to know if we require or forbid a body in this case.
414 if Operating_Mode = Check_Syntax then
418 -- Check for body not allowed
420 if (Main_Kind = N_Package_Declaration
421 and then not Body_Required (Main_Unit_Node))
422 or else (Main_Kind = N_Generic_Package_Declaration
423 and then not Body_Required (Main_Unit_Node))
424 or else Main_Kind = N_Package_Renaming_Declaration
425 or else Main_Kind = N_Subprogram_Renaming_Declaration
426 or else Nkind (Original_Node (Unit (Main_Unit_Node)))
427 in N_Generic_Instantiation
429 Sname := Unit_Name (Main_Unit);
431 -- If we do not already have a body name, then get the body name
432 -- (but how can we have a body name here ???)
434 if not Is_Body_Name (Sname) then
435 Sname := Get_Body_Name (Sname);
438 Fname := Get_File_Name (Sname, Subunit => False);
439 Src_Ind := Load_Source_File (Fname);
441 -- Case where body is present and it is not a subunit. Exclude
442 -- the subunit case, because it has nothing to do with the
443 -- package we are compiling. It is illegal for a child unit and a
444 -- subunit with the same expanded name (RM 10.2(9)) to appear
445 -- together in a partition, but there is nothing to stop a
446 -- compilation environment from having both, and the test here
447 -- simply allows that. If there is an attempt to include both in
448 -- a partition, this is diagnosed at bind time. In Ada 83 mode
449 -- this is not a warning case.
451 -- Note: if weird file names are being used, we can have
452 -- situation where the file name that supposedly contains body,
453 -- in fact contains a spec, or we can't tell what it contains.
454 -- Skip the error message in these cases.
456 -- Also ignore body that is nothing but pragma No_Body; (that's the
457 -- whole point of this pragma, to be used this way and to cause the
458 -- body file to be ignored in this context).
460 if Src_Ind /= No_Source_File
461 and then Get_Expected_Unit_Type (Fname) = Expect_Body
462 and then not Source_File_Is_Subunit (Src_Ind)
463 and then not Source_File_Is_No_Body (Src_Ind)
465 Errout.Finalize (Last_Call => False);
467 Error_Msg_Unit_1 := Sname;
469 -- Ada 83 case of a package body being ignored. This is not an
470 -- error as far as the Ada 83 RM is concerned, but it is almost
471 -- certainly not what is wanted so output a warning. Give this
472 -- message only if there were no errors, since otherwise it may
473 -- be incorrect (we may have misinterpreted a junk spec as not
474 -- needing a body when it really does).
476 if Main_Kind = N_Package_Declaration
477 and then Ada_Version = Ada_83
478 and then Operating_Mode = Generate_Code
479 and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
480 and then not Compilation_Errors
483 ("package $$ does not require a body?", Main_Unit_Node);
484 Error_Msg_File_1 := Fname;
485 Error_Msg_N ("body in file{? will be ignored", Main_Unit_Node);
487 -- Ada 95 cases of a body file present when no body is
488 -- permitted. This we consider to be an error.
491 -- For generic instantiations, we never allow a body
493 if Nkind (Original_Node (Unit (Main_Unit_Node)))
494 in N_Generic_Instantiation
497 ("generic instantiation for $$ does not allow a body");
499 -- A library unit that is a renaming never allows a body
501 elsif Main_Kind in N_Renaming_Declaration then
503 ("renaming declaration for $$ does not allow a body!");
505 -- Remaining cases are packages and generic packages. Here
506 -- we only do the test if there are no previous errors,
507 -- because if there are errors, they may lead us to
508 -- incorrectly believe that a package does not allow a body
509 -- when in fact it does.
511 elsif not Compilation_Errors then
512 if Main_Kind = N_Package_Declaration then
514 ("package $$ does not allow a body!");
516 elsif Main_Kind = N_Generic_Package_Declaration then
518 ("generic package $$ does not allow a body!");
527 -------------------------
528 -- Check_Library_Items --
529 -------------------------
531 -- Walk_Library_Items has plenty of assertions, so all we need to do is
532 -- call it, just for these assertions, not actually doing anything else.
534 procedure Check_Library_Items is
536 procedure Action (Item : Node_Id);
537 -- Action passed to Walk_Library_Items to do nothing
543 procedure Action (Item : Node_Id) is
548 procedure Walk is new Sem.Walk_Library_Items (Action);
550 -- Start of processing for Check_Library_Items
554 end Check_Library_Items;
560 procedure Check_Rep_Info is
562 if List_Representation_Info /= 0
563 or else List_Representation_Info_Mechanisms
568 ("cannot generate representation information, no code generated");
575 -- Start of processing for Gnat1drv
578 -- This inner block is set up to catch assertion errors and constraint
579 -- errors. Since the code for handling these errors can cause another
580 -- exception to be raised (namely Unrecoverable_Error), we need two
581 -- nested blocks, so that the outer one handles unrecoverable error.
584 -- Initialize all packages. For the most part, these initialization
585 -- calls can be made in any order. Exceptions are as follows:
587 -- Lib.Initialize need to be called before Scan_Compiler_Arguments,
588 -- because it initializes a table filled by Scan_Compiler_Arguments.
594 Scan_Compiler_Arguments;
595 Osint.Add_Default_Search_Dirs;
616 Sem_Type.Init_Interp_Tables;
618 -- Acquire target parameters from system.ads (source of package System)
623 S : Source_File_Index;
627 Name_Buffer (1 .. 10) := "system.ads";
630 S := Load_Source_File (N);
632 if S = No_Source_File then
634 ("fatal error, run-time library not installed correctly");
636 ("cannot locate file system.ads");
637 raise Unrecoverable_Error;
639 -- Remember source index of system.ads (which was read successfully)
642 System_Source_File_Index := S;
645 Targparm.Get_Target_Parameters
646 (System_Text => Source_Text (S),
647 Source_First => Source_First (S),
648 Source_Last => Source_Last (S));
650 -- Acquire configuration pragma information from Targparm
652 Restrict.Restrictions := Targparm.Restrictions_On_Target;
655 Adjust_Global_Switches;
657 -- Output copyright notice if full list mode unless we have a list
658 -- file, in which case we defer this so that it is output in the file
660 if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
661 and then not Debug_Flag_7
665 Write_Str (Gnat_Version_String);
667 Write_Str ("Copyright 1992-" &
669 ", Free Software Foundation, Inc.");
673 -- Check we do not have more than one source file, this happens only in
674 -- the case where the driver is called directly, it cannot happen when
675 -- gnat1 is invoked from gcc in the normal case.
677 if Osint.Number_Of_Files /= 1 then
680 Osint.Fail ("you must provide one source file");
682 elsif Usage_Requested then
686 Original_Operating_Mode := Operating_Mode;
689 -- Exit with errors if the main source could not be parsed
691 if Sinput.Main_Source_File = No_Source_File then
692 Errout.Finalize (Last_Call => True);
693 Errout.Output_Messages;
694 Exit_Program (E_Errors);
697 Main_Unit_Node := Cunit (Main_Unit);
698 Main_Kind := Nkind (Unit (Main_Unit_Node));
701 -- Exit if compilation errors detected
703 Errout.Finalize (Last_Call => False);
705 if Compilation_Errors then
707 Sem_Ch13.Validate_Unchecked_Conversions;
708 Sem_Ch13.Validate_Address_Clauses;
709 Errout.Output_Messages;
712 -- Generate ALI file if specially requested
714 if Opt.Force_ALI_Tree_File then
715 Write_ALI (Object => False);
719 Errout.Finalize (Last_Call => True);
720 Exit_Program (E_Errors);
723 -- Set Generate_Code on main unit and its spec. We do this even if are
724 -- not generating code, since Lib-Writ uses this to determine which
725 -- units get written in the ali file.
727 Set_Generate_Code (Main_Unit);
729 -- If we have a corresponding spec, and it comes from source
730 -- or it is not a generated spec for a child subprogram body,
731 -- then we need object code for the spec unit as well.
733 if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
734 and then not Acts_As_Spec (Main_Unit_Node)
736 if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body
737 and then not Comes_From_Source (Library_Unit (Main_Unit_Node))
742 (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
746 -- Case of no code required to be generated, exit indicating no error
748 if Original_Operating_Mode = Check_Syntax then
750 Errout.Finalize (Last_Call => True);
751 Errout.Output_Messages;
756 -- Use a goto instead of calling Exit_Program so that finalization
761 elsif Original_Operating_Mode = Check_Semantics then
762 Back_End_Mode := Declarations_Only;
764 -- All remaining cases are cases in which the user requested that code
765 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if
766 -- we can in fact satisfy this request.
768 -- Cannot generate code if someone has turned off code generation for
769 -- any reason at all. We will try to figure out a reason below.
771 elsif Operating_Mode /= Generate_Code then
772 Back_End_Mode := Skip;
774 -- We can generate code for a subprogram body unless there were missing
775 -- subunits. Note that we always generate code for all generic units (a
776 -- change from some previous versions of GNAT).
778 elsif Main_Kind = N_Subprogram_Body
779 and then not Subunits_Missing
781 Back_End_Mode := Generate_Object;
783 -- We can generate code for a package body unless there are subunits
784 -- missing (note that we always generate code for generic units, which
785 -- is a change from some earlier versions of GNAT).
787 elsif Main_Kind = N_Package_Body
788 and then not Subunits_Missing
790 Back_End_Mode := Generate_Object;
792 -- We can generate code for a package declaration or a subprogram
793 -- declaration only if it does not required a body.
795 elsif (Main_Kind = N_Package_Declaration
797 Main_Kind = N_Subprogram_Declaration)
799 (not Body_Required (Main_Unit_Node)
801 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
803 Back_End_Mode := Generate_Object;
805 -- We can generate code for a generic package declaration of a generic
806 -- subprogram declaration only if does not require a body.
808 elsif (Main_Kind = N_Generic_Package_Declaration
810 Main_Kind = N_Generic_Subprogram_Declaration)
811 and then not Body_Required (Main_Unit_Node)
813 Back_End_Mode := Generate_Object;
815 -- Compilation units that are renamings do not require bodies,
816 -- so we can generate code for them.
818 elsif Main_Kind = N_Package_Renaming_Declaration
819 or else Main_Kind = N_Subprogram_Renaming_Declaration
821 Back_End_Mode := Generate_Object;
823 -- Compilation units that are generic renamings do not require bodies
824 -- so we can generate code for them.
826 elsif Main_Kind in N_Generic_Renaming_Declaration then
827 Back_End_Mode := Generate_Object;
829 -- It's not an error to generate SCIL for e.g. a spec which has a body
831 elsif CodePeer_Mode then
832 Back_End_Mode := Generate_Object;
834 -- In all other cases (specs which have bodies, generics, and bodies
835 -- where subunits are missing), we cannot generate code and we generate
836 -- a warning message. Note that generic instantiations are gone at this
837 -- stage since they have been replaced by their instances.
840 Back_End_Mode := Skip;
843 -- At this stage Back_End_Mode is set to indicate if the backend should
844 -- be called to generate code. If it is Skip, then code generation has
845 -- been turned off, even though code was requested by the original
846 -- command. This is not an error from the user point of view, but it is
847 -- an error from the point of view of the gcc driver, so we must exit
848 -- with an error status.
850 -- We generate an informative message (from the gcc point of view, it
851 -- is an error message, but from the users point of view this is not an
852 -- error, just a consequence of compiling something that cannot
855 if Back_End_Mode = Skip then
857 Write_Str ("cannot generate code for ");
859 Write_Name (Unit_File_Name (Main_Unit));
861 if Subunits_Missing then
862 Write_Str (" (missing subunits)");
864 Write_Str ("to check parent unit");
866 elsif Main_Kind = N_Subunit then
867 Write_Str (" (subunit)");
869 Write_Str ("to check subunit");
871 elsif Main_Kind = N_Subprogram_Declaration then
872 Write_Str (" (subprogram spec)");
874 Write_Str ("to check subprogram spec");
876 -- Generic package body in GNAT implementation mode
878 elsif Main_Kind = N_Package_Body and then GNAT_Mode then
879 Write_Str (" (predefined generic)");
881 Write_Str ("to check predefined generic");
883 -- Only other case is a package spec
886 Write_Str (" (package spec)");
888 Write_Str ("to check package spec");
891 Write_Str (" for errors, use ");
893 if Hostparm.OpenVMS then
894 Write_Str ("/NOLOAD");
896 Write_Str ("-gnatc");
902 Sem_Ch13.Validate_Unchecked_Conversions;
903 Sem_Ch13.Validate_Address_Clauses;
904 Errout.Finalize (Last_Call => True);
905 Errout.Output_Messages;
908 Write_ALI (Object => False);
912 -- Exit program with error indication, to kill object file
914 Exit_Program (E_No_Code);
917 -- In -gnatc mode, we only do annotation if -gnatt or -gnatR is also
918 -- set as indicated by Back_Annotate_Rep_Info being set to True.
920 -- We don't call for annotations on a subunit, because to process those
921 -- the back-end requires that the parent(s) be properly compiled.
923 -- Annotation is suppressed for targets where front-end layout is
924 -- enabled, because the front end determines representations.
926 -- Annotation is also suppressed in the case of compiling for
927 -- a VM, since representations are largely symbolic there.
929 if Back_End_Mode = Declarations_Only
930 and then (not (Back_Annotate_Rep_Info or Generate_SCIL)
931 or else Main_Kind = N_Subunit
932 or else Targparm.Frontend_Layout_On_Target
933 or else Targparm.VM_Target /= No_VM)
935 Sem_Ch13.Validate_Unchecked_Conversions;
936 Sem_Ch13.Validate_Address_Clauses;
937 Errout.Finalize (Last_Call => True);
938 Errout.Output_Messages;
939 Write_ALI (Object => False);
947 -- Ensure that we properly register a dependency on system.ads, since
948 -- even if we do not semantically depend on this, Targparm has read
949 -- system parameters from the system.ads file.
951 Lib.Writ.Ensure_System_Dependency;
953 -- Add dependencies, if any, on preprocessing data file and on
954 -- preprocessing definition file(s).
956 Prepcomp.Add_Dependencies;
958 -- Back end needs to explicitly unlock tables it needs to touch
971 -- ???Check_Library_Items under control of a debug flag, because it
972 -- currently does not work if the -gnatn switch (back end inlining) is
975 if Debug_Flag_Dot_WW then
979 -- Here we call the back end to generate the output code
981 Generating_Code := True;
982 Back_End.Call_Back_End (Back_End_Mode);
984 -- Once the backend is complete, we unlock the names table. This call
985 -- allows a few extra entries, needed for example for the file name for
986 -- the library file output.
990 -- Generate the call-graph output of dispatching calls
992 Exp_CG.Generate_CG_Output;
994 -- Validate unchecked conversions (using the values for size and
995 -- alignment annotated by the backend where possible).
997 Sem_Ch13.Validate_Unchecked_Conversions;
999 -- Validate address clauses (again using alignment values annotated
1000 -- by the backend where possible).
1002 Sem_Ch13.Validate_Address_Clauses;
1004 -- Now we complete output of errors, rep info and the tree info. These
1005 -- are delayed till now, since it is perfectly possible for gigi to
1006 -- generate errors, modify the tree (in particular by setting flags
1007 -- indicating that elaboration is required, and also to back annotate
1008 -- representation information for List_Rep_Info.
1010 Errout.Finalize (Last_Call => True);
1011 Errout.Output_Messages;
1014 -- Only write the library if the backend did not generate any error
1015 -- messages. Otherwise signal errors to the driver program so that
1016 -- there will be no attempt to generate an object file.
1018 if Compilation_Errors then
1020 Exit_Program (E_Errors);
1023 Write_ALI (Object => (Back_End_Mode = Generate_Object));
1025 -- Generate the ASIS tree after writing the ALI file, since in ASIS
1026 -- mode, Write_ALI may in fact result in further tree decoration from
1027 -- the original tree file. Note that we dump the tree just before
1028 -- generating it, so that the dump will exactly reflect what is written
1034 -- Finalize name table and we are all done
1039 -- Handle fatal internal compiler errors
1041 when Rtsfind.RE_Not_Available =>
1042 Comperr.Compiler_Abort ("RE_Not_Available");
1044 when System.Assertions.Assert_Failure =>
1045 Comperr.Compiler_Abort ("Assert_Failure");
1047 when Constraint_Error =>
1048 Comperr.Compiler_Abort ("Constraint_Error");
1050 when Program_Error =>
1051 Comperr.Compiler_Abort ("Program_Error");
1053 when Storage_Error =>
1055 -- Assume this is a bug. If it is real, the message will in any case
1056 -- say Storage_Error, giving a strong hint!
1058 Comperr.Compiler_Abort ("Storage_Error");
1064 -- The outer exception handles an unrecoverable error
1067 when Unrecoverable_Error =>
1068 Errout.Finalize (Last_Call => True);
1069 Errout.Output_Messages;
1072 Write_Str ("compilation abandoned");
1075 Set_Standard_Output;
1078 Exit_Program (E_Errors);