Debian Codegraph @

gcc/m2/gm2-compiler/ObjectFiles.mod

raw
1 (* ObjectFiles.mod determines whether object files exist.
2
3 Copyright (C) 2018-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
21
22 IMPLEMENTATION MODULE ObjectFiles ;
23
24 FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
25 FROM DynamicStrings IMPORT Dup, Mark, string ;
26 FROM Indexing IMPORT Index, InitIndex, KillIndex, GetIndice, PutIndice,
27 HighIndice, LowIndice, InBounds, IsIndiceInIndex,
28 RemoveIndiceFromIndex, IncludeIndiceIntoIndex,
29 ForeachIndiceInIndexDo ;
30
31 FROM wrapc IMPORT fileinode ;
32 FROM libc IMPORT open, close ;
33 FROM M2Printf IMPORT fprintf1, fprintf0 ;
34 FROM FIO IMPORT StdErr ;
35 FROM Assertion IMPORT Assert ;
36
37
38 CONST
39 UNIXREADONLY = 0 ;
40 Debugging = FALSE ;
41
42 TYPE
43 FileObject = POINTER TO RECORD
44 name : String ;
45 inodeLow, inodeHigh: CARDINAL ;
46 END ;
47
48 FileObjects = POINTER TO RECORD
49 objects: Index ;
50 END ;
51
52
53 (*
54 RegisterModuleObject - returns TRUE if location has not already been registered.
55 *)
56
57 PROCEDURE RegisterModuleObject (fo: FileObjects; location: String) : BOOLEAN ;
58 VAR
59 p: FileObject ;
60 f: INTEGER ;
61 BEGIN
62 IF Debugging
63 THEN
64 fprintf1 (StdErr, "first time file %s has been registered... ", location)
65 END ;
66 IF NOT IsRegistered (fo, location)
67 THEN
68 NEW (p) ;
69 p^.name := Dup (location) ;
70 f := open (string (location), UNIXREADONLY, 0) ;
71 IF fileinode (f, p^.inodeLow, p^.inodeHigh) = 0
72 THEN
73 close (f) ;
74 IncludeIndiceIntoIndex (fo^.objects, p) ;
75 IF Debugging
76 THEN
77 fprintf0 (StdErr, " yes\n")
78 END ;
79 RETURN TRUE
80 ELSE
81 IF Debugging
82 THEN
83 fprintf0 (StdErr, " fileinode failed\n")
84 END
85 END ;
86 close (f) ;
87 DISPOSE (p)
88 END ;
89 IF Debugging
90 THEN
91 fprintf0 (StdErr, " no\n")
92 END ;
93 RETURN FALSE
94 END RegisterModuleObject ;
95
96
97 (*
98 isRegistered -
99 *)
100
101 PROCEDURE isRegistered (fo: FileObjects; f: INTEGER) : BOOLEAN ;
102 VAR
103 i, h,
104 low, high: CARDINAL ;
105 o : FileObject ;
106 BEGIN
107 IF fileinode (f, low, high) = 0
108 THEN
109 h := HighIndice (fo^.objects) ;
110 i := 1 ;
111 WHILE i <= h DO
112 o := GetIndice (fo^.objects, i) ;
113 IF o # NIL
114 THEN
115 IF (o^.inodeLow = low) AND (o^.inodeHigh = high)
116 THEN
117 RETURN TRUE
118 END
119 END ;
120 INC (i)
121 END
122 END ;
123 RETURN FALSE
124 END isRegistered ;
125
126
127 (*
128 IsRegistered - returns TRUE if the object at, location, is already registered.
129 It uses the physical location on the filesystem to determine the
130 uniqueness of the object file.
131 *)
132
133 PROCEDURE IsRegistered (fo: FileObjects; location: String) : BOOLEAN ;
134 VAR
135 f : INTEGER ;
136 result: BOOLEAN ;
137 BEGIN
138 f := open (string (location), UNIXREADONLY, 0) ;
139 result := isRegistered (fo, f) ;
140 close (f) ;
141 RETURN result
142 END IsRegistered ;
143
144
145 (*
146 InitFileObject - returns a new file object container.
147 *)
148
149 PROCEDURE InitFileObject () : FileObjects ;
150 VAR
151 fo: FileObjects ;
152 BEGIN
153 NEW (fo) ;
154 fo^.objects := InitIndex (1) ;
155 RETURN fo
156 END InitFileObject ;
157
158
159 (*
160 KillFileObject - destroys a file object container.
161 *)
162
163 PROCEDURE KillFileObject (fo: FileObjects) : FileObjects ;
164 BEGIN
165 fo^.objects := KillIndex (fo^.objects) ;
166 DISPOSE (fo) ;
167 RETURN NIL
168 END KillFileObject ;
169
170
171 END ObjectFiles.