From b12ab608fe80d5597090063ee3d72377d7560914 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 19 Aug 2014 22:05:47 +0000 Subject: [PATCH] Split parseAssembly into parseAssembly and parseAssemblyInto. This should restore the functionality of parsing new code into an existing module without the confusing interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216031 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/AsmParser/Parser.h | 15 +++++++++++++-- lib/AsmParser/Parser.cpp | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/llvm/AsmParser/Parser.h b/include/llvm/AsmParser/Parser.h index ab440cc47c7..c362a177439 100644 --- a/include/llvm/AsmParser/Parser.h +++ b/include/llvm/AsmParser/Parser.h @@ -50,8 +50,7 @@ std::unique_ptr parseAssemblyString(StringRef AsmString, SMDiagnostic &Error, LLVMContext &Context); -/// This function is the low-level interface to the LLVM Assembly Parser. -/// ParseAssemblyFile and ParseAssemblyString are wrappers around this function. +/// parseAssemblyFile and parseAssemblyString are wrappers around this function. /// @brief Parse LLVM Assembly from a MemoryBuffer. /// @param F The MemoryBuffer containing assembly /// @param Err Error result info. @@ -59,6 +58,18 @@ std::unique_ptr parseAssemblyString(StringRef AsmString, std::unique_ptr parseAssembly(std::unique_ptr F, SMDiagnostic &Err, LLVMContext &Context); +/// This function is the low-level interface to the LLVM Assembly Parser. +/// This is kept as an independent function instead of being inlined into +/// parseAssembly for the convenience of interactive users that want to add +/// recently parsed bits to an existing module. +/// +/// @param F The MemoryBuffer containing assembly +/// @param M The module to add data to. +/// @param Err Error result info. +/// @return true on error. +bool parseAssemblyInto(std::unique_ptr F, Module &M, + SMDiagnostic &Err); + } // End llvm namespace #endif diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 7c6598106ec..9bc9b241666 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,17 +21,24 @@ #include using namespace llvm; -std::unique_ptr llvm::parseAssembly(std::unique_ptr F, - SMDiagnostic &Err, - LLVMContext &Context) { +bool llvm::parseAssemblyInto(std::unique_ptr F, Module &M, + SMDiagnostic &Err) { SourceMgr SM; - MemoryBuffer *Buf = F.get(); + StringRef Buf = F->getBuffer(); SM.AddNewSourceBuffer(F.release(), SMLoc()); + return LLParser(Buf, SM, Err, &M).Run(); +} + +std::unique_ptr llvm::parseAssembly(std::unique_ptr F, + SMDiagnostic &Err, + LLVMContext &Context) { std::unique_ptr M = - make_unique(Buf->getBufferIdentifier(), Context); - if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run()) + make_unique(F->getBufferIdentifier(), Context); + + if (parseAssemblyInto(std::move(F), *M, Err)) return nullptr; + return std::move(M); } -- 2.34.1