xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- PrettyBuiltinDumper.cpp ---------------------------------- *- C++ *-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "PrettyBuiltinDumper.h"
10*0b57cec5SDimitry Andric #include "LinePrinter.h"
11*0b57cec5SDimitry Andric 
12*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
13*0b57cec5SDimitry Andric 
14*0b57cec5SDimitry Andric using namespace llvm;
15*0b57cec5SDimitry Andric using namespace llvm::pdb;
16*0b57cec5SDimitry Andric 
17*0b57cec5SDimitry Andric BuiltinDumper::BuiltinDumper(LinePrinter &P)
18*0b57cec5SDimitry Andric     : PDBSymDumper(false), Printer(P) {}
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric void BuiltinDumper::start(const PDBSymbolTypeBuiltin &Symbol) {
21*0b57cec5SDimitry Andric   if (Symbol.isConstType())
22*0b57cec5SDimitry Andric     WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
23*0b57cec5SDimitry Andric   if (Symbol.isVolatileType())
24*0b57cec5SDimitry Andric     WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
25*0b57cec5SDimitry Andric   WithColor(Printer, PDB_ColorItem::Type).get() << getTypeName(Symbol);
26*0b57cec5SDimitry Andric }
27*0b57cec5SDimitry Andric 
28*0b57cec5SDimitry Andric StringRef BuiltinDumper::getTypeName(const PDBSymbolTypeBuiltin &Symbol) {
29*0b57cec5SDimitry Andric   PDB_BuiltinType Type = Symbol.getBuiltinType();
30*0b57cec5SDimitry Andric   switch (Type) {
31*0b57cec5SDimitry Andric   case PDB_BuiltinType::Float:
32*0b57cec5SDimitry Andric     if (Symbol.getLength() == 4)
33*0b57cec5SDimitry Andric       return "float";
34*0b57cec5SDimitry Andric     return "double";
35*0b57cec5SDimitry Andric   case PDB_BuiltinType::UInt:
36*0b57cec5SDimitry Andric     switch (Symbol.getLength()) {
37*0b57cec5SDimitry Andric     case 8:
38*0b57cec5SDimitry Andric       return "unsigned __int64";
39*0b57cec5SDimitry Andric     case 4:
40*0b57cec5SDimitry Andric       return "unsigned int";
41*0b57cec5SDimitry Andric     case 2:
42*0b57cec5SDimitry Andric       return "unsigned short";
43*0b57cec5SDimitry Andric     case 1:
44*0b57cec5SDimitry Andric       return "unsigned char";
45*0b57cec5SDimitry Andric     default:
46*0b57cec5SDimitry Andric       return "unsigned";
47*0b57cec5SDimitry Andric     }
48*0b57cec5SDimitry Andric   case PDB_BuiltinType::Int:
49*0b57cec5SDimitry Andric     switch (Symbol.getLength()) {
50*0b57cec5SDimitry Andric     case 8:
51*0b57cec5SDimitry Andric       return "__int64";
52*0b57cec5SDimitry Andric     case 4:
53*0b57cec5SDimitry Andric       return "int";
54*0b57cec5SDimitry Andric     case 2:
55*0b57cec5SDimitry Andric       return "short";
56*0b57cec5SDimitry Andric     case 1:
57*0b57cec5SDimitry Andric       return "char";
58*0b57cec5SDimitry Andric     default:
59*0b57cec5SDimitry Andric       return "int";
60*0b57cec5SDimitry Andric     }
61*0b57cec5SDimitry Andric   case PDB_BuiltinType::Char:
62*0b57cec5SDimitry Andric     return "char";
63*0b57cec5SDimitry Andric   case PDB_BuiltinType::WCharT:
64*0b57cec5SDimitry Andric     return "wchar_t";
65*0b57cec5SDimitry Andric   case PDB_BuiltinType::Void:
66*0b57cec5SDimitry Andric     return "void";
67*0b57cec5SDimitry Andric   case PDB_BuiltinType::Long:
68*0b57cec5SDimitry Andric     return "long";
69*0b57cec5SDimitry Andric   case PDB_BuiltinType::ULong:
70*0b57cec5SDimitry Andric     return "unsigned long";
71*0b57cec5SDimitry Andric   case PDB_BuiltinType::Bool:
72*0b57cec5SDimitry Andric     return "bool";
73*0b57cec5SDimitry Andric   case PDB_BuiltinType::Currency:
74*0b57cec5SDimitry Andric     return "CURRENCY";
75*0b57cec5SDimitry Andric   case PDB_BuiltinType::Date:
76*0b57cec5SDimitry Andric     return "DATE";
77*0b57cec5SDimitry Andric   case PDB_BuiltinType::Variant:
78*0b57cec5SDimitry Andric     return "VARIANT";
79*0b57cec5SDimitry Andric   case PDB_BuiltinType::Complex:
80*0b57cec5SDimitry Andric     return "complex";
81*0b57cec5SDimitry Andric   case PDB_BuiltinType::Bitfield:
82*0b57cec5SDimitry Andric     return "bitfield";
83*0b57cec5SDimitry Andric   case PDB_BuiltinType::BSTR:
84*0b57cec5SDimitry Andric     return "BSTR";
85*0b57cec5SDimitry Andric   case PDB_BuiltinType::HResult:
86*0b57cec5SDimitry Andric     return "HRESULT";
87*0b57cec5SDimitry Andric   case PDB_BuiltinType::BCD:
88*0b57cec5SDimitry Andric     return "HRESULT";
89*0b57cec5SDimitry Andric   case PDB_BuiltinType::Char16:
90*0b57cec5SDimitry Andric     return "char16_t";
91*0b57cec5SDimitry Andric   case PDB_BuiltinType::Char32:
92*0b57cec5SDimitry Andric     return "char32_t";
93*0b57cec5SDimitry Andric   case PDB_BuiltinType::None:
94*0b57cec5SDimitry Andric     return "...";
95*0b57cec5SDimitry Andric   }
96*0b57cec5SDimitry Andric   llvm_unreachable("Unknown PDB_BuiltinType");
97*0b57cec5SDimitry Andric }
98