PrettyEnumDumper.cpp 2.4 KB

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