Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 20 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 21 | using namespace llvm::pdb; |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 22 | |
| 23 | EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {} |
| 24 | |
| 25 | void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) { |
| 26 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; |
| 27 | WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame^] | 28 | if (!opts::pretty::NoEnumDefs) { |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 29 | 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 | } |