Stream: wamr

Topic: WASI + WAMR as a compiler backend


view this post on Zulip Rishav Sharan (Oct 09 2023 at 11:33):

hey there

I am working on a toy language and I was wondering if it would make sense for me to use WASI + WAMR as a compiler backend and get AOT binaries as output? I was thinking of this chain;
compiler frontend > wat files as the IR > wat2wasm to generate wasm > wamr to compile

does that approach makes sense?

Few more questions, as I am very new to the webassembly area;

  1. Does webassembly, or wasi, or wamr etc impose any memory management. or am I expected to build it on my own?
  2. can I load dlls/.so files using my compiled binaries?
  3. How about support for C ABI?

Note: I would prefer not to use cranelift as I am not comfortable with rust and would prefer c99 instead.

view this post on Zulip Wenyong Huang (Oct 11 2023 at 03:58):

Hi,

yes, normally you can use WASI + WAMR as a compiler backend as long as the input is a well-formed wasm file and it compiles with the proposal of wasi snapshot preview1:
https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md
And maybe you can refer to the output wasm file compiled by wasi-sdk or emsdk.

And there is a similar project which compiles typescript into wasm, and then uses WAMR to run the wasm file:
https://github.com/intel/Wasmnizer-ts
Note that it uses binaryen to emit the wasm bytecodes. And now it only supports interpreter mode, since the AOT mode requires WAMR GC AOT feature which is under development.

For some questions:

  1. Does webassembly, or wasi, or wamr etc impose any memory management. or am I expected to build it on my own?

Per our understanding, normally the linear memory is divided into three areas: data area, aux stack area (or shadow stack) and heap area, the __data_end and __heap_base globals can be exported to mark them. Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/memory_tune.md

  1. can I load dlls/.so files using my compiled binaries?

WAMR runtime doesn't support loading .dll/.so files yet.

  1. How about support for C ABI?

Do you mean calling libc APIs from wasm application? It is supported if the wasm file imports the wasi APIs. And WAMR also supports the libc-builtin APIs to support a subset of libc, in which file/socket operations are not supported. Refer to here for a list of supported libc APIs:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c#L989-L1041

Toolchain for compiling TypeScript to WasmGC. Contribute to intel/Wasmnizer-ts development by creating an account on GitHub.

Last updated: Dec 23 2024 at 12:05 UTC