blob: 8d128b35394488359f75578570f5d49be2c3839c [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"
Marshall Clowc57b8882012-06-19 18:02:35 +000011#include "llvm/ADT/OwningPtr.h"
Chandler Carruth4ffd89f2012-12-04 10:37:14 +000012#include "llvm/Object/Archive.h"
13#include "llvm/Object/COFF.h"
Marshall Clowc57b8882012-06-19 18:02:35 +000014#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 Carruth97034bb2013-04-08 08:55:14 +000019using namespace llvm;
20
Chandler Carruth97034bb2013-04-08 08:55:14 +000021namespace {
Chandler Carruth724a7b12013-04-08 08:39:59 +000022enum ObjectFileType {
23 coff
24};
Chandler Carruth97034bb2013-04-08 08:55:14 +000025}
Marshall Clowc57b8882012-06-19 18:02:35 +000026
27cl::opt<ObjectFileType> InputFormat(
Chandler Carruth724a7b12013-04-08 08:39:59 +000028 cl::desc("Choose input format"),
29 cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd));
Marshall Clowc57b8882012-06-19 18:02:35 +000030
Chandler Carruth724a7b12013-04-08 08:39:59 +000031cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
32 cl::init("-"));
33
34int main(int argc, char *argv[]) {
Marshall Clowc57b8882012-06-19 18:02:35 +000035 cl::ParseCommandLineOptions(argc, argv);
36 sys::PrintStackTraceOnErrorSignal();
37 PrettyStackTraceProgram X(argc, argv);
Chandler Carruth724a7b12013-04-08 08:39:59 +000038 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Marshall Clowc57b8882012-06-19 18:02:35 +000039
Chandler Carruth724a7b12013-04-08 08:39:59 +000040 // Process the input file
Marshall Clowc57b8882012-06-19 18:02:35 +000041 OwningPtr<MemoryBuffer> buf;
42
Chandler Carruth724a7b12013-04-08 08:39:59 +000043 // TODO: If this is an archive, then burst it and dump each entry
44 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) {
Chandler Carruth97034bb2013-04-08 08:55:14 +000045 errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename
46 << "'\n";
Chandler Carruth724a7b12013-04-08 08:39:59 +000047 } else {
Chandler Carruth97034bb2013-04-08 08:55:14 +000048 ec = coff2yaml(outs(), buf.take());
Marshall Clowc57b8882012-06-19 18:02:35 +000049 if (ec)
Chandler Carruth97034bb2013-04-08 08:55:14 +000050 errs() << "Error: " << ec.message() << " dumping COFF file\n";
Marshall Clowc57b8882012-06-19 18:02:35 +000051 }
52
53 return 0;
54}