Skip to content

Commit c60df09

Browse files
author
Ary Borenszweig
committedFeb 13, 2017
LLVM: get_module_identifer and set_module_identifier were introduced in LLVM 3.9
1 parent 4175143 commit c60df09

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed
 

‎src/llvm/context.cr

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class LLVM::Context
88
end
99

1010
def new_module(name : String) : Module
11-
Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
11+
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
12+
Module.new(LibLLVM.module_create_with_name_in_context(name, self), name, self)
13+
{% else %}
14+
Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
15+
{% end %}
1216
end
1317

1418
def new_builder : Builder
@@ -97,7 +101,11 @@ class LLVM::Context
97101
if ret != 0 && msg
98102
raise LLVM.string_and_dispose(msg)
99103
end
100-
Module.new(mod, self)
104+
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
105+
Module.new(mod, "unknown", self)
106+
{% else %}
107+
Module.new(mod, self)
108+
{% end %}
101109
end
102110

103111
def ==(other : self)

‎src/llvm/lib_llvm.cr

+3-2
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,16 @@ lib LibLLVM
318318
fun add_attribute_at_index = LLVMAddAttributeAtIndex(f : ValueRef, idx : AttributeIndex, a : AttributeRef)
319319
fun get_enum_attribute_at_index = LLVMGetEnumAttributeAtIndex(f : ValueRef, idx : AttributeIndex, kind_id : UInt) : AttributeRef
320320
fun add_call_site_attribute = LLVMAddCallSiteAttribute(f : ValueRef, idx : AttributeIndex, value : AttributeRef)
321+
322+
fun get_module_identifier = LLVMGetModuleIdentifier(m : ModuleRef, len : LibC::SizeT*) : UInt8*
323+
fun set_module_identifier = LLVMSetModuleIdentifier(m : ModuleRef, ident : UInt8*, len : LibC::SizeT)
321324
{% end %}
322325

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

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

332333
fun void_type_in_context = LLVMVoidTypeInContext(ContextRef) : TypeRef

‎src/llvm/module.cr

+20-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ class LLVM::Module
66

77
getter context : Context
88

9-
def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
10-
@owned = false
11-
end
9+
{% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
10+
def initialize(@unwrap : LibLLVM::ModuleRef, @name : String, @context : Context)
11+
@owned = false
12+
end
1213

13-
def name : String
14-
bytes = LibLLVM.get_module_identifier(self, out bytesize)
15-
String.new(Slice.new(bytes, bytesize))
16-
end
14+
def name : String
15+
@name
16+
end
17+
{% else %}
18+
def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
19+
@owned = false
20+
end
1721

18-
def name=(name : String)
19-
LibLLVM.set_module_identifier(self, name, name.bytesize)
20-
end
22+
def name : String
23+
bytes = LibLLVM.get_module_identifier(self, out bytesize)
24+
String.new(Slice.new(bytes, bytesize))
25+
end
26+
27+
def name=(name : String)
28+
LibLLVM.set_module_identifier(self, name, name.bytesize)
29+
end
30+
{% end %}
2131

2232
def target=(target)
2333
LibLLVM.set_target(self, target)

0 commit comments

Comments
 (0)
Please sign in to comment.