annotate tools/llvm-pdbutil/PrettyEnumDumper.cpp @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #include "PrettyEnumDumper.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "LinePrinter.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "PrettyBuiltinDumper.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm-pdbutil.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 using namespace llvm::pdb;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 if (!opts::pretty::NoEnumDefs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 auto UnderlyingType = Symbol.getUnderlyingType();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 if (!UnderlyingType)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 UnderlyingType->getLength() != 4) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 Printer << " : ";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 BuiltinDumper Dumper(Printer);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 Dumper.start(*UnderlyingType);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 Printer << " {";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 Printer.Indent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 if (EnumValues && EnumValues->getChildCount() > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 while (auto EnumValue = EnumValues->getNext()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 if (EnumValue->getDataKind() != PDB_DataKind::Constant)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 WithColor(Printer, PDB_ColorItem::Identifier).get()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 << EnumValue->getName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 Printer << " = ";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 WithColor(Printer, PDB_ColorItem::LiteralValue).get()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 << EnumValue->getValue();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 Printer.Unindent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 Printer << "}";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 }