14
14
#define SWIFT_SIL_SILBRIDGING_H
15
15
16
16
#include " BridgedSwiftObject.h"
17
+
18
+ #include " swift/SIL/SILNode.h"
19
+ #include " swift/SIL/SILType.h"
20
+ #include " swift/SIL/SILUndef.h"
21
+ #include " swift/SIL/SILArgument.h"
22
+ #include " swift/SIL/SILInstruction.h"
23
+ #include " swift/SIL/SILBasicBlock.h"
24
+ #include " swift/SIL/SILFunction.h"
25
+
26
+ #include " swift/AST/AnyFunctionRef.h"
27
+
17
28
#include < stddef.h>
18
29
#include < string>
19
30
31
+ using namespace swift ;
32
+
33
+ #define INST (ID, NAME ) \
34
+ inline SILInstruction * _Nonnull getAsSILInstruction (ID * _Nonnull I) { \
35
+ return static_cast <SILInstruction *>(I); \
36
+ } \
37
+ inline ID * _Nullable getAs##ID(SILInstruction * _Nonnull p) { \
38
+ return dyn_cast<ID>(p); \
39
+ } \
40
+ inline bool isa##ID(SILInstruction * _Nonnull p) { return isa<ID>(p); }
41
+
42
+ #define ABSTRACT_INST (ID, NAME ) \
43
+ inline SILInstruction * _Nonnull getAsSILInstruction (ID * _Nonnull I) { \
44
+ return static_cast <SILInstruction *>(I); \
45
+ } \
46
+ inline ID * _Nullable getAs##ID(SILInstruction * _Nonnull p) { \
47
+ return dyn_cast<ID>(p); \
48
+ } \
49
+ inline bool isa##ID(SILInstruction * _Nonnull p) { return isa<ID>(p); }
50
+
51
+ #include " swift/SIL/SILNodes.def"
52
+ #undef INST
53
+
54
+ #define VALUE (ID, NAME ) \
55
+ inline ID * _Nullable getAs##ID(ValueBase *v) { \
56
+ return dyn_cast<ID>(v); \
57
+ } \
58
+ inline bool isa##ID(ValueBase *v) { return isa<ID>(v); } \
59
+ inline ValueBase * _Nullable getAsValue (ID * _Nonnull v) { \
60
+ return dyn_cast<ValueBase>(v); \
61
+ }
62
+
63
+ #include " swift/SIL/SILNodes.def"
64
+ #undef SINGLE_VALUE_INST
65
+
66
+ // There are a couple of holes in the above set of functions.
67
+ inline SILArgument * _Nullable getAsSILArgument (ValueBase *a) {
68
+ return dyn_cast<SILArgument>(a);
69
+ }
70
+
71
+ inline SILArgument * _Nullable getAsSILArgument (SILPhiArgument *a) {
72
+ return dyn_cast<SILArgument>(a);
73
+ }
74
+
75
+ inline SILArgument * _Nullable getAsSILArgument (SILFunctionArgument *a) {
76
+ return dyn_cast<SILArgument>(a);
77
+ }
78
+
79
+ inline SingleValueInstruction * _Nullable
80
+ getAsSingleValueInstruction (ValueBase *v) {
81
+ return dyn_cast<SingleValueInstruction>(v);
82
+ }
83
+
84
+ inline ValueBase * _Nullable getAsValue (SILArgument * _Nonnull v) {
85
+ return dyn_cast<ValueBase>(v);
86
+ }
87
+
88
+ inline ValueBase * _Nullable getAsValue (SingleValueInstruction * _Nonnull v) {
89
+ return dyn_cast<ValueBase>(v);
90
+ }
91
+
92
+ inline ValueBase * _Nullable getAsValue (SILValue v) { return v; }
93
+
20
94
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
21
95
96
+ template <class T > using OptionalRef = T * _Nullable;
97
+
22
98
typedef struct {
23
99
const unsigned char * _Nullable data;
24
100
size_t length;
@@ -62,10 +138,6 @@ typedef struct {
62
138
void * _Null_unspecified word2;
63
139
} BridgedLocation;
64
140
65
- typedef struct {
66
- void * _Nullable typePtr;
67
- } BridgedType;
68
-
69
141
typedef struct {
70
142
const void * _Nullable data;
71
143
size_t count;
@@ -87,46 +159,10 @@ typedef struct {
87
159
const void * _Nullable succ;
88
160
} OptionalBridgedSuccessor;
89
161
90
- typedef struct {
91
- SwiftObject obj;
92
- } BridgedFunction;
93
-
94
162
typedef struct {
95
163
SwiftObject obj;
96
164
} BridgedGlobalVar;
97
165
98
- typedef struct {
99
- SwiftObject obj;
100
- } BridgedBasicBlock;
101
-
102
- typedef struct {
103
- OptionalSwiftObject obj;
104
- } OptionalBridgedBasicBlock;
105
-
106
- typedef struct {
107
- SwiftObject obj;
108
- } BridgedArgument;
109
-
110
- typedef struct {
111
- OptionalSwiftObject obj;
112
- } OptionalBridgedArgument;
113
-
114
- typedef struct {
115
- SwiftObject obj;
116
- } BridgedNode;
117
-
118
- typedef struct {
119
- SwiftObject obj;
120
- } BridgedValue;
121
-
122
- typedef struct {
123
- SwiftObject obj;
124
- } BridgedInstruction;
125
-
126
- typedef struct {
127
- OptionalSwiftObject obj;
128
- } OptionalBridgedInstruction;
129
-
130
166
typedef struct {
131
167
SwiftObject obj;
132
168
} BridgedMultiValueResult;
@@ -144,6 +180,12 @@ typedef enum {
144
180
145
181
typedef intptr_t SwiftInt;
146
182
183
+ // TODO: we can remove these once we auto generate equality operators for
184
+ // foreign reference types.
185
+ inline bool isPtrEq (ValueBase *a, ValueBase *b) { return a == b; }
186
+ inline bool isPtrEq (SILInstruction *a, SILInstruction *b) { return a == b; }
187
+ inline bool isPtrEq (SILBasicBlock *a, SILBasicBlock *b) { return a == b; }
188
+
147
189
void registerBridgedClass (BridgedStringRef className, SwiftMetatype metatype);
148
190
149
191
void OStream_write (BridgedOStream os, BridgedStringRef str);
@@ -153,90 +195,94 @@ void freeBridgedStringRef(BridgedStringRef str);
153
195
void PassContext_notifyChanges (BridgedPassContext passContext,
154
196
enum ChangeNotificationKind changeKind);
155
197
void PassContext_eraseInstruction (BridgedPassContext passContext,
156
- BridgedInstruction inst);
198
+ SILInstruction * inst);
157
199
BridgedSlab PassContext_getNextSlab (BridgedSlab slab);
158
200
BridgedSlab PassContext_allocSlab (BridgedPassContext passContext,
159
201
BridgedSlab afterSlab);
160
202
BridgedSlab PassContext_freeSlab (BridgedPassContext passContext,
161
203
BridgedSlab slab);
162
204
163
- BridgedStringRef SILFunction_getName (BridgedFunction function);
164
- std::string SILFunction_debugDescription (BridgedFunction function);
165
- OptionalBridgedBasicBlock SILFunction_firstBlock (BridgedFunction function);
166
- OptionalBridgedBasicBlock SILFunction_lastBlock (BridgedFunction function);
167
- SwiftInt SILFunction_numIndirectResultArguments (BridgedFunction function);
168
- SwiftInt SILFunction_getSelfArgumentIndex (BridgedFunction function);
205
+ BridgedStringRef SILFunction_getName (SILFunction * function);
206
+ std::string SILFunction_debugDescription (SILFunction * function);
207
+ SILBasicBlock * _Nullable SILFunction_firstBlock (SILFunction * function);
208
+ OptionalRef<SILBasicBlock> SILFunction_lastBlock (SILFunction * function);
209
+ SwiftInt SILFunction_numIndirectResultArguments (SILFunction * function);
210
+ SwiftInt SILFunction_getSelfArgumentIndex (SILFunction * function);
169
211
170
212
BridgedStringRef SILGlobalVariable_getName (BridgedGlobalVar global);
171
213
std::string SILGlobalVariable_debugDescription (BridgedGlobalVar global);
172
214
173
- OptionalBridgedBasicBlock SILBasicBlock_next (BridgedBasicBlock block);
174
- OptionalBridgedBasicBlock SILBasicBlock_previous (BridgedBasicBlock block);
175
- BridgedFunction SILBasicBlock_getFunction (BridgedBasicBlock block);
176
- std::string SILBasicBlock_debugDescription (BridgedBasicBlock block);
177
- OptionalBridgedInstruction SILBasicBlock_firstInst (BridgedBasicBlock block);
178
- OptionalBridgedInstruction SILBasicBlock_lastInst (BridgedBasicBlock block);
179
- SwiftInt SILBasicBlock_getNumArguments (BridgedBasicBlock block);
180
- BridgedArgument SILBasicBlock_getArgument (BridgedBasicBlock block, SwiftInt index);
181
- OptionalBridgedSuccessor SILBasicBlock_getFirstPred (BridgedBasicBlock block);
215
+ int SILBasicBlock_mytest (SILBasicBlock *b);
216
+
217
+ OptionalRef<SILBasicBlock> SILBasicBlock_next (SILBasicBlock *block);
218
+ OptionalRef<SILBasicBlock> SILBasicBlock_previous (SILBasicBlock *block);
219
+ SILFunction *SILBasicBlock_getFunction (SILBasicBlock *block);
220
+ std::string SILBasicBlock_debugDescription (SILBasicBlock *block);
221
+ SILInstruction *SILBasicBlock_firstInst (SILBasicBlock *block);
222
+ // TODO: we could make this a terminator inst.
223
+ OptionalRef<SILInstruction> SILBasicBlock_lastInst (SILBasicBlock *block);
224
+ SwiftInt SILBasicBlock_getNumArguments (SILBasicBlock *block);
225
+ SILArgument *SILBasicBlock_getArgument (SILBasicBlock *block, SwiftInt index);
226
+ OptionalBridgedSuccessor SILBasicBlock_getFirstPred (SILBasicBlock *block);
182
227
OptionalBridgedSuccessor SILSuccessor_getNext (BridgedSuccessor succ);
183
- BridgedBasicBlock SILSuccessor_getTargetBlock (BridgedSuccessor succ);
184
- BridgedInstruction SILSuccessor_getContainingInst (BridgedSuccessor succ);
228
+ SILBasicBlock * SILSuccessor_getTargetBlock (BridgedSuccessor succ);
229
+ SILInstruction * SILSuccessor_getContainingInst (BridgedSuccessor succ);
185
230
186
- BridgedValue Operand_getValue (BridgedOperand);
231
+ ValueBase * Operand_getValue (BridgedOperand);
187
232
OptionalBridgedOperand Operand_nextUse (BridgedOperand);
188
- BridgedInstruction Operand_getUser (BridgedOperand);
233
+ SILInstruction * Operand_getUser (BridgedOperand);
189
234
SwiftInt Operand_isTypeDependent (BridgedOperand);
190
235
191
- std::string SILNode_debugDescription (BridgedNode node);
192
- OptionalBridgedOperand SILValue_firstUse (BridgedValue value);
193
- BridgedType SILValue_getType (BridgedValue value);
236
+ std::string SILNode_debugDescription (ValueBase *node);
237
+ std::string SILInstruction_debugDescription (SILInstruction *i);
238
+ OptionalBridgedOperand SILValue_firstUse (ValueBase *value);
239
+ SILType SILValue_getType (ValueBase *value);
194
240
195
- SwiftInt SILType_isAddress (BridgedType );
196
- SwiftInt SILType_isTrivial (BridgedType, BridgedFunction );
241
+ SwiftInt SILType_isAddress (SILType );
242
+ SwiftInt SILType_isTrivial (SILType, SILFunction * );
197
243
198
- BridgedBasicBlock SILArgument_getParent (BridgedArgument argument);
244
+ SILBasicBlock * SILArgument_getParent (SILArgument * argument);
199
245
200
- OptionalBridgedInstruction SILInstruction_next (BridgedInstruction inst);
201
- OptionalBridgedInstruction SILInstruction_previous (BridgedInstruction inst);
202
- BridgedBasicBlock SILInstruction_getParent (BridgedInstruction inst);
203
- BridgedArrayRef SILInstruction_getOperands (BridgedInstruction inst);
204
- void SILInstruction_setOperand (BridgedInstruction inst, SwiftInt index,
205
- BridgedValue value);
206
- BridgedLocation SILInstruction_getLocation (BridgedInstruction inst);
207
- BridgedMemoryBehavior SILInstruction_getMemBehavior (BridgedInstruction inst);
246
+ OptionalRef<SILInstruction> SILInstruction_next (SILInstruction * inst);
247
+ OptionalRef<SILInstruction> SILInstruction_previous (SILInstruction * inst);
248
+ SILBasicBlock * SILInstruction_getParent (SILInstruction * inst);
249
+ BridgedArrayRef SILInstruction_getOperands (SILInstruction * inst);
250
+ void SILInstruction_setOperand (SILInstruction * inst, SwiftInt index,
251
+ ValueBase * value);
252
+ BridgedLocation SILInstruction_getLocation (SILInstruction * inst);
253
+ BridgedMemoryBehavior SILInstruction_getMemBehavior (SILInstruction * inst);
208
254
209
- BridgedInstruction MultiValueInstResult_getParent (BridgedMultiValueResult result);
210
- SwiftInt MultipleValueInstruction_getNumResults (BridgedInstruction inst);
255
+ SILInstruction * MultiValueInstResult_getParent (BridgedMultiValueResult result);
256
+ SwiftInt MultipleValueInstruction_getNumResults (MultipleValueInstruction * inst);
211
257
BridgedMultiValueResult
212
- MultipleValueInstruction_getResult (BridgedInstruction inst, SwiftInt index);
213
-
214
- BridgedArrayRef TermInst_getSuccessors (BridgedInstruction term);
215
-
216
- BridgedStringRef CondFailInst_getMessage (BridgedInstruction cfi);
217
- BridgedGlobalVar GlobalAccessInst_getGlobal (BridgedInstruction globalInst);
218
- SwiftInt TupleExtractInst_fieldIndex (BridgedInstruction tei);
219
- SwiftInt TupleElementAddrInst_fieldIndex (BridgedInstruction teai);
220
- SwiftInt StructExtractInst_fieldIndex (BridgedInstruction sei);
221
- SwiftInt StructElementAddrInst_fieldIndex (BridgedInstruction seai);
222
- SwiftInt EnumInst_caseIndex (BridgedInstruction ei);
223
- SwiftInt UncheckedEnumDataInst_caseIndex (BridgedInstruction uedi);
224
- SwiftInt RefElementAddrInst_fieldIndex (BridgedInstruction reai);
225
- SwiftInt PartialApplyInst_numArguments (BridgedInstruction ai);
226
- SwiftInt ApplyInst_numArguments (BridgedInstruction ai);
227
- SwiftInt BeginApplyInst_numArguments (BridgedInstruction ai);
228
- SwiftInt TryApplyInst_numArguments (BridgedInstruction ai);
229
- BridgedBasicBlock BranchInst_getTargetBlock (BridgedInstruction bi);
230
- SwiftInt SwitchEnumInst_getNumCases (BridgedInstruction se);
231
- SwiftInt SwitchEnumInst_getCaseIndex (BridgedInstruction se, SwiftInt idx);
232
- SwiftInt StoreInst_getStoreOwnership (BridgedInstruction store);
233
-
234
- BridgedInstruction SILBuilder_createBuiltinBinaryFunction (
235
- BridgedInstruction insertionPoint,
258
+ MultipleValueInstruction_getResult (MultipleValueInstruction * inst, SwiftInt index);
259
+
260
+ BridgedArrayRef TermInst_getSuccessors (TermInst * term);
261
+
262
+ BridgedStringRef CondFailInst_getMessage (CondFailInst * cfi);
263
+ BridgedGlobalVar GlobalAccessInst_getGlobal (GlobalAccessInst * globalInst);
264
+ SwiftInt TupleExtractInst_fieldIndex (TupleExtractInst * tei);
265
+ SwiftInt TupleElementAddrInst_fieldIndex (TupleElementAddrInst * teai);
266
+ SwiftInt StructExtractInst_fieldIndex (StructExtractInst * sei);
267
+ SwiftInt StructElementAddrInst_fieldIndex (StructElementAddrInst * seai);
268
+ SwiftInt EnumInst_caseIndex (EnumInst * ei);
269
+ SwiftInt UncheckedEnumDataInst_caseIndex (UncheckedEnumDataInst * uedi);
270
+ SwiftInt RefElementAddrInst_fieldIndex (RefElementAddrInst * reai);
271
+ SwiftInt PartialApplyInst_numArguments (PartialApplyInst * ai);
272
+ SwiftInt ApplyInst_numArguments (ApplyInst * ai);
273
+ SwiftInt BeginApplyInst_numArguments (BeginApplyInst * ai);
274
+ SwiftInt TryApplyInst_numArguments (TryApplyInst * ai);
275
+ SILBasicBlock * BranchInst_getTargetBlock (BranchInst * bi);
276
+ SwiftInt SwitchEnumInst_getNumCases (SwitchEnumInst * se);
277
+ SwiftInt SwitchEnumInst_getCaseIndex (SwitchEnumInst * se, SwiftInt idx);
278
+ SwiftInt StoreInst_getStoreOwnership (StoreInst * store);
279
+
280
+ SILInstruction * SILBuilder_createBuiltinBinaryFunction (
281
+ SILInstruction * insertionPoint,
236
282
BridgedLocation loc, BridgedStringRef name,
237
- BridgedType operandType, BridgedType resultType, BridgedValueArray arguments);
238
- BridgedInstruction SILBuilder_createCondFail (BridgedInstruction insertionPoint,
239
- BridgedLocation loc, BridgedValue condition, BridgedStringRef messge);
283
+ SILType operandType, SILType resultType, BridgedValueArray arguments);
284
+ SILInstruction * SILBuilder_createCondFail (SILInstruction * insertionPoint,
285
+ BridgedLocation loc, ValueBase * condition, BridgedStringRef messge);
240
286
241
287
SWIFT_END_NULLABILITY_ANNOTATIONS
242
288
0 commit comments