1 //===-- llvm-ranlib.cpp - LLVM archive index generator --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Adds or updates an index (symbol table) for an LLVM archive file.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Module.h"
15 #include "llvm/Bytecode/Archive.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/FileUtilities.h"
18 #include "llvm/System/Signals.h"
25 // llvm-ar operation code and modifier flags
27 ArchiveName(cl::Positional, cl::Optional, cl::desc("<archive-file>..."));
30 Verbose("verbose",cl::Optional,cl::init(false),
31 cl::desc("Print the symbol table"));
36 if (TmpArchive.exists())
37 TmpArchive.destroyFile();
40 int main(int argc, char **argv) {
42 // Have the command line options parsed and handle things
43 // like --help and --version.
44 cl::ParseCommandLineOptions(argc, argv,
45 " LLVM Archive Index Generator (llvm-ranlib)\n\n"
46 " This program adds or updates an index of bytecode symbols\n"
47 " to an LLVM archive file."
50 // Print a stack trace if we signal out.
51 sys::PrintStackTraceOnErrorSignal();
55 // Make sure we don't exit with "unhandled exception".
58 // Check the path name of the archive
59 sys::Path ArchivePath;
60 if (!ArchivePath.setFile(ArchiveName))
61 throw std::string("Archive name invalid: ") + ArchiveName;
63 // Make sure it exists, we don't create empty archives
64 if (!ArchivePath.exists())
65 throw "Archive file does not exist";
67 // Archive* TheArchive = Archive::OpenAndLoad(ArchivePath);
68 Archive* TheArchive = Archive::OpenAndLoad(ArchivePath);
70 assert(TheArchive && "Unable to instantiate the archive");
72 TheArchive->writeToDisk(true,false,false,Verbose);
76 } catch (const char*msg) {
77 std::cerr << argv[0] << ": " << msg << "\n\n";
79 } catch (const std::string& msg) {
80 std::cerr << argv[0] << ": " << msg << "\n";
83 std::cerr << argv[0] << ": An nexpected unknown exception occurred.\n";