[llvm-commits] CVS: llvm/tools/llvm-nm/Makefile llvm-nm.cpp

Chris Lattner sabre at nondot.org
Sat May 5 22:36:36 PDT 2007



Changes in directory llvm/tools/llvm-nm:

Makefile updated: 1.9 -> 1.10
llvm-nm.cpp updated: 1.33 -> 1.34
---
Log message:

add bitcode reading support to llvm-nm


---
Diffs of the changes:  (+33 -24)

 Makefile    |    3 +--
 llvm-nm.cpp |   54 ++++++++++++++++++++++++++++++++----------------------
 2 files changed, 33 insertions(+), 24 deletions(-)


Index: llvm/tools/llvm-nm/Makefile
diff -u llvm/tools/llvm-nm/Makefile:1.9 llvm/tools/llvm-nm/Makefile:1.10
--- llvm/tools/llvm-nm/Makefile:1.9	Mon Sep  4 00:59:09 2006
+++ llvm/tools/llvm-nm/Makefile	Sun May  6 00:36:18 2007
@@ -9,7 +9,6 @@
 LEVEL = ../..
 
 TOOLNAME = llvm-nm
-LINK_COMPONENTS = archive bcreader
-REQUIRES_EH := 1
+LINK_COMPONENTS = archive bcreader bitreader
 
 include $(LEVEL)/Makefile.common


Index: llvm/tools/llvm-nm/llvm-nm.cpp
diff -u llvm/tools/llvm-nm/llvm-nm.cpp:1.33 llvm/tools/llvm-nm/llvm-nm.cpp:1.34
--- llvm/tools/llvm-nm/llvm-nm.cpp:1.33	Thu Mar 29 14:49:07 2007
+++ llvm/tools/llvm-nm/llvm-nm.cpp	Sun May  6 00:36:18 2007
@@ -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 @@
       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 @@
 
 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;
 }






More information about the llvm-commits mailing list