PrettyBuiltinDumper.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===- PrettyBuiltinDumper.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 "PrettyBuiltinDumper.h"
  9. #include "LinePrinter.h"
  10. #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
  11. using namespace llvm;
  12. using namespace llvm::pdb;
  13. BuiltinDumper::BuiltinDumper(LinePrinter &P)
  14. : PDBSymDumper(false), Printer(P) {}
  15. void BuiltinDumper::start(const PDBSymbolTypeBuiltin &Symbol) {
  16. if (Symbol.isConstType())
  17. WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
  18. if (Symbol.isVolatileType())
  19. WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
  20. WithColor(Printer, PDB_ColorItem::Type).get() << getTypeName(Symbol);
  21. }
  22. StringRef BuiltinDumper::getTypeName(const PDBSymbolTypeBuiltin &Symbol) {
  23. PDB_BuiltinType Type = Symbol.getBuiltinType();
  24. switch (Type) {
  25. case PDB_BuiltinType::Float:
  26. if (Symbol.getLength() == 4)
  27. return "float";
  28. return "double";
  29. case PDB_BuiltinType::UInt:
  30. switch (Symbol.getLength()) {
  31. case 8:
  32. return "unsigned __int64";
  33. case 4:
  34. return "unsigned int";
  35. case 2:
  36. return "unsigned short";
  37. case 1:
  38. return "unsigned char";
  39. default:
  40. return "unsigned";
  41. }
  42. case PDB_BuiltinType::Int:
  43. switch (Symbol.getLength()) {
  44. case 8:
  45. return "__int64";
  46. case 4:
  47. return "int";
  48. case 2:
  49. return "short";
  50. case 1:
  51. return "char";
  52. default:
  53. return "int";
  54. }
  55. case PDB_BuiltinType::Char:
  56. return "char";
  57. case PDB_BuiltinType::WCharT:
  58. return "wchar_t";
  59. case PDB_BuiltinType::Void:
  60. return "void";
  61. case PDB_BuiltinType::Long:
  62. return "long";
  63. case PDB_BuiltinType::ULong:
  64. return "unsigned long";
  65. case PDB_BuiltinType::Bool:
  66. return "bool";
  67. case PDB_BuiltinType::Currency:
  68. return "CURRENCY";
  69. case PDB_BuiltinType::Date:
  70. return "DATE";
  71. case PDB_BuiltinType::Variant:
  72. return "VARIANT";
  73. case PDB_BuiltinType::Complex:
  74. return "complex";
  75. case PDB_BuiltinType::Bitfield:
  76. return "bitfield";
  77. case PDB_BuiltinType::BSTR:
  78. return "BSTR";
  79. case PDB_BuiltinType::HResult:
  80. return "HRESULT";
  81. case PDB_BuiltinType::BCD:
  82. return "HRESULT";
  83. case PDB_BuiltinType::Char16:
  84. return "char16_t";
  85. case PDB_BuiltinType::Char32:
  86. return "char32_t";
  87. case PDB_BuiltinType::None:
  88. return "...";
  89. }
  90. llvm_unreachable("Unknown PDB_BuiltinType");
  91. }