wasm.c (1622B)
1 /* Public wasm host-import API surface. 2 * 3 * The setter/getter stash a borrowed table on the compiler. The actual bind 4 * (reading module-emitted import metadata and writing function pointers 5 * into instance slots) lives in lang/wasm/host_imports.c so the wasm 6 * frontend owns the metadata wire format. */ 7 8 #include <kit/wasm.h> 9 10 #include "core/core.h" 11 12 KIT_API void kit_wasm_set_host_imports(KitCompiler* c, 13 const KitWasmHostImport* imports, 14 size_t nimports, 15 KitWasmResolveFn resolve, void* user) { 16 if (!c) return; 17 c->wasm_host_imports = imports; 18 c->wasm_host_nimports = nimports; 19 /* Function-pointer / void* conversion is implementation-defined in C 20 * but accepted by POSIX hosts kit targets. Stash through a void* so 21 * we don't pull the public type into the internal header. */ 22 c->wasm_host_resolve = (void*)resolve; 23 c->wasm_host_user = user; 24 } 25 26 KIT_API void kit_wasm_get_host_imports(KitCompiler* c, 27 const KitWasmHostImport** imports_out, 28 size_t* nimports_out, 29 KitWasmResolveFn* resolve_out, 30 void** user_out) { 31 if (imports_out) 32 *imports_out = c ? (const KitWasmHostImport*)c->wasm_host_imports : NULL; 33 if (nimports_out) *nimports_out = c ? c->wasm_host_nimports : 0; 34 if (resolve_out) 35 *resolve_out = c ? (KitWasmResolveFn)c->wasm_host_resolve : NULL; 36 if (user_out) *user_out = c ? c->wasm_host_user : NULL; 37 }