Chris Lattner | f9f065e | 2009-06-18 23:04:45 +0000 | [diff] [blame^] | 1 | //===-- llvm-dis.cpp - The low-level LLVM disassembler --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This utility may be invoked in the following manner: |
| 11 | // llvm-dis [options] - Read LLVM bitcode from stdin, write asm to stdout |
| 12 | // llvm-dis [options] x.bc - Read LLVM bitcode from the x.bc file, write asm |
| 13 | // to the x.ll file. |
| 14 | // Options: |
| 15 | // --help - Output information about command line switches |
| 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #include "llvm/Support/CommandLine.h" |
| 20 | #include "llvm/Support/ManagedStatic.h" |
| 21 | #include "llvm/Support/MemoryBuffer.h" |
| 22 | #include "llvm/Support/PrettyStackTrace.h" |
| 23 | #include "llvm/Support/raw_ostream.h" |
| 24 | #include "llvm/System/Signals.h" |
| 25 | using namespace llvm; |
| 26 | |
| 27 | static cl::opt<std::string> |
| 28 | InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-")); |
| 29 | |
| 30 | static cl::opt<std::string> |
| 31 | OutputFilename("o", cl::desc("Output filename"), |
| 32 | cl::value_desc("filename")); |
| 33 | |
| 34 | int main(int argc, char **argv) { |
| 35 | // Print a stack trace if we signal out. |
| 36 | sys::PrintStackTraceOnErrorSignal(); |
| 37 | PrettyStackTraceProgram X(argc, argv); |
| 38 | |
| 39 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 40 | |
| 41 | cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); |
| 42 | |
| 43 | std::string ErrorMessage; |
| 44 | |
| 45 | MemoryBuffer *Buffer |
| 46 | = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage); |
| 47 | |
| 48 | if (Buffer == 0) { |
| 49 | errs() << argv[0] << ": "; |
| 50 | if (ErrorMessage.size()) |
| 51 | errs() << ErrorMessage << "\n"; |
| 52 | else |
| 53 | errs() << "input file didn't read correctly.\n"; |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |