Minor cleanup related to my latest scheduler changes.
[oota-llvm.git] / tools / llvm-ar / llvm-ar.cpp
index 51f00cd9a5ee1a9444b015c058a03b37d8474518..3271f7c82f46670635ee43aaf28d681e24582d57 100644 (file)
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/System/Signals.h"
-#include <iostream>
+#include "llvm/Support/Signals.h"
 #include <algorithm>
-#include <iomanip>
 #include <memory>
+#include <fstream>
 using namespace llvm;
 
 // Option for compatibility with AIX, not used but must allow it to be present.
@@ -334,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";
   }
 }
 
@@ -364,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--;
       }
@@ -381,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
@@ -410,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";
       }
     }
   }
@@ -528,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++;
@@ -616,7 +615,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
     std::set<sys::Path>::iterator found = remaining.end();
     for (std::set<sys::Path>::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();
@@ -629,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;
       }
@@ -661,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++;
     }
@@ -692,7 +691,7 @@ int main(int argc, char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  LLVMContext Context;
+  LLVMContext &Context = getGlobalContext();
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
@@ -719,14 +718,14 @@ int main(int argc, char **argv) {
     if (!ArchivePath.exists()) {
       // Produce a warning if we should and we're creating the archive
       if (!Create)
-        errs() << argv[0] << ": creating " << ArchivePath.toString() << "\n";
+        errs() << argv[0] << ": creating " << ArchivePath.str() << "\n";
       TheArchive = Archive::CreateEmpty(ArchivePath, Context);
       TheArchive->writeToDisk();
     } else {
       std::string Error;
       TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
       if (TheArchive == 0) {
-        errs() << argv[0] << ": error loading '" << ArchivePath << "': "
+        errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': "
                << Error << "!\n";
         return 1;
       }