1 //===- PrettyEnumDumper.cpp -------------------------------------*- 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 #include "PrettyEnumDumper.h"
10
11 #include "PrettyBuiltinDumper.h"
12 #include "llvm-pdbutil.h"
13
14 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
15 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
19
20 using namespace llvm;
21 using namespace llvm::pdb;
22
EnumDumper(LinePrinter & P)23 EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
24
start(const PDBSymbolTypeEnum & Symbol)25 void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
26 if (Symbol.getUnmodifiedTypeId() != 0) {
27 if (Symbol.isConstType())
28 WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
29 if (Symbol.isVolatileType())
30 WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
31 if (Symbol.isUnalignedType())
32 WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
33 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
34 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
35 return;
36 }
37
38 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
39 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
40 if (!opts::pretty::NoEnumDefs) {
41 auto UnderlyingType = Symbol.getUnderlyingType();
42 if (!UnderlyingType)
43 return;
44 if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
45 UnderlyingType->getLength() != 4) {
46 Printer << " : ";
47 BuiltinDumper Dumper(Printer);
48 Dumper.start(*UnderlyingType);
49 }
50 auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
51 Printer << " {";
52 Printer.Indent();
53 if (EnumValues && EnumValues->getChildCount() > 0) {
54 while (auto EnumValue = EnumValues->getNext()) {
55 if (EnumValue->getDataKind() != PDB_DataKind::Constant)
56 continue;
57 Printer.NewLine();
58 WithColor(Printer, PDB_ColorItem::Identifier).get()
59 << EnumValue->getName();
60 Printer << " = ";
61 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
62 << EnumValue->getValue();
63 }
64 }
65 Printer.Unindent();
66 Printer.NewLine();
67 Printer << "}";
68 }
69 }
70