Skip to content

Commit d41288d

Browse files
committed
Document Switch
1 parent 0a342be commit d41288d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Sources/LLVMSwift/Switch.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import cllvm
22

3+
/// A `Switch` represents a `switch` instruction. A `switch` instruction
4+
/// defines a jump table of values and destination basic blocks to pass the flow
5+
/// of control to if a condition value matches. If no match is made, control
6+
/// flow passes to the default basic block.
37
public struct Switch: IRValue {
4-
internal let llvm: LLVMValueRef
5-
6-
public func addCase(_ value: IRValue, _ block: BasicBlock) {
7-
LLVMAddCase(llvm, value.asLLVM(), block.asLLVM())
8-
}
9-
10-
public func asLLVM() -> LLVMValueRef {
11-
return llvm
12-
}
8+
internal let llvm: LLVMValueRef
9+
10+
/// Inserts a case with the given value and destination basic block in the
11+
/// jump table of this `switch` instruction.
12+
///
13+
/// - parameter value: The value that acts as the selector for this case.
14+
/// - parameter block: The destination block for the flow of control if this
15+
/// case is matched.
16+
public func addCase(_ value: IRValue, _ block: BasicBlock) {
17+
LLVMAddCase(llvm, value.asLLVM(), block.asLLVM())
18+
}
19+
20+
/// Retrieves the underlying LLVM value object.
21+
public func asLLVM() -> LLVMValueRef {
22+
return llvm
23+
}
1324
}

0 commit comments

Comments
 (0)