Skip to content

Commit 04c9016

Browse files
committed
Swift Bridging: use C++ instead of C bridging for BridgedBuilder
1 parent b451010 commit 04c9016

File tree

5 files changed

+217
-286
lines changed

5 files changed

+217
-286
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,80 +64,78 @@ public struct Builder {
6464
operandType: Type, resultType: Type, arguments: [Value]) -> BuiltinInst {
6565
return arguments.withBridgedValues { valuesRef in
6666
return name._withStringRef { nameStr in
67-
let bi = SILBuilder_createBuiltinBinaryFunction(
68-
bridged, nameStr, operandType.bridged, resultType.bridged, valuesRef)
67+
let bi = bridged.createBuiltinBinaryFunction(
68+
nameStr, operandType.bridged, resultType.bridged, valuesRef)
6969
return notifyNew(bi.getAs(BuiltinInst.self))
7070
}
7171
}
7272
}
7373

7474
public func createCondFail(condition: Value, message: String) -> CondFailInst {
7575
return message._withStringRef { messageStr in
76-
let cf = SILBuilder_createCondFail(bridged, condition.bridged, messageStr)
76+
let cf = bridged.createCondFail(condition.bridged, messageStr)
7777
return notifyNew(cf.getAs(CondFailInst.self))
7878
}
7979
}
8080

8181
public func createIntegerLiteral(_ value: Int, type: Type) -> IntegerLiteralInst {
82-
let literal = SILBuilder_createIntegerLiteral(bridged, type.bridged, value)
82+
let literal = bridged.createIntegerLiteral(type.bridged, value)
8383
return notifyNew(literal.getAs(IntegerLiteralInst.self))
8484
}
8585

8686
public func createAllocStack(_ type: Type, hasDynamicLifetime: Bool = false,
87-
isLexical: Bool = false,
88-
usesMoveableValueDebugInfo: Bool = false) -> AllocStackInst {
89-
let dr = SILBuilder_createAllocStack(bridged, type.bridged, hasDynamicLifetime ? 1 : 0,
90-
isLexical ? 1 : 0, usesMoveableValueDebugInfo ? 1 : 0)
87+
isLexical: Bool = false, usesMoveableValueDebugInfo: Bool = false) -> AllocStackInst {
88+
let dr = bridged.createAllocStack(type.bridged, hasDynamicLifetime, isLexical, usesMoveableValueDebugInfo)
9189
return notifyNew(dr.getAs(AllocStackInst.self))
9290
}
9391

9492
@discardableResult
9593
public func createDeallocStack(_ operand: Value) -> DeallocStackInst {
96-
let dr = SILBuilder_createDeallocStack(bridged, operand.bridged)
94+
let dr = bridged.createDeallocStack(operand.bridged)
9795
return notifyNew(dr.getAs(DeallocStackInst.self))
9896
}
9997

10098
@discardableResult
10199
public func createDeallocStackRef(_ operand: Value) -> DeallocStackRefInst {
102-
let dr = SILBuilder_createDeallocStackRef(bridged, operand.bridged)
100+
let dr = bridged.createDeallocStackRef(operand.bridged)
103101
return notifyNew(dr.getAs(DeallocStackRefInst.self))
104102
}
105103

106104
public func createUncheckedRefCast(object: Value, type: Type) -> UncheckedRefCastInst {
107-
let object = SILBuilder_createUncheckedRefCast(bridged, object.bridged, type.bridged)
105+
let object = bridged.createUncheckedRefCast(object.bridged, type.bridged)
108106
return notifyNew(object.getAs(UncheckedRefCastInst.self))
109107
}
110108

111109
@discardableResult
112110
public func createSetDeallocating(operand: Value, isAtomic: Bool) -> SetDeallocatingInst {
113-
let setDeallocating = SILBuilder_createSetDeallocating(bridged, operand.bridged, isAtomic)
111+
let setDeallocating = bridged.createSetDeallocating(operand.bridged, isAtomic)
114112
return notifyNew(setDeallocating.getAs(SetDeallocatingInst.self))
115113
}
116114

117115
public func createFunctionRef(_ function: Function) -> FunctionRefInst {
118-
let functionRef = SILBuilder_createFunctionRef(bridged, function.bridged)
116+
let functionRef = bridged.createFunctionRef(function.bridged)
119117
return notifyNew(functionRef.getAs(FunctionRefInst.self))
120118
}
121119

122120
public func createCopyValue(operand: Value) -> CopyValueInst {
123-
return notifyNew(SILBuilder_createCopyValue(bridged, operand.bridged).getAs(CopyValueInst.self))
121+
return notifyNew(bridged.createCopyValue(operand.bridged).getAs(CopyValueInst.self))
124122
}
125123

126124
@discardableResult
127125
public func createCopyAddr(from fromAddr: Value, to toAddr: Value,
128126
takeSource: Bool = false, initializeDest: Bool = false) -> CopyAddrInst {
129-
return notifyNew(SILBuilder_createCopyAddr(bridged, fromAddr.bridged, toAddr.bridged,
130-
takeSource ? 1 : 0, initializeDest ? 1 : 0).getAs(CopyAddrInst.self))
127+
return notifyNew(bridged.createCopyAddr(fromAddr.bridged, toAddr.bridged,
128+
takeSource, initializeDest).getAs(CopyAddrInst.self))
131129
}
132130

133131
@discardableResult
134132
public func createDestroyValue(operand: Value) -> DestroyValueInst {
135-
return notifyNew(SILBuilder_createDestroyValue(bridged, operand.bridged).getAs(DestroyValueInst.self))
133+
return notifyNew(bridged.createDestroyValue(operand.bridged).getAs(DestroyValueInst.self))
136134
}
137135

138136
@discardableResult
139137
public func createDebugStep() -> DebugStepInst {
140-
return notifyNew(SILBuilder_createDebugStep(bridged).getAs(DebugStepInst.self))
138+
return notifyNew(bridged.createDebugStep().getAs(DebugStepInst.self))
141139
}
142140

143141
@discardableResult
@@ -150,40 +148,40 @@ public struct Builder {
150148
specializationInfo: ApplyInst.SpecializationInfo = nil
151149
) -> ApplyInst {
152150
let apply = arguments.withBridgedValues { valuesRef in
153-
SILBuilder_createApply(bridged, function.bridged, substitutionMap.bridged, valuesRef,
154-
isNonThrowing, isNonAsync, specializationInfo)
151+
bridged.createApply(function.bridged, substitutionMap.bridged, valuesRef,
152+
isNonThrowing, isNonAsync, specializationInfo)
155153
}
156154
return notifyNew(apply.getAs(ApplyInst.self))
157155
}
158156

159157
public func createUncheckedEnumData(enum enumVal: Value,
160158
caseIndex: Int,
161159
resultType: Type) -> UncheckedEnumDataInst {
162-
let ued = SILBuilder_createUncheckedEnumData(bridged, enumVal.bridged, caseIndex, resultType.bridged)
160+
let ued = bridged.createUncheckedEnumData(enumVal.bridged, caseIndex, resultType.bridged)
163161
return notifyNew(ued.getAs(UncheckedEnumDataInst.self))
164162
}
165163
@discardableResult
166164
public func createSwitchEnum(enum enumVal: Value,
167165
cases: [(Int, BasicBlock)],
168166
defaultBlock: BasicBlock? = nil) -> SwitchEnumInst {
169167
let se = cases.withUnsafeBufferPointer { caseBuffer in
170-
SILBuilder_createSwitchEnumInst(
171-
bridged, enumVal.bridged, defaultBlock.bridged, caseBuffer.baseAddress, caseBuffer.count)
168+
bridged.createSwitchEnumInst(enumVal.bridged, defaultBlock.bridged,
169+
caseBuffer.baseAddress, caseBuffer.count)
172170
}
173171
return notifyNew(se.getAs(SwitchEnumInst.self))
174172
}
175173

176174
@discardableResult
177175
public func createBranch(to destBlock: BasicBlock, arguments: [Value] = []) -> BranchInst {
178176
return arguments.withBridgedValues { valuesRef in
179-
let bi = SILBuilder_createBranch(bridged, destBlock.bridged, valuesRef)
177+
let bi = bridged.createBranch(destBlock.bridged, valuesRef)
180178
return notifyNew(bi.getAs(BranchInst.self))
181179
}
182180
}
183181

184182
@discardableResult
185183
public func createUnreachable() -> UnreachableInst {
186-
let ui = SILBuilder_createUnreachable(bridged)
184+
let ui = bridged.createUnreachable()
187185
return notifyNew(ui.getAs(UnreachableInst.self))
188186
}
189187
}

0 commit comments

Comments
 (0)