forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWasmGlobalMacros.h
More file actions
45 lines (39 loc) · 1.42 KB
/
Copy pathWasmGlobalMacros.h
File metadata and controls
45 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _CJavaScriptKit_WasmGlobalMacros_h
#define _CJavaScriptKit_WasmGlobalMacros_h
// Define an inline getter for a Wasm global
#define WASM_GLOBAL_DEFINE_INLINE_GETTER(name, core_type, c_type) \
static inline c_type name##_get(void) { \
c_type val; \
__asm__( \
".globaltype " #name ", " #core_type "\n" \
"global.get " #name "\n" \
"local.set %0\n" \
: "=r"(val)); \
return val; \
}
// Define an inline setter for a Wasm global
#define WASM_GLOBAL_DEFINE_INLINE_SETTER(name, core_type, c_type) \
static inline void name##_set(c_type val) { \
__asm__( \
".globaltype " #name ", " #core_type "\n" \
"local.get %0\n" \
"global.set " #name "\n" \
: : "r"(val)); \
}
// Define an inline getter and setter for a Wasm global
#define WASM_GLOBAL_DEFINE_INLINE_ACCESSORS(name, core_type, c_type) \
WASM_GLOBAL_DEFINE_INLINE_GETTER(name, core_type, c_type) \
WASM_GLOBAL_DEFINE_INLINE_SETTER(name, core_type, c_type)
// Define a Wasm global storage
#define WASM_GLOBAL_DEFINE_STORAGE(name, core_type) \
__asm__( \
".globaltype " #name ", " #core_type "\n" \
".global " #name "\n" \
#name ":\n" \
);
// Define an export name for a Wasm value
#define WASM_EXPORT_NAME(name, export_name) \
__asm__( \
".export_name " #name ", " #export_name "\n" \
);
#endif