* libgfortran.h (support_fpu_underflow_control,
[official-gcc.git] / gcc / ada / frontend.adb
blob24b33cfe2096f7ef29b53cb8f7d0d0bba794c526
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R O N T E N D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with System.Strings; use System.Strings;
28 with Atree; use Atree;
29 with Checks;
30 with CStand;
31 with Debug; use Debug;
32 with Elists;
33 with Exp_Dbug;
34 with Fmap;
35 with Fname.UF;
36 with Inline; use Inline;
37 with Lib; use Lib;
38 with Lib.Load; use Lib.Load;
39 with Lib.Xref; use Lib.Xref;
40 with Live; use Live;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Opt; use Opt;
44 with Osint;
45 with Par;
46 with Prep;
47 with Prepcomp;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
51 with Snames; use Snames;
52 with Sprint;
53 with Scn; use Scn;
54 with Sem; use Sem;
55 with Sem_Aux;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_SCIL;
58 with Sem_Elab; use Sem_Elab;
59 with Sem_Prag; use Sem_Prag;
60 with Sem_VFpt; use Sem_VFpt;
61 with Sem_Warn; use Sem_Warn;
62 with Sinfo; use Sinfo;
63 with Sinput; use Sinput;
64 with Sinput.L; use Sinput.L;
65 with SCIL_LL; use SCIL_LL;
66 with Targparm; use Targparm;
67 with Tbuild; use Tbuild;
68 with Types; use Types;
70 procedure Frontend is
71 Config_Pragmas : List_Id;
72 -- Gather configuration pragmas
74 begin
75 -- Carry out package initializations. These are initializations which might
76 -- logically be performed at elaboration time, were it not for the fact
77 -- that we may be doing things more than once in the big loop over files.
78 -- Like elaboration, the order in which these calls are made is in some
79 -- cases important. For example, Lib cannot be initialized before Namet,
80 -- since it uses names table entries.
82 Rtsfind.Initialize;
83 Nlists.Initialize;
84 Elists.Initialize;
85 Lib.Load.Initialize;
86 Sem_Aux.Initialize;
87 Sem_Ch8.Initialize;
88 Sem_Prag.Initialize;
89 Fname.UF.Initialize;
90 Checks.Initialize;
91 Sem_Warn.Initialize;
92 Prep.Initialize;
94 if Generate_SCIL then
95 SCIL_LL.Initialize;
96 end if;
98 -- Create package Standard
100 CStand.Create_Standard;
102 -- Check possible symbol definitions specified by -gnateD switches
104 Prepcomp.Process_Command_Line_Symbol_Definitions;
106 -- If -gnatep= was specified, parse the preprocessing data file
108 if Preprocessing_Data_File /= null then
109 Name_Len := Preprocessing_Data_File'Length;
110 Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
111 Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
113 -- Otherwise, check if there were preprocessing symbols on the command
114 -- line and set preprocessing if there are.
116 else
117 Prepcomp.Check_Symbols;
118 end if;
120 -- We set Parsing_Main_Extended_Source true here to cover processing of all
121 -- the configuration pragma files, as well as the main source unit itself.
123 Parsing_Main_Extended_Source := True;
125 -- Now that the preprocessing situation is established, we are able to
126 -- load the main source (this is no longer done by Lib.Load.Initialize).
128 Lib.Load.Load_Main_Source;
130 -- Return immediately if the main source could not be found
132 if Sinput.Main_Source_File = No_Source_File then
133 return;
134 end if;
136 -- Read and process configuration pragma files if present
138 declare
139 Save_Style_Check : constant Boolean := Opt.Style_Check;
140 -- Save style check mode so it can be restored later
142 Source_Config_File : Source_File_Index;
143 -- Source reference for -gnatec configuration file
145 Prag : Node_Id;
147 begin
148 -- We always analyze config files with style checks off, since
149 -- we don't want a miscellaneous gnat.adc that is around to
150 -- discombobulate intended -gnatg or -gnaty compilations. We
151 -- also disconnect checking for maximum line length.
153 Opt.Style_Check := False;
154 Style_Check := False;
156 -- Capture current suppress options, which may get modified
158 Scope_Suppress := Opt.Suppress_Options;
160 -- First deal with gnat.adc file
162 if Opt.Config_File then
163 Name_Buffer (1 .. 8) := "gnat.adc";
164 Name_Len := 8;
165 Source_gnat_adc := Load_Config_File (Name_Enter);
167 if Source_gnat_adc /= No_Source_File then
168 Initialize_Scanner (No_Unit, Source_gnat_adc);
169 Config_Pragmas := Par (Configuration_Pragmas => True);
170 else
171 Config_Pragmas := Empty_List;
172 end if;
174 else
175 Config_Pragmas := Empty_List;
176 end if;
178 -- Check for VAX Float
180 if Targparm.VAX_Float_On_Target then
182 -- pragma Float_Representation (VAX_Float);
184 Opt.Float_Format := 'V';
186 -- pragma Long_Float (G_Float);
188 Opt.Float_Format_Long := 'G';
190 Set_Standard_Fpt_Formats;
191 end if;
193 -- Now deal with specified config pragmas files if there are any
195 if Opt.Config_File_Names /= null then
196 for Index in Opt.Config_File_Names'Range loop
197 Name_Len := Config_File_Names (Index)'Length;
198 Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
199 Source_Config_File := Load_Config_File (Name_Enter);
201 if Source_Config_File = No_Source_File then
202 Osint.Fail
203 ("cannot find configuration pragmas file "
204 & Config_File_Names (Index).all);
205 end if;
207 Initialize_Scanner (No_Unit, Source_Config_File);
208 Append_List_To
209 (Config_Pragmas, Par (Configuration_Pragmas => True));
210 end loop;
211 end if;
213 -- Now analyze all pragmas except those whose analysis must be
214 -- deferred till after the main unit is analyzed.
216 if Config_Pragmas /= Error_List
217 and then Operating_Mode /= Check_Syntax
218 then
219 Prag := First (Config_Pragmas);
220 while Present (Prag) loop
221 if not Delay_Config_Pragma_Analyze (Prag) then
222 Analyze_Pragma (Prag);
223 end if;
225 Next (Prag);
226 end loop;
227 end if;
229 -- Restore style check, but if config file turned on checks, leave on
231 Opt.Style_Check := Save_Style_Check or Style_Check;
233 -- Capture any modifications to suppress options from config pragmas
235 Opt.Suppress_Options := Scope_Suppress;
236 end;
238 -- This is where we can capture the value of the compilation unit specific
239 -- restrictions that have been set by the config pragma files (or from
240 -- Targparm), for later restoration when processing e.g. subunits.
242 Save_Config_Cunit_Boolean_Restrictions;
244 -- If there was a -gnatem switch, initialize the mappings of unit names to
245 -- file names and of file names to path names from the mapping file.
247 if Mapping_File_Name /= null then
248 Fmap.Initialize (Mapping_File_Name.all);
249 end if;
251 -- Adjust Optimize_Alignment mode from debug switches if necessary
253 if Debug_Flag_Dot_SS then
254 Optimize_Alignment := 'S';
255 elsif Debug_Flag_Dot_TT then
256 Optimize_Alignment := 'T';
257 end if;
259 -- We have now processed the command line switches, and the configuration
260 -- pragma files, so this is the point at which we want to capture the
261 -- values of the configuration switches (see Opt for further details).
263 Opt.Register_Opt_Config_Switches;
265 -- Check for file which contains No_Body pragma
267 if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
268 Change_Main_Unit_To_Spec;
269 end if;
271 -- Initialize the scanner. Note that we do this after the call to
272 -- Create_Standard, which uses the scanner in its processing of
273 -- floating-point bounds.
275 Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
277 -- Here we call the parser to parse the compilation unit (or units in
278 -- the check syntax mode, but in that case we won't go on to the
279 -- semantics in any case).
281 Discard_List (Par (Configuration_Pragmas => False));
282 Parsing_Main_Extended_Source := False;
284 -- The main unit is now loaded, and subunits of it can be loaded,
285 -- without reporting spurious loading circularities.
287 Set_Loading (Main_Unit, False);
289 -- Now that the main unit is installed, we can complete the analysis
290 -- of the pragmas in gnat.adc and the configuration file, that require
291 -- a context for their semantic processing.
293 if Config_Pragmas /= Error_List
294 and then Operating_Mode /= Check_Syntax
296 -- Do not attempt to process deferred configuration pragmas if the main
297 -- unit failed to load, to avoid cascaded inconsistencies that can lead
298 -- to a compiler crash.
300 and then not Fatal_Error (Main_Unit)
301 then
302 -- Pragmas that require some semantic activity, such as
303 -- Interrupt_State, cannot be processed until the main unit
304 -- is installed, because they require a compilation unit on
305 -- which to attach with_clauses, etc. So analyze them now.
307 declare
308 Prag : Node_Id;
310 begin
311 Prag := First (Config_Pragmas);
312 while Present (Prag) loop
313 if Delay_Config_Pragma_Analyze (Prag) then
314 Analyze_Pragma (Prag);
315 end if;
317 Next (Prag);
318 end loop;
319 end;
320 end if;
322 -- If we have restriction No_Exception_Propagation, and we did not have an
323 -- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
324 -- this warning by default if we have encountered an exception handler.
326 if Restriction_Check_Required (No_Exception_Propagation)
327 and then not No_Warn_On_Non_Local_Exception
328 and then Exception_Handler_Encountered
329 then
330 Warn_On_Non_Local_Exception := True;
331 end if;
333 -- Now on to the semantics. Skip if in syntax only mode
335 if Operating_Mode /= Check_Syntax then
337 -- Install the configuration pragmas in the tree
339 Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
341 -- Following steps are skipped if we had a fatal error during parsing
343 if not Fatal_Error (Main_Unit) then
345 -- Reset Operating_Mode to Check_Semantics for subunits. We cannot
346 -- actually generate code for subunits, so we suppress expansion.
347 -- This also corrects certain problems that occur if we try to
348 -- incorporate subunits at a lower level.
350 if Operating_Mode = Generate_Code
351 and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
352 then
353 Operating_Mode := Check_Semantics;
354 end if;
356 -- Analyze (and possibly expand) main unit
358 Scope_Suppress := Suppress_Options;
359 Semantics (Cunit (Main_Unit));
361 -- Cleanup processing after completing main analysis
363 -- Comment needed for ASIS mode test and GNATprove mode test???
365 if Operating_Mode = Generate_Code
366 or else (Operating_Mode = Check_Semantics
367 and then (ASIS_Mode or GNATprove_Mode))
368 then
369 Instantiate_Bodies;
370 end if;
372 if Operating_Mode = Generate_Code then
373 if Inline_Processing_Required then
374 Analyze_Inlined_Bodies;
375 end if;
377 -- Remove entities from program that do not have any
378 -- execution time references.
380 if Debug_Flag_UU then
381 Collect_Garbage_Entities;
382 end if;
384 Check_Elab_Calls;
385 end if;
387 -- List library units if requested
389 if List_Units then
390 Lib.List;
391 end if;
393 -- Output waiting warning messages
395 Lib.Xref.Process_Deferred_References;
396 Sem_Warn.Output_Non_Modified_In_Out_Warnings;
397 Sem_Warn.Output_Unreferenced_Messages;
398 Sem_Warn.Check_Unused_Withs;
399 Sem_Warn.Output_Unused_Warnings_Off_Warnings;
400 end if;
401 end if;
403 -- Qualify all entity names in inner packages, package bodies, etc.,
404 -- except when compiling for the VM back-ends, which depend on having
405 -- unqualified names in certain cases and handles the generation of
406 -- qualified names when needed.
408 if VM_Target = No_VM then
409 Exp_Dbug.Qualify_All_Entity_Names;
410 end if;
412 -- SCIL backend requirement. Check that SCIL nodes associated with
413 -- dispatching calls reference subprogram calls.
415 if Generate_SCIL then
416 pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
417 null;
418 end if;
420 -- Dump the source now. Note that we do this as soon as the analysis
421 -- of the tree is complete, because it is not just a dump in the case
422 -- of -gnatD, where it rewrites all source locations in the tree.
424 Sprint.Source_Dump;
426 -- Check again for configuration pragmas that appear in the context of
427 -- the main unit. These pragmas only affect the main unit, and the
428 -- corresponding flag is reset after each call to Semantics, but they
429 -- may affect the generated ali for the unit, and therefore the flag
430 -- must be set properly after compilation. Currently we only check for
431 -- Initialize_Scalars, but others should be checked: as well???
433 declare
434 Item : Node_Id;
436 begin
437 Item := First (Context_Items (Cunit (Main_Unit)));
438 while Present (Item) loop
439 if Nkind (Item) = N_Pragma
440 and then Pragma_Name (Item) = Name_Initialize_Scalars
441 then
442 Initialize_Scalars := True;
443 end if;
445 Next (Item);
446 end loop;
447 end;
449 -- If a mapping file has been specified by a -gnatem switch, update
450 -- it if there has been some sources that were not in the mappings.
452 if Mapping_File_Name /= null then
453 Fmap.Update_Mapping_File (Mapping_File_Name.all);
454 end if;
456 return;
457 end Frontend;