1//===-- CTFTypes.h ----------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
11
12#include "lldb/lldb-types.h"
13#include "llvm/ADT/StringRef.h"
14
15namespace lldb_private {
16
17struct CTFType {
18 enum Kind : uint32_t {
19 eUnknown = 0,
20 eInteger = 1,
21 eFloat = 2,
22 ePointer = 3,
23 eArray = 4,
24 eFunction = 5,
25 eStruct = 6,
26 eUnion = 7,
27 eEnum = 8,
28 eForward = 9,
29 eTypedef = 10,
30 eVolatile = 11,
31 eConst = 12,
32 eRestrict = 13,
33 eSlice = 14,
34 };
35
36 Kind kind;
37 lldb::user_id_t uid;
38 llvm::StringRef name;
39
40 CTFType(Kind kind, lldb::user_id_t uid, llvm::StringRef name)
41 : kind(kind), uid(uid), name(name) {}
42};
43
44struct CTFInteger : public CTFType {
45 CTFInteger(lldb::user_id_t uid, llvm::StringRef name, uint32_t bits,
46 uint32_t encoding)
47 : CTFType(eInteger, uid, name), bits(bits), encoding(encoding) {}
48
49 static bool classof(const CTFType *T) { return T->kind == eInteger; }
50
51 uint32_t bits;
52 uint32_t encoding;
53};
54
55struct CTFModifier : public CTFType {
56protected:
57 CTFModifier(Kind kind, lldb::user_id_t uid, uint32_t type)
58 : CTFType(kind, uid, ""), type(type) {}
59
60 static bool classof(const CTFType *T) {
61 return T->kind == ePointer || T->kind == eConst || T->kind == eVolatile ||
62 T->kind == eRestrict;
63 }
64
65public:
66 uint32_t type;
67};
68
69struct CTFPointer : public CTFModifier {
70 CTFPointer(lldb::user_id_t uid, uint32_t type)
71 : CTFModifier(ePointer, uid, type) {}
72
73 static bool classof(const CTFType *T) { return T->kind == ePointer; }
74};
75
76struct CTFConst : public CTFModifier {
77 CTFConst(lldb::user_id_t uid, uint32_t type)
78 : CTFModifier(eConst, uid, type) {}
79
80 static bool classof(const CTFType *T) { return T->kind == eConst; }
81};
82
83struct CTFVolatile : public CTFModifier {
84 CTFVolatile(lldb::user_id_t uid, uint32_t type)
85 : CTFModifier(eVolatile, uid, type) {}
86
87 static bool classof(const CTFType *T) { return T->kind == eVolatile; }
88};
89
90struct CTFRestrict : public CTFModifier {
91 CTFRestrict(lldb::user_id_t uid, uint32_t type)
92 : CTFModifier(eRestrict, uid, type) {}
93 static bool classof(const CTFType *T) { return T->kind == eRestrict; }
94};
95
96struct CTFTypedef : public CTFType {
97 CTFTypedef(lldb::user_id_t uid, llvm::StringRef name, uint32_t type)
98 : CTFType(eTypedef, uid, name), type(type) {}
99
100 static bool classof(const CTFType *T) { return T->kind == eTypedef; }
101
102 uint32_t type;
103};
104
105struct CTFArray : public CTFType {
106 CTFArray(lldb::user_id_t uid, llvm::StringRef name, uint32_t type,
107 uint32_t index, uint32_t nelems)
108 : CTFType(eArray, uid, name), type(type), index(index), nelems(nelems) {}
109
110 static bool classof(const CTFType *T) { return T->kind == eArray; }
111
112 uint32_t type;
113 uint32_t index;
114 uint32_t nelems;
115};
116
117struct CTFEnum : public CTFType {
118 struct Value {
119 Value(llvm::StringRef name, uint32_t value) : name(name), value(value){};
120 llvm::StringRef name;
121 uint32_t value;
122 };
123
124 CTFEnum(lldb::user_id_t uid, llvm::StringRef name, uint32_t nelems,
125 uint32_t size, std::vector<Value> values)
126 : CTFType(eEnum, uid, name), nelems(nelems), size(size),
127 values(std::move(values)) {
128 assert(this->values.size() == nelems);
129 }
130
131 static bool classof(const CTFType *T) { return T->kind == eEnum; }
132
133 uint32_t nelems;
134 uint32_t size;
135 std::vector<Value> values;
136};
137
138struct CTFFunction : public CTFType {
139 CTFFunction(lldb::user_id_t uid, llvm::StringRef name, uint32_t nargs,
140 uint32_t return_type, std::vector<uint32_t> args, bool variadic)
141 : CTFType(eFunction, uid, name), nargs(nargs), return_type(return_type),
142 args(std::move(args)), variadic(variadic) {}
143
144 static bool classof(const CTFType *T) { return T->kind == eFunction; }
145
146 uint32_t nargs;
147 uint32_t return_type;
148
149 std::vector<uint32_t> args;
150 bool variadic = false;
151};
152
153struct CTFRecord : public CTFType {
154public:
155 struct Field {
156 Field(llvm::StringRef name, uint32_t type, uint64_t offset)
157 : name(name), type(type), offset(offset) {}
158
159 llvm::StringRef name;
160 uint32_t type;
161 uint64_t offset;
162 };
163
164 CTFRecord(Kind kind, lldb::user_id_t uid, llvm::StringRef name,
165 uint32_t nfields, uint32_t size, std::vector<Field> fields)
166 : CTFType(kind, uid, name), nfields(nfields), size(size),
167 fields(std::move(fields)) {}
168
169 static bool classof(const CTFType *T) {
170 return T->kind == eStruct || T->kind == eUnion;
171 }
172
173 uint32_t nfields;
174 uint32_t size;
175 std::vector<Field> fields;
176};
177
178struct CTFStruct : public CTFRecord {
179 CTFStruct(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
180 uint32_t size, std::vector<Field> fields)
181 : CTFRecord(eStruct, uid, name, nfields, size, std::move(fields)){};
182
183 static bool classof(const CTFType *T) { return T->kind == eStruct; }
184};
185
186struct CTFUnion : public CTFRecord {
187 CTFUnion(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
188 uint32_t size, std::vector<Field> fields)
189 : CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
190
191 static bool classof(const CTFType *T) { return T->kind == eUnion; }
192};
193
194struct CTFForward : public CTFType {
195 CTFForward(lldb::user_id_t uid, llvm::StringRef name)
196 : CTFType(eForward, uid, name) {}
197
198 static bool classof(const CTFType *T) { return T->kind == eForward; }
199};
200
201} // namespace lldb_private
202
203#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
204

source code of lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h