diff options
Diffstat (limited to 'wasm2c/examples/fac/fac.c')
-rw-r--r-- | wasm2c/examples/fac/fac.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/wasm2c/examples/fac/fac.c b/wasm2c/examples/fac/fac.c index f6d6d0de..33151cdd 100644 --- a/wasm2c/examples/fac/fac.c +++ b/wasm2c/examples/fac/fac.c @@ -39,11 +39,16 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a, return (a == b) || LIKELY(a && b && !memcmp(a, b, 32)); } -#define CALL_INDIRECT(table, t, ft, x, ...) \ +#define CHECK_CALL_INDIRECT(table, ft, x) \ (LIKELY((x) < table.size && table.data[x].func && \ func_types_eq(ft, table.data[x].func_type)) || \ - TRAP(CALL_INDIRECT), \ - ((t)table.data[x].func)(__VA_ARGS__)) + TRAP(CALL_INDIRECT)) + +#define DO_CALL_INDIRECT(table, t, x, ...) ((t)table.data[x].func)(__VA_ARGS__) + +#define CALL_INDIRECT(table, t, ft, x, ...) \ + (CHECK_CALL_INDIRECT(table, ft, x), \ + DO_CALL_INDIRECT(table, t, x, __VA_ARGS__)) #ifdef SUPPORT_MEMORY64 #define RANGE_CHECK(mem, offset, len) \ @@ -522,6 +527,7 @@ typedef struct { enum { RefFunc, RefNull, GlobalGet } expr_type; wasm_rt_func_type_t type; wasm_rt_function_ptr_t func; + wasm_rt_tailcallee_t func_tailcallee; size_t module_offset; } wasm_elem_segment_expr_t; @@ -542,7 +548,7 @@ static inline void funcref_table_init(wasm_rt_funcref_table_t* dest, switch (src_expr->expr_type) { case RefFunc: *dest_val = (wasm_rt_funcref_t){ - src_expr->type, src_expr->func, + src_expr->type, src_expr->func, src_expr->func_tailcallee, (char*)module_instance + src_expr->module_offset}; break; case RefNull: @@ -633,6 +639,24 @@ DEFINE_TABLE_FILL(externref) #define FUNC_TYPE_T(x) static const char x[] #endif +#if (__STDC_VERSION__ < 201112L) && !defined(static_assert) +#define static_assert(X) \ + extern int(*assertion(void))[!!sizeof(struct { int x : (X) ? 2 : -1; })]; +#endif + +#ifdef _MSC_VER +#define WEAK_FUNC_DECL(func, fallback) \ + __pragma(comment(linker, "/alternatename:" #func "=" #fallback)) \ + \ + void \ + fallback(void** instance_ptr, void* tail_call_stack, \ + wasm_rt_tailcallee_t* next) +#else +#define WEAK_FUNC_DECL(func, fallback) \ + __attribute__((weak)) void func(void** instance_ptr, void* tail_call_stack, \ + wasm_rt_tailcallee_t* next) +#endif + static u32 w2c_fac_fac_0(w2c_fac*, u32); 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"; |