mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Improve collections in the swift SIL/Optimizer
Improve block/instruction lists and similar collections * pretty print collections in the form “[a, b, c]” * also do this for lazy sequences * define a custom Mirror * in a collection, only print the name of blocks, functions and globals (instead of the full object) * replace `BasicBlock.reverseInstructions` with `BasicBlock.instructions.reversed()` - in an efficient way
This commit is contained in:
@@ -12,10 +12,15 @@
|
||||
|
||||
import SILBridging
|
||||
|
||||
final public class BasicBlock : ListNode, CustomStringConvertible {
|
||||
final public class BasicBlock : ListNode, CustomStringConvertible, HasName {
|
||||
public var next: BasicBlock? { SILBasicBlock_next(bridged).block }
|
||||
public var previous: BasicBlock? { SILBasicBlock_previous(bridged).block }
|
||||
|
||||
// Needed for ReverseList<BasicBlock>.reversed(). Never use directly.
|
||||
public var _firstInList: BasicBlock { SILFunction_firstBlock(function.bridged).block! }
|
||||
// Needed for List<BasicBlock>.reversed(). Never use directly.
|
||||
public var _lastInList: BasicBlock { SILFunction_lastBlock(function.bridged).block! }
|
||||
|
||||
public var function: Function { SILBasicBlock_getFunction(bridged).function }
|
||||
|
||||
public var description: String {
|
||||
@@ -25,11 +30,7 @@ final public class BasicBlock : ListNode, CustomStringConvertible {
|
||||
public var arguments: ArgumentArray { ArgumentArray(block: self) }
|
||||
|
||||
public var instructions: List<Instruction> {
|
||||
List(startAt: SILBasicBlock_firstInst(bridged).instruction)
|
||||
}
|
||||
|
||||
public var reverseInstructions: ReverseList<Instruction> {
|
||||
ReverseList(startAt: SILBasicBlock_lastInst(bridged).instruction)
|
||||
List(first: SILBasicBlock_firstInst(bridged).instruction)
|
||||
}
|
||||
|
||||
public var terminator: TermInst {
|
||||
@@ -60,8 +61,8 @@ final public class BasicBlock : ListNode, CustomStringConvertible {
|
||||
}
|
||||
fatalError()
|
||||
}
|
||||
|
||||
public var label: String { "bb\(index)" }
|
||||
|
||||
public var name: String { "bb\(index)" }
|
||||
|
||||
var bridged: BridgedBasicBlock { BridgedBasicBlock(obj: SwiftObject(self)) }
|
||||
}
|
||||
@@ -80,7 +81,7 @@ public struct ArgumentArray : RandomAccessCollection {
|
||||
}
|
||||
}
|
||||
|
||||
public struct SuccessorArray : RandomAccessCollection, CustomReflectable {
|
||||
public struct SuccessorArray : RandomAccessCollection, FormattedLikeArray {
|
||||
private let succArray: BridgedArrayRef
|
||||
|
||||
init(succArray: BridgedArrayRef) {
|
||||
@@ -95,14 +96,9 @@ public struct SuccessorArray : RandomAccessCollection, CustomReflectable {
|
||||
let s = BridgedSuccessor(succ: succArray.data + index &* BridgedSuccessorSize);
|
||||
return SILSuccessor_getTargetBlock(s).block
|
||||
}
|
||||
|
||||
public var customMirror: Mirror {
|
||||
let c: [Mirror.Child] = map { (label: nil, value: $0.label) }
|
||||
return Mirror(self, children: c)
|
||||
}
|
||||
}
|
||||
|
||||
public struct PredecessorList : Sequence, IteratorProtocol, CustomReflectable {
|
||||
public struct PredecessorList : CollectionLikeSequence, IteratorProtocol {
|
||||
private var currentSucc: OptionalBridgedSuccessor
|
||||
|
||||
public init(startAt: OptionalBridgedSuccessor) { currentSucc = startAt }
|
||||
@@ -115,11 +111,6 @@ public struct PredecessorList : Sequence, IteratorProtocol, CustomReflectable {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public var customMirror: Mirror {
|
||||
let c: [Mirror.Child] = map { (label: nil, value: $0) }
|
||||
return Mirror(self, children: c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user