10b57cec5SDimitry Andric //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "PrettyEnumDumper.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric #include "PrettyBuiltinDumper.h"
120b57cec5SDimitry Andric #include "llvm-pdbutil.h"
130b57cec5SDimitry Andric
14*81ad6265SDimitry Andric #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
15*81ad6265SDimitry Andric #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
160b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
170b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
180b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
190b57cec5SDimitry Andric
200b57cec5SDimitry Andric using namespace llvm;
210b57cec5SDimitry Andric using namespace llvm::pdb;
220b57cec5SDimitry Andric
EnumDumper(LinePrinter & P)230b57cec5SDimitry Andric EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
240b57cec5SDimitry Andric
start(const PDBSymbolTypeEnum & Symbol)250b57cec5SDimitry Andric void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
260b57cec5SDimitry Andric if (Symbol.getUnmodifiedTypeId() != 0) {
270b57cec5SDimitry Andric if (Symbol.isConstType())
280b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
290b57cec5SDimitry Andric if (Symbol.isVolatileType())
300b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
310b57cec5SDimitry Andric if (Symbol.isUnalignedType())
320b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
330b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
340b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
350b57cec5SDimitry Andric return;
360b57cec5SDimitry Andric }
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
390b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
400b57cec5SDimitry Andric if (!opts::pretty::NoEnumDefs) {
410b57cec5SDimitry Andric auto UnderlyingType = Symbol.getUnderlyingType();
420b57cec5SDimitry Andric if (!UnderlyingType)
430b57cec5SDimitry Andric return;
440b57cec5SDimitry Andric if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
450b57cec5SDimitry Andric UnderlyingType->getLength() != 4) {
460b57cec5SDimitry Andric Printer << " : ";
470b57cec5SDimitry Andric BuiltinDumper Dumper(Printer);
480b57cec5SDimitry Andric Dumper.start(*UnderlyingType);
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
510b57cec5SDimitry Andric Printer << " {";
520b57cec5SDimitry Andric Printer.Indent();
530b57cec5SDimitry Andric if (EnumValues && EnumValues->getChildCount() > 0) {
540b57cec5SDimitry Andric while (auto EnumValue = EnumValues->getNext()) {
550b57cec5SDimitry Andric if (EnumValue->getDataKind() != PDB_DataKind::Constant)
560b57cec5SDimitry Andric continue;
570b57cec5SDimitry Andric Printer.NewLine();
580b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::Identifier).get()
590b57cec5SDimitry Andric << EnumValue->getName();
600b57cec5SDimitry Andric Printer << " = ";
610b57cec5SDimitry Andric WithColor(Printer, PDB_ColorItem::LiteralValue).get()
620b57cec5SDimitry Andric << EnumValue->getValue();
630b57cec5SDimitry Andric }
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric Printer.Unindent();
660b57cec5SDimitry Andric Printer.NewLine();
670b57cec5SDimitry Andric Printer << "}";
680b57cec5SDimitry Andric }
690b57cec5SDimitry Andric }
70