Skip to content

Commit 2ae4e58

Browse files
Added delete() functions to Function and Global. (#20)
1 parent b40c63a commit 2ae4e58

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Sources/LLVM/BasicBlock.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public struct BasicBlock: IRValue, Sequence {
5050
return BasicBlock(llvm: blockRef)
5151
}
5252

53-
/// Removes this basic block from a function and deletes it.
53+
/// Deletes the basic block from its containing function.
54+
/// - note: This does not remove breaks to this block from the
55+
/// function. Ensure you have removed all insructions that reference
56+
/// this basic block before deleting it.
5457
public func delete() {
5558
LLVMDeleteBasicBlock(llvm)
5659
}

Sources/LLVM/Function.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public class Function: IRValue {
9999
return BasicBlock(llvm: block)
100100
}
101101

102+
/// Deletes the function from its containing module.
103+
/// - note: This does not remove calls to this function from the
104+
/// module. Ensure you have removed all insructions that reference
105+
/// this function before deleting it.
106+
public func delete() {
107+
LLVMDeleteFunction(llvm)
108+
}
109+
102110
/// Retrieves the underlying LLVM value object.
103111
public func asLLVM() -> LLVMValueRef {
104112
return llvm

Sources/LLVM/Global.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public struct Global: IRValue {
3333
set { LLVMSetThreadLocal(asLLVM(), newValue.llvm) }
3434
}
3535

36+
/// Deletes the global variable from its containing module.
37+
/// - note: This does not remove references to this global from the
38+
/// module. Ensure you have removed all insructions that reference
39+
/// this global before deleting it.
40+
public func delete() {
41+
LLVMDeleteGlobal(llvm)
42+
}
43+
3644
/// Retrieves the underlying LLVM value object.
3745
public func asLLVM() -> LLVMValueRef {
3846
return llvm

0 commit comments

Comments
 (0)