From 838901b5d7465e2b296010a555f213452270d2a6 Mon Sep 17 00:00:00 2001 From: Harlan Haskins Date: Thu, 9 Feb 2017 13:01:33 -0500 Subject: [PATCH] Fixed BasicBlock.parent and added IRBuilder.currentFunction --- Sources/LLVM/BasicBlock.swift | 8 ++++---- Sources/LLVM/IRBuilder.swift | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/LLVM/BasicBlock.swift b/Sources/LLVM/BasicBlock.swift index 93be9bc3..f5ddcf30 100644 --- a/Sources/LLVM/BasicBlock.swift +++ b/Sources/LLVM/BasicBlock.swift @@ -40,10 +40,10 @@ public struct BasicBlock: IRValue { return Instruction(llvm: val) } - /// Returns the parent of this basic block, if it exists. - public func parent() -> BasicBlock? { - guard let blockRef = LLVMGetBasicBlockParent(llvm) else { return nil } - return BasicBlock(llvm: blockRef) + /// Returns the parent function of this basic block, if it exists. + public var parent: Function? { + guard let functionRef = LLVMGetBasicBlockParent(llvm) else { return nil } + return Function(llvm: functionRef) } /// Returns the basic block following this basic block, if it exists. diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index a8ba41b2..28ab7773 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -400,6 +400,11 @@ public class IRBuilder { return BasicBlock(llvm: blockRef) } + /// Gets the function this builder is building into. + public var currentFunction: Function? { + return insertBlock?.parent + } + /// Inserts the given instruction into the IR Builder. /// /// - parameter inst: The instruction to insert.