X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-ar%2Fllvm-ar.cpp;h=1620bf440d5f00ee1a19e97732451c8b4b21ef87;hb=82a13c9c4811e40d0ff858c508cb54d672ee926e;hp=55a60a331f43fcdad6b0e39ed8bca2878f230b1d;hpb=0ff2d31766209ce1a69d4d2c5d35761ef57362aa;p=oota-llvm.git diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 55a60a331f4..1620bf440d5 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -8,20 +8,19 @@ //===----------------------------------------------------------------------===// // // Builds up (relatively) standard unix archive files (.a) containing LLVM -// bytecode or other files. +// bitcode or other files. // //===----------------------------------------------------------------------===// #include "llvm/Module.h" -#include "llvm/Bytecode/Archive.h" +#include "llvm/Bitcode/Archive.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Compressor.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/System/Signals.h" #include #include #include #include - using namespace llvm; // Option for compatibility with ASIX, not used but must allow it to be present. @@ -55,7 +54,7 @@ static cl::extrahelp MoreHelp( " [b] - put file(s) before [relpos] (same as [i])\n" " [f] - truncate inserted file names\n" " [i] - put file(s) before [relpos] (same as [b])\n" - " [k] - always print bytecode files (default is to skip them)\n" + " [k] - always print bitcode files (default is to skip them)\n" " [N] - use instance [count] of name\n" " [o] - preserve original dates\n" " [P] - use full path names when matching\n" @@ -89,7 +88,7 @@ bool AddBefore = false; ///< 'b' modifier bool Create = false; ///< 'c' modifier bool TruncateNames = false; ///< 'f' modifier bool InsertBefore = false; ///< 'i' modifier -bool DontSkipBytecode = false; ///< 'k' modifier +bool DontSkipBitcode = false; ///< 'k' modifier bool UseCount = false; ///< 'N' modifier bool OriginalDates = false; ///< 'o' modifier bool FullPath = false; ///< 'P' modifier @@ -194,7 +193,7 @@ ArchiveOperation parseCommandLine() { case 'x': ++NumOperations; Operation = Extract; break; case 'c': Create = true; break; case 'f': TruncateNames = true; break; - case 'k': DontSkipBytecode = true; break; + case 'k': DontSkipBitcode = true; break; case 'l': /* accepted but unused */ break; case 'o': OriginalDates = true; break; case 'P': FullPath = true; break; @@ -281,16 +280,17 @@ recurseDirectories(const sys::Path& path, for (std::set::iterator I = content.begin(), E = content.end(); I != E; ++I) { // Make sure it exists and is a directory - sys::FileStatus Status; - if (I->getFileStatus(Status)) { - if (Status.isDir) { - std::set moreResults; - if (recurseDirectories(*I, moreResults, ErrMsg)) - return true; - result.insert(moreResults.begin(), moreResults.end()); - } else { + sys::PathWithStatus PwS(*I); + const sys::FileStatus *Status = PwS.getFileStatus(false, ErrMsg); + if (!Status) + return true; + if (Status->isDir) { + std::set moreResults; + if (recurseDirectories(*I, moreResults, ErrMsg)) + return true; + result.insert(moreResults.begin(), moreResults.end()); + } else { result.insert(*I); - } } } } @@ -308,11 +308,12 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) { if (checkExistence) { if (!aPath.exists()) throw std::string("File does not exist: ") + Members[i]; - sys::FileStatus si; std::string Err; - if (aPath.getFileStatus(si, &Err)) + sys::PathWithStatus PwS(aPath); + const sys::FileStatus *si = PwS.getFileStatus(false, &Err); + if (!si) throw Err; - if (si.isDir) { + if (si->isDir) { std::set dirpaths; if (recurseDirectories(aPath, dirpaths, ErrMsg)) return true; @@ -340,7 +341,7 @@ void printSymbolTable() { // doPrint - Implements the 'p' operation. This function traverses the archive // looking for members that match the path list. It is careful to uncompress -// things that should be and to skip bytecode files unless the 'k' modifier was +// things that should be and to skip bitcode files unless the 'k' modifier was // given. bool doPrint(std::string* ErrMsg) { if (buildPaths(false, ErrMsg)) @@ -355,21 +356,14 @@ bool doPrint(std::string* ErrMsg) { // Skip things that don't make sense to print if (I->isLLVMSymbolTable() || I->isSVR4SymbolTable() || - I->isBSD4SymbolTable() || (!DontSkipBytecode && - (I->isBytecode() || I->isCompressedBytecode()))) + I->isBSD4SymbolTable() || (!DontSkipBitcode && I->isBitcode())) continue; if (Verbose) std::cout << "Printing " << I->getPath().toString() << "\n"; - if (I->isCompressedBytecode()) - Compressor::decompressToStream(data+4,I->getSize()-4,std::cout); - else if (I->isCompressed()) { - Compressor::decompressToStream(data,I->getSize(),std::cout); - } else { - unsigned len = I->getSize(); - std::cout.write(data, len); - } + unsigned len = I->getSize(); + std::cout.write(data, len); } else { countDown--; } @@ -411,10 +405,8 @@ doDisplayTable(std::string* ErrMsg) { if (Verbose) { // FIXME: Output should be this format: // Zrw-r--r-- 500/ 500 525 Nov 8 17:42 2004 Makefile - if (I->isBytecode()) + if (I->isBitcode()) std::cout << "b"; - else if (I->isCompressedBytecode()) - std::cout << "B"; else if (I->isCompressed()) std::cout << "Z"; else @@ -445,7 +437,6 @@ bool doExtract(std::string* ErrMsg) { if (buildPaths(false, ErrMsg)) return true; - unsigned countDown = Count; for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); I != E; ++I ) { if (Paths.empty() || @@ -468,12 +459,8 @@ doExtract(std::string* ErrMsg) { const char* data = reinterpret_cast(I->getData()); unsigned len = I->getSize(); - // Write the data, making sure to uncompress things first - if (I->isCompressed()) { - Compressor::decompressToStream(data,len,file); - } else { - file.write(data,len); - } + // Write the data. + file.write(data,len); file.close(); // If we're supposed to retain the original modification times, etc. do so @@ -511,7 +498,7 @@ doDelete(std::string* ErrMsg) { } // We're done editting, reconstruct the archive. - if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) + if (TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) return true; if (ReallyVerbose) printSymbolTable(); @@ -566,7 +553,7 @@ doMove(std::string* ErrMsg) { } // We're done editting, reconstruct the archive. - if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) + if (TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) return true; if (ReallyVerbose) printSymbolTable(); @@ -591,7 +578,7 @@ doQuickAppend(std::string* ErrMsg) { } // We're done editting, reconstruct the archive. - if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) + if (TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) return true; if (ReallyVerbose) printSymbolTable(); @@ -645,14 +632,15 @@ doReplaceOrInsert(std::string* ErrMsg) { } if (found != remaining.end()) { - sys::FileStatus si; std::string Err; - if (found->getFileStatus(si, &Err)) + sys::PathWithStatus PwS(*found); + 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()) + if (si->modTime > I->getModTime()) if (I->replaceWith(*found, ErrMsg)) return true; } else { @@ -688,7 +676,7 @@ doReplaceOrInsert(std::string* ErrMsg) { } // We're done editting, reconstruct the archive. - if (!TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) + if (TheArchive->writeToDisk(SymTable,TruncateNames,Compression,ErrMsg)) return true; if (ReallyVerbose) printSymbolTable(); @@ -697,12 +685,13 @@ 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. // Have the command line options parsed and handle things // like --help and --version. cl::ParseCommandLineOptions(argc, argv, - " LLVM Archiver (llvm-ar)\n\n" - " This program archives bytecode files into single libraries\n" + "LLVM Archiver (llvm-ar)\n\n" + " This program archives bitcode files into single libraries\n" ); // Print a stack trace if we signal out.