Update for llvm api change.

llvm-svn: 212408
This commit is contained in:
Rafael Espindola 2014-07-06 17:43:24 +00:00
parent c2199ecf1e
commit 2d2b420ab9
14 changed files with 79 additions and 53 deletions

View File

@ -65,12 +65,13 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
std::vector<std::pair<const FileEntry *, const FileEntry *> > pairs; std::vector<std::pair<const FileEntry *, const FileEntry *> > pairs;
std::unique_ptr<llvm::MemoryBuffer> fileBuf; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
if (llvm::MemoryBuffer::getFile(infoFile.c_str(), fileBuf)) llvm::MemoryBuffer::getFile(infoFile.c_str());
if (!fileBuf)
return report("Error opening file: " + infoFile, Diag); return report("Error opening file: " + infoFile, Diag);
SmallVector<StringRef, 64> lines; SmallVector<StringRef, 64> lines;
fileBuf->getBuffer().split(lines, "\n"); fileBuf.get()->getBuffer().split(lines, "\n");
for (unsigned idx = 0; idx+3 <= lines.size(); idx += 3) { for (unsigned idx = 0; idx+3 <= lines.size(); idx += 3) {
StringRef fromFilename = lines[idx]; StringRef fromFilename = lines[idx];

View File

@ -1943,12 +1943,13 @@ public:
bool parse(StringRef File, SmallVectorImpl<EditEntry> &Entries) { bool parse(StringRef File, SmallVectorImpl<EditEntry> &Entries) {
using namespace llvm::yaml; using namespace llvm::yaml;
std::unique_ptr<llvm::MemoryBuffer> FileBuf; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
if (llvm::MemoryBuffer::getFile(File, FileBuf)) llvm::MemoryBuffer::getFile(File);
if (!FileBufOrErr)
return true; return true;
llvm::SourceMgr SM; llvm::SourceMgr SM;
Stream YAMLStream(FileBuf.release(), SM); Stream YAMLStream(FileBufOrErr.get().release(), SM);
document_iterator I = YAMLStream.begin(); document_iterator I = YAMLStream.begin();
if (I == YAMLStream.end()) if (I == YAMLStream.end())
return true; return true;

View File

@ -126,8 +126,13 @@ std::error_code RealFile::getBuffer(const Twine &Name,
bool RequiresNullTerminator, bool RequiresNullTerminator,
bool IsVolatile) { bool IsVolatile) {
assert(FD != -1 && "cannot get buffer for closed file"); assert(FD != -1 && "cannot get buffer for closed file");
return MemoryBuffer::getOpenFile(FD, Name.str().c_str(), Result, FileSize, ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getOpenFile(FD, Name.str().c_str(), FileSize,
RequiresNullTerminator, IsVolatile); RequiresNullTerminator, IsVolatile);
if (std::error_code EC = BufferOrErr.getError())
return EC;
Result = std::move(BufferOrErr.get());
return std::error_code();
} }
// FIXME: This is terrible, we need this for ::close. // FIXME: This is terrible, we need this for ::close.

View File

@ -2794,8 +2794,9 @@ static bool IsUbuntu(enum Distro Distro) {
} }
static Distro DetectDistro(llvm::Triple::ArchType Arch) { static Distro DetectDistro(llvm::Triple::ArchType Arch) {
std::unique_ptr<llvm::MemoryBuffer> File; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
if (!llvm::MemoryBuffer::getFile("/etc/lsb-release", File)) { llvm::MemoryBuffer::getFile("/etc/lsb-release");
if (File) {
StringRef Data = File.get()->getBuffer(); StringRef Data = File.get()->getBuffer();
SmallVector<StringRef, 8> Lines; SmallVector<StringRef, 8> Lines;
Data.split(Lines, "\n"); Data.split(Lines, "\n");
@ -2820,7 +2821,8 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
return Version; return Version;
} }
if (!llvm::MemoryBuffer::getFile("/etc/redhat-release", File)) { File = llvm::MemoryBuffer::getFile("/etc/redhat-release");
if (File) {
StringRef Data = File.get()->getBuffer(); StringRef Data = File.get()->getBuffer();
if (Data.startswith("Fedora release")) if (Data.startswith("Fedora release"))
return Fedora; return Fedora;
@ -2836,7 +2838,8 @@ static Distro DetectDistro(llvm::Triple::ArchType Arch) {
return UnknownDistro; return UnknownDistro;
} }
if (!llvm::MemoryBuffer::getFile("/etc/debian_version", File)) { File = llvm::MemoryBuffer::getFile("/etc/debian_version");
if (File) {
StringRef Data = File.get()->getBuffer(); StringRef Data = File.get()->getBuffer();
if (Data[0] == '5') if (Data[0] == '5')
return DebianLenny; return DebianLenny;

View File

@ -2082,13 +2082,14 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName,
} }
if (IsFile) { if (IsFile) {
std::unique_ptr<llvm::MemoryBuffer> Text; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
if (std::error_code ec = llvm::MemoryBuffer::getFile(ConfigFile.c_str());
llvm::MemoryBuffer::getFile(ConfigFile.c_str(), Text)) { if (std::error_code EC = Text.getError()) {
llvm::errs() << ec.message() << "\n"; llvm::errs() << EC.message() << "\n";
break; break;
} }
if (std::error_code ec = parseConfiguration(Text->getBuffer(), &Style)) { if (std::error_code ec =
parseConfiguration(Text.get()->getBuffer(), &Style)) {
if (ec == ParseError::Unsuitable) { if (ec == ParseError::Unsuitable) {
if (!UnsuitableConfigFiles.empty()) if (!UnsuitableConfigFiles.empty())
UnsuitableConfigFiles.append(", "); UnsuitableConfigFiles.append(", ");

View File

@ -683,11 +683,14 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
SourceMgr.setMainFileID( SourceMgr.setMainFileID(
SourceMgr.createFileID(File, SourceLocation(), Kind)); SourceMgr.createFileID(File, SourceLocation(), Kind));
} else { } else {
std::unique_ptr<llvm::MemoryBuffer> SB; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr =
if (std::error_code ec = llvm::MemoryBuffer::getSTDIN(SB)) { llvm::MemoryBuffer::getSTDIN();
Diags.Report(diag::err_fe_error_reading_stdin) << ec.message(); if (std::error_code EC = SBOrErr.getError()) {
Diags.Report(diag::err_fe_error_reading_stdin) << EC.message();
return false; return false;
} }
std::unique_ptr<llvm::MemoryBuffer> SB = std::move(SBOrErr.get());
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0); SB->getBufferSize(), 0);
SourceMgr.setMainFileID( SourceMgr.setMainFileID(

View File

@ -1957,14 +1957,16 @@ std::string CompilerInvocation::getModuleHash() const {
// $sysroot/System/Library/CoreServices/SystemVersion.plist // $sysroot/System/Library/CoreServices/SystemVersion.plist
// as part of the module hash. // as part of the module hash.
if (!hsOpts.Sysroot.empty()) { if (!hsOpts.Sysroot.empty()) {
std::unique_ptr<llvm::MemoryBuffer> buffer;
SmallString<128> systemVersionFile; SmallString<128> systemVersionFile;
systemVersionFile += hsOpts.Sysroot; systemVersionFile += hsOpts.Sysroot;
llvm::sys::path::append(systemVersionFile, "System"); llvm::sys::path::append(systemVersionFile, "System");
llvm::sys::path::append(systemVersionFile, "Library"); llvm::sys::path::append(systemVersionFile, "Library");
llvm::sys::path::append(systemVersionFile, "CoreServices"); llvm::sys::path::append(systemVersionFile, "CoreServices");
llvm::sys::path::append(systemVersionFile, "SystemVersion.plist"); llvm::sys::path::append(systemVersionFile, "SystemVersion.plist");
if (!llvm::MemoryBuffer::getFile(systemVersionFile.str(), buffer)) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
llvm::MemoryBuffer::getFile(systemVersionFile.str());
if (buffer) {
code = hash_combine(code, buffer.get()->getBuffer()); code = hash_combine(code, buffer.get()->getBuffer());
struct stat statBuf; struct stat statBuf;
@ -2031,14 +2033,15 @@ createVFSFromCompilerInvocation(const CompilerInvocation &CI,
Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
// earlier vfs files are on the bottom // earlier vfs files are on the bottom
for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) { for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) {
std::unique_ptr<llvm::MemoryBuffer> Buffer; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
if (llvm::MemoryBuffer::getFile(File, Buffer)) { llvm::MemoryBuffer::getFile(File);
if (!Buffer) {
Diags.Report(diag::err_missing_vfs_overlay_file) << File; Diags.Report(diag::err_missing_vfs_overlay_file) << File;
return IntrusiveRefCntPtr<vfs::FileSystem>(); return IntrusiveRefCntPtr<vfs::FileSystem>();
} }
IntrusiveRefCntPtr<vfs::FileSystem> FS = IntrusiveRefCntPtr<vfs::FileSystem> FS =
vfs::getVFSFromYAML(Buffer.release(), /*DiagHandler*/nullptr); vfs::getVFSFromYAML(Buffer->release(), /*DiagHandler*/ nullptr);
if (!FS.get()) { if (!FS.get()) {
Diags.Report(diag::err_invalid_vfs_overlay) << File; Diags.Report(diag::err_invalid_vfs_overlay) << File;
return IntrusiveRefCntPtr<vfs::FileSystem>(); return IntrusiveRefCntPtr<vfs::FileSystem>();

View File

@ -440,13 +440,15 @@ static void InvalidPTH(DiagnosticsEngine &Diags, const char *Msg) {
PTHManager *PTHManager::Create(const std::string &file, PTHManager *PTHManager::Create(const std::string &file,
DiagnosticsEngine &Diags) { DiagnosticsEngine &Diags) {
// Memory map the PTH file. // Memory map the PTH file.
std::unique_ptr<llvm::MemoryBuffer> File; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
llvm::MemoryBuffer::getFile(file);
if (llvm::MemoryBuffer::getFile(file, File)) { if (!FileOrErr) {
// FIXME: Add ec.message() to this diag. // FIXME: Add ec.message() to this diag.
Diags.Report(diag::err_invalid_pth_file) << file; Diags.Report(diag::err_invalid_pth_file) << file;
return nullptr; return nullptr;
} }
std::unique_ptr<llvm::MemoryBuffer> File = std::move(FileOrErr.get());
using namespace llvm::support; using namespace llvm::support;

View File

@ -239,9 +239,11 @@ GlobalModuleIndex::readIndex(StringRef Path) {
IndexPath += Path; IndexPath += Path;
llvm::sys::path::append(IndexPath, IndexFileName); llvm::sys::path::append(IndexPath, IndexFileName);
std::unique_ptr<llvm::MemoryBuffer> Buffer; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrErr =
if (llvm::MemoryBuffer::getFile(IndexPath.c_str(), Buffer)) llvm::MemoryBuffer::getFile(IndexPath.c_str());
if (!BufferOrErr)
return std::make_pair(nullptr, EC_NotFound); return std::make_pair(nullptr, EC_NotFound);
std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrErr.get());
/// \brief The bitstream reader from which we'll read the AST file. /// \brief The bitstream reader from which we'll read the AST file.
llvm::BitstreamReader Reader((const unsigned char *)Buffer->getBufferStart(), llvm::BitstreamReader Reader((const unsigned char *)Buffer->getBufferStart(),

View File

@ -106,9 +106,13 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
// Open the AST file. // Open the AST file.
std::error_code ec; std::error_code ec;
if (FileName == "-") { if (FileName == "-") {
ec = llvm::MemoryBuffer::getSTDIN(New->Buffer); llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf =
llvm::MemoryBuffer::getSTDIN();
ec = Buf.getError();
if (ec) if (ec)
ErrorStr = ec.message(); ErrorStr = ec.message();
else
New->Buffer = std::move(Buf.get());
} else { } else {
// Leave the FileEntry open so if it gets read again by another // Leave the FileEntry open so if it gets read again by another
// ModuleManager it must be the same underlying file. // ModuleManager it must be the same underlying file.

View File

@ -144,15 +144,14 @@ volatile int JSONAnchorSource = 0;
JSONCompilationDatabase * JSONCompilationDatabase *
JSONCompilationDatabase::loadFromFile(StringRef FilePath, JSONCompilationDatabase::loadFromFile(StringRef FilePath,
std::string &ErrorMessage) { std::string &ErrorMessage) {
std::unique_ptr<llvm::MemoryBuffer> DatabaseBuffer; llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
std::error_code Result = llvm::MemoryBuffer::getFile(FilePath);
llvm::MemoryBuffer::getFile(FilePath, DatabaseBuffer); if (std::error_code Result = DatabaseBuffer.getError()) {
if (Result) {
ErrorMessage = "Error while opening JSON database: " + Result.message(); ErrorMessage = "Error while opening JSON database: " + Result.message();
return nullptr; return nullptr;
} }
std::unique_ptr<JSONCompilationDatabase> Database( std::unique_ptr<JSONCompilationDatabase> Database(
new JSONCompilationDatabase(DatabaseBuffer.release())); new JSONCompilationDatabase(DatabaseBuffer->release()));
if (!Database->parse(ErrorMessage)) if (!Database->parse(ErrorMessage))
return nullptr; return nullptr;
return Database.release(); return Database.release();

View File

@ -207,17 +207,15 @@ static bool performTransformations(StringRef resourcesPath,
static bool filesCompareEqual(StringRef fname1, StringRef fname2) { static bool filesCompareEqual(StringRef fname1, StringRef fname2) {
using namespace llvm; using namespace llvm;
std::unique_ptr<MemoryBuffer> file1; ErrorOr<std::unique_ptr<MemoryBuffer>> file1 = MemoryBuffer::getFile(fname1);
MemoryBuffer::getFile(fname1, file1);
if (!file1) if (!file1)
return false; return false;
std::unique_ptr<MemoryBuffer> file2; ErrorOr<std::unique_ptr<MemoryBuffer>> file2 = MemoryBuffer::getFile(fname2);
MemoryBuffer::getFile(fname2, file2);
if (!file2) if (!file2)
return false; return false;
return file1->getBuffer() == file2->getBuffer(); return file1.get()->getBuffer() == file2.get()->getBuffer();
} }
static bool verifyTransformedFiles(ArrayRef<std::string> resultFiles) { static bool verifyTransformedFiles(ArrayRef<std::string> resultFiles) {
@ -238,18 +236,19 @@ static bool verifyTransformedFiles(ArrayRef<std::string> resultFiles) {
resultMap[sys::path::stem(fname)] = fname; resultMap[sys::path::stem(fname)] = fname;
} }
std::unique_ptr<MemoryBuffer> inputBuf; ErrorOr<std::unique_ptr<MemoryBuffer>> inputBuf = std::error_code();
if (RemappingsFile.empty()) if (RemappingsFile.empty())
MemoryBuffer::getSTDIN(inputBuf); inputBuf = MemoryBuffer::getSTDIN();
else else
MemoryBuffer::getFile(RemappingsFile, inputBuf); inputBuf = MemoryBuffer::getFile(RemappingsFile);
if (!inputBuf) { if (!inputBuf) {
errs() << "error: could not read remappings input\n"; errs() << "error: could not read remappings input\n";
return true; return true;
} }
SmallVector<StringRef, 8> strs; SmallVector<StringRef, 8> strs;
inputBuf->getBuffer().split(strs, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); inputBuf.get()->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
if (strs.empty()) { if (strs.empty()) {
errs() << "error: no files to verify from stdin\n"; errs() << "error: no files to verify from stdin\n";

View File

@ -209,11 +209,13 @@ static bool format(StringRef FileName) {
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
new DiagnosticOptions); new DiagnosticOptions);
SourceManager Sources(Diagnostics, Files); SourceManager Sources(Diagnostics, Files);
std::unique_ptr<MemoryBuffer> Code; ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(FileName, Code)) { MemoryBuffer::getFileOrSTDIN(FileName);
llvm::errs() << ec.message() << "\n"; if (std::error_code EC = CodeOrErr.getError()) {
llvm::errs() << EC.message() << "\n";
return true; return true;
} }
std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get());
if (Code->getBufferSize() == 0) if (Code->getBufferSize() == 0)
return false; // Empty files are formatted correctly. return false; // Empty files are formatted correctly.
FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files); FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files);

View File

@ -281,17 +281,18 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
if (!TheTarget) if (!TheTarget)
return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;
std::unique_ptr<MemoryBuffer> Buffer; ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Opts.InputFile);
MemoryBuffer::getFileOrSTDIN(Opts.InputFile, Buffer)) {
Error = ec.message(); if (std::error_code EC = Buffer.getError()) {
Error = EC.message();
return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile; return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
} }
SourceMgr SrcMgr; SourceMgr SrcMgr;
// Tell SrcMgr about this buffer, which is what the parser will pick up. // Tell SrcMgr about this buffer, which is what the parser will pick up.
SrcMgr.AddNewSourceBuffer(Buffer.release(), SMLoc()); SrcMgr.AddNewSourceBuffer(Buffer->release(), SMLoc());
// Record the location of the include directories so that the lexer can find // Record the location of the include directories so that the lexer can find
// it later. // it later.