Skip to content

Commit

Permalink
LLVM: make Context keep a reference to its builders, and make an DIBu…
Browse files Browse the repository at this point in the history
…ilder keep a reference to its module.
  • Loading branch information
asterite committed Feb 19, 2017
1 parent e276338 commit 8926897
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/llvm/builder.cr
@@ -1,9 +1,6 @@
class LLVM::Builder
@disposed = false

# def initialize(@unwrap : LibLLVM::BuilderRef, @context : Context)
# end

def initialize(@unwrap : LibLLVM::BuilderRef)
end

Expand Down Expand Up @@ -239,7 +236,7 @@ class LLVM::Builder
@unwrap
end

def finalize
protected def dispose
return if @disposed
@disposed = true

Expand Down
9 changes: 7 additions & 2 deletions src/llvm/context.cr
Expand Up @@ -5,6 +5,7 @@ class LLVM::Context

def initialize(@unwrap : LibLLVM::ContextRef, @dispose_on_finalize = true)
@disposed = false
@builders = [] of LLVM::Builder
end

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

def new_builder : Builder
# Builder.new(LibLLVM.create_builder_in_context(self), self)
Builder.new(LibLLVM.create_builder_in_context(self))
# builder = Builder.new(LibLLVM.create_builder_in_context(self), self)
builder = Builder.new(LibLLVM.create_builder_in_context(self))
@builders << builder
builder
end

def void : Type
Expand Down Expand Up @@ -121,6 +124,8 @@ class LLVM::Context
return if @disposed
@disposed = true

@builders.each &.dispose

LibLLVM.dispose_context(self)
end

Expand Down
2 changes: 1 addition & 1 deletion src/llvm/di_builder.cr
@@ -1,7 +1,7 @@
require "./lib_llvm"

struct LLVM::DIBuilder
def initialize(llvm_module)
def initialize(@llvm_module : Module)
@unwrap = LibLLVMExt.create_di_builder(llvm_module)
end

Expand Down

0 comments on commit 8926897

Please sign in to comment.