annotate gcc/ada/gnat1drv.adb @ 144:8f4e72ab4e11

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