| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 1 | //===------ utils/obj2yaml.cpp - obj2yaml conversion tool -------*- C++ -*-===// |
| 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 | #include "obj2yaml.h" |
| Chandler Carruth | 4ffd89f | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 11 | #include "llvm/Object/Archive.h" |
| 12 | #include "llvm/Object/COFF.h" |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 13 | #include "llvm/Support/CommandLine.h" |
| 14 | #include "llvm/Support/ManagedStatic.h" |
| 15 | #include "llvm/Support/PrettyStackTrace.h" |
| 16 | #include "llvm/Support/Signals.h" |
| 17 | |
| Chandler Carruth | 97034bb | 2013-04-08 08:55:14 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
| Chandler Carruth | 97034bb | 2013-04-08 08:55:14 +0000 | [diff] [blame] | 20 | namespace { |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 21 | enum ObjectFileType { |
| 22 | coff |
| 23 | }; |
| Chandler Carruth | 97034bb | 2013-04-08 08:55:14 +0000 | [diff] [blame] | 24 | } |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 25 | |
| 26 | cl::opt<ObjectFileType> InputFormat( |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 27 | cl::desc("Choose input format"), |
| 28 | cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd)); |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 29 | |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 30 | cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"), |
| 31 | cl::init("-")); |
| 32 | |
| 33 | int main(int argc, char *argv[]) { |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 34 | cl::ParseCommandLineOptions(argc, argv); |
| 35 | sys::PrintStackTraceOnErrorSignal(); |
| 36 | PrettyStackTraceProgram X(argc, argv); |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 37 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 38 | |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 39 | // Process the input file |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 40 | std::unique_ptr<MemoryBuffer> buf; |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 41 | |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 42 | // TODO: If this is an archive, then burst it and dump each entry |
| 43 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) { |
| Chandler Carruth | 97034bb | 2013-04-08 08:55:14 +0000 | [diff] [blame] | 44 | errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename |
| 45 | << "'\n"; |
| Chandler Carruth | 724a7b1 | 2013-04-08 08:39:59 +0000 | [diff] [blame] | 46 | } else { |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 47 | ec = coff2yaml(outs(), buf.release()); |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 48 | if (ec) |
| Chandler Carruth | 97034bb | 2013-04-08 08:55:14 +0000 | [diff] [blame] | 49 | errs() << "Error: " << ec.message() << " dumping COFF file\n"; |
| Marshall Clow | c57b888 | 2012-06-19 18:02:35 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return 0; |
| 53 | } |