8d128b35394488359f75578570f5d49be2c3839c
[oota-llvm.git] / tools / obj2yaml / obj2yaml.cpp
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"
11 #include "llvm/ADT/OwningPtr.h"
12 #include "llvm/Object/Archive.h"
13 #include "llvm/Object/COFF.h"
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
19 using namespace llvm;
20
21 namespace {
22 enum ObjectFileType {
23   coff
24 };
25 }
26
27 cl::opt<ObjectFileType> InputFormat(
28     cl::desc("Choose input format"),
29     cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd));
30
31 cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
32                                    cl::init("-"));
33
34 int main(int argc, char *argv[]) {
35   cl::ParseCommandLineOptions(argc, argv);
36   sys::PrintStackTraceOnErrorSignal();
37   PrettyStackTraceProgram X(argc, argv);
38   llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
39
40   // Process the input file
41   OwningPtr<MemoryBuffer> buf;
42
43   // TODO: If this is an archive, then burst it and dump each entry
44   if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) {
45     errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename
46            << "'\n";
47   } else {
48     ec = coff2yaml(outs(), buf.take());
49     if (ec)
50       errs() << "Error: " << ec.message() << " dumping COFF file\n";
51   }
52
53   return 0;
54 }