forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSILFormat.h
379 lines (339 loc) · 11 KB
/
SILFormat.h
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//===--- SILFormat.h - The internals of serialized SILs --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file Contains various constants and helper types to deal with serialized
/// SILs.
///
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SERIALIZATION_SILFORMAT_H
#define SWIFT_SERIALIZATION_SILFORMAT_H
#include "swift/Serialization/ModuleFormat.h"
namespace swift {
namespace serialization {
using ValueID = DeclID;
using ValueIDField = DeclIDField;
using SILInstOpCodeField = BCFixed<8>;
using SILTypeCategoryField = BCFixed<2>;
using SILValueResultField = BCFixed<8>;
enum SILStringEncoding : uint8_t {
SIL_UTF8,
SIL_UTF16
};
enum SILLinkageEncoding : uint8_t {
SIL_LINKAGE_PUBLIC,
SIL_LINKAGE_HIDDEN,
SIL_LINKAGE_SHARED,
SIL_LINKAGE_PRIVATE,
SIL_LINKAGE_PUBLIC_EXTERNAL,
SIL_LINKAGE_HIDDEN_EXTERNAL,
SIL_LINKAGE_SHARED_EXTERNAL,
SIL_LINKAGE_PRIVATE_EXTERNAL,
};
using SILLinkageField = BCFixed<3>;
enum CheckedCastKindEncoding : uint8_t {
SIL_CHECKED_CAST_ARCHETYPE_TO_ARCHETYPE,
SIL_CHECKED_CAST_ARCHETYPE_TO_CONCRETE,
SIL_CHECKED_CAST_ARRAY_DOWNCAST,
SIL_CHECKED_CAST_ARRAY_DOWNCAST_BRIDGED,
SIL_CHECKED_CAST_DICTIONARY_DOWNCAST,
SIL_CHECKED_CAST_DICTIONARY_DOWNCAST_BRIDGED,
SIL_CHECKED_CAST_DOWNCAST,
SIL_CHECKED_CAST_IDENTICAL,
SIL_CHECKED_CAST_EXISTENTIAL_TO_ARCHETYPE,
SIL_CHECKED_CAST_EXISTENTIAL_TO_CONCRETE,
SIL_CHECKED_CAST_SUPER_TO_ARCHETYPE,
SIL_CHECKED_CAST_CONCRETE_TO_ARCHETYPE,
SIL_CHECKED_CAST_CONCRETE_TO_UNRELATED_EXISTENTIAL,
};
enum CastConsumptionKindEncoding : uint8_t {
SIL_CAST_CONSUMPTION_TAKE_ALWAYS,
SIL_CAST_CONSUMPTION_TAKE_ON_SUCCESS,
SIL_CAST_CONSUMPTION_COPY_ON_SUCCESS,
};
// Constants for packing an encoded CheckedCastKind and
// CastConsumptionKind together.
enum {
// Must be large enough to store all the CheckedCastKindEncodings
SIL_CAST_CONSUMPTION_BIT_OFFSET = 4,
SIL_CHECKED_CAST_MASK =
(1 << SIL_CAST_CONSUMPTION_BIT_OFFSET) - 1
};
/// The record types within the "sil-index" block.
///
/// \sa SIL_INDEX_BLOCK_ID
namespace sil_index_block {
// These IDs must \em not be renumbered or reordered without incrementing
// VERSION_MAJOR.
enum RecordKind {
SIL_FUNC_NAMES = 1,
SIL_FUNC_OFFSETS,
SIL_VTABLE_NAMES,
SIL_VTABLE_OFFSETS,
SIL_GLOBALVAR_NAMES,
SIL_GLOBALVAR_OFFSETS,
SIL_WITNESSTABLE_NAMES,
SIL_WITNESSTABLE_OFFSETS
};
using ListLayout = BCGenericRecordLayout<
BCFixed<4>, // record ID
BCVBR<16>, // table offset within the blob
BCBlob // map from identifier strings to IDs.
>;
using OffsetLayout = BCGenericRecordLayout<
BCFixed<4>, // record ID
BCArray<BitOffsetField>
>;
}
/// The record types within the "sil" block.
///
/// \sa SIL_BLOCK_ID
namespace sil_block {
// These IDs must \em not be renumbered or reordered without incrementing
// VERSION_MAJOR.
enum RecordKind : uint8_t {
SIL_FUNCTION = 1,
SIL_BASIC_BLOCK,
SIL_ONE_VALUE_ONE_OPERAND,
SIL_ONE_TYPE,
SIL_ONE_OPERAND,
SIL_ONE_TYPE_ONE_OPERAND,
SIL_ONE_TYPE_VALUES,
SIL_TWO_OPERANDS,
SIL_INST_APPLY,
SIL_INST_NO_OPERAND,
SIL_VTABLE,
SIL_VTABLE_ENTRY,
SIL_GLOBALVAR,
SIL_INST_CAST, // It has a cast kind instead of an attribute.
SIL_INIT_EXISTENTIAL,
SIL_WITNESSTABLE,
SIL_WITNESS_METHOD_ENTRY,
// To avoid overlapping with BOUND_GENERIC_SUBSTITUTION, we start from +1.
// FIXME: another option is to start SIL_FUNCTION at a large number.
SIL_WITNESS_BASE_ENTRY = decls_block::BOUND_GENERIC_SUBSTITUTION + 1,
SIL_WITNESS_ASSOC_PROTOCOL,
SIL_WITNESS_ASSOC_ENTRY,
SIL_GENERIC_OUTER_PARAMS,
SIL_INST_WITNESS_METHOD,
// We also share these layouts from the decls block. Their enumerators must
// not overlap with ours.
BOUND_GENERIC_SUBSTITUTION = decls_block::BOUND_GENERIC_SUBSTITUTION,
NO_CONFORMANCE = decls_block::NO_CONFORMANCE,
NORMAL_PROTOCOL_CONFORMANCE = decls_block::NORMAL_PROTOCOL_CONFORMANCE,
SPECIALIZED_PROTOCOL_CONFORMANCE
= decls_block::SPECIALIZED_PROTOCOL_CONFORMANCE,
INHERITED_PROTOCOL_CONFORMANCE
= decls_block::INHERITED_PROTOCOL_CONFORMANCE,
GENERIC_PARAM_LIST = decls_block::GENERIC_PARAM_LIST,
GENERIC_PARAM = decls_block::GENERIC_PARAM,
GENERIC_REQUIREMENT = decls_block::GENERIC_REQUIREMENT,
LAST_GENERIC_REQUIREMENT = decls_block::LAST_GENERIC_REQUIREMENT,
};
using SILInstNoOperandLayout = BCRecordLayout<
SIL_INST_NO_OPERAND,
SILInstOpCodeField
>;
using VTableLayout = BCRecordLayout<
SIL_VTABLE,
DeclIDField // Class Decl
>;
using VTableEntryLayout = BCRecordLayout<
SIL_VTABLE_ENTRY,
DeclIDField, // SILFunction name
BCArray<ValueIDField> // SILDeclRef
>;
using WitnessTableLayout = BCRecordLayout<
SIL_WITNESSTABLE,
SILLinkageField, // Linkage
BCFixed<1>, // Is this a declaration. We represent this separately
// from whether or not we have entries since we can
// have empty witness tables.
BCFixed<1> // IsFragile.
// Conformance follows
// Witness table entries will be serialized after.
>;
using WitnessMethodEntryLayout = BCRecordLayout<
SIL_WITNESS_METHOD_ENTRY,
DeclIDField, // SILFunction name
BCArray<ValueIDField> // SILDeclRef
>;
using WitnessBaseEntryLayout = BCRecordLayout<
SIL_WITNESS_BASE_ENTRY,
DeclIDField // ID of protocol decl
// Trailed by the conformance itself.
>;
using WitnessAssocProtocolLayout = BCRecordLayout<
SIL_WITNESS_ASSOC_PROTOCOL,
DeclIDField, // ID of AssociatedTypeDecl
DeclIDField // ID of ProtocolDecl
// Trailed by the conformance itself if appropriate.
>;
using WitnessAssocEntryLayout = BCRecordLayout<
SIL_WITNESS_ASSOC_ENTRY,
DeclIDField, // ID of AssociatedTypeDecl
TypeIDField
>;
using GlobalVarLayout = BCRecordLayout<
SIL_GLOBALVAR,
SILLinkageField,
BCFixed<1>, // fragile
TypeIDField,
DeclIDField,
BCFixed<1>, // Is this a declaration.
BCFixed<1> // Is this a let variable.
>;
using SILFunctionLayout = BCRecordLayout<
SIL_FUNCTION,
SILLinkageField,
BCFixed<1>, // transparent
BCFixed<1>, // fragile
BCFixed<2>, // thunk/reabstraction_thunk
BCFixed<1>, // global_init
BCFixed<2>, // inlineStrategy
BCFixed<2>, // side effect info.
TypeIDField,
IdentifierIDField // Semantics Attribute
// followed by generic param list, if any
>;
// Has an optional argument list where each argument is a typed valueref.
using SILBasicBlockLayout = BCRecordLayout<
SIL_BASIC_BLOCK,
BCArray<DeclIDField> // The array contains type-value pairs.
>;
// SIL instructions with one valueref and one typed valueref.
// (store)
using SILOneValueOneOperandLayout = BCRecordLayout<
SIL_ONE_VALUE_ONE_OPERAND,
SILInstOpCodeField,
BCFixed<2>, // Optional attributes
ValueIDField,
SILValueResultField,
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField
>;
// SIL instructions with one type and one typed valueref.
using SILOneTypeOneOperandLayout = BCRecordLayout<
SIL_ONE_TYPE_ONE_OPERAND,
SILInstOpCodeField,
BCFixed<2>, // Optional attributes
TypeIDField,
SILTypeCategoryField,
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField
>;
// SIL instructions that construct existential values.
using SILInitExistentialLayout = BCRecordLayout<
SIL_INIT_EXISTENTIAL,
SILInstOpCodeField, // opcode
TypeIDField, // result type
SILTypeCategoryField, // result type category
TypeIDField, // operand type
SILTypeCategoryField, // operand type category
ValueIDField, // operand id
SILValueResultField, // operand result id
TypeIDField, // formal concrete type
BCVBR<5> // # of protocol conformances
// Trailed by protocol conformance info (if any)
>;
// SIL Cast instructions with a cast kind, one type and one typed valueref.
using SILInstCastLayout = BCRecordLayout<
SIL_INST_CAST,
SILInstOpCodeField,
BCFixed<4>, // Cast kind
TypeIDField,
SILTypeCategoryField,
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField
>;
// SIL instructions with one type and a list of values.
using SILOneTypeValuesLayout = BCRecordLayout<
SIL_ONE_TYPE_VALUES,
SILInstOpCodeField,
TypeIDField,
SILTypeCategoryField,
BCArray<ValueIDField>
>;
enum ApplyKind : unsigned {
SIL_APPLY = 0,
SIL_PARTIAL_APPLY,
SIL_BUILTIN,
SIL_TRY_APPLY,
SIL_NON_THROWING_APPLY
};
using SILInstApplyLayout = BCRecordLayout<
SIL_INST_APPLY,
BCFixed<3>, // ApplyKind
BCFixed<32>, // num substitutions
TypeIDField, // callee unsubstituted type
TypeIDField, // callee substituted type
ValueIDField, // callee value
SILValueResultField,
BCArray<ValueIDField> // a list of arguments
>;
// SIL instructions with one type. (alloc_stack)
using SILOneTypeLayout = BCRecordLayout<
SIL_ONE_TYPE,
SILInstOpCodeField,
TypeIDField,
SILTypeCategoryField
>;
// SIL instructions with one typed valueref. (dealloc_stack, return)
using SILOneOperandLayout = BCRecordLayout<
SIL_ONE_OPERAND,
SILInstOpCodeField,
BCFixed<3>, // Optional attributes
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField
>;
// SIL instructions with two typed values.
using SILTwoOperandsLayout = BCRecordLayout<
SIL_TWO_OPERANDS,
SILInstOpCodeField,
BCFixed<2>, // Optional attributes
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField,
TypeIDField,
SILTypeCategoryField,
ValueIDField,
SILValueResultField
>;
using SILGenericOuterParamsLayout = BCRecordLayout<
SIL_GENERIC_OUTER_PARAMS,
DeclIDField // The decl id of the outer param if any.
>;
using SILInstWitnessMethodLayout = BCRecordLayout<
SIL_INST_WITNESS_METHOD,
TypeIDField, // result type
SILTypeCategoryField,
BCFixed<1>, // volatile?
TypeIDField, // lookup type
SILTypeCategoryField,
TypeIDField, // Optional
SILTypeCategoryField, // opened
ValueIDField, // existential
BCArray<ValueIDField> // SILDeclRef
// may be trailed by an inline protocol conformance
>;
}
} // end namespace serialization
} // end namespace swift
#endif