Skip to content

Commit

Permalink
LLVM: get_module_identifer and set_module_identifier were introdu…
Browse files Browse the repository at this point in the history
…ced in LLVM 3.9
  • Loading branch information
Ary Borenszweig committed Feb 13, 2017
1 parent 4175143 commit c60df09
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/llvm/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class LLVM::Context
end

def new_module(name : String) : Module
Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
Module.new(LibLLVM.module_create_with_name_in_context(name, self), name, self)
{% else %}
Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
{% end %}
end

def new_builder : Builder
Expand Down Expand Up @@ -97,7 +101,11 @@ class LLVM::Context
if ret != 0 && msg
raise LLVM.string_and_dispose(msg)
end
Module.new(mod, self)
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
Module.new(mod, "unknown", self)
{% else %}
Module.new(mod, self)
{% end %}
end

def ==(other : self)
Expand Down
5 changes: 3 additions & 2 deletions src/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,16 @@ lib LibLLVM
fun add_attribute_at_index = LLVMAddAttributeAtIndex(f : ValueRef, idx : AttributeIndex, a : AttributeRef)
fun get_enum_attribute_at_index = LLVMGetEnumAttributeAtIndex(f : ValueRef, idx : AttributeIndex, kind_id : UInt) : AttributeRef
fun add_call_site_attribute = LLVMAddCallSiteAttribute(f : ValueRef, idx : AttributeIndex, value : AttributeRef)

fun get_module_identifier = LLVMGetModuleIdentifier(m : ModuleRef, len : LibC::SizeT*) : UInt8*
fun set_module_identifier = LLVMSetModuleIdentifier(m : ModuleRef, ident : UInt8*, len : LibC::SizeT)
{% end %}

fun get_module_context = LLVMGetModuleContext(m : ModuleRef) : ContextRef
fun get_global_parent = LLVMGetGlobalParent(global : ValueRef) : ModuleRef

fun create_memory_buffer_with_contents_of_file = LLVMCreateMemoryBufferWithContentsOfFile(path : UInt8*, out_mem_buf : MemoryBufferRef*, out_message : UInt8**) : Int32
fun parse_ir_in_context = LLVMParseIRInContext(context : ContextRef, mem_buf : MemoryBufferRef, out_m : ModuleRef*, out_message : UInt8**) : Int32
fun get_module_identifier = LLVMGetModuleIdentifier(m : ModuleRef, len : LibC::SizeT*) : UInt8*
fun set_module_identifier = LLVMSetModuleIdentifier(m : ModuleRef, ident : UInt8*, len : LibC::SizeT)
fun context_dispose = LLVMContextDispose(ContextRef)

fun void_type_in_context = LLVMVoidTypeInContext(ContextRef) : TypeRef
Expand Down
30 changes: 20 additions & 10 deletions src/llvm/module.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ class LLVM::Module

getter context : Context

def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
@owned = false
end
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
def initialize(@unwrap : LibLLVM::ModuleRef, @name : String, @context : Context)
@owned = false
end

def name : String
bytes = LibLLVM.get_module_identifier(self, out bytesize)
String.new(Slice.new(bytes, bytesize))
end
def name : String
@name
end
{% else %}
def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
@owned = false
end

def name=(name : String)
LibLLVM.set_module_identifier(self, name, name.bytesize)
end
def name : String
bytes = LibLLVM.get_module_identifier(self, out bytesize)
String.new(Slice.new(bytes, bytesize))
end

def name=(name : String)
LibLLVM.set_module_identifier(self, name, name.bytesize)
end
{% end %}

def target=(target)
LibLLVM.set_target(self, target)
Expand Down

0 comments on commit c60df09

Please sign in to comment.