summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
blob: c1016b2af0c6bc0cf3fe683ae239d3cd10d55c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//===-- CTFTypes.h ----------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H

#include "lldb/lldb-types.h"
#include "llvm/ADT/StringRef.h"

namespace lldb_private {

struct CTFType {
  enum Kind : uint32_t {
    eUnknown = 0,
    eInteger = 1,
    eFloat = 2,
    ePointer = 3,
    eArray = 4,
    eFunction = 5,
    eStruct = 6,
    eUnion = 7,
    eEnum = 8,
    eForward = 9,
    eTypedef = 10,
    eVolatile = 11,
    eConst = 12,
    eRestrict = 13,
    eSlice = 14,
  };

  Kind kind;
  lldb::user_id_t uid;
  llvm::StringRef name;

  CTFType(Kind kind, lldb::user_id_t uid, llvm::StringRef name)
      : kind(kind), uid(uid), name(name) {}
};

struct CTFInteger : public CTFType {
  CTFInteger(lldb::user_id_t uid, llvm::StringRef name, uint32_t bits,
             uint32_t encoding)
      : CTFType(eInteger, uid, name), bits(bits), encoding(encoding) {}

  static bool classof(const CTFType *T) { return T->kind == eInteger; }

  uint32_t bits;
  uint32_t encoding;
};

struct CTFModifier : public CTFType {
protected:
  CTFModifier(Kind kind, lldb::user_id_t uid, uint32_t type)
      : CTFType(kind, uid, ""), type(type) {}

  static bool classof(const CTFType *T) {
    return T->kind == ePointer || T->kind == eConst || T->kind == eVolatile ||
           T->kind == eRestrict;
  }

public:
  uint32_t type;
};

struct CTFPointer : public CTFModifier {
  CTFPointer(lldb::user_id_t uid, uint32_t type)
      : CTFModifier(ePointer, uid, type) {}

  static bool classof(const CTFType *T) { return T->kind == ePointer; }
};

struct CTFConst : public CTFModifier {
  CTFConst(lldb::user_id_t uid, uint32_t type)
      : CTFModifier(eConst, uid, type) {}

  static bool classof(const CTFType *T) { return T->kind == eConst; }
};

struct CTFVolatile : public CTFModifier {
  CTFVolatile(lldb::user_id_t uid, uint32_t type)
      : CTFModifier(eVolatile, uid, type) {}

  static bool classof(const CTFType *T) { return T->kind == eVolatile; }
};

struct CTFRestrict : public CTFModifier {
  CTFRestrict(lldb::user_id_t uid, uint32_t type)
      : CTFModifier(eRestrict, uid, type) {}
  static bool classof(const CTFType *T) { return T->kind == eRestrict; }
};

struct CTFTypedef : public CTFType {
  CTFTypedef(lldb::user_id_t uid, llvm::StringRef name, uint32_t type)
      : CTFType(eTypedef, uid, name), type(type) {}

  static bool classof(const CTFType *T) { return T->kind == eTypedef; }

  uint32_t type;
};

struct CTFArray : public CTFType {
  CTFArray(lldb::user_id_t uid, llvm::StringRef name, uint32_t type,
           uint32_t index, uint32_t nelems)
      : CTFType(eArray, uid, name), type(type), index(index), nelems(nelems) {}

  static bool classof(const CTFType *T) { return T->kind == eArray; }

  uint32_t type;
  uint32_t index;
  uint32_t nelems;
};

struct CTFEnum : public CTFType {
  struct Value {
    Value(llvm::StringRef name, uint32_t value) : name(name), value(value){};
    llvm::StringRef name;
    uint32_t value;
  };

  CTFEnum(lldb::user_id_t uid, llvm::StringRef name, uint32_t nelems,
          uint32_t size, std::vector<Value> values)
      : CTFType(eEnum, uid, name), nelems(nelems), size(size),
        values(std::move(values)) {
    assert(this->values.size() == nelems);
  }

  static bool classof(const CTFType *T) { return T->kind == eEnum; }

  uint32_t nelems;
  uint32_t size;
  std::vector<Value> values;
};

struct CTFFunction : public CTFType {
  CTFFunction(lldb::user_id_t uid, llvm::StringRef name, uint32_t nargs,
              uint32_t return_type, std::vector<uint32_t> args, bool variadic)
      : CTFType(eFunction, uid, name), nargs(nargs), return_type(return_type),
        args(std::move(args)), variadic(variadic) {}

  static bool classof(const CTFType *T) { return T->kind == eFunction; }

  uint32_t nargs;
  uint32_t return_type;

  std::vector<uint32_t> args;
  bool variadic = false;
};

struct CTFRecord : public CTFType {
public:
  struct Field {
    Field(llvm::StringRef name, uint32_t type, uint64_t offset)
        : name(name), type(type), offset(offset) {}

    llvm::StringRef name;
    uint32_t type;
    uint64_t offset;
  };

  CTFRecord(Kind kind, lldb::user_id_t uid, llvm::StringRef name,
            uint32_t nfields, uint32_t size, std::vector<Field> fields)
      : CTFType(kind, uid, name), nfields(nfields), size(size),
        fields(std::move(fields)) {}

  static bool classof(const CTFType *T) {
    return T->kind == eStruct || T->kind == eUnion;
  }

  uint32_t nfields;
  uint32_t size;
  std::vector<Field> fields;
};

struct CTFStruct : public CTFRecord {
  CTFStruct(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
            uint32_t size, std::vector<Field> fields)
      : CTFRecord(eStruct, uid, name, nfields, size, std::move(fields)){};

  static bool classof(const CTFType *T) { return T->kind == eStruct; }
};

struct CTFUnion : public CTFRecord {
  CTFUnion(lldb::user_id_t uid, llvm::StringRef name, uint32_t nfields,
           uint32_t size, std::vector<Field> fields)
      : CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};

  static bool classof(const CTFType *T) { return T->kind == eUnion; }
};

struct CTFForward : public CTFType {
  CTFForward(lldb::user_id_t uid, llvm::StringRef name)
      : CTFType(eForward, uid, name) {}

  static bool classof(const CTFType *T) { return T->kind == eForward; }
};

} // namespace lldb_private

#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H