OLD | NEW |
(Empty) | |
| 1 //===-- pnacl-bcdis.cpp - Disassemble pnacl bitcode -----------------------===// |
| 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 /// TODO(kschimpf): Add disassembling abbreviations. |
| 11 |
| 12 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
| 13 #include "llvm/Support/CommandLine.h" |
| 14 #include "llvm/Support/FileSystem.h" |
| 15 #include "llvm/Support/ManagedStatic.h" |
| 16 #include "llvm/Support/MemoryBuffer.h" |
| 17 #include "llvm/Support/PrettyStackTrace.h" |
| 18 #include "llvm/Support/Signals.h" |
| 19 #include "llvm/Support/ToolOutputFile.h" |
| 20 #include "llvm/Support/raw_ostream.h" |
| 21 #include <system_error> |
| 22 |
| 23 namespace { |
| 24 |
| 25 using namespace llvm; |
| 26 |
| 27 // The input file to read. |
| 28 static cl::opt<std::string> |
| 29 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
| 30 |
| 31 // The output file to generate. |
| 32 static cl::opt<std::string> |
| 33 OutputFilename("o", cl::desc("Specify output filename"), |
| 34 cl::value_desc("filename"), cl::init("-")); |
| 35 |
| 36 static cl::opt<bool> |
| 37 NoRecords("no-records", |
| 38 cl::desc("Don't include records"), |
| 39 cl::init(false)); |
| 40 |
| 41 static cl::opt<bool> |
| 42 NoAssembly("no-assembly", |
| 43 cl::desc("Don't include assembly"), |
| 44 cl::init(false)); |
| 45 |
| 46 // Reads and disassembles the bitcode file. Returns false |
| 47 // if successful, true otherwise. |
| 48 static bool DisassembleBitcode() { |
| 49 // Open the bitcode file and put into a buffer. |
| 50 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = |
| 51 MemoryBuffer::getFileOrSTDIN(InputFilename); |
| 52 if (std::error_code EC = ErrOrFile.getError()) { |
| 53 errs() << "Error reading '" << InputFilename << "': " << EC.message() |
| 54 << "\n"; |
| 55 return true; |
| 56 } |
| 57 |
| 58 // Create a stream to output the bitcode text to. |
| 59 std::error_code EC; |
| 60 raw_fd_ostream Output(OutputFilename, EC, sys::fs::F_None); |
| 61 if (EC) { |
| 62 errs() << EC.message() << '\n'; |
| 63 return true; |
| 64 } |
| 65 |
| 66 // Parse the the bitcode file. |
| 67 return NaClObjDump(ErrOrFile.get().release(), Output, NoRecords, NoAssembly); |
| 68 } |
| 69 |
| 70 } |
| 71 |
| 72 int main(int argc, char **argv) { |
| 73 // Print a stack trace if we signal out. |
| 74 sys::PrintStackTraceOnErrorSignal(); |
| 75 PrettyStackTraceProgram X(argc, argv); |
| 76 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 77 cl::ParseCommandLineOptions(argc, argv, "pnacl-bccompress file analyzer\n"); |
| 78 |
| 79 if (DisassembleBitcode()) return 1; |
| 80 return 0; |
| 81 } |
OLD | NEW |