Skip to content

Commit d71db97

Browse files
committed
Allow creating standalone blocks and moving blocks
Unfortunately, we don't have inserting standalone blocks yet. Needs https://reviews.llvm.org/D59658
1 parent 932c6a7 commit d71db97

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Sources/LLVM/BasicBlock.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ public struct BasicBlock: IRValue {
2323
self.llvm = llvm
2424
}
2525

26+
/// Creates a new basic block without a parent function.
27+
///
28+
/// The basic block should be inserted into a function or destroyed before
29+
/// the IR builder is finalized.
30+
public init(context: Context = .global, name: String = "") {
31+
self.llvm = LLVMCreateBasicBlockInContext(context.llvm, name)
32+
}
33+
34+
/// Given that this block and a given block share a parent function, move this
35+
/// block before the given block in that function's basic block list.
36+
///
37+
/// - Parameter position: The basic block that acts as a position before
38+
/// which this block will be moved.
39+
public func move(before position: BasicBlock) {
40+
LLVMMoveBasicBlockBefore(self.asLLVM(), position.asLLVM())
41+
}
42+
43+
/// Given that this block and a given block share a parent function, move this
44+
/// block after the given block in that function's basic block list.
45+
///
46+
/// - Parameter position: The basic block that acts as a position after
47+
/// which this block will be moved.
48+
public func move(after position: BasicBlock) {
49+
LLVMMoveBasicBlockAfter(self.asLLVM(), position.asLLVM())
50+
}
51+
2652
/// Retrieves the underlying LLVM value object.
2753
public func asLLVM() -> LLVMValueRef {
2854
return llvm

0 commit comments

Comments
 (0)