blob: 9ed5893f252e8cf9f71552928574d055cfda0ca9 [file] [log] [blame]
Zachary Turnera9054dd2017-01-11 00:35:43 +00001//===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
Zachary Turner65323652015-03-04 06:09:53 +00002//
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
Zachary Turner65323652015-03-04 06:09:53 +00006//
7//===----------------------------------------------------------------------===//
8
Zachary Turnera9054dd2017-01-11 00:35:43 +00009#include "PrettyEnumDumper.h"
Zachary Turner65323652015-03-04 06:09:53 +000010
Zachary Turner65323652015-03-04 06:09:53 +000011#include "LinePrinter.h"
Zachary Turnera9054dd2017-01-11 00:35:43 +000012#include "PrettyBuiltinDumper.h"
Zachary Turnerbd336e42017-06-09 20:46:17 +000013#include "llvm-pdbutil.h"
Zachary Turner65323652015-03-04 06:09:53 +000014
15#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
16#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
17#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
18
19using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000020using namespace llvm::pdb;
Zachary Turner65323652015-03-04 06:09:53 +000021
22EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
23
24void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
Zachary Turnera98ee582018-09-14 22:29:19 +000025 if (Symbol.getUnmodifiedTypeId() != 0) {
26 if (Symbol.isConstType())
27 WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
28 if (Symbol.isVolatileType())
29 WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
30 if (Symbol.isUnalignedType())
31 WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
32 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
33 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
34 return;
35 }
36
Zachary Turner65323652015-03-04 06:09:53 +000037 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
38 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
Zachary Turnera30bd1a2016-06-30 17:42:48 +000039 if (!opts::pretty::NoEnumDefs) {
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000040 auto UnderlyingType = Symbol.getUnderlyingType();
41 if (!UnderlyingType)
42 return;
43 if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
44 UnderlyingType->getLength() != 4) {
Zachary Turner65323652015-03-04 06:09:53 +000045 Printer << " : ";
46 BuiltinDumper Dumper(Printer);
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000047 Dumper.start(*UnderlyingType);
Zachary Turner65323652015-03-04 06:09:53 +000048 }
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000049 auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
Zachary Turner65323652015-03-04 06:09:53 +000050 Printer << " {";
51 Printer.Indent();
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000052 if (EnumValues && EnumValues->getChildCount() > 0) {
53 while (auto EnumValue = EnumValues->getNext()) {
54 if (EnumValue->getDataKind() != PDB_DataKind::Constant)
55 continue;
56 Printer.NewLine();
57 WithColor(Printer, PDB_ColorItem::Identifier).get()
58 << EnumValue->getName();
59 Printer << " = ";
60 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
61 << EnumValue->getValue();
62 }
Zachary Turner65323652015-03-04 06:09:53 +000063 }
64 Printer.Unindent();
65 Printer.NewLine();
66 Printer << "}";
67 }
68}