Skip to content

Commit a539cee

Browse files
Fixed BasicBlock.parent and added IRBuilder.currentFunction (#63)
1 parent 328d63d commit a539cee

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Sources/LLVM/BasicBlock.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public struct BasicBlock: IRValue {
4040
return Instruction(llvm: val)
4141
}
4242

43-
/// Returns the parent of this basic block, if it exists.
44-
public func parent() -> BasicBlock? {
45-
guard let blockRef = LLVMGetBasicBlockParent(llvm) else { return nil }
46-
return BasicBlock(llvm: blockRef)
43+
/// Returns the parent function of this basic block, if it exists.
44+
public var parent: Function? {
45+
guard let functionRef = LLVMGetBasicBlockParent(llvm) else { return nil }
46+
return Function(llvm: functionRef)
4747
}
4848

4949
/// Returns the basic block following this basic block, if it exists.

Sources/LLVM/IRBuilder.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ public class IRBuilder {
400400
return BasicBlock(llvm: blockRef)
401401
}
402402

403+
/// Gets the function this builder is building into.
404+
public var currentFunction: Function? {
405+
return insertBlock?.parent
406+
}
407+
403408
/// Inserts the given instruction into the IR Builder.
404409
///
405410
/// - parameter inst: The instruction to insert.

0 commit comments

Comments
 (0)