* include/parallel/numeric.h: Do not use default arguments in function
[official-gcc.git] / gcc / ada / gnat1drv.adb
blob0da8a51fe786f7b89fbf974e27c236a0f75c0479
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-2014, 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 ------------------------------------------------------------------------------
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 Gnatvsn; use Gnatvsn;
40 with Inline;
41 with Lib; use Lib;
42 with Lib.Writ; use Lib.Writ;
43 with Lib.Xref;
44 with Namet; use Namet;
45 with Nlists;
46 with Opt; use Opt;
47 with Osint; use Osint;
48 with Output; use Output;
49 with Par_SCO;
50 with Prepcomp;
51 with Repinfo; use Repinfo;
52 with Restrict;
53 with Rident; use Rident;
54 with Rtsfind;
55 with SCOs;
56 with Sem;
57 with Sem_Ch8;
58 with Sem_Ch12;
59 with Sem_Ch13;
60 with Sem_Elim;
61 with Sem_Eval;
62 with Sem_Type;
63 with Set_Targ;
64 with Sinfo; use Sinfo;
65 with Sinput.L; use Sinput.L;
66 with Snames;
67 with Sprint; use Sprint;
68 with Stringt;
69 with Stylesw; use Stylesw;
70 with Targparm; use Targparm;
71 with Tbuild;
72 with Tree_Gen;
73 with Treepr; use Treepr;
74 with Ttypes;
75 with Types; use Types;
76 with Uintp; use Uintp;
77 with Uname; use Uname;
78 with Urealp;
79 with Usage;
80 with Validsw; use Validsw;
82 with System.Assertions;
83 with System.OS_Lib;
85 --------------
86 -- Gnat1drv --
87 --------------
89 procedure Gnat1drv is
90 Main_Unit_Node : Node_Id;
91 -- Compilation unit node for main unit
93 Main_Kind : Node_Kind;
94 -- Kind of main compilation unit node
96 Back_End_Mode : Back_End.Back_End_Mode_Type;
97 -- Record back end mode
99 procedure Adjust_Global_Switches;
100 -- There are various interactions between front end switch settings,
101 -- including debug switch settings and target dependent parameters.
102 -- This procedure takes care of properly handling these interactions.
103 -- We do it after scanning out all the switches, so that we are not
104 -- depending on the order in which switches appear.
106 procedure Check_Bad_Body;
107 -- Called to check if the unit we are compiling has a bad body
109 procedure Check_Rep_Info;
110 -- Called when we are not generating code, to check if -gnatR was requested
111 -- and if so, explain that we will not be honoring the request.
113 procedure Post_Compilation_Validation_Checks;
114 -- This procedure performs various validation checks that have to be left
115 -- to the end of the compilation process, after generating code but before
116 -- issuing error messages. In particular, these checks generally require
117 -- the information provided by the back end in back annotation of declared
118 -- entities (e.g. actual size and alignment values chosen by the back end).
120 ----------------------------
121 -- Adjust_Global_Switches --
122 ----------------------------
124 procedure Adjust_Global_Switches is
125 begin
126 -- -gnatd.M enables Relaxed_RM_Semantics
128 if Debug_Flag_Dot_MM then
129 Relaxed_RM_Semantics := True;
130 end if;
132 -- -gnatd.V or -gnatd.u enables special C expansion mode
134 if Debug_Flag_Dot_VV or Debug_Flag_Dot_U then
135 Modify_Tree_For_C := True;
136 end if;
138 -- -gnatd.E sets Error_To_Warning mode, causing selected error messages
139 -- to be treated as warnings instead of errors.
141 if Debug_Flag_Dot_EE then
142 Error_To_Warning := True;
143 end if;
145 -- Disable CodePeer_Mode in Check_Syntax, since we need front-end
146 -- expansion.
148 if Operating_Mode = Check_Syntax then
149 CodePeer_Mode := False;
150 end if;
152 -- Set ASIS mode if -gnatt and -gnatc are set
154 if Operating_Mode = Check_Semantics and then Tree_Output then
155 ASIS_Mode := True;
157 -- Turn off inlining in ASIS mode, since ASIS cannot handle the extra
158 -- information in the trees caused by inlining being active.
160 -- More specifically, the tree seems to be malformed from the ASIS
161 -- point of view if -gnatc and -gnatn appear together???
163 Inline_Active := False;
165 -- Turn off SCIL generation and CodePeer mode in semantics mode,
166 -- since SCIL requires front-end expansion.
168 Generate_SCIL := False;
169 CodePeer_Mode := False;
170 end if;
172 -- SCIL mode needs to disable front-end inlining since the generated
173 -- trees (in particular order and consistency between specs compiled
174 -- as part of a main unit or as part of a with-clause) are causing
175 -- troubles.
177 if Generate_SCIL then
178 Front_End_Inlining := False;
179 end if;
181 -- Tune settings for optimal SCIL generation in CodePeer mode
183 if CodePeer_Mode then
185 -- Turn off inlining, confuses CodePeer output and gains nothing
187 Front_End_Inlining := False;
188 Inline_Active := False;
190 -- Disable front-end optimizations, to keep the tree as close to the
191 -- source code as possible, and also to avoid inconsistencies between
192 -- trees when using different optimization switches.
194 Optimization_Level := 0;
196 -- Enable some restrictions systematically to simplify the generated
197 -- code (and ease analysis). Note that restriction checks are also
198 -- disabled in CodePeer mode, see Restrict.Check_Restriction, and
199 -- user specified Restrictions pragmas are ignored, see
200 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
202 Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
203 Restrict.Restrictions.Set (No_Task_Hierarchy) := True;
204 Restrict.Restrictions.Set (No_Abort_Statements) := True;
205 Restrict.Restrictions.Set (Max_Asynchronous_Select_Nesting) := True;
206 Restrict.Restrictions.Value (Max_Asynchronous_Select_Nesting) := 0;
208 -- Suppress division by zero and access checks since they are handled
209 -- implicitly by CodePeer.
211 -- Turn off dynamic elaboration checks: generates inconsistencies in
212 -- trees between specs compiled as part of a main unit or as part of
213 -- a with-clause.
215 -- Turn off alignment checks: these cannot be proved statically by
216 -- CodePeer and generate false positives.
218 -- Enable all other language checks
220 Suppress_Options.Suppress :=
221 (Access_Check => True,
222 Alignment_Check => True,
223 Division_Check => True,
224 Elaboration_Check => True,
225 others => False);
227 Dynamic_Elaboration_Checks := False;
229 -- Set STRICT mode for overflow checks if not set explicitly. This
230 -- prevents suppressing of overflow checks by default, in code down
231 -- below.
233 if Suppress_Options.Overflow_Mode_General = Not_Set then
234 Suppress_Options.Overflow_Mode_General := Strict;
235 Suppress_Options.Overflow_Mode_Assertions := Strict;
236 end if;
238 -- CodePeer handles division and overflow checks directly, based on
239 -- the marks set by the frontend, hence no special expansion should
240 -- be performed in the frontend for division and overflow checks.
242 Backend_Divide_Checks_On_Target := True;
243 Backend_Overflow_Checks_On_Target := True;
245 -- Kill debug of generated code, since it messes up sloc values
247 Debug_Generated_Code := False;
249 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
250 -- Do we really need to spend time generating xref in CodePeer
251 -- mode??? Consider setting Xref_Active to False.
253 Xref_Active := True;
255 -- Polling mode forced off, since it generates confusing junk
257 Polling_Required := False;
259 -- Set operating mode to Generate_Code to benefit from full front-end
260 -- expansion (e.g. generics).
262 Operating_Mode := Generate_Code;
264 -- We need SCIL generation of course
266 Generate_SCIL := True;
268 -- Enable assertions, since they give CodePeer valuable extra info
270 Assertions_Enabled := True;
272 -- Disable all simple value propagation. This is an optimization
273 -- which is valuable for code optimization, and also for generation
274 -- of compiler warnings, but these are being turned off by default,
275 -- and CodePeer generates better messages (referencing original
276 -- variables) this way.
278 Debug_Flag_MM := True;
280 -- Set normal RM validity checking, and checking of IN OUT parameters
281 -- (this might give CodePeer more useful checks to analyze, to be
282 -- confirmed???). All other validity checking is turned off, since
283 -- this can generate very complex trees that only confuse CodePeer
284 -- and do not bring enough useful info.
286 Reset_Validity_Check_Options;
287 Validity_Check_Default := True;
288 Validity_Check_In_Out_Params := True;
289 Validity_Check_In_Params := True;
291 -- Turn off style check options and ignore any style check pragmas
292 -- since we are not interested in any front-end warnings when we are
293 -- getting CodePeer output.
295 Reset_Style_Check_Options;
296 Ignore_Style_Checks_Pragmas := True;
298 -- Always perform semantics and generate ali files in CodePeer mode,
299 -- so that a gnatmake -c -k will proceed further when possible.
301 Force_ALI_Tree_File := True;
302 Try_Semantics := True;
304 -- Make the Ada front-end more liberal so that the compiler will
305 -- allow illegal code that is allowed by other compilers. CodePeer
306 -- is in the business of finding problems, not enforcing rules.
307 -- This is useful when using CodePeer mode with other compilers.
309 Relaxed_RM_Semantics := True;
310 end if;
312 -- Enable some individual switches that are implied by relaxed RM
313 -- semantics mode.
315 if Relaxed_RM_Semantics then
316 Opt.Allow_Integer_Address := True;
317 Overriding_Renamings := True;
318 Treat_Categorization_Errors_As_Warnings := True;
319 end if;
321 -- Enable GNATprove_Mode when using -gnatd.F switch
323 if Debug_Flag_Dot_FF then
324 GNATprove_Mode := True;
325 end if;
327 -- GNATprove_Mode is also activated by default in the gnat2why
328 -- executable.
330 if GNATprove_Mode then
332 -- Turn off inlining, which would confuse formal verification output
333 -- and gain nothing.
335 Front_End_Inlining := False;
336 Inline_Active := False;
338 -- Issue warnings for failure to inline subprograms, as otherwise
339 -- expected in GNATprove mode for the local subprograms without
340 -- contracts.
342 Ineffective_Inline_Warnings := True;
344 -- Disable front-end optimizations, to keep the tree as close to the
345 -- source code as possible, and also to avoid inconsistencies between
346 -- trees when using different optimization switches.
348 Optimization_Level := 0;
350 -- Enable some restrictions systematically to simplify the generated
351 -- code (and ease analysis). Note that restriction checks are also
352 -- disabled in SPARK mode, see Restrict.Check_Restriction, and user
353 -- specified Restrictions pragmas are ignored, see
354 -- Sem_Prag.Process_Restrictions_Or_Restriction_Warnings.
356 Restrict.Restrictions.Set (No_Initialize_Scalars) := True;
358 -- Note: at this point we used to suppress various checks, but that
359 -- is not what we want. We need the semantic processing for these
360 -- checks (which will set flags like Do_Overflow_Check, showing the
361 -- points at which potential checks are required semantically). We
362 -- don't want the expansion associated with these checks, but that
363 -- happens anyway because this expansion is simply not done in the
364 -- SPARK version of the expander.
366 -- On the contrary, we need to enable explicitly all language checks,
367 -- as they may have been marked as suppressed by the use of switch
368 -- -gnatp
370 Suppress_Options.Suppress := (others => False);
372 -- Turn off dynamic elaboration checks: generates inconsistencies in
373 -- trees between specs compiled as part of a main unit or as part of
374 -- a with-clause.
376 -- Comment is incomplete, SPARK semantics rely on static mode no???
378 Dynamic_Elaboration_Checks := False;
380 -- Detect overflow on unconstrained floating-point types, such as
381 -- the predefined types Float, Long_Float and Long_Long_Float from
382 -- package Standard. Not necessary if float overflows are checked
383 -- (Machine_Overflow true), since appropriate Do_Overflow_Check flags
384 -- will be set in any case.
386 Check_Float_Overflow := not Machine_Overflows_On_Target;
388 -- Set STRICT mode for overflow checks if not set explicitly. This
389 -- prevents suppressing of overflow checks by default, in code down
390 -- below.
392 if Suppress_Options.Overflow_Mode_General = Not_Set then
393 Suppress_Options.Overflow_Mode_General := Strict;
394 Suppress_Options.Overflow_Mode_Assertions := Strict;
395 end if;
397 -- Kill debug of generated code, since it messes up sloc values
399 Debug_Generated_Code := False;
401 -- Turn cross-referencing on in case it was disabled (e.g. by -gnatD)
402 -- as it is needed for computing effects of subprograms in the formal
403 -- verification backend.
405 Xref_Active := True;
407 -- Polling mode forced off, since it generates confusing junk
409 Polling_Required := False;
411 -- Set operating mode to Check_Semantics, but a light front-end
412 -- expansion is still performed.
414 Operating_Mode := Check_Semantics;
416 -- Enable assertions, since they give valuable extra information for
417 -- formal verification.
419 Assertions_Enabled := True;
421 -- Disable validity checks, since it generates code raising
422 -- exceptions for invalid data, which confuses GNATprove. Invalid
423 -- data is directly detected by GNATprove's flow analysis.
425 Validity_Checks_On := False;
427 -- Turn off style check options since we are not interested in any
428 -- front-end warnings when we are getting SPARK output.
430 Reset_Style_Check_Options;
432 -- Suppress the generation of name tables for enumerations, which are
433 -- not needed for formal verification, and fall outside the SPARK
434 -- subset (use of pointers).
436 Global_Discard_Names := True;
438 -- Suppress the expansion of tagged types and dispatching calls,
439 -- which lead to the generation of non-SPARK code (use of pointers),
440 -- which is more complex to formally verify than the original source.
442 Tagged_Type_Expansion := False;
443 end if;
445 -- Set Configurable_Run_Time mode if system.ads flag set or if the
446 -- special debug flag -gnatdY is set.
448 if Targparm.Configurable_Run_Time_On_Target or Debug_Flag_YY then
449 Configurable_Run_Time_Mode := True;
450 end if;
452 -- Set -gnatR3m mode if debug flag A set
454 if Debug_Flag_AA then
455 Back_Annotate_Rep_Info := True;
456 List_Representation_Info := 1;
457 List_Representation_Info_Mechanisms := True;
458 end if;
460 -- Force Target_Strict_Alignment true if debug flag -gnatd.a is set
462 if Debug_Flag_Dot_A then
463 Ttypes.Target_Strict_Alignment := True;
464 end if;
466 -- Increase size of allocated entities if debug flag -gnatd.N is set
468 if Debug_Flag_Dot_NN then
469 Atree.Num_Extension_Nodes := Atree.Num_Extension_Nodes + 1;
470 end if;
472 -- Disable static allocation of dispatch tables if -gnatd.t or if layout
473 -- is enabled. The front end's layout phase currently treats types that
474 -- have discriminant-dependent arrays as not being static even when a
475 -- discriminant constraint on the type is static, and this leads to
476 -- problems with subtypes of type Ada.Tags.Dispatch_Table_Wrapper. ???
478 if Debug_Flag_Dot_T or else Frontend_Layout_On_Target then
479 Static_Dispatch_Tables := False;
480 end if;
482 -- Flip endian mode if -gnatd8 set
484 if Debug_Flag_8 then
485 Ttypes.Bytes_Big_Endian := not Ttypes.Bytes_Big_Endian;
486 end if;
488 -- Activate front end layout if debug flag -gnatdF is set
490 if Debug_Flag_FF then
491 Targparm.Frontend_Layout_On_Target := True;
492 end if;
494 -- Set and check exception mechanism
496 if Targparm.ZCX_By_Default_On_Target then
497 Exception_Mechanism := Back_End_Exceptions;
498 end if;
500 -- Set proper status for overflow check mechanism
502 -- If already set (by -gnato or above in SPARK or CodePeer mode) then we
503 -- have nothing to do.
505 if Opt.Suppress_Options.Overflow_Mode_General /= Not_Set then
506 null;
508 -- Otherwise set overflow mode defaults
510 else
511 -- Overflow checks are on by default (Suppress set False) except in
512 -- GNAT_Mode, where we want them off by default (we are not ready to
513 -- enable overflow checks in the compiler yet, for one thing the case
514 -- of 64-bit checks needs System.Arith_64 which is not a compiler
515 -- unit and it is a pain to try to include it in the compiler.
517 Suppress_Options.Suppress (Overflow_Check) := GNAT_Mode;
519 -- Set appropriate default overflow handling mode. Note: at present
520 -- we set STRICT in all three of the following cases. They are
521 -- separated because in the future we may make different choices.
523 -- By default set STRICT mode if -gnatg in effect
525 if GNAT_Mode then
526 Suppress_Options.Overflow_Mode_General := Strict;
527 Suppress_Options.Overflow_Mode_Assertions := Strict;
529 -- If we have backend divide and overflow checks, then by default
530 -- overflow checks are STRICT. Historically this code used to also
531 -- activate overflow checks, although no target currently has these
532 -- flags set, so this was dead code anyway.
534 elsif Targparm.Backend_Divide_Checks_On_Target
536 Targparm.Backend_Overflow_Checks_On_Target
537 then
538 Suppress_Options.Overflow_Mode_General := Strict;
539 Suppress_Options.Overflow_Mode_Assertions := Strict;
541 -- Otherwise for now, default is STRICT mode. This may change in the
542 -- future, but for now this is the compatible behavior with previous
543 -- versions of GNAT.
545 else
546 Suppress_Options.Overflow_Mode_General := Strict;
547 Suppress_Options.Overflow_Mode_Assertions := Strict;
548 end if;
549 end if;
551 -- Set default for atomic synchronization. As this synchronization
552 -- between atomic accesses can be expensive, and not typically needed
553 -- on some targets, an optional target parameter can turn the option
554 -- off. Note Atomic Synchronization is implemented as check.
556 Suppress_Options.Suppress (Atomic_Synchronization) :=
557 not Atomic_Sync_Default_On_Target;
559 -- Set switch indicating if back end can handle limited types, and
560 -- guarantee that no incorrect copies are made (e.g. in the context
561 -- of an if or case expression).
563 -- Debug flag -gnatd.L decisively sets usage on
565 if Debug_Flag_Dot_LL then
566 Back_End_Handles_Limited_Types := True;
568 -- If no debug flag, usage off for AAMP, VM, SCIL cases
570 elsif AAMP_On_Target
571 or else VM_Target /= No_VM
572 or else Generate_SCIL
573 then
574 Back_End_Handles_Limited_Types := False;
576 -- Otherwise normal gcc back end, for now still turn flag off by
577 -- default, since there are unresolved problems in the front end.
579 else
580 Back_End_Handles_Limited_Types := False;
581 end if;
583 -- If the inlining level has not been set by the user, compute it from
584 -- the optimization level: 1 at -O1/-O2 (and -Os), 2 at -O3 and above.
586 if Inline_Level = 0 then
587 if Optimization_Level < 3 then
588 Inline_Level := 1;
589 else
590 Inline_Level := 2;
591 end if;
592 end if;
594 -- Treat -gnatn as equivalent to -gnatN for non-GCC targets
596 if Inline_Active and not Front_End_Inlining then
598 -- We really should have a tag for this, what if we added a new
599 -- back end some day, it would not be true for this test, but it
600 -- would be non-GCC, so this is a bit troublesome ???
602 Front_End_Inlining := VM_Target /= No_VM or else AAMP_On_Target;
603 end if;
605 -- Set back end inlining indication
607 Back_End_Inlining :=
609 -- No back end inlining if inlining is suppressed
611 not Suppress_All_Inlining
613 -- No back end inlining available for VM targets
615 and then VM_Target = No_VM
617 -- No back end inlining available on AAMP
619 and then not AAMP_On_Target
621 -- No back end inlining in GNATprove mode, since it just confuses
622 -- the formal verification process.
624 and then not GNATprove_Mode
626 -- No back end inlining if front end inlining explicitly enabled.
627 -- Done to minimize the output differences to customers still using
628 -- this deprecated switch; in addition, this behavior reduces the
629 -- output differences in old tests.
631 and then not Front_End_Inlining
633 -- Back end inlining is disabled if debug flag .z is set
635 and then not Debug_Flag_Dot_Z;
637 -- Output warning if -gnateE specified and cannot be supported
639 if Exception_Extra_Info
640 and then Restrict.No_Exception_Handlers_Set
641 then
642 Set_Standard_Error;
643 Write_Str
644 ("warning: extra exception information (-gnateE) was specified");
645 Write_Eol;
646 Write_Str
647 ("warning: this capability is not available in this configuration");
648 Write_Eol;
649 Set_Standard_Output;
650 end if;
652 -- Finally capture adjusted value of Suppress_Options as the initial
653 -- value for Scope_Suppress, which will be modified as we move from
654 -- scope to scope (by Suppress/Unsuppress/Overflow_Checks pragmas).
656 Sem.Scope_Suppress := Opt.Suppress_Options;
657 end Adjust_Global_Switches;
659 --------------------
660 -- Check_Bad_Body --
661 --------------------
663 procedure Check_Bad_Body is
664 Sname : Unit_Name_Type;
665 Src_Ind : Source_File_Index;
666 Fname : File_Name_Type;
668 procedure Bad_Body_Error (Msg : String);
669 -- Issue message for bad body found
671 --------------------
672 -- Bad_Body_Error --
673 --------------------
675 procedure Bad_Body_Error (Msg : String) is
676 begin
677 Error_Msg_N (Msg, Main_Unit_Node);
678 Error_Msg_File_1 := Fname;
679 Error_Msg_N ("remove incorrect body in file{!", Main_Unit_Node);
680 end Bad_Body_Error;
682 -- Start of processing for Check_Bad_Body
684 begin
685 -- Nothing to do if we are only checking syntax, because we don't know
686 -- enough to know if we require or forbid a body in this case.
688 if Operating_Mode = Check_Syntax then
689 return;
690 end if;
692 -- Check for body not allowed
694 if (Main_Kind = N_Package_Declaration
695 and then not Body_Required (Main_Unit_Node))
696 or else (Main_Kind = N_Generic_Package_Declaration
697 and then not Body_Required (Main_Unit_Node))
698 or else Main_Kind = N_Package_Renaming_Declaration
699 or else Main_Kind = N_Subprogram_Renaming_Declaration
700 or else Nkind (Original_Node (Unit (Main_Unit_Node)))
701 in N_Generic_Instantiation
702 then
703 Sname := Unit_Name (Main_Unit);
705 -- If we do not already have a body name, then get the body name
707 if not Is_Body_Name (Sname) then
708 Sname := Get_Body_Name (Sname);
709 end if;
711 Fname := Get_File_Name (Sname, Subunit => False);
712 Src_Ind := Load_Source_File (Fname);
714 -- Case where body is present and it is not a subunit. Exclude the
715 -- subunit case, because it has nothing to do with the package we are
716 -- compiling. It is illegal for a child unit and a subunit with the
717 -- same expanded name (RM 10.2(9)) to appear together in a partition,
718 -- but there is nothing to stop a compilation environment from having
719 -- both, and the test here simply allows that. If there is an attempt
720 -- to include both in a partition, this is diagnosed at bind time. In
721 -- Ada 83 mode this is not a warning case.
723 -- Note that in general we do not give the message if the file in
724 -- question does not look like a body. This includes weird cases,
725 -- but in particular means that if the file is just a No_Body pragma,
726 -- then we won't give the message (that's the whole point of this
727 -- pragma, to be used this way and to cause the body file to be
728 -- ignored in this context).
730 if Src_Ind /= No_Source_File
731 and then Source_File_Is_Body (Src_Ind)
732 then
733 Errout.Finalize (Last_Call => False);
735 Error_Msg_Unit_1 := Sname;
737 -- Ada 83 case of a package body being ignored. This is not an
738 -- error as far as the Ada 83 RM is concerned, but it is almost
739 -- certainly not what is wanted so output a warning. Give this
740 -- message only if there were no errors, since otherwise it may
741 -- be incorrect (we may have misinterpreted a junk spec as not
742 -- needing a body when it really does).
744 if Main_Kind = N_Package_Declaration
745 and then Ada_Version = Ada_83
746 and then Operating_Mode = Generate_Code
747 and then Distribution_Stub_Mode /= Generate_Caller_Stub_Body
748 and then not Compilation_Errors
749 then
750 Error_Msg_N
751 ("package $$ does not require a body??", Main_Unit_Node);
752 Error_Msg_File_1 := Fname;
753 Error_Msg_N ("body in file{ will be ignored??", Main_Unit_Node);
755 -- Ada 95 cases of a body file present when no body is
756 -- permitted. This we consider to be an error.
758 else
759 -- For generic instantiations, we never allow a body
761 if Nkind (Original_Node (Unit (Main_Unit_Node))) in
762 N_Generic_Instantiation
763 then
764 Bad_Body_Error
765 ("generic instantiation for $$ does not allow a body");
767 -- A library unit that is a renaming never allows a body
769 elsif Main_Kind in N_Renaming_Declaration then
770 Bad_Body_Error
771 ("renaming declaration for $$ does not allow a body!");
773 -- Remaining cases are packages and generic packages. Here
774 -- we only do the test if there are no previous errors,
775 -- because if there are errors, they may lead us to
776 -- incorrectly believe that a package does not allow a
777 -- body when in fact it does.
779 elsif not Compilation_Errors then
780 if Main_Kind = N_Package_Declaration then
781 Bad_Body_Error
782 ("package $$ does not allow a body!");
784 elsif Main_Kind = N_Generic_Package_Declaration then
785 Bad_Body_Error
786 ("generic package $$ does not allow a body!");
787 end if;
788 end if;
790 end if;
791 end if;
792 end if;
793 end Check_Bad_Body;
795 --------------------
796 -- Check_Rep_Info --
797 --------------------
799 procedure Check_Rep_Info is
800 begin
801 if List_Representation_Info /= 0
802 or else List_Representation_Info_Mechanisms
803 then
804 Set_Standard_Error;
805 Write_Eol;
806 Write_Str
807 ("cannot generate representation information, no code generated");
808 Write_Eol;
809 Write_Eol;
810 Set_Standard_Output;
811 end if;
812 end Check_Rep_Info;
814 ----------------------------------------
815 -- Post_Compilation_Validation_Checks --
816 ----------------------------------------
818 procedure Post_Compilation_Validation_Checks is
819 begin
820 -- Validate alignment check warnings. In some cases we generate warnings
821 -- about possible alignment errors because we don't know the alignment
822 -- that will be chosen by the back end. This routine is in charge of
823 -- getting rid of those warnings if we can tell they are not needed.
825 Checks.Validate_Alignment_Check_Warnings;
827 -- Validate unchecked conversions (using the values for size and
828 -- alignment annotated by the backend where possible).
830 Sem_Ch13.Validate_Unchecked_Conversions;
832 -- Validate address clauses (again using alignment values annotated
833 -- by the backend where possible).
835 Sem_Ch13.Validate_Address_Clauses;
837 -- Validate independence pragmas (again using values annotated by
838 -- the back end for component layout etc.)
840 Sem_Ch13.Validate_Independence;
841 end Post_Compilation_Validation_Checks;
843 -- Start of processing for Gnat1drv
845 begin
846 -- This inner block is set up to catch assertion errors and constraint
847 -- errors. Since the code for handling these errors can cause another
848 -- exception to be raised (namely Unrecoverable_Error), we need two
849 -- nested blocks, so that the outer one handles unrecoverable error.
851 begin
852 -- Initialize all packages. For the most part, these initialization
853 -- calls can be made in any order. Exceptions are as follows:
855 -- Lib.Initialize need to be called before Scan_Compiler_Arguments,
856 -- because it initializes a table filled by Scan_Compiler_Arguments.
858 Osint.Initialize;
859 Fmap.Reset_Tables;
860 Lib.Initialize;
861 Lib.Xref.Initialize;
862 Scan_Compiler_Arguments;
863 Osint.Add_Default_Search_Dirs;
865 Atree.Initialize;
866 Nlists.Initialize;
867 Sinput.Initialize;
868 Sem.Initialize;
869 Exp_CG.Initialize;
870 Csets.Initialize;
871 Uintp.Initialize;
872 Urealp.Initialize;
873 Errout.Initialize;
874 SCOs.Initialize;
875 Snames.Initialize;
876 Stringt.Initialize;
877 Inline.Initialize;
878 Par_SCO.Initialize;
879 Sem_Ch8.Initialize;
880 Sem_Ch12.Initialize;
881 Sem_Ch13.Initialize;
882 Sem_Elim.Initialize;
883 Sem_Eval.Initialize;
884 Sem_Type.Init_Interp_Tables;
886 -- Capture compilation date and time
888 Opt.Compilation_Time := System.OS_Lib.Current_Time_String;
890 -- Get the target parameters only when -gnats is not used, to avoid
891 -- failing when there is no default runtime.
893 if Operating_Mode /= Check_Syntax then
895 -- Acquire target parameters from system.ads (package System source)
897 Targparm_Acquire : declare
898 use Sinput;
900 S : Source_File_Index;
901 N : File_Name_Type;
903 begin
904 Name_Buffer (1 .. 10) := "system.ads";
905 Name_Len := 10;
906 N := Name_Find;
907 S := Load_Source_File (N);
909 -- Failed to read system.ads, fatal error
911 if S = No_Source_File then
912 Write_Line
913 ("fatal error, run-time library not installed correctly");
914 Write_Line ("cannot locate file system.ads");
915 raise Unrecoverable_Error;
917 -- Read system.ads successfully, remember its source index
919 else
920 System_Source_File_Index := S;
921 end if;
923 Targparm.Get_Target_Parameters
924 (System_Text => Source_Text (S),
925 Source_First => Source_First (S),
926 Source_Last => Source_Last (S),
927 Make_Id => Tbuild.Make_Id'Access,
928 Make_SC => Tbuild.Make_SC'Access,
929 Set_RND => Tbuild.Set_RND'Access);
931 -- Acquire configuration pragma information from Targparm
933 Restrict.Restrictions := Targparm.Restrictions_On_Target;
934 end Targparm_Acquire;
935 end if;
937 -- Perform various adjustments and settings of global switches
939 Adjust_Global_Switches;
941 -- Output copyright notice if full list mode unless we have a list
942 -- file, in which case we defer this so that it is output in the file.
944 if (Verbose_Mode or else (Full_List and then Full_List_File_Name = null))
946 -- Debug flag gnatd7 suppresses this copyright notice
948 and then not Debug_Flag_7
949 then
950 Write_Eol;
951 Write_Str ("GNAT ");
952 Write_Str (Gnat_Version_String);
953 Write_Eol;
954 Write_Str ("Copyright 1992-" & Current_Year
955 & ", Free Software Foundation, Inc.");
956 Write_Eol;
957 end if;
959 -- Check we do not have more than one source file, this happens only in
960 -- the case where the driver is called directly, it cannot happen when
961 -- gnat1 is invoked from gcc in the normal case.
963 if Osint.Number_Of_Files /= 1 then
964 Usage;
965 Write_Eol;
966 Osint.Fail ("you must provide one source file");
968 elsif Usage_Requested then
969 Usage;
970 end if;
972 -- Generate target dependent output file if requested
974 if Target_Dependent_Info_Write_Name /= null then
975 Set_Targ.Write_Target_Dependent_Values;
976 end if;
978 -- Call the front end
980 Original_Operating_Mode := Operating_Mode;
981 Frontend;
983 -- Exit with errors if the main source could not be parsed.
985 if Sinput.Main_Source_File = No_Source_File then
986 Errout.Finalize (Last_Call => True);
987 Errout.Output_Messages;
988 Exit_Program (E_Errors);
989 end if;
991 Main_Unit_Node := Cunit (Main_Unit);
992 Main_Kind := Nkind (Unit (Main_Unit_Node));
993 Check_Bad_Body;
995 -- In CodePeer mode we always delete old SCIL files before regenerating
996 -- new ones, in case of e.g. errors, and also to remove obsolete scilx
997 -- files generated by CodePeer itself.
999 if CodePeer_Mode then
1000 Comperr.Delete_SCIL_Files;
1001 end if;
1003 -- Exit if compilation errors detected
1005 Errout.Finalize (Last_Call => False);
1007 if Compilation_Errors then
1008 Treepr.Tree_Dump;
1009 Post_Compilation_Validation_Checks;
1010 Errout.Output_Messages;
1011 Namet.Finalize;
1013 -- Generate ALI file if specially requested
1015 if Opt.Force_ALI_Tree_File then
1016 Write_ALI (Object => False);
1017 Tree_Gen;
1018 end if;
1020 Errout.Finalize (Last_Call => True);
1021 Exit_Program (E_Errors);
1022 end if;
1024 -- Set Generate_Code on main unit and its spec. We do this even if are
1025 -- not generating code, since Lib-Writ uses this to determine which
1026 -- units get written in the ali file.
1028 Set_Generate_Code (Main_Unit);
1030 -- If we have a corresponding spec, and it comes from source or it is
1031 -- not a generated spec for a child subprogram body, then we need object
1032 -- code for the spec unit as well.
1034 if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body
1035 and then not Acts_As_Spec (Main_Unit_Node)
1036 then
1037 if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body
1038 and then not Comes_From_Source (Library_Unit (Main_Unit_Node))
1039 then
1040 null;
1041 else
1042 Set_Generate_Code
1043 (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node)));
1044 end if;
1045 end if;
1047 -- Case of no code required to be generated, exit indicating no error
1049 if Original_Operating_Mode = Check_Syntax then
1050 Treepr.Tree_Dump;
1051 Errout.Finalize (Last_Call => True);
1052 Errout.Output_Messages;
1053 Tree_Gen;
1054 Namet.Finalize;
1055 Check_Rep_Info;
1057 -- Use a goto instead of calling Exit_Program so that finalization
1058 -- occurs normally.
1060 goto End_Of_Program;
1062 elsif Original_Operating_Mode = Check_Semantics then
1063 Back_End_Mode := Declarations_Only;
1065 -- All remaining cases are cases in which the user requested that code
1066 -- be generated (i.e. no -gnatc or -gnats switch was used). Check if we
1067 -- can in fact satisfy this request.
1069 -- Cannot generate code if someone has turned off code generation for
1070 -- any reason at all. We will try to figure out a reason below.
1072 elsif Operating_Mode /= Generate_Code then
1073 Back_End_Mode := Skip;
1075 -- We can generate code for a subprogram body unless there were missing
1076 -- subunits. Note that we always generate code for all generic units (a
1077 -- change from some previous versions of GNAT).
1079 elsif Main_Kind = N_Subprogram_Body and then not Subunits_Missing then
1080 Back_End_Mode := Generate_Object;
1082 -- We can generate code for a package body unless there are subunits
1083 -- missing (note that we always generate code for generic units, which
1084 -- is a change from some earlier versions of GNAT).
1086 elsif Main_Kind = N_Package_Body and then not Subunits_Missing then
1087 Back_End_Mode := Generate_Object;
1089 -- We can generate code for a package declaration or a subprogram
1090 -- declaration only if it does not required a body.
1092 elsif Nkind_In (Main_Kind,
1093 N_Package_Declaration,
1094 N_Subprogram_Declaration)
1095 and then
1096 (not Body_Required (Main_Unit_Node)
1097 or else
1098 Distribution_Stub_Mode = Generate_Caller_Stub_Body)
1099 then
1100 Back_End_Mode := Generate_Object;
1102 -- We can generate code for a generic package declaration of a generic
1103 -- subprogram declaration only if does not require a body.
1105 elsif Nkind_In (Main_Kind, N_Generic_Package_Declaration,
1106 N_Generic_Subprogram_Declaration)
1107 and then not Body_Required (Main_Unit_Node)
1108 then
1109 Back_End_Mode := Generate_Object;
1111 -- Compilation units that are renamings do not require bodies, so we can
1112 -- generate code for them.
1114 elsif Nkind_In (Main_Kind, N_Package_Renaming_Declaration,
1115 N_Subprogram_Renaming_Declaration)
1116 then
1117 Back_End_Mode := Generate_Object;
1119 -- Compilation units that are generic renamings do not require bodies
1120 -- so we can generate code for them.
1122 elsif Main_Kind in N_Generic_Renaming_Declaration then
1123 Back_End_Mode := Generate_Object;
1125 -- It is not an error to analyze in CodePeer mode a spec which requires
1126 -- a body, in order to generate SCIL for this spec.
1128 elsif CodePeer_Mode then
1129 Back_End_Mode := Generate_Object;
1131 -- It is not an error to analyze in GNATprove mode a spec which requires
1132 -- a body, when the body is not available. During frame condition
1133 -- generation, the corresponding ALI file is generated. During
1134 -- analysis, the spec is analyzed.
1136 elsif GNATprove_Mode then
1137 Back_End_Mode := Declarations_Only;
1139 -- In all other cases (specs which have bodies, generics, and bodies
1140 -- where subunits are missing), we cannot generate code and we generate
1141 -- a warning message. Note that generic instantiations are gone at this
1142 -- stage since they have been replaced by their instances.
1144 else
1145 Back_End_Mode := Skip;
1146 end if;
1148 -- At this stage Back_End_Mode is set to indicate if the backend should
1149 -- be called to generate code. If it is Skip, then code generation has
1150 -- been turned off, even though code was requested by the original
1151 -- command. This is not an error from the user point of view, but it is
1152 -- an error from the point of view of the gcc driver, so we must exit
1153 -- with an error status.
1155 -- We generate an informative message (from the gcc point of view, it
1156 -- is an error message, but from the users point of view this is not an
1157 -- error, just a consequence of compiling something that cannot
1158 -- generate code).
1160 if Back_End_Mode = Skip then
1161 Set_Standard_Error;
1162 Write_Str ("cannot generate code for ");
1163 Write_Str ("file ");
1164 Write_Name (Unit_File_Name (Main_Unit));
1166 if Subunits_Missing then
1167 Write_Str (" (missing subunits)");
1168 Write_Eol;
1170 -- Force generation of ALI file, for backward compatibility
1172 Opt.Force_ALI_Tree_File := True;
1174 elsif Main_Kind = N_Subunit then
1175 Write_Str (" (subunit)");
1176 Write_Eol;
1178 -- Force generation of ALI file, for backward compatibility
1180 Opt.Force_ALI_Tree_File := True;
1182 elsif Main_Kind = N_Subprogram_Declaration then
1183 Write_Str (" (subprogram spec)");
1184 Write_Eol;
1186 -- Generic package body in GNAT implementation mode
1188 elsif Main_Kind = N_Package_Body and then GNAT_Mode then
1189 Write_Str (" (predefined generic)");
1190 Write_Eol;
1192 -- Force generation of ALI file, for backward compatibility
1194 Opt.Force_ALI_Tree_File := True;
1196 -- Only other case is a package spec
1198 else
1199 Write_Str (" (package spec)");
1200 Write_Eol;
1201 end if;
1203 Set_Standard_Output;
1205 Post_Compilation_Validation_Checks;
1206 Errout.Finalize (Last_Call => True);
1207 Errout.Output_Messages;
1208 Treepr.Tree_Dump;
1209 Tree_Gen;
1211 -- Generate ALI file if specially requested, or for missing subunits,
1212 -- subunits or predefined generic.
1214 if Opt.Force_ALI_Tree_File then
1215 Write_ALI (Object => False);
1216 end if;
1218 Namet.Finalize;
1219 Check_Rep_Info;
1221 -- Exit program with error indication, to kill object file
1223 Exit_Program (E_No_Code);
1224 end if;
1226 -- In -gnatc mode, we only do annotation if -gnatt or -gnatR is also set
1227 -- as indicated by Back_Annotate_Rep_Info being set to True.
1229 -- We don't call for annotations on a subunit, because to process those
1230 -- the back-end requires that the parent(s) be properly compiled.
1232 -- Annotation is suppressed for targets where front-end layout is
1233 -- enabled, because the front end determines representations.
1235 -- Annotation is also suppressed in the case of compiling for a VM,
1236 -- since representations are largely symbolic there.
1238 if Back_End_Mode = Declarations_Only
1239 and then
1240 (not (Back_Annotate_Rep_Info or Generate_SCIL or GNATprove_Mode)
1241 or else Main_Kind = N_Subunit
1242 or else Targparm.Frontend_Layout_On_Target
1243 or else Targparm.VM_Target /= No_VM)
1244 then
1245 Post_Compilation_Validation_Checks;
1246 Errout.Finalize (Last_Call => True);
1247 Errout.Output_Messages;
1248 Write_ALI (Object => False);
1249 Tree_Dump;
1250 Tree_Gen;
1251 Namet.Finalize;
1252 Check_Rep_Info;
1253 return;
1254 end if;
1256 -- Ensure that we properly register a dependency on system.ads, since
1257 -- even if we do not semantically depend on this, Targparm has read
1258 -- system parameters from the system.ads file.
1260 Lib.Writ.Ensure_System_Dependency;
1262 -- Add dependencies, if any, on preprocessing data file and on
1263 -- preprocessing definition file(s).
1265 Prepcomp.Add_Dependencies;
1267 -- In gnatprove mode we're writing the ALI much earlier than usual
1268 -- as flow analysis needs the file present in order to append its
1269 -- own globals to it.
1271 if GNATprove_Mode then
1273 -- Note: In GNATprove mode, an "object" file is always generated as
1274 -- the result of calling gnat1 or gnat2why, although this is not the
1275 -- same as the object file produced for compilation.
1277 Write_ALI (Object => True);
1278 end if;
1280 -- Back end needs to explicitly unlock tables it needs to touch
1282 Atree.Lock;
1283 Elists.Lock;
1284 Fname.UF.Lock;
1285 Inline.Lock;
1286 Lib.Lock;
1287 Nlists.Lock;
1288 Sem.Lock;
1289 Sinput.Lock;
1290 Namet.Lock;
1291 Stringt.Lock;
1293 -- Here we call the back end to generate the output code
1295 Generating_Code := True;
1296 Back_End.Call_Back_End (Back_End_Mode);
1298 -- Once the backend is complete, we unlock the names table. This call
1299 -- allows a few extra entries, needed for example for the file name for
1300 -- the library file output.
1302 Namet.Unlock;
1304 -- Generate the call-graph output of dispatching calls
1306 Exp_CG.Generate_CG_Output;
1308 -- Perform post compilation validation checks
1310 Post_Compilation_Validation_Checks;
1312 -- Now we complete output of errors, rep info and the tree info. These
1313 -- are delayed till now, since it is perfectly possible for gigi to
1314 -- generate errors, modify the tree (in particular by setting flags
1315 -- indicating that elaboration is required, and also to back annotate
1316 -- representation information for List_Rep_Info.
1318 Errout.Finalize (Last_Call => True);
1319 Errout.Output_Messages;
1320 List_Rep_Info (Ttypes.Bytes_Big_Endian);
1321 Inline.List_Inlining_Info;
1323 -- Only write the library if the backend did not generate any error
1324 -- messages. Otherwise signal errors to the driver program so that
1325 -- there will be no attempt to generate an object file.
1327 if Compilation_Errors then
1328 Treepr.Tree_Dump;
1329 Exit_Program (E_Errors);
1330 end if;
1332 if not GNATprove_Mode then
1333 Write_ALI (Object => (Back_End_Mode = Generate_Object));
1334 end if;
1336 if not Compilation_Errors then
1338 -- In case of ada backends, we need to make sure that the generated
1339 -- object file has a timestamp greater than the ALI file. We do this
1340 -- to make gnatmake happy when checking the ALI and obj timestamps,
1341 -- where it expects the object file being written after the ali file.
1343 -- Gnatmake's assumption is true for gcc platforms where the gcc
1344 -- wrapper needs to call the assembler after calling gnat1, but is
1345 -- not true for ada backends, where the object files are created
1346 -- directly by gnat1 (so are created before the ali file).
1348 Back_End.Gen_Or_Update_Object_File;
1349 end if;
1351 -- Generate ASIS tree after writing the ALI file, since in ASIS mode,
1352 -- Write_ALI may in fact result in further tree decoration from the
1353 -- original tree file. Note that we dump the tree just before generating
1354 -- it, so that the dump will exactly reflect what is written out.
1356 Treepr.Tree_Dump;
1357 Tree_Gen;
1359 -- Finalize name table and we are all done
1361 Namet.Finalize;
1363 exception
1364 -- Handle fatal internal compiler errors
1366 when Rtsfind.RE_Not_Available =>
1367 Comperr.Compiler_Abort ("RE_Not_Available");
1369 when System.Assertions.Assert_Failure =>
1370 Comperr.Compiler_Abort ("Assert_Failure");
1372 when Constraint_Error =>
1373 Comperr.Compiler_Abort ("Constraint_Error");
1375 when Program_Error =>
1376 Comperr.Compiler_Abort ("Program_Error");
1378 when Storage_Error =>
1380 -- Assume this is a bug. If it is real, the message will in any case
1381 -- say Storage_Error, giving a strong hint.
1383 Comperr.Compiler_Abort ("Storage_Error");
1384 end;
1386 <<End_Of_Program>>
1387 null;
1389 -- The outer exception handles an unrecoverable error
1391 exception
1392 when Unrecoverable_Error =>
1393 Errout.Finalize (Last_Call => True);
1394 Errout.Output_Messages;
1396 Set_Standard_Error;
1397 Write_Str ("compilation abandoned");
1398 Write_Eol;
1400 Set_Standard_Output;
1401 Source_Dump;
1402 Tree_Dump;
1403 Exit_Program (E_Errors);
1405 end Gnat1drv;