summaryrefslogtreecommitdiff
path: root/wasm2c/examples/rot13/main.c
Commit message (Collapse)AuthorAgeFilesLines
* wasm2c: prettify/change name mangling (#2142)Keith Winstein2023-02-231-31/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* wasm2c: serialize types at wasm2c-time (#2120)Keith Winstein2023-01-251-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Update wasm2c examples to reflect new wasm_rt_allocate_memory() parameter ↵Keith Winstein2023-01-221-1/+1
| | | | (#2133)
* wasm2c examples print usage messages for missing arguments (#2028)Shravan Narayan2022-10-311-0/+5
|
* wasm2c: support for module instancing (#1814)Yuhan Deng2022-09-161-29/+43
| | | Co-authored-by: Angela Montemayor <amontema@cs.stanford.edu>
* wasm2c: export free() function to free module state (#1901)Keith Winstein2022-04-141-0/+3
| | | | | | 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.
* wasm2c: Always use a module prefix and set one by default (#1897)Sam Clegg2022-04-141-7/+3
| | | | | | | | | | | | 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.
* Remove signature mangling from wasm2c output (#1896)Sam Clegg2022-04-141-7/+7
| | | | | | | | | | | 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
* wasm2c: use signal handler to detect stack exhaustion (#1875)Keith Winstein2022-04-041-0/+7
| | | | | | 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.)
* [wasm2c] Add rot13 example (#1384)Ben Smith2020-04-141-0/+93
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.)