@@ -41,9 +41,13 @@ getMachOFatMemoryBuffers(StringRef Filename, MemoryBuffer &Mem,
41
41
return Buffers;
42
42
}
43
43
44
+ BinaryHolder::BinaryHolder (IntrusiveRefCntPtr<vfs::FileSystem> VFS,
45
+ BinaryHolder::Options Opts)
46
+ : VFS(VFS), Opts(Opts) {}
47
+
44
48
Error BinaryHolder::ArchiveEntry::load (IntrusiveRefCntPtr<vfs::FileSystem> VFS,
45
49
StringRef Filename,
46
- TimestampTy Timestamp, bool Verbose ) {
50
+ TimestampTy Timestamp, Options Opts ) {
47
51
StringRef ArchiveFilename = getArchiveAndObjectName (Filename).first ;
48
52
49
53
// Try to load archive and force it to be memory mapped.
@@ -55,7 +59,7 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
55
59
56
60
MemBuffer = std::move (*ErrOrBuff);
57
61
58
- if (Verbose)
62
+ if (Opts. Verbose )
59
63
WithColor::note () << " loaded archive '" << ArchiveFilename << " '\n " ;
60
64
61
65
// Load one or more archive buffers, depending on whether we're dealing with
@@ -88,15 +92,15 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
88
92
89
93
Error BinaryHolder::ObjectEntry::load (IntrusiveRefCntPtr<vfs::FileSystem> VFS,
90
94
StringRef Filename, TimestampTy Timestamp,
91
- bool Verbose ) {
95
+ Options Opts ) {
92
96
// Try to load regular binary and force it to be memory mapped.
93
97
auto ErrOrBuff = (Filename == " -" )
94
98
? MemoryBuffer::getSTDIN ()
95
99
: VFS->getBufferForFile (Filename, -1 , false );
96
100
if (auto Err = ErrOrBuff.getError ())
97
101
return errorCodeToError (Err);
98
102
99
- if (Filename != " -" && Timestamp != sys::TimePoint<>()) {
103
+ if (Opts. Warn && Filename != " -" && Timestamp != sys::TimePoint<>()) {
100
104
llvm::ErrorOr<vfs::Status> Stat = VFS->status (Filename);
101
105
if (!Stat)
102
106
return errorCodeToError (Stat.getError ());
@@ -110,7 +114,7 @@ Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
110
114
111
115
MemBuffer = std::move (*ErrOrBuff);
112
116
113
- if (Verbose)
117
+ if (Opts. Verbose )
114
118
WithColor::note () << " loaded object.\n " ;
115
119
116
120
// Load one or more object buffers, depending on whether we're dealing with a
@@ -164,7 +168,7 @@ BinaryHolder::ObjectEntry::getObject(const Triple &T) const {
164
168
Expected<const BinaryHolder::ObjectEntry &>
165
169
BinaryHolder::ArchiveEntry::getObjectEntry (StringRef Filename,
166
170
TimestampTy Timestamp,
167
- bool Verbose ) {
171
+ Options Opts ) {
168
172
StringRef ArchiveFilename;
169
173
StringRef ObjectFilename;
170
174
std::tie (ArchiveFilename, ObjectFilename) = getArchiveAndObjectName (Filename);
@@ -192,7 +196,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
192
196
if (Timestamp != sys::TimePoint<>() &&
193
197
Timestamp != std::chrono::time_point_cast<std::chrono::seconds>(
194
198
ModTimeOrErr.get ())) {
195
- if (Verbose)
199
+ if (Opts. Verbose )
196
200
WithColor::warning ()
197
201
<< *NameOrErr
198
202
<< " : timestamp mismatch between archive member ("
@@ -201,7 +205,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
201
205
continue ;
202
206
}
203
207
204
- if (Verbose)
208
+ if (Opts. Verbose )
205
209
WithColor::note () << " found member in archive.\n " ;
206
210
207
211
auto ErrOrMem = Child.getMemoryBufferRef ();
@@ -230,7 +234,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
230
234
231
235
Expected<const BinaryHolder::ObjectEntry &>
232
236
BinaryHolder::getObjectEntry (StringRef Filename, TimestampTy Timestamp) {
233
- if (Verbose)
237
+ if (Opts. Verbose )
234
238
WithColor::note () << " trying to open '" << Filename << " '\n " ;
235
239
236
240
// If this is an archive, we might have either the object or the archive
@@ -241,17 +245,17 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
241
245
ArchiveRefCounter[ArchiveFilename]++;
242
246
if (ArchiveCache.count (ArchiveFilename)) {
243
247
return ArchiveCache[ArchiveFilename]->getObjectEntry (Filename, Timestamp,
244
- Verbose );
248
+ Opts );
245
249
} else {
246
250
auto AE = std::make_unique<ArchiveEntry>();
247
- auto Err = AE->load (VFS, Filename, Timestamp, Verbose );
251
+ auto Err = AE->load (VFS, Filename, Timestamp, Opts );
248
252
if (Err) {
249
253
// Don't return the error here: maybe the file wasn't an archive.
250
254
llvm::consumeError (std::move (Err));
251
255
} else {
252
256
ArchiveCache[ArchiveFilename] = std::move (AE);
253
- return ArchiveCache[ArchiveFilename]->getObjectEntry (
254
- Filename, Timestamp, Verbose );
257
+ return ArchiveCache[ArchiveFilename]->getObjectEntry (Filename,
258
+ Timestamp, Opts );
255
259
}
256
260
}
257
261
}
@@ -262,7 +266,7 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
262
266
ObjectRefCounter[Filename]++;
263
267
if (!ObjectCache.count (Filename)) {
264
268
auto OE = std::make_unique<ObjectEntry>();
265
- auto Err = OE->load (VFS, Filename, Timestamp, Verbose );
269
+ auto Err = OE->load (VFS, Filename, Timestamp, Opts );
266
270
if (Err)
267
271
return std::move (Err);
268
272
ObjectCache[Filename] = std::move (OE);
@@ -279,7 +283,7 @@ void BinaryHolder::clear() {
279
283
}
280
284
281
285
void BinaryHolder::eraseObjectEntry (StringRef Filename) {
282
- if (Verbose)
286
+ if (Opts. Verbose )
283
287
WithColor::note () << " erasing '" << Filename << " ' from cache\n " ;
284
288
285
289
if (isArchive (Filename)) {
0 commit comments