[llvm-commits] CVS: llvm/tools/llvm-dis/llvm-dis.cpp

Chris Lattner sabre at nondot.org
Sun Apr 29 00:54:57 PDT 2007



Changes in directory llvm/tools/llvm-dis:

llvm-dis.cpp updated: 1.58 -> 1.59
---
Log message:

Switch the bitcode reader interface to take a MemoryBuffer instead of knowing
anything about disk I/O itself.  This greatly simplifies its interface -
eliminating the need for the ReaderWrappers.cpp file.

This adds a new option to llvm-dis (-bitcode) which instructs it to read
the input file as bitcode.  Until/unless the bytecode reader is taught to
read from MemoryBuffer, there is no way to handle stdin reading without it.

I don't plan to switch the bytecode reader over, I'd rather delete it :),
so the option will stay around temporarily.



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

 llvm-dis.cpp |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)


Index: llvm/tools/llvm-dis/llvm-dis.cpp
diff -u llvm/tools/llvm-dis/llvm-dis.cpp:1.58 llvm/tools/llvm-dis/llvm-dis.cpp:1.59
--- llvm/tools/llvm-dis/llvm-dis.cpp:1.58	Sun Apr 22 01:35:20 2007
+++ llvm/tools/llvm-dis/llvm-dis.cpp	Sun Apr 29 02:54:31 2007
@@ -24,6 +24,7 @@
 #include "llvm/Support/Compressor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/System/Signals.h"
 #include <iostream>
@@ -44,6 +45,9 @@
 static cl::opt<bool>
 DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden);
 
+static cl::opt<bool>
+Bitcode("bitcode", cl::desc("Read a bitcode file"));
+
 int main(int argc, char **argv) {
   llvm_shutdown_obj X;  // Call llvm_shutdown() on exit.
   try {
@@ -55,12 +59,26 @@
 
     std::auto_ptr<Module> M;
    
-    if (InputFilename != "-") 
-      M.reset(ParseBitcodeFile(InputFilename, &ErrorMessage));
-    
-    if (M.get() == 0)
-      M.reset(ParseBytecodeFile(InputFilename,Compressor::decompressToNewBuffer,
+    if (Bitcode) {
+      MemoryBuffer *Buffer;
+      if (InputFilename == "-") {
+        Buffer = MemoryBuffer::getSTDIN();
+      } else {
+        Buffer = MemoryBuffer::getFile(&InputFilename[0], InputFilename.size());
+      }
+
+      if (Buffer == 0)
+        ErrorMessage = "Error reading file '" + InputFilename + "'";
+      else
+        M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      
+      delete Buffer;
+    } else {
+      M.reset(ParseBytecodeFile(InputFilename,
+                                Compressor::decompressToNewBuffer,
                                 &ErrorMessage));
+    }
+
     if (M.get() == 0) {
       cerr << argv[0] << ": ";
       if (ErrorMessage.size())
@@ -69,7 +87,7 @@
         cerr << "bytecode didn't read correctly.\n";
       return 1;
     }
-
+    
     if (DontPrint) {
       // Just use stdout.  We won't actually print anything on it.
     } else if (OutputFilename != "") {   // Specified an output filename?






More information about the llvm-commits mailing list