From babb45b3277e0d85358d19d6618818a9cef561a3 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 16 Nov 2004 06:41:20 +0000 Subject: Per code review: \ * Make static things static \ * Get rid of unused TmpArchive variable \ * Implement symbol table printing \ * Adjust to changes in llvm::Archive interface \ * Make sure we destruct objects even if exceptions occur. \ * Fix a typo in an output string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17878 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-ranlib/llvm-ranlib.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'tools/llvm-ranlib/llvm-ranlib.cpp') diff --git a/tools/llvm-ranlib/llvm-ranlib.cpp b/tools/llvm-ranlib/llvm-ranlib.cpp index b387aa5eec..6ac2b16da1 100644 --- a/tools/llvm-ranlib/llvm-ranlib.cpp +++ b/tools/llvm-ranlib/llvm-ranlib.cpp @@ -17,24 +17,27 @@ #include "llvm/Support/FileUtilities.h" #include "llvm/System/Signals.h" #include -#include #include using namespace llvm; // llvm-ar operation code and modifier flags -cl::opt +static cl::opt ArchiveName(cl::Positional, cl::Optional, cl::desc("...")); -cl::opt +static cl::opt Verbose("verbose",cl::Optional,cl::init(false), cl::desc("Print the symbol table")); -sys::Path TmpArchive; - -void cleanup() { - if (TmpArchive.exists()) - TmpArchive.destroyFile(); +// printSymbolTable - print out the archive's symbol table. +void printSymbolTable(Archive* TheArchive) { + std::cout << "\nArchive Symbol Table:\n"; + const Archive::SymTabType& symtab = TheArchive->getSymbolTable(); + for (Archive::SymTabType::const_iterator I=symtab.begin(), E=symtab.end(); + I != E; ++I ) { + unsigned offset = TheArchive->getFirstFileOffset() + I->second; + std::cout << " " << std::setw(9) << offset << "\t" << I->first <<"\n"; + } } int main(int argc, char **argv) { @@ -64,14 +67,15 @@ int main(int argc, char **argv) { if (!ArchivePath.exists()) throw "Archive file does not exist"; - // Archive* TheArchive = Archive::OpenAndLoad(ArchivePath); - Archive* TheArchive = Archive::OpenAndLoad(ArchivePath); + std::auto_ptr AutoArchive(Archive::OpenAndLoad(ArchivePath)); + Archive* TheArchive = AutoArchive.get(); assert(TheArchive && "Unable to instantiate the archive"); - TheArchive->writeToDisk(true,false,false,Verbose); + TheArchive->writeToDisk(true, false, false ); - delete TheArchive; + if (Verbose) + printSymbolTable(TheArchive); } catch (const char*msg) { std::cerr << argv[0] << ": " << msg << "\n\n"; @@ -80,9 +84,8 @@ int main(int argc, char **argv) { std::cerr << argv[0] << ": " << msg << "\n"; exitCode = 2; } catch (...) { - std::cerr << argv[0] << ": An nexpected unknown exception occurred.\n"; + std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; exitCode = 3; } - cleanup(); return exitCode; } -- cgit v1.2.3