Stream: general

Topic: Get FuncRef by JIT Compiled Function


view this post on Zulip Robin Lindner (Aug 06 2022 at 16:09):

I create the function with Module->declare_function and Module ->define_function.
And how can I get the FuncRef to this (to call this declared fn)?

view this post on Zulip Afonso Bordado (Aug 06 2022 at 16:13):

You can do it with get_finalized_function, but then have to do some transmute tricks (be careful here!).

https://github.com/bytecodealliance/wasmtime/blob/c5e3c0cafbc21d9181b4105034c50b5164b1bfc5/cranelift/jit/examples/jit-minimal.rs#L77-L84

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Robin Lindner (Aug 06 2022 at 16:18):

@Afonso Bordado Is there some official way to Call a JIT compiled function by another function?

view this post on Zulip Afonso Bordado (Aug 06 2022 at 16:23):

Not really. As far as I know its pretty much that.

However, in our current test runner we do build a trampoline and call functions via that. The trampoline deals with the ABI issues that may occur if we used the transmute method.

Moving the trampoline to cranelift-jit would probably be a good idea.

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Robin Lindner (Aug 06 2022 at 16:26):

@Afonso Bordado
I mean that I call ".call" via InstBuilder and the first argument must be a FuncRef.
Does this apply here?

view this post on Zulip Afonso Bordado (Aug 06 2022 at 16:29):

Oh, i missunderstood.

To call clif functions from clif functions you need to declare_func_in_func and then pass that to call

A standalone runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

Last updated: Oct 23 2024 at 20:03 UTC