X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FParser.cpp;h=7c6598106ece07fdb9ebfc12b6e0d4b00676a379;hb=f2b844d0b1d1cf62ba172f97981840fa9ccdf693;hp=4cc94cb270d9af3cd2ef738671b3f5673a1e6093;hpb=822199b9e6867c3fe94bffa6ab57be903014f98a;p=oota-llvm.git diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index 4cc94cb270d..7c6598106ec 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -21,25 +21,23 @@ #include using namespace llvm; -Module *llvm::ParseAssembly(std::unique_ptr F, Module *M, - SMDiagnostic &Err, LLVMContext &Context) { +std::unique_ptr llvm::parseAssembly(std::unique_ptr F, + SMDiagnostic &Err, + LLVMContext &Context) { SourceMgr SM; MemoryBuffer *Buf = F.get(); SM.AddNewSourceBuffer(F.release(), SMLoc()); - // If we are parsing into an existing module, do it. - if (M) - return LLParser(Buf, SM, Err, M).Run() ? nullptr : M; - - // Otherwise create a new module. - std::unique_ptr M2(new Module(Buf->getBufferIdentifier(), Context)); - if (LLParser(Buf, SM, Err, M2.get()).Run()) + std::unique_ptr M = + make_unique(Buf->getBufferIdentifier(), Context); + if (LLParser(Buf->getBuffer(), SM, Err, M.get()).Run()) return nullptr; - return M2.release(); + return std::move(M); } -Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, - LLVMContext &Context) { +std::unique_ptr llvm::parseAssemblyFile(StringRef Filename, + SMDiagnostic &Err, + LLVMContext &Context) { ErrorOr> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = FileOrErr.getError()) { @@ -48,13 +46,14 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err, return nullptr; } - return ParseAssembly(std::move(FileOrErr.get()), 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(std::unique_ptr(F), M, Err, Context); + return parseAssembly(std::move(F), Err, Context); }