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