summaryrefslogtreecommitdiff
path: root/wasm2c/wasm-rt-impl.c
diff options
context:
space:
mode:
authorShravan Narayan <shravanrn@gmail.com>2024-01-31 15:40:01 -0600
committerShravan Narayan <shravanrn@gmail.com>2024-01-31 17:49:08 -0600
commit49950cbcb8e3729cd056f1f76ee4000dbcbe309f (patch)
treec6a1e2c10ebe527cc18a90c4d520867f2227bd2b /wasm2c/wasm-rt-impl.c
parentcfe0f5e7690c940c0c6ee27fa1e44791e5afee43 (diff)
downloadwabt-49950cbcb8e3729cd056f1f76ee4000dbcbe309f.tar.gz
wabt-49950cbcb8e3729cd056f1f76ee4000dbcbe309f.tar.bz2
wabt-49950cbcb8e3729cd056f1f76ee4000dbcbe309f.zip
wasm2c: move table ops to an include file
Diffstat (limited to 'wasm2c/wasm-rt-impl.c')
-rw-r--r--wasm2c/wasm-rt-impl.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 7c88499d..52a42e85 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -257,43 +257,15 @@ void wasm_rt_free_thread(void) {
#endif
}
-#define DEFINE_TABLE_OPS(type) \
- void wasm_rt_allocate_##type##_table(wasm_rt_##type##_table_t* table, \
- uint32_t elements, \
- uint32_t max_elements) { \
- table->size = elements; \
- table->max_size = max_elements; \
- table->data = calloc(table->size, sizeof(wasm_rt_##type##_t)); \
- } \
- void wasm_rt_free_##type##_table(wasm_rt_##type##_table_t* table) { \
- free(table->data); \
- } \
- uint32_t wasm_rt_grow_##type##_table(wasm_rt_##type##_table_t* table, \
- uint32_t delta, \
- wasm_rt_##type##_t init) { \
- uint32_t old_elems = table->size; \
- uint64_t new_elems = (uint64_t)table->size + delta; \
- if (new_elems == 0) { \
- return 0; \
- } \
- if ((new_elems < old_elems) || (new_elems > table->max_size)) { \
- return (uint32_t)-1; \
- } \
- void* new_data = \
- realloc(table->data, new_elems * sizeof(wasm_rt_##type##_t)); \
- if (!new_data) { \
- return (uint32_t)-1; \
- } \
- table->data = new_data; \
- table->size = new_elems; \
- for (uint32_t i = old_elems; i < new_elems; i++) { \
- table->data[i] = init; \
- } \
- return old_elems; \
- }
-
-DEFINE_TABLE_OPS(funcref)
-DEFINE_TABLE_OPS(externref)
+// Include table operations for funcref
+#define WASM_RT_TABLE_OPS_FUNCREF
+#include "wasm-rt-impl-tableops.inc"
+#undef WASM_RT_TABLE_OPS_FUNCREF
+
+// Include table operations for externref
+#define WASM_RT_TABLE_OPS_EXTERNREF
+#include "wasm-rt-impl-tableops.inc"
+#undef WASM_RT_TABLE_OPS_EXTERNREF
const char* wasm_rt_strerror(wasm_rt_trap_t trap) {
switch (trap) {