blob: c9d5e82263db111899b3fece970d58ed836376a3 [file] [log] [blame]
Rui Ueyama93210892015-08-28 10:27:50 +00001//===-- COFFImportDumper.cpp - COFF import library dumper -------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Rui Ueyama93210892015-08-28 10:27:50 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file implements the COFF import library dumper for llvm-readobj.
Rui Ueyama93210892015-08-28 10:27:50 +000011///
12//===----------------------------------------------------------------------===//
13
Zachary Turner264b5d92017-06-07 03:48:56 +000014#include "llvm/BinaryFormat/COFF.h"
Rui Ueyama93210892015-08-28 10:27:50 +000015#include "llvm/Object/COFF.h"
16#include "llvm/Object/COFFImportFile.h"
Sam Clegg88e9a152018-01-10 00:14:19 +000017#include "llvm/Support/ScopedPrinter.h"
Rui Ueyama93210892015-08-28 10:27:50 +000018
19using namespace llvm::object;
20
21namespace llvm {
22
Sam Clegg88e9a152018-01-10 00:14:19 +000023void dumpCOFFImportFile(const COFFImportFile *File, ScopedPrinter &Writer) {
24 Writer.startLine() << '\n';
25 Writer.printString("File", File->getFileName());
26 Writer.printString("Format", "COFF-import-file");
Rui Ueyama93210892015-08-28 10:27:50 +000027
28 const coff_import_header *H = File->getCOFFImportHeader();
29 switch (H->getType()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000030 case COFF::IMPORT_CODE: Writer.printString("Type", "code"); break;
31 case COFF::IMPORT_DATA: Writer.printString("Type", "data"); break;
32 case COFF::IMPORT_CONST: Writer.printString("Type", "const"); break;
Rui Ueyama93210892015-08-28 10:27:50 +000033 }
34
35 switch (H->getNameType()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000036 case COFF::IMPORT_ORDINAL:
37 Writer.printString("Name type", "ordinal");
38 break;
39 case COFF::IMPORT_NAME:
40 Writer.printString("Name type", "name");
41 break;
42 case COFF::IMPORT_NAME_NOPREFIX:
43 Writer.printString("Name type", "noprefix");
44 break;
45 case COFF::IMPORT_NAME_UNDECORATE:
46 Writer.printString("Name type", "undecorate");
47 break;
Rui Ueyama93210892015-08-28 10:27:50 +000048 }
49
50 for (const object::BasicSymbolRef &Sym : File->symbols()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000051 raw_ostream &OS = Writer.startLine();
52 OS << "Symbol: ";
Fangrui Songe357ca82019-05-10 09:59:04 +000053 cantFail(Sym.printName(OS));
Sam Clegg88e9a152018-01-10 00:14:19 +000054 OS << "\n";
Rui Ueyama93210892015-08-28 10:27:50 +000055 }
56}
57
58} // namespace llvm