summaryrefslogtreecommitdiff
path: root/src/template/wasm2c.declarations.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/template/wasm2c.declarations.c')
-rw-r--r--src/template/wasm2c.declarations.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/template/wasm2c.declarations.c b/src/template/wasm2c.declarations.c
index a0a26dff..c0a44707 100644
--- a/src/template/wasm2c.declarations.c
+++ b/src/template/wasm2c.declarations.c
@@ -20,11 +20,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) \
@@ -503,6 +508,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;
@@ -523,7 +529,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:
@@ -613,3 +619,21 @@ DEFINE_TABLE_FILL(externref)
#define FUNC_TYPE_EXTERN_T(x) const char x[]
#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