obj2yaml.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "Error.h"
  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. using namespace llvm;
  18. using namespace llvm::object;
  19. static std::error_code dumpObject(const ObjectFile &Obj) {
  20. if (Obj.isCOFF())
  21. return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
  22. if (Obj.isELF())
  23. return elf2yaml(outs(), Obj);
  24. return obj2yaml_error::unsupported_obj_file_format;
  25. }
  26. static std::error_code dumpInput(StringRef File) {
  27. if (File != "-" && !sys::fs::exists(File))
  28. return obj2yaml_error::file_not_found;
  29. ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
  30. if (std::error_code EC = BinaryOrErr.getError())
  31. return EC;
  32. Binary &Binary = *BinaryOrErr.get().getBinary();
  33. // TODO: If this is an archive, then burst it and dump each entry
  34. if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
  35. return dumpObject(*Obj);
  36. return obj2yaml_error::unrecognized_file_format;
  37. }
  38. cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
  39. cl::init("-"));
  40. // HLSL Change: changed calling convention to __cdecl
  41. int __cdecl main(int argc, char *argv[]) {
  42. cl::ParseCommandLineOptions(argc, argv);
  43. sys::PrintStackTraceOnErrorSignal();
  44. PrettyStackTraceProgram X(argc, argv);
  45. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
  46. if (std::error_code EC = dumpInput(InputFilename)) {
  47. errs() << "Error: '" << EC.message() << "'\n";
  48. return 1;
  49. }
  50. return 0;
  51. }