Skip to content

Commit 0bd6034

Browse files
committed
SwiftCompilerSources: add some Builder APIs
* `createAddressToPointer` * `createLoadBorrow`
1 parent 36dd2c9 commit 0bd6034

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public struct Builder {
7373
}
7474
}
7575

76+
@discardableResult
7677
public func createCondFail(condition: Value, message: String) -> CondFailInst {
7778
return message._withBridgedStringRef { messageStr in
7879
let cf = bridged.createCondFail(condition.bridged, messageStr)
@@ -103,6 +104,12 @@ public struct Builder {
103104
return notifyNew(dr.getAs(DeallocStackRefInst.self))
104105
}
105106

107+
public func createAddressToPointer(address: Value, pointerType: Type,
108+
needStackProtection: Bool) -> AddressToPointerInst {
109+
let dr = bridged.createAddressToPointer(address.bridged, pointerType.bridged, needStackProtection)
110+
return notifyNew(dr.getAs(AddressToPointerInst.self))
111+
}
112+
106113
public func createUncheckedRefCast(from value: Value, to type: Type) -> UncheckedRefCastInst {
107114
let cast = bridged.createUncheckedRefCast(value.bridged, type.bridged)
108115
return notifyNew(cast.getAs(UncheckedRefCastInst.self))
@@ -118,6 +125,11 @@ public struct Builder {
118125
return notifyNew(load.getAs(LoadInst.self))
119126
}
120127

128+
public func createLoadBorrow(fromAddress: Value) -> LoadBorrowInst {
129+
let load = bridged.createLoadBorrow(fromAddress.bridged)
130+
return notifyNew(load.getAs(LoadBorrowInst.self))
131+
}
132+
121133
public func createBeginDeallocRef(reference: Value, allocation: AllocRefInstBase) -> BeginDeallocRefInst {
122134
let beginDealloc = bridged.createBeginDeallocRef(reference.bridged, allocation.bridged)
123135
return notifyNew(beginDealloc.getAs(BeginDeallocRefInst.self))

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,14 @@ struct BridgedBuilder{
902902
bool hasDynamicLifetime, bool isLexical, bool wasMoved) const;
903903
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDeallocStack(BridgedValue operand) const;
904904
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDeallocStackRef(BridgedValue operand) const;
905+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createAddressToPointer(BridgedValue address,
906+
BridgedType pointerTy,
907+
bool needsStackProtection) const;
905908
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedRefCast(BridgedValue op,
906909
BridgedType type) const;
907910
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUpcast(BridgedValue op, BridgedType type) const;
908911
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoad(BridgedValue op, SwiftInt ownership) const;
912+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createLoadBorrow(BridgedValue op) const;
909913
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createBeginDeallocRef(BridgedValue reference,
910914
BridgedValue allocation) const;
911915
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndInitLetRef(BridgedValue op) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,12 @@ BridgedInstruction BridgedBuilder::createDeallocStackRef(BridgedValue operand) c
12711271
unbridged().createDeallocStackRef(regularLoc(), operand.getSILValue())};
12721272
}
12731273

1274+
BridgedInstruction BridgedBuilder::createAddressToPointer(BridgedValue address, BridgedType pointerTy,
1275+
bool needsStackProtection) const {
1276+
return {unbridged().createAddressToPointer(regularLoc(), address.getSILValue(), pointerTy.unbridged(),
1277+
needsStackProtection)};
1278+
}
1279+
12741280
BridgedInstruction BridgedBuilder::createUncheckedRefCast(BridgedValue op, BridgedType type) const {
12751281
return {unbridged().createUncheckedRefCast(regularLoc(), op.getSILValue(),
12761282
type.unbridged())};
@@ -1286,6 +1292,10 @@ BridgedInstruction BridgedBuilder::createLoad(BridgedValue op, SwiftInt ownershi
12861292
(swift::LoadOwnershipQualifier)ownership)};
12871293
}
12881294

1295+
BridgedInstruction BridgedBuilder::createLoadBorrow(BridgedValue op) const {
1296+
return {unbridged().createLoadBorrow(regularLoc(), op.getSILValue())};
1297+
}
1298+
12891299
BridgedInstruction BridgedBuilder::createBeginDeallocRef(BridgedValue reference, BridgedValue allocation) const {
12901300
return {unbridged().createBeginDeallocRef(
12911301
regularLoc(), reference.getSILValue(), allocation.getSILValue())};

0 commit comments

Comments
 (0)