COFFImportDumper.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===-- COFFImportDumper.cpp - COFF import library dumper -------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// \file
  10. /// This file implements the COFF import library dumper for llvm-readobj.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/BinaryFormat/COFF.h"
  14. #include "llvm/Object/COFF.h"
  15. #include "llvm/Object/COFFImportFile.h"
  16. #include "llvm/Support/ScopedPrinter.h"
  17. using namespace llvm::object;
  18. namespace llvm {
  19. void dumpCOFFImportFile(const COFFImportFile *File, ScopedPrinter &Writer) {
  20. Writer.startLine() << '\n';
  21. Writer.printString("File", File->getFileName());
  22. Writer.printString("Format", "COFF-import-file");
  23. const coff_import_header *H = File->getCOFFImportHeader();
  24. switch (H->getType()) {
  25. case COFF::IMPORT_CODE: Writer.printString("Type", "code"); break;
  26. case COFF::IMPORT_DATA: Writer.printString("Type", "data"); break;
  27. case COFF::IMPORT_CONST: Writer.printString("Type", "const"); break;
  28. }
  29. switch (H->getNameType()) {
  30. case COFF::IMPORT_ORDINAL:
  31. Writer.printString("Name type", "ordinal");
  32. break;
  33. case COFF::IMPORT_NAME:
  34. Writer.printString("Name type", "name");
  35. break;
  36. case COFF::IMPORT_NAME_NOPREFIX:
  37. Writer.printString("Name type", "noprefix");
  38. break;
  39. case COFF::IMPORT_NAME_UNDECORATE:
  40. Writer.printString("Name type", "undecorate");
  41. break;
  42. }
  43. for (const object::BasicSymbolRef &Sym : File->symbols()) {
  44. raw_ostream &OS = Writer.startLine();
  45. OS << "Symbol: ";
  46. cantFail(Sym.printName(OS));
  47. OS << "\n";
  48. }
  49. }
  50. } // namespace llvm