I'd like to turn the following
i32_from_name(id) = @extern("i32_from_name", Int32, (Any,), string(id))
into:
i32_from_name(id) = ccall("extern i32_from_name", llvmcall, Int32, (Any,), string(id))
I just want to simplify the ccall
with a macro or generated function, so I don't have to include the "extern "
and llvmcall
every time. I haven't had luck with either macros or generated functions.
As background, I want to compile Julia to WebAssembly. To do that, I want to compile Julia code statically: https://github.com/tshort/StaticCompiler.jl. This ccall
incantation provides a way to call external functions. Here's an example of the LLVM code generated. From the WebAssembly point of view, this is how I'd call JavaScript functions from Julia. For other embedded or static use cases, you could call to functions in other libraries.
julia> i32_from_name(id) = ccall("extern i32_from_name", llvmcall, Int32, (Any,), string(id))
i32_from_name (generic function with 1 method)
julia> @code_llvm i32_from_name("a")
; @ REPL[2]:1 within `i32_from_name'
define i32 @julia_i32_from_name_17496(%jl_value_t addrspace(10)* nonnull) {
top:
%1 = call i32 @i32_from_name(%jl_value_t addrspace(10)* nonnull %0)
ret i32 %1
}
Got it figured out. See: tshort/StaticCompiler.jl#11.