Update for llvm api change.

llvm-svn: 212407
This commit is contained in:
Rafael Espindola 2014-07-06 17:43:22 +00:00
parent 43f0aa6caf
commit c2199ecf1e
8 changed files with 38 additions and 29 deletions

View File

@ -40,11 +40,12 @@ public:
return make_error_code(llvm::errc::no_such_file_or_directory);
// Create a memory buffer
std::unique_ptr<MemoryBuffer> mb;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, mb))
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFileOrSTDIN(*filePath);
if (std::error_code ec = mb.getError())
return ec;
_buffer = std::move(mb);
_buffer = std::move(mb.get());
return ctx.registry().parseFile(_buffer, _files);
}

View File

@ -86,10 +86,11 @@ void InputGraph::normalize() {
/// \brief Read the file into _buffer.
std::error_code FileNode::getBuffer(StringRef filePath) {
// Create a memory buffer
std::unique_ptr<MemoryBuffer> mb;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, mb))
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFileOrSTDIN(filePath);
if (std::error_code ec = mb.getError())
return ec;
_buffer = std::move(mb);
_buffer = std::move(mb.get());
return std::error_code();
}

View File

@ -251,12 +251,12 @@ static bool parseSection(StringRef option, std::string &section,
static bool readFile(PECOFFLinkingContext &ctx, StringRef path,
ArrayRef<uint8_t> &result) {
std::unique_ptr<MemoryBuffer> buf;
if (MemoryBuffer::getFile(path, buf))
ErrorOr<std::unique_ptr<MemoryBuffer>> buf = MemoryBuffer::getFile(path);
if (!buf)
return false;
StringRef Data = buf.get()->getBuffer();
result = ctx.allocate(ArrayRef<uint8_t>(
reinterpret_cast<const uint8_t *>(buf->getBufferStart()),
buf->getBufferSize()));
reinterpret_cast<const uint8_t *>(Data.begin()), Data.size()));
return true;
}
@ -353,10 +353,10 @@ static bool parseExport(StringRef option,
// Read module-definition file.
static bool parseDef(StringRef option, llvm::BumpPtrAllocator &alloc,
std::vector<moduledef::Directive *> &result) {
std::unique_ptr<MemoryBuffer> buf;
if (MemoryBuffer::getFile(option, buf))
ErrorOr<std::unique_ptr<MemoryBuffer>> buf = MemoryBuffer::getFile(option);
if (!buf)
return llvm::None;
moduledef::Lexer lexer(std::move(buf));
moduledef::Lexer lexer(std::move(buf.get()));
moduledef::Parser parser(lexer, alloc);
return parser.parse(result);
}

View File

@ -37,11 +37,12 @@ void RoundTripNativePass::perform(std::unique_ptr<MutableFile> &mergedFile) {
// The file that is written would be kept around if there is a problem
// writing to the file or when reading atoms back from the file.
nativeWriter->writeFile(*mergedFile, tmpNativeFile.str());
std::unique_ptr<MemoryBuffer> mb;
if (MemoryBuffer::getFile(tmpNativeFile.str(), mb))
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFile(tmpNativeFile.str());
if (!mb)
return;
std::error_code ec = _context.registry().parseFile(mb, _nativeFile);
std::error_code ec = _context.registry().parseFile(mb.get(), _nativeFile);
if (ec) {
// Note: we need a way for Passes to report errors.
llvm_unreachable("native reader not registered or read error");

View File

@ -37,11 +37,12 @@ void RoundTripYAMLPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
// The file that is written would be kept around if there is a problem
// writing to the file or when reading atoms back from the file.
yamlWriter->writeFile(*mergedFile, tmpYAMLFile.str());
std::unique_ptr<MemoryBuffer> mb;
if (MemoryBuffer::getFile(tmpYAMLFile.str(), mb))
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFile(tmpYAMLFile.str());
if (!mb)
return;
std::error_code ec = _context.registry().parseFile(mb, _yamlFile);
std::error_code ec = _context.registry().parseFile(mb.get(), _yamlFile);
if (ec) {
// Note: we need a way for Passes to report errors.
llvm_unreachable("yaml reader not registered or read error");

View File

@ -958,11 +958,12 @@ public:
llvm::FileRemover coffFileRemover(*coffPath);
// Read and parse the COFF
std::unique_ptr<MemoryBuffer> newmb;
if (std::error_code ec = MemoryBuffer::getFile(*coffPath, newmb))
ErrorOr<std::unique_ptr<MemoryBuffer>> newmb =
MemoryBuffer::getFile(*coffPath);
if (std::error_code ec = newmb.getError())
return ec;
std::error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(newmb), ec));
std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(newmb.get()), ec));
if (ec)
return ec;
if (std::error_code ec = file->parse())

View File

@ -30,8 +30,10 @@ using namespace lld::mach_o::normalized;
// Normalized file to nf parameter.
static void fromBinary(StringRef path, std::unique_ptr<MemoryBuffer> &mb,
std::unique_ptr<NormalizedFile> &nf, StringRef archStr) {
std::error_code ec = MemoryBuffer::getFile(path, mb);
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
std::error_code ec = mbOrErr.getError();
EXPECT_FALSE(ec);
mb = std::move(mbOrErr.get());
ErrorOr<std::unique_ptr<NormalizedFile>> r =
lld::mach_o::normalized::readBinary(

View File

@ -26,12 +26,13 @@ int main(int argc, const char **argv) {
llvm::PrettyStackTraceProgram X(argc, argv);
{
std::unique_ptr<MemoryBuffer> mb;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) {
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFileOrSTDIN(argv[1]);
if (std::error_code ec = mb.getError()) {
llvm::errs() << ec.message() << "\n";
return 1;
}
Lexer l(std::move(mb));
Lexer l(std::move(mb.get()));
Token tok;
while (true) {
l.lex(tok);
@ -41,12 +42,13 @@ int main(int argc, const char **argv) {
}
}
{
std::unique_ptr<MemoryBuffer> mb;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) {
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFileOrSTDIN(argv[1]);
if (std::error_code ec = mb.getError()) {
llvm::errs() << ec.message() << "\n";
return 1;
}
Lexer l(std::move(mb));
Lexer l(std::move(mb.get()));
Parser p(l);
LinkerScript *ls = p.parse();
if (ls)