| 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 | |
| 14 | #include "llvm/BinaryFormat/COFF.h" |
| 15 | #include "llvm/Object/COFF.h" |
| 16 | #include "llvm/Object/COFFImportFile.h" |
| 17 | #include "llvm/Support/ScopedPrinter.h" |
| 18 | |
| 19 | using namespace llvm::object; |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | void dumpCOFFImportFile(const COFFImportFile *File, ScopedPrinter &Writer) { |
| 24 | Writer.startLine() << '\n'; |
| 25 | Writer.printString(Label: "File" , Value: File->getFileName()); |
| 26 | Writer.printString(Label: "Format" , Value: File->getFileFormatName()); |
| 27 | |
| 28 | const coff_import_header *H = File->getCOFFImportHeader(); |
| 29 | switch (H->getType()) { |
| 30 | case COFF::IMPORT_CODE: Writer.printString(Label: "Type" , Value: "code" ); break; |
| 31 | case COFF::IMPORT_DATA: Writer.printString(Label: "Type" , Value: "data" ); break; |
| 32 | case COFF::IMPORT_CONST: Writer.printString(Label: "Type" , Value: "const" ); break; |
| 33 | } |
| 34 | |
| 35 | switch (H->getNameType()) { |
| 36 | case COFF::IMPORT_ORDINAL: |
| 37 | Writer.printString(Label: "Name type" , Value: "ordinal" ); |
| 38 | break; |
| 39 | case COFF::IMPORT_NAME: |
| 40 | Writer.printString(Label: "Name type" , Value: "name" ); |
| 41 | break; |
| 42 | case COFF::IMPORT_NAME_NOPREFIX: |
| 43 | Writer.printString(Label: "Name type" , Value: "noprefix" ); |
| 44 | break; |
| 45 | case COFF::IMPORT_NAME_UNDECORATE: |
| 46 | Writer.printString(Label: "Name type" , Value: "undecorate" ); |
| 47 | break; |
| 48 | case COFF::IMPORT_NAME_EXPORTAS: |
| 49 | Writer.printString(Label: "Name type" , Value: "export as" ); |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | if (H->getNameType() != COFF::IMPORT_ORDINAL) |
| 54 | Writer.printString(Label: "Export name" , Value: File->getExportName()); |
| 55 | |
| 56 | for (const object::BasicSymbolRef &Sym : File->symbols()) { |
| 57 | raw_ostream &OS = Writer.startLine(); |
| 58 | OS << "Symbol: " ; |
| 59 | cantFail(Err: Sym.printName(OS)); |
| 60 | OS << "\n" ; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } // namespace llvm |
| 65 | |