bytecodealliance / cranelift-jit-demo

JIT compiler and runtime for a toy language, using Cranelift
Apache License 2.0
649 stars 61 forks source link

Ability to call JIT-compiled function without hard-coding function signature with mem::transmute #8

Open keyneom opened 5 years ago

keyneom commented 5 years ago

In the example provided, the function signature for the to-be compiled code-string must be known in advance in order to be able to call into the function properly.

https://github.com/CraneStation/simplejit-demo/blob/4b7b8099346d877fe559dd5b593b18344d62e30d/src/toy.rs#L47

Is it possible to make a call dynamically using an array of parameters instead of being required to mem::transmute to the correct function signature?

sunfishcode commented 5 years ago

No, that's not currently possible in SimpleJIT.

Wasmtime has such a mechanism here, though it depends on functions in Wasmtime's runtime.

Cy6er7um commented 2 years ago

You can use libffi to implement that, but the performance of this program will not be very impressive.....