X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=9bc9b241666e1f83a84c46bdf88badbe881ab159;hb=0e9c68e6bc8768143308b0162e900ba8bd10dc01;hp=2138fde5eb2bf1f3399940ca1b26deb59f04650a;hpb=d0996e5b33ede018999044f3c5f05e72540d97c4;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 2138fde5eb2..9bc9b241666 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,40 +21,46 @@ #include using namespace llvm; -Module *llvm::ParseAssembly(MemoryBuffer *F, - Module *M, - SMDiagnostic &Err, - LLVMContext &Context) { +bool llvm::parseAssemblyInto(std::unique_ptr F, Module &M, + SMDiagnostic &Err) { SourceMgr SM; - SM.AddNewSourceBuffer(F, SMLoc()); + StringRef Buf = F->getBuffer(); + 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; + return LLParser(Buf, SM, Err, &M).Run(); +} + +std::unique_ptr llvm::parseAssembly(std::unique_ptr F, + SMDiagnostic &Err, + LLVMContext &Context) { + std::unique_ptr M = + make_unique(F->getBufferIdentifier(), Context); - // Otherwise create a new module. - std::unique_ptr M2(new Module(F->getBufferIdentifier(), Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) + if (parseAssemblyInto(std::move(F), *M, Err)) 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); }