summaryrefslogtreecommitdiff
path: root/tools/llvm-dis
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-29 07:54:31 +0000
committerChris Lattner <sabre@nondot.org>2007-04-29 07:54:31 +0000
commitc453f76e2b4d7fd1e042b5b6d4c20556779186df (patch)
treea24882c0c4c773a77d7e16562335fe8364ffc47d /tools/llvm-dis
parent333ffd4abfcc3be32a945dc73c81adeafde1ba6b (diff)
downloadllvm-c453f76e2b4d7fd1e042b5b6d4c20556779186df.tar.gz
llvm-c453f76e2b4d7fd1e042b5b6d4c20556779186df.tar.bz2
llvm-c453f76e2b4d7fd1e042b5b6d4c20556779186df.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-dis')
-rw-r--r--tools/llvm-dis/llvm-dis.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index bb91ad6fce..6065e9ba5e 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -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 @@ Force("f", cl::desc("Overwrite output files"));
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 @@ int main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
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?