Pass a std::uinque_ptr to ParseAssembly to make the ownership explicit. NFC.

llvm-svn: 215852
This commit is contained in:
Rafael Espindola 2014-08-17 21:36:47 +00:00
parent 23e76772b0
commit 164d599b63
3 changed files with 18 additions and 20 deletions

View File

@ -14,6 +14,7 @@
#ifndef LLVM_ASMPARSER_PARSER_H
#define LLVM_ASMPARSER_PARSER_H
#include <memory>
#include <string>
namespace llvm {
@ -50,14 +51,12 @@ Module *ParseAssemblyString(
/// This function is the low-level interface to the LLVM Assembly Parser.
/// ParseAssemblyFile and ParseAssemblyString are wrappers around this function.
/// @brief Parse LLVM Assembly from a MemoryBuffer. This function *always*
/// takes ownership of the MemoryBuffer.
/// @brief Parse LLVM Assembly from a MemoryBuffer.
Module *ParseAssembly(
MemoryBuffer *F, ///< The MemoryBuffer containing assembly
Module *M, ///< A module to add the assembly too.
SMDiagnostic &Err, ///< Error result info.
LLVMContext &Context
);
std::unique_ptr<MemoryBuffer> F, ///< The MemoryBuffer containing assembly
Module *M, ///< A module to add the assembly too.
SMDiagnostic &Err, ///< Error result info.
LLVMContext &Context);
} // End llvm namespace

View File

@ -21,20 +21,19 @@
#include <system_error>
using namespace llvm;
Module *llvm::ParseAssembly(MemoryBuffer *F,
Module *M,
SMDiagnostic &Err,
LLVMContext &Context) {
Module *llvm::ParseAssembly(std::unique_ptr<MemoryBuffer> F, Module *M,
SMDiagnostic &Err, LLVMContext &Context) {
SourceMgr SM;
SM.AddNewSourceBuffer(F, SMLoc());
MemoryBuffer *Buf = F.get();
SM.AddNewSourceBuffer(F.release(), SMLoc());
// If we are parsing into an existing module, do it.
if (M)
return LLParser(F, SM, Err, M).Run() ? nullptr : M;
return LLParser(Buf, SM, Err, M).Run() ? nullptr : M;
// Otherwise create a new module.
std::unique_ptr<Module> M2(new Module(F->getBufferIdentifier(), Context));
if (LLParser(F, SM, Err, M2.get()).Run())
std::unique_ptr<Module> M2(new Module(Buf->getBufferIdentifier(), Context));
if (LLParser(Buf, SM, Err, M2.get()).Run())
return nullptr;
return M2.release();
}
@ -49,7 +48,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
return nullptr;
}
return ParseAssembly(FileOrErr.get().release(), nullptr, Err, Context);
return ParseAssembly(std::move(FileOrErr.get()), nullptr, Err, Context);
}
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
@ -57,5 +56,5 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
MemoryBuffer *F =
MemoryBuffer::getMemBuffer(StringRef(AsmString), "<string>");
return ParseAssembly(F, M, Err, Context);
return ParseAssembly(std::unique_ptr<MemoryBuffer>(F), M, Err, Context);
}

View File

@ -45,7 +45,7 @@ static Module *getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer,
return ModuleOrErr.get();
}
return ParseAssembly(Buffer.release(), nullptr, Err, Context);
return ParseAssembly(std::move(Buffer), nullptr, Err, Context);
}
Module *llvm::getLazyIRFileModule(const std::string &Filename,
@ -78,8 +78,8 @@ Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
return M;
}
return ParseAssembly(MemoryBuffer::getMemBuffer(
Buffer->getBuffer(), Buffer->getBufferIdentifier()),
return ParseAssembly(std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer(
Buffer->getBuffer(), Buffer->getBufferIdentifier())),
nullptr, Err, Context);
}