@@ -16,49 +16,48 @@ import SILBridging
1616public struct Operand : CustomStringConvertible , NoReflectionChildren {
1717 fileprivate let bridged : BridgedOperand
1818
19- init ( _ bridged: BridgedOperand ) {
19+ init ( bridged: BridgedOperand ) {
2020 self . bridged = bridged
2121 }
2222
23- public var value : Value {
24- Operand_getValue ( bridged) . value
25- }
23+ public var value : Value { bridged. getValue ( ) . value }
2624
2725 public static func == ( lhs: Operand , rhs: Operand ) -> Bool {
2826 return lhs. bridged. op == rhs. bridged. op
2927 }
3028
3129 public var instruction : Instruction {
32- return Operand_getUser ( bridged) . instruction
30+ return bridged. getUser ( ) . instruction
3331 }
3432
3533 public var index : Int { instruction. operands. getIndex ( of: self ) }
3634
3735 /// True if the operand is used to describe a type dependency, but it's not
3836 /// used as value.
39- public var isTypeDependent : Bool { Operand_isTypeDependent ( bridged) != 0 }
37+ public var isTypeDependent : Bool { bridged. isTypeDependent ( ) }
4038
4139 public var description : String { " operand # \( index) of \( instruction) " }
4240}
4341
4442public struct OperandArray : RandomAccessCollection , CustomReflectable {
45- private let opArray : BridgedArrayRef
43+ private let base : OptionalBridgedOperand
44+ public let count : Int
4645
47- init ( opArray: BridgedArrayRef ) {
48- self . opArray = opArray
46+ init ( base: OptionalBridgedOperand , count: Int ) {
47+ self . base = base
48+ self . count = count
4949 }
50-
50+
5151 public var startIndex : Int { return 0 }
52- public var endIndex : Int { return Int ( opArray . numElements ) }
52+ public var endIndex : Int { return count }
5353
5454 public subscript( _ index: Int ) -> Operand {
55- assert ( index >= 0 && index < endIndex)
56- return Operand ( BridgedOperand ( op : opArray . data! + index &* BridgedOperandSize ) )
55+ assert ( index >= startIndex && index < endIndex)
56+ return Operand ( bridged : base . advancedBy ( index) )
5757 }
5858
5959 public func getIndex( of operand: Operand ) -> Int {
60- let idx = ( operand. bridged. op - UnsafeRawPointer( opArray. data!) ) /
61- BridgedOperandSize
60+ let idx = base. distanceTo ( operand. bridged)
6261 assert ( self [ idx] . bridged. op == operand. bridged. op)
6362 return idx
6463 }
@@ -72,38 +71,38 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
7271 ///
7372 /// Note: this does not return a Slice. The first index of the returnd array is always 0.
7473 public subscript( bounds: Range < Int > ) -> OperandArray {
75- assert ( bounds. lowerBound >= 0 )
76- assert ( bounds. upperBound <= endIndex)
77- return OperandArray ( opArray: BridgedArrayRef (
78- data: opArray. data! + bounds. lowerBound &* BridgedOperandSize,
79- numElements: bounds. upperBound - bounds. lowerBound) )
74+ assert ( bounds. lowerBound >= startIndex && bounds. upperBound <= endIndex)
75+ return OperandArray (
76+ base: OptionalBridgedOperand ( op: base. advancedBy ( bounds. lowerBound) . op) ,
77+ count: bounds. upperBound - bounds. lowerBound)
8078 }
8179}
8280
8381public struct UseList : CollectionLikeSequence {
8482 public struct Iterator : IteratorProtocol {
85- var currentOpPtr : UnsafeRawPointer ?
83+ var currentOpPtr : OptionalBridgedOperand
8684
8785 public mutating func next( ) -> Operand ? {
88- if let opPtr = currentOpPtr {
89- let bridged = BridgedOperand ( op: opPtr)
90- currentOpPtr = Operand_nextUse ( bridged) . op
91- return Operand ( bridged)
86+ if let op = currentOpPtr. operand {
87+ currentOpPtr = op. getNextUse ( )
88+ return Operand ( bridged: op)
9289 }
9390 return nil
9491 }
9592 }
9693
97- private let firstOpPtr : UnsafeRawPointer ?
94+ private let firstOpPtr : OptionalBridgedOperand
9895
9996 init ( _ firstOpPtr: OptionalBridgedOperand ) {
100- self . firstOpPtr = firstOpPtr. op
97+ self . firstOpPtr = firstOpPtr
10198 }
10299
103100 public var singleUse : Operand ? {
104- if let opPtr = firstOpPtr {
105- if Operand_nextUse ( BridgedOperand ( op: opPtr) ) . op != nil { return nil }
106- return Operand ( BridgedOperand ( op: opPtr) )
101+ if let op = firstOpPtr. operand {
102+ if op. getNextUse ( ) . operand != nil {
103+ return nil
104+ }
105+ return Operand ( bridged: op)
107106 }
108107 return nil
109108 }
@@ -114,3 +113,12 @@ public struct UseList : CollectionLikeSequence {
114113 return Iterator ( currentOpPtr: firstOpPtr)
115114 }
116115}
116+
117+ extension OptionalBridgedOperand {
118+ var operand : BridgedOperand ? {
119+ if let op = op {
120+ return BridgedOperand ( op: op)
121+ }
122+ return nil
123+ }
124+ }
0 commit comments