X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=d777ab91af81b48dc8388c628da6c864796102c7;hb=b3cabb44c32b5a3aba9b4d23aae9723d498ea7a9;hp=d66c13d39c09f656efc511510ccdb6d2d43dce73;hpb=eeb4a84ac8d91fb1d5a7c484a1c7047409faee30;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index d66c13d39c0..d777ab91af8 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -13,49 +13,50 @@ #include "llvm/Assembly/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 "llvm/Support/system_error.h" #include using namespace llvm; +Module *llvm::ParseAssembly(MemoryBuffer *F, + Module *M, + 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. + OwningPtr M2(new Module(F->getBufferIdentifier(), Context)); + if (LLParser(F, SM, Err, M2.get()).Run()) + return 0; + return M2.take(); +} + 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 + "'", ""); + OwningPtr File; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) { + Err = SMDiagnostic(Filename, SourceMgr::DK_Error, + "Could not open input file: " + ec.message()); return 0; } - SourceMgr SM; - SM.AddNewSourceBuffer(F, SMLoc()); - - OwningPtr M(new Module(Filename, Context)); - if (LLParser(F, SM, Err, M.get()).Run()) - return 0; - return M.take(); + return ParseAssembly(File.take(), 0, 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, strlen(AsmString)), ""); - - 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. - OwningPtr M2(new Module("", Context)); - if (LLParser(F, SM, Err, M2.get()).Run()) - return 0; - return M2.take(); + return ParseAssembly(F, M, Err, Context); }