PrettyEnumDumper.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "PrettyEnumDumper.h"
  9. #include "PrettyBuiltinDumper.h"
  10. #include "llvm-pdbutil.h"
  11. #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
  12. #include "llvm/DebugInfo/PDB/IPDBLineNumber.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. using namespace llvm::pdb;
  18. EnumDumper::EnumDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
  19. void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
  20. if (Symbol.getUnmodifiedTypeId() != 0) {
  21. if (Symbol.isConstType())
  22. WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
  23. if (Symbol.isVolatileType())
  24. WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
  25. if (Symbol.isUnalignedType())
  26. WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
  27. WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
  28. WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
  29. return;
  30. }
  31. WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
  32. WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
  33. if (!opts::pretty::NoEnumDefs) {
  34. auto UnderlyingType = Symbol.getUnderlyingType();
  35. if (!UnderlyingType)
  36. return;
  37. if (UnderlyingType->getBuiltinType() != PDB_BuiltinType::Int ||
  38. UnderlyingType->getLength() != 4) {
  39. Printer << " : ";
  40. BuiltinDumper Dumper(Printer);
  41. Dumper.start(*UnderlyingType);
  42. }
  43. auto EnumValues = Symbol.findAllChildren<PDBSymbolData>();
  44. Printer << " {";
  45. Printer.Indent();
  46. if (EnumValues && EnumValues->getChildCount() > 0) {
  47. while (auto EnumValue = EnumValues->getNext()) {
  48. if (EnumValue->getDataKind() != PDB_DataKind::Constant)
  49. continue;
  50. Printer.NewLine();
  51. WithColor(Printer, PDB_ColorItem::Identifier).get()
  52. << EnumValue->getName();
  53. Printer << " = ";
  54. WithColor(Printer, PDB_ColorItem::LiteralValue).get()
  55. << EnumValue->getValue();
  56. }
  57. }
  58. Printer.Unindent();
  59. Printer.NewLine();
  60. Printer << "}";
  61. }
  62. }