9#include "clang/AST/DeclCXX.h"
15#include "llvm/ADT/bit.h"
32 return std::make_shared<RegisterTypeBuilderClang>(target);
45 clang::ASTContext &ast = type_system->getASTContext();
47 if (builtin_type->
GetID() ==
"data_ptr" ||
48 builtin_type->
GetID() ==
"code_ptr")
49 compiler_type = type_system->GetType(ast.VoidPtrTy);
50 else if (builtin_type->
GetID() ==
"bool")
51 compiler_type = type_system->GetType(ast.BoolTy);
52 else if (builtin_type->
GetID() ==
"bfloat16")
53 compiler_type = type_system->GetType(ast.BFloat16Ty);
54 else if (std::optional<uint64_t> byte_size = builtin_type->
GetByteSize())
55 compiler_type = type_system->GetBuiltinTypeForEncodingAndBitSize(
59 llvm::expectedToOptional(compiler_type.
GetByteSize(
nullptr)) !=
64 std::make_pair(builtin_type->
GetUID(), expected_byte_size),
71 uint32_t register_byte_size,
73 if (
auto maybe_compiler_type =
75 return *maybe_compiler_type;
79 register_byte_size * 8);
80 CompilerType enum_type = type_system->CreateEnumerationType(
84 type_system->StartTagDeclarationDefinition(enum_type);
88 type_system->AddEnumerationValueToEnumerationType(
89 enum_type, decl, enumerator.m_name.c_str(), enumerator.m_value,
90 register_byte_size * 8);
93 type_system->CompleteTagDeclarationDefinition(enum_type);
96 std::make_pair(enum_type_info->
GetUID(), register_byte_size), enum_type);
103 if (
auto maybe_compiler_type =
105 return *maybe_compiler_type;
112 register_byte_size * 8);
114 CompilerType flags_type = type_system->CreateRecordType(
117 type_system->StartTagDeclarationDefinition(flags_type);
119 for (
auto field : flags_info->
GetFields()) {
123 if (!enum_type_info->GetEnumerators().empty())
125 BuildEnumType(enum_type_info, register_byte_size, type_system);
127 type_system->AddFieldToRecordType(flags_type, field.GetName(), field_type,
128 field.GetSizeInBits());
131 type_system->CompleteTagDeclarationDefinition(flags_type);
133 type_system->SetIsPacked(flags_type);
137 llvm::expectedToOptional(flags_type.
GetByteSize(
nullptr)).value_or(0) ==
141 std::make_pair(flags_info->
GetUID(), register_byte_size), flags_type);
147 uint32_t expected_byte_size,
149 if (!expected_byte_size)
154 std::optional<uint64_t> element_size =
157 if (expected_byte_size % vector_type->
GetCount())
159 element_size = expected_byte_size / vector_type->
GetCount();
162 expected_byte_size % vector_type->
GetCount() ||
163 *element_size != expected_byte_size / vector_type->
GetCount())
168 switch (element_register_type->
getKind()) {
172 *element_size, type_system);
177 *element_size, type_system);
186 const auto *builtin_element =
187 llvm::dyn_cast<RegisterTypeBuiltin>(element_register_type);
188 bool pointer_element =
189 builtin_element && (builtin_element->GetID() ==
"data_ptr" ||
190 builtin_element->GetID() ==
"code_ptr");
194 bool use_vector = builtin_element && !pointer_element &&
195 builtin_element->GetID() !=
"bool" &&
196 llvm::has_single_bit(vector_type->
GetCount());
197 CompilerType compiler_type = type_system->CreateArrayType(
198 element_type, vector_type->
GetCount(), use_vector);
201 llvm::expectedToOptional(compiler_type.
GetByteSize(
nullptr));
204 if (use_vector && compiler_size != expected_byte_size) {
205 compiler_type = type_system->CreateArrayType(
206 element_type, vector_type->
GetCount(),
false);
208 llvm::expectedToOptional(compiler_type.
GetByteSize(
nullptr));
210 if (compiler_size != expected_byte_size)
214 std::make_pair(vector_type->
GetUID(), expected_byte_size), compiler_type);
215 return compiler_type;
257 const RegisterType *register_type, uint32_t register_byte_size) {
261 return cached->second;
#define LLDB_PLUGIN_DEFINE(PluginName)
Generic representation of a type in a programming language.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
A class that describes the declaration location of a lldb object.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
CompilerType BuildVectorType(const RegisterTypeVector *vector_type, uint32_t expected_byte_size, lldb::TypeSystemClangSP type_system)
std::optional< CompilerType > GetExistingCompilerType(const RegisterType *register_type, uint32_t register_byte_size)
CompilerType BuildEnumType(const RegisterTypeEnum *enum_type_info, uint32_t register_byte_size, lldb::TypeSystemClangSP type_system)
CompilerType BuildFlagsType(const RegisterTypeFlags *flags_info, uint32_t register_byte_size, lldb::TypeSystemClangSP type_system)
std::weak_ptr< TypeSystemClang > m_cached_type_system
CompilerType GetRegisterType(const RegisterInfo ®_info) override
Do not cache the returned CompilerType.
llvm::SmallDenseMap< std::pair< uint64_t, uint32_t >, CompilerType, 8 > m_type_cache
CompilerType BuildBuiltinType(const RegisterTypeBuiltin *builtin_type, uint32_t expected_byte_size, lldb::TypeSystemClangSP type_system)
static llvm::StringRef GetPluginNameStatic()
RegisterTypeBuilderClang(Target &target)
static llvm::StringRef GetPluginDescriptionStatic()
static lldb::RegisterTypeBuilderSP CreateInstance(Target &target)
A predefined GDB target-description type.
lldb::Encoding GetEncoding() const
std::optional< uint64_t > GetByteSize() const override
Return this type's fixed size in bytes, if it has one.
const Enumerators & GetEnumerators() const
const std::vector< Field > & GetFields() const
A GDB target-description vector type. The element type must outlive it.
const RegisterType * GetElementType() const
uint32_t GetCount() const
RegisterTypeKind getKind() const
virtual std::optional< uint64_t > GetByteSize() const
Return this type's fixed size in bytes, if it has one.
const std::string & GetID() const
@ eRegisterTypeKindBuiltin
@ eRegisterTypeKindVector
uint64_t GetUID() const
Return an identifier unique among all RegisterType instances constructed during the lifetime of the L...
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::RegisterTypeBuilder > RegisterTypeBuilderSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eEncodingUint
unsigned integer
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
const RegisterType * register_type
If not nullptr, a type defined by XML descriptions.