1 //===-- PdbSymUid.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 using namespace lldb_private
;
12 using namespace lldb_private::npdb
;
13 using namespace llvm::codeview
;
16 struct GenericIdRepr
{
21 struct CompilandIdRepr
{
27 struct CompilandSymIdRepr
{
34 struct GlobalSymIdRepr
{
41 struct TypeSymIdRepr
{
48 struct FieldListMemberIdRepr
{
55 static_assert(sizeof(CompilandIdRepr
) == 8, "Invalid structure size!");
56 static_assert(sizeof(CompilandSymIdRepr
) == 8, "Invalid structure size!");
57 static_assert(sizeof(GlobalSymIdRepr
) == 8, "Invalid structure size!");
58 static_assert(sizeof(TypeSymIdRepr
) == 8, "Invalid structure size!");
59 static_assert(sizeof(FieldListMemberIdRepr
) == 8, "Invalid structure size!");
62 template <typename OutT
, typename InT
> static OutT
repr_cast(const InT
&value
) {
64 ::memcpy(&result
, &value
, sizeof(value
));
68 PdbSymUid::PdbSymUid(const PdbCompilandId
&cid
) {
70 ::memset(&repr
, 0, sizeof(repr
));
72 repr
.tag
= static_cast<uint64_t>(PdbSymUidKind::Compiland
);
73 m_repr
= repr_cast
<uint64_t>(repr
);
76 PdbSymUid::PdbSymUid(const PdbCompilandSymId
&csid
) {
77 CompilandSymIdRepr repr
;
78 ::memset(&repr
, 0, sizeof(repr
));
79 repr
.modi
= csid
.modi
;
80 repr
.offset
= csid
.offset
;
81 repr
.tag
= static_cast<uint64_t>(PdbSymUidKind::CompilandSym
);
82 m_repr
= repr_cast
<uint64_t>(repr
);
85 PdbSymUid::PdbSymUid(const PdbGlobalSymId
&gsid
) {
87 ::memset(&repr
, 0, sizeof(repr
));
88 repr
.pub
= gsid
.is_public
;
89 repr
.offset
= gsid
.offset
;
90 repr
.tag
= static_cast<uint64_t>(PdbSymUidKind::GlobalSym
);
91 m_repr
= repr_cast
<uint64_t>(repr
);
94 PdbSymUid::PdbSymUid(const PdbTypeSymId
&tsid
) {
96 ::memset(&repr
, 0, sizeof(repr
));
97 repr
.index
= tsid
.index
.getIndex();
98 repr
.ipi
= tsid
.is_ipi
;
99 repr
.tag
= static_cast<uint64_t>(PdbSymUidKind::Type
);
100 m_repr
= repr_cast
<uint64_t>(repr
);
103 PdbSymUid::PdbSymUid(const PdbFieldListMemberId
&flmid
) {
104 FieldListMemberIdRepr repr
;
105 ::memset(&repr
, 0, sizeof(repr
));
106 repr
.index
= flmid
.index
.getIndex();
107 repr
.offset
= flmid
.offset
;
108 repr
.tag
= static_cast<uint64_t>(PdbSymUidKind::FieldListMember
);
109 m_repr
= repr_cast
<uint64_t>(repr
);
112 PdbSymUidKind
PdbSymUid::kind() const {
113 GenericIdRepr generic
= repr_cast
<GenericIdRepr
>(m_repr
);
114 return static_cast<PdbSymUidKind
>(generic
.tag
);
117 PdbCompilandId
PdbSymUid::asCompiland() const {
118 assert(kind() == PdbSymUidKind::Compiland
);
119 auto repr
= repr_cast
<CompilandIdRepr
>(m_repr
);
120 PdbCompilandId result
;
121 result
.modi
= repr
.modi
;
125 PdbCompilandSymId
PdbSymUid::asCompilandSym() const {
126 assert(kind() == PdbSymUidKind::CompilandSym
);
127 auto repr
= repr_cast
<CompilandSymIdRepr
>(m_repr
);
128 PdbCompilandSymId result
;
129 result
.modi
= repr
.modi
;
130 result
.offset
= repr
.offset
;
134 PdbGlobalSymId
PdbSymUid::asGlobalSym() const {
135 assert(kind() == PdbSymUidKind::GlobalSym
||
136 kind() == PdbSymUidKind::PublicSym
);
137 auto repr
= repr_cast
<GlobalSymIdRepr
>(m_repr
);
138 PdbGlobalSymId result
;
139 result
.is_public
= repr
.pub
;
140 result
.offset
= repr
.offset
;
144 PdbTypeSymId
PdbSymUid::asTypeSym() const {
145 assert(kind() == PdbSymUidKind::Type
);
146 auto repr
= repr_cast
<TypeSymIdRepr
>(m_repr
);
148 result
.index
.setIndex(repr
.index
);
149 result
.is_ipi
= repr
.ipi
;
153 PdbFieldListMemberId
PdbSymUid::asFieldListMember() const {
154 assert(kind() == PdbSymUidKind::FieldListMember
);
155 auto repr
= repr_cast
<FieldListMemberIdRepr
>(m_repr
);
156 PdbFieldListMemberId result
;
157 result
.index
.setIndex(repr
.index
);
158 result
.offset
= repr
.offset
;