summaryrefslogtreecommitdiff
path: root/wasm2c/wasm-rt.h
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-03-10 02:29:36 +0000
committerGitHub <noreply@github.com>2022-03-09 18:29:36 -0800
commit6a89e3f74560eb8f0396c24ce625de0023cb46b2 (patch)
tree163f824574bbd03d85f9bc4a17ce1886fd7936a4 /wasm2c/wasm-rt.h
parentda9f07ce054c7af5061279c3d237fd64d63d9f9b (diff)
downloadwabt-6a89e3f74560eb8f0396c24ce625de0023cb46b2.tar.gz
wabt-6a89e3f74560eb8f0396c24ce625de0023cb46b2.tar.bz2
wabt-6a89e3f74560eb8f0396c24ce625de0023cb46b2.zip
Add windows implementation of wasm2c runtime (#1843)
All tests are now passing with cl.exe under x64. With x86 there are some test failure that I believe relate the use of the x87 registers to pass floating point numbers. I suggest we look into fixing those as a followup. Split out from #1833
Diffstat (limited to 'wasm2c/wasm-rt.h')
-rw-r--r--wasm2c/wasm-rt.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h
index 639c2406..d3c25194 100644
--- a/wasm2c/wasm-rt.h
+++ b/wasm2c/wasm-rt.h
@@ -17,12 +17,32 @@
#ifndef WASM_RT_H_
#define WASM_RT_H_
+#include <stdbool.h>
#include <stdint.h>
+#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
+#ifndef __has_builtin
+#define __has_builtin(x) 0 // Compatibility with non-clang compilers.
+#endif
+
+#if __has_builtin(__builtin_expect)
+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
+#define LIKELY(x) __builtin_expect(!!(x), 1)
+#else
+#define UNLIKELY(x) (x)
+#define LIKELY(x) (x)
+#endif
+
+#if __has_builtin(__builtin_memcpy)
+#define wasm_rt_memcpy __builtin_memcpy
+#else
+#define wasm_rt_memcpy memcpy
+#endif
+
/** Maximum stack depth before trapping. This can be configured by defining
* this symbol before including wasm-rt when building the generated c files,
* for example:
@@ -68,6 +88,12 @@ extern "C" {
#endif
+#if defined(_MSC_VER)
+#define WASM_RT_NO_RETURN __declspec(noreturn)
+#else
+#define WASM_RT_NO_RETURN __attribute__((noreturn))
+#endif
+
/** Reason a trap occurred. Provide this to `wasm_rt_trap`. */
typedef enum {
WASM_RT_TRAP_NONE, /** No error. */
@@ -128,7 +154,7 @@ typedef struct {
* The result of `wasm_rt_try` will be the provided trap reason.
*
* This is typically called by the generated code, and not the embedder. */
-extern void wasm_rt_trap(wasm_rt_trap_t) __attribute__((noreturn));
+WASM_RT_NO_RETURN void wasm_rt_trap(wasm_rt_trap_t);
/**
* Return a human readable error string based on a trap type.
@@ -199,6 +225,22 @@ extern void wasm_rt_allocate_table(wasm_rt_table_t*,
/** Current call stack depth. */
extern uint32_t wasm_rt_call_stack_depth;
+#ifdef _WIN32
+float wasm_rt_truncf(float x);
+double wasm_rt_trunc(double x);
+float wasm_rt_nearbyintf(float x);
+double wasm_rt_nearbyint(double x);
+float wasm_rt_fabsf(float x);
+double wasm_rt_fabs(double x);
+#else
+#define wasm_rt_truncf(x) truncf(x)
+#define wasm_rt_trunc(x) trunc(x)
+#define wasm_rt_nearbyintf(x) nearbyintf(x)
+#define wasm_rt_nearbyint(x) nearbyint(x)
+#define wasm_rt_fabsf(x) fabsf(x)
+#define wasm_rt_fabs(x) fabs(x)
+#endif
+
#ifdef __cplusplus
}
#endif