| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* wasm2c: prettify/change name-mangling
This refactors the wasm2c name-mangling in two big ways:
1) Removing the `Z_` prefix and trying to make the names somewhat
ergonomic/pretty. Previously the `factorial` export from a `fac`
module looked like this:
```
u32 Z_facZ_factorial(Z_fac_instance_t*, u32);
```
After this commit, it looks like this:
```
u32 w2c_fac_factorial(w2c_fac*, u32);
```
Symbols defined by wasm2c itself (including instantiate, free,
get_func_type and the imported memory limits) are now prefixed with
`wasm2c_` to avoid conflicting with names defined by the module.
2) Using globally unique (module-prefixed) names for functions, types,
segments, and tags, even though they are currently static
(internal-linkage) symbols in the .c output. This is preparation for
a future "multiple .c output" option where these symbols will need to
have external linkage.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This makes wasm2c serialize each function type, rather than registering
function types at module-initialization time. The serialized function
type is the SHA-256 of the mangled param and result types (with a space
between params and results).
At runtime in call_indirect, a known (immediate) function type is
compared against the function type stored in a funcref structure. For
call_indirects to functions local to the module, or for any
call_indirect when the toolchain merges string constants across
compilation units (generally, GCC and clang), this can be done by
comparing the pointers to each function type. Otherwise, the actual
32-byte values are compared.
The function type IDs can be looked up at runtime with
`Z_[modname]_get_func_type`, which matches the API from
`wasm_rt_register_func_type`. A new `callback` example demos this.
wasm2c does the SHA-256 either by linking against libcrypto or, if not
available or if requested via `cmake -DUSE_INTERNAL_SHA256=ON`, by using
a vendored (header-only) PicoSHA2. There is no runtime dependency on
SHA-256 in the wasm2c runtime or generated modules.
This eliminates the last of the per-module state, so this commit also removes
the [modname]_init_module() function and the s_module_initialized bool.
|
|
|
|
| |
(#2133)
|
| |
|
|
|
| |
Co-authored-by: Angela Montemayor <amontema@cs.stanford.edu>
|
|
|
|
|
|
| |
This will be required by module instancing and bulk memory
ops to avoid a memory leak detected by asan.
Update README.md to reflect changes, including the `fac` walkthrough.
|
|
|
|
|
|
|
|
|
|
|
|
| |
The module prefix is no longer optional and is now set by default to the
name of the module as given in the name section, or taken from the name
of the input file.
A new `-n/--module-name` command line flag can also be used to override.
The prefix used by the generated code is now fixed at wasm2c time which
makes the output code easier to read and also avoid the symbol pasting
in the C pre-processor which makes the source hard to understand. For
example, it makes symbols hard to `grep` for.
|
|
|
|
|
|
|
|
|
|
|
| |
This effectively means that we no longer support imports that are
overloaded by signature only. This is not something that we need to
support in order to support the core wasm spec.
This feature is available in the JS embedding but there is no good
reason (AFAICT) to support it in wasm2c, and this simplifies the
generated code.
Fixes #1858
|
|
|
|
|
|
| |
On MacOS, merge OOB and exhaustion traps. (Linux distinguishes these as SEGV_ACCERR vs. SEGV_MAPERR in the
si_code, but MacOS seems to deliver a SEGV_ACCERR for both.)
Add wasm_rt_init() and wasm_rt_free() functions to wasm-rt.h that the embedder must call to set up and clean up the runtime state. (If the embedder doesn't call these, OOB and exhaustion will result in an uncaught segfault.)
|
|
This example demonstrates how to use imported functions. The `rot13`
program takes each command line argument, and rot13-encodes it.
The exported `rot13` function has no arguments, and instead calls back
into the program (via `fill_buf`) with a buffer to fill in. When the
function finishes it calls `buf_done`.
(rot13.wat is the same as in src/test-interp.cc.)
|