1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- A L I . U T I L --
|
6 |
|
|
-- --
|
7 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2011, 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 |
|
|
-- This child unit provides utility data structures and procedures used
|
27 |
|
|
-- for manipulation of ALI data by the gnatbind and gnatmake.
|
28 |
|
|
|
29 |
|
|
package ALI.Util is
|
30 |
|
|
|
31 |
|
|
-----------------------
|
32 |
|
|
-- Source File Table --
|
33 |
|
|
-----------------------
|
34 |
|
|
|
35 |
|
|
-- A table entry is built for every source file that is in the source
|
36 |
|
|
-- dependency table of any ALI file that is part of the current program.
|
37 |
|
|
|
38 |
|
|
No_Source_Id : constant Source_Id := Source_Id'First;
|
39 |
|
|
-- Special value indicating no Source table entry
|
40 |
|
|
|
41 |
|
|
First_Source_Entry : constant Source_Id := No_Source_Id + 1;
|
42 |
|
|
-- Id of first actual entry in table
|
43 |
|
|
|
44 |
|
|
type Source_Record is record
|
45 |
|
|
|
46 |
|
|
Sfile : File_Name_Type;
|
47 |
|
|
-- Name of source file
|
48 |
|
|
|
49 |
|
|
Stamp : Time_Stamp_Type;
|
50 |
|
|
-- Time stamp value. If Check_Source_Files is set and the source
|
51 |
|
|
-- file is located, then Stamp is set from the source file. Otherwise
|
52 |
|
|
-- Stamp is set from the latest stamp value found in any of the
|
53 |
|
|
-- ALI files for the current program.
|
54 |
|
|
|
55 |
|
|
Source_Found : Boolean;
|
56 |
|
|
-- This flag is set to True if the corresponding source file was
|
57 |
|
|
-- located and the Stamp value was set from the actual source file.
|
58 |
|
|
-- It is always false if Check_Source_Files is not set.
|
59 |
|
|
|
60 |
|
|
All_Timestamps_Match : Boolean;
|
61 |
|
|
-- This flag is set only if all files referencing this source file
|
62 |
|
|
-- have a matching time stamp, and also, if Source_Found is True,
|
63 |
|
|
-- then the stamp of the source file also matches. If this flag is
|
64 |
|
|
-- True, then checksums for this file are never referenced. We only
|
65 |
|
|
-- use checksums if there are time stamp mismatches.
|
66 |
|
|
|
67 |
|
|
All_Checksums_Match : Boolean;
|
68 |
|
|
-- This flag is set only if all files referencing this source file
|
69 |
|
|
-- have checksums, and if all these checksums match. If this flag
|
70 |
|
|
-- is set to True, then the binder will ignore a timestamp mismatch.
|
71 |
|
|
-- An absent checksum causes this flag to be set False, and a mismatch
|
72 |
|
|
-- of checksums also causes it to be set False. The checksum of the
|
73 |
|
|
-- actual source file (if Source_Found is True) is included only if
|
74 |
|
|
-- All_Timestamps_Match is False (since checksums are only interesting
|
75 |
|
|
-- if we have time stamp mismatches, and we want to avoid computing the
|
76 |
|
|
-- checksum of the source file if it is not needed.)
|
77 |
|
|
|
78 |
|
|
Checksum : Word;
|
79 |
|
|
-- If no dependency line has a checksum for this source file (i.e. the
|
80 |
|
|
-- corresponding entries in the source dependency records all have the
|
81 |
|
|
-- Checksum_Present flag set False), then this field is undefined. If
|
82 |
|
|
-- at least one dependency entry has a checksum present, then this
|
83 |
|
|
-- field contains one of the possible checksum values that has been
|
84 |
|
|
-- seen. This is used to set All_Checksums_Match properly.
|
85 |
|
|
|
86 |
|
|
end record;
|
87 |
|
|
|
88 |
|
|
package Source is new Table.Table (
|
89 |
|
|
Table_Component_Type => Source_Record,
|
90 |
|
|
Table_Index_Type => Source_Id,
|
91 |
|
|
Table_Low_Bound => First_Source_Entry,
|
92 |
|
|
Table_Initial => 1000,
|
93 |
|
|
Table_Increment => 200,
|
94 |
|
|
Table_Name => "Source");
|
95 |
|
|
|
96 |
|
|
procedure Initialize_ALI_Source;
|
97 |
|
|
-- Initialize Source table
|
98 |
|
|
|
99 |
|
|
--------------------------------------------------
|
100 |
|
|
-- Subprograms for Manipulating ALI Information --
|
101 |
|
|
--------------------------------------------------
|
102 |
|
|
|
103 |
|
|
procedure Read_Withed_ALIs
|
104 |
|
|
(Id : ALI_Id;
|
105 |
|
|
Ignore_Errors : Boolean := False);
|
106 |
|
|
-- Process an ALI file which has been read and scanned by looping through
|
107 |
|
|
-- all withed units in the ALI file, checking if they have been processed.
|
108 |
|
|
-- Each unit that has not yet been processed will be read, scanned, and
|
109 |
|
|
-- processed recursively. If Ignore_Errors is True, then failure to read an
|
110 |
|
|
-- ALI file is not reported as an error, and scanning continues with other
|
111 |
|
|
-- ALI files.
|
112 |
|
|
|
113 |
|
|
procedure Set_Source_Table (A : ALI_Id);
|
114 |
|
|
-- Build source table entry corresponding to the ALI file whose id is A
|
115 |
|
|
|
116 |
|
|
procedure Set_Source_Table;
|
117 |
|
|
-- Build the entire source table
|
118 |
|
|
|
119 |
|
|
function Time_Stamp_Mismatch
|
120 |
|
|
(A : ALI_Id;
|
121 |
|
|
Read_Only : Boolean := False) return File_Name_Type;
|
122 |
|
|
-- Looks in the Source_Table and checks time stamp mismatches between
|
123 |
|
|
-- the sources there and the sources in the Sdep section of ali file whose
|
124 |
|
|
-- id is A. If no time stamp mismatches are found No_File is returned.
|
125 |
|
|
-- Otherwise return the first file for which there is a mismatch.
|
126 |
|
|
-- Note that in check source files mode (Check_Source_Files = True), the
|
127 |
|
|
-- time stamp in the Source_Table should be the actual time stamp of the
|
128 |
|
|
-- source files. In minimal recompilation mode (Minimal_Recompilation set
|
129 |
|
|
-- to True, no mismatch is found if the file's timestamp has not changed.
|
130 |
|
|
-- If Read_Only is True, missing sources are not considered.
|
131 |
|
|
|
132 |
|
|
--------------------------------------------
|
133 |
|
|
-- Subprograms for manipulating checksums --
|
134 |
|
|
--------------------------------------------
|
135 |
|
|
|
136 |
|
|
Checksum_Error : constant Word := 16#FFFF_FFFF#;
|
137 |
|
|
-- This value is used to indicate an error in computing the checksum.
|
138 |
|
|
-- When comparing checksums for smart recompilation, the CRC_Error
|
139 |
|
|
-- value is never considered to match. This could possibly result
|
140 |
|
|
-- in a false negative, but that is never harmful, it just means
|
141 |
|
|
-- that in unusual cases an unnecessary recompilation occurs.
|
142 |
|
|
|
143 |
|
|
function Get_File_Checksum (Fname : File_Name_Type) return Word;
|
144 |
|
|
-- Compute checksum for the given file. As far as possible, this circuit
|
145 |
|
|
-- computes exactly the same value computed by the compiler, but it does
|
146 |
|
|
-- not matter if it gets it wrong in marginal cases, since the only result
|
147 |
|
|
-- is to miss some smart recompilation cases, correct functioning is not
|
148 |
|
|
-- affected by a miscomputation. Returns Checksum_Error if the file is
|
149 |
|
|
-- missing or has an error.
|
150 |
|
|
|
151 |
|
|
function Checksums_Match (Checksum1, Checksum2 : Word) return Boolean;
|
152 |
|
|
pragma Inline (Checksums_Match);
|
153 |
|
|
-- Returns True if Checksum1 and Checksum2 have the same value and are
|
154 |
|
|
-- not equal to Checksum_Error, returns False in all other cases. This
|
155 |
|
|
-- routine must always be used to compare for checksum equality, to
|
156 |
|
|
-- ensure that the case of Checksum_Error is handled properly.
|
157 |
|
|
|
158 |
|
|
end ALI.Util;
|