+#include "llvm/AsmParser/Parser.h"
+#include "LLParser.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstring>
+#include <system_error>
+using namespace llvm;
+
+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->getBuffer(), SM, Err, M).Run() ? nullptr : M;
+
+ // Otherwise create a new module.
+ std::unique_ptr<Module> M2(new Module(Buf->getBufferIdentifier(), Context));
+ if (LLParser(Buf->getBuffer(), SM, Err, M2.get()).Run())
+ return nullptr;
+ return M2.release();