1 //===------ utils/obj2yaml.cpp - obj2yaml conversion tool -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
21 namespace objyaml { // generic yaml-writing specific routines
23 unsigned char printable(unsigned char Ch) {
24 return Ch >= ' ' && Ch <= '~' ? Ch : '.';
27 raw_ostream &writeHexStream(raw_ostream &Out, const ArrayRef<uint8_t> arr) {
28 const char *hex = "0123456789ABCDEF";
31 typedef ArrayRef<uint8_t>::const_iterator iter_t;
32 const iter_t end = arr.end();
33 for (iter_t iter = arr.begin(); iter != end; ++iter)
34 Out << hex[(*iter >> 4) & 0x0F] << hex[(*iter & 0x0F)];
37 for (iter_t iter = arr.begin(); iter != end; ++iter)
38 Out << printable(*iter);
44 raw_ostream &writeHexNumber(raw_ostream &Out, unsigned long long N) {
51 } // end namespace yaml
59 cl::opt<ObjectFileType> InputFormat(
60 cl::desc("Choose input format"),
61 cl::values(clEnumVal(coff, "process COFF object files"), clEnumValEnd));
63 cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
66 int main(int argc, char *argv[]) {
67 cl::ParseCommandLineOptions(argc, argv);
68 sys::PrintStackTraceOnErrorSignal();
69 PrettyStackTraceProgram X(argc, argv);
70 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
72 // Process the input file
73 OwningPtr<MemoryBuffer> buf;
75 // TODO: If this is an archive, then burst it and dump each entry
76 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, buf)) {
77 errs() << "Error: '" << ec.message() << "' opening file '" << InputFilename
80 ec = coff2yaml(outs(), buf.take());
82 errs() << "Error: " << ec.message() << " dumping COFF file\n";