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