X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=7c6598106ece07fdb9ebfc12b6e0d4b00676a379;hb=78f686d37cc3b4e70bbfc2acdfcfec8443fd3250;hp=2138fde5eb2bf1f3399940ca1b26deb59f04650a;hpb=d0996e5b33ede018999044f3c5f05e72540d97c4;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 2138fde5eb2..7c6598106ec 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,40 +21,39 @@ #include using namespace llvm; -Module *llvm::ParseAssembly(MemoryBuffer *F, - Module *M, - SMDiagnostic &Err, - LLVMContext &Context) { +std::unique_ptr llvm::parseAssembly(std::unique_ptr F, + SMDiagnostic &Err, + LLVMContext &Context) { SourceMgr SM; - SM.AddNewSourceBuffer(F, SMLoc()); + MemoryBuffer *Buf = F.get(); + SM.AddNewSourceBuffer(F.release(), SMLoc()); - // If we are parsing into an existing module, do it. - if (M) - return LLParser(F, SM, Err, M).Run() ? nullptr : M; - - // Otherwise create a new module. - std::unique_ptr M2(new Module(F->getBufferIdentifier(), Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) + std::unique_ptr M = + make_unique(Buf->getBufferIdentifier(), Context); + if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run()) return nullptr; - return M2.release(); + return std::move(M); } -Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, - LLVMContext &Context) { - std::unique_ptr File; - if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { +std::unique_ptr llvm::parseAssemblyFile(StringRef Filename, + SMDiagnostic &Err, + LLVMContext &Context) { + ErrorOr> FileOrErr = + MemoryBuffer::getFileOrSTDIN(Filename); + if (std::error_code EC = FileOrErr.getError()) { Err = SMDiagnostic(Filename, SourceMgr::DK_Error, - "Could not open input file: " + ec.message()); + "Could not open input file: " + EC.message()); return nullptr; } - return ParseAssembly(File.release(), nullptr, Err, Context); + return parseAssembly(std::move(FileOrErr.get()), Err, Context); } -Module *llvm::ParseAssemblyString(const char *AsmString, Module *M, - SMDiagnostic &Err, LLVMContext &Context) { - MemoryBuffer *F = - MemoryBuffer::getMemBuffer(StringRef(AsmString), ""); +std::unique_ptr llvm::parseAssemblyString(StringRef AsmString, + SMDiagnostic &Err, + LLVMContext &Context) { + std::unique_ptr F( + MemoryBuffer::getMemBuffer(AsmString, "")); - return ParseAssembly(F, M, Err, Context); + return parseAssembly(std::move(F), Err, Context); }