Skip to content

Commit 0a5e0d3

Browse files
committed
[lldb] Split CTF parsing and type creation (NFC)
Separate parsing CTF and creating LLDB types. This is a prerequisite to parsing forward references and recursive types. Differential revision: https://reviews.llvm.org/D156447
1 parent b0688ed commit 0a5e0d3

File tree

4 files changed

+428
-250
lines changed

4 files changed

+428
-250
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
15+
namespace lldb_private {
16+
17+
struct 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+
44+
struct 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+
uint32_t bits;
50+
uint32_t encoding;
51+
};
52+
53+
struct CTFModifier : public CTFType {
54+
protected:
55+
CTFModifier(Kind kind, lldb::user_id_t uid, uint32_t type)
56+
: CTFType(kind, uid, ""), type(type) {}
57+
58+
public:
59+
uint32_t type;
60+
};
61+
62+
struct CTFPointer : public CTFModifier {
63+
CTFPointer(lldb::user_id_t uid, uint32_t type)
64+
: CTFModifier(ePointer, uid, type) {}
65+
};
66+
67+
struct CTFConst : public CTFModifier {
68+
CTFConst(lldb::user_id_t uid, uint32_t type)
69+
: CTFModifier(eConst, uid, type) {}
70+
};
71+
72+
struct CTFVolatile : public CTFModifier {
73+
CTFVolatile(lldb::user_id_t uid, uint32_t type)
74+
: CTFModifier(eVolatile, uid, type) {}
75+
};
76+
77+
struct CTFRestrict : public CTFModifier {
78+
CTFRestrict(lldb::user_id_t uid, uint32_t type)
79+
: CTFModifier(eRestrict, uid, type) {}
80+
};
81+
82+
struct CTFTypedef : public CTFType {
83+
CTFTypedef(lldb::user_id_t uid, llvm::StringRef name, uint32_t type)
84+
: CTFType(eTypedef, uid, name), type(type) {}
85+
86+
uint32_t type;
87+
};
88+
89+
struct CTFArray : public CTFType {
90+
CTFArray(lldb::user_id_t uid, llvm::StringRef name, uint32_t type,
91+
uint32_t index, uint32_t nelems)
92+
: CTFType(eArray, uid, name), type(type), index(index), nelems(nelems) {}
93+
94+
uint32_t type;
95+
uint32_t index;
96+
uint32_t nelems;
97+
};
98+
99+
struct CTFEnum : public CTFType {
100+
struct Value {
101+
Value(llvm::StringRef name, uint32_t value) : name(name), value(value){};
102+
llvm::StringRef name;
103+
uint32_t value;
104+
};
105+
106+
CTFEnum(lldb::user_id_t uid, llvm::StringRef name, uint32_t nelems,
107+
uint32_t size, std::vector<Value> values)
108+
: CTFType(eEnum, uid, name), nelems(nelems), size(size),
109+
values(std::move(values)) {
110+
assert(this->values.size() == nelems);
111+
}
112+
113+
uint32_t nelems;
114+
uint32_t size;
115+
std::vector<Value> values;
116+
};
117+
118+
struct CTFFunction : public CTFType {
119+
CTFFunction(lldb::user_id_t uid, llvm::StringRef name, uint32_t nargs,
120+
uint32_t return_type, std::vector<uint32_t> args, bool variadic)
121+
: CTFType(eFunction, uid, name), nargs(nargs), return_type(return_type),
122+
args(std::move(args)), variadic(variadic) {}
123+
124+
uint32_t nargs;
125+
uint32_t return_type;
126+
127+
std::vector<uint32_t> args;
128+
bool variadic = false;
129+
};
130+
131+
struct CTFRecord : public CTFType {
132+
public:
133+
struct Field {
134+
Field(llvm::StringRef name, uint32_t type, uint16_t offset,
135+
uint16_t padding)
136+
: name(name), type(type), offset(offset), padding(padding) {}
137+
138+
llvm::StringRef name;
139+
uint32_t type;
140+
uint16_t offset;
141+
uint16_t padding;
142+
};
143+
144+
CTFRecord(Kind kind, lldb::user_id_t uid, llvm::StringRef name,
145+
uint32_t nfields, uint32_t size, std::vector<Field> fields)
146+
: CTFType(kind, uid, name), nfields(nfields), size(size),
147+
fields(std::move(fields)) {}
148+
149+
uint32_t nfields;
150+
uint32_t size;
151+
std::vector<Field> fields;
152+
};
153+
154+
struct CTFStruct : public CTFRecord {
155+
CTFStruct(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
156+
uint32_t size, std::vector<Field> fields)
157+
: CTFRecord(eStruct, uid, name, nfields, size, std::move(fields)){};
158+
};
159+
160+
struct CTFUnion : public CTFRecord {
161+
CTFUnion(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
162+
uint32_t size, std::vector<Field> fields)
163+
: CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
164+
};
165+
166+
} // namespace lldb_private
167+
168+
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H

0 commit comments

Comments
 (0)