2012-06-19 20:02:35 +02:00
|
|
|
//===------ utils/obj2yaml.cpp - obj2yaml conversion tool -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-07 07:18:51 +02:00
|
|
|
#include "Error.h"
|
2012-06-19 20:02:35 +02:00
|
|
|
#include "obj2yaml.h"
|
2012-12-04 11:37:14 +01:00
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/COFF.h"
|
2012-06-19 20:02:35 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
|
2013-04-08 10:55:14 +02:00
|
|
|
using namespace llvm;
|
2014-05-07 07:18:51 +02:00
|
|
|
using namespace llvm::object;
|
2013-04-08 10:55:14 +02:00
|
|
|
|
2014-06-13 05:07:50 +02:00
|
|
|
static std::error_code dumpObject(const ObjectFile &Obj) {
|
2014-05-07 07:18:51 +02:00
|
|
|
if (Obj.isCOFF())
|
|
|
|
return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
|
2014-05-14 07:07:47 +02:00
|
|
|
if (Obj.isELF())
|
|
|
|
return elf2yaml(outs(), Obj);
|
2014-05-07 07:18:51 +02:00
|
|
|
|
|
|
|
return obj2yaml_error::unsupported_obj_file_format;
|
2013-04-08 10:55:14 +02:00
|
|
|
}
|
2012-06-19 20:02:35 +02:00
|
|
|
|
2014-06-13 05:07:50 +02:00
|
|
|
static std::error_code dumpInput(StringRef File) {
|
2016-04-07 00:14:09 +02:00
|
|
|
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
|
|
|
|
if (!BinaryOrErr)
|
|
|
|
return errorToErrorCode(BinaryOrErr.takeError());
|
2014-05-07 07:18:51 +02:00
|
|
|
|
2014-08-19 20:44:46 +02:00
|
|
|
Binary &Binary = *BinaryOrErr.get().getBinary();
|
2016-06-24 22:42:28 +02:00
|
|
|
// Universal MachO is not a subclass of ObjectFile, so it needs to be handled
|
|
|
|
// here with the other binary types.
|
|
|
|
if (Binary.isMachO() || Binary.isMachOUniversalBinary())
|
|
|
|
return macho2yaml(outs(), Binary);
|
2014-05-07 07:18:51 +02:00
|
|
|
// TODO: If this is an archive, then burst it and dump each entry
|
2014-08-01 16:31:55 +02:00
|
|
|
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
|
2014-05-07 07:18:51 +02:00
|
|
|
return dumpObject(*Obj);
|
|
|
|
|
|
|
|
return obj2yaml_error::unrecognized_file_format;
|
|
|
|
}
|
2013-04-08 10:39:59 +02:00
|
|
|
|
|
|
|
cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
|
|
|
|
cl::init("-"));
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2012-06-19 20:02:35 +02:00
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
2016-06-09 02:53:21 +02:00
|
|
|
sys::PrintStackTraceOnErrorSignal(argv[0]);
|
2012-06-19 20:02:35 +02:00
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
2013-04-08 10:39:59 +02:00
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
2012-06-19 20:02:35 +02:00
|
|
|
|
2014-06-13 05:07:50 +02:00
|
|
|
if (std::error_code EC = dumpInput(InputFilename)) {
|
2014-05-07 07:18:51 +02:00
|
|
|
errs() << "Error: '" << EC.message() << "'\n";
|
|
|
|
return 1;
|
2012-06-19 20:02:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|