Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing LLVM::Context bindings #14612

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading