make all llvm tools call llvm_shutdown when they exit, static'ify some stuff.

With this change, I can now move -stats to print when llvm_shutdown is called.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32250 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-12-06 01:18:01 +00:00
parent bdbf5fd1c9
commit c30598bc3a
21 changed files with 94 additions and 59 deletions

View File

@ -20,6 +20,7 @@
#include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/System/Signals.h"
#include <cctype>
#include <cerrno>
@ -65,18 +66,18 @@ namespace {
std::string ToolName;
}
char TypeCharForSymbol (GlobalValue &GV) {
if (GV.isExternal ()) return 'U';
if (GV.hasLinkOnceLinkage ()) return 'C';
if (GV.hasWeakLinkage ()) return 'W';
if (isa<Function> (GV) && GV.hasInternalLinkage ()) return 't';
if (isa<Function> (GV)) return 'T';
if (isa<GlobalVariable> (GV) && GV.hasInternalLinkage ()) return 'd';
if (isa<GlobalVariable> (GV)) return 'D';
static char TypeCharForSymbol(GlobalValue &GV) {
if (GV.isExternal()) return 'U';
if (GV.hasLinkOnceLinkage()) return 'C';
if (GV.hasWeakLinkage()) return 'W';
if (isa<Function>(GV) && GV.hasInternalLinkage()) return 't';
if (isa<Function>(GV)) return 'T';
if (isa<GlobalVariable>(GV) && GV.hasInternalLinkage()) return 'd';
if (isa<GlobalVariable>(GV)) return 'D';
return '?';
}
void DumpSymbolNameForGlobalValue (GlobalValue &GV) {
static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
const std::string SymbolAddrStr = " "; // Not used yet...
char TypeChar = TypeCharForSymbol (GV);
if ((TypeChar != 'U') && UndefinedOnly)
@ -101,7 +102,7 @@ void DumpSymbolNameForGlobalValue (GlobalValue &GV) {
}
}
void DumpSymbolNamesFromModule (Module *M) {
static void DumpSymbolNamesFromModule(Module *M) {
const std::string &Filename = M->getModuleIdentifier ();
if (OutputFormat == posix && MultipleFiles) {
std::cout << Filename << ":\n";
@ -116,7 +117,7 @@ void DumpSymbolNamesFromModule (Module *M) {
std::for_each (M->global_begin (), M->global_end (), DumpSymbolNameForGlobalValue);
}
void DumpSymbolNamesFromFile (std::string &Filename) {
static void DumpSymbolNamesFromFile(std::string &Filename) {
std::string ErrorMessage;
sys::Path aPath(Filename);
if (Filename != "-") {
@ -135,16 +136,16 @@ void DumpSymbolNamesFromFile (std::string &Filename) {
}
} else if (aPath.isArchive()) {
std::string ErrMsg;
Archive* archive = Archive::OpenAndLoad(sys::Path(Filename),&ErrorMessage);
Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
if (!archive)
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
std::vector<Module *> Modules;
if (archive->getAllModules(Modules,&ErrorMessage)) {
if (archive->getAllModules(Modules, &ErrorMessage)) {
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
return;
}
MultipleFiles = true;
std::for_each (Modules.begin (), Modules.end (), DumpSymbolNamesFromModule);
std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule);
} else {
std::cerr << ToolName << ": " << Filename << ": "
<< "unrecognizable file type\n";
@ -153,6 +154,7 @@ void DumpSymbolNamesFromFile (std::string &Filename) {
}
int main(int argc, char **argv) {
llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n");
sys::PrintStackTraceOnErrorSignal();