Skip to content

Commit 26d89d6

Browse files
committed
[lldb] Implement GetBitSize for builtin types in D TypeSystem
1 parent 38e5f71 commit 26d89d6

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

lldb/source/Plugins/TypeSystem/D/DType.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,61 @@ lldb::BasicType DType::GetBasicType() const {
124124
return lldb::eBasicTypeOther;
125125
}
126126
}
127+
128+
static uint64_t GetRealBitSize(llvm::Triple &target_triple) {
129+
if (target_triple.isX86() && target_triple.isArch64Bit())
130+
// Assume x87 support: x87 FPU register size
131+
return 80;
132+
133+
// at least size of a double type kind
134+
return 64;
135+
}
136+
137+
llvm::Optional<uint64_t> DType::GetBitSize(llvm::Triple &target_triple) const {
138+
return DType::GetBitSize(m_kind, target_triple);
139+
}
140+
141+
llvm::Optional<uint64_t> DType::GetBitSize(DTypeKind kind, llvm::Triple &target_triple) {
142+
switch(kind)
143+
{
144+
case eDTypeKindPtr:
145+
if (target_triple.isArch64Bit())
146+
return 64;
147+
if (target_triple.isArch32Bit())
148+
return 32;
149+
if (target_triple.isArch16Bit())
150+
return 16;
151+
152+
// unknown arch bit size
153+
return llvm::None;
154+
case eDTypeKindBool:
155+
case eDTypeKindByte:
156+
case eDTypeKindUByte:
157+
case eDTypeKindChar:
158+
return 8;
159+
case eDTypeKindShort:
160+
case eDTypeKindUShort:
161+
case eDTypeKindWChar:
162+
return 16;
163+
case eDTypeKindInt:
164+
case eDTypeKindUInt:
165+
case eDTypeKindDChar:
166+
case eDTypeKindFloat:
167+
return 32;
168+
case eDTypeKindLong:
169+
case eDTypeKindULong:
170+
case eDTypeKindDouble:
171+
case eDTypeKindCFloat:
172+
return 64;
173+
case eDTypeKindCent:
174+
case eDTypeKindUCent:
175+
case eDTypeKindCDouble:
176+
return 128;
177+
case eDTypeKindReal:
178+
return GetRealBitSize(target_triple);
179+
case eDTypeKindCReal:
180+
return GetRealBitSize(target_triple) * 2;
181+
default:
182+
return llvm::None;
183+
}
184+
}

lldb/source/Plugins/TypeSystem/D/DType.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "lldb/Utility/ConstString.h"
1313
#include "lldb/lldb-enumerations.h"
14+
#include "llvm/ADT/APInt.h"
15+
#include "llvm/ADT/Triple.h"
1416

1517
enum DTypeKind : uint8_t {
1618
eDTypeKindInvalid = 0,
@@ -61,6 +63,9 @@ class DType {
6163
lldb::Encoding GetEncoding(uint64_t &count) const;
6264
lldb::BasicType GetBasicType() const;
6365

66+
static llvm::Optional<uint64_t> GetBitSize(DTypeKind kind, llvm::Triple &target_triple);
67+
llvm::Optional<uint64_t> GetBitSize(llvm::Triple &target_triple) const;
68+
6469
private:
6570
DTypeKind m_kind;
6671
ConstString m_name;

lldb/source/Plugins/TypeSystem/D/TypeSystemD.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ CompilerType TypeSystemD::GetBasicTypeFromAST(lldb::BasicType basic_type) {
300300
llvm::Optional<uint64_t>
301301
TypeSystemD::GetBitSize(lldb::opaque_compiler_type_t type,
302302
ExecutionContextScope *exe_scope) {
303-
return llvm::None;
303+
if(!GetCompleteType(type))
304+
return llvm::None;
305+
306+
return static_cast<DType*>(type)->GetBitSize(m_target_triple);
304307
}
305308

306309
lldb::Encoding TypeSystemD::GetEncoding(lldb::opaque_compiler_type_t type,

0 commit comments

Comments
 (0)