llvm.org GIT mirror llvm / 822199b
Pass a std::uinque_ptr to ParseAssembly to make the ownership explicit. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215852 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
3 changed file(s) with 18 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_ASMPARSER_PARSER_H
1414 #define LLVM_ASMPARSER_PARSER_H
1515
16 #include
1617 #include
1718
1819 namespace llvm {
4950
5051 /// This function is the low-level interface to the LLVM Assembly Parser.
5152 /// ParseAssemblyFile and ParseAssemblyString are wrappers around this function.
52 /// @brief Parse LLVM Assembly from a MemoryBuffer. This function *always*
53 /// takes ownership of the MemoryBuffer.
53 /// @brief Parse LLVM Assembly from a MemoryBuffer.
5454 Module *ParseAssembly(
55 MemoryBuffer *F, ///< The MemoryBuffer containing assembly
56 Module *M, ///< A module to add the assembly too.
57 SMDiagnostic &Err, ///< Error result info.
58 LLVMContext &Context
59 );
55 std::unique_ptr F, ///< The MemoryBuffer containing assembly
56 Module *M, ///< A module to add the assembly too.
57 SMDiagnostic &Err, ///< Error result info.
58 LLVMContext &Context);
6059
6160 } // End llvm namespace
6261
2020 #include
2121 using namespace llvm;
2222
23 Module *llvm::ParseAssembly(MemoryBuffer *F,
24 Module *M,
25 SMDiagnostic &Err,
26 LLVMContext &Context) {
23 Module *llvm::ParseAssembly(std::unique_ptr F, Module *M,
24 SMDiagnostic &Err, LLVMContext &Context) {
2725 SourceMgr SM;
28 SM.AddNewSourceBuffer(F, SMLoc());
26 MemoryBuffer *Buf = F.get();
27 SM.AddNewSourceBuffer(F.release(), SMLoc());
2928
3029 // If we are parsing into an existing module, do it.
3130 if (M)
32 return LLParser(F, SM, Err, M).Run() ? nullptr : M;
31 return LLParser(Buf, SM, Err, M).Run() ? nullptr : M;
3332
3433 // Otherwise create a new module.
35 std::unique_ptr M2(new Module(F->getBufferIdentifier(), Context));
36 if (LLParser(F, SM, Err, M2.get()).Run())
34 std::unique_ptr M2(new Module(Buf->getBufferIdentifier(), Context));
35 if (LLParser(Buf, SM, Err, M2.get()).Run())
3736 return nullptr;
3837 return M2.release();
3938 }
4847 return nullptr;
4948 }
5049
51 return ParseAssembly(FileOrErr.get().release(), nullptr, Err, Context);
50 return ParseAssembly(std::move(FileOrErr.get()), nullptr, Err, Context);
5251 }
5352
5453 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
5655 MemoryBuffer *F =
5756 MemoryBuffer::getMemBuffer(StringRef(AsmString), "");
5857
59 return ParseAssembly(F, M, Err, Context);
58 return ParseAssembly(std::unique_ptr(F), M, Err, Context);
6059 }
4444 return ModuleOrErr.get();
4545 }
4646
47 return ParseAssembly(Buffer.release(), nullptr, Err, Context);
47 return ParseAssembly(std::move(Buffer), nullptr, Err, Context);
4848 }
4949
5050 Module *llvm::getLazyIRFileModule(const std::string &Filename,
7777 return M;
7878 }
7979
80 return ParseAssembly(MemoryBuffer::getMemBuffer(
81 Buffer->getBuffer(), Buffer->getBufferIdentifier()),
80 return ParseAssembly(std::unique_ptr(MemoryBuffer::getMemBuffer(
81 Buffer->getBuffer(), Buffer->getBufferIdentifier())),
8282 nullptr, Err, Context);
8383 }
8484