1 //===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "PrettyClassDefinitionDumper.h"
12 #include "LinePrinter.h"
13 #include "PrettyClassLayoutGraphicalDumper.h"
14 #include "llvm-pdbutil.h"
16 #include "llvm/ADT/APFloat.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
20 #include "llvm/DebugInfo/PDB/UDTLayout.h"
22 #include "llvm/Support/Format.h"
25 using namespace llvm::pdb
;
27 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter
&P
)
28 : PDBSymDumper(true), Printer(P
) {}
30 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT
&Class
) {
31 assert(opts::pretty::ClassFormat
!=
32 opts::pretty::ClassDefinitionFormat::None
);
34 ClassLayout
Layout(Class
);
38 void ClassDefinitionDumper::start(const ClassLayout
&Layout
) {
39 prettyPrintClassIntro(Layout
);
41 PrettyClassLayoutGraphicalDumper
Dumper(Printer
, 1, 0);
42 DumpedAnything
|= Dumper
.start(Layout
);
44 prettyPrintClassOutro(Layout
);
47 void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout
&Layout
) {
48 DumpedAnything
= false;
51 uint32_t Size
= Layout
.getSize();
52 const PDBSymbolTypeUDT
&Class
= Layout
.getClass();
54 if (Layout
.getClass().isConstType())
55 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "const ";
56 if (Layout
.getClass().isVolatileType())
57 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "volatile ";
58 if (Layout
.getClass().isUnalignedType())
59 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "unaligned ";
61 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << Class
.getUdtKind() << " ";
62 WithColor(Printer
, PDB_ColorItem::Type
).get() << Class
.getName();
63 WithColor(Printer
, PDB_ColorItem::Comment
).get() << " [sizeof = " << Size
65 uint32_t BaseCount
= Layout
.bases().size();
68 char NextSeparator
= ':';
69 for (auto BC
: Layout
.bases()) {
70 const auto &Base
= BC
->getBase();
71 if (Base
.isIndirectVirtualBaseClass())
75 Printer
<< NextSeparator
<< " ";
76 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << Base
.getAccess();
77 if (BC
->isVirtualBase())
78 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << " virtual";
80 WithColor(Printer
, PDB_ColorItem::Type
).get() << " " << Base
.getName();
91 void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout
&Layout
) {
97 if (Layout
.deepPaddingSize() > 0) {
98 APFloat
Pct(100.0 * (double)Layout
.deepPaddingSize() /
99 (double)Layout
.getSize());
100 SmallString
<8> PctStr
;
101 Pct
.toString(PctStr
, 4);
102 WithColor(Printer
, PDB_ColorItem::Padding
).get()
103 << "Total padding " << Layout
.deepPaddingSize() << " bytes (" << PctStr
104 << "% of class size)";
106 APFloat
Pct2(100.0 * (double)Layout
.immediatePadding() /
107 (double)Layout
.getSize());
109 Pct2
.toString(PctStr
, 4);
110 WithColor(Printer
, PDB_ColorItem::Padding
).get()
111 << "Immediate padding " << Layout
.immediatePadding() << " bytes ("
112 << PctStr
<< "% of class size)";