diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 23:45:49 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 23:45:49 +0000 |
commit | 065344dfd5a7b3502098810b981eb0077e5d81f3 (patch) | |
tree | 6521b00f224a62ade1e796532e30c6cba5d36633 /tools | |
parent | 5499da88331a31a9dcc24dc160f58b411fb0d34a (diff) |
use the new MemoryBuffer interfaces to simplify error reporting in clients.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36900 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bugpoint/BugDriver.cpp | 9 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 6 | ||||
-rw-r--r-- | tools/lli/lli.cpp | 6 | ||||
-rw-r--r-- | tools/llvm-dis/llvm-dis.cpp | 11 | ||||
-rw-r--r-- | tools/llvm-extract/llvm-extract.cpp | 3 | ||||
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 10 | ||||
-rw-r--r-- | tools/llvm-nm/llvm-nm.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-prof/llvm-prof.cpp | 10 | ||||
-rw-r--r-- | tools/llvm2cpp/llvm2cpp.cpp | 4 | ||||
-rw-r--r-- | tools/llvmc/CompilerDriver.cpp | 3 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 11 |
11 files changed, 27 insertions, 48 deletions
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp index 00dfc32774a..7ce1e689431 100644 --- a/tools/bugpoint/BugDriver.cpp +++ b/tools/bugpoint/BugDriver.cpp @@ -72,18 +72,18 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs, /// ParseInputFile - Given a bytecode or assembly input filename, parse and /// return it, or return null if not possible. /// -Module *llvm::ParseInputFile(const std::string &InputFilename) { - std::auto_ptr<MemoryBuffer> Buffer( - MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); +Module *llvm::ParseInputFile(const std::string &Filename) { + std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename)); Module *Result = 0; if (Buffer.get()) Result = ParseBitcodeFile(Buffer.get()); ParseError Err; - if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) { + if (!Result && !(Result = ParseAssemblyFile(Filename, &Err))) { std::cerr << "bugpoint: " << Err.getMessage() << "\n"; Result = 0; } + return Result; } @@ -100,6 +100,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) { // Load the first input file. Program = ParseInputFile(Filenames[0]); if (Program == 0) return true; + if (!run_as_child) std::cout << "Read input file : '" << Filenames[0] << "'\n"; diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 052242054c4..8797c58ce8f 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -179,14 +179,10 @@ int main(int argc, char **argv) { std::string ErrorMessage; std::auto_ptr<Module> M; - { std::auto_ptr<MemoryBuffer> Buffer( - MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); + MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)); if (Buffer.get()) M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage)); - else - ErrorMessage = "Error reading file '" + InputFilename + "'"; - } if (M.get() == 0) { std::cerr << argv[0] << ": bytecode didn't read correctly.\n"; std::cerr << "Reason: " << ErrorMessage << "\n"; diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index a1caf1172db..fdb5f4aa397 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -77,11 +77,7 @@ int main(int argc, char **argv, char * const *envp) { // Load the bytecode... std::string ErrorMsg; ModuleProvider *MP = 0; - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0], - InputFile.size()); - if (Buffer == 0) - ErrorMsg = "Error reading file '" + InputFile + "'"; - else { + if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){ MP = getBitcodeModuleProvider(Buffer, &ErrorMsg); if (!MP) delete Buffer; } diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 6321551446a..97ec4c73061 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -54,14 +54,11 @@ int main(int argc, char **argv) { std::auto_ptr<Module> M; - MemoryBuffer *Buffer - = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()); - - if (Buffer == 0) - ErrorMessage = "Error reading file '" + InputFilename + "'"; - else + if (MemoryBuffer *Buffer + = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { M.reset(ParseBitcodeFile(Buffer, &ErrorMessage)); - delete Buffer; + delete Buffer; + } if (M.get() == 0) { cerr << argv[0] << ": "; diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 97c45f6dcce..441063848ca 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -57,8 +57,7 @@ int main(int argc, char **argv) { std::auto_ptr<Module> M; - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], - InputFilename.size()); + MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename); if (Buffer == 0) { cerr << "Error reading file '" + InputFilename + "'"; return 1; diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index b19213a6fa5..28be3a97f38 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -58,13 +58,11 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) { Module* Result = 0; const std::string &FNStr = Filename.toString(); - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&FNStr[0], - FNStr.size()); - if (Buffer == 0) - ErrorMessage = "Error reading file '" + FNStr + "'"; - else + if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr, + &ErrorMessage)) { Result = ParseBitcodeFile(Buffer, &ErrorMessage); - delete Buffer; + delete Buffer; + } if (Result) return std::auto_ptr<Module>(Result); // Load successful! if (Verbose) { diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index c4aa7baf43e..e0013999e6e 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -124,7 +124,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) { // Note: Currently we do not support reading an archive from stdin. if (Filename == "-" || aPath.isBitcodeFile()) { std::auto_ptr<MemoryBuffer> Buffer( - MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size())); + MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage)); Module *Result = 0; if (Buffer.get()) Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage); diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp index 106eed8c3f4..f88f1fcc028 100644 --- a/tools/llvm-prof/llvm-prof.cpp +++ b/tools/llvm-prof/llvm-prof.cpp @@ -118,13 +118,11 @@ int main(int argc, char **argv) { // Read in the bytecode file... std::string ErrorMessage; Module *M; - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&BytecodeFile[0], - BytecodeFile.size()); - if (Buffer == 0) - ErrorMessage = "Error reading file '" + BytecodeFile + "'"; - else + if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BytecodeFile, + &ErrorMessage)) { M = ParseBitcodeFile(Buffer, &ErrorMessage); - delete Buffer; + delete Buffer; + } if (M == 0) { std::cerr << argv[0] << ": " << BytecodeFile << ": " << ErrorMessage << "\n"; diff --git a/tools/llvm2cpp/llvm2cpp.cpp b/tools/llvm2cpp/llvm2cpp.cpp index 7a4460282d7..d4382cd5cee 100644 --- a/tools/llvm2cpp/llvm2cpp.cpp +++ b/tools/llvm2cpp/llvm2cpp.cpp @@ -52,11 +52,9 @@ int main(int argc, char **argv) { std::auto_ptr<Module> M; std::auto_ptr<MemoryBuffer> Buffer( - MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); + MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)); if (Buffer.get()) M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage)); - else - ErrorMessage = "Error reading file '" + InputFilename + "'"; if (M.get() == 0) { std::cerr << argv[0] << ": "; if (ErrorMessage.size()) diff --git a/tools/llvmc/CompilerDriver.cpp b/tools/llvmc/CompilerDriver.cpp index 2f94ee84c78..b170270b0c7 100644 --- a/tools/llvmc/CompilerDriver.cpp +++ b/tools/llvmc/CompilerDriver.cpp @@ -69,8 +69,7 @@ static bool GetBytecodeDependentLibraries(const std::string &fname, Module::LibraryListType& deplibs, std::string* ErrMsg) { ModuleProvider *MP = 0; - if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&fname[0], - fname.size())) { + if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(fname)) { MP = getBitcodeModuleProvider(Buffer); if (MP == 0) delete Buffer; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 4ef1a6e39c7..14e02d0e467 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -260,15 +260,12 @@ int main(int argc, char **argv) { // Load the input module... std::auto_ptr<Module> M; - MemoryBuffer *Buffer - = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()); - - if (Buffer == 0) - ErrorMessage = "Error reading file '" + InputFilename + "'"; - else + if (MemoryBuffer *Buffer + = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { M.reset(ParseBitcodeFile(Buffer, &ErrorMessage)); + delete Buffer; + } - delete Buffer; if (M.get() == 0) { cerr << argv[0] << ": "; if (ErrorMessage.size()) |