OSDN Git Service

2009-04-20 Arnaud Charlet <charlet@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / gnat1drv.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             G N A T 1 D R V                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with Atree;    use Atree;
27 with Back_End; use Back_End;
28 with Comperr;
29 with Csets;    use Csets;
30 with Debug;    use Debug;
31 with Elists;
32 with Errout;   use Errout;
33 with Fmap;
34 with Fname;    use Fname;
35 with Fname.UF; use Fname.UF;
36 with Frontend;
37 with Gnatvsn;  use Gnatvsn;
38 with Hostparm;
39 with Inline;
40 with Lib;      use Lib;
41 with Lib.Writ; use Lib.Writ;
42 with Lib.Xref;
43 with Namet;    use Namet;
44 with Nlists;
45 with Opt;      use Opt;
46 with Osint;    use Osint;
47 with Output;   use Output;
48 with Prepcomp;
49 with Repinfo;  use Repinfo;
50 with Restrict;
51 with Rtsfind;
52 with Sem;
53 with Sem_Ch8;
54 with Sem_Ch12;
55 with Sem_Ch13;
56 with Sem_Elim;
57 with Sem_Eval;
58 with Sem_Type;
59 with Sinfo;    use Sinfo;
60 with Sinput.L; use Sinput.L;
61 with Snames;
62 with Sprint;   use Sprint;
63 with Stringt;
64 with Targparm; use Targparm;
65 with Tree_Gen;
66 with Treepr;   use Treepr;
67 with Ttypes;
68 with Types;    use Types;
69 with Uintp;    use Uintp;
70 with Uname;    use Uname;
71 with Urealp;
72 with Usage;
73
74 with System.Assertions;
75
76 procedure Gnat1drv is
77    Main_Unit_Node : Node_Id;
78    --  Compilation unit node for main unit
79
80    Main_Kind : Node_Kind;
81    --  Kind of main compilation unit node
82
83    Back_End_Mode : Back_End.Back_End_Mode_Type;
84    --  Record back end mode
85
86    procedure Check_Bad_Body;
87    --  Called to check if the unit we are compiling has a bad body
88
89    procedure Check_Rep_Info;
90    --  Called when we are not generating code, to check if -gnatR was requested
91    --  and if so, explain that we will not be honoring the request.
92
93    --------------------
94    -- Check_Bad_Body --
95    --------------------
96
97    procedure Check_Bad_Body is
98       Sname   : Unit_Name_Type;
99       Src_Ind : Source_File_Index;
100       Fname   : File_Name_Type;
101
102       procedure Bad_Body_Error (Msg : String);
103       --  Issue message for bad body found
104
105       --------------------
106       -- Bad_Body_Error --
107       --------------------
108
109       procedure Bad_Body_Error (Msg : String) is
110       begin
111          Error_Msg_N (Msg, Main_Unit_Node);
112          Error_Msg_File_1 := Fname;
113          Error_Msg_N ("remove incorrect body in file{!", Main_Unit_Node);
114       end Bad_Body_Error;
115
116       --  Start of processing for Check_Bad_Body
117
118    begin
119       --  Nothing to do if we are only checking syntax, because we don't know
120       --  enough to know if we require or forbid a body in this case.
121
122       if Operating_Mode = Check_Syntax then
123          return;
124       end if;
125
126       --  Check for body not allowed
127
128       if (Main_Kind = N_Package_Declaration
129            and then not Body_Required (Main_Unit_Node))
130         or else (Main_Kind = N_Generic_Package_Declaration
131                   and then not Body_Required (Main_Unit_Node))
132         or else Main_Kind = N_Package_Renaming_Declaration
133         or else Main_Kind = N_Subprogram_Renaming_Declaration
134         or else Nkind (Original_Node (Unit (Main_Unit_Node)))
135                          in N_Generic_Instantiation
136       then
137          Sname := Unit_Name (Main_Unit);
138
139          --  If we do not already have a body name, then get the body name
140          --  (but how can we have a body name here ???)
141
142          if not Is_Body_Name (Sname) then
143             Sname := Get_Body_Name (Sname);
144          end if;
145
146          Fname := Get_File_Name (Sname, Subunit => False);
147          Src_Ind := Load_Source_File (Fname);
148
149          --  Case where body is present and it is not a subunit. Exclude
150          --  the subunit case, because it has nothing to do with the
151          --  package we are compiling. It is illegal for a child unit and a
152          --  subunit with the same expanded name (RM 10.2(9)) to appear
153          --  together in a partition, but there is nothing to stop a
154          --  compilation environment from having both, and the test here
155          --  simply allows that. If there is an attempt to include both in
156          --  a partition, this is diagnosed at bind time. In Ada 83 mode
157          --  this is not a warning case.
158
159          --  Note: if weird file names are being used, we can have
160          --  situation where the file name that supposedly contains body,
161          --  in fact contains a spec, or we can't tell what it contains.
162          --  Skip the error message in these cases.
163
164          --  Also ignore body that is nothing but pragma No_Body; (that's the
165          --  whole point of this pragma, to be used this way and to cause the
166          --  body file to be ignored in this context).
167
168          if Src_Ind /= No_Source_File
169            and then Get_Expected_Unit_Type (Fname) = Expect_Body
170            and then not Source_File_Is_Subunit (Src_Ind)
171            and then not Source_File_Is_No_Body (Src_Ind)
172          then
173             Errout.Finalize (Last_Call => False);
174
175             Error_Msg_Unit_1 := Sname;
176
177             --  Ada 83 case of a package body being ignored. This is not an
178             --  error as far as the Ada 83 RM is concerned, but it is almost
179             --  certainly not what is wanted so output a warning. Give this
180             --  message only if there were no errors, since otherwise it may
181             --  be incorrect (we may have misinterpreted a junk spec as not
182             --  needing a body when it really does).
183
184             if Main_Kind = N_Package_Declaration
185               and then Ada_Version = Ada_83
186               and then Operating_Mode = Generate_Code
187               and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
188               and then not Compilation_Errors
189             then
190                Error_Msg_N
191                  ("package $$ does not require a body?", Main_Unit_Node);
192                Error_Msg_File_1 := Fname;
193                Error_Msg_N ("body in file{? will be ignored", Main_Unit_Node);
194
195                --  Ada 95 cases of a body file present when no body is
196                --  permitted. This we consider to be an error.
197
198             else
199                --  For generic instantiations, we never allow a body
200
201                if Nkind (Original_Node (Unit (Main_Unit_Node)))
202                in N_Generic_Instantiation
203                then
204                   Bad_Body_Error
205                     ("generic instantiation for $$ does not allow a body");
206
207                   --  A library unit that is a renaming never allows a body
208
209                elsif Main_Kind in N_Renaming_Declaration then
210                   Bad_Body_Error
211                     ("renaming declaration for $$ does not allow a body!");
212
213                   --  Remaining cases are packages and generic packages. Here
214                   --  we only do the test if there are no previous errors,
215                   --  because if there are errors, they may lead us to
216                   --  incorrectly believe that a package does not allow a body
217                   --  when in fact it does.
218
219                elsif not Compilation_Errors then
220                   if Main_Kind = N_Package_Declaration then
221                      Bad_Body_Error
222                        ("package $$ does not allow a body!");
223
224                   elsif Main_Kind = N_Generic_Package_Declaration then
225                      Bad_Body_Error
226                        ("generic package $$ does not allow a body!");
227                   end if;
228                end if;
229
230             end if;
231          end if;
232       end if;
233    end Check_Bad_Body;
234
235    --------------------
236    -- Check_Rep_Info --
237    --------------------
238
239    procedure Check_Rep_Info is
240    begin
241       if List_Representation_Info /= 0
242         or else List_Representation_Info_Mechanisms
243       then
244          Set_Standard_Error;
245          Write_Eol;
246          Write_Str
247            ("cannot generate representation information, no code generated");
248          Write_Eol;
249          Write_Eol;
250          Set_Standard_Output;
251       end if;
252    end Check_Rep_Info;
253
254 --  Start of processing for Gnat1drv
255
256 begin
257    --  This inner block is set up to catch assertion errors and constraint
258    --  errors. Since the code for handling these errors can cause another
259    --  exception to be raised (namely Unrecoverable_Error), we need two
260    --  nested blocks, so that the outer one handles unrecoverable error.
261
262    begin
263       --  Lib.Initialize need to be called before Scan_Compiler_Arguments,
264       --  because it initializes a table filled by Scan_Compiler_Arguments.
265
266       Osint.Initialize;
267       Fmap.Reset_Tables;
268       Lib.Initialize;
269       Lib.Xref.Initialize;
270       Scan_Compiler_Arguments;
271       Osint.Add_Default_Search_Dirs;
272
273       Nlists.Initialize;
274       Sinput.Initialize;
275       Sem.Initialize;
276       Csets.Initialize;
277       Uintp.Initialize;
278       Urealp.Initialize;
279       Errout.Initialize;
280       Namet.Initialize;
281       Snames.Initialize;
282       Stringt.Initialize;
283       Inline.Initialize;
284       Sem_Ch8.Initialize;
285       Sem_Ch12.Initialize;
286       Sem_Ch13.Initialize;
287       Sem_Elim.Initialize;
288       Sem_Eval.Initialize;
289       Sem_Type.Init_Interp_Tables;
290
291       --  Acquire target parameters from system.ads (source of package System)
292
293       declare
294          use Sinput;
295
296          S : Source_File_Index;
297          N : File_Name_Type;
298
299       begin
300          Name_Buffer (1 .. 10) := "system.ads";
301          Name_Len := 10;
302          N := Name_Find;
303          S := Load_Source_File (N);
304
305          if S = No_Source_File then
306             Write_Line
307               ("fatal error, run-time library not installed correctly");
308             Write_Line
309               ("cannot locate file system.ads");
310             raise Unrecoverable_Error;
311
312          --  Remember source index of system.ads (which was read successfully)
313
314          else
315             System_Source_File_Index := S;
316          end if;
317
318          Targparm.Get_Target_Parameters
319            (System_Text  => Source_Text  (S),
320             Source_First => Source_First (S),
321             Source_Last  => Source_Last  (S));
322
323          --  Acquire configuration pragma information from Targparm
324
325          Restrict.Restrictions := Targparm.Restrictions_On_Target;
326       end;
327
328       --  Set Configurable_Run_Time mode if system.ads flag set
329
330       if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
331          Configurable_Run_Time_Mode := True;
332       end if;
333
334       --  Set -gnatR3m mode if debug flag A set
335
336       if Debug_Flag_AA then
337          Back_Annotate_Rep_Info := True;
338          List_Representation_Info := 1;
339          List_Representation_Info_Mechanisms := True;
340       end if;
341
342       --  Force Target_Strict_Alignment true if debug flag -gnatd.a is set
343
344       if Debug_Flag_Dot_A then
345          Ttypes.Target_Strict_Alignment := True;
346       end if;
347
348       --  Disable static allocation of dispatch tables if -gnatd.t or if layout
349       --  is enabled. The front end's layout phase currently treats types that
350       --  have discriminant-dependent arrays as not being static even when a
351       --  discriminant constraint on the type is static, and this leads to
352       --  problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
353
354       if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then
355          Static_Dispatch_Tables := False;
356       end if;
357
358       --  Output copyright notice if full list mode unless we have a list
359       --  file, in which case we defer this so that it is output in the file
360
361       if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
362         and then not Debug_Flag_7
363       then
364          Write_Eol;
365          Write_Str ("GNAT ");
366          Write_Str (Gnat_Version_String);
367          Write_Eol;
368          Write_Str ("Copyright 1992-" &
369                     Current_Year &
370                     ", Free Software Foundation, Inc.");
371          Write_Eol;
372       end if;
373
374       --  Before we do anything else, adjust certain global values for
375       --  debug switches which modify their normal natural settings.
376
377       if Debug_Flag_8 then
378          Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
379       end if;
380
381       --  Deal with forcing OpenVMS switches Ture if debug flag M is set, but
382       --  record the setting of Targparm.Open_VMS_On_Target in True_VMS_Target
383       --  before doing this.
384
385       Opt.True_VMS_Target := Targparm.OpenVMS_On_Target;
386
387       if Debug_Flag_M then
388          Targparm.OpenVMS_On_Target := True;
389          Hostparm.OpenVMS := True;
390       end if;
391
392       if Debug_Flag_FF then
393          Targparm.Frontend_Layout_On_Target := True;
394       end if;
395
396       --  We take the default exception mechanism into account
397
398       if Targparm.ZCX_By_Default_On_Target then
399          if Targparm.GCC_ZCX_Support_On_Target then
400             Exception_Mechanism := Back_End_Exceptions;
401          else
402             Osint.Fail ("Zero Cost Exceptions not supported on this target");
403          end if;
404       end if;
405
406       --  Set proper status for overflow checks. We turn on overflow checks
407       --  if -gnatp was not specified, and either -gnato is set or the back
408       --  end takes care of overflow checks. Otherwise we suppress overflow
409       --  checks by default (since front end checks are expensive).
410
411       if not Opt.Suppress_Checks
412         and then (Opt.Enable_Overflow_Checks
413                     or else
414                       (Targparm.Backend_Divide_Checks_On_Target
415                         and
416                        Targparm.Backend_Overflow_Checks_On_Target))
417       then
418          Suppress_Options (Overflow_Check) := False;
419       else
420          Suppress_Options (Overflow_Check) := True;
421       end if;
422
423       --  Check we do not have more than one source file, this happens only in
424       --  the case where the driver is called directly, it cannot happen when
425       --  gnat1 is invoked from gcc in the normal case.
426
427       if Osint.Number_Of_Files /= 1 then
428          Usage;
429          Write_Eol;
430          Osint.Fail ("you must provide one source file");
431
432       elsif Usage_Requested then
433          Usage;
434       end if;
435
436       Original_Operating_Mode := Operating_Mode;
437       Frontend;
438
439       --  Exit with errors if the main source could not be parsed
440
441       if Sinput.Main_Source_File = No_Source_File then
442          Errout.Finalize (Last_Call => True);
443          Errout.Output_Messages;
444          Exit_Program (E_Errors);
445       end if;
446
447       Main_Unit_Node := Cunit (Main_Unit);
448       Main_Kind := Nkind (Unit (Main_Unit_Node));
449       Check_Bad_Body;
450
451       --  Exit if compilation errors detected
452
453       Errout.Finalize (Last_Call => False);
454
455       if Compilation_Errors then
456          Treepr.Tree_Dump;
457          Sem_Ch13.Validate_Unchecked_Conversions;
458          Sem_Ch13.Validate_Address_Clauses;
459          Errout.Output_Messages;
460          Namet.Finalize;
461
462          --  Generate ALI file if specially requested
463
464          if Opt.Force_ALI_Tree_File then
465             Write_ALI (Object => False);
466             Tree_Gen;
467          end if;
468
469          Errout.Finalize (Last_Call => True);
470          Exit_Program (E_Errors);
471       end if;
472
473       --  Set Generate_Code on main unit and its spec. We do this even if are
474       --  not generating code, since Lib-Writ uses this to determine which
475       --  units get written in the ali file.
476
477       Set_Generate_Code (Main_Unit);
478
479       --  If we have a corresponding spec, then we need object
480       --  code for the spec unit as well
481
482       if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
483         and then not Acts_As_Spec (Main_Unit_Node)
484       then
485          Set_Generate_Code
486            (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
487       end if;
488
489       --  Case of no code required to be generated, exit indicating no error
490
491       if Original_Operating_Mode = Check_Syntax then
492          Treepr.Tree_Dump;
493          Errout.Finalize (Last_Call => True);
494          Errout.Output_Messages;
495          Tree_Gen;
496          Namet.Finalize;
497          Check_Rep_Info;
498
499          --  Use a goto instead of calling Exit_Program so that finalization
500          --  occurs normally.
501
502          goto End_Of_Program;
503
504       elsif Original_Operating_Mode = Check_Semantics then
505          Back_End_Mode := Declarations_Only;
506
507       --  All remaining cases are cases in which the user requested that code
508       --  be generated (i.e. no -gnatc or -gnats switch was used). Check if
509       --  we can in fact satisfy this request.
510
511       --  Cannot generate code if someone has turned off code generation for
512       --  any reason at all. We will try to figure out a reason below.
513
514       elsif Operating_Mode /= Generate_Code then
515          Back_End_Mode := Skip;
516
517       --  We can generate code for a subprogram body unless there were missing
518       --  subunits. Note that we always generate code for all generic units (a
519       --  change from some previous versions of GNAT).
520
521       elsif Main_Kind = N_Subprogram_Body
522         and then not Subunits_Missing
523       then
524          Back_End_Mode := Generate_Object;
525
526       --  We can generate code for a package body unless there are subunits
527       --  missing (note that we always generate code for generic units, which
528       --  is a change from some earlier versions of GNAT).
529
530       elsif Main_Kind = N_Package_Body
531         and then not Subunits_Missing
532       then
533          Back_End_Mode := Generate_Object;
534
535       --  We can generate code for a package declaration or a subprogram
536       --  declaration only if it does not required a body.
537
538       elsif (Main_Kind = N_Package_Declaration
539                or else
540              Main_Kind = N_Subprogram_Declaration)
541         and then
542           (not Body_Required (Main_Unit_Node)
543              or else
544            Distribution_Stub_Mode = Generate_Caller_Stub_Body)
545       then
546          Back_End_Mode := Generate_Object;
547
548       --  We can generate code for a generic package declaration of a generic
549       --  subprogram declaration only if does not require a body.
550
551       elsif (Main_Kind = N_Generic_Package_Declaration
552                or else
553              Main_Kind = N_Generic_Subprogram_Declaration)
554         and then not Body_Required (Main_Unit_Node)
555       then
556          Back_End_Mode := Generate_Object;
557
558       --  Compilation units that are renamings do not require bodies,
559       --  so we can generate code for them.
560
561       elsif Main_Kind = N_Package_Renaming_Declaration
562         or else Main_Kind = N_Subprogram_Renaming_Declaration
563       then
564          Back_End_Mode := Generate_Object;
565
566       --  Compilation units that are generic renamings do not require bodies
567       --  so we can generate code for them.
568
569       elsif Main_Kind in N_Generic_Renaming_Declaration then
570          Back_End_Mode := Generate_Object;
571
572       --  In all other cases (specs which have bodies, generics, and bodies
573       --  where subunits are missing), we cannot generate code and we generate
574       --  a warning message. Note that generic instantiations are gone at this
575       --  stage since they have been replaced by their instances.
576
577       else
578          Back_End_Mode := Skip;
579       end if;
580
581       --  At this stage Call_Back_End is set to indicate if the backend should
582       --  be called to generate code. If it is not set, then code generation
583       --  has been turned off, even though code was requested by the original
584       --  command. This is not an error from the user point of view, but it is
585       --  an error from the point of view of the gcc driver, so we must exit
586       --  with an error status.
587
588       --  We generate an informative message (from the gcc point of view, it
589       --  is an error message, but from the users point of view this is not an
590       --  error, just a consequence of compiling something that cannot
591       --  generate code).
592
593       if Back_End_Mode = Skip then
594          Set_Standard_Error;
595          Write_Str ("cannot generate code for ");
596          Write_Str ("file ");
597          Write_Name (Unit_File_Name (Main_Unit));
598
599          if Subunits_Missing then
600             Write_Str (" (missing subunits)");
601             Write_Eol;
602             Write_Str ("to check parent unit");
603
604          elsif Main_Kind = N_Subunit then
605             Write_Str (" (subunit)");
606             Write_Eol;
607             Write_Str ("to check subunit");
608
609          elsif Main_Kind = N_Subprogram_Declaration then
610             Write_Str (" (subprogram spec)");
611             Write_Eol;
612             Write_Str ("to check subprogram spec");
613
614          --  Generic package body in GNAT implementation mode
615
616          elsif Main_Kind = N_Package_Body and then GNAT_Mode then
617             Write_Str (" (predefined generic)");
618             Write_Eol;
619             Write_Str ("to check predefined generic");
620
621          --  Only other case is a package spec
622
623          else
624             Write_Str (" (package spec)");
625             Write_Eol;
626             Write_Str ("to check package spec");
627          end if;
628
629          Write_Str (" for errors, use ");
630
631          if Hostparm.OpenVMS then
632             Write_Str ("/NOLOAD");
633          else
634             Write_Str ("-gnatc");
635          end if;
636
637          Write_Eol;
638          Set_Standard_Output;
639
640          Sem_Ch13.Validate_Unchecked_Conversions;
641          Sem_Ch13.Validate_Address_Clauses;
642          Errout.Finalize (Last_Call => True);
643          Errout.Output_Messages;
644          Treepr.Tree_Dump;
645          Tree_Gen;
646          Write_ALI (Object => False);
647          Namet.Finalize;
648          Check_Rep_Info;
649
650          --  Exit program with error indication, to kill object file
651
652          Exit_Program (E_No_Code);
653       end if;
654
655       --  In -gnatc mode, we only do annotation if -gnatt or -gnatR is also
656       --  set as indicated by Back_Annotate_Rep_Info being set to True.
657
658       --  We don't call for annotations on a subunit, because to process those
659       --  the back-end requires that the parent(s) be properly compiled.
660
661       --  Annotation is suppressed for targets where front-end layout is
662       --  enabled, because the front end determines representations.
663
664       --  Annotation is also suppressed in the case of compiling for
665       --  a VM, since representations are largely symbolic there.
666
667       if Back_End_Mode = Declarations_Only
668         and then (not Back_Annotate_Rep_Info
669                    or else Main_Kind = N_Subunit
670                    or else Targparm.Frontend_Layout_On_Target
671                    or else Targparm.VM_Target /= No_VM)
672       then
673          Sem_Ch13.Validate_Unchecked_Conversions;
674          Sem_Ch13.Validate_Address_Clauses;
675          Errout.Finalize (Last_Call => True);
676          Errout.Output_Messages;
677          Write_ALI (Object => False);
678          Tree_Dump;
679          Tree_Gen;
680          Namet.Finalize;
681          Check_Rep_Info;
682          return;
683       end if;
684
685       --  Ensure that we properly register a dependency on system.ads, since
686       --  even if we do not semantically depend on this, Targparm has read
687       --  system parameters from the system.ads file.
688
689       Lib.Writ.Ensure_System_Dependency;
690
691       --  Add dependencies, if any, on preprocessing data file and on
692       --  preprocessing definition file(s).
693
694       Prepcomp.Add_Dependencies;
695
696       --  Back end needs to explicitly unlock tables it needs to touch
697
698       Atree.Lock;
699       Elists.Lock;
700       Fname.UF.Lock;
701       Inline.Lock;
702       Lib.Lock;
703       Nlists.Lock;
704       Sem.Lock;
705       Sinput.Lock;
706       Namet.Lock;
707       Stringt.Lock;
708
709       --  Here we call the back end to generate the output code
710
711       Generating_Code := True;
712       Back_End.Call_Back_End (Back_End_Mode);
713
714       --  Once the backend is complete, we unlock the names table. This call
715       --  allows a few extra entries, needed for example for the file name for
716       --  the library file output.
717
718       Namet.Unlock;
719
720       --  Validate unchecked conversions (using the values for size and
721       --  alignment annotated by the backend where possible).
722
723       Sem_Ch13.Validate_Unchecked_Conversions;
724
725       --  Validate address clauses (again using alignment values annotated
726       --  by the backend where possible).
727
728       Sem_Ch13.Validate_Address_Clauses;
729
730       --  Now we complete output of errors, rep info and the tree info. These
731       --  are delayed till now, since it is perfectly possible for gigi to
732       --  generate errors, modify the tree (in particular by setting flags
733       --  indicating that elaboration is required, and also to back annotate
734       --  representation information for List_Rep_Info.
735
736       Errout.Finalize (Last_Call => True);
737       Errout.Output_Messages;
738       List_Rep_Info;
739
740       --  Only write the library if the backend did not generate any error
741       --  messages. Otherwise signal errors to the driver program so that
742       --  there will be no attempt to generate an object file.
743
744       if Compilation_Errors then
745          Treepr.Tree_Dump;
746          Exit_Program (E_Errors);
747       end if;
748
749       Write_ALI (Object => (Back_End_Mode = Generate_Object));
750
751       --  Generate the ASIS tree after writing the ALI file, since in ASIS
752       --  mode, Write_ALI may in fact result in further tree decoration from
753       --  the original tree file. Note that we dump the tree just before
754       --  generating it, so that the dump will exactly reflect what is written
755       --  out.
756
757       Treepr.Tree_Dump;
758       Tree_Gen;
759
760       --  Finalize name table and we are all done
761
762       Namet.Finalize;
763
764    exception
765       --  Handle fatal internal compiler errors
766
767       when Rtsfind.RE_Not_Available =>
768          Comperr.Compiler_Abort ("RE_Not_Available");
769
770       when System.Assertions.Assert_Failure =>
771          Comperr.Compiler_Abort ("Assert_Failure");
772
773       when Constraint_Error =>
774          Comperr.Compiler_Abort ("Constraint_Error");
775
776       when Program_Error =>
777          Comperr.Compiler_Abort ("Program_Error");
778
779       when Storage_Error =>
780
781          --  Assume this is a bug. If it is real, the message will in any case
782          --  say Storage_Error, giving a strong hint!
783
784          Comperr.Compiler_Abort ("Storage_Error");
785    end;
786
787    <<End_Of_Program>>
788    null;
789
790    --  The outer exception handles an unrecoverable error
791
792 exception
793    when Unrecoverable_Error =>
794       Errout.Finalize (Last_Call => True);
795       Errout.Output_Messages;
796
797       Set_Standard_Error;
798       Write_Str ("compilation abandoned");
799       Write_Eol;
800
801       Set_Standard_Output;
802       Source_Dump;
803       Tree_Dump;
804       Exit_Program (E_Errors);
805
806 end Gnat1drv;