File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ public struct BasicBlock: IRValue {
40
40
return Instruction ( llvm: val)
41
41
}
42
42
43
+ /// Returns the terminator instruction if this basic block is well formed or
44
+ /// `nil` if it is not well formed.
45
+ public var terminator : TerminatorInstruction ? {
46
+ guard let term = LLVMGetBasicBlockTerminator ( llvm) else { return nil }
47
+ return TerminatorInstruction ( llvm: term)
48
+ }
49
+
43
50
/// Returns the parent function of this basic block, if it exists.
44
51
public var parent : Function ? {
45
52
guard let functionRef = LLVMGetBasicBlockParent ( llvm) else { return nil }
Original file line number Diff line number Diff line change @@ -51,3 +51,30 @@ public struct Instruction: IRValue {
51
51
}
52
52
}
53
53
}
54
+
55
+ /// A `TerminatorInstruction` represents an instruction that terminates a
56
+ /// basic block.
57
+ public struct TerminatorInstruction {
58
+ internal let llvm : LLVMValueRef
59
+
60
+ /// Creates a `TerminatorInstruction` from an `LLVMValueRef` object.
61
+ public init ( llvm: LLVMValueRef ) {
62
+ self . llvm = llvm
63
+ }
64
+
65
+ /// Retrieves the number of successors of this terminator instruction.
66
+ public var successorCount : Int {
67
+ return Int ( LLVMGetNumSuccessors ( llvm) )
68
+ }
69
+
70
+ /// Returns the successor block at the specified index, if it exists.
71
+ public func getSuccessor( at idx: Int ) -> BasicBlock ? {
72
+ guard let succ = LLVMGetSuccessor ( llvm, UInt32 ( idx) ) else { return nil }
73
+ return BasicBlock ( llvm: succ)
74
+ }
75
+
76
+ /// Updates the successor block at the specified index.
77
+ public func setSuccessor( at idx: Int , to bb: BasicBlock ) {
78
+ LLVMSetSuccessor ( llvm, UInt32 ( idx) , bb. asLLVM ( ) )
79
+ }
80
+ }
You can’t perform that action at this time.
0 commit comments