blob: 38779fe45656bb310812f479a39400e7e5c325ed [file] [log] [blame]
Marshall Clowc57b8882012-06-19 18:02:35 +00001//===------ 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 Carruth4ffd89f2012-12-04 10:37:14 +000011#include "llvm/Object/Archive.h"
12#include "llvm/Object/COFF.h"
Marshall Clowc57b8882012-06-19 18:02:35 +000013#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 Carruth97034bb2013-04-08 08:55:14 +000018using namespace llvm;
19
Chandler Carruth97034bb2013-04-08 08:55:14 +000020namespace {
Chandler Carruth724a7b12013-04-08 08:39:59 +000021enum ObjectFileType {
22 coff
23};
Chandler Carruth97034bb2013-04-08 08:55:14 +000024}
Marshall Clowc57b8882012-06-19 18:02:35 +000025
26cl::opt<ObjectFileType> InputFormat(
Chandler Carruth724a7b12013-04-08 08:39:59 +000027 cl::desc("Choose input format"),
28 cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd));
Marshall Clowc57b8882012-06-19 18:02:35 +000029
Chandler Carruth724a7b12013-04-08 08:39:59 +000030cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
31 cl::init("-"));
32
33int main(int argc, char *argv[]) {
Marshall Clowc57b8882012-06-19 18:02:35 +000034 cl::ParseCommandLineOptions(argc, argv);
35 sys::PrintStackTraceOnErrorSignal();
36 PrettyStackTraceProgram X(argc, argv);
Chandler Carruth724a7b12013-04-08 08:39:59 +000037 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Marshall Clowc57b8882012-06-19 18:02:35 +000038
Chandler Carruth724a7b12013-04-08 08:39:59 +000039 // Process the input file
Stephen Hines36b56882014-04-23 16:57:46 -070040 std::unique_ptr<MemoryBuffer> buf;
Marshall Clowc57b8882012-06-19 18:02:35 +000041
Chandler Carruth724a7b12013-04-08 08:39:59 +000042 // TODO: If this is an archive, then burst it and dump each entry
43 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) {
Chandler Carruth97034bb2013-04-08 08:55:14 +000044 errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename
45 << "'\n";
Chandler Carruth724a7b12013-04-08 08:39:59 +000046 } else {
Stephen Hines36b56882014-04-23 16:57:46 -070047 ec = coff2yaml(outs(), buf.release());
Marshall Clowc57b8882012-06-19 18:02:35 +000048 if (ec)
Chandler Carruth97034bb2013-04-08 08:55:14 +000049 errs() << "Error: " << ec.message() << " dumping COFF file\n";
Marshall Clowc57b8882012-06-19 18:02:35 +000050 }
51
52 return 0;
53}