+Module *llvm::ParseAssembly(std::unique_ptr<MemoryBuffer> F, Module *M,
+ SMDiagnostic &Err, LLVMContext &Context) {
+ SourceMgr SM;
+ MemoryBuffer *Buf = F.get();
+ SM.AddNewSourceBuffer(F.release(), SMLoc());
+
+ // If we are parsing into an existing module, do it.
+ if (M)
+ return LLParser(Buf, SM, Err, M).Run() ? nullptr : M;
+
+ // Otherwise create a new module.
+ std::unique_ptr<Module> M2(new Module(Buf->getBufferIdentifier(), Context));
+ if (LLParser(Buf, SM, Err, M2.get()).Run())
+ return nullptr;
+ return M2.release();
+}
+