@@ -195,6 +195,26 @@ SwiftInt SILFunction_getSelfArgumentIndex(BridgedFunction function) {
195195 return fTy ->getNumParameters () + fTy ->getNumIndirectFormalResults () - 1 ;
196196}
197197
198+ SwiftInt SILFunction_getNumSILArguments (BridgedFunction function) {
199+ SILFunction *f = castToFunction (function);
200+ SILFunctionConventions conv (f->getConventionsInContext ());
201+ return conv.getNumSILArguments ();
202+ }
203+
204+ BridgedType SILFunction_getSILArgumentType (BridgedFunction function, SwiftInt idx) {
205+ SILFunction *f = castToFunction (function);
206+ SILFunctionConventions conv (f->getConventionsInContext ());
207+ SILType argTy = conv.getSILArgumentType (idx, f->getTypeExpansionContext ());
208+ return {argTy.getOpaqueValue ()};
209+ }
210+
211+ BridgedType SILFunction_getSILResultType (BridgedFunction function) {
212+ SILFunction *f = castToFunction (function);
213+ SILFunctionConventions conv (f->getConventionsInContext ());
214+ SILType resTy = conv.getSILResultType (f->getTypeExpansionContext ());
215+ return {resTy.getOpaqueValue ()};
216+ }
217+
198218// ===----------------------------------------------------------------------===//
199219// SILBasicBlock
200220// ===----------------------------------------------------------------------===//
@@ -325,6 +345,13 @@ BridgedType SILValue_getType(BridgedValue value) {
325345// SILType
326346// ===----------------------------------------------------------------------===//
327347
348+ BridgedStringRef SILType_debugDescription (BridgedType type) {
349+ std::string str;
350+ llvm::raw_string_ostream os (str);
351+ castToSILType (type).print (os);
352+ return getCopiedBridgedStringRef (str, /* removeTrailingNewline*/ true );
353+ }
354+
328355SwiftInt SILType_isAddress (BridgedType type) {
329356 return castToSILType (type).isAddress ();
330357}
@@ -333,6 +360,85 @@ SwiftInt SILType_isTrivial(BridgedType type, BridgedFunction function) {
333360 return castToSILType (type).isTrivial (*castToFunction (function));
334361}
335362
363+ SwiftInt SILType_isNominal (BridgedType type) {
364+ return castToSILType (type).getNominalOrBoundGenericNominal () ? 1 : 0 ;
365+ }
366+
367+ SwiftInt SILType_isClass (BridgedType type) {
368+ return castToSILType (type).getClassOrBoundGenericClass () ? 1 : 0 ;
369+ }
370+
371+ SwiftInt SILType_isStruct (BridgedType type) {
372+ return castToSILType (type).getStructOrBoundGenericStruct () ? 1 : 0 ;
373+ }
374+
375+ SwiftInt SILType_isTuple (BridgedType type) {
376+ return castToSILType (type).is <TupleType>() ? 1 : 0 ;
377+ }
378+
379+ SwiftInt SILType_isEnum (BridgedType type) {
380+ return castToSILType (type).getEnumOrBoundGenericEnum () ? 1 : 0 ;
381+ }
382+
383+ SwiftInt SILType_isNonTrivialOrContainsRawPointer (BridgedType type,
384+ BridgedFunction function) {
385+ SILFunction *f = castToFunction (function);
386+ return castToSILType (type).isNonTrivialOrContainsRawPointer (*f);
387+ }
388+
389+ SwiftInt SILType_getFieldIdxOfNominalType (BridgedType type,
390+ BridgedStringRef fieldName) {
391+ SILType ty = castToSILType (type);
392+ auto *nominal = ty.getNominalOrBoundGenericNominal ();
393+ if (!nominal)
394+ return -1 ;
395+
396+ SmallVector<NominalTypeDecl *, 5 > decls;
397+ decls.push_back (nominal);
398+ if (auto *cd = dyn_cast<ClassDecl>(nominal)) {
399+ while ((cd = cd->getSuperclassDecl ()) != nullptr ) {
400+ decls.push_back (cd);
401+ }
402+ }
403+ std::reverse (decls.begin (), decls.end ());
404+
405+ SwiftInt idx = 0 ;
406+ StringRef fieldNm ((const char *)fieldName.data , fieldName.length );
407+ for (auto *decl : decls) {
408+ for (VarDecl *field : decl->getStoredProperties ()) {
409+ if (field->getName ().str () == fieldNm)
410+ return idx;
411+ idx++;
412+ }
413+ }
414+ return -1 ;
415+ }
416+
417+ BridgedType SILType_getTypeOfField (BridgedType type, SwiftInt fieldIndex,
418+ BridgedFunction inFunction) {
419+ SILType ty = castToSILType (type);
420+ auto *nominal = ty.getNominalOrBoundGenericNominal ();
421+ assert (nominal);
422+
423+ VarDecl *field = getIndexedField (nominal, (unsigned )fieldIndex);
424+ assert (field);
425+
426+ SILFunction *f = castToFunction (inFunction);
427+ SILType fieldTy = ty.getFieldType (field, f->getModule (),f->getTypeExpansionContext ());
428+ return {fieldTy.getOpaqueValue ()};
429+ }
430+
431+ SwiftInt SILType_getNumTupleElements (BridgedType type) {
432+ TupleType *tupleTy = castToSILType (type).castTo <TupleType>();
433+ return tupleTy->getNumElements ();
434+ }
435+
436+ BridgedType SILType_getTupleElementType (BridgedType type, SwiftInt elementIdx) {
437+ SILType ty = castToSILType (type);
438+ SILType elmtTy = ty.getTupleElementType ((unsigned )elementIdx);
439+ return {elmtTy.getOpaqueValue ()};
440+ }
441+
336442// ===----------------------------------------------------------------------===//
337443// SILGlobalVariable
338444// ===----------------------------------------------------------------------===//
0 commit comments