wasm3 / wasm3-rs

Rust wrapper for Wasm3, the fastest WebAssembly interpreter
MIT License
155 stars 43 forks source link

Support wasm3 compile flags #22

Open jiayihu opened 3 years ago

jiayihu commented 3 years ago

With #21 one can pass the propert clang flags in order to set the compilation flags in https://github.com/wasm3/wasm3/blob/master/source/m3_config.h, for instance:

BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/local/opt/gcc-arm-none-eabi/arm-none-eabi -Dd_m3HasFloat=0" cargo build

Currently passing -Dd_m3HasFloat=0 results in this error because the wasm3 signature changes:

error[E0061]: this function takes 4 arguments but 5 arguments were supplied
   --> /Users/jiayihu/Desktop/Repo/wasm3-rs/src/function.rs:185:13
    |
185 |             (*_pc.cast::<ffi::IM3Operation>()).expect("IM3Operation was null")(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 4 arguments
186 |                 _pc.add(1),
    |                 ----------
187 |                 _sp,
    |                 ---
188 |                 _mem,
    |                 ----
189 |                 _r0,
    |                 ---
190 |                 _fp0,
    |                 ---- supplied 5 arguments

Passing d_m3FixedHeap, such as -Dd_m3FixedHeap=(8 * 1024), also results in compilation error because the (8 * 1024) syntax is not supported by #21 .

I just wanted to report the issues and causes for anyone interested. After being finally able to compile everything, I realized while I was implementing the intrinsics for calloc, free, realloc (required if d_m3FixedHeap is unset) that I was not very satisfied with the wasm3 implementation itself. Its C code is very hard to read and extend IMO. I'm ditching in favor of https://github.com/paritytech/wasmi or writing a WASM runtime myself.

Veykril commented 3 years ago

Thanks for the heads up, I'll take a look at this when I can. I can agree that the C-source of wasm3 is very difficult to read as it looks very opinionated style-wise with the massive amount of macro magic going on. I hope wasmi will do you well 👍

jiayihu commented 3 years ago

Thanks! Also additional note: although wasm3 supports d_m3HasFloat to disable float operations, it's a all-or-nothing flag. In my case, the STM32F4 board has FPU support but only for single-precision operations. Disabling floating point operations would severely limit the runnable WASM modules, while enabling the flag would probably result in runtime error for f64 types I guess.

vshymanskyy commented 3 years ago

@jiayihu i think we could add a flag to treat all f64 types as f32 (loosing precision), at some point. Regarding the changing signatute. @Veykril with the latest wasm3, you should be able to use just the public API (only wasm3.h). Let me know if you struggle to implement some functionality via the new API.