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