Skip to content

Fixed BasicBlock.parent and added IRBuilder.currentFunction #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/LLVM/BasicBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down