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;
34 with Fname; use Fname;
35 with Fname.UF; use Fname.UF;
37 with Gnatvsn; use Gnatvsn;
41 with Lib.Writ; use Lib.Writ;
43 with Namet; use Namet;
46 with Osint; use Osint;
47 with Output; use Output;
50 with Repinfo; use Repinfo;
61 with Sinfo; use Sinfo;
62 with Sinput.L; use Sinput.L;
64 with Sprint; use Sprint;
66 with Stylesw; use Stylesw;
67 with Targparm; use Targparm;
69 with Treepr; use Treepr;
71 with Types; use Types;
72 with Uintp; use Uintp;
73 with Uname; use Uname;
76 with Validsw; use Validsw;
78 with System.Assertions;
81 Main_Unit_Node : Node_Id;
82 -- Compilation unit node for main unit
84 Main_Kind : Node_Kind;
85 -- Kind of main compilation unit node
87 Back_End_Mode : Back_End.Back_End_Mode_Type;
88 -- Record back end mode
90 procedure Adjust_Global_Switches;
91 -- There are various interactions between front end switch settings,
92 -- including debug switch settings and target dependent parameters.
93 -- This procedure takes care of properly handling these interactions.
94 -- We do it after scanning out all the switches, so that we are not
95 -- depending on the order in which switches appear.
97 procedure Check_Bad_Body;
98 -- Called to check if the unit we are compiling has a bad body
100 procedure Check_Rep_Info;
101 -- Called when we are not generating code, to check if -gnatR was requested
102 -- and if so, explain that we will not be honoring the request.
104 procedure Check_Library_Items;
105 -- For debugging -- checks the behavior of Walk_Library_Items
106 pragma Warnings (Off, Check_Library_Items);
107 -- In case the call below is commented out
109 ----------------------------
110 -- Adjust_Global_Switches --
111 ----------------------------
113 procedure Adjust_Global_Switches is
115 -- Debug flag -gnatd.I is a synonym for Generate_SCIL and requires code
119 and then Operating_Mode = Generate_Code
121 Generate_SCIL := True;
124 -- Set ASIS mode if -gnatt and -gnatc are set
126 if Operating_Mode = Check_Semantics and then Tree_Output then
129 -- Turn off inlining in ASIS mode, since ASIS cannot handle the extra
130 -- information in the trees caused by inlining being active.
132 -- More specifically, the tree seems to be malformed from the ASIS
133 -- point of view if -gnatc and -gnatn appear together???
135 Inline_Active := False;
137 -- Turn off SCIL generation in ASIS mode, since SCIL requires front-
140 Generate_SCIL := False;
143 -- SCIL mode needs to disable front-end inlining since the generated
144 -- trees (in particular order and consistency between specs compiled
145 -- as part of a main unit or as part of a with-clause) are causing
148 if Generate_SCIL then
149 Front_End_Inlining := False;
152 -- Tune settings for optimal SCIL generation in CodePeer_Mode
154 if CodePeer_Mode then
156 -- Turn off inlining, confuses CodePeer output and gains nothing
158 Front_End_Inlining := False;
159 Inline_Active := False;
161 -- Turn off ASIS mode: incompatible with front-end expansion
165 -- Disable front-end optimizations, to keep the tree as close to the
166 -- source code as possible, and also to avoid inconsistencies between
167 -- trees when using different optimization switches.
169 Optimization_Level := 0;
171 -- Disable specific expansions for Restrictions pragmas to avoid
172 -- tree inconsistencies between compilations with different pragmas
173 -- that will cause different SCIL files to be generated for the
176 Treat_Restrictions_As_Warnings := True;
178 -- Suppress overflow, division by zero and access checks since they
179 -- are handled implicitly by CodePeer.
181 -- Turn off dynamic elaboration checks: generates inconsistencies in
182 -- trees between specs compiled as part of a main unit or as part of
185 -- Turn off alignment checks: these cannot be proved statically by
186 -- CodePeer and generate false positives.
188 -- Enable all other language checks
191 (Access_Check => True,
192 Alignment_Check => True,
193 Division_Check => True,
194 Elaboration_Check => True,
195 Overflow_Check => True,
197 Enable_Overflow_Checks := False;
198 Dynamic_Elaboration_Checks := False;
200 -- Kill debug of generated code, since it messes up sloc values
202 Debug_Generated_Code := False;
204 -- Turn cross-referencing on in case it was disabled (by e.g. -gnatD)
205 -- Do we really need to spend time generating xref in CodePeer
206 -- mode??? Consider setting Xref_Active to False.
210 -- Polling mode forced off, since it generates confusing junk
212 Polling_Required := False;
214 -- Set operating mode to Generate_Code to benefit from full
215 -- front-end expansion (e.g. generics).
217 Operating_Mode := Generate_Code;
219 -- We need SCIL generation of course
221 Generate_SCIL := True;
223 -- Enable assertions and debug pragmas, since they give CodePeer
224 -- valuable extra information.
226 Assertions_Enabled := True;
227 Debug_Pragmas_Enabled := True;
229 -- Suppress compiler warnings, since what we are interested in here
230 -- is what CodePeer can find out. Also disable all simple value
231 -- propagation. This is an optimization which is valuable for code
232 -- optimization, and also for generation of compiler warnings, but
233 -- these are being turned off anyway, and CodePeer understands
234 -- things more clearly if references are not optimized in this way.
236 Warning_Mode := Suppress;
237 Debug_Flag_MM := True;
239 -- Set normal RM validity checking, and checking of IN OUT parameters
240 -- (this might give CodePeer more useful checks to analyze, to be
241 -- confirmed???). All other validity checking is turned off, since
242 -- this can generate very complex trees that only confuse CodePeer
243 -- and do not bring enough useful info.
245 Reset_Validity_Check_Options;
246 Validity_Check_Default := True;
247 Validity_Check_In_Out_Params := True;
248 Validity_Check_In_Params := True;
250 -- Turn off style check options since we are not interested in any
251 -- front-end warnings when we are getting CodePeer output.
253 Reset_Style_Check_Options;
256 -- Set Configurable_Run_Time mode if system.ads flag set
258 if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
259 Configurable_Run_Time_Mode := True;
262 -- Set -gnatR3m mode if debug flag A set
264 if Debug_Flag_AA then
265 Back_Annotate_Rep_Info := True;
266 List_Representation_Info := 1;
267 List_Representation_Info_Mechanisms := True;
270 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
272 if Debug_Flag_Dot_A then
273 Ttypes.Target_Strict_Alignment := True;
276 -- Disable static allocation of dispatch tables if -gnatd.t or if layout
277 -- is enabled. The front end's layout phase currently treats types that
278 -- have discriminant-dependent arrays as not being static even when a
279 -- discriminant constraint on the type is static, and this leads to
280 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
282 if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then
283 Static_Dispatch_Tables := False;
286 -- Flip endian mode if -gnatd8 set
289 Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
292 -- Deal with forcing OpenVMS switches True if debug flag M is set, but
293 -- record the setting of Targparm.Open_VMS_On_Target in True_VMS_Target
294 -- before doing this, so we know if we are in real OpenVMS or not!
296 Opt.True_VMS_Target := Targparm.OpenVMS_On_Target;
299 Targparm.OpenVMS_On_Target := True;
300 Hostparm.OpenVMS := True;
303 -- Activate front end layout if debug flag -gnatdF is set
305 if Debug_Flag_FF then
306 Targparm.Frontend_Layout_On_Target := True;
309 -- Set and check exception mechnism
311 if Targparm.ZCX_By_Default_On_Target then
312 if Targparm.GCC_ZCX_Support_On_Target then
313 Exception_Mechanism := Back_End_Exceptions;
315 Osint.Fail ("Zero Cost Exceptions not supported on this target");
319 -- Set proper status for overflow checks. We turn on overflow checks
320 -- if -gnatp was not specified, and either -gnato is set or the back
321 -- end takes care of overflow checks. Otherwise we suppress overflow
322 -- checks by default (since front end checks are expensive).
324 if not Opt.Suppress_Checks
325 and then (Opt.Enable_Overflow_Checks
327 (Targparm.Backend_Divide_Checks_On_Target
329 Targparm.Backend_Overflow_Checks_On_Target))
331 Suppress_Options (Overflow_Check) := False;
333 Suppress_Options (Overflow_Check) := True;
336 -- Set switch indicating if we can use N_Expression_With_Actions
338 -- Debug flag -gnatd.X decisively sets usage on
340 if Debug_Flag_Dot_XX then
341 Use_Expression_With_Actions := True;
343 -- Debug flag -gnatd.Y decisively sets usage off
345 elsif Debug_Flag_Dot_YY then
346 Use_Expression_With_Actions := False;
348 -- If no debug flags, usage off for AAMP, VM, SCIL cases
351 or else VM_Target /= No_VM
352 or else Generate_SCIL
354 Use_Expression_With_Actions := False;
356 -- Otherwise normal gcc back end, which does implement this feature
357 -- so by default we allow its use.
360 Use_Expression_With_Actions := True;
363 -- Set switch indicating if back end can handle limited types, and
364 -- guarantee that no incorrect copies are made (e.g. in the context
365 -- of a conditional expression).
367 -- Debug flag -gnatd.L decisively sets usage on
369 if Debug_Flag_Dot_LL then
370 Back_End_Handles_Limited_Types := True;
372 -- If no debug flag, usage off for AAMP, VM, SCIL cases
375 or else VM_Target /= No_VM
376 or else Generate_SCIL
378 Back_End_Handles_Limited_Types := False;
380 -- Otherwise normal gcc back end, for now still turn flag off by
381 -- default, since we have not verified proper back end handling.
384 Back_End_Handles_Limited_Types := False;
386 end Adjust_Global_Switches;
392 procedure Check_Bad_Body is
393 Sname : Unit_Name_Type;
394 Src_Ind : Source_File_Index;
395 Fname : File_Name_Type;
397 procedure Bad_Body_Error (Msg : String);
398 -- Issue message for bad body found
404 procedure Bad_Body_Error (Msg : String) is
406 Error_Msg_N (Msg, Main_Unit_Node);
407 Error_Msg_File_1 := Fname;
408 Error_Msg_N ("remove incorrect body in file{!", Main_Unit_Node);
411 -- Start of processing for Check_Bad_Body
414 -- Nothing to do if we are only checking syntax, because we don't know
415 -- enough to know if we require or forbid a body in this case.
417 if Operating_Mode = Check_Syntax then
421 -- Check for body not allowed
423 if (Main_Kind = N_Package_Declaration
424 and then not Body_Required (Main_Unit_Node))
425 or else (Main_Kind = N_Generic_Package_Declaration
426 and then not Body_Required (Main_Unit_Node))
427 or else Main_Kind = N_Package_Renaming_Declaration
428 or else Main_Kind = N_Subprogram_Renaming_Declaration
429 or else Nkind (Original_Node (Unit (Main_Unit_Node)))
430 in N_Generic_Instantiation
432 Sname := Unit_Name (Main_Unit);
434 -- If we do not already have a body name, then get the body name
435 -- (but how can we have a body name here ???)
437 if not Is_Body_Name (Sname) then
438 Sname := Get_Body_Name (Sname);
441 Fname := Get_File_Name (Sname, Subunit => False);
442 Src_Ind := Load_Source_File (Fname);
444 -- Case where body is present and it is not a subunit. Exclude
445 -- the subunit case, because it has nothing to do with the
446 -- package we are compiling. It is illegal for a child unit and a
447 -- subunit with the same expanded name (RM 10.2(9)) to appear
448 -- together in a partition, but there is nothing to stop a
449 -- compilation environment from having both, and the test here
450 -- simply allows that. If there is an attempt to include both in
451 -- a partition, this is diagnosed at bind time. In Ada 83 mode
452 -- this is not a warning case.
454 -- Note: if weird file names are being used, we can have
455 -- situation where the file name that supposedly contains body,
456 -- in fact contains a spec, or we can't tell what it contains.
457 -- Skip the error message in these cases.
459 -- Also ignore body that is nothing but pragma No_Body; (that's the
460 -- whole point of this pragma, to be used this way and to cause the
461 -- body file to be ignored in this context).
463 if Src_Ind /= No_Source_File
464 and then Get_Expected_Unit_Type (Fname) = Expect_Body
465 and then not Source_File_Is_Subunit (Src_Ind)
466 and then not Source_File_Is_No_Body (Src_Ind)
468 Errout.Finalize (Last_Call => False);
470 Error_Msg_Unit_1 := Sname;
472 -- Ada 83 case of a package body being ignored. This is not an
473 -- error as far as the Ada 83 RM is concerned, but it is almost
474 -- certainly not what is wanted so output a warning. Give this
475 -- message only if there were no errors, since otherwise it may
476 -- be incorrect (we may have misinterpreted a junk spec as not
477 -- needing a body when it really does).
479 if Main_Kind = N_Package_Declaration
480 and then Ada_Version = Ada_83
481 and then Operating_Mode = Generate_Code
482 and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
483 and then not Compilation_Errors
486 ("package $$ does not require a body?", Main_Unit_Node);
487 Error_Msg_File_1 := Fname;
488 Error_Msg_N ("body in file{? will be ignored", Main_Unit_Node);
490 -- Ada 95 cases of a body file present when no body is
491 -- permitted. This we consider to be an error.
494 -- For generic instantiations, we never allow a body
496 if Nkind (Original_Node (Unit (Main_Unit_Node)))
497 in N_Generic_Instantiation
500 ("generic instantiation for $$ does not allow a body");
502 -- A library unit that is a renaming never allows a body
504 elsif Main_Kind in N_Renaming_Declaration then
506 ("renaming declaration for $$ does not allow a body!");
508 -- Remaining cases are packages and generic packages. Here
509 -- we only do the test if there are no previous errors,
510 -- because if there are errors, they may lead us to
511 -- incorrectly believe that a package does not allow a body
512 -- when in fact it does.
514 elsif not Compilation_Errors then
515 if Main_Kind = N_Package_Declaration then
517 ("package $$ does not allow a body!");
519 elsif Main_Kind = N_Generic_Package_Declaration then
521 ("generic package $$ does not allow a body!");
530 -------------------------
531 -- Check_Library_Items --
532 -------------------------
534 -- Walk_Library_Items has plenty of assertions, so all we need to do is
535 -- call it, just for these assertions, not actually doing anything else.
537 procedure Check_Library_Items is
539 procedure Action (Item : Node_Id);
540 -- Action passed to Walk_Library_Items to do nothing
546 procedure Action (Item : Node_Id) is
551 procedure Walk is new Sem.Walk_Library_Items (Action);
553 -- Start of processing for Check_Library_Items
557 end Check_Library_Items;
563 procedure Check_Rep_Info is
565 if List_Representation_Info /= 0
566 or else List_Representation_Info_Mechanisms
571 ("cannot generate representation information, no code generated");
578 -- Start of processing for Gnat1drv
581 -- This inner block is set up to catch assertion errors and constraint
582 -- errors. Since the code for handling these errors can cause another
583 -- exception to be raised (namely Unrecoverable_Error), we need two
584 -- nested blocks, so that the outer one handles unrecoverable error.
587 -- Initialize all packages. For the most part, these initialization
588 -- calls can be made in any order. Exceptions are as follows:
590 -- Lib.Initialize need to be called before Scan_Compiler_Arguments,
591 -- because it initializes a table filled by Scan_Compiler_Arguments.
597 Scan_Compiler_Arguments;
598 Osint.Add_Default_Search_Dirs;
618 Sem_Type.Init_Interp_Tables;
620 -- Acquire target parameters from system.ads (source of package System)
625 S : Source_File_Index;
629 Name_Buffer (1 .. 10) := "system.ads";
632 S := Load_Source_File (N);
634 if S = No_Source_File then
636 ("fatal error, run-time library not installed correctly");
638 ("cannot locate file system.ads");
639 raise Unrecoverable_Error;
641 -- Remember source index of system.ads (which was read successfully)
644 System_Source_File_Index := S;
647 Targparm.Get_Target_Parameters
648 (System_Text => Source_Text (S),
649 Source_First => Source_First (S),
650 Source_Last => Source_Last (S));
652 -- Acquire configuration pragma information from Targparm
654 Restrict.Restrictions := Targparm.Restrictions_On_Target;
657 Adjust_Global_Switches;
659 -- Output copyright notice if full list mode unless we have a list
660 -- file, in which case we defer this so that it is output in the file
662 if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
663 and then not Debug_Flag_7
667 Write_Str (Gnat_Version_String);
669 Write_Str ("Copyright 1992-" &
671 ", Free Software Foundation, Inc.");
675 -- Check we do not have more than one source file, this happens only in
676 -- the case where the driver is called directly, it cannot happen when
677 -- gnat1 is invoked from gcc in the normal case.
679 if Osint.Number_Of_Files /= 1 then
682 Osint.Fail ("you must provide one source file");
684 elsif Usage_Requested then
688 Original_Operating_Mode := Operating_Mode;
691 -- Exit with errors if the main source could not be parsed
693 if Sinput.Main_Source_File = No_Source_File then
694 Errout.Finalize (Last_Call => True);
695 Errout.Output_Messages;
696 Exit_Program (E_Errors);
699 Main_Unit_Node := Cunit (Main_Unit);
700 Main_Kind := Nkind (Unit (Main_Unit_Node));
703 -- Exit if compilation errors detected
705 Errout.Finalize (Last_Call => False);
707 if Compilation_Errors then
709 Sem_Ch13.Validate_Unchecked_Conversions;
710 Sem_Ch13.Validate_Address_Clauses;
711 Errout.Output_Messages;
714 -- Generate ALI file if specially requested
716 if Opt.Force_ALI_Tree_File then
717 Write_ALI (Object => False);
721 Errout.Finalize (Last_Call => True);
722 Exit_Program (E_Errors);
725 -- Set Generate_Code on main unit and its spec. We do this even if are
726 -- not generating code, since Lib-Writ uses this to determine which
727 -- units get written in the ali file.
729 Set_Generate_Code (Main_Unit);
731 -- If we have a corresponding spec, and it comes from source
732 -- or it is not a generated spec for a child subprogram body,
733 -- then we need object code for the spec unit as well.
735 if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
736 and then not Acts_As_Spec (Main_Unit_Node)
738 if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body
739 and then not Comes_From_Source (Library_Unit (Main_Unit_Node))
744 (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
748 -- Case of no code required to be generated, exit indicating no error
750 if Original_Operating_Mode = Check_Syntax then
752 Errout.Finalize (Last_Call => True);
753 Errout.Output_Messages;
758 -- Use a goto instead of calling Exit_Program so that finalization
763 elsif Original_Operating_Mode = Check_Semantics then
764 Back_End_Mode := Declarations_Only;
766 -- All remaining cases are cases in which the user requested that code
767 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if
768 -- we can in fact satisfy this request.
770 -- Cannot generate code if someone has turned off code generation for
771 -- any reason at all. We will try to figure out a reason below.
773 elsif Operating_Mode /= Generate_Code then
774 Back_End_Mode := Skip;
776 -- We can generate code for a subprogram body unless there were missing
777 -- subunits. Note that we always generate code for all generic units (a
778 -- change from some previous versions of GNAT).
780 elsif Main_Kind = N_Subprogram_Body
781 and then not Subunits_Missing
783 Back_End_Mode := Generate_Object;
785 -- We can generate code for a package body unless there are subunits
786 -- missing (note that we always generate code for generic units, which
787 -- is a change from some earlier versions of GNAT).
789 elsif Main_Kind = N_Package_Body
790 and then not Subunits_Missing
792 Back_End_Mode := Generate_Object;
794 -- We can generate code for a package declaration or a subprogram
795 -- declaration only if it does not required a body.
797 elsif (Main_Kind = N_Package_Declaration
799 Main_Kind = N_Subprogram_Declaration)
801 (not Body_Required (Main_Unit_Node)
803 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
805 Back_End_Mode := Generate_Object;
807 -- We can generate code for a generic package declaration of a generic
808 -- subprogram declaration only if does not require a body.
810 elsif (Main_Kind = N_Generic_Package_Declaration
812 Main_Kind = N_Generic_Subprogram_Declaration)
813 and then not Body_Required (Main_Unit_Node)
815 Back_End_Mode := Generate_Object;
817 -- Compilation units that are renamings do not require bodies,
818 -- so we can generate code for them.
820 elsif Main_Kind = N_Package_Renaming_Declaration
821 or else Main_Kind = N_Subprogram_Renaming_Declaration
823 Back_End_Mode := Generate_Object;
825 -- Compilation units that are generic renamings do not require bodies
826 -- so we can generate code for them.
828 elsif Main_Kind in N_Generic_Renaming_Declaration then
829 Back_End_Mode := Generate_Object;
831 -- It's not an error to generate SCIL for e.g. a spec which has a body
833 elsif CodePeer_Mode then
834 Back_End_Mode := Generate_Object;
836 -- In all other cases (specs which have bodies, generics, and bodies
837 -- where subunits are missing), we cannot generate code and we generate
838 -- a warning message. Note that generic instantiations are gone at this
839 -- stage since they have been replaced by their instances.
842 Back_End_Mode := Skip;
845 -- At this stage Back_End_Mode is set to indicate if the backend should
846 -- be called to generate code. If it is Skip, then code generation has
847 -- been turned off, even though code was requested by the original
848 -- command. This is not an error from the user point of view, but it is
849 -- an error from the point of view of the gcc driver, so we must exit
850 -- with an error status.
852 -- We generate an informative message (from the gcc point of view, it
853 -- is an error message, but from the users point of view this is not an
854 -- error, just a consequence of compiling something that cannot
857 if Back_End_Mode = Skip then
859 Write_Str ("cannot generate code for ");
861 Write_Name (Unit_File_Name (Main_Unit));
863 if Subunits_Missing then
864 Write_Str (" (missing subunits)");
866 Write_Str ("to check parent unit");
868 elsif Main_Kind = N_Subunit then
869 Write_Str (" (subunit)");
871 Write_Str ("to check subunit");
873 elsif Main_Kind = N_Subprogram_Declaration then
874 Write_Str (" (subprogram spec)");
876 Write_Str ("to check subprogram spec");
878 -- Generic package body in GNAT implementation mode
880 elsif Main_Kind = N_Package_Body and then GNAT_Mode then
881 Write_Str (" (predefined generic)");
883 Write_Str ("to check predefined generic");
885 -- Only other case is a package spec
888 Write_Str (" (package spec)");
890 Write_Str ("to check package spec");
893 Write_Str (" for errors, use ");
895 if Hostparm.OpenVMS then
896 Write_Str ("/NOLOAD");
898 Write_Str ("-gnatc");
904 Sem_Ch13.Validate_Unchecked_Conversions;
905 Sem_Ch13.Validate_Address_Clauses;
906 Errout.Finalize (Last_Call => True);
907 Errout.Output_Messages;
910 Write_ALI (Object => False);
914 -- Exit program with error indication, to kill object file
916 Exit_Program (E_No_Code);
919 -- In -gnatc mode, we only do annotation if -gnatt or -gnatR is also
920 -- set as indicated by Back_Annotate_Rep_Info being set to True.
922 -- We don't call for annotations on a subunit, because to process those
923 -- the back-end requires that the parent(s) be properly compiled.
925 -- Annotation is suppressed for targets where front-end layout is
926 -- enabled, because the front end determines representations.
928 -- Annotation is also suppressed in the case of compiling for
929 -- a VM, since representations are largely symbolic there.
931 if Back_End_Mode = Declarations_Only
932 and then (not (Back_Annotate_Rep_Info or Generate_SCIL)
933 or else Main_Kind = N_Subunit
934 or else Targparm.Frontend_Layout_On_Target
935 or else Targparm.VM_Target /= No_VM)
937 Sem_Ch13.Validate_Unchecked_Conversions;
938 Sem_Ch13.Validate_Address_Clauses;
939 Errout.Finalize (Last_Call => True);
940 Errout.Output_Messages;
941 Write_ALI (Object => False);
949 -- Ensure that we properly register a dependency on system.ads, since
950 -- even if we do not semantically depend on this, Targparm has read
951 -- system parameters from the system.ads file.
953 Lib.Writ.Ensure_System_Dependency;
955 -- Add dependencies, if any, on preprocessing data file and on
956 -- preprocessing definition file(s).
958 Prepcomp.Add_Dependencies;
960 -- Back end needs to explicitly unlock tables it needs to touch
973 -- ???Check_Library_Items under control of a debug flag, because it
974 -- currently does not work if the -gnatn switch (back end inlining) is
977 if Debug_Flag_Dot_WW then
981 -- Here we call the back end to generate the output code
983 Generating_Code := True;
984 Back_End.Call_Back_End (Back_End_Mode);
986 -- Once the backend is complete, we unlock the names table. This call
987 -- allows a few extra entries, needed for example for the file name for
988 -- the library file output.
992 -- Validate unchecked conversions (using the values for size and
993 -- alignment annotated by the backend where possible).
995 Sem_Ch13.Validate_Unchecked_Conversions;
997 -- Validate address clauses (again using alignment values annotated
998 -- by the backend where possible).
1000 Sem_Ch13.Validate_Address_Clauses;
1002 -- Now we complete output of errors, rep info and the tree info. These
1003 -- are delayed till now, since it is perfectly possible for gigi to
1004 -- generate errors, modify the tree (in particular by setting flags
1005 -- indicating that elaboration is required, and also to back annotate
1006 -- representation information for List_Rep_Info.
1008 Errout.Finalize (Last_Call => True);
1009 Errout.Output_Messages;
1012 -- Only write the library if the backend did not generate any error
1013 -- messages. Otherwise signal errors to the driver program so that
1014 -- there will be no attempt to generate an object file.
1016 if Compilation_Errors then
1018 Exit_Program (E_Errors);
1021 Write_ALI (Object => (Back_End_Mode = Generate_Object));
1023 -- Generate the ASIS tree after writing the ALI file, since in ASIS
1024 -- mode, Write_ALI may in fact result in further tree decoration from
1025 -- the original tree file. Note that we dump the tree just before
1026 -- generating it, so that the dump will exactly reflect what is written
1032 -- Finalize name table and we are all done
1037 -- Handle fatal internal compiler errors
1039 when Rtsfind.RE_Not_Available =>
1040 Comperr.Compiler_Abort ("RE_Not_Available");
1042 when System.Assertions.Assert_Failure =>
1043 Comperr.Compiler_Abort ("Assert_Failure");
1045 when Constraint_Error =>
1046 Comperr.Compiler_Abort ("Constraint_Error");
1048 when Program_Error =>
1049 Comperr.Compiler_Abort ("Program_Error");
1051 when Storage_Error =>
1053 -- Assume this is a bug. If it is real, the message will in any case
1054 -- say Storage_Error, giving a strong hint!
1056 Comperr.Compiler_Abort ("Storage_Error");
1062 -- The outer exception handles an unrecoverable error
1065 when Unrecoverable_Error =>
1066 Errout.Finalize (Last_Call => True);
1067 Errout.Output_Messages;
1070 Write_Str ("compilation abandoned");
1073 Set_Standard_Output;
1076 Exit_Program (E_Errors);