@@ -146,6 +146,28 @@ struct BridgedOperandArray {
146146 SwiftInt count;
147147};
148148
149+ // Unfortunately we need to take a detour over this enum.
150+ // Currently it's not possible to switch over `SILArgumentConvention::ConventionType`,
151+ // because it's not a class enum.
152+ enum class BridgedArgumentConvention {
153+ Indirect_In = swift::SILArgumentConvention::Indirect_In,
154+ Indirect_In_Guaranteed = swift::SILArgumentConvention::Indirect_In_Guaranteed,
155+ Indirect_Inout = swift::SILArgumentConvention::Indirect_Inout,
156+ Indirect_InoutAliasable = swift::SILArgumentConvention::Indirect_InoutAliasable,
157+ Indirect_Out = swift::SILArgumentConvention::Indirect_Out,
158+ Direct_Owned = swift::SILArgumentConvention::Direct_Owned,
159+ Direct_Unowned = swift::SILArgumentConvention::Direct_Unowned,
160+ Direct_Guaranteed = swift::SILArgumentConvention::Direct_Guaranteed,
161+ Pack_Owned = swift::SILArgumentConvention::Pack_Owned,
162+ Pack_Inout = swift::SILArgumentConvention::Pack_Inout,
163+ Pack_Guaranteed = swift::SILArgumentConvention::Pack_Guaranteed,
164+ Pack_Out = swift::SILArgumentConvention::Pack_Out
165+ };
166+
167+ inline BridgedArgumentConvention castToArgumentConvention (swift::SILArgumentConvention convention) {
168+ return static_cast <BridgedArgumentConvention>(convention.Value );
169+ }
170+
149171struct BridgedFunction {
150172 SwiftObject obj;
151173
@@ -154,20 +176,6 @@ struct BridgedFunction {
154176 return static_cast <swift::SILFunction *>(obj);
155177 }
156178
157- // Unfortunately we need to take a detour over this enum.
158- // Currently it's not possible to switch over `SILArgumentConvention::ConventionType`,
159- // because it's not a class enum.
160- enum class ArgumentConvention {
161- Indirect_In,
162- Indirect_In_Guaranteed,
163- Indirect_Inout,
164- Indirect_InoutAliasable,
165- Indirect_Out,
166- Direct_Owned,
167- Direct_Unowned,
168- Direct_Guaranteed
169- };
170-
171179 SWIFT_IMPORT_UNSAFE
172180 llvm::StringRef getName () const { return getFunction ()->getName (); }
173181
@@ -206,11 +214,9 @@ struct BridgedFunction {
206214 return conv.getSILArgumentType (idx, getFunction ()->getTypeExpansionContext ());
207215 }
208216
209- ArgumentConvention getBridged (swift::SILArgumentConvention conv) const ;
210-
211- ArgumentConvention getSILArgumentConvention (SwiftInt idx) const {
217+ BridgedArgumentConvention getSILArgumentConvention (SwiftInt idx) const {
212218 swift::SILFunctionConventions conv (getFunction ()->getConventionsInContext ());
213- return getBridged (swift::SILArgumentConvention (conv.getParamInfoForSILArg (idx).getConvention ()));
219+ return castToArgumentConvention (swift::SILArgumentConvention (conv.getParamInfoForSILArg (idx).getConvention ()));
214220 }
215221
216222 swift::SILType getSILResultType () const {
@@ -307,8 +313,6 @@ struct BridgedGlobalVar {
307313 bool isLet () const { return getGlobal ()->isLet (); }
308314};
309315
310- BridgedFunction::ArgumentConvention castToArgumentConvention (swift::SILArgumentConvention convention);
311-
312316struct BridgedMultiValueResult {
313317 SwiftObject obj;
314318};
@@ -621,7 +625,7 @@ struct BridgedInstruction {
621625 return as.getSubstitutionMap ();
622626 }
623627
624- BridgedFunction::ArgumentConvention ApplySite_getArgumentConvention (SwiftInt calleeArgIdx) const {
628+ BridgedArgumentConvention ApplySite_getArgumentConvention (SwiftInt calleeArgIdx) const {
625629 auto as = swift::ApplySite (getInst ());
626630 auto conv = as.getSubstCalleeConv ().getSILArgumentConvention (calleeArgIdx);
627631 return castToArgumentConvention (conv.Value );
@@ -637,13 +641,25 @@ struct BridgedInstruction {
637641 }
638642};
639643
640- typedef struct {
644+ struct BridgedArgument {
641645 SwiftObject obj;
642- } BridgedArgument;
643646
644- typedef struct {
647+ swift::SILArgument * _Nonnull getArgument () const {
648+ return static_cast <swift::SILArgument *>(obj);
649+ }
650+
651+ SWIFT_IMPORT_UNSAFE
652+ inline BridgedBasicBlock getParent () const ;
653+
654+ BridgedArgumentConvention getConvention () const {
655+ auto *fArg = llvm::cast<swift::SILFunctionArgument>(getArgument ());
656+ return castToArgumentConvention (fArg ->getArgumentConvention ());
657+ }
658+ };
659+
660+ struct OptionalBridgedArgument {
645661 OptionalSwiftObject obj;
646- } OptionalBridgedArgument ;
662+ };
647663
648664struct OptionalBridgedBasicBlock {
649665 OptionalSwiftObject obj;
@@ -876,9 +892,6 @@ SILLocation_getAutogeneratedLocation(swift::SILDebugLocation loc);
876892bool SILLocation_equal (swift::SILDebugLocation lhs, swift::SILDebugLocation rhs);
877893bool SILLocation_hasSameSourceLocation (swift::SILDebugLocation lhs, swift::SILDebugLocation rhs);
878894
879- BridgedBasicBlock SILArgument_getParent (BridgedArgument argument);
880- BridgedFunction::ArgumentConvention SILArgument_getConvention (BridgedArgument argument);
881-
882895BridgedInstruction MultiValueInstResult_getParent (BridgedMultiValueResult result);
883896SwiftInt MultiValueInstResult_getIndex (BridgedMultiValueResult result);
884897
@@ -973,6 +986,11 @@ OptionalBridgedSuccessor BridgedBasicBlock::getFirstPred() const {
973986 return {getBlock ()->pred_begin ().getSuccessorRef ()};
974987}
975988
989+ BridgedBasicBlock BridgedArgument::getParent () const {
990+ return {getArgument ()->getParent ()};
991+ }
992+
993+
976994SWIFT_END_NULLABILITY_ANNOTATIONS
977995
978996#endif
0 commit comments