2017-01-11 08:35:43 +08:00
|
|
|
//===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
|
2015-03-04 14:09:53 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-03-04 14:09:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyEnumDumper.h"
|
2015-03-04 14:09:53 +08:00
|
|
|
|
|
|
|
#include "LinePrinter.h"
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyBuiltinDumper.h"
|
2017-06-10 04:46:17 +08:00
|
|
|
#include "llvm-pdbutil.h"
|
2015-03-04 14:09:53 +08:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2016-05-05 04:32:13 +08:00
|
|
|
using namespace llvm::pdb;
|
2015-03-04 14:09:53 +08:00
|
|
|
|
|
|
|
EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
|
|
|
|
|
|
|
|
void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
|
2018-09-15 06:29:19 +08:00
|
|
|
if (Symbol.getUnmodifiedTypeId() != 0) {
|
|
|
|
if (Symbol.isConstType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
|
|
|
if (Symbol.isVolatileType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
|
|
|
|
if (Symbol.isUnalignedType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:09:53 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2016-07-01 01:42:48 +08:00
|
|
|
if (!opts::pretty::NoEnumDefs) {
|
2017-08-05 06:37:58 +08:00
|
|
|
auto UnderlyingType = Symbol.getUnderlyingType();
|
|
|
|
if (!UnderlyingType)
|
|
|
|
return;
|
|
|
|
if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
|
|
|
|
UnderlyingType->getLength() != 4) {
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer << " : ";
|
|
|
|
BuiltinDumper Dumper(Printer);
|
2017-08-05 06:37:58 +08:00
|
|
|
Dumper.start(*UnderlyingType);
|
2015-03-04 14:09:53 +08:00
|
|
|
}
|
2017-08-05 06:37:58 +08:00
|
|
|
auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer << " {";
|
|
|
|
Printer.Indent();
|
2017-08-05 06:37:58 +08:00
|
|
|
if (EnumValues && EnumValues->getChildCount() > 0) {
|
|
|
|
while (auto EnumValue = EnumValues->getNext()) {
|
|
|
|
if (EnumValue->getDataKind() != PDB_DataKind::Constant)
|
|
|
|
continue;
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< EnumValue->getName();
|
|
|
|
Printer << " = ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get()
|
|
|
|
<< EnumValue->getValue();
|
|
|
|
}
|
2015-03-04 14:09:53 +08:00
|
|
|
}
|
|
|
|
Printer.Unindent();
|
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "}";
|
|
|
|
}
|
|
|
|
}
|