EnumDumper.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===- EnumDumper.cpp -------------------------------------------*- C++ -*-===//
  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. #include "EnumDumper.h"
  10. #include "BuiltinDumper.h"
  11. #include "LinePrinter.h"
  12. #include "llvm-pdbdump.h"
  13. #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
  14. #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
  15. #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
  16. using namespace llvm;
  17. EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
  18. void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
  19. WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
  20. WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
  21. if (!opts::NoEnumDefs) {
  22. auto BuiltinType = Symbol.getUnderlyingType();
  23. if (BuiltinType->getBuiltinType() != PDB_BuiltinType::Int ||
  24. BuiltinType->getLength() != 4) {
  25. Printer << " : ";
  26. BuiltinDumper Dumper(Printer);
  27. Dumper.start(*BuiltinType);
  28. }
  29. Printer << " {";
  30. Printer.Indent();
  31. auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
  32. while (auto EnumValue = EnumValues->getNext()) {
  33. if (EnumValue->getDataKind() != PDB_DataKind::Constant)
  34. continue;
  35. Printer.NewLine();
  36. WithColor(Printer, PDB_ColorItem::Identifier).get()
  37. << EnumValue->getName();
  38. Printer << " = ";
  39. WithColor(Printer, PDB_ColorItem::LiteralValue).get()
  40. << EnumValue->getValue();
  41. }
  42. Printer.Unindent();
  43. Printer.NewLine();
  44. Printer << "}";
  45. }
  46. }