X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=4cc94cb270d9af3cd2ef738671b3f5673a1e6093;hb=540b4f6c08a089f487edad2befb7caf98c127ac5;hp=331a23323b517214156d78b62505d3ec1ea3a334;hpb=f31657990191d5b2bb1eb3bd95020fc3375f0e3d;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 331a23323b5..4cc94cb270d 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -7,56 +7,54 @@ // //===----------------------------------------------------------------------===// // -// This library implements the functionality defined in llvm/Assembly/Parser.h +// This library implements the functionality defined in llvm/AsmParser/Parser.h // //===----------------------------------------------------------------------===// -#include "llvm/Assembly/Parser.h" +#include "llvm/AsmParser/Parser.h" #include "LLParser.h" -#include "llvm/Module.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/Support/SourceMgr.h" +#include "llvm/IR/Module.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace llvm; -Module *llvm::ParseAssembly(MemoryBuffer *F, - Module *M, - SMDiagnostic &Err, - LLVMContext &Context) { +Module *llvm::ParseAssembly(std::unique_ptr F, Module *M, + 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() ? 0 : M; + return LLParser(Buf, SM, Err, M).Run() ? nullptr : M; // Otherwise create a new module. - OwningPtr M2(new Module(F->getBufferIdentifier(), Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) - return 0; - return M2.take(); + std::unique_ptr M2(new Module(Buf->getBufferIdentifier(), Context)); + if (LLParser(Buf, SM, Err, M2.get()).Run()) + return nullptr; + return M2.release(); } Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { - std::string ErrorStr; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr); - if (F == 0) { - Err = SMDiagnostic("", -1, -1, - "Could not open input file '" + Filename + "'", ""); - return 0; + 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 nullptr; } - return ParseAssembly(F, 0, Err, Context); + return ParseAssembly(std::move(FileOrErr.get()), nullptr, Err, Context); } Module *llvm::ParseAssemblyString(const char *AsmString, Module *M, SMDiagnostic &Err, LLVMContext &Context) { MemoryBuffer *F = - MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString), - ""); + MemoryBuffer::getMemBuffer(StringRef(AsmString), ""); - return ParseAssembly(F, M, Err, Context); + return ParseAssembly(std::unique_ptr(F), M, Err, Context); }