1*b5893f02SDimitry Andric //===- NativeSymbolEnumerator.cpp - info about enumerators ------*- C++ -*-===//
2*b5893f02SDimitry Andric //
3*b5893f02SDimitry Andric //                     The LLVM Compiler Infrastructure
4*b5893f02SDimitry Andric //
5*b5893f02SDimitry Andric // This file is distributed under the University of Illinois Open Source
6*b5893f02SDimitry Andric // License. See LICENSE.TXT for details.
7*b5893f02SDimitry Andric //
8*b5893f02SDimitry Andric //===----------------------------------------------------------------------===//
9*b5893f02SDimitry Andric 
10*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h"
11*b5893f02SDimitry Andric 
12*b5893f02SDimitry Andric #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
13*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
14*b5893f02SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
15*b5893f02SDimitry Andric 
16*b5893f02SDimitry Andric using namespace llvm;
17*b5893f02SDimitry Andric using namespace llvm::codeview;
18*b5893f02SDimitry Andric using namespace llvm::pdb;
19*b5893f02SDimitry Andric 
NativeSymbolEnumerator(NativeSession & Session,SymIndexId Id,const NativeTypeEnum & Parent,codeview::EnumeratorRecord Record)20*b5893f02SDimitry Andric NativeSymbolEnumerator::NativeSymbolEnumerator(
21*b5893f02SDimitry Andric     NativeSession &Session, SymIndexId Id, const NativeTypeEnum &Parent,
22*b5893f02SDimitry Andric     codeview::EnumeratorRecord Record)
23*b5893f02SDimitry Andric     : NativeRawSymbol(Session, PDB_SymType::Data, Id), Parent(Parent),
24*b5893f02SDimitry Andric       Record(std::move(Record)) {}
25*b5893f02SDimitry Andric 
~NativeSymbolEnumerator()26*b5893f02SDimitry Andric NativeSymbolEnumerator::~NativeSymbolEnumerator() {}
27*b5893f02SDimitry Andric 
dump(raw_ostream & OS,int Indent,PdbSymbolIdField ShowIdFields,PdbSymbolIdField RecurseIdFields) const28*b5893f02SDimitry Andric void NativeSymbolEnumerator::dump(raw_ostream &OS, int Indent,
29*b5893f02SDimitry Andric                                   PdbSymbolIdField ShowIdFields,
30*b5893f02SDimitry Andric                                   PdbSymbolIdField RecurseIdFields) const {
31*b5893f02SDimitry Andric   NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
32*b5893f02SDimitry Andric   dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
33*b5893f02SDimitry Andric                     PdbSymbolIdField::ClassParent, ShowIdFields,
34*b5893f02SDimitry Andric                     RecurseIdFields);
35*b5893f02SDimitry Andric   dumpSymbolIdField(OS, "lexicalParentId", getLexicalParentId(), Indent,
36*b5893f02SDimitry Andric                     Session, PdbSymbolIdField::LexicalParent, ShowIdFields,
37*b5893f02SDimitry Andric                     RecurseIdFields);
38*b5893f02SDimitry Andric   dumpSymbolField(OS, "name", getName(), Indent);
39*b5893f02SDimitry Andric   dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
40*b5893f02SDimitry Andric                     PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
41*b5893f02SDimitry Andric   dumpSymbolField(OS, "dataKind", getDataKind(), Indent);
42*b5893f02SDimitry Andric   dumpSymbolField(OS, "locationType", getLocationType(), Indent);
43*b5893f02SDimitry Andric   dumpSymbolField(OS, "constType", isConstType(), Indent);
44*b5893f02SDimitry Andric   dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
45*b5893f02SDimitry Andric   dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
46*b5893f02SDimitry Andric   dumpSymbolField(OS, "value", getValue(), Indent);
47*b5893f02SDimitry Andric }
48*b5893f02SDimitry Andric 
getClassParentId() const49*b5893f02SDimitry Andric SymIndexId NativeSymbolEnumerator::getClassParentId() const {
50*b5893f02SDimitry Andric   return Parent.getSymIndexId();
51*b5893f02SDimitry Andric }
52*b5893f02SDimitry Andric 
getLexicalParentId() const53*b5893f02SDimitry Andric SymIndexId NativeSymbolEnumerator::getLexicalParentId() const { return 0; }
54*b5893f02SDimitry Andric 
getName() const55*b5893f02SDimitry Andric std::string NativeSymbolEnumerator::getName() const { return Record.Name; }
56*b5893f02SDimitry Andric 
getTypeId() const57*b5893f02SDimitry Andric SymIndexId NativeSymbolEnumerator::getTypeId() const {
58*b5893f02SDimitry Andric   return Parent.getTypeId();
59*b5893f02SDimitry Andric }
60*b5893f02SDimitry Andric 
getDataKind() const61*b5893f02SDimitry Andric PDB_DataKind NativeSymbolEnumerator::getDataKind() const {
62*b5893f02SDimitry Andric   return PDB_DataKind::Constant;
63*b5893f02SDimitry Andric }
64*b5893f02SDimitry Andric 
getLocationType() const65*b5893f02SDimitry Andric PDB_LocType NativeSymbolEnumerator::getLocationType() const {
66*b5893f02SDimitry Andric   return PDB_LocType::Constant;
67*b5893f02SDimitry Andric }
68*b5893f02SDimitry Andric 
isConstType() const69*b5893f02SDimitry Andric bool NativeSymbolEnumerator::isConstType() const { return false; }
70*b5893f02SDimitry Andric 
isVolatileType() const71*b5893f02SDimitry Andric bool NativeSymbolEnumerator::isVolatileType() const { return false; }
72*b5893f02SDimitry Andric 
isUnalignedType() const73*b5893f02SDimitry Andric bool NativeSymbolEnumerator::isUnalignedType() const { return false; }
74*b5893f02SDimitry Andric 
getValue() const75*b5893f02SDimitry Andric Variant NativeSymbolEnumerator::getValue() const {
76*b5893f02SDimitry Andric   const NativeTypeBuiltin &BT = Parent.getUnderlyingBuiltinType();
77*b5893f02SDimitry Andric 
78*b5893f02SDimitry Andric   switch (BT.getBuiltinType()) {
79*b5893f02SDimitry Andric   case PDB_BuiltinType::Int:
80*b5893f02SDimitry Andric   case PDB_BuiltinType::Long:
81*b5893f02SDimitry Andric   case PDB_BuiltinType::Char: {
82*b5893f02SDimitry Andric     assert(Record.Value.isSignedIntN(BT.getLength() * 8));
83*b5893f02SDimitry Andric     int64_t N = Record.Value.getSExtValue();
84*b5893f02SDimitry Andric     switch (BT.getLength()) {
85*b5893f02SDimitry Andric     case 1:
86*b5893f02SDimitry Andric       return Variant{static_cast<int8_t>(N)};
87*b5893f02SDimitry Andric     case 2:
88*b5893f02SDimitry Andric       return Variant{static_cast<int16_t>(N)};
89*b5893f02SDimitry Andric     case 4:
90*b5893f02SDimitry Andric       return Variant{static_cast<int32_t>(N)};
91*b5893f02SDimitry Andric     case 8:
92*b5893f02SDimitry Andric       return Variant{static_cast<int64_t>(N)};
93*b5893f02SDimitry Andric     }
94*b5893f02SDimitry Andric     break;
95*b5893f02SDimitry Andric   }
96*b5893f02SDimitry Andric   case PDB_BuiltinType::UInt:
97*b5893f02SDimitry Andric   case PDB_BuiltinType::ULong: {
98*b5893f02SDimitry Andric     assert(Record.Value.isIntN(BT.getLength() * 8));
99*b5893f02SDimitry Andric     uint64_t U = Record.Value.getZExtValue();
100*b5893f02SDimitry Andric     switch (BT.getLength()) {
101*b5893f02SDimitry Andric     case 1:
102*b5893f02SDimitry Andric       return Variant{static_cast<uint8_t>(U)};
103*b5893f02SDimitry Andric     case 2:
104*b5893f02SDimitry Andric       return Variant{static_cast<uint16_t>(U)};
105*b5893f02SDimitry Andric     case 4:
106*b5893f02SDimitry Andric       return Variant{static_cast<uint32_t>(U)};
107*b5893f02SDimitry Andric     case 8:
108*b5893f02SDimitry Andric       return Variant{static_cast<uint64_t>(U)};
109*b5893f02SDimitry Andric     }
110*b5893f02SDimitry Andric     break;
111*b5893f02SDimitry Andric   }
112*b5893f02SDimitry Andric   case PDB_BuiltinType::Bool: {
113*b5893f02SDimitry Andric     assert(Record.Value.isIntN(BT.getLength() * 8));
114*b5893f02SDimitry Andric     uint64_t U = Record.Value.getZExtValue();
115*b5893f02SDimitry Andric     return Variant{static_cast<bool>(U)};
116*b5893f02SDimitry Andric   }
117*b5893f02SDimitry Andric   default:
118*b5893f02SDimitry Andric     assert(false && "Invalid enumeration type");
119*b5893f02SDimitry Andric     break;
120*b5893f02SDimitry Andric   }
121*b5893f02SDimitry Andric 
122*b5893f02SDimitry Andric   return Variant{Record.Value.getSExtValue()};
123*b5893f02SDimitry Andric }
124