diff options
author | Sam Clegg <sbc@chromium.org> | 2022-04-14 07:58:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 00:58:11 -0700 |
commit | 67c7490aea420a98bd90005cffd7544b804530a0 (patch) | |
tree | d920ff346577d01891263d2e8ba672af901d923a /wasm2c | |
parent | 39022f8cd717ec5f219c56f4ebd07f016c457afc (diff) | |
download | wabt-67c7490aea420a98bd90005cffd7544b804530a0.tar.gz wabt-67c7490aea420a98bd90005cffd7544b804530a0.tar.bz2 wabt-67c7490aea420a98bd90005cffd7544b804530a0.zip |
Remove signature mangling from wasm2c output (#1896)
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
Diffstat (limited to 'wasm2c')
-rw-r--r-- | wasm2c/README.md | 17 | ||||
-rw-r--r-- | wasm2c/examples/fac/fac.c | 4 | ||||
-rw-r--r-- | wasm2c/examples/fac/fac.h | 2 | ||||
-rw-r--r-- | wasm2c/examples/fac/main.c | 4 | ||||
-rw-r--r-- | wasm2c/examples/rot13/main.c | 14 |
5 files changed, 20 insertions, 21 deletions
diff --git a/wasm2c/README.md b/wasm2c/README.md index 3e335c74..b68fe57a 100644 --- a/wasm2c/README.md +++ b/wasm2c/README.md @@ -48,21 +48,21 @@ files. To actually use our fac module, we'll use create a new file, `main.c`, that include `fac.h`, initializes the module, and calls `fac`. -`wasm2c` generates a few symbols for us, `init` and `Z_facZ_ii`. `init` -initializes the module, and `Z_facZ_ii` is our exported `fac` function, but +`wasm2c` generates a few symbols for us, `init` and `Z_fac`. `init` +initializes the module, and `Z_fac` is our exported `fac` function, but [name-mangled](https://en.wikipedia.org/wiki/Name_mangling) to include the function signature. We can define `WASM_RT_MODULE_PREFIX` before including `fac.h` to generate these symbols with a prefix, in case we already have a symbol called `init` (or -even `Z_facZ_ii`!) Note that you'll have to compile `fac.c` with this macro +even `Z_fac`!) Note that you'll have to compile `fac.c` with this macro too, for this to work. ```c #include <stdio.h> #include <stdlib.h> -/* Uncomment this to define fac_init and fac_Z_facZ_ii instead. */ +/* Uncomment this to define fac_init and fac_Z_fac instead. */ /* #define WASM_RT_MODULE_PREFIX fac_ */ #include "fac.h" @@ -83,7 +83,7 @@ int main(int argc, char** argv) { init(); /* Call `fac`, using the mangled name. */ - u32 result = Z_facZ_ii(x); + u32 result = Z_fac(x); /* Print the result. */ printf("fac(%u) -> %u\n", x, result); @@ -138,7 +138,7 @@ extern "C" { extern void WASM_RT_ADD_PREFIX(init)(void); /* export: 'fac' */ -extern u32 (*WASM_RT_ADD_PREFIX(Z_facZ_ii))(u32); +extern u32 (*WASM_RT_ADD_PREFIX(Z_fac))(u32); #ifdef __cplusplus } #endif @@ -345,15 +345,14 @@ the module can be used: extern void WASM_RT_ADD_PREFIX(init)(void); /* export: 'fac' */ -extern u32 (*WASM_RT_ADD_PREFIX(Z_facZ_ii))(u32); +extern u32 (*WASM_RT_ADD_PREFIX(Z_fac))(u32); ``` All exported names use `WASM_RT_ADD_PREFIX` (as described above) to allow the symbols to placed in a namespace as decided by the embedder. All symbols are also mangled so they include the types of the function signature. -In our example, `Z_facZ_ii` is the mangling for a function named `fac` that -takes one `i32` parameter and returns one `i32` result. +In our example, `Z_fac` is the mangling for a function named `fac`. ## A quick look at `fac.c` diff --git a/wasm2c/examples/fac/fac.c b/wasm2c/examples/fac/fac.c index 945c9967..b307d089 100644 --- a/wasm2c/examples/fac/fac.c +++ b/wasm2c/examples/fac/fac.c @@ -332,11 +332,11 @@ static void init_table(void) { } /* export: 'fac' */ -u32 (*WASM_RT_ADD_PREFIX(Z_facZ_ii))(u32); +u32 (*WASM_RT_ADD_PREFIX(Z_fac))(u32); static void init_exports(void) { /* export: 'fac' */ - WASM_RT_ADD_PREFIX(Z_facZ_ii) = (&w2c_fac); + WASM_RT_ADD_PREFIX(Z_fac) = (&w2c_fac); } void WASM_RT_ADD_PREFIX(init)(void) { diff --git a/wasm2c/examples/fac/fac.h b/wasm2c/examples/fac/fac.h index 41c50d4d..9a6a9aba 100644 --- a/wasm2c/examples/fac/fac.h +++ b/wasm2c/examples/fac/fac.h @@ -35,7 +35,7 @@ typedef double f64; extern void WASM_RT_ADD_PREFIX(init)(void); /* export: 'fac' */ -extern u32 (*WASM_RT_ADD_PREFIX(Z_facZ_ii))(u32); +extern u32 (*WASM_RT_ADD_PREFIX(Z_fac))(u32); #ifdef __cplusplus } #endif diff --git a/wasm2c/examples/fac/main.c b/wasm2c/examples/fac/main.c index 55255b5d..fe79aa94 100644 --- a/wasm2c/examples/fac/main.c +++ b/wasm2c/examples/fac/main.c @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> -/* Uncomment this to define fac_init and fac_Z_facZ_ii instead. */ +/* Uncomment this to define fac_init and fac_Z_fac instead. */ /* #define WASM_RT_MODULE_PREFIX fac_ */ #include "fac.h" @@ -22,7 +22,7 @@ int main(int argc, char** argv) { init(); /* Call `fac`, using the mangled name. */ - u32 result = Z_facZ_ii(x); + u32 result = Z_fac(x); /* Print the result. */ printf("fac(%u) -> %u\n", x, result); diff --git a/wasm2c/examples/rot13/main.c b/wasm2c/examples/rot13/main.c index 19ec799e..c5ba0e9d 100644 --- a/wasm2c/examples/rot13/main.c +++ b/wasm2c/examples/rot13/main.c @@ -17,15 +17,15 @@ #include <stdio.h> #include <stdlib.h> -/* Uncomment this to define rot13_init rot13_Z_rot13Z_vv instead. */ +/* Uncomment this to define rot13_init rot13_Z_rot13 instead. */ /* #define WASM_RT_MODULE_PREFIX rot13_ */ #include "rot13.h" /* Define the imports as declared in rot13.h. */ wasm_rt_memory_t (*Z_hostZ_mem); -u32 (*Z_hostZ_fill_bufZ_iii)(u32, u32); -void (*Z_hostZ_buf_doneZ_vii)(u32, u32); +u32 (*Z_hostZ_fill_buf)(u32, u32); +void (*Z_hostZ_buf_done)(u32, u32); /* Define the implementations of the imports. */ static wasm_rt_memory_t s_memory; @@ -49,10 +49,10 @@ int main(int argc, char** argv) { /* Provide the imports expected by the module: "host.mem", "host.fill_buf" * and "host.buf_done". Their mangled names are `Z_hostZ_mem`, - * `Z_hostZ_fill_bufZ_iii` and `Z_hostZ_buf_doneZ_vii`. */ + * `Z_hostZ_fill_buf` and `Z_hostZ_buf_done`. */ Z_hostZ_mem = &s_memory; - Z_hostZ_fill_bufZ_iii = &fill_buf; - Z_hostZ_buf_doneZ_vii = &buf_done; + Z_hostZ_fill_buf = &fill_buf; + Z_hostZ_buf_done = &buf_done; /* Call `rot13` on each argument, using the mangled name. */ while (argc > 1) { @@ -60,7 +60,7 @@ int main(int argc, char** argv) { argc--; argv++; s_input = argv[0]; - Z_rot13Z_vv(); + Z_rot13(); } /* Free the Wasm runtime state. */ |