From 3ff9563c3e391954b2e224afcf8b2b0fcc3888aa Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 16 Dec 2010 03:29:14 +0000 Subject: MemoryBuffer now return an error_code and returns a OwningPtr via an out parm. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121958 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/FileCheck/FileCheck.cpp | 15 +++++++++------ utils/FileUpdate/FileUpdate.cpp | 12 +++++------- utils/TableGen/TableGen.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'utils') diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index b8c14f0..a4aa693 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -16,6 +16,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" @@ -489,13 +490,14 @@ static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) { static bool ReadCheckFile(SourceMgr &SM, std::vector &CheckStrings) { // Open the check file, and tell SourceMgr about it. - error_code ec; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), ec); - if (F == 0) { + OwningPtr File; + if (error_code ec = + MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), File)) { errs() << "Could not open check file '" << CheckFilename << "': " << ec.message() << '\n'; return true; } + MemoryBuffer *F = File.take(); // If we want to canonicalize whitespace, strip excess whitespace from the // buffer containing the CHECK lines. @@ -648,13 +650,14 @@ int main(int argc, char **argv) { return 2; // Open the file to check and add it to SourceMgr. - error_code ec; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), ec); - if (F == 0) { + OwningPtr File; + if (error_code ec = + MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) { errs() << "Could not open input file '" << InputFilename << "': " << ec.message() << '\n'; return true; } + MemoryBuffer *F = File.take(); // Remove duplicate spaces in the input file if requested. if (!NoCanonicalizeWhiteSpace) diff --git a/utils/FileUpdate/FileUpdate.cpp b/utils/FileUpdate/FileUpdate.cpp index 3514d0f..3ea1e4f 100644 --- a/utils/FileUpdate/FileUpdate.cpp +++ b/utils/FileUpdate/FileUpdate.cpp @@ -15,6 +15,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/Signals.h" @@ -43,17 +44,16 @@ int main(int argc, char **argv) { } // Get the input data. - error_code ec; - MemoryBuffer *In = - MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), ec); - if (In == 0) { + OwningPtr In; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), In)) { errs() << argv[0] << ": error: Unable to get input '" << InputFilename << "': " << ec.message() << '\n'; return 1; } // Get the output data. - MemoryBuffer *Out = MemoryBuffer::getFile(OutputFilename.c_str(), ec); + OwningPtr Out; + MemoryBuffer::getFile(OutputFilename.c_str(), Out); // If the output exists and the contents match, we are done. if (Out && In->getBufferSize() == Out->getBufferSize() && @@ -65,8 +65,6 @@ int main(int argc, char **argv) { return 0; } - delete Out; - // Otherwise, overwrite the output. if (!Quiet) errs() << argv[0] << ": Updating '" << OutputFilename diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index f206d2b..61a8141 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -37,6 +37,7 @@ #include "ARMDecoderEmitter.h" #include "SubtargetEmitter.h" #include "TGParser.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" @@ -190,13 +191,13 @@ static bool ParseFile(const std::string &Filename, const std::vector &IncludeDirs, SourceMgr &SrcMgr, RecordKeeper &Records) { - error_code ec; - MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), ec); - if (F == 0) { + OwningPtr File; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { errs() << "Could not open input file '" << Filename << "': " << ec.message() <<"\n"; return true; } + MemoryBuffer *F = File.take(); // Tell SrcMgr about this buffer, which is what TGParser will pick up. SrcMgr.AddNewSourceBuffer(F, SMLoc()); -- cgit v1.1