@@ -47,35 +47,53 @@ function call_function(llvmf::LLVM.Function, rettyp::Type=Nothing, argtyp::Type=
47
47
end
48
48
end
49
49
50
+
50
51
"""
51
- isboxed(typ::Type)
52
+ isboxed(typ::Type; [ctx::Context] )
52
53
53
54
Return if a type would be boxed when instantiated in the code generator.
54
55
"""
55
- function isboxed (typ:: Type )
56
+ function isboxed (typ:: Type ; ctx :: Union{Nothing,Context} = nothing )
56
57
isboxed_ref = Ref {Bool} ()
57
- ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef, (Any, Ptr{Bool}), typ, isboxed_ref)
58
+ if VERSION >= v " 1.9.0-DEV.115"
59
+ if ctx === nothing
60
+ Context () do ctx
61
+ ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
62
+ (Any, LLVM. API. LLVMContextRef, Ptr{Bool}), typ, ctx, isboxed_ref)
63
+ end
64
+ else
65
+ ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
66
+ (Any, LLVM. API. LLVMContextRef, Ptr{Bool}), typ, ctx, isboxed_ref)
67
+ end
68
+ else
69
+ ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
70
+ (Any, Ptr{Bool}), typ, isboxed_ref)
71
+ end
58
72
return isboxed_ref[]
59
73
end
60
74
61
75
"""
62
- convert(LLVMType, typ::Type, [ ctx::Context] ; allow_boxed=true)
76
+ convert(LLVMType, typ::Type, ctx::Context; allow_boxed=true)
63
77
64
- Convert a Julia type `typ` to its LLVM representation. Fails if the type would be boxed .
65
- If `ctx` is specified, the returned LLVM type will be valid in that context .
78
+ Convert a Julia type `typ` to its LLVM representation in context `ctx` .
79
+ The `allow_boxed` argument determines whether boxed types are allowed .
66
80
"""
67
- function Base. convert (:: Type{LLVMType} , typ:: Type ; ctx:: Union{Nothing, Context} = nothing ,
81
+ function Base. convert (:: Type{LLVMType} , typ:: Type ; ctx:: Context ,
68
82
allow_boxed:: Bool = false )
69
83
isboxed_ref = Ref {Bool} ()
70
- llvmtyp = LLVMType (ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
71
- (Any, Ptr{Bool}), typ, isboxed_ref))
84
+ llvmtyp = if VERSION >= v " 1.9.0-DEV.115"
85
+ LLVMType (ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
86
+ (Any, Context, Ptr{Bool}), typ, ctx, isboxed_ref))
87
+ else
88
+ LLVMType (ccall (:jl_type_to_llvm , LLVM. API. LLVMTypeRef,
89
+ (Any, Ptr{Bool}), typ, isboxed_ref))
90
+ end
72
91
if ! allow_boxed && isboxed_ref[]
73
92
error (" Conversion of boxed type $typ is not allowed" )
74
93
end
75
94
76
- if ctx != = nothing && ctx != context (llvmtyp)
77
- # FIXME : Julia currently doesn't offer an API to fetch types in a specific context
78
-
95
+ # HACK: older versions of Julia don't offer an API to fetch types in a specific context
96
+ if VERSION < v " 1.9.0-DEV.115" && ctx != context (llvmtyp)
79
97
if llvmtyp == LLVM. VoidType (context (llvmtyp))
80
98
return LLVM. VoidType (ctx)
81
99
end
0 commit comments