Skip to content

Commit 6bb5ad6

Browse files
committed
Swift SIL: complete APIs for CheckedCastAddrBranchInst
1 parent 81812ea commit 6bb5ad6

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,5 +1481,35 @@ final public class CheckedCastBranchInst : TermInst, UnaryInstruction {
14811481
public var failureBlock: BasicBlock { bridged.CheckedCastBranch_getFailureBlock().block }
14821482
}
14831483

1484-
final public class CheckedCastAddrBranchInst : TermInst, UnaryInstruction {
1484+
final public class CheckedCastAddrBranchInst : TermInst {
1485+
public var source: Value { operands[0].value }
1486+
public var destination: Value { operands[1].value }
1487+
1488+
public var successBlock: BasicBlock { bridged.CheckedCastAddrBranch_getSuccessBlock().block }
1489+
public var failureBlock: BasicBlock { bridged.CheckedCastAddrBranch_getFailureBlock().block }
1490+
1491+
public enum CastConsumptionKind {
1492+
/// The source value is always taken, regardless of whether the cast
1493+
/// succeeds. That is, if the cast fails, the source value is
1494+
/// destroyed.
1495+
case TakeAlways
1496+
1497+
/// The source value is taken only on a successful cast; otherwise,
1498+
/// it is left in place.
1499+
case TakeOnSuccess
1500+
1501+
/// The source value is always left in place, and the destination
1502+
/// value is copied into on success.
1503+
case CopyOnSuccess
1504+
}
1505+
1506+
public var consumptionKind: CastConsumptionKind {
1507+
switch bridged.CheckedCastAddrBranch_getConsumptionKind() {
1508+
case .TakeAlways: return .TakeAlways
1509+
case .TakeOnSuccess: return .TakeOnSuccess
1510+
case .CopyOnSuccess: return .CopyOnSuccess
1511+
default:
1512+
fatalError("invalid cast consumption kind")
1513+
}
1514+
}
14851515
}

include/swift/SIL/SILBridging.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@ struct BridgedInstruction {
823823
SwiftInt numFunctions;
824824
};
825825

826+
enum class CastConsumptionKind {
827+
TakeAlways,
828+
TakeOnSuccess,
829+
CopyOnSuccess
830+
};
831+
826832
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef CondFailInst_getMessage() const;
827833
BRIDGED_INLINE SwiftInt LoadInst_getLoadOwnership() const ;
828834
BRIDGED_INLINE BuiltinValueKind BuiltinInst_getID() const;
@@ -904,6 +910,9 @@ struct BridgedInstruction {
904910
BRIDGED_INLINE void LoadInst_setOwnership(SwiftInt ownership) const;
905911
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getSuccessBlock() const;
906912
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getFailureBlock() const;
913+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getSuccessBlock() const;
914+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getFailureBlock() const;
915+
BRIDGED_INLINE CastConsumptionKind CheckedCastAddrBranch_getConsumptionKind() const;
907916
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap ApplySite_getSubstitutionMap() const;
908917
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType ApplySite_getSubstitutedCalleeType() const;
909918
BRIDGED_INLINE SwiftInt ApplySite_getNumArguments() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,27 @@ BridgedBasicBlock BridgedInstruction::CheckedCastBranch_getFailureBlock() const
12441244
return {getAs<swift::CheckedCastBranchInst>()->getFailureBB()};
12451245
}
12461246

1247+
BridgedBasicBlock BridgedInstruction::CheckedCastAddrBranch_getSuccessBlock() const {
1248+
return {getAs<swift::CheckedCastAddrBranchInst>()->getSuccessBB()};
1249+
}
1250+
1251+
BridgedBasicBlock BridgedInstruction::CheckedCastAddrBranch_getFailureBlock() const {
1252+
return {getAs<swift::CheckedCastAddrBranchInst>()->getFailureBB()};
1253+
}
1254+
1255+
BridgedInstruction::CastConsumptionKind BridgedInstruction::CheckedCastAddrBranch_getConsumptionKind() const {
1256+
static_assert((int)BridgedInstruction::CastConsumptionKind::TakeAlways ==
1257+
(int)swift::CastConsumptionKind::TakeAlways);
1258+
static_assert((int)BridgedInstruction::CastConsumptionKind::TakeOnSuccess ==
1259+
(int)swift::CastConsumptionKind::TakeOnSuccess);
1260+
static_assert((int)BridgedInstruction::CastConsumptionKind::CopyOnSuccess ==
1261+
(int)swift::CastConsumptionKind::CopyOnSuccess);
1262+
1263+
return static_cast<BridgedInstruction::CastConsumptionKind>(
1264+
getAs<swift::CheckedCastAddrBranchInst>()->getConsumptionKind());
1265+
}
1266+
1267+
12471268
BridgedSubstitutionMap BridgedInstruction::ApplySite_getSubstitutionMap() const {
12481269
auto as = swift::ApplySite(unbridged());
12491270
return as.getSubstitutionMap();

0 commit comments

Comments
 (0)