Path: blob/main/contrib/llvm-project/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
35260 views
//===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "PrettyEnumDumper.h"910#include "PrettyBuiltinDumper.h"11#include "llvm-pdbutil.h"1213#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"14#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"15#include "llvm/DebugInfo/PDB/PDBSymbolData.h"16#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"17#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"1819using namespace llvm;20using namespace llvm::pdb;2122EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}2324void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {25if (Symbol.getUnmodifiedTypeId() != 0) {26if (Symbol.isConstType())27WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";28if (Symbol.isVolatileType())29WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";30if (Symbol.isUnalignedType())31WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";32WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";33WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();34return;35}3637WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";38WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();39if (!opts::pretty::NoEnumDefs) {40auto UnderlyingType = Symbol.getUnderlyingType();41if (!UnderlyingType)42return;43if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||44UnderlyingType->getLength() != 4) {45Printer << " : ";46BuiltinDumper Dumper(Printer);47Dumper.start(*UnderlyingType);48}49auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();50Printer << " {";51Printer.Indent();52if (EnumValues && EnumValues->getChildCount() > 0) {53while (auto EnumValue = EnumValues->getNext()) {54if (EnumValue->getDataKind() != PDB_DataKind::Constant)55continue;56Printer.NewLine();57WithColor(Printer, PDB_ColorItem::Identifier).get()58<< EnumValue->getName();59Printer << " = ";60WithColor(Printer, PDB_ColorItem::LiteralValue).get()61<< EnumValue->getValue();62}63}64Printer.Unindent();65Printer.NewLine();66Printer << "}";67}68}697071