Skip to content

Commit

Permalink
Add some missing LLVM::Context bindings (#14612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed May 24, 2024
1 parent e043a25 commit b12f17f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
26 changes: 21 additions & 5 deletions src/llvm/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class LLVM::Context
Type.new LibLLVM.int_type_in_context(self, bits)
end

def half : Type
Type.new LibLLVM.half_type_in_context(self)
end

def float : Type
Type.new LibLLVM.float_type_in_context(self)
end
Expand All @@ -59,19 +63,31 @@ class LLVM::Context
Type.new LibLLVM.double_type_in_context(self)
end

def pointer : Type
def x86_fp80 : Type
Type.new LibLLVM.x86_fp80_type_in_context(self)
end

def fp128 : Type
Type.new LibLLVM.fp128_type_in_context(self)
end

def ppc_fp128 : Type
Type.new LibLLVM.ppc_fp128_type_in_context(self)
end

def pointer(address_space = 0) : Type
{% if LibLLVM::IS_LT_150 %}
{% raise "Opaque pointers are only supported on LLVM 15.0 or above" %}
{% else %}
Type.new LibLLVM.pointer_type_in_context(self, 0)
Type.new LibLLVM.pointer_type_in_context(self, address_space)
{% end %}
end

def void_pointer : Type
def void_pointer(address_space = 0) : Type
{% if LibLLVM::IS_LT_150 %}
int8.pointer
int8.pointer(address_space)
{% else %}
pointer
pointer(address_space)
{% end %}
end

Expand Down
4 changes: 4 additions & 0 deletions src/llvm/lib_llvm/core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ lib LibLLVM
fun int_type_in_context = LLVMIntTypeInContext(c : ContextRef, num_bits : UInt) : TypeRef
fun get_int_type_width = LLVMGetIntTypeWidth(integer_ty : TypeRef) : UInt

fun half_type_in_context = LLVMHalfTypeInContext(c : ContextRef) : TypeRef
fun float_type_in_context = LLVMFloatTypeInContext(c : ContextRef) : TypeRef
fun double_type_in_context = LLVMDoubleTypeInContext(c : ContextRef) : TypeRef
fun x86_fp80_type_in_context = LLVMX86FP80TypeInContext(c : ContextRef) : TypeRef
fun fp128_type_in_context = LLVMFP128TypeInContext(c : ContextRef) : TypeRef
fun ppc_fp128_type_in_context = LLVMPPCFP128TypeInContext(c : ContextRef) : TypeRef

fun function_type = LLVMFunctionType(return_type : TypeRef, param_types : TypeRef*, param_count : UInt, is_var_arg : Bool) : TypeRef
fun is_function_var_arg = LLVMIsFunctionVarArg(function_ty : TypeRef) : Bool
Expand Down
6 changes: 3 additions & 3 deletions src/llvm/type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ struct LLVM::Type
Value.new LibLLVM.get_undef(self)
end

def pointer : LLVM::Type
def pointer(address_space = 0) : LLVM::Type
{% if LibLLVM::IS_LT_150 %}
Type.new LibLLVM.pointer_type(self, 0)
Type.new LibLLVM.pointer_type(self, address_space)
{% else %}
Type.new LibLLVM.pointer_type_in_context(LibLLVM.get_type_context(self), 0)
Type.new LibLLVM.pointer_type_in_context(LibLLVM.get_type_context(self), address_space)
{% end %}
end

Expand Down

0 comments on commit b12f17f

Please sign in to comment.