X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FIRReader.h;h=6d8a9b30ae1fd8bfee9f0c9b7f6bdceb765a2743;hb=b09c146b116359616f6cbd4c8b3328607e00ff42;hp=50de73803cf9e9df68c56c065fa434a7d4d51dc1;hpb=f0356fe140af1a30587b9a86bcfb1b2c51b8ce20;p=oota-llvm.git diff --git a/include/llvm/Support/IRReader.h b/include/llvm/Support/IRReader.h index 50de73803cf..6d8a9b30ae1 100644 --- a/include/llvm/Support/IRReader.h +++ b/include/llvm/Support/IRReader.h @@ -19,10 +19,12 @@ #ifndef LLVM_SUPPORT_IRREADER_H #define LLVM_SUPPORT_IRREADER_H +#include "llvm/ADT/OwningPtr.h" #include "llvm/Assembly/Parser.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/system_error.h" namespace llvm { @@ -30,15 +32,16 @@ namespace llvm { /// which does lazy deserialization of function bodies. Otherwise, attempt to /// parse it as LLVM Assembly and return a fully populated Module. This /// function *always* takes ownership of the given MemoryBuffer. - inline Module *getIRModule(MemoryBuffer *Buffer, - SMDiagnostic &Err, - LLVMContext &Context) { + inline Module *getLazyIRModule(MemoryBuffer *Buffer, + SMDiagnostic &Err, + LLVMContext &Context) { if (isBitcode((const unsigned char *)Buffer->getBufferStart(), (const unsigned char *)Buffer->getBufferEnd())) { std::string ErrMsg; Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg); if (M == 0) { - Err = SMDiagnostic(Buffer->getBufferIdentifier(), -1, -1, ErrMsg, ""); + Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + ErrMsg); // ParseBitcodeFile does not take ownership of the Buffer in the // case of an error. delete Buffer; @@ -53,18 +56,17 @@ namespace llvm { /// for it which does lazy deserialization of function bodies. Otherwise, /// attempt to parse it as LLVM Assembly and return a fully populated /// Module. - inline Module *getIRFileModule(const std::string &Filename, - SMDiagnostic &Err, - LLVMContext &Context) { - std::string ErrMsg; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg); - if (F == 0) { - Err = SMDiagnostic(Filename, -1, -1, - "Could not open input file '" + Filename + "'", ""); + inline Module *getLazyIRFileModule(const std::string &Filename, + SMDiagnostic &Err, + LLVMContext &Context) { + OwningPtr File; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { + Err = SMDiagnostic(Filename, SourceMgr::DK_Error, + "Could not open input file: " + ec.message()); return 0; } - return getIRModule(F, Err, Context); + return getLazyIRModule(File.take(), Err, Context); } /// If the given MemoryBuffer holds a bitcode image, return a Module @@ -78,10 +80,11 @@ namespace llvm { (const unsigned char *)Buffer->getBufferEnd())) { std::string ErrMsg; Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg); + if (M == 0) + Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + ErrMsg); // ParseBitcodeFile does not take ownership of the Buffer. delete Buffer; - if (M == 0) - Err = SMDiagnostic(Buffer->getBufferIdentifier(), -1, -1, ErrMsg, ""); return M; } @@ -94,15 +97,14 @@ namespace llvm { inline Module *ParseIRFile(const std::string &Filename, SMDiagnostic &Err, LLVMContext &Context) { - std::string ErrMsg; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg); - if (F == 0) { - Err = SMDiagnostic(Filename, -1, -1, - "Could not open input file '" + Filename + "'", ""); + OwningPtr File; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { + Err = SMDiagnostic(Filename, SourceMgr::DK_Error, + "Could not open input file: " + ec.message()); return 0; } - return ParseIR(F, Err, Context); + return ParseIR(File.take(), Err, Context); } }