[llvm] r216031 - Split parseAssembly into parseAssembly and parseAssemblyInto.

Rafael Espindola rafael.espindola at gmail.com
Tue Aug 19 15:05:48 PDT 2014


Author: rafael
Date: Tue Aug 19 17:05:47 2014
New Revision: 216031

URL: http://llvm.org/viewvc/llvm-project?rev=216031&view=rev
Log:
Split parseAssembly into parseAssembly and parseAssemblyInto.

This should restore the functionality of parsing new code into an existing
module without the confusing interface.

Modified:
    llvm/trunk/include/llvm/AsmParser/Parser.h
    llvm/trunk/lib/AsmParser/Parser.cpp

Modified: llvm/trunk/include/llvm/AsmParser/Parser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/AsmParser/Parser.h?rev=216031&r1=216030&r2=216031&view=diff
==============================================================================
--- llvm/trunk/include/llvm/AsmParser/Parser.h (original)
+++ llvm/trunk/include/llvm/AsmParser/Parser.h Tue Aug 19 17:05:47 2014
@@ -50,8 +50,7 @@ std::unique_ptr<Module> parseAssemblyStr
                                             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> parseAssemblyStr
 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

Modified: llvm/trunk/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/Parser.cpp?rev=216031&r1=216030&r2=216031&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/Parser.cpp (original)
+++ llvm/trunk/lib/AsmParser/Parser.cpp Tue Aug 19 17:05:47 2014
@@ -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);
 }
 





More information about the llvm-commits mailing list