X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=7c6598106ece07fdb9ebfc12b6e0d4b00676a379;hb=78f686d37cc3b4e70bbfc2acdfcfec8443fd3250;hp=a1da5e11639ed1512fce926fe9918f1d59945fe7;hpb=f4ccd110750a3f3fe6a107d5c74c649c2a0dc407;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index a1da5e11639..7c6598106ec 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -17,45 +17,43 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" #include +#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()); - - // If we are parsing into an existing module, do it. - if (M) - return LLParser(F, SM, Err, M).Run() ? 0 : M; - - // Otherwise create a new module. - std::unique_ptr M2(new Module(F->getBufferIdentifier(), Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) - return 0; - return M2.release(); + MemoryBuffer *Buf = F.get(); + SM.AddNewSourceBuffer(F.release(), SMLoc()); + + std::unique_ptr M = + make_unique(Buf->getBufferIdentifier(), Context); + if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run()) + return nullptr; + return std::move(M); } -Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, - LLVMContext &Context) { - std::unique_ptr File; - if (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()); - return 0; + "Could not open input file: " + EC.message()); + return nullptr; } - return ParseAssembly(File.release(), 0, 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, strlen(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); }