@@ -116,7 +116,8 @@ function lookup_global_refs!(ex::Expr)
116
116
return nothing
117
117
end
118
118
119
- const rng = MersenneTwister ()
119
+ # See https://github.com/JuliaLang/julia/pull/32800
120
+ const foreigncall_version = VERSION < v " 1.3.0-alpha.108" ? 0 : 1
120
121
121
122
"""
122
123
optimize!(code::CodeInfo, mod::Module)
@@ -164,13 +165,13 @@ function optimize!(code::CodeInfo, scope)
164
165
arg1 = stmt. args[1 ]
165
166
if (arg1 == :llvmcall || lookup_stmt (code. code, arg1) == Base. llvmcall) && isempty (sparams) && scope isa Method
166
167
nargs = length (stmt. args)- 4
167
- delete_idx = build_compiled_call! (stmt, Base. llvmcall, stmt . args[ 2 : 4 ], code, idx, nargs, sparams, evalmod)
168
+ delete_idx = build_compiled_call! (stmt, Base. llvmcall, code, idx, nargs, sparams, evalmod)
168
169
push! (foreigncalls_idx, idx)
169
170
append! (delete_idxs, delete_idx)
170
171
end
171
172
elseif isexpr (stmt, :foreigncall ) && scope isa Method
172
- nargs = stmt. args[5 ]
173
- delete_idx = build_compiled_call! (stmt, :ccall , stmt . args[ 1 : 3 ], code, idx, nargs, sparams, evalmod)
173
+ nargs = foreigncall_version == 0 ? stmt. args[5 ] : length (stmt . args[ 3 ])
174
+ delete_idx = build_compiled_call! (stmt, :ccall , code, idx, nargs, sparams, evalmod)
174
175
push! (foreigncalls_idx, idx)
175
176
append! (delete_idxs, delete_idx)
176
177
end
@@ -227,9 +228,8 @@ function parametric_type_to_expr(t::Type)
227
228
end
228
229
229
230
# Handle :llvmcall & :foreigncall (issue #28)
230
- function build_compiled_call! (stmt, fcall, typargs, code, idx, nargs, sparams, evalmod)
231
+ function build_compiled_call! (stmt, fcall, code, idx, nargs, sparams, evalmod)
231
232
TVal = evalmod == Core. Compiler ? Core. Compiler. Val : Val
232
- argnames = Any[Symbol (" arg" , string (i)) for i = 1 : nargs]
233
233
delete_idx = Int[]
234
234
if fcall == :ccall
235
235
cfunc, RetType, ArgType = lookup_stmt (code. code, stmt. args[1 ]), stmt. args[2 ], stmt. args[3 ]
@@ -289,6 +289,7 @@ function build_compiled_call!(stmt, fcall, typargs, code, idx, nargs, sparams, e
289
289
# When the ccall is dynamic we pass the pointer as an argument so can reuse the function
290
290
cc_key = (dynamic_ccall ? :ptr : cfunc, RetType, ArgType, evalmod) # compiled call key
291
291
f = get (compiled_calls, cc_key, nothing )
292
+ argnames = Any[Symbol (" arg" , string (i)) for i = 1 : nargs]
292
293
if f === nothing
293
294
if fcall == :ccall
294
295
ArgType = Expr (:tuple , [parametric_type_to_expr (t) for t in ArgType]. .. )
@@ -302,12 +303,13 @@ function build_compiled_call!(stmt, fcall, typargs, code, idx, nargs, sparams, e
302
303
push! (wrapargs, :(:: $TVal{$sparam} ))
303
304
end
304
305
methname = gensym (" compiledcall" )
305
- if stmt. args[4 ] == :(:llvmcall )
306
+ calling_convention = stmt. args[foreigncall_version == 0 ? 4 : 5 ]
307
+ if calling_convention == :(:llvmcall )
306
308
def = :(
307
309
function $methname ($ (wrapargs... )) where {$ (sparams... )}
308
310
return $ fcall ($ cfunc, llvmcall, $ RetType, $ ArgType, $ (argnames... ))
309
311
end )
310
- elseif stmt . args[ 4 ] == :(:stdcall )
312
+ elseif calling_convention == :(:stdcall )
311
313
def = :(
312
314
function $methname ($ (wrapargs... )) where {$ (sparams... )}
313
315
return $ fcall ($ cfunc, stdcall, $ RetType, $ ArgType, $ (argnames... ))
0 commit comments