Skip to content

Commit 8926897

Browse files
author
Ary Borenszweig
committedFeb 19, 2017
LLVM: make Context keep a reference to its builders, and make an DIBuilder keep a reference to its module.
1 parent e276338 commit 8926897

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed
 

Diff for: ‎src/llvm/builder.cr

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
class LLVM::Builder
22
@disposed = false
33

4-
# def initialize(@unwrap : LibLLVM::BuilderRef, @context : Context)
5-
# end
6-
74
def initialize(@unwrap : LibLLVM::BuilderRef)
85
end
96

@@ -239,7 +236,7 @@ class LLVM::Builder
239236
@unwrap
240237
end
241238

242-
def finalize
239+
protected def dispose
243240
return if @disposed
244241
@disposed = true
245242

Diff for: ‎src/llvm/context.cr

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class LLVM::Context
55

66
def initialize(@unwrap : LibLLVM::ContextRef, @dispose_on_finalize = true)
77
@disposed = false
8+
@builders = [] of LLVM::Builder
89
end
910

1011
def new_module(name : String) : Module
@@ -16,8 +17,10 @@ class LLVM::Context
1617
end
1718

1819
def new_builder : Builder
19-
# Builder.new(LibLLVM.create_builder_in_context(self), self)
20-
Builder.new(LibLLVM.create_builder_in_context(self))
20+
# builder = Builder.new(LibLLVM.create_builder_in_context(self), self)
21+
builder = Builder.new(LibLLVM.create_builder_in_context(self))
22+
@builders << builder
23+
builder
2124
end
2225

2326
def void : Type
@@ -121,6 +124,8 @@ class LLVM::Context
121124
return if @disposed
122125
@disposed = true
123126

127+
@builders.each &.dispose
128+
124129
LibLLVM.dispose_context(self)
125130
end
126131

Diff for: ‎src/llvm/di_builder.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "./lib_llvm"
22

33
struct LLVM::DIBuilder
4-
def initialize(llvm_module)
4+
def initialize(@llvm_module : Module)
55
@unwrap = LibLLVMExt.create_di_builder(llvm_module)
66
end
77

0 commit comments

Comments
 (0)
Please sign in to comment.