diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-19 22:05:47 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-19 22:05:47 +0000 |
commit | 3f3d7acbcfbeca95c98360a9c5170961d0f7ca3f (patch) | |
tree | 763a4f85cbae9ab0f6fbddf1c10351e7ec18e880 /llvm | |
parent | 96b02d1573895ec0dc71e1605d9b36e825c35987 (diff) | |
download | bcm5719-llvm-3f3d7acbcfbeca95c98360a9c5170961d0f7ca3f.tar.gz bcm5719-llvm-3f3d7acbcfbeca95c98360a9c5170961d0f7ca3f.zip |
Split parseAssembly into parseAssembly and parseAssemblyInto.
This should restore the functionality of parsing new code into an existing
module without the confusing interface.
llvm-svn: 216031
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/AsmParser/Parser.h | 15 | ||||
-rw-r--r-- | llvm/lib/AsmParser/Parser.cpp | 19 |
2 files changed, 26 insertions, 8 deletions
diff --git a/llvm/include/llvm/AsmParser/Parser.h b/llvm/include/llvm/AsmParser/Parser.h index ab440cc47c7..c362a177439 100644 --- a/llvm/include/llvm/AsmParser/Parser.h +++ b/llvm/include/llvm/AsmParser/Parser.h @@ -50,8 +50,7 @@ std::unique_ptr<Module> 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<Module> parseAssemblyString(StringRef AsmString, std::unique_ptr<Module> parseAssembly(std::unique_ptr<MemoryBuffer> 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<MemoryBuffer> F, Module &M, + SMDiagnostic &Err); + } // End llvm namespace #endif diff --git a/llvm/lib/AsmParser/Parser.cpp b/llvm/lib/AsmParser/Parser.cpp index 7c6598106ec..9bc9b241666 100644 --- a/llvm/lib/AsmParser/Parser.cpp +++ b/llvm/lib/AsmParser/Parser.cpp @@ -21,17 +21,24 @@ #include <system_error> using namespace llvm; -std::unique_ptr<Module> llvm::parseAssembly(std::unique_ptr<MemoryBuffer> F, - SMDiagnostic &Err, - LLVMContext &Context) { +bool llvm::parseAssemblyInto(std::unique_ptr<MemoryBuffer> 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<Module> llvm::parseAssembly(std::unique_ptr<MemoryBuffer> F, + SMDiagnostic &Err, + LLVMContext &Context) { std::unique_ptr<Module> M = - make_unique<Module>(Buf->getBufferIdentifier(), Context); - if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run()) + make_unique<Module>(F->getBufferIdentifier(), Context); + + if (parseAssemblyInto(std::move(F), *M, Err)) return nullptr; + return std::move(M); } |