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