[Reproducer] Add LoadBuffer<> helper (NFC)

Introduce a helper method named LoadBuffer in the Loader to abstract
reading a reproducer file from disk.

llvm-svn: 375060
This commit is contained in:
Jonas Devlieghere
2019-10-17 00:01:57 +00:00
parent 27ef81cd48
commit b2575da9aa
2 changed files with 13 additions and 11 deletions

View File

@@ -265,19 +265,12 @@ protected:
return true;
}
case eReproducerProviderVersion: {
FileSpec version_file = loader->GetFile<VersionProvider::Info>();
// Load the version info into a buffer.
ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
vfs::getRealFileSystem()->getBufferForFile(version_file.GetPath());
if (!buffer) {
SetError(result, errorCodeToError(buffer.getError()));
Expected<std::string> version = loader->LoadBuffer<VersionProvider>();
if (!version) {
SetError(result, version.takeError());
return false;
}
// Return the version string.
StringRef version = (*buffer)->getBuffer();
result.AppendMessage(version.str());
result.AppendMessage(*version);
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}