[NFC] Reordering parameters in getFile and getFileOrSTDIN
In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used.
```
static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFile(const Twine &Filename, bool IsText = false,
bool RequiresNullTerminator = true, bool IsVolatile = false);
static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileOrSTDIN(const Twine &Filename, bool IsText = false,
bool RequiresNullTerminator = true);
static ErrorOr<std::unique_ptr<MB>>
getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
bool IsText, bool RequiresNullTerminator, bool IsVolatile);
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
getFile(const Twine &Filename, bool IsVolatile = false);
```
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D99182
GitOrigin-RevId: c83cd8feef7eb8319131d968bb8c94fdc8dbb6a6
diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp
index c5c8d5c..cf96ecb 100644
--- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -157,9 +157,8 @@
auto strategy = std::launch::deferred;
#endif
return std::async(strategy, [=]() {
- auto mbOrErr = MemoryBuffer::getFile(path,
- /*FileSize*/ -1,
- /*RequiresNullTerminator*/ false);
+ auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false);
if (!mbOrErr)
return MBErrPair{nullptr, mbOrErr.getError()};
return MBErrPair{std::move(*mbOrErr), std::error_code()};
@@ -829,7 +828,7 @@
// If the import library already exists, replace it only if the contents
// have changed.
ErrorOr<std::unique_ptr<MemoryBuffer>> oldBuf = MemoryBuffer::getFile(
- path, /*FileSize*/ -1, /*RequiresNullTerminator*/ false);
+ path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
if (!oldBuf) {
handleError(writeImportLibrary(libName, path, exports, config->machine,
config->mingw));
@@ -849,7 +848,7 @@
}
std::unique_ptr<MemoryBuffer> newBuf = check(MemoryBuffer::getFile(
- tmpName, /*FileSize*/ -1, /*RequiresNullTerminator*/ false));
+ tmpName, /*IsText=*/false, /*RequiresNullTerminator=*/false));
if ((*oldBuf)->getBuffer() != newBuf->getBuffer()) {
oldBuf->reset();
handleError(errorCodeToError(sys::fs::rename(tmpName, path)));
@@ -859,8 +858,11 @@
}
static void parseModuleDefs(StringRef path) {
- std::unique_ptr<MemoryBuffer> mb = CHECK(
- MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
+ std::unique_ptr<MemoryBuffer> mb =
+ CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false,
+ /*IsVolatile=*/true),
+ "could not open " + path);
COFFModuleDefinition m = check(parseCOFFModuleDefinition(
mb->getMemBufferRef(), config->machine, config->mingw));
@@ -948,8 +950,11 @@
// Open a file.
StringRef path = arg.substr(1);
- std::unique_ptr<MemoryBuffer> mb = CHECK(
- MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
+ std::unique_ptr<MemoryBuffer> mb =
+ CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false,
+ /*IsVolatile=*/true),
+ "could not open " + path);
// Parse a file. An order file contains one symbol per line.
// All symbols that were not present in a given order file are
@@ -973,8 +978,11 @@
}
static void parseCallGraphFile(StringRef path) {
- std::unique_ptr<MemoryBuffer> mb = CHECK(
- MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
+ std::unique_ptr<MemoryBuffer> mb =
+ CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false,
+ /*IsVolatile=*/true),
+ "could not open " + path);
// Build a map from symbol name to section.
DenseMap<StringRef, Symbol *> map;
diff --git a/COFF/DriverUtils.cpp b/COFF/DriverUtils.cpp
index 1996442..1e8cbe8 100644
--- a/COFF/DriverUtils.cpp
+++ b/COFF/DriverUtils.cpp
@@ -350,7 +350,7 @@
// is called (you cannot remove an opened file on Windows.)
std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
// IsVolatile=true forces MemoryBuffer to not use mmap().
- return CHECK(MemoryBuffer::getFile(path, /*FileSize=*/-1,
+ return CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
/*RequiresNullTerminator=*/false,
/*IsVolatile=*/true),
"could not open " + path);
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 6cf668d..1f1ff22 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -115,7 +115,8 @@
log(path);
config->dependencyFiles.insert(llvm::CachedHashString(path));
- auto mbOrErr = MemoryBuffer::getFile(path, -1, false);
+ auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
+ /*RequiresNullTerminator=*/false);
if (auto ec = mbOrErr.getError()) {
error("cannot open " + path + ": " + ec.message());
return None;