blob: 43b6018ffedf38e0fef19028b1b72a152babef7b [file] [log] [blame]
Zachary Turner65323652015-03-04 06:09:53 +00001//===- EnumDumper.cpp -------------------------------------------*- 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 "EnumDumper.h"
11
12#include "BuiltinDumper.h"
13#include "LinePrinter.h"
14#include "llvm-pdbdump.h"
15
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 Turnerec28fc32016-05-04 20:32:13 +000021using namespace llvm::pdb;
Zachary Turner65323652015-03-04 06:09:53 +000022
23EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
24
25void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
26 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
27 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
Zachary Turnera30bd1a2016-06-30 17:42:48 +000028 if (!opts::pretty::NoEnumDefs) {
Zachary Turner65323652015-03-04 06:09:53 +000029 auto BuiltinType = Symbol.getUnderlyingType();
30 if (BuiltinType->getBuiltinType() != PDB_BuiltinType::Int ||
31 BuiltinType->getLength() != 4) {
32 Printer << " : ";
33 BuiltinDumper Dumper(Printer);
34 Dumper.start(*BuiltinType);
35 }
36 Printer << " {";
37 Printer.Indent();
38 auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
39 while (auto EnumValue = EnumValues->getNext()) {
40 if (EnumValue->getDataKind() != PDB_DataKind::Constant)
41 continue;
42 Printer.NewLine();
43 WithColor(Printer, PDB_ColorItem::Identifier).get()
44 << EnumValue->getName();
45 Printer << " = ";
46 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
47 << EnumValue->getValue();
48 }
49 Printer.Unindent();
50 Printer.NewLine();
51 Printer << "}";
52 }
53}