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