diff options
author | Keith Winstein <keithw@cs.stanford.edu> | 2023-02-23 13:45:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-23 21:45:08 +0000 |
commit | 046451f9091083148f810c5932543fb805b17f4e (patch) | |
tree | 7d45728b69612ab82186c1c5d8ee701e1e4ffc73 /wasm2c | |
parent | 4bf38aaefa33bcf89a8e707b406c49090c5a00e3 (diff) | |
download | wabt-046451f9091083148f810c5932543fb805b17f4e.tar.gz wabt-046451f9091083148f810c5932543fb805b17f4e.tar.bz2 wabt-046451f9091083148f810c5932543fb805b17f4e.zip |
wasm2c: prettify/change name mangling (#2142)
* 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.
Diffstat (limited to 'wasm2c')
-rw-r--r-- | wasm2c/README.md | 142 | ||||
-rw-r--r-- | wasm2c/examples/callback/callback.wat | 2 | ||||
-rw-r--r-- | wasm2c/examples/callback/main.c | 17 | ||||
-rw-r--r-- | wasm2c/examples/fac/fac.c | 20 | ||||
-rw-r--r-- | wasm2c/examples/fac/fac.h | 12 | ||||
-rw-r--r-- | wasm2c/examples/fac/main.c | 8 | ||||
-rw-r--r-- | wasm2c/examples/rot13/main.c | 48 |
7 files changed, 112 insertions, 137 deletions
diff --git a/wasm2c/README.md b/wasm2c/README.md index 80a86952..cdc4f09e 100644 --- a/wasm2c/README.md +++ b/wasm2c/README.md @@ -49,19 +49,17 @@ 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 C symbols based on the `fac.wasm` module: `Z_fac_instantiate` -and `Z_facZ_fac`. The first constructs an instance of the module, and the second is the -exported `fac` function. - -All the exported symbols shared a common prefix (`Z_fac`) which, by default, is +`wasm2c` generates a few C symbols based on the `fac.wasm` module. +The first is `w2c_fac`, a type that represents an instance of the +`fac` module. `wasm2c` generates functions that construct and free a +`w2c_fac` instance: `wasm2c_fac_instantiate` and +`wasm2c_fac_free`. Finally, `wasm2c` generates the exported `fac` +function itself (`w2c_fac_fac`), which acts on a `w2c_fac` instance. + +All the exported symbols shared a common module ID (`fac`) which, by default, is based on the name section in the module or the name of input file. This prefix can be overridden using the `-n/--module-name` command line flag. -In addition to parameters defined in `fac.wat`, `Z_fac_instantiate` and `Z_facZ_fac` -take in a pointer to a `Z_fac_instance_t`. The structure is used to -store the context information of the module instance, and `main.c` is responsible -for providing it. - ```c #include <stdio.h> #include <stdlib.h> @@ -70,8 +68,10 @@ for providing it. int main(int argc, char** argv) { /* Make sure there is at least one command-line argument. */ - if (argc < 2) + if (argc < 2) { + printf("Invalid argument. Expected '%s NUMBER'\n", argv[0]); return 1; + } /* Convert the argument from a string to an int. We'll implicitly cast the int to a `u32`, which is what `fac` expects. */ @@ -81,19 +81,19 @@ int main(int argc, char** argv) { wasm_rt_init(); /* Declare an instance of the `fac` module. */ - Z_fac_instance_t instance; + w2c_fac fac; /* Construct the module instance. */ - Z_fac_instantiate(&instance); + wasm2c_fac_instantiate(&fac); /* Call `fac`, using the mangled name. */ - u32 result = Z_facZ_fac(&instance, x); + u32 result = w2c_fac_fac(&fac, x); /* Print the result. */ printf("fac(%u) -> %u\n", x, result); /* Free the fac module. */ - Z_fac_free(&instance); + wasm2c_fac_free(&fac); /* Free the Wasm runtime state. */ wasm_rt_free(); @@ -143,6 +143,7 @@ You can take a look at the all of these files in The generated header file looks something like this: ```c +/* Automatically generated by wasm2c */ #ifndef FAC_H_GENERATED_ #define FAC_H_GENERATED_ @@ -162,15 +163,16 @@ The generated header file looks something like this: extern "C" { #endif -typedef struct Z_fac_instance_t { +typedef struct w2c_fac { char dummy_member; -} Z_fac_instance_t; +} w2c_fac; -void Z_fac_instantiate(Z_fac_instance_t*); -void Z_fac_free(Z_fac_instance_t*); +void wasm2c_fac_instantiate(w2c_fac*); +void wasm2c_fac_free(w2c_fac*); +wasm_rt_func_type_t wasm2c_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...); /* export: 'fac' */ -u32 Z_facZ_fac(Z_fac_instance_t*, u32); +u32 w2c_fac_fac(w2c_fac*, u32); #ifdef __cplusplus } @@ -382,10 +384,10 @@ of `fac` is essentially empty), and the exported symbols provided by the module. In our example, the only function we exported was `fac`. -`Z_fac_instantiate(Z_fac_instance_t*)` creates an instance of +`wasm2c_fac_instantiate(w2c_fac*)` creates an instance of the module and must be called before the module instance can be -used. `Z_fac_free(Z_fac_instance_t*)` frees the instance. -`Z_fac_get_func_type` can be used to look up a function type ID +used. `wasm2c_fac_free(w2c_fac*)` frees the instance. +`wasm2c_fac_get_func_type` can be used to look up a function type ID at runtime. It is a variadic function where the first two arguments give the number of parameters and results, and the following arguments are the types from the wasm_rt_type_t enum described above. The @@ -393,16 +395,16 @@ are the types from the wasm_rt_type_t enum described above. The a WebAssembly module dynamically at runtime. ```c -typedef struct Z_fac_instance_t { +typedef struct w2c_fac { char dummy_member; -} Z_fac_instance_t; +} w2c_fac; -void Z_fac_instantiate(Z_fac_instance_t*); -void Z_fac_free(Z_fac_instance_t*); -wasm_rt_func_type_t Z_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...); +void wasm2c_fac_instantiate(w2c_fac*); +void wasm2c_fac_free(w2c_fac*); +wasm_rt_func_type_t wasm2c_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...); /* export: 'fac' */ -u32 Z_facZ_fac(Z_fac_instance_t*, u32); +u32 w2c_fac_fac(w2c_fac*, u32); ``` ## Handling other kinds of imports and exports of modules @@ -427,14 +429,15 @@ then `wasm2c` would declare the following function in the header: ```c /* export: 'mem' */ -extern wasm_rt_memory_t* Z_facZ_mem(Z_fac_instance_t*); +wasm_rt_memory_t* w2c_fac_mem(w2c_fac* instance); + ``` which would be defined as: ```c /* export: 'mem' */ -wasm_rt_memory_t* Z_fac_Z_mem(Z_fac_instance_t* instance) { - return &instance->w2c_M0; +wasm_rt_memory_t* w2c_fac_mem(w2c_fac* instance) { + return &instance->w2c_mem; } ``` @@ -455,7 +458,7 @@ module doesn't use any globals, memory or tables. The most interesting part is the definition of the function `fac`: ```c -static u32 w2c_fac(Z_fac_instance_t* instance, u32 w2c_p0) { +static u32 w2c_fac_fac_0(w2c_fac* instance, u32 w2c_p0) { FUNC_PROLOGUE; u32 w2c_i0, w2c_i1, w2c_i2; w2c_i0 = w2c_p0; @@ -468,7 +471,7 @@ static u32 w2c_fac(Z_fac_instance_t* instance, u32 w2c_p0) { w2c_i1 = w2c_p0; w2c_i2 = 1u; w2c_i1 -= w2c_i2; - w2c_i1 = w2c_fac(instance, w2c_i1); + w2c_i1 = w2c_fac_fac_0(instance, w2c_i1); w2c_i0 *= w2c_i1; } FUNC_EPILOGUE; @@ -546,62 +549,45 @@ in the same address space. #include "rot13.h" /* Define structure to hold the imports */ -struct Z_host_instance_t { +typedef struct w2c_host { wasm_rt_memory_t memory; char* input; -}; +} w2c_host; /* Accessor to access the memory member of the host */ -wasm_rt_memory_t* Z_hostZ_mem(struct Z_host_instance_t* instance) { +wasm_rt_memory_t* w2c_host_mem(w2c_host* instance) { return &instance->memory; } -/* Declare the implementations of the imports. */ -static u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size); -static void buf_done(struct Z_host_instance_t* instance, u32 ptr, u32 size); - -/* Define host-provided functions under the names imported by the `rot13` instance */ -u32 Z_hostZ_fill_buf(struct Z_host_instance_t* instance, - u32 ptr, - u32 size) { - return fill_buf(instance, ptr, size); -} - -void Z_hostZ_buf_done(struct Z_host_instance_t* instance, - u32 ptr, - u32 size) { - return buf_done(instance, ptr, size); -} - int main(int argc, char** argv) { + /* Make sure there is at least one command-line argument. */ + if (argc < 2) { + printf("Invalid argument. Expected '%s WORD...'\n", argv[0]); + return 1; + } /* Initialize the Wasm runtime. */ wasm_rt_init(); - /* Declare two instances of the `rot13` module. */ - Z_rot13_instance_t rot13_instance_1; - Z_rot13_instance_t rot13_instance_2; - - /* Create two `host` module instances to store the memory and current string */ - struct Z_host_instance_t host_instance_1; - struct Z_host_instance_t host_instance_2; - /* Allocate 1 page of wasm memory (64KiB). */ - wasm_rt_allocate_memory(&host_instance_1.memory, 1, 1, false); - wasm_rt_allocate_memory(&host_instance_2.memory, 1, 1, false); + /* Create two `host` instances to store the memory and current string */ + w2c_host host_1, host_2; + wasm_rt_allocate_memory(&host_1.memory, 1, 1, false); + wasm_rt_allocate_memory(&host_2.memory, 1, 1, false); - /* Construct the module instances */ - Z_rot13_instantiate(&rot13_instance_1, &host_instance_1); - Z_rot13_instantiate(&rot13_instance_2, &host_instance_2); + /* Construct the `rot13` module instances */ + w2c_rot13 rot13_1, rot13_2; + wasm2c_rot13_instantiate(&rot13_1, &host_1); + wasm2c_rot13_instantiate(&rot13_2, &host_2); - /* Call `rot13` on first two argument, using the mangled name. */ + /* Call `rot13` on the first two arguments. */ assert(argc > 2); - host_instance_1.input = argv[1]; - Z_rot13Z_rot13(&rot13_instance_1); - host_instance_2.input = argv[2]; - Z_rot13Z_rot13(&rot13_instance_2); + host_1.input = argv[1]; + w2c_rot13_rot13(&rot13_1); + host_2.input = argv[2]; + w2c_rot13_rot13(&rot13_2); - /* Free the rot13 modules. */ - Z_rot13_free(&rot13_instance_1); - Z_rot13_free(&rot13_instance_2); + /* Free the rot13 instances. */ + wasm2c_rot13_free(&rot13_1); + wasm2c_rot13_free(&rot13_2); /* Free the Wasm runtime state. */ wasm_rt_free(); @@ -612,12 +598,13 @@ int main(int argc, char** argv) { /* Fill the wasm buffer with the input to be rot13'd. * * params: + * instance: An instance of the w2c_host structure * ptr: The wasm memory address of the buffer to fill data. * size: The size of the buffer in wasm memory. * result: * The number of bytes filled into the buffer. (Must be <= size). */ -u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size) { +u32 w2c_host_fill_buf(w2c_host* instance, u32 ptr, u32 size) { for (size_t i = 0; i < size; ++i) { if (instance->input[i] == 0) { return i; @@ -630,10 +617,11 @@ u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size) { /* Called when the wasm buffer has been rot13'd. * * params: + * w2c_host: An instance of the w2c_host structure * ptr: The wasm memory address of the buffer. * size: The size of the buffer in wasm memory. */ -void buf_done(struct Z_host_instance_t* instance, u32 ptr, u32 size) { +void w2c_host_buf_done(w2c_host* instance, u32 ptr, u32 size) { /* The output buffer is not necessarily null-terminated, so use the %*.s * printf format to limit the number of characters printed. */ printf("%s -> %.*s\n", instance->input, (int)size, &instance->memory.data[ptr]); diff --git a/wasm2c/examples/callback/callback.wat b/wasm2c/examples/callback/callback.wat index 6a8ab233..9786209a 100644 --- a/wasm2c/examples/callback/callback.wat +++ b/wasm2c/examples/callback/callback.wat @@ -1,7 +1,7 @@ ;; Module demonstrating use of a host-installed callback function. ;; The type of the callback function. The type ID can be looked up outside the module by calling -;; Z_[modname]_get_func_type(1, 0, WASM_RT_I32) (indicating 1 param, 0 results, param type is i32). +;; wasm2c_[modname]_get_func_type(1, 0, WASM_RT_I32) (indicating 1 param, 0 results, param type is i32). (type $print_type (func (param i32))) ;; An indirect function table to hold the callback function diff --git a/wasm2c/examples/callback/main.c b/wasm2c/examples/callback/main.c index b0b37d46..8c6f9db0 100644 --- a/wasm2c/examples/callback/main.c +++ b/wasm2c/examples/callback/main.c @@ -6,8 +6,8 @@ * The callback function. Prints the null-terminated string at the given * location in the instance's exported memory. */ -void print(Z_callback_instance_t* instance, uint32_t ptr) { - puts(Z_callbackZ_memory(instance)->data + ptr); +void print(w2c_callback* instance, uint32_t ptr) { + puts(w2c_callback_memory(instance)->data + ptr); } int main(int argc, char** argv) { @@ -15,8 +15,8 @@ int main(int argc, char** argv) { wasm_rt_init(); /* Instantiate the callback module. */ - Z_callback_instance_t inst; - Z_callback_instantiate(&inst); + w2c_callback inst; + wasm2c_callback_instantiate(&inst); /* * Call the module's "set_print_function" function, which takes a funcref to @@ -24,15 +24,16 @@ int main(int argc, char** argv) { * looked up with "Z_callback_get_func_type"), a pointer to the function, and * a module instance pointer that will be passed to the function when called. */ - wasm_rt_func_type_t fn_type = Z_callback_get_func_type(1, 0, WASM_RT_I32); + wasm_rt_func_type_t fn_type = + wasm2c_callback_get_func_type(1, 0, WASM_RT_I32); wasm_rt_funcref_t fn_ref = {fn_type, (wasm_rt_function_ptr_t)print, &inst}; - Z_callbackZ_set_print_function(&inst, fn_ref); + w2c_callback_set_print_function(&inst, fn_ref); /* "say_hello" uses the previously installed callback. */ - Z_callbackZ_say_hello(&inst); + w2c_callback_say_hello(&inst); /* Free the module instance and the Wasm runtime state. */ - Z_callback_free(&inst); + wasm2c_callback_free(&inst); wasm_rt_free(); return 0; diff --git a/wasm2c/examples/fac/fac.c b/wasm2c/examples/fac/fac.c index c00a60d0..40cb43b2 100644 --- a/wasm2c/examples/fac/fac.c +++ b/wasm2c/examples/fac/fac.c @@ -724,11 +724,11 @@ DEFINE_TABLE_FILL(externref) #define FUNC_TYPE_T(x) static const char x[] #endif -FUNC_TYPE_T(w2c_t0) = "\x07\x80\x96\x7a\x42\xf7\x3e\xe6\x70\x5c\x2f\xac\x83\xf5\x67\xd2\xa2\xa0\x69\x41\x5f\xf8\xe7\x96\x7f\x23\xab\x00\x03\x5f\x4a\x3c"; +FUNC_TYPE_T(w2c_fac_t0) = "\x07\x80\x96\x7a\x42\xf7\x3e\xe6\x70\x5c\x2f\xac\x83\xf5\x67\xd2\xa2\xa0\x69\x41\x5f\xf8\xe7\x96\x7f\x23\xab\x00\x03\x5f\x4a\x3c"; -static u32 w2c_fac(Z_fac_instance_t*, u32); +static u32 w2c_fac_fac_0(w2c_fac*, u32); -static u32 w2c_fac(Z_fac_instance_t* instance, u32 w2c_p0) { +static u32 w2c_fac_fac_0(w2c_fac* instance, u32 w2c_p0) { FUNC_PROLOGUE; u32 w2c_i0, w2c_i1, w2c_i2; w2c_i0 = w2c_p0; @@ -741,7 +741,7 @@ static u32 w2c_fac(Z_fac_instance_t* instance, u32 w2c_p0) { w2c_i1 = w2c_p0; w2c_i2 = 1u; w2c_i1 -= w2c_i2; - w2c_i1 = w2c_fac(instance, w2c_i1); + w2c_i1 = w2c_fac_fac_0(instance, w2c_i1); w2c_i0 *= w2c_i1; } FUNC_EPILOGUE; @@ -749,25 +749,25 @@ static u32 w2c_fac(Z_fac_instance_t* instance, u32 w2c_p0) { } /* export: 'fac' */ -u32 Z_facZ_fac(Z_fac_instance_t* instance, u32 w2c_p0) { - return w2c_fac(instance, w2c_p0); +u32 w2c_fac_fac(w2c_fac* instance, u32 w2c_p0) { + return w2c_fac_fac_0(instance, w2c_p0); } -void Z_fac_instantiate(Z_fac_instance_t* instance) { +void wasm2c_fac_instantiate(w2c_fac* instance) { assert(wasm_rt_is_initialized()); } -void Z_fac_free(Z_fac_instance_t* instance) { +void wasm2c_fac_free(w2c_fac* instance) { } -wasm_rt_func_type_t Z_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...) { +wasm_rt_func_type_t wasm2c_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...) { va_list args; if (param_count == 1 && result_count == 1) { va_start(args, result_count); if (true && va_arg(args, wasm_rt_type_t) == WASM_RT_I32 && va_arg(args, wasm_rt_type_t) == WASM_RT_I32) { va_end(args); - return w2c_t0; + return w2c_fac_t0; } va_end(args); } diff --git a/wasm2c/examples/fac/fac.h b/wasm2c/examples/fac/fac.h index 1354411a..5450fe42 100644 --- a/wasm2c/examples/fac/fac.h +++ b/wasm2c/examples/fac/fac.h @@ -34,16 +34,16 @@ typedef simde_v128_t v128; extern "C" { #endif -typedef struct Z_fac_instance_t { +typedef struct w2c_fac { char dummy_member; -} Z_fac_instance_t; +} w2c_fac; -void Z_fac_instantiate(Z_fac_instance_t*); -void Z_fac_free(Z_fac_instance_t*); -wasm_rt_func_type_t Z_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...); +void wasm2c_fac_instantiate(w2c_fac*); +void wasm2c_fac_free(w2c_fac*); +wasm_rt_func_type_t wasm2c_fac_get_func_type(uint32_t param_count, uint32_t result_count, ...); /* export: 'fac' */ -u32 Z_facZ_fac(Z_fac_instance_t*, u32); +u32 w2c_fac_fac(w2c_fac*, u32); #ifdef __cplusplus } diff --git a/wasm2c/examples/fac/main.c b/wasm2c/examples/fac/main.c index 37593f6e..eb85376e 100644 --- a/wasm2c/examples/fac/main.c +++ b/wasm2c/examples/fac/main.c @@ -18,19 +18,19 @@ int main(int argc, char** argv) { wasm_rt_init(); /* Declare an instance of the `fac` module. */ - Z_fac_instance_t instance; + w2c_fac fac; /* Construct the module instance. */ - Z_fac_instantiate(&instance); + wasm2c_fac_instantiate(&fac); /* Call `fac`, using the mangled name. */ - u32 result = Z_facZ_fac(&instance, x); + u32 result = w2c_fac_fac(&fac, x); /* Print the result. */ printf("fac(%u) -> %u\n", x, result); /* Free the fac module. */ - Z_fac_free(&instance); + wasm2c_fac_free(&fac); /* Free the Wasm runtime state. */ wasm_rt_free(); diff --git a/wasm2c/examples/rot13/main.c b/wasm2c/examples/rot13/main.c index d6517f39..f0164fba 100644 --- a/wasm2c/examples/rot13/main.c +++ b/wasm2c/examples/rot13/main.c @@ -20,49 +20,33 @@ #include "rot13.h" /* Define structure to hold the imports */ -struct Z_host_instance_t { +struct w2c_host { wasm_rt_memory_t memory; char* input; }; /* Accessor to access the memory member of the host */ -wasm_rt_memory_t* Z_hostZ_mem(struct Z_host_instance_t* instance) { +wasm_rt_memory_t* w2c_host_mem(struct w2c_host* instance) { return &instance->memory; } -/* Declare the implementations of the imports. */ -static u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size); -static void buf_done(struct Z_host_instance_t* instance, u32 ptr, u32 size); - -/* Define host-provided functions under the names imported by the `rot13` - * instance */ -u32 Z_hostZ_fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size) { - return fill_buf(instance, ptr, size); -} - -void Z_hostZ_buf_done(struct Z_host_instance_t* instance, u32 ptr, u32 size) { - return buf_done(instance, ptr, size); -} - int main(int argc, char** argv) { /* Make sure there is at least one command-line argument. */ if (argc < 2) { - printf("Invalid argument. Expected '%s WORD'\n", argv[0]); + printf("Invalid argument. Expected '%s WORD...'\n", argv[0]); return 1; } /* Initialize the Wasm runtime. */ wasm_rt_init(); - /* Declare an instance of the `rot13` module. */ - Z_rot13_instance_t rot13_instance; - - /* Create a `host` module instance to store the memory and current string */ - struct Z_host_instance_t host_instance; - /* Allocate 1 page of wasm memory (64KiB). */ - wasm_rt_allocate_memory(&host_instance.memory, 1, 1, false); + /* Create a structure to store the memory and current string, allocating 1 + page of Wasm memory (64 KiB) that the rot13 module instance will import. */ + struct w2c_host host; + wasm_rt_allocate_memory(&host.memory, 1, 1, false); - /* Construct the module instance */ - Z_rot13_instantiate(&rot13_instance, &host_instance); + // Construct an instance of the `rot13` module, which imports from the host. + w2c_rot13 rot13; + wasm2c_rot13_instantiate(&rot13, &host); /* Call `rot13` on each argument. */ while (argc > 1) { @@ -70,12 +54,12 @@ int main(int argc, char** argv) { argc--; argv++; - host_instance.input = argv[0]; - Z_rot13Z_rot13(&rot13_instance); + host.input = argv[0]; + w2c_rot13_rot13(&rot13); } /* Free the rot13 module. */ - Z_rot13_free(&rot13_instance); + wasm2c_rot13_free(&rot13); /* Free the Wasm runtime state. */ wasm_rt_free(); @@ -86,12 +70,13 @@ int main(int argc, char** argv) { /* Fill the wasm buffer with the input to be rot13'd. * * params: + * instance: An instance of the w2c_host structure * ptr: The wasm memory address of the buffer to fill data. * size: The size of the buffer in wasm memory. * result: * The number of bytes filled into the buffer. (Must be <= size). */ -u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size) { +u32 w2c_host_fill_buf(struct w2c_host* instance, u32 ptr, u32 size) { for (size_t i = 0; i < size; ++i) { if (instance->input[i] == 0) { return i; @@ -104,10 +89,11 @@ u32 fill_buf(struct Z_host_instance_t* instance, u32 ptr, u32 size) { /* Called when the wasm buffer has been rot13'd. * * params: + * w2c_host: An instance of the w2c_host structure * ptr: The wasm memory address of the buffer. * size: The size of the buffer in wasm memory. */ -void buf_done(struct Z_host_instance_t* instance, u32 ptr, u32 size) { +void w2c_host_buf_done(struct w2c_host* instance, u32 ptr, u32 size) { /* The output buffer is not necessarily null-terminated, so use the %*.s * printf format to limit the number of characters printed. */ printf("%s -> %.*s\n", instance->input, (int)size, |