]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/CompactTypeDumpVisitor.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304460, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / CompactTypeDumpVisitor.cpp
1 //===-- CompactTypeDumpVisitor.cpp - CodeView type info 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 #include "CompactTypeDumpVisitor.h"
11 #include "llvm/DebugInfo/CodeView/TypeDatabase.h"
12 #include "llvm/Support/FormatVariadic.h"
13 #include "llvm/Support/ScopedPrinter.h"
14
15 using namespace llvm;
16 using namespace llvm::codeview;
17 using namespace llvm::pdb;
18
19 static const EnumEntry<TypeLeafKind> LeafTypeNames[] = {
20 #define CV_TYPE(enum, val) {#enum, enum},
21 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
22 };
23
24 static StringRef getLeafName(TypeLeafKind K) {
25   for (const auto &E : LeafTypeNames) {
26     if (E.Value == K)
27       return E.Name;
28   }
29   return StringRef();
30 }
31
32 CompactTypeDumpVisitor::CompactTypeDumpVisitor(TypeCollection &Types,
33                                                ScopedPrinter *W)
34     : CompactTypeDumpVisitor(Types, TypeIndex(TypeIndex::FirstNonSimpleIndex),
35                              W) {}
36
37 CompactTypeDumpVisitor::CompactTypeDumpVisitor(TypeCollection &Types,
38                                                TypeIndex FirstTI,
39                                                ScopedPrinter *W)
40     : W(W), TI(FirstTI), Offset(0), Types(Types) {}
41
42 Error CompactTypeDumpVisitor::visitTypeBegin(CVType &Record) {
43   return Error::success();
44 }
45
46 Error CompactTypeDumpVisitor::visitTypeEnd(CVType &Record) {
47   uint32_t I = TI.getIndex();
48   StringRef Leaf = getLeafName(Record.Type);
49   StringRef Name = Types.getTypeName(TI);
50   W->printString(
51       llvm::formatv("Index: {0:x} ({1:N} bytes, offset {2:N}) {3} \"{4}\"", I,
52                     Record.length(), Offset, Leaf, Name)
53           .str());
54
55   Offset += Record.length();
56   TI.setIndex(TI.getIndex() + 1);
57
58   return Error::success();
59 }