summaryrefslogtreecommitdiff
path: root/tools/llvm-nm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-06 05:36:18 +0000
committerChris Lattner <sabre@nondot.org>2007-05-06 05:36:18 +0000
commit4d5aad2d99233fdee38cbbf844f65b7a74073954 (patch)
tree668adb91b9f2b351c7ca7e4ffd8491ae40d7886e /tools/llvm-nm
parentf283a5e53a99d13035a9e783acff80d4ea064a92 (diff)
downloadllvm-4d5aad2d99233fdee38cbbf844f65b7a74073954.tar.gz
llvm-4d5aad2d99233fdee38cbbf844f65b7a74073954.tar.bz2
llvm-4d5aad2d99233fdee38cbbf844f65b7a74073954.tar.xz
add bitcode reading support to llvm-nm
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36847 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-nm')
-rw-r--r--tools/llvm-nm/Makefile3
-rw-r--r--tools/llvm-nm/llvm-nm.cpp54
2 files changed, 33 insertions, 24 deletions
diff --git a/tools/llvm-nm/Makefile b/tools/llvm-nm/Makefile
index 5e18c4a162..42233c7894 100644
--- a/tools/llvm-nm/Makefile
+++ b/tools/llvm-nm/Makefile
@@ -9,7 +9,6 @@
LEVEL = ../..
TOOLNAME = llvm-nm
-LINK_COMPONENTS = archive bcreader
-REQUIRES_EH := 1
+LINK_COMPONENTS = archive bcreader bitreader
include $(LEVEL)/Makefile.common
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index d195f70083..5b98be7056 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -17,19 +17,22 @@
//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Signals.h"
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cstring>
#include <iostream>
-
using namespace llvm;
+cl::opt<bool> Bitcode("bitcode");
+
namespace {
enum OutputFormatTy { bsd, sysv, posix };
cl::opt<OutputFormatTy>
@@ -132,6 +135,20 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
return;
}
+ } else if (aPath.isBitcodeFile()) {
+ std::auto_ptr<MemoryBuffer> Buffer(
+ MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
+ Module *Result = 0;
+ if (Buffer.get())
+ Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
+
+ if (Result)
+ DumpSymbolNamesFromModule(Result);
+ else {
+ std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
+ return;
+ }
+
} else if (aPath.isArchive()) {
std::string ErrMsg;
Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
@@ -153,27 +170,20 @@ static 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();
-
- ToolName = argv[0];
- if (BSDFormat) OutputFormat = bsd;
- if (POSIXFormat) OutputFormat = posix;
-
- switch (InputFilenames.size()) {
- case 0: InputFilenames.push_back("-");
- case 1: break;
- default: MultipleFiles = true;
- }
+ cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n");
+ sys::PrintStackTraceOnErrorSignal();
- std::for_each (InputFilenames.begin (), InputFilenames.end (),
- DumpSymbolNamesFromFile);
- return 0;
- } catch (const std::string& msg) {
- std::cerr << argv[0] << ": " << msg << "\n";
- } catch (...) {
- std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+ ToolName = argv[0];
+ if (BSDFormat) OutputFormat = bsd;
+ if (POSIXFormat) OutputFormat = posix;
+
+ switch (InputFilenames.size()) {
+ case 0: InputFilenames.push_back("-");
+ case 1: break;
+ default: MultipleFiles = true;
}
- return 1;
+
+ std::for_each(InputFilenames.begin(), InputFilenames.end(),
+ DumpSymbolNamesFromFile);
+ return 0;
}