diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-26 21:49:01 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-26 21:49:01 +0000 |
commit | d96d553d76b56496e73aa30910d81f0d692f36fc (patch) | |
tree | e88f2eeb131aca32e87c1a37891c47e89106a361 /llvm/lib/IRReader | |
parent | 59953f0dbea2678f1ad59ac75c871a888e3a9875 (diff) | |
download | llvm-d96d553d76b56496e73aa30910d81f0d692f36fc.zip llvm-d96d553d76b56496e73aa30910d81f0d692f36fc.tar.gz llvm-d96d553d76b56496e73aa30910d81f0d692f36fc.tar.bz2 |
Pass a MemoryBufferRef when we can avoid taking ownership.
The attached patch simplifies a few interfaces that don't need to take
ownership of a buffer.
For example, both parseAssembly and parseBitcodeFile will parse the
entire buffer before returning. There is no need to take ownership.
Using a MemoryBufferRef makes it obvious in the type signature that
there is no ownership transfer.
llvm-svn: 216488
Diffstat (limited to 'llvm/lib/IRReader')
-rw-r--r-- | llvm/lib/IRReader/IRReader.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp index 259b41a..5c31248 100644 --- a/llvm/lib/IRReader/IRReader.cpp +++ b/llvm/lib/IRReader/IRReader.cpp @@ -46,7 +46,7 @@ getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer, SMDiagnostic &Err, return std::unique_ptr<Module>(ModuleOrErr.get()); } - return parseAssembly(std::move(Buffer), Err, Context); + return parseAssembly(Buffer->getMemBufferRef(), Err, Context); } std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename, @@ -63,24 +63,22 @@ std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename, return getLazyIRModule(std::move(FileOrErr.get()), Err, Context); } -std::unique_ptr<Module> llvm::parseIR(MemoryBuffer *Buffer, SMDiagnostic &Err, +std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context) { NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, TimePassesIsEnabled); - if (isBitcode((const unsigned char *)Buffer->getBufferStart(), - (const unsigned char *)Buffer->getBufferEnd())) { + if (isBitcode((const unsigned char *)Buffer.getBufferStart(), + (const unsigned char *)Buffer.getBufferEnd())) { ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context); if (std::error_code EC = ModuleOrErr.getError()) { - Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, EC.message()); return nullptr; } return std::unique_ptr<Module>(ModuleOrErr.get()); } - return parseAssembly(std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer( - Buffer->getBuffer(), Buffer->getBufferIdentifier())), - Err, Context); + return parseAssembly(Buffer, Err, Context); } std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, @@ -93,7 +91,7 @@ std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, return nullptr; } - return parseIR(FileOrErr.get().get(), Err, Context); + return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context); } //===----------------------------------------------------------------------===// @@ -106,7 +104,8 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, SMDiagnostic Diag; std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf)); - *OutM = wrap(parseIR(MB.get(), Diag, *unwrap(ContextRef)).release()); + *OutM = + wrap(parseIR(MB->getMemBufferRef(), Diag, *unwrap(ContextRef)).release()); if(!*OutM) { if (OutMessage) { |