* gcc-interface/Makefile.in: Clean up VxWorks targets.
[platform/upstream/gcc.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-2016, 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 Checks;
29 with Comperr;
30 with Csets;    use Csets;
31 with Debug;    use Debug;
32 with Elists;
33 with Errout;   use Errout;
34 with Exp_CG;
35 with Fmap;
36 with Fname;    use Fname;
37 with Fname.UF; use Fname.UF;
38 with Frontend;
39 with Ghost;
40 with Gnatvsn;  use Gnatvsn;
41 with Inline;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref;
45 with Namet;    use Namet;
46 with Nlists;
47 with Opt;      use Opt;
48 with Osint;    use Osint;
49 with Osint.C;  use Osint.C;
50 with Output;   use Output;
51 with Par_SCO;
52 with Prepcomp;
53 with Repinfo;  use Repinfo;
54 with Restrict;
55 with Rident;   use Rident;
56 with Rtsfind;
57 with SCOs;
58 with Sem;
59 with Sem_Ch8;
60 with Sem_Ch12;
61 with Sem_Ch13;
62 with Sem_Elim;
63 with Sem_Eval;
64 with Sem_Type;
65 with Set_Targ;
66 with Sinfo;    use Sinfo;
67 with Sinput.L; use Sinput.L;
68 with Snames;
69 with Sprint;   use Sprint;
70 with Stringt;
71 with Stylesw;  use Stylesw;
72 with Targparm; use Targparm;
73 with Tbuild;
74 with Tree_Gen;
75 with Treepr;   use Treepr;
76 with Ttypes;
77 with Types;    use Types;
78 with Uintp;    use Uintp;
79 with Uname;    use Uname;
80 with Urealp;
81 with Usage;
82 with Validsw;  use Validsw;
83
84 with System.Assertions;
85 with System.OS_Lib;
86
87 --------------
88 -- Gnat1drv --
89 --------------
90
91 procedure Gnat1drv is
92    procedure Adjust_Global_Switches;
93    --  There are various interactions between front-end switch settings,
94    --  including debug switch settings and target dependent parameters.
95    --  This procedure takes care of properly handling these interactions.
96    --  We do it after scanning out all the switches, so that we are not
97    --  depending on the order in which switches appear.
98
99    procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind);
100    --  Called to check whether a unit described by its compilation unit node
101    --  and kind has a bad body.
102
103    procedure Check_Rep_Info;
104    --  Called when we are not generating code, to check if -gnatR was requested
105    --  and if so, explain that we will not be honoring the request.
106
107    procedure Post_Compilation_Validation_Checks;
108    --  This procedure performs various validation checks that have to be left
109    --  to the end of the compilation process, after generating code but before
110    --  issuing error messages. In particular, these checks generally require
111    --  the information provided by the back end in back annotation of declared
112    --  entities (e.g. actual size and alignment values chosen by the back end).
113
114    ----------------------------
115    -- Adjust_Global_Switches --
116    ----------------------------
117
118    procedure Adjust_Global_Switches is
119    begin
120       --  -gnatd.M enables Relaxed_RM_Semantics
121
122       if Debug_Flag_Dot_MM then
123          Relaxed_RM_Semantics := True;
124       end if;
125
126       --  -gnatd.1 enables unnesting of subprograms
127
128       if Debug_Flag_Dot_1 then
129          Unnest_Subprogram_Mode := True;
130       end if;
131
132       --  -gnatd.u enables special C expansion mode
133
134       if Debug_Flag_Dot_U then
135          Modify_Tree_For_C := True;
136       end if;
137
138       --  Set all flags required when generating C code
139
140       if Generate_C_Code then
141          Modify_Tree_For_C := True;
142          Unnest_Subprogram_Mode := True;
143          Minimize_Expression_With_Actions := True;
144
145          --  Set operating mode to Generate_Code to benefit from full front-end
146          --  expansion (e.g. generics).
147
148          Operating_Mode := Generate_Code;
149
150          --  Suppress alignment checks since we do not have access to alignment
151          --  info on the target.
152
153          Suppress_Options.Suppress (Alignment_Check) := False;
154       end if;
155
156       --  -gnatd.E sets Error_To_Warning mode, causing selected error messages
157       --  to be treated as warnings instead of errors.
158
159       if Debug_Flag_Dot_EE then
160          Error_To_Warning := True;
161       end if;
162
163       --  Disable CodePeer_Mode in Check_Syntax, since we need front-end
164       --  expansion.
165
166       if Operating_Mode = Check_Syntax then
167          CodePeer_Mode := False;
168       end if;
169
170       --  Set ASIS mode if -gnatt and -gnatc are set
171
172       if Operating_Mode = Check_Semantics and then Tree_Output then
173          ASIS_Mode := True;
174
175          --  Set ASIS GNSA mode if -gnatd.H is set
176
177          if Debug_Flag_Dot_HH then
178             ASIS_GNSA_Mode := True;
179          end if;
180
181          --  Turn off inlining in ASIS mode, since ASIS cannot handle the extra
182          --  information in the trees caused by inlining being active.
183
184          --  More specifically, the tree seems to be malformed from the ASIS
185          --  point of view if -gnatc and -gnatn appear together???
186
187          Inline_Active := False;
188
189          --  Turn off SCIL generation and CodePeer mode in semantics mode,
190          --  since SCIL requires front-end expansion.
191
192          Generate_SCIL := False;
193          CodePeer_Mode := False;
194       end if;
195
196       --  SCIL mode needs to disable front-end inlining since the generated
197       --  trees (in particular order and consistency between specs compiled
198       --  as part of a main unit or as part of a with-clause) are causing
199       --  troubles.
200
201       if Generate_SCIL then
202          Front_End_Inlining := False;
203       end if;
204
205       --  Tune settings for optimal SCIL generation in CodePeer mode
206
207       if CodePeer_Mode then
208
209          --  Turn off gnatprove mode (which can be set via e.g. -gnatd.F), not
210          --  compatible with CodePeer mode.
211
212          GNATprove_Mode := False;
213          Debug_Flag_Dot_FF := False;
214
215          --  Turn off C tree generation, not compatible with CodePeer mode. We
216          --  do not expect this to happen in normal use, since both modes are
217          --  enabled by special tools, but it is useful to turn off these flags
218          --  this way when we are doing CodePeer tests on existing test suites
219          --  that may have -gnateg set, to avoid the need for special casing.
220
221          Modify_Tree_For_C := False;
222          Generate_C_Code := False;
223          Unnest_Subprogram_Mode := False;
224
225          --  Turn off inlining, confuses CodePeer output and gains nothing
226
227          Front_End_Inlining := False;
228          Inline_Active      := False;
229
230          --  Disable front-end optimizations, to keep the tree as close to the
231          --  source code as possible, and also to avoid inconsistencies between
232          --  trees when using different optimization switches.
233
234          Optimization_Level := 0;
235
236          --  Enable some restrictions systematically to simplify the generated
237          --  code (and ease analysis). Note that restriction checks are also
238          --  disabled in CodePeer mode, see Restrict.Check_Restriction, and
239          --  user specified Restrictions pragmas are ignored, see
240          --  Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
241
242          Restrict.Restrictions.Set   (No_Exception_Registration)       := True;
243          Restrict.Restrictions.Set   (No_Initialize_Scalars)           := True;
244          Restrict.Restrictions.Set   (No_Task_Hierarchy)               := True;
245          Restrict.Restrictions.Set   (No_Abort_Statements)             := True;
246          Restrict.Restrictions.Set   (Max_Asynchronous_Select_Nesting) := True;
247          Restrict.Restrictions.Value (Max_Asynchronous_Select_Nesting) := 0;
248
249          --  Suppress division by zero and access checks since they are handled
250          --  implicitly by CodePeer.
251
252          --  Turn off dynamic elaboration checks: generates inconsistencies in
253          --  trees between specs compiled as part of a main unit or as part of
254          --  a with-clause.
255
256          --  Turn off alignment checks: these cannot be proved statically by
257          --  CodePeer and generate false positives.
258
259          --  Enable all other language checks
260
261          Suppress_Options.Suppress :=
262            (Alignment_Check   => True,
263             Division_Check    => True,
264             Elaboration_Check => True,
265             others            => False);
266
267          Dynamic_Elaboration_Checks := False;
268
269          --  Set STRICT mode for overflow checks if not set explicitly. This
270          --  prevents suppressing of overflow checks by default, in code down
271          --  below.
272
273          if Suppress_Options.Overflow_Mode_General = Not_Set then
274             Suppress_Options.Overflow_Mode_General    := Strict;
275             Suppress_Options.Overflow_Mode_Assertions := Strict;
276          end if;
277
278          --  CodePeer handles division and overflow checks directly, based on
279          --  the marks set by the frontend, hence no special expansion should
280          --  be performed in the frontend for division and overflow checks.
281
282          Backend_Divide_Checks_On_Target   := True;
283          Backend_Overflow_Checks_On_Target := True;
284
285          --  Kill debug of generated code, since it messes up sloc values
286
287          Debug_Generated_Code := False;
288
289          --  Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
290          --  to support source navigation.
291
292          Xref_Active := True;
293
294          --  Polling mode forced off, since it generates confusing junk
295
296          Polling_Required := False;
297
298          --  Set operating mode to Generate_Code to benefit from full front-end
299          --  expansion (e.g. generics).
300
301          Operating_Mode := Generate_Code;
302
303          --  We need SCIL generation of course
304
305          Generate_SCIL := True;
306
307          --  Enable assertions, since they give CodePeer valuable extra info
308
309          Assertions_Enabled := True;
310
311          --  Set normal RM validity checking and checking of copies (to catch
312          --  e.g. wrong values used in unchecked conversions).
313          --  All other validity checking is turned off, since this can generate
314          --  very complex trees that only confuse CodePeer and do not bring
315          --  enough useful info.
316
317          Reset_Validity_Check_Options;
318          Validity_Check_Default       := True;
319          Validity_Check_Copies        := True;
320
321          --  Turn off style check options and ignore any style check pragmas
322          --  since we are not interested in any front-end warnings when we are
323          --  getting CodePeer output.
324
325          Reset_Style_Check_Options;
326          Ignore_Style_Checks_Pragmas := True;
327
328          --  Always perform semantics and generate ali files in CodePeer mode,
329          --  so that a gnatmake -c -k will proceed further when possible.
330
331          Force_ALI_Tree_File := True;
332          Try_Semantics := True;
333
334          --  Make the Ada front end more liberal so that the compiler will
335          --  allow illegal code that is allowed by other compilers. CodePeer
336          --  is in the business of finding problems, not enforcing rules.
337          --  This is useful when using CodePeer mode with other compilers.
338
339          Relaxed_RM_Semantics := True;
340
341          --  Disable all simple value propagation. This is an optimization
342          --  which is valuable for code optimization, and also for generation
343          --  of compiler warnings, but these are being turned off by default,
344          --  and CodePeer generates better messages (referencing original
345          --  variables) this way.
346          --  Do this only if -gnatws is set (the default with -gnatcC), so that
347          --  if warnings are enabled, we'll get better messages from GNAT.
348
349          if Warning_Mode = Suppress then
350             Debug_Flag_MM := True;
351          end if;
352       end if;
353
354       --  Enable some individual switches that are implied by relaxed RM
355       --  semantics mode.
356
357       if Relaxed_RM_Semantics then
358          Opt.Allow_Integer_Address := True;
359          Overriding_Renamings := True;
360          Treat_Categorization_Errors_As_Warnings := True;
361       end if;
362
363       --  Enable GNATprove_Mode when using -gnatd.F switch
364
365       if Debug_Flag_Dot_FF then
366          GNATprove_Mode := True;
367       end if;
368
369       --  GNATprove_Mode is also activated by default in the gnat2why
370       --  executable.
371
372       if GNATprove_Mode then
373
374          --  Turn off inlining, which would confuse formal verification output
375          --  and gain nothing.
376
377          Front_End_Inlining := False;
378          Inline_Active      := False;
379
380          --  Issue warnings for failure to inline subprograms, as otherwise
381          --  expected in GNATprove mode for the local subprograms without
382          --  contracts.
383
384          Ineffective_Inline_Warnings := True;
385
386          --  Disable front-end optimizations, to keep the tree as close to the
387          --  source code as possible, and also to avoid inconsistencies between
388          --  trees when using different optimization switches.
389
390          Optimization_Level := 0;
391
392          --  Enable some restrictions systematically to simplify the generated
393          --  code (and ease analysis).
394
395          Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
396
397          --  Note: at this point we used to suppress various checks, but that
398          --  is not what we want. We need the semantic processing for these
399          --  checks (which will set flags like Do_Overflow_Check, showing the
400          --  points at which potential checks are required semantically). We
401          --  don't want the expansion associated with these checks, but that
402          --  happens anyway because this expansion is simply not done in the
403          --  SPARK version of the expander.
404
405          --  On the contrary, we need to enable explicitly all language checks,
406          --  as they may have been suppressed by the use of switch -gnatp.
407
408          Suppress_Options.Suppress := (others => False);
409
410          --  Detect overflow on unconstrained floating-point types, such as
411          --  the predefined types Float, Long_Float and Long_Long_Float from
412          --  package Standard. Not necessary if float overflows are checked
413          --  (Machine_Overflow true), since appropriate Do_Overflow_Check flags
414          --  will be set in any case.
415
416          Check_Float_Overflow := not Machine_Overflows_On_Target;
417
418          --  Set STRICT mode for overflow checks if not set explicitly. This
419          --  prevents suppressing of overflow checks by default, in code down
420          --  below.
421
422          if Suppress_Options.Overflow_Mode_General = Not_Set then
423             Suppress_Options.Overflow_Mode_General    := Strict;
424             Suppress_Options.Overflow_Mode_Assertions := Strict;
425          end if;
426
427          --  Kill debug of generated code, since it messes up sloc values
428
429          Debug_Generated_Code := False;
430
431          --  Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
432          --  as it is needed for computing effects of subprograms in the formal
433          --  verification backend.
434
435          Xref_Active := True;
436
437          --  Polling mode forced off, since it generates confusing junk
438
439          Polling_Required := False;
440
441          --  Set operating mode to Check_Semantics, but a light front-end
442          --  expansion is still performed.
443
444          Operating_Mode := Check_Semantics;
445
446          --  Enable assertions, since they give valuable extra information for
447          --  formal verification.
448
449          Assertions_Enabled := True;
450
451          --  Disable validity checks, since it generates code raising
452          --  exceptions for invalid data, which confuses GNATprove. Invalid
453          --  data is directly detected by GNATprove's flow analysis.
454
455          Validity_Checks_On := False;
456
457          --  Turn off style check options since we are not interested in any
458          --  front-end warnings when we are getting SPARK output.
459
460          Reset_Style_Check_Options;
461
462          --  Suppress the generation of name tables for enumerations, which are
463          --  not needed for formal verification, and fall outside the SPARK
464          --  subset (use of pointers).
465
466          Global_Discard_Names := True;
467
468          --  Suppress the expansion of tagged types and dispatching calls,
469          --  which lead to the generation of non-SPARK code (use of pointers),
470          --  which is more complex to formally verify than the original source.
471
472          Tagged_Type_Expansion := False;
473       end if;
474
475       --  Set Configurable_Run_Time mode if system.ads flag set or if the
476       --  special debug flag -gnatdY is set.
477
478       if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
479          Configurable_Run_Time_Mode := True;
480       end if;
481
482       --  Set -gnatR3m mode if debug flag A set
483
484       if Debug_Flag_AA then
485          Back_Annotate_Rep_Info := True;
486          List_Representation_Info := 1;
487          List_Representation_Info_Mechanisms := True;
488       end if;
489
490       --  Force Target_Strict_Alignment true if debug flag -gnatd.a is set
491
492       if Debug_Flag_Dot_A then
493          Ttypes.Target_Strict_Alignment := True;
494       end if;
495
496       --  Increase size of allocated entities if debug flag -gnatd.N is set
497
498       if Debug_Flag_Dot_NN then
499          Atree.Num_Extension_Nodes := Atree.Num_Extension_Nodes + 1;
500       end if;
501
502       --  Disable static allocation of dispatch tables if -gnatd.t or if layout
503       --  is enabled. The front end's layout phase currently treats types that
504       --  have discriminant-dependent arrays as not being static even when a
505       --  discriminant constraint on the type is static, and this leads to
506       --  problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
507
508       if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then
509          Static_Dispatch_Tables := False;
510       end if;
511
512       --  Flip endian mode if -gnatd8 set
513
514       if Debug_Flag_8 then
515          Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
516       end if;
517
518       --  Activate front-end layout if debug flag -gnatdF is set
519
520       if Debug_Flag_FF then
521          Targparm.Frontend_Layout_On_Target := True;
522       end if;
523
524       --  Set and check exception mechanism. This is only meaningful when
525       --  compiling, and in particular not meaningful for special modes used
526       --  for program analysis rather than compilation: ASIS mode, CodePeer
527       --  mode and GNATprove mode.
528
529       if Operating_Mode = Generate_Code
530         and then not (ASIS_Mode or CodePeer_Mode or GNATprove_Mode)
531       then
532          case Targparm.Frontend_Exceptions_On_Target is
533             when True =>
534                case Targparm.ZCX_By_Default_On_Target is
535                   when True =>
536                      Write_Line
537                        ("Run-time library configured incorrectly");
538                      Write_Line
539                        ("(requesting support for Frontend ZCX exceptions)");
540                      raise Unrecoverable_Error;
541                   when False =>
542                      Exception_Mechanism := Front_End_SJLJ;
543                end case;
544             when False =>
545                case Targparm.ZCX_By_Default_On_Target is
546                   when True =>
547                      Exception_Mechanism := Back_End_ZCX;
548                   when False =>
549                      Exception_Mechanism := Back_End_SJLJ;
550                end case;
551          end case;
552       end if;
553
554       --  Set proper status for overflow check mechanism
555
556       --  If already set (by -gnato or above in SPARK or CodePeer mode) then we
557       --  have nothing to do.
558
559       if Opt.Suppress_Options.Overflow_Mode_General /= Not_Set then
560          null;
561
562       --  Otherwise set overflow mode defaults
563
564       else
565          --  Overflow checks are on by default (Suppress set False) except in
566          --  GNAT_Mode, where we want them off by default (we are not ready to
567          --  enable overflow checks in the compiler yet, for one thing the case
568          --  of 64-bit checks needs System.Arith_64 which is not a compiler
569          --  unit and it is a pain to try to include it in the compiler.
570
571          Suppress_Options.Suppress (Overflow_Check) := GNAT_Mode;
572
573          --  Set appropriate default overflow handling mode. Note: at present
574          --  we set STRICT in all three of the following cases. They are
575          --  separated because in the future we may make different choices.
576
577          --  By default set STRICT mode if -gnatg in effect
578
579          if GNAT_Mode then
580             Suppress_Options.Overflow_Mode_General    := Strict;
581             Suppress_Options.Overflow_Mode_Assertions := Strict;
582
583          --  If we have backend divide and overflow checks, then by default
584          --  overflow checks are STRICT. Historically this code used to also
585          --  activate overflow checks, although no target currently has these
586          --  flags set, so this was dead code anyway.
587
588          elsif Targparm.Backend_Divide_Checks_On_Target
589                  and
590                Targparm.Backend_Overflow_Checks_On_Target
591          then
592             Suppress_Options.Overflow_Mode_General    := Strict;
593             Suppress_Options.Overflow_Mode_Assertions := Strict;
594
595          --  Otherwise for now, default is STRICT mode. This may change in the
596          --  future, but for now this is the compatible behavior with previous
597          --  versions of GNAT.
598
599          else
600             Suppress_Options.Overflow_Mode_General    := Strict;
601             Suppress_Options.Overflow_Mode_Assertions := Strict;
602          end if;
603       end if;
604
605       --  Set default for atomic synchronization. As this synchronization
606       --  between atomic accesses can be expensive, and not typically needed
607       --  on some targets, an optional target parameter can turn the option
608       --  off. Note Atomic Synchronization is implemented as check.
609
610       Suppress_Options.Suppress (Atomic_Synchronization) :=
611         not Atomic_Sync_Default_On_Target;
612
613       --  Set default for Alignment_Check, if we are on a machine with non-
614       --  strict alignment, then we suppress this check, since it is over-
615       --  zealous for such machines.
616
617       if not Ttypes.Target_Strict_Alignment then
618          Suppress_Options.Suppress (Alignment_Check) := True;
619       end if;
620
621       --  Set switch indicating if back end can handle limited types, and
622       --  guarantee that no incorrect copies are made (e.g. in the context
623       --  of an if or case expression).
624
625       --  Debug flag -gnatd.L decisively sets usage on
626
627       if Debug_Flag_Dot_LL then
628          Back_End_Handles_Limited_Types := True;
629
630       --  If no debug flag, usage off for SCIL cases
631
632       elsif Generate_SCIL then
633          Back_End_Handles_Limited_Types := False;
634
635       --  Otherwise normal gcc back end, for now still turn flag off by
636       --  default, since there are unresolved problems in the front end.
637
638       else
639          Back_End_Handles_Limited_Types := False;
640       end if;
641
642       --  If the inlining level has not been set by the user, compute it from
643       --  the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
644
645       if Inline_Level = 0 then
646          if Optimization_Level < 3 then
647             Inline_Level := 1;
648          else
649             Inline_Level := 2;
650          end if;
651       end if;
652
653       --  Treat -gnatn as equivalent to -gnatN for non-GCC targets
654
655       if Inline_Active and not Front_End_Inlining then
656
657          --  We really should have a tag for this, what if we added a new
658          --  back end some day, it would not be true for this test, but it
659          --  would be non-GCC, so this is a bit troublesome ???
660
661          Front_End_Inlining := Generate_C_Code;
662       end if;
663
664       --  Set back-end inlining indication
665
666       Back_End_Inlining :=
667
668         --  No back-end inlining available on C generation
669
670         not Generate_C_Code
671
672         --  No back-end inlining in GNATprove mode, since it just confuses
673         --  the formal verification process.
674
675         and then not GNATprove_Mode
676
677         --  No back-end inlining if front-end inlining explicitly enabled.
678         --  Done to minimize the output differences to customers still using
679         --  this deprecated switch; in addition, this behavior reduces the
680         --  output differences in old tests.
681
682         and then not Front_End_Inlining
683
684         --  Back-end inlining is disabled if debug flag .z is set
685
686         and then not Debug_Flag_Dot_Z;
687
688       --  Output warning if -gnateE specified and cannot be supported
689
690       if Exception_Extra_Info
691         and then Restrict.No_Exception_Handlers_Set
692       then
693          Set_Standard_Error;
694          Write_Str
695            ("warning: extra exception information (-gnateE) was specified");
696          Write_Eol;
697          Write_Str
698            ("warning: this capability is not available in this configuration");
699          Write_Eol;
700          Set_Standard_Output;
701       end if;
702
703       --  Finally capture adjusted value of Suppress_Options as the initial
704       --  value for Scope_Suppress, which will be modified as we move from
705       --  scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
706
707       Sem.Scope_Suppress := Opt.Suppress_Options;
708    end Adjust_Global_Switches;
709
710    --------------------
711    -- Check_Bad_Body --
712    --------------------
713
714    procedure Check_Bad_Body (Unit_Node : Node_Id; Unit_Kind : Node_Kind) is
715       Fname : File_Name_Type;
716
717       procedure Bad_Body_Error (Msg : String);
718       --  Issue message for bad body found
719
720       --------------------
721       -- Bad_Body_Error --
722       --------------------
723
724       procedure Bad_Body_Error (Msg : String) is
725       begin
726          Error_Msg_N (Msg, Unit_Node);
727          Error_Msg_File_1 := Fname;
728          Error_Msg_N ("remove incorrect body in file{!", Unit_Node);
729       end Bad_Body_Error;
730
731       --  Local variables
732
733       Sname   : Unit_Name_Type;
734       Src_Ind : Source_File_Index;
735
736    --  Start of processing for Check_Bad_Body
737
738    begin
739       --  Nothing to do if we are only checking syntax, because we don't know
740       --  enough to know if we require or forbid a body in this case.
741
742       if Operating_Mode = Check_Syntax then
743          return;
744       end if;
745
746       --  Check for body not allowed
747
748       if (Unit_Kind = N_Package_Declaration
749            and then not Body_Required (Unit_Node))
750         or else (Unit_Kind = N_Generic_Package_Declaration
751                   and then not Body_Required (Unit_Node))
752         or else Unit_Kind = N_Package_Renaming_Declaration
753         or else Unit_Kind = N_Subprogram_Renaming_Declaration
754         or else Nkind (Original_Node (Unit (Unit_Node)))
755                          in N_Generic_Instantiation
756       then
757          Sname := Unit_Name (Main_Unit);
758
759          --  If we do not already have a body name, then get the body name
760
761          if not Is_Body_Name (Sname) then
762             Sname := Get_Body_Name (Sname);
763          end if;
764
765          Fname := Get_File_Name (Sname, Subunit => False);
766          Src_Ind := Load_Source_File (Fname);
767
768          --  Case where body is present and it is not a subunit. Exclude the
769          --  subunit case, because it has nothing to do with the package we are
770          --  compiling. It is illegal for a child unit and a subunit with the
771          --  same expanded name (RM 10.2(9)) to appear together in a partition,
772          --  but there is nothing to stop a compilation environment from having
773          --  both, and the test here simply allows that. If there is an attempt
774          --  to include both in a partition, this is diagnosed at bind time. In
775          --  Ada 83 mode this is not a warning case.
776
777          --  Note that in general we do not give the message if the file in
778          --  question does not look like a body. This includes weird cases,
779          --  but in particular means that if the file is just a No_Body pragma,
780          --  then we won't give the message (that's the whole point of this
781          --  pragma, to be used this way and to cause the body file to be
782          --  ignored in this context).
783
784          if Src_Ind /= No_Source_File
785            and then Source_File_Is_Body (Src_Ind)
786          then
787             Errout.Finalize (Last_Call => False);
788
789             Error_Msg_Unit_1 := Sname;
790
791             --  Ada 83 case of a package body being ignored. This is not an
792             --  error as far as the Ada 83 RM is concerned, but it is almost
793             --  certainly not what is wanted so output a warning. Give this
794             --  message only if there were no errors, since otherwise it may
795             --  be incorrect (we may have misinterpreted a junk spec as not
796             --  needing a body when it really does).
797
798             if Unit_Kind = N_Package_Declaration
799               and then Ada_Version = Ada_83
800               and then Operating_Mode = Generate_Code
801               and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
802               and then not Compilation_Errors
803             then
804                Error_Msg_N
805                  ("package $$ does not require a body??", Unit_Node);
806                Error_Msg_File_1 := Fname;
807                Error_Msg_N ("body in file{ will be ignored??", Unit_Node);
808
809                --  Ada 95 cases of a body file present when no body is
810                --  permitted. This we consider to be an error.
811
812             else
813                --  For generic instantiations, we never allow a body
814
815                if Nkind (Original_Node (Unit (Unit_Node))) in
816                                                     N_Generic_Instantiation
817                then
818                   Bad_Body_Error
819                     ("generic instantiation for $$ does not allow a body");
820
821                --  A library unit that is a renaming never allows a body
822
823                elsif Unit_Kind in N_Renaming_Declaration then
824                   Bad_Body_Error
825                     ("renaming declaration for $$ does not allow a body!");
826
827                   --  Remaining cases are packages and generic packages. Here
828                   --  we only do the test if there are no previous errors,
829                   --  because if there are errors, they may lead us to
830                   --  incorrectly believe that a package does not allow a
831                   --  body when in fact it does.
832
833                elsif not Compilation_Errors then
834                   if Unit_Kind = N_Package_Declaration then
835                      Bad_Body_Error
836                        ("package $$ does not allow a body!");
837
838                   elsif Unit_Kind = N_Generic_Package_Declaration then
839                      Bad_Body_Error
840                        ("generic package $$ does not allow a body!");
841                   end if;
842                end if;
843
844             end if;
845          end if;
846       end if;
847    end Check_Bad_Body;
848
849    --------------------
850    -- Check_Rep_Info --
851    --------------------
852
853    procedure Check_Rep_Info is
854    begin
855       if List_Representation_Info /= 0
856         or else List_Representation_Info_Mechanisms
857       then
858          Set_Standard_Error;
859          Write_Eol;
860          Write_Str
861            ("cannot generate representation information, no code generated");
862          Write_Eol;
863          Write_Eol;
864          Set_Standard_Output;
865       end if;
866    end Check_Rep_Info;
867
868    ----------------------------------------
869    -- Post_Compilation_Validation_Checks --
870    ----------------------------------------
871
872    procedure Post_Compilation_Validation_Checks is
873    begin
874       --  Validate alignment check warnings. In some cases we generate warnings
875       --  about possible alignment errors because we don't know the alignment
876       --  that will be chosen by the back end. This routine is in charge of
877       --  getting rid of those warnings if we can tell they are not needed.
878
879       Checks.Validate_Alignment_Check_Warnings;
880
881       --  Validate compile time warnings and errors (using the values for size
882       --  and alignment annotated by the backend where possible). We need to
883       --  unlock temporarily these tables to reanalyze their expression.
884
885       Atree.Unlock;
886       Nlists.Unlock;
887       Sem.Unlock;
888       Sem_Ch13.Validate_Compile_Time_Warning_Errors;
889       Sem.Lock;
890       Nlists.Lock;
891       Atree.Lock;
892
893       --  Validate unchecked conversions (using the values for size and
894       --  alignment annotated by the backend where possible).
895
896       Sem_Ch13.Validate_Unchecked_Conversions;
897
898       --  Validate address clauses (again using alignment values annotated
899       --  by the backend where possible).
900
901       Sem_Ch13.Validate_Address_Clauses;
902
903       --  Validate independence pragmas (again using values annotated by the
904       --  back end for component layout where possible) but only for non-GCC
905       --  back ends, as this is done a priori for GCC back ends.
906
907       if AAMP_On_Target then
908          Sem_Ch13.Validate_Independence;
909       end if;
910    end Post_Compilation_Validation_Checks;
911
912    --  Local variables
913
914    Back_End_Mode : Back_End.Back_End_Mode_Type;
915
916    Main_Unit_Kind : Node_Kind;
917    --  Kind of main compilation unit node
918
919    Main_Unit_Node : Node_Id;
920    --  Compilation unit node for main unit
921
922 --  Start of processing for Gnat1drv
923
924 begin
925    --  This inner block is set up to catch assertion errors and constraint
926    --  errors. Since the code for handling these errors can cause another
927    --  exception to be raised (namely Unrecoverable_Error), we need two
928    --  nested blocks, so that the outer one handles unrecoverable error.
929
930    begin
931       --  Initialize all packages. For the most part, these initialization
932       --  calls can be made in any order. Exceptions are as follows:
933
934       --  Lib.Initialize need to be called before Scan_Compiler_Arguments,
935       --  because it initializes a table filled by Scan_Compiler_Arguments.
936
937       Osint.Initialize;
938       Fmap.Reset_Tables;
939       Lib.Initialize;
940       Lib.Xref.Initialize;
941       Scan_Compiler_Arguments;
942       Osint.Add_Default_Search_Dirs;
943       Atree.Initialize;
944       Nlists.Initialize;
945       Sinput.Initialize;
946       Sem.Initialize;
947       Exp_CG.Initialize;
948       Csets.Initialize;
949       Uintp.Initialize;
950       Urealp.Initialize;
951       Errout.Initialize;
952       SCOs.Initialize;
953       Snames.Initialize;
954       Stringt.Initialize;
955       Ghost.Initialize;
956       Inline.Initialize;
957       Par_SCO.Initialize;
958       Sem_Ch8.Initialize;
959       Sem_Ch12.Initialize;
960       Sem_Ch13.Initialize;
961       Sem_Elim.Initialize;
962       Sem_Eval.Initialize;
963       Sem_Type.Init_Interp_Tables;
964
965       --  Capture compilation date and time
966
967       Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
968
969       --  Get the target parameters only when -gnats is not used, to avoid
970       --  failing when there is no default runtime.
971
972       if Operating_Mode /= Check_Syntax then
973
974          --  Acquire target parameters from system.ads (package System source)
975
976          Targparm_Acquire : declare
977             use Sinput;
978
979             S : Source_File_Index;
980             N : File_Name_Type;
981
982          begin
983             Name_Buffer (1 .. 10) := "system.ads";
984             Name_Len := 10;
985             N := Name_Find;
986             S := Load_Source_File (N);
987
988             --  Failed to read system.ads, fatal error
989
990             if S = No_Source_File then
991                Write_Line
992                  ("fatal error, run-time library not installed correctly");
993                Write_Line ("cannot locate file system.ads");
994                raise Unrecoverable_Error;
995
996             --  Read system.ads successfully, remember its source index
997
998             else
999                System_Source_File_Index := S;
1000             end if;
1001
1002             --  Call to get target parameters. Note that the actual interface
1003             --  routines are in Tbuild. They can't be in this procedure because
1004             --  of accessibility issues.
1005
1006             Targparm.Get_Target_Parameters
1007               (System_Text  => Source_Text  (S),
1008                Source_First => Source_First (S),
1009                Source_Last  => Source_Last  (S),
1010                Make_Id      => Tbuild.Make_Id'Access,
1011                Make_SC      => Tbuild.Make_SC'Access,
1012                Set_NOD      => Tbuild.Set_NOD'Access,
1013                Set_NSA      => Tbuild.Set_NSA'Access,
1014                Set_NUA      => Tbuild.Set_NUA'Access,
1015                Set_NUP      => Tbuild.Set_NUP'Access);
1016
1017             --  Acquire configuration pragma information from Targparm
1018
1019             Restrict.Restrictions := Targparm.Restrictions_On_Target;
1020          end Targparm_Acquire;
1021       end if;
1022
1023       --  Perform various adjustments and settings of global switches
1024
1025       Adjust_Global_Switches;
1026
1027       --  Output copyright notice if full list mode unless we have a list
1028       --  file, in which case we defer this so that it is output in the file.
1029
1030       if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
1031
1032         --  Debug flag gnatd7 suppresses this copyright notice
1033
1034         and then not Debug_Flag_7
1035       then
1036          Write_Eol;
1037          Write_Str ("GNAT ");
1038          Write_Str (Gnat_Version_String);
1039          Write_Eol;
1040          Write_Str ("Copyright 1992-" & Current_Year
1041                     & ", Free Software Foundation, Inc.");
1042          Write_Eol;
1043       end if;
1044
1045       --  Check we do not have more than one source file, this happens only in
1046       --  the case where the driver is called directly, it cannot happen when
1047       --  gnat1 is invoked from gcc in the normal case.
1048
1049       if Osint.Number_Of_Files /= 1 then
1050          Usage;
1051          Write_Eol;
1052          Osint.Fail ("you must provide one source file");
1053
1054       elsif Usage_Requested then
1055          Usage;
1056       end if;
1057
1058       --  Generate target dependent output file if requested
1059
1060       if Target_Dependent_Info_Write_Name /= null then
1061          Set_Targ.Write_Target_Dependent_Values;
1062       end if;
1063
1064       --  Call the front end
1065
1066       Original_Operating_Mode := Operating_Mode;
1067       Frontend;
1068
1069       --  In GNATprove mode, force loading of System unit to ensure that
1070       --  System.Interrupt_Priority is available to GNATprove for the
1071       --  generation of VCs related to ceiling priority.
1072
1073       if GNATprove_Mode then
1074          declare
1075             Unused_E : constant Entity_Id :=
1076                          Rtsfind.RTE (Rtsfind.RE_Interrupt_Priority);
1077          begin
1078             null;
1079          end;
1080       end if;
1081
1082       --  Exit with errors if the main source could not be parsed
1083
1084       if Sinput.Main_Source_File = No_Source_File then
1085          Errout.Finalize (Last_Call => True);
1086          Errout.Output_Messages;
1087          Exit_Program (E_Errors);
1088       end if;
1089
1090       Main_Unit_Node := Cunit (Main_Unit);
1091       Main_Unit_Kind := Nkind (Unit (Main_Unit_Node));
1092
1093       Check_Bad_Body (Main_Unit_Node, Main_Unit_Kind);
1094
1095       --  In CodePeer mode we always delete old SCIL files before regenerating
1096       --  new ones, in case of e.g. errors, and also to remove obsolete scilx
1097       --  files generated by CodePeer itself.
1098
1099       if CodePeer_Mode then
1100          Comperr.Delete_SCIL_Files;
1101       end if;
1102
1103       --  Ditto for old C files before regenerating new ones
1104
1105       if Generate_C_Code then
1106          Delete_C_File;
1107          Delete_H_File;
1108       end if;
1109
1110       --  Exit if compilation errors detected
1111
1112       Errout.Finalize (Last_Call => False);
1113
1114       if Compilation_Errors then
1115          Treepr.Tree_Dump;
1116          Post_Compilation_Validation_Checks;
1117          Errout.Output_Messages;
1118          Namet.Finalize;
1119
1120          --  Generate ALI file if specially requested
1121
1122          if Opt.Force_ALI_Tree_File then
1123             Write_ALI (Object => False);
1124             Tree_Gen;
1125          end if;
1126
1127          Errout.Finalize (Last_Call => True);
1128          Exit_Program (E_Errors);
1129       end if;
1130
1131       --  Set Generate_Code on main unit and its spec. We do this even if are
1132       --  not generating code, since Lib-Writ uses this to determine which
1133       --  units get written in the ali file.
1134
1135       Set_Generate_Code (Main_Unit);
1136
1137       --  If we have a corresponding spec, and it comes from source or it is
1138       --  not a generated spec for a child subprogram body, then we need object
1139       --  code for the spec unit as well.
1140
1141       if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
1142         and then not Acts_As_Spec (Main_Unit_Node)
1143       then
1144          if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body
1145            and then not Comes_From_Source (Library_Unit (Main_Unit_Node))
1146          then
1147             null;
1148          else
1149             Set_Generate_Code
1150               (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
1151          end if;
1152       end if;
1153
1154       --  Case of no code required to be generated, exit indicating no error
1155
1156       if Original_Operating_Mode = Check_Syntax then
1157          Treepr.Tree_Dump;
1158          Errout.Finalize (Last_Call => True);
1159          Errout.Output_Messages;
1160          Tree_Gen;
1161          Namet.Finalize;
1162          Check_Rep_Info;
1163
1164          --  Use a goto instead of calling Exit_Program so that finalization
1165          --  occurs normally.
1166
1167          goto End_Of_Program;
1168
1169       elsif Original_Operating_Mode = Check_Semantics then
1170          Back_End_Mode := Declarations_Only;
1171
1172       --  All remaining cases are cases in which the user requested that code
1173       --  be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1174       --  can in fact satisfy this request.
1175
1176       --  Cannot generate code if someone has turned off code generation for
1177       --  any reason at all. We will try to figure out a reason below.
1178
1179       elsif Operating_Mode /= Generate_Code then
1180          Back_End_Mode := Skip;
1181
1182       --  We can generate code for a subprogram body unless there were missing
1183       --  subunits. Note that we always generate code for all generic units (a
1184       --  change from some previous versions of GNAT).
1185
1186       elsif Main_Unit_Kind = N_Subprogram_Body
1187         and then not Subunits_Missing
1188       then
1189          Back_End_Mode := Generate_Object;
1190
1191       --  We can generate code for a package body unless there are subunits
1192       --  missing (note that we always generate code for generic units, which
1193       --  is a change from some earlier versions of GNAT).
1194
1195       elsif Main_Unit_Kind = N_Package_Body and then not Subunits_Missing then
1196          Back_End_Mode := Generate_Object;
1197
1198       --  We can generate code for a package declaration or a subprogram
1199       --  declaration only if it does not required a body.
1200
1201       elsif Nkind_In (Main_Unit_Kind, N_Package_Declaration,
1202                                       N_Subprogram_Declaration)
1203         and then
1204           (not Body_Required (Main_Unit_Node)
1205              or else Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1206       then
1207          Back_End_Mode := Generate_Object;
1208
1209       --  We can generate code for a generic package declaration of a generic
1210       --  subprogram declaration only if does not require a body.
1211
1212       elsif Nkind_In (Main_Unit_Kind, N_Generic_Package_Declaration,
1213                                       N_Generic_Subprogram_Declaration)
1214         and then not Body_Required (Main_Unit_Node)
1215       then
1216          Back_End_Mode := Generate_Object;
1217
1218       --  Compilation units that are renamings do not require bodies, so we can
1219       --  generate code for them.
1220
1221       elsif Nkind_In (Main_Unit_Kind, N_Package_Renaming_Declaration,
1222                                       N_Subprogram_Renaming_Declaration)
1223       then
1224          Back_End_Mode := Generate_Object;
1225
1226       --  Compilation units that are generic renamings do not require bodies
1227       --  so we can generate code for them.
1228
1229       elsif Main_Unit_Kind in N_Generic_Renaming_Declaration then
1230          Back_End_Mode := Generate_Object;
1231
1232       --  It is not an error to analyze in CodePeer mode a spec which requires
1233       --  a body, in order to generate SCIL for this spec.
1234       --  Ditto for Generate_C_Code mode and generate a C header for a spec.
1235
1236       elsif CodePeer_Mode or Generate_C_Code then
1237          Back_End_Mode := Generate_Object;
1238
1239       --  It is not an error to analyze in GNATprove mode a spec which requires
1240       --  a body, when the body is not available. During frame condition
1241       --  generation, the corresponding ALI file is generated. During
1242       --  analysis, the spec is analyzed.
1243
1244       elsif GNATprove_Mode then
1245          Back_End_Mode := Declarations_Only;
1246
1247       --  In all other cases (specs which have bodies, generics, and bodies
1248       --  where subunits are missing), we cannot generate code and we generate
1249       --  a warning message. Note that generic instantiations are gone at this
1250       --  stage since they have been replaced by their instances.
1251
1252       else
1253          Back_End_Mode := Skip;
1254       end if;
1255
1256       --  At this stage Back_End_Mode is set to indicate if the backend should
1257       --  be called to generate code. If it is Skip, then code generation has
1258       --  been turned off, even though code was requested by the original
1259       --  command. This is not an error from the user point of view, but it is
1260       --  an error from the point of view of the gcc driver, so we must exit
1261       --  with an error status.
1262
1263       --  We generate an informative message (from the gcc point of view, it
1264       --  is an error message, but from the users point of view this is not an
1265       --  error, just a consequence of compiling something that cannot
1266       --  generate code).
1267
1268       if Back_End_Mode = Skip then
1269
1270          --  An ignored Ghost unit is rewritten into a null statement because
1271          --  it must not produce an ALI or object file. Do not emit any errors
1272          --  related to code generation because the unit does not exist.
1273
1274          if Main_Unit_Kind = N_Null_Statement
1275            and then Is_Ignored_Ghost_Node
1276                       (Original_Node (Unit (Main_Unit_Node)))
1277          then
1278             null;
1279
1280          --  Otherwise the unit is missing a crucial piece that prevents code
1281          --  generation.
1282
1283          else
1284             Set_Standard_Error;
1285             Write_Str ("cannot generate code for file ");
1286             Write_Name (Unit_File_Name (Main_Unit));
1287
1288             if Subunits_Missing then
1289                Write_Str (" (missing subunits)");
1290                Write_Eol;
1291
1292                --  Force generation of ALI file, for backward compatibility
1293
1294                Opt.Force_ALI_Tree_File := True;
1295
1296             elsif Main_Unit_Kind = N_Subunit then
1297                Write_Str (" (subunit)");
1298                Write_Eol;
1299
1300                --  Force generation of ALI file, for backward compatibility
1301
1302                Opt.Force_ALI_Tree_File := True;
1303
1304             elsif Main_Unit_Kind = N_Subprogram_Declaration then
1305                Write_Str (" (subprogram spec)");
1306                Write_Eol;
1307
1308             --  Generic package body in GNAT implementation mode
1309
1310             elsif Main_Unit_Kind = N_Package_Body and then GNAT_Mode then
1311                Write_Str (" (predefined generic)");
1312                Write_Eol;
1313
1314                --  Force generation of ALI file, for backward compatibility
1315
1316                Opt.Force_ALI_Tree_File := True;
1317
1318             --  Only other case is a package spec
1319
1320             else
1321                Write_Str (" (package spec)");
1322                Write_Eol;
1323             end if;
1324          end if;
1325
1326          Set_Standard_Output;
1327
1328          Post_Compilation_Validation_Checks;
1329          Errout.Finalize (Last_Call => True);
1330          Errout.Output_Messages;
1331          Treepr.Tree_Dump;
1332          Tree_Gen;
1333
1334          --  Generate ALI file if specially requested, or for missing subunits,
1335          --  subunits or predefined generic.
1336
1337          if Opt.Force_ALI_Tree_File then
1338             Write_ALI (Object => False);
1339          end if;
1340
1341          Namet.Finalize;
1342          Check_Rep_Info;
1343
1344          --  Exit program with error indication, to kill object file
1345
1346          Exit_Program (E_No_Code);
1347       end if;
1348
1349       --  In -gnatc mode, we only do annotation if -gnatt or -gnatR is also set
1350       --  as indicated by Back_Annotate_Rep_Info being set to True.
1351
1352       --  We don't call for annotations on a subunit, because to process those
1353       --  the back end requires that the parent(s) be properly compiled.
1354
1355       --  Annotation is suppressed for targets where front-end layout is
1356       --  enabled, because the front end determines representations.
1357
1358       --  The back end is not invoked in ASIS mode with GNSA because all type
1359       --  representation information will be provided by the GNSA back end, not
1360       --  gigi.
1361
1362       if Back_End_Mode = Declarations_Only
1363         and then
1364           (not (Back_Annotate_Rep_Info or Generate_SCIL or GNATprove_Mode)
1365             or else Main_Unit_Kind = N_Subunit
1366             or else Frontend_Layout_On_Target
1367             or else ASIS_GNSA_Mode)
1368       then
1369          Post_Compilation_Validation_Checks;
1370          Errout.Finalize (Last_Call => True);
1371          Errout.Output_Messages;
1372          Write_ALI (Object => False);
1373          Tree_Dump;
1374          Tree_Gen;
1375          Namet.Finalize;
1376          Check_Rep_Info;
1377          return;
1378       end if;
1379
1380       --  Ensure that we properly register a dependency on system.ads, since
1381       --  even if we do not semantically depend on this, Targparm has read
1382       --  system parameters from the system.ads file.
1383
1384       Lib.Writ.Ensure_System_Dependency;
1385
1386       --  Add dependencies, if any, on preprocessing data file and on
1387       --  preprocessing definition file(s).
1388
1389       Prepcomp.Add_Dependencies;
1390
1391       --  In gnatprove mode we're writing the ALI much earlier than usual
1392       --  as flow analysis needs the file present in order to append its
1393       --  own globals to it.
1394
1395       if GNATprove_Mode then
1396
1397          --  Note: In GNATprove mode, an "object" file is always generated as
1398          --  the result of calling gnat1 or gnat2why, although this is not the
1399          --  same as the object file produced for compilation.
1400
1401          Write_ALI (Object => True);
1402       end if;
1403
1404       --  Some back ends (for instance Gigi) are known to rely on SCOs for code
1405       --  generation. Make sure they are available.
1406
1407       if Generate_SCO then
1408          Par_SCO.SCO_Record_Filtered;
1409       end if;
1410
1411       --  Back end needs to explicitly unlock tables it needs to touch
1412
1413       Atree.Lock;
1414       Elists.Lock;
1415       Fname.UF.Lock;
1416       Ghost.Lock;
1417       Inline.Lock;
1418       Lib.Lock;
1419       Namet.Lock;
1420       Nlists.Lock;
1421       Sem.Lock;
1422       Sinput.Lock;
1423       Stringt.Lock;
1424
1425       --  Here we call the back end to generate the output code
1426
1427       Generating_Code := True;
1428       Back_End.Call_Back_End (Back_End_Mode);
1429
1430       --  Once the backend is complete, we unlock the names table. This call
1431       --  allows a few extra entries, needed for example for the file name
1432       --  for the library file output.
1433
1434       Namet.Unlock;
1435
1436       --  Generate the call-graph output of dispatching calls
1437
1438       Exp_CG.Generate_CG_Output;
1439
1440       --  Perform post compilation validation checks
1441
1442       Post_Compilation_Validation_Checks;
1443
1444       --  Now we complete output of errors, rep info and the tree info. These
1445       --  are delayed till now, since it is perfectly possible for gigi to
1446       --  generate errors, modify the tree (in particular by setting flags
1447       --  indicating that elaboration is required, and also to back annotate
1448       --  representation information for List_Rep_Info.
1449
1450       Errout.Finalize (Last_Call => True);
1451       Errout.Output_Messages;
1452       List_Rep_Info (Ttypes.Bytes_Big_Endian);
1453       Inline.List_Inlining_Info;
1454
1455       --  Only write the library if the backend did not generate any error
1456       --  messages. Otherwise signal errors to the driver program so that
1457       --  there will be no attempt to generate an object file.
1458
1459       if Compilation_Errors then
1460          Treepr.Tree_Dump;
1461          Exit_Program (E_Errors);
1462       end if;
1463
1464       if not GNATprove_Mode then
1465          Write_ALI (Object => (Back_End_Mode = Generate_Object));
1466       end if;
1467
1468       if not Compilation_Errors then
1469
1470          --  In case of ada backends, we need to make sure that the generated
1471          --  object file has a timestamp greater than the ALI file. We do this
1472          --  to make gnatmake happy when checking the ALI and obj timestamps,
1473          --  where it expects the object file being written after the ali file.
1474
1475          --  Gnatmake's assumption is true for gcc platforms where the gcc
1476          --  wrapper needs to call the assembler after calling gnat1, but is
1477          --  not true for ada backends, where the object files are created
1478          --  directly by gnat1 (so are created before the ali file).
1479
1480          Back_End.Gen_Or_Update_Object_File;
1481       end if;
1482
1483       --  Generate ASIS tree after writing the ALI file, since in ASIS mode,
1484       --  Write_ALI may in fact result in further tree decoration from the
1485       --  original tree file. Note that we dump the tree just before generating
1486       --  it, so that the dump will exactly reflect what is written out.
1487
1488       Treepr.Tree_Dump;
1489       Tree_Gen;
1490
1491       --  Finalize name table and we are all done
1492
1493       Namet.Finalize;
1494
1495    exception
1496       --  Handle fatal internal compiler errors
1497
1498       when Rtsfind.RE_Not_Available =>
1499          Comperr.Compiler_Abort ("RE_Not_Available");
1500
1501       when System.Assertions.Assert_Failure =>
1502          Comperr.Compiler_Abort ("Assert_Failure");
1503
1504       when Constraint_Error =>
1505          Comperr.Compiler_Abort ("Constraint_Error");
1506
1507       when Program_Error =>
1508          Comperr.Compiler_Abort ("Program_Error");
1509
1510       --  Assume this is a bug. If it is real, the message will in any case
1511       --  say Storage_Error, giving a strong hint.
1512
1513       when Storage_Error =>
1514          Comperr.Compiler_Abort ("Storage_Error");
1515
1516       when Unrecoverable_Error =>
1517          raise;
1518
1519       when others =>
1520          Comperr.Compiler_Abort ("exception");
1521    end;
1522
1523    <<End_Of_Program>>
1524    null;
1525
1526 --  The outer exception handler handles an unrecoverable error
1527
1528 exception
1529    when Unrecoverable_Error =>
1530       Errout.Finalize (Last_Call => True);
1531       Errout.Output_Messages;
1532
1533       Set_Standard_Error;
1534       Write_Str ("compilation abandoned");
1535       Write_Eol;
1536
1537       Set_Standard_Output;
1538       Source_Dump;
1539       Tree_Dump;
1540       Exit_Program (E_Errors);
1541
1542 end Gnat1drv;