diff options
author | Keith Winstein <keithw@cs.stanford.edu> | 2023-09-06 15:54:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 22:54:12 +0000 |
commit | ab05e50ec44506dc81220a21fb8f5e8d048772e0 (patch) | |
tree | 452bbeab86c82b531447e28037bf47c6e9e23520 /test/wasm2c/add.txt | |
parent | 9008bc8080a4adc703643ea67321dd7b6075fe76 (diff) | |
download | wabt-ab05e50ec44506dc81220a21fb8f5e8d048772e0.tar.gz wabt-ab05e50ec44506dc81220a21fb8f5e8d048772e0.tar.bz2 wabt-ab05e50ec44506dc81220a21fb8f5e8d048772e0.zip |
Share reading/validation code between elem exprs & other const exprs (#2288)
This continues the work from #1783 and reduces special handling of elem
exprs, by treating them the same as other const expressions (init
expressions).
Diffstat (limited to 'test/wasm2c/add.txt')
-rw-r--r-- | test/wasm2c/add.txt | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/test/wasm2c/add.txt b/test/wasm2c/add.txt index 783f443c..1d25c416 100644 --- a/test/wasm2c/add.txt +++ b/test/wasm2c/add.txt @@ -567,6 +567,7 @@ static inline void memory_init(wasm_rt_memory_t* dest, } typedef struct { + enum { RefFunc, RefNull, GlobalGet } expr_type; wasm_rt_func_type_t type; wasm_rt_function_ptr_t func; size_t module_offset; @@ -584,14 +585,26 @@ static inline void funcref_table_init(wasm_rt_funcref_table_t* dest, if (UNLIKELY(dest_addr + (uint64_t)n > dest->size)) TRAP(OOB); for (u32 i = 0; i < n; i++) { - const wasm_elem_segment_expr_t* src_expr = &src[src_addr + i]; - dest->data[dest_addr + i] = - (wasm_rt_funcref_t){src_expr->type, src_expr->func, - (char*)module_instance + src_expr->module_offset}; + const wasm_elem_segment_expr_t* const src_expr = &src[src_addr + i]; + wasm_rt_funcref_t* const dest_val = &(dest->data[dest_addr + i]); + switch (src_expr->expr_type) { + case RefFunc: + *dest_val = (wasm_rt_funcref_t){ + src_expr->type, src_expr->func, + (char*)module_instance + src_expr->module_offset}; + break; + case RefNull: + *dest_val = wasm_rt_funcref_null_value; + break; + case GlobalGet: + *dest_val = **(wasm_rt_funcref_t**)((char*)module_instance + + src_expr->module_offset); + break; + } } } -// Currently Wasm only supports initializing externref tables with ref.null. +// Currently wasm2c only supports initializing externref tables with ref.null. static inline void externref_table_init(wasm_rt_externref_table_t* dest, u32 src_size, u32 dest_addr, |