@@ -86,6 +86,9 @@ void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype) {
86
86
return SILGlobalVariable::registerBridgedMetatype (metatype);
87
87
if (clName == " BlockArgument" ) {
88
88
nodeMetatypes[(unsigned )SILNodeKind::SILPhiArgument] = metatype;
89
+ return ;
90
+ }
91
+ if (clName == " FunctionArgument" ) {
89
92
nodeMetatypes[(unsigned )SILNodeKind::SILFunctionArgument] = metatype;
90
93
return ;
91
94
}
@@ -100,21 +103,21 @@ void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype) {
100
103
return setUnimplementedRange (metatype, VALUE_RANGE (RefCountingInst));
101
104
if (clName == " UnimplementedSingleValueInst" )
102
105
return setUnimplementedRange (metatype, VALUE_RANGE (SingleValueInstruction));
103
- if (clName == " UnimplementedMultiValueInst" )
104
- return setUnimplementedRange (metatype, VALUE_RANGE (MultipleValueInstruction));
105
106
if (clName == " UnimplementedInstruction" )
106
107
return setUnimplementedRange (metatype, VALUE_RANGE (SILInstruction));
107
108
#undef VALUE_RANGE
108
109
109
110
if (valueNamesToKind.empty ()) {
110
- #define BRIDGED_VALUE (ID, PARENT ) \
111
+ #define VALUE (ID, PARENT ) \
111
112
valueNamesToKind[#ID] = SILNodeKind::ID;
112
113
#define BRIDGED_NON_VALUE_INST (ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE ) \
113
- BRIDGED_VALUE (ID, NAME)
114
- #define BRIDGED_ARGUMENT (ID, PARENT ) \
115
- BRIDGED_VALUE (ID, NAME)
114
+ VALUE (ID, NAME)
115
+ #define ARGUMENT (ID, PARENT ) \
116
+ VALUE (ID, NAME)
116
117
#define BRIDGED_SINGLE_VALUE_INST (ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE ) \
117
- BRIDGED_VALUE (ID, NAME)
118
+ VALUE (ID, NAME)
119
+ #define MULTIPLE_VALUE_INST (ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE ) \
120
+ VALUE (ID, NAME)
118
121
#include " swift/SIL/SILNodes.def"
119
122
}
120
123
@@ -123,14 +126,13 @@ void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype) {
123
126
if (iter == valueNamesToKind.end ()) {
124
127
// Try again with a "SIL" prefix. For example Argument -> SILArgument.
125
128
prefixedName = std::string (" SIL" ) + std::string (clName);
129
+ iter = valueNamesToKind.find (prefixedName);
130
+ if (iter == valueNamesToKind.end ()) {
131
+ llvm::errs () << " Unknown bridged node class " << clName << ' \n ' ;
132
+ abort ();
133
+ }
126
134
clName = prefixedName;
127
135
}
128
-
129
- iter = valueNamesToKind.find (clName);
130
- if (iter == valueNamesToKind.end ()) {
131
- llvm::errs () << " Unknonwn bridged node class " << clName << ' \n ' ;
132
- abort ();
133
- }
134
136
SILNodeKind kind = iter->second ;
135
137
SwiftMetatype existingTy = nodeMetatypes[(unsigned )kind];
136
138
if (existingTy && !unimplementedTypes.count (existingTy)) {
@@ -182,6 +184,9 @@ OptionalBridgedBasicBlock SILFunction_lastBlock(BridgedFunction function) {
182
184
// SILBasicBlock
183
185
// ===----------------------------------------------------------------------===//
184
186
187
+ static_assert (BridgedSuccessorSize == sizeof (SILSuccessor),
188
+ "wrong bridged SILSuccessor size");
189
+
185
190
OptionalBridgedBasicBlock SILBasicBlock_next (BridgedBasicBlock block) {
186
191
SILBasicBlock *b = castToBasicBlock (block);
187
192
auto iter = std::next (b->getIterator ());
@@ -198,6 +203,10 @@ OptionalBridgedBasicBlock SILBasicBlock_previous(BridgedBasicBlock block) {
198
203
return {&*iter};
199
204
}
200
205
206
+ BridgedFunction SILBasicBlock_getFunction (BridgedBasicBlock block) {
207
+ return {castToBasicBlock (block)->getParent ()};
208
+ }
209
+
201
210
BridgedStringRef SILBasicBlock_debugDescription (BridgedBasicBlock block) {
202
211
std::string str;
203
212
llvm::raw_string_ostream os (str);
@@ -227,6 +236,25 @@ BridgedArgument SILBasicBlock_getArgument(BridgedBasicBlock block, SwiftInt inde
227
236
return {castToBasicBlock (block)->getArgument (index)};
228
237
}
229
238
239
+ OptionalBridgedSuccessor SILBasicBlock_getFirstPred (BridgedBasicBlock block) {
240
+ return {castToBasicBlock (block)->pred_begin ().getSuccessorRef ()};
241
+ }
242
+
243
+ static SILSuccessor *castToSuccessor (BridgedSuccessor succ) {
244
+ return const_cast <SILSuccessor *>(static_cast <const SILSuccessor *>(succ.succ ));
245
+ }
246
+
247
+ OptionalBridgedSuccessor SILSuccessor_getNext (BridgedSuccessor succ) {
248
+ return {castToSuccessor (succ)->getNext ()};
249
+ }
250
+
251
+ BridgedBasicBlock SILSuccessor_getTargetBlock (BridgedSuccessor succ) {
252
+ return {castToSuccessor (succ)->getBB ()};
253
+ }
254
+
255
+ BridgedInstruction SILSuccessor_getContainingInst (BridgedSuccessor succ) {
256
+ return {castToSuccessor (succ)->getContainingInst ()};
257
+ }
230
258
231
259
// ===----------------------------------------------------------------------===//
232
260
// SILArgument
@@ -324,7 +352,7 @@ BridgedBasicBlock SILInstruction_getParent(BridgedInstruction inst) {
324
352
return {i->getParent ()};
325
353
}
326
354
327
- BridgedOperandArray SILInstruction_getOperands (BridgedInstruction inst) {
355
+ BridgedArrayRef SILInstruction_getOperands (BridgedInstruction inst) {
328
356
auto operands = castToInst (inst)->getAllOperands ();
329
357
return {(const unsigned char *)operands.data (), operands.size ()};
330
358
}
@@ -350,6 +378,11 @@ MultipleValueInstruction_getResult(BridgedInstruction inst, SwiftInt index) {
350
378
return {castToInst<MultipleValueInstruction>(inst)->getResult (index)};
351
379
}
352
380
381
+ BridgedArrayRef TermInst_getSuccessors (BridgedInstruction term) {
382
+ auto successors = castToInst<TermInst>(term)->getSuccessors ();
383
+ return {(const unsigned char *)successors.data (), successors.size ()};
384
+ }
385
+
353
386
// ===----------------------------------------------------------------------===//
354
387
// Instruction classes
355
388
// ===----------------------------------------------------------------------===//
@@ -362,6 +395,62 @@ BridgedGlobalVar GlobalAccessInst_getGlobal(BridgedInstruction globalInst) {
362
395
return {castToInst<GlobalAccessInst>(globalInst)->getReferencedGlobal ()};
363
396
}
364
397
398
+ SwiftInt TupleExtractInst_fieldIndex (BridgedInstruction tei) {
399
+ return castToInst<TupleExtractInst>(tei)->getFieldIndex ();
400
+ }
401
+
402
+ SwiftInt TupleElementAddrInst_fieldIndex (BridgedInstruction teai) {
403
+ return castToInst<TupleElementAddrInst>(teai)->getFieldIndex ();
404
+ }
405
+
406
+ SwiftInt StructExtractInst_fieldIndex (BridgedInstruction sei) {
407
+ return castToInst<StructExtractInst>(sei)->getFieldIndex ();
408
+ }
409
+
410
+ SwiftInt StructElementAddrInst_fieldIndex (BridgedInstruction seai) {
411
+ return castToInst<StructElementAddrInst>(seai)->getFieldIndex ();
412
+ }
413
+
414
+ SwiftInt EnumInst_caseIndex (BridgedInstruction ei) {
415
+ return getCaseIndex (castToInst<EnumInst>(ei)->getElement ());
416
+ }
417
+
418
+ SwiftInt UncheckedEnumDataInst_caseIndex (BridgedInstruction uedi) {
419
+ return getCaseIndex (castToInst<UncheckedEnumDataInst>(uedi)->getElement ());
420
+ }
421
+
422
+ SwiftInt RefElementAddrInst_fieldIndex (BridgedInstruction reai) {
423
+ return castToInst<RefElementAddrInst>(reai)->getFieldIndex ();
424
+ }
425
+
426
+ SwiftInt PartialApplyInst_numArguments (BridgedInstruction pai) {
427
+ return castToInst<PartialApplyInst>(pai)->getNumArguments ();
428
+ }
429
+
430
+ SwiftInt ApplyInst_numArguments (BridgedInstruction ai) {
431
+ return castToInst<ApplyInst>(ai)->getNumArguments ();
432
+ }
433
+
434
+ SwiftInt BeginApplyInst_numArguments (BridgedInstruction tai) {
435
+ return castToInst<BeginApplyInst>(tai)->getNumArguments ();
436
+ }
437
+
438
+ SwiftInt TryApplyInst_numArguments (BridgedInstruction tai) {
439
+ return castToInst<TryApplyInst>(tai)->getNumArguments ();
440
+ }
441
+
442
+ BridgedBasicBlock BranchInst_getTargetBlock (BridgedInstruction bi) {
443
+ return {castToInst<BranchInst>(bi)->getDestBB ()};
444
+ }
445
+
446
+ SwiftInt SwitchEnumInst_getNumCases (BridgedInstruction se) {
447
+ return castToInst<SwitchEnumInst>(se)->getNumCases ();
448
+ }
449
+
450
+ SwiftInt SwitchEnumInst_getCaseIndex (BridgedInstruction se, SwiftInt idx) {
451
+ return getCaseIndex (castToInst<SwitchEnumInst>(se)->getCase (idx).first );
452
+ }
453
+
365
454
// ===----------------------------------------------------------------------===//
366
455
// SILBuilder
367
456
// ===----------------------------------------------------------------------===//
0 commit comments