blob: f4cbd3f8fa144c5a077b0a4d43770793c3c452ec [file] [log] [blame]
Zachary Turnereb6ab042017-01-11 00:35:43 +00001//===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
Zachary Turnerb9c28bc2015-03-04 06:09:53 +00002//
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
Zachary Turnereb6ab042017-01-11 00:35:43 +000010#include "PrettyEnumDumper.h"
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000011
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000012#include "LinePrinter.h"
Zachary Turnereb6ab042017-01-11 00:35:43 +000013#include "PrettyBuiltinDumper.h"
Zachary Turnercfb13562017-06-09 20:46:17 +000014#include "llvm-pdbutil.h"
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000015
16#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
17#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
18#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
19
20using namespace llvm;
Zachary Turnerc95df942016-05-04 20:32:13 +000021using namespace llvm::pdb;
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000022
23EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
24
25void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
Zachary Turner903e31c2018-09-14 22:29:19 +000026 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
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000038 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
39 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
Zachary Turner3a4681d2016-06-30 17:42:48 +000040 if (!opts::pretty::NoEnumDefs) {
Adrian McCarthy2d30fac2017-08-04 22:37:58 +000041 auto UnderlyingType = Symbol.getUnderlyingType();
42 if (!UnderlyingType)
43 return;
44 if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
45 UnderlyingType->getLength() != 4) {
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000046 Printer << " : ";
47 BuiltinDumper Dumper(Printer);
Adrian McCarthy2d30fac2017-08-04 22:37:58 +000048 Dumper.start(*UnderlyingType);
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000049 }
Adrian McCarthy2d30fac2017-08-04 22:37:58 +000050 auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000051 Printer << " {";
52 Printer.Indent();
Adrian McCarthy2d30fac2017-08-04 22:37:58 +000053 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 }
Zachary Turnerb9c28bc2015-03-04 06:09:53 +000064 }
65 Printer.Unindent();
66 Printer.NewLine();
67 Printer << "}";
68 }
69}