-Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
- Err.setFilename(Filename);
-
- std::string ErrorStr;
- OwningPtr<MemoryBuffer>
- F(MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr));
- if (F == 0) {
- Err.setError("Could not open input file '" + Filename + "'");
- return 0;
- }
-
- OwningPtr<Module> M(new Module(Filename));
- if (LLParser(F.get(), Err, M.get()).Run())
- return 0;
- return M.take();
-}
-
-Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
- ParseError &Err) {
- Err.setFilename("<string>");
-
- OwningPtr<MemoryBuffer>
- F(MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
- "<string>"));
-
- // If we are parsing into an existing module, do it.
- if (M)
- return LLParser(F.get(), Err, M).Run() ? 0 : M;
-
- // Otherwise create a new module.
- OwningPtr<Module> M2(new Module("<string>"));
- if (LLParser(F.get(), Err, M2.get()).Run())
- return 0;
- return M2.take();
+std::unique_ptr<Module> llvm::parseAssembly(std::unique_ptr<MemoryBuffer> F,
+ SMDiagnostic &Err,
+ LLVMContext &Context) {
+ SourceMgr SM;
+ MemoryBuffer *Buf = F.get();
+ SM.AddNewSourceBuffer(F.release(), SMLoc());
+
+ std::unique_ptr<Module> M =
+ make_unique<Module>(Buf->getBufferIdentifier(), Context);
+ if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run())
+ return nullptr;
+ return std::move(M);