[llvm] r215852 - Pass a std::uinque_ptr to ParseAssembly to make the ownership explicit. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Sun Aug 17 14:36:48 PDT 2014
Author: rafael
Date: Sun Aug 17 16:36:47 2014
New Revision: 215852
URL: http://llvm.org/viewvc/llvm-project?rev=215852&view=rev
Log:
Pass a std::uinque_ptr to ParseAssembly to make the ownership explicit. NFC.
Modified:
llvm/trunk/include/llvm/AsmParser/Parser.h
llvm/trunk/lib/AsmParser/Parser.cpp
llvm/trunk/lib/IRReader/IRReader.cpp
Modified: llvm/trunk/include/llvm/AsmParser/Parser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/AsmParser/Parser.h?rev=215852&r1=215851&r2=215852&view=diff
==============================================================================
--- llvm/trunk/include/llvm/AsmParser/Parser.h (original)
+++ llvm/trunk/include/llvm/AsmParser/Parser.h Sun Aug 17 16:36:47 2014
@@ -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
Modified: llvm/trunk/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/Parser.cpp?rev=215852&r1=215851&r2=215852&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/Parser.cpp (original)
+++ llvm/trunk/lib/AsmParser/Parser.cpp Sun Aug 17 16:36:47 2014
@@ -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 st
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
MemoryBuffer *F =
MemoryBuffer::getMemBuffer(StringRef(AsmString), "<string>");
- return ParseAssembly(F, M, Err, Context);
+ return ParseAssembly(std::unique_ptr<MemoryBuffer>(F), M, Err, Context);
}
Modified: llvm/trunk/lib/IRReader/IRReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IRReader/IRReader.cpp?rev=215852&r1=215851&r2=215852&view=diff
==============================================================================
--- llvm/trunk/lib/IRReader/IRReader.cpp (original)
+++ llvm/trunk/lib/IRReader/IRReader.cpp Sun Aug 17 16:36:47 2014
@@ -45,7 +45,7 @@ static Module *getLazyIRModule(std::uniq
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 *Buff
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);
}
More information about the llvm-commits
mailing list