blob: fa6118ee4d6ca13f65e285dca52418579ab0072f [file] [log] [blame]
Rui Ueyama93210892015-08-28 10:27:50 +00001//===-- COFFImportDumper.cpp - COFF import library dumper -------*- 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///
10/// \file
11/// \brief This file implements the COFF import library dumper for llvm-readobj.
12///
13//===----------------------------------------------------------------------===//
14
Zachary Turner264b5d92017-06-07 03:48:56 +000015#include "llvm/BinaryFormat/COFF.h"
Rui Ueyama93210892015-08-28 10:27:50 +000016#include "llvm/Object/COFF.h"
17#include "llvm/Object/COFFImportFile.h"
Sam Clegg88e9a152018-01-10 00:14:19 +000018#include "llvm/Support/ScopedPrinter.h"
Rui Ueyama93210892015-08-28 10:27:50 +000019
20using namespace llvm::object;
21
22namespace llvm {
23
Sam Clegg88e9a152018-01-10 00:14:19 +000024void dumpCOFFImportFile(const COFFImportFile *File, ScopedPrinter &Writer) {
25 Writer.startLine() << '\n';
26 Writer.printString("File", File->getFileName());
27 Writer.printString("Format", "COFF-import-file");
Rui Ueyama93210892015-08-28 10:27:50 +000028
29 const coff_import_header *H = File->getCOFFImportHeader();
30 switch (H->getType()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000031 case COFF::IMPORT_CODE: Writer.printString("Type", "code"); break;
32 case COFF::IMPORT_DATA: Writer.printString("Type", "data"); break;
33 case COFF::IMPORT_CONST: Writer.printString("Type", "const"); break;
Rui Ueyama93210892015-08-28 10:27:50 +000034 }
35
36 switch (H->getNameType()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000037 case COFF::IMPORT_ORDINAL:
38 Writer.printString("Name type", "ordinal");
39 break;
40 case COFF::IMPORT_NAME:
41 Writer.printString("Name type", "name");
42 break;
43 case COFF::IMPORT_NAME_NOPREFIX:
44 Writer.printString("Name type", "noprefix");
45 break;
46 case COFF::IMPORT_NAME_UNDECORATE:
47 Writer.printString("Name type", "undecorate");
48 break;
Rui Ueyama93210892015-08-28 10:27:50 +000049 }
50
51 for (const object::BasicSymbolRef &Sym : File->symbols()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000052 raw_ostream &OS = Writer.startLine();
53 OS << "Symbol: ";
54 Sym.printName(OS);
55 OS << "\n";
Rui Ueyama93210892015-08-28 10:27:50 +000056 }
57}
58
59} // namespace llvm