Zachary Turner | eb6ab04 | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 1 | //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===// |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 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 | |
Zachary Turner | eb6ab04 | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 10 | #include "PrettyEnumDumper.h" |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 11 | |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 12 | #include "LinePrinter.h" |
Zachary Turner | eb6ab04 | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 13 | #include "PrettyBuiltinDumper.h" |
Zachary Turner | cfb1356 | 2017-06-09 20:46:17 +0000 | [diff] [blame] | 14 | #include "llvm-pdbutil.h" |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 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 | c95df94 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 21 | using namespace llvm::pdb; |
Zachary Turner | b9c28bc | 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) { |
Zachary Turner | 903e31c | 2018-09-14 22:29:19 +0000 | [diff] [blame] | 26 | 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 Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 38 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; |
| 39 | WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); |
Zachary Turner | 3a4681d | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 40 | if (!opts::pretty::NoEnumDefs) { |
Adrian McCarthy | 2d30fac | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 41 | auto UnderlyingType = Symbol.getUnderlyingType(); |
| 42 | if (!UnderlyingType) |
| 43 | return; |
| 44 | if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int || |
| 45 | UnderlyingType->getLength() != 4) { |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 46 | Printer << " : "; |
| 47 | BuiltinDumper Dumper(Printer); |
Adrian McCarthy | 2d30fac | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 48 | Dumper.start(*UnderlyingType); |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 49 | } |
Adrian McCarthy | 2d30fac | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 50 | auto EnumValues = Symbol.findAllChildren<PDBSymbolData>(); |
Zachary Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 51 | Printer << " {"; |
| 52 | Printer.Indent(); |
Adrian McCarthy | 2d30fac | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 53 | 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 Turner | b9c28bc | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 64 | } |
| 65 | Printer.Unindent(); |
| 66 | Printer.NewLine(); |
| 67 | Printer << "}"; |
| 68 | } |
| 69 | } |