X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-ar%2Fllvm-ar.cpp;h=3271f7c82f46670635ee43aaf28d681e24582d57;hb=a75ce9f5d2236d93c117e861e60e6f3f748c9555;hp=a72a4c00190e0ca415b17b5bdc950713482c3a9a;hpb=21c62da287237d39d0d95004881ea4baae3be6da;p=oota-llvm.git diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index a72a4c00190..3271f7c82f4 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -12,15 +12,18 @@ // //===----------------------------------------------------------------------===// +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Bitcode/Archive.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/System/Signals.h" -#include +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Signals.h" #include -#include #include +#include using namespace llvm; // Option for compatibility with AIX, not used but must allow it to be present. @@ -331,12 +334,12 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) { // printSymbolTable - print out the archive's symbol table. void printSymbolTable() { - std::cout << "\nArchive Symbol Table:\n"; + outs() << "\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"; + outs() << " " << format("%9u", offset) << "\t" << I->first <<"\n"; } } @@ -361,10 +364,10 @@ bool doPrint(std::string* ErrMsg) { continue; if (Verbose) - std::cout << "Printing " << I->getPath().toString() << "\n"; + outs() << "Printing " << I->getPath().str() << "\n"; unsigned len = I->getSize(); - std::cout.write(data, len); + outs().write(data, len); } else { countDown--; } @@ -378,17 +381,17 @@ bool doPrint(std::string* ErrMsg) { void printMode(unsigned mode) { if (mode & 004) - std::cout << "r"; + outs() << "r"; else - std::cout << "-"; + outs() << "-"; if (mode & 002) - std::cout << "w"; + outs() << "w"; else - std::cout << "-"; + outs() << "-"; if (mode & 001) - std::cout << "x"; + outs() << "x"; else - std::cout << "-"; + outs() << "-"; } // doDisplayTable - Implement the 't' operation. This function prints out just @@ -407,23 +410,22 @@ doDisplayTable(std::string* ErrMsg) { // FIXME: Output should be this format: // Zrw-r--r-- 500/ 500 525 Nov 8 17:42 2004 Makefile if (I->isBitcode()) - std::cout << "b"; + outs() << "b"; else if (I->isCompressed()) - std::cout << "Z"; + outs() << "Z"; else - std::cout << " "; + outs() << " "; unsigned mode = I->getMode(); printMode((mode >> 6) & 007); printMode((mode >> 3) & 007); printMode(mode & 007); - std::cout << " " << std::setw(4) << I->getUser(); - std::cout << "/" << std::setw(4) << I->getGroup(); - std::cout << " " << std::setw(8) << I->getSize(); - std::cout << " " << std::setw(20) << - I->getModTime().toString().substr(4); - std::cout << " " << I->getPath().toString() << "\n"; + outs() << " " << format("%4u", I->getUser()); + outs() << "/" << format("%4u", I->getGroup()); + outs() << " " << format("%8u", I->getSize()); + outs() << " " << format("%20s", I->getModTime().str().substr(4).c_str()); + outs() << " " << I->getPath().str() << "\n"; } else { - std::cout << I->getPath().toString() << "\n"; + outs() << I->getPath().str() << "\n"; } } } @@ -525,7 +527,7 @@ doMove(std::string* ErrMsg) { if (AddBefore || InsertBefore || AddAfter) { for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end(); I != E; ++I ) { - if (RelPos == I->getPath().toString()) { + if (RelPos == I->getPath().str()) { if (AddAfter) { moveto_spot = I; moveto_spot++; @@ -613,7 +615,7 @@ doReplaceOrInsert(std::string* ErrMsg) { std::set::iterator found = remaining.end(); for (std::set::iterator RI = remaining.begin(), RE = remaining.end(); RI != RE; ++RI ) { - std::string compare(RI->toString()); + std::string compare(RI->str()); if (TruncateNames && compare.length() > 15) { const char* nm = compare.c_str(); unsigned len = compare.length(); @@ -626,7 +628,7 @@ doReplaceOrInsert(std::string* ErrMsg) { len = 15; compare.assign(nm,len); } - if (compare == I->getPath().toString()) { + if (compare == I->getPath().str()) { found = RI; break; } @@ -638,7 +640,7 @@ doReplaceOrInsert(std::string* ErrMsg) { const sys::FileStatus *si = PwS.getFileStatus(false, &Err); if (!si) return true; - if (si->isDir) { + if (!si->isDir) { if (OnlyUpdate) { // Replace the item only if it is newer. if (si->modTime > I->getModTime()) @@ -658,9 +660,9 @@ doReplaceOrInsert(std::string* ErrMsg) { } // Determine if this is the place where we should insert - if ((AddBefore || InsertBefore) && (RelPos == I->getPath().toString())) + if ((AddBefore || InsertBefore) && RelPos == I->getPath().str()) insert_spot = I; - else if (AddAfter && (RelPos == I->getPath().toString())) { + else if (AddAfter && RelPos == I->getPath().str()) { insert_spot = I; insert_spot++; } @@ -686,7 +688,11 @@ doReplaceOrInsert(std::string* ErrMsg) { // main - main program for llvm-ar .. see comments in the code int main(int argc, char **argv) { - llvm_shutdown_obj X; // Call llvm_shutdown() on exit. + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc, argv); + LLVMContext &Context = getGlobalContext(); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. // Have the command line options parsed and handle things // like --help and --version. @@ -695,9 +701,6 @@ int main(int argc, char **argv) { " This program archives bitcode files into single libraries\n" ); - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(); - int exitCode = 0; // Make sure we don't exit with "unhandled exception". @@ -715,14 +718,15 @@ int main(int argc, char **argv) { if (!ArchivePath.exists()) { // Produce a warning if we should and we're creating the archive if (!Create) - std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n"; - TheArchive = Archive::CreateEmpty(ArchivePath); + errs() << argv[0] << ": creating " << ArchivePath.str() << "\n"; + TheArchive = Archive::CreateEmpty(ArchivePath, Context); + TheArchive->writeToDisk(); } else { std::string Error; - TheArchive = Archive::OpenAndLoad(ArchivePath, &Error); + TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error); if (TheArchive == 0) { - std::cerr << argv[0] << ": error loading '" << ArchivePath << "': " - << Error << "!\n"; + errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': " + << Error << "!\n"; return 1; } } @@ -745,27 +749,27 @@ int main(int argc, char **argv) { case DisplayTable: haveError = doDisplayTable(&ErrMsg); break; case Extract: haveError = doExtract(&ErrMsg); break; case NoOperation: - std::cerr << argv[0] << ": No operation was selected.\n"; + errs() << argv[0] << ": No operation was selected.\n"; break; } if (haveError) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + errs() << argv[0] << ": " << ErrMsg << "\n"; return 1; } } catch (const char*msg) { // These errors are usage errors, thrown only by the various checks in the // code above. - std::cerr << argv[0] << ": " << msg << "\n\n"; + errs() << argv[0] << ": " << msg << "\n\n"; cl::PrintHelpMessage(); exitCode = 1; } catch (const std::string& msg) { // These errors are thrown by LLVM libraries (e.g. lib System) and represent // a more serious error so we bump the exitCode and don't print the usage. - std::cerr << argv[0] << ": " << msg << "\n"; + errs() << argv[0] << ": " << msg << "\n"; exitCode = 2; } catch (...) { // This really shouldn't happen, but just in case .... - std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; + errs() << argv[0] << ": An unexpected unknown exception occurred.\n"; exitCode = 3; }