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