@@ -19,6 +19,7 @@ public struct Builder {
19
19
public enum InsertionPoint {
20
20
case before( Instruction )
21
21
case atEndOf( BasicBlock )
22
+ case staticInitializer( GlobalVariable )
22
23
}
23
24
24
25
let insertAt : InsertionPoint
@@ -29,12 +30,13 @@ public struct Builder {
29
30
public var bridged : BridgedBuilder {
30
31
switch insertAt {
31
32
case . before( let inst) :
32
- return BridgedBuilder ( insertBefore: inst. bridged. optional,
33
- insertAtEnd: OptionalBridgedBasicBlock . none,
33
+ return BridgedBuilder ( insertAt: . beforeInst, insertionObj: inst. bridged. obj,
34
34
loc: location. bridged)
35
35
case . atEndOf( let block) :
36
- return BridgedBuilder ( insertBefore: OptionalBridgedInstruction ( ) ,
37
- insertAtEnd: block. bridged. optional,
36
+ return BridgedBuilder ( insertAt: . endOfBlock, insertionObj: block. bridged. obj,
37
+ loc: location. bridged)
38
+ case . staticInitializer( let global) :
39
+ return BridgedBuilder ( insertAt: . intoGlobal, insertionObj: global. bridged. obj,
38
40
loc: location. bridged)
39
41
}
40
42
}
@@ -101,9 +103,19 @@ public struct Builder {
101
103
return notifyNew ( dr. getAs ( DeallocStackRefInst . self) )
102
104
}
103
105
104
- public func createUncheckedRefCast( object: Value , type: Type ) -> UncheckedRefCastInst {
105
- let object = bridged. createUncheckedRefCast ( object. bridged, type. bridged)
106
- return notifyNew ( object. getAs ( UncheckedRefCastInst . self) )
106
+ public func createUncheckedRefCast( from value: Value , to type: Type ) -> UncheckedRefCastInst {
107
+ let cast = bridged. createUncheckedRefCast ( value. bridged, type. bridged)
108
+ return notifyNew ( cast. getAs ( UncheckedRefCastInst . self) )
109
+ }
110
+
111
+ public func createUpcast( from value: Value , to type: Type ) -> UpcastInst {
112
+ let cast = bridged. createUpcast ( value. bridged, type. bridged)
113
+ return notifyNew ( cast. getAs ( UpcastInst . self) )
114
+ }
115
+
116
+ public func createLoad( fromAddress: Value , ownership: LoadInst . LoadOwnership ) -> LoadInst {
117
+ let load = bridged. createLoad ( fromAddress. bridged, ownership. rawValue)
118
+ return notifyNew ( load. getAs ( LoadInst . self) )
107
119
}
108
120
109
121
@discardableResult
@@ -112,6 +124,18 @@ public struct Builder {
112
124
return notifyNew ( setDeallocating. getAs ( SetDeallocatingInst . self) )
113
125
}
114
126
127
+ @discardableResult
128
+ public func createStrongRetain( operand: Value ) -> StrongRetainInst {
129
+ let retain = bridged. createStrongRetain ( operand. bridged)
130
+ return notifyNew ( retain. getAs ( StrongRetainInst . self) )
131
+ }
132
+
133
+ @discardableResult
134
+ public func createStrongRelease( operand: Value ) -> StrongReleaseInst {
135
+ let release = bridged. createStrongRelease ( operand. bridged)
136
+ return notifyNew ( release. getAs ( StrongReleaseInst . self) )
137
+ }
138
+
115
139
public func createFunctionRef( _ function: Function ) -> FunctionRefInst {
116
140
let functionRef = bridged. createFunctionRef ( function. bridged)
117
141
return notifyNew ( functionRef. getAs ( FunctionRefInst . self) )
@@ -184,4 +208,37 @@ public struct Builder {
184
208
let ui = bridged. createUnreachable ( )
185
209
return notifyNew ( ui. getAs ( UnreachableInst . self) )
186
210
}
211
+
212
+ @discardableResult
213
+ public func createObject( type: Type , arguments: [ Value ] , numBaseElements: Int ) -> ObjectInst {
214
+ let objectInst = arguments. withBridgedValues { valuesRef in
215
+ return bridged. createObject ( type. bridged, valuesRef, numBaseElements)
216
+ }
217
+ return notifyNew ( objectInst. getAs ( ObjectInst . self) )
218
+ }
219
+
220
+ public func createGlobalAddr( global: GlobalVariable ) -> GlobalAddrInst {
221
+ return notifyNew ( bridged. createGlobalAddr ( global. bridged) . getAs ( GlobalAddrInst . self) )
222
+ }
223
+
224
+ public func createGlobalValue( global: GlobalVariable ) -> GlobalValueInst {
225
+ return notifyNew ( bridged. createGlobalValue ( global. bridged) . getAs ( GlobalValueInst . self) )
226
+ }
227
+
228
+ @discardableResult
229
+ public func createStruct( type: Type , elements: [ Value ] ) -> StructInst {
230
+ let structInst = elements. withBridgedValues { valuesRef in
231
+ return bridged. createStruct ( type. bridged, valuesRef)
232
+ }
233
+ return notifyNew ( structInst. getAs ( StructInst . self) )
234
+ }
235
+
236
+ @discardableResult
237
+ public func createTuple( type: Type , elements: [ Value ] ) -> TupleInst {
238
+ let tuple = elements. withBridgedValues { valuesRef in
239
+ return bridged. createTuple ( type. bridged, valuesRef)
240
+ }
241
+ return notifyNew ( tuple. getAs ( TupleInst . self) )
242
+ }
243
+
187
244
}
0 commit comments