Zachary Turner | a9054dd | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 1 | //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===// |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Zachary Turner | a9054dd | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 9 | #include "PrettyEnumDumper.h" |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 10 | |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 11 | #include "LinePrinter.h" |
Zachary Turner | a9054dd | 2017-01-11 00:35:43 +0000 | [diff] [blame] | 12 | #include "PrettyBuiltinDumper.h" |
Zachary Turner | bd336e4 | 2017-06-09 20:46:17 +0000 | [diff] [blame] | 13 | #include "llvm-pdbutil.h" |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 14 | |
| 15 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" |
| 16 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" |
| 17 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" |
| 18 | |
| 19 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 20 | using namespace llvm::pdb; |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 21 | |
| 22 | EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {} |
| 23 | |
| 24 | void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) { |
Zachary Turner | a98ee58 | 2018-09-14 22:29:19 +0000 | [diff] [blame] | 25 | if (Symbol.getUnmodifiedTypeId() != 0) { |
| 26 | if (Symbol.isConstType()) |
| 27 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "const "; |
| 28 | if (Symbol.isVolatileType()) |
| 29 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile "; |
| 30 | if (Symbol.isUnalignedType()) |
| 31 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned "; |
| 32 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; |
| 33 | WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); |
| 34 | return; |
| 35 | } |
| 36 | |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 37 | WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; |
| 38 | WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 39 | if (!opts::pretty::NoEnumDefs) { |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 40 | auto UnderlyingType = Symbol.getUnderlyingType(); |
| 41 | if (!UnderlyingType) |
| 42 | return; |
| 43 | if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int || |
| 44 | UnderlyingType->getLength() != 4) { |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 45 | Printer << " : "; |
| 46 | BuiltinDumper Dumper(Printer); |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 47 | Dumper.start(*UnderlyingType); |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 48 | } |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 49 | auto EnumValues = Symbol.findAllChildren<PDBSymbolData>(); |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 50 | Printer << " {"; |
| 51 | Printer.Indent(); |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 52 | if (EnumValues && EnumValues->getChildCount() > 0) { |
| 53 | while (auto EnumValue = EnumValues->getNext()) { |
| 54 | if (EnumValue->getDataKind() != PDB_DataKind::Constant) |
| 55 | continue; |
| 56 | Printer.NewLine(); |
| 57 | WithColor(Printer, PDB_ColorItem::Identifier).get() |
| 58 | << EnumValue->getName(); |
| 59 | Printer << " = "; |
| 60 | WithColor(Printer, PDB_ColorItem::LiteralValue).get() |
| 61 | << EnumValue->getValue(); |
| 62 | } |
Zachary Turner | 6532365 | 2015-03-04 06:09:53 +0000 | [diff] [blame] | 63 | } |
| 64 | Printer.Unindent(); |
| 65 | Printer.NewLine(); |
| 66 | Printer << "}"; |
| 67 | } |
| 68 | } |