diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..d02d093f4cae737cd124744192e5a04ea2a7faf1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "njet"] + path = njet + url = https://gitee.com/njet-rd/njet.git diff --git a/README.md b/README.md index f4b0bae2d27908e93851404a3e43c6062967e000..2a770847705507607a81aa65e952af6c42b60de2 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,23 @@ # OpenNJet-WASM #### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +该程序是 OpenNJet 的 wasm 插件程序,支持动态引入 OpenNJet 程序中,通过使用 wasm 程序处理 http 请求 #### 软件架构 -软件架构说明 +实现思路 +1. 在 njet 启动时创建 wasm 运行时 +2. 在 http 请求过来的时候组合相关请求参数 +3. 使用组合好的参数调用 wasm 运行时中处理方法 +4. 集成了 wasmedge 在 njet 中 +5. 用户配置时可灵活指定 wasm 文件路径及处理方法名称 #### 安装教程 -1. xxxx -2. xxxx -3. xxxx +1. sh build.sh #### 使用说明 - -1. xxxx -2. xxxx -3. xxxx +无需特殊环境,和 njet 主程序相同即可 #### 参与贡献 @@ -27,13 +25,3 @@ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..8109f9cf1dbff0ef74b68cdde36ed4fdde618c1a --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +cp -r ./njet-http-wasm-module/ ./njet/modules/ +cp -r ./wasmedge/ ./njet/auto/lib/ + +grep -qxF ". auto/lib/wasmedge/conf" njet/auto/lib/conf || echo ". auto/lib/wasmedge/conf" >> njet/auto/lib/conf + +grep -qxF ". auto/lib/wasmedge/make" njet/auto/lib/make || echo ". auto/lib/wasmedge/make" >> njet/auto/lib/make + +grep -qxF "./modules/njet-http-wasm-module" njet/modules_dynamic || echo "./modules/njet-http-wasm-module" >> njet/modules_dynamic + +cd njet && sh build_cc.sh conf make \ No newline at end of file diff --git a/clean.sh b/clean.sh new file mode 100644 index 0000000000000000000000000000000000000000..a35e2e4137420f5b34ac128235ed99d833bb65e3 --- /dev/null +++ b/clean.sh @@ -0,0 +1,3 @@ +cd njet +git checkout . +sh build_cc.sh clean \ No newline at end of file diff --git a/njet b/njet new file mode 160000 index 0000000000000000000000000000000000000000..663012b684327b0f1eb99e2c19ade72266aafc65 --- /dev/null +++ b/njet @@ -0,0 +1 @@ +Subproject commit 663012b684327b0f1eb99e2c19ade72266aafc65 diff --git a/njet-http-wasm-module/config b/njet-http-wasm-module/config new file mode 100644 index 0000000000000000000000000000000000000000..9ccf10efbd25bfe4da8bf28b8d0430e821e120d5 --- /dev/null +++ b/njet-http-wasm-module/config @@ -0,0 +1,22 @@ +njt_addon_name=njt_http_wasm_module +njt_module_type=HTTP +njt_module_name=$njt_addon_name +njt_module_incs=" \ +$njt_addon_dir/include \ +" +njt_module_srcs=" \ + $njt_addon_dir/src/njt_http_wasm_module.c \ +" + +njt_module_libs="" #-lpthread + +have=NJT_HTTP_WASM_MODULE . auto/have +njt_module_incs="$njt_addon_dir/../../auto/lib/wasmedge/build/include/" +njt_module_libs="-L$njt_addon_dir/../../auto/lib/wasmedge/build/lib/ -lwasmedge" + +NJT_HTTP_WASM="YES" +. auto/module + + +# CORE_INCS="$CORE_INCS /root/.wasmedge/include/" +# CORE_LIBS="$CORE_LIBS -L/root/.wasmedge/lib/ -lwasmedge" \ No newline at end of file diff --git a/njet-http-wasm-module/src/njt_http_wasm_module.c b/njet-http-wasm-module/src/njt_http_wasm_module.c new file mode 100644 index 0000000000000000000000000000000000000000..12ec4381ab80fddd03d8eb7ea7c9e2e39abd0ee7 --- /dev/null +++ b/njet-http-wasm-module/src/njt_http_wasm_module.c @@ -0,0 +1,484 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "njt_http_api_register_module.h" +#include + +#include "njt_string.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef struct njt_http_wasm_main_conf_s +{ + njt_http_request_t **reqs; + njt_int_t size; +} njt_http_wasm_main_conf_t; + +typedef struct +{ + njt_http_request_t *req; + njt_int_t index; + njt_http_wasm_main_conf_t *dlmcf; +} njt_http_wasm_rpc_ctx_t; + +typedef struct njt_http_wasm_loc_conf_s +{ + njt_flag_t wasm_enable; + njt_str_t func_name; + njt_str_t plugin_path; +} njt_http_wasm_loc_conf_t; + + +static WasmEdge_VMContext *vm; +static WasmEdge_MemoryInstanceContext *memory; +static void +njt_http_wasm_read_data(njt_http_request_t *r); + +static njt_int_t +njt_http_wasm_handler(njt_http_request_t *r); + +static njt_int_t +njt_http_wasm_init_worker(njt_cycle_t *cycle); + +static void * +njt_http_wasm_create_loc_conf(njt_conf_t *cf); + +static char *njt_http_wasm_merge_loc_conf(njt_conf_t *cf, + void *parent, void *child); + +static void * +njt_http_wasm_create_main_conf(njt_conf_t *cf); + +static void njt_http_wasm_exit(njt_cycle_t *cycle); + +static njt_int_t +njt_http_wasm_init(njt_conf_t *cf); +static njt_int_t +load_wasm_instance(njt_http_wasm_loc_conf_t *conf, const char *path); + +static char * +njt_http_wasm_plugin(njt_conf_t *cf, njt_command_t *cmd, void *conf); + +uint32_t ptr_offset = 10240; + +static njt_command_t njt_http_wasm_commands[] = { + {njt_string("wasm_plugin"), + NJT_HTTP_MAIN_CONF | NJT_HTTP_SRV_CONF | NJT_HTTP_LOC_CONF | NJT_CONF_ANY, + njt_http_wasm_plugin, + NJT_HTTP_LOC_CONF_OFFSET, + offsetof(njt_http_wasm_loc_conf_t, wasm_enable), + NULL}, + {njt_string("wasm_func_name"), + NJT_HTTP_MAIN_CONF | NJT_HTTP_SRV_CONF | NJT_HTTP_LOC_CONF | NJT_CONF_ANY, + njt_conf_set_str_slot, + NJT_HTTP_LOC_CONF_OFFSET, + offsetof(njt_http_wasm_loc_conf_t, func_name), + NULL}, + {njt_string("wasm_plugin_path"), + NJT_HTTP_MAIN_CONF | NJT_HTTP_SRV_CONF | NJT_HTTP_LOC_CONF | NJT_CONF_ANY, + njt_conf_set_str_slot, + NJT_HTTP_LOC_CONF_OFFSET, + offsetof(njt_http_wasm_loc_conf_t, plugin_path), + NULL}, + njt_null_command}; + +static njt_http_module_t njt_http_wasm_module_ctx = { + NULL, + njt_http_wasm_init, + njt_http_wasm_create_main_conf, + NULL, + NULL, + NULL, + njt_http_wasm_create_loc_conf, + njt_http_wasm_merge_loc_conf}; + +njt_module_t njt_http_wasm_module = { + NJT_MODULE_V1, + &njt_http_wasm_module_ctx, + njt_http_wasm_commands, + NJT_HTTP_MODULE, + NULL, + NULL, + njt_http_wasm_init_worker, + NULL, + NULL, + njt_http_wasm_exit, + NULL, + NJT_MODULE_V1_PADDING}; + +static char * +njt_http_wasm_plugin(njt_conf_t *cf, njt_command_t *cmd, void *conf) +{ + + njt_http_wasm_loc_conf_t *clcf = conf; + clcf->wasm_enable = 1; + + njt_http_core_loc_conf_t *core_conf; + core_conf = njt_http_conf_get_module_loc_conf(cf, njt_http_core_module); + core_conf->handler = njt_http_wasm_handler; + + return NJT_CONF_OK; +} + +static njt_int_t +njt_http_wasm_init(njt_conf_t *cf) +{ + return NJT_OK; +} + +static void * +njt_http_wasm_create_loc_conf(njt_conf_t *cf) +{ + njt_http_wasm_loc_conf_t *uclcf; + uclcf = njt_pcalloc(cf->pool, sizeof(njt_http_wasm_loc_conf_t)); + if (uclcf == NULL) + { + njt_log_error(NJT_LOG_ERR, cf->log, 0, "malloc uclcf eror"); + return NULL; + } + uclcf->wasm_enable = NJT_CONF_UNSET; + uclcf->func_name.len = 0; + uclcf->func_name.data = NULL; + uclcf->plugin_path.len = 0; + uclcf->plugin_path.data = NULL; + return uclcf; +} + +static void * +njt_http_wasm_create_main_conf(njt_conf_t *cf) +{ + njt_http_wasm_main_conf_t *uclcf; + + uclcf = njt_pcalloc(cf->pool, sizeof(njt_http_wasm_main_conf_t)); + if (uclcf == NULL) + { + njt_log_error(NJT_LOG_ERR, cf->log, 0, "malloc njt_http_wasm_main_conf_t eror"); + return NULL; + } + uclcf->size = NJT_CONF_UNSET; + return uclcf; +} + +static njt_int_t load_wasm_instance(njt_http_wasm_loc_conf_t *conf, const char *path) +{ + WasmEdge_ConfigureContext *ConfCxt = WasmEdge_ConfigureCreate(); + WasmEdge_ConfigureAddHostRegistration(ConfCxt, WasmEdge_HostRegistration_Wasi); + + vm = WasmEdge_VMCreate(ConfCxt, NULL); + WasmEdge_VMContext *VMCxt = vm; + WasmEdge_ConfigureDelete(ConfCxt); + + WasmEdge_ModuleInstanceContext *WasiCxt = + WasmEdge_VMGetImportModuleContext(VMCxt, WasmEdge_HostRegistration_Wasi); + WasmEdge_ModuleInstanceInitWASI(WasiCxt, NULL, 0, NULL, 3, NULL, 0); + + WasmEdge_Result Res; + + Res = WasmEdge_VMLoadWasmFromFile(VMCxt, path); + if (!WasmEdge_ResultOK(Res)) + { + njt_log_error(NJT_LOG_EMERG, njt_cycle->log, 0, "Load WASM failed. Error message: %s\n", + WasmEdge_ResultGetMessage(Res)); + return NJT_ERROR; + } + Res = WasmEdge_VMValidate(VMCxt); + + if (!WasmEdge_ResultOK(Res)) + { + njt_log_error(NJT_LOG_EMERG, njt_cycle->log, 0, "Validate WASM failed. Error message: %s\n", + WasmEdge_ResultGetMessage(Res)); + return NJT_ERROR; + } + Res = WasmEdge_VMInstantiate(VMCxt); + + if (!WasmEdge_ResultOK(Res)) + { + njt_log_error(NJT_LOG_EMERG, njt_cycle->log, 0, "Instantiate WASM failed. Error message: %s\n", + WasmEdge_ResultGetMessage(Res)); + return NJT_ERROR; + } + + const WasmEdge_ModuleInstanceContext *mod_inst = WasmEdge_VMGetActiveModule(VMCxt); + memory = WasmEdge_ModuleInstanceFindMemory(mod_inst, WasmEdge_StringCreateByCString("memory")); + if (!memory) + { + njt_log_error(NJT_LOG_EMERG, njt_cycle->log, 0, "Failed to find memory instance.", + WasmEdge_ResultGetMessage(Res)); + return NJT_ERROR; + } + return NJT_OK; +} + +static char *njt_http_wasm_merge_loc_conf(njt_conf_t *cf, + void *parent, void *child) +{ + njt_http_wasm_loc_conf_t *prev = parent; + njt_http_wasm_loc_conf_t *conf = child; + + njt_conf_merge_value(conf->wasm_enable, prev->wasm_enable, 0); + njt_conf_merge_str_value(conf->func_name, prev->func_name, ""); + njt_conf_merge_str_value(conf->plugin_path, prev->plugin_path, ""); + return NJT_CONF_OK; +} + +static njt_int_t +njt_http_wasm_handler(njt_http_request_t *r) +{ + njt_int_t rc = NJT_OK; + + njt_http_core_loc_conf_t *loc; + njt_http_wasm_loc_conf_t *wasm_clcf; + + loc = njt_http_get_module_loc_conf(r, njt_http_core_module); + wasm_clcf = njt_http_get_module_loc_conf(r, njt_http_wasm_module); + if (wasm_clcf && wasm_clcf->wasm_enable && loc) + { + } + else + { + return NJT_DECLINED; + } + + njt_log_debug0(NJT_LOG_DEBUG_ALLOC, r->pool->log, 0, "1 read_client_request_body start +++++++++++++++"); + rc = njt_http_read_client_request_body(r, njt_http_wasm_read_data); + if (rc >= NJT_HTTP_SPECIAL_RESPONSE) + { + return rc; + } + + return NJT_DONE; +} + +static njt_int_t +njt_http_wasm_init_worker(njt_cycle_t *cycle) +{ + + return NJT_OK; +} + +static int njt_http_wasm_request_output(njt_http_request_t *r, njt_int_t code, njt_str_t *msg) +{ + njt_int_t rc; + njt_buf_t *buf; + njt_chain_t out; + + if (code == NJT_OK) + { + if (msg == NULL || msg->len == 0) + { + r->headers_out.status = NJT_HTTP_NO_CONTENT; + } + else + { + r->headers_out.status = NJT_HTTP_OK; + } + } + else + { + r->headers_out.status = code; + } + r->headers_out.content_length_n = 0; + if (msg != NULL && msg->len > 0) + { + njt_str_t type = njt_string("text/plain"); + r->headers_out.content_type = type; + r->headers_out.content_length_n = msg->len; + } + if (r->headers_out.content_length) + { + r->headers_out.content_length->hash = 0; + r->headers_out.content_length = NULL; + } + rc = njt_http_send_header(r); + if (rc == NJT_ERROR || rc > NJT_OK || r->header_only || msg == NULL || msg->len < 1) + { + return rc; + } + buf = njt_create_temp_buf(r->pool, msg->len); + if (buf == NULL) + { + return NJT_ERROR; + } + njt_memcpy(buf->pos, msg->data, msg->len); + buf->last = buf->pos + msg->len; + buf->last_buf = 1; + out.buf = buf; + out.next = NULL; + return njt_http_output_filter(r, &out); +} + +static void add_obj_to_json(char *str, char *key, char *value) +{ + strcat(str, ",\""); + strcat(str, key); + strcat(str, "\":\""); + strcat(str, value); + strcat(str, "\""); +} + +static char *loop_headers(njt_http_request_t *r) +{ + char *res = njt_palloc(r->pool, 1000); + memset(res, 0, 1000); + strcat(res, "{\"headers\": { \"proxy-from\": \"wasm-module\""); + njt_list_part_t *part = &r->headers_in.headers.part; + njt_table_elt_t *data = part->elts; + njt_uint_t i = 0; + for (i = 0 ; /* void */ ; i++) { + if (i >= part->nelts) { + if (part->next == NULL) { + break; + } + + part = part->next; + data = part->elts; + i = 0; + } + add_obj_to_json(res, (char *) data[i].key.data, (char *) data[i].value.data); + } + strcat(res, "}"); + return res; +} + +static void +njt_http_wasm_read_data(njt_http_request_t *r) +{ + njt_int_t rc; + + njt_http_wasm_loc_conf_t *wasm_clcf = njt_http_get_module_loc_conf(r, njt_http_wasm_module); + if (vm == NULL) + { + njt_str_t path = wasm_clcf->plugin_path; + // check wasm plugin path config + if(path.len == 0) { + njt_str_t err = njt_string("no wasm plugin_path config!"); + rc = njt_http_wasm_request_output(r, NJT_HTTP_INTERNAL_SERVER_ERROR, &err); + njt_http_finalize_request(r, rc); + return; + } + + u_char *wasmPath = path.data; + if (path.data[path.len - 1] != '\0') + { + u_char *new_data = njt_palloc(r->pool, path.len + 1); + if (new_data == NULL) + { + return; + } + njt_memcpy(new_data, path.data, path.len); + new_data[path.len] = '\0'; + wasmPath = new_data; + } + njt_int_t load_result = load_wasm_instance(wasm_clcf, (const char *)wasmPath); + + if(load_result != NJT_OK) { + njt_str_t err = njt_string("load wasm plugin error!"); + rc = njt_http_wasm_request_output(r, NJT_HTTP_INTERNAL_SERVER_ERROR, &err); + njt_http_finalize_request(r, rc); + return; + } + } + + njt_str_t response_data = njt_string("wasm world!"); + njt_str_t no_json_body = njt_string("\"no body content\""); + njt_str_t json_body; + rc = njt_http_util_read_request_body(r, &json_body, 2, 5242880); + if (rc != NJT_OK) + { + json_body = no_json_body; + } + + char *request_str = loop_headers(r); + + strcat(request_str, ",\"body\": "); + strcat(request_str, (char *)(char *)json_body.data); + strcat(request_str, "}"); + + const char *input = request_str; + size_t input_len = strlen(input); + WasmEdge_Result Res; + + WasmEdge_MemoryInstanceSetData(memory, (const uint8_t *)input, ptr_offset, input_len); + + WasmEdge_Value Params[2] = {WasmEdge_ValueGenI32(ptr_offset), + WasmEdge_ValueGenI32(input_len)}; + ptr_offset += input_len; + + WasmEdge_Value Returns[1] = {}; + WasmEdge_String FuncName = WasmEdge_StringCreateByCString((char *)wasm_clcf->func_name.data); + Res = WasmEdge_VMExecute(vm, FuncName, Params, 2, Returns, 1); + if (!WasmEdge_ResultOK(Res)) + { + njt_str_t err = njt_string("wasm execute error!"); + rc = njt_http_wasm_request_output(r, NJT_HTTP_OK, &err); + njt_http_finalize_request(r, rc); + return; + } + + uint32_t ptr = WasmEdge_ValueGetI32(Returns[0]); + + uint32_t *data = (uint32_t *)WasmEdge_MemoryInstanceGetPointer(memory, ptr, 2 * sizeof(uint32_t)); + + uint32_t str_ptr = data[0]; + uint32_t str_len = data[1]; + + u_char *c_string = (u_char *)WasmEdge_MemoryInstanceGetPointer(memory, str_ptr, str_len); + + njt_int_t plugin_response_status = 200; + if (str_len > 3) + { + char tmp[4]; + njt_memcpy(tmp, c_string, 3); + tmp[3] = '\0'; + plugin_response_status = atoi(tmp); + if (plugin_response_status == 0) + { + c_string = (u_char *)"插件返回格式出错"; + str_len = 24; + + } + else + { + c_string = c_string + 3; + str_len = str_len - 3; + } + } + else + { + c_string = (u_char *)"插件返回格式出错"; + str_len = 24; + } + + njt_str_t tmp_str; + tmp_str.data = c_string; + tmp_str.len = str_len; + + response_data = tmp_str; + rc = njt_http_wasm_request_output(r, plugin_response_status, &response_data); + njt_http_finalize_request(r, rc); + return; +} + + +static void njt_http_wasm_exit(njt_cycle_t *cycle) +{ + WasmEdge_VMDelete(vm); + WasmEdge_MemoryInstanceDelete(memory); + return; +} \ No newline at end of file diff --git a/wasmedge/conf b/wasmedge/conf new file mode 100644 index 0000000000000000000000000000000000000000..81d592439406eeb382333226ad4eefac873a1787 --- /dev/null +++ b/wasmedge/conf @@ -0,0 +1,31 @@ + +# Copyright (C) Igor Sysoev +# Copyright (C) Nginx, Inc. +# Copyright (C) TMLake, Inc. + +WASMEDGE="auto/lib/wasmedge" +wasm_arch=$(uname -m) +wasm_os_type=$(uname -s) + +case "$CC" in + *) + if [ "$wasm_arch" != "x86_64" ] && [ "$wasm_arch" != "aarch64" ]; then + cat << END + $0: error: not allow build use with system architecture $wasm_arch. +END + exit 1 + fi + + if [ "$wasm_os_type" != Linux ]; then + cat << END + $0: error: not allow build use with operating system $wasm_os_type. +END + exit 1 + fi + + CORE_DEPS="$CORE_DEPS $WASMEDGE/build/include/wasmedge/wasmedge.h" + ;; +esac + + + diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum.inc b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum.inc new file mode 100644 index 0000000000000000000000000000000000000000..bf1c8f7c78cadc318de23d5319956d6bc6ce427d --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum.inc @@ -0,0 +1,1201 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum.inc - Enumerations ---------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains all enumerations of WasmEdge. +/// +//===----------------------------------------------------------------------===// + +#ifndef Line +#error "this header file must not be included directly" +#endif + +// enum_ast.hpp + +#ifdef UseASTNodeAttr +#define A Line + +A(Component, "component") +A(Sec_CoreMod, "component core:module section") +A(Sec_CoreInstance, "component core:instance section") +A(Sec_Alias, "component alias section") +A(Sec_Comp, "nested component section") +A(Sec_Instance, "component instance section") +A(Sec_CompType, "component type section") +A(Sec_Canon, "component canonical section") +A(Sec_CompStart, "component start section") +A(Sec_CompImport, "component import section") +A(Sec_CompExport, "component export section") +A(ImportExportName, "import/export name") +A(Import, "import") +A(Export, "export") +A(Canonical, "canonical") +A(Alias, "alias") +A(DefType, "component defined type") +A(InstanceDecl, "instance decl") +A(ExternDesc, "extern desc") +A(Name, "import/export name") +A(AliasTarget, "alias target") +A(Sort, "sort") +A(Instance, "instance expr") +A(CoreInstance, "core:instance expr") +A(Module, "module") +A(Sec_Custom, "custom section") +A(Sec_Type, "type section") +A(Sec_Import, "import section") +A(Sec_Function, "function section") +A(Sec_Table, "table section") +A(Sec_Memory, "memory section") +A(Sec_Global, "global section") +A(Sec_Export, "export section") +A(Sec_Start, "start section") +A(Sec_Element, "element section") +A(Sec_Code, "code section") +A(Sec_Data, "data section") +A(Sec_DataCount, "data count section") +A(Sec_Tag, "tag section") +A(Desc_Import, "import description") +A(Desc_Export, "export description") +A(Seg_Table, "table segment") +A(Seg_Global, "global segment") +A(Seg_Element, "element segment") +A(Seg_Code, "code segment") +A(Seg_Data, "data segment") +A(Type_Module, "module type") +A(Type_Rec, "recursive type") +A(Type_Sub, "sub type") +A(Type_Limit, "limit") +A(Type_Function, "function type") +A(Type_Memory, "memory type") +A(Type_Table, "table type") +A(Type_Global, "global type") +A(Type_Instance, "instance type") +A(Type_Component, "component type") +A(Expression, "expression") +A(Instruction, "instruction") +A(Sec_AOT, "aot section") + +#undef A +#endif // UseASTNodeAttr + +#ifdef UseOpCode +#define O Line +#define OFB Line_FB +#define OFC Line_FC +#define OFD Line_FD +#define OFE Line_FE + +// OpCode: +// NAME | STRING | CODE [ | EXTEND ] + +// Control instructions (part 1) +O(Unreachable, "unreachable", 0x00) +O(Nop, "nop", 0x01) +O(Block, "block", 0x02) +O(Loop, "loop", 0x03) +O(If, "if", 0x04) +O(Else, "else", 0x05) +O(Try, "try", 0x06) // For legacy EH proposal +O(Catch, "catch", 0x07) // For legacy EH proposal +O(Throw, "throw", 0x08) +O(Rethrow, "rethrow", 0x09) // For legacy EH proposal +O(Throw_ref, "throw_ref", 0x0A) +O(End, "end", 0x0B) +O(Br, "br", 0x0C) +O(Br_if, "br_if", 0x0D) +O(Br_table, "br_table", 0x0E) +O(Return, "return", 0x0F) +O(Call, "call", 0x10) +O(Call_indirect, "call_indirect", 0x11) +O(Return_call, "return_call", 0x12) +O(Return_call_indirect, "return_call_indirect", 0x13) +O(Call_ref, "call_ref", 0x14) +O(Return_call_ref, "return_call_ref", 0x15) +// 0x16: Reserved +// 0x17: Reserved +O(Delegate, "delegate", 0x18) // For legacy EH proposal +O(Catch_all, "catch_all", 0x19) // For legacy EH proposal + +// Parametric Instructions +O(Drop, "drop", 0x1A) +O(Select, "select", 0x1B) +O(Select_t, "select", 0x1C) +// 0x1D: Reserved +// 0x1E: Reserved + +// Control instructions (part 2) +O(Try_table, "try_table", 0x1F) + +// Variable Instructions +O(Local__get, "local.get", 0x20) +O(Local__set, "local.set", 0x21) +O(Local__tee, "local.tee", 0x22) +O(Global__get, "global.get", 0x23) +O(Global__set, "global.set", 0x24) + +// Table Instructions (part 1) +O(Table__get, "table.get", 0x25) +O(Table__set, "table.set", 0x26) +// 0x27: Reserved + +// Memory Instructions (part 1) +O(I32__load, "i32.load", 0x28) +O(I64__load, "i64.load", 0x29) +O(F32__load, "f32.load", 0x2A) +O(F64__load, "f64.load", 0x2B) +O(I32__load8_s, "i32.load8_s", 0x2C) +O(I32__load8_u, "i32.load8_u", 0x2D) +O(I32__load16_s, "i32.load16_s", 0x2E) +O(I32__load16_u, "i32.load16_u", 0x2F) +O(I64__load8_s, "i64.load8_s", 0x30) +O(I64__load8_u, "i64.load8_u", 0x31) +O(I64__load16_s, "i64.load16_s", 0x32) +O(I64__load16_u, "i64.load16_u", 0x33) +O(I64__load32_s, "i64.load32_s", 0x34) +O(I64__load32_u, "i64.load32_u", 0x35) +O(I32__store, "i32.store", 0x36) +O(I64__store, "i64.store", 0x37) +O(F32__store, "f32.store", 0x38) +O(F64__store, "f64.store", 0x39) +O(I32__store8, "i32.store8", 0x3A) +O(I32__store16, "i32.store16", 0x3B) +O(I64__store8, "i64.store8", 0x3C) +O(I64__store16, "i64.store16", 0x3D) +O(I64__store32, "i64.store32", 0x3E) +O(Memory__size, "memory.size", 0x3F) +O(Memory__grow, "memory.grow", 0x40) + +// Const numeric instructions +O(I32__const, "i32.const", 0x41) +O(I64__const, "i64.const", 0x42) +O(F32__const, "f32.const", 0x43) +O(F64__const, "f64.const", 0x44) + +// Numeric instructions +O(I32__eqz, "i32.eqz", 0x45) +O(I32__eq, "i32.eq", 0x46) +O(I32__ne, "i32.ne", 0x47) +O(I32__lt_s, "i32.lt_s", 0x48) +O(I32__lt_u, "i32.lt_u", 0x49) +O(I32__gt_s, "i32.gt_s", 0x4A) +O(I32__gt_u, "i32.gt_u", 0x4B) +O(I32__le_s, "i32.le_s", 0x4C) +O(I32__le_u, "i32.le_u", 0x4D) +O(I32__ge_s, "i32.ge_s", 0x4E) +O(I32__ge_u, "i32.ge_u", 0x4F) +O(I64__eqz, "i64.eqz", 0x50) +O(I64__eq, "i64.eq", 0x51) +O(I64__ne, "i64.ne", 0x52) +O(I64__lt_s, "i64.lt_s", 0x53) +O(I64__lt_u, "i64.lt_u", 0x54) +O(I64__gt_s, "i64.gt_s", 0x55) +O(I64__gt_u, "i64.gt_u", 0x56) +O(I64__le_s, "i64.le_s", 0x57) +O(I64__le_u, "i64.le_u", 0x58) +O(I64__ge_s, "i64.ge_s", 0x59) +O(I64__ge_u, "i64.ge_u", 0x5A) +O(F32__eq, "f32.eq", 0x5B) +O(F32__ne, "f32.ne", 0x5C) +O(F32__lt, "f32.lt", 0x5D) +O(F32__gt, "f32.gt", 0x5E) +O(F32__le, "f32.le", 0x5F) +O(F32__ge, "f32.ge", 0x60) +O(F64__eq, "f64.eq", 0x61) +O(F64__ne, "f64.ne", 0x62) +O(F64__lt, "f64.lt", 0x63) +O(F64__gt, "f64.gt", 0x64) +O(F64__le, "f64.le", 0x65) +O(F64__ge, "f64.ge", 0x66) +O(I32__clz, "i32.clz", 0x67) +O(I32__ctz, "i32.ctz", 0x68) +O(I32__popcnt, "i32.popcnt", 0x69) +O(I32__add, "i32.add", 0x6A) +O(I32__sub, "i32.sub", 0x6B) +O(I32__mul, "i32.mul", 0x6C) +O(I32__div_s, "i32.div_s", 0x6D) +O(I32__div_u, "i32.div_u", 0x6E) +O(I32__rem_s, "i32.rem_s", 0x6F) +O(I32__rem_u, "i32.rem_u", 0x70) +O(I32__and, "i32.and", 0x71) +O(I32__or, "i32.or", 0x72) +O(I32__xor, "i32.xor", 0x73) +O(I32__shl, "i32.shl", 0x74) +O(I32__shr_s, "i32.shr_s", 0x75) +O(I32__shr_u, "i32.shr_u", 0x76) +O(I32__rotl, "i32.rotl", 0x77) +O(I32__rotr, "i32.rotr", 0x78) +O(I64__clz, "i64.clz", 0x79) +O(I64__ctz, "i64.ctz", 0x7A) +O(I64__popcnt, "i64.popcnt", 0x7B) +O(I64__add, "i64.add", 0x7C) +O(I64__sub, "i64.sub", 0x7D) +O(I64__mul, "i64.mul", 0x7E) +O(I64__div_s, "i64.div_s", 0x7F) +O(I64__div_u, "i64.div_u", 0x80) +O(I64__rem_s, "i64.rem_s", 0x81) +O(I64__rem_u, "i64.rem_u", 0x82) +O(I64__and, "i64.and", 0x83) +O(I64__or, "i64.or", 0x84) +O(I64__xor, "i64.xor", 0x85) +O(I64__shl, "i64.shl", 0x86) +O(I64__shr_s, "i64.shr_s", 0x87) +O(I64__shr_u, "i64.shr_u", 0x88) +O(I64__rotl, "i64.rotl", 0x89) +O(I64__rotr, "i64.rotr", 0x8A) +O(F32__abs, "f32.abs", 0x8B) +O(F32__neg, "f32.neg", 0x8C) +O(F32__ceil, "f32.ceil", 0x8D) +O(F32__floor, "f32.floor", 0x8E) +O(F32__trunc, "f32.trunc", 0x8F) +O(F32__nearest, "f32.nearest", 0x90) +O(F32__sqrt, "f32.sqrt", 0x91) +O(F32__add, "f32.add", 0x92) +O(F32__sub, "f32.sub", 0x93) +O(F32__mul, "f32.mul", 0x94) +O(F32__div, "f32.div", 0x95) +O(F32__min, "f32.min", 0x96) +O(F32__max, "f32.max", 0x97) +O(F32__copysign, "f32.copysign", 0x98) +O(F64__abs, "f64.abs", 0x99) +O(F64__neg, "f64.neg", 0x9A) +O(F64__ceil, "f64.ceil", 0x9B) +O(F64__floor, "f64.floor", 0x9C) +O(F64__trunc, "f64.trunc", 0x9D) +O(F64__nearest, "f64.nearest", 0x9E) +O(F64__sqrt, "f64.sqrt", 0x9F) +O(F64__add, "f64.add", 0xA0) +O(F64__sub, "f64.sub", 0xA1) +O(F64__mul, "f64.mul", 0xA2) +O(F64__div, "f64.div", 0xA3) +O(F64__min, "f64.min", 0xA4) +O(F64__max, "f64.max", 0xA5) +O(F64__copysign, "f64.copysign", 0xA6) +O(I32__wrap_i64, "i32.wrap_i64", 0xA7) +O(I32__trunc_f32_s, "i32.trunc_f32_s", 0xA8) +O(I32__trunc_f32_u, "i32.trunc_f32_u", 0xA9) +O(I32__trunc_f64_s, "i32.trunc_f64_s", 0xAA) +O(I32__trunc_f64_u, "i32.trunc_f64_u", 0xAB) +O(I64__extend_i32_s, "i64.extend_i32_s", 0xAC) +O(I64__extend_i32_u, "i64.extend_i32_u", 0xAD) +O(I64__trunc_f32_s, "i64.trunc_f32_s", 0xAE) +O(I64__trunc_f32_u, "i64.trunc_f32_u", 0xAF) +O(I64__trunc_f64_s, "i64.trunc_f64_s", 0xB0) +O(I64__trunc_f64_u, "i64.trunc_f64_u", 0xB1) +O(F32__convert_i32_s, "f32.convert_i32_s", 0xB2) +O(F32__convert_i32_u, "f32.convert_i32_u", 0xB3) +O(F32__convert_i64_s, "f32.convert_i64_s", 0xB4) +O(F32__convert_i64_u, "f32.convert_i64_u", 0xB5) +O(F32__demote_f64, "f32.demote_f64", 0xB6) +O(F64__convert_i32_s, "f64.convert_i32_s", 0xB7) +O(F64__convert_i32_u, "f64.convert_i32_u", 0xB8) +O(F64__convert_i64_s, "f64.convert_i64_s", 0xB9) +O(F64__convert_i64_u, "f64.convert_i64_u", 0xBA) +O(F64__promote_f32, "f64.promote_f32", 0xBB) +O(I32__reinterpret_f32, "i32.reinterpret_f32", 0xBC) +O(I64__reinterpret_f64, "i64.reinterpret_f64", 0xBD) +O(F32__reinterpret_i32, "f32.reinterpret_i32", 0xBE) +O(F64__reinterpret_i64, "f64.reinterpret_i64", 0xBF) +O(I32__extend8_s, "i32.extend8_s", 0xC0) +O(I32__extend16_s, "i32.extend16_s", 0xC1) +O(I64__extend8_s, "i64.extend8_s", 0xC2) +O(I64__extend16_s, "i64.extend16_s", 0xC3) +O(I64__extend32_s, "i64.extend32_s", 0xC4) +// 0xC5 ~ 0xCF: Reserved + +// Reference Instructions +O(Ref__null, "ref.null", 0xD0) +O(Ref__is_null, "ref.is_null", 0xD1) +O(Ref__func, "ref.func", 0xD2) +O(Ref__eq, "ref.eq", 0xD3) +O(Ref__as_non_null, "ref.as_non_null", 0xD4) + +// Control Instructions (part 3) +O(Br_on_null, "br_on_null", 0xD5) +O(Br_on_non_null, "br_on_non_null", 0xD6) +// 0xD7 ~ 0xFA: Reserved + +// 0xFB prefix - GC Instructions +OFB(Struct__new, "struct.new", 0xFB, 0) +OFB(Struct__new_default, "struct.new_default", 0xFB, 1) +OFB(Struct__get, "struct.get", 0xFB, 2) +OFB(Struct__get_s, "struct.get_s", 0xFB, 3) +OFB(Struct__get_u, "struct.get_u", 0xFB, 4) +OFB(Struct__set, "struct.set", 0xFB, 5) +OFB(Array__new, "array.new", 0xFB, 6) +OFB(Array__new_default, "array.new_default", 0xFB, 7) +OFB(Array__new_fixed, "array.new_fixed", 0xFB, 8) +OFB(Array__new_data, "array.new_data", 0xFB, 9) +OFB(Array__new_elem, "array.new_elem", 0xFB, 10) +OFB(Array__get, "array.get", 0xFB, 11) +OFB(Array__get_s, "array.get_s", 0xFB, 12) +OFB(Array__get_u, "array.get_u", 0xFB, 13) +OFB(Array__set, "array.set", 0xFB, 14) +OFB(Array__len, "array.len", 0xFB, 15) +OFB(Array__fill, "array.fill", 0xFB, 16) +OFB(Array__copy, "array.copy", 0xFB, 17) +OFB(Array__init_data, "array.init_data", 0xFB, 18) +OFB(Array__init_elem, "array.init_elem", 0xFB, 19) +OFB(Ref__test, "ref.test (ref)", 0xFB, 20) +OFB(Ref__test_null, "ref.test (ref.null)", 0xFB, 21) +OFB(Ref__cast, "ref.cast (ref)", 0xFB, 22) +OFB(Ref__cast_null, "ref.cast (ref.null)", 0xFB, 23) +OFB(Br_on_cast, "br_on_cast", 0xFB, 24) +OFB(Br_on_cast_fail, "br_on_cast_fail", 0xFB, 25) +OFB(Any__convert_extern, "any.convert_extern", 0xFB, 26) +OFB(Extern__convert_any, "extern.convert_any", 0xFB, 27) +OFB(Ref__i31, "ref.i31", 0xFB, 28) +OFB(I31__get_s, "i31.get_s", 0xFB, 29) +OFB(I31__get_u, "i31.get_u", 0xFB, 30) + +// 0xFC prefix - Saturating Truncation Instructions +OFC(I32__trunc_sat_f32_s, "i32.trunc_sat_f32_s", 0xFC, 0) +OFC(I32__trunc_sat_f32_u, "i32.trunc_sat_f32_u", 0xFC, 1) +OFC(I32__trunc_sat_f64_s, "i32.trunc_sat_f64_s", 0xFC, 2) +OFC(I32__trunc_sat_f64_u, "i32.trunc_sat_f64_u", 0xFC, 3) +OFC(I64__trunc_sat_f32_s, "i64.trunc_sat_f32_s", 0xFC, 4) +OFC(I64__trunc_sat_f32_u, "i64.trunc_sat_f32_u", 0xFC, 5) +OFC(I64__trunc_sat_f64_s, "i64.trunc_sat_f64_s", 0xFC, 6) +OFC(I64__trunc_sat_f64_u, "i64.trunc_sat_f64_u", 0xFC, 7) + +// 0xFC prefix - Memory Instructions (part 2) +OFC(Memory__init, "memory.init", 0xFC, 8) +OFC(Data__drop, "data.drop", 0xFC, 9) +OFC(Memory__copy, "memory.copy", 0xFC, 10) +OFC(Memory__fill, "memory.fill", 0xFC, 11) + +// 0xFC prefix - Table Instructions (part 2) +OFC(Table__init, "table.init", 0xFC, 12) +OFC(Elem__drop, "elem.drop", 0xFC, 13) +OFC(Table__copy, "table.copy", 0xFC, 14) +OFC(Table__grow, "table.grow", 0xFC, 15) +OFC(Table__size, "table.size", 0xFC, 16) +OFC(Table__fill, "table.fill", 0xFC, 17) + +// 0xFD prefix - Vector Memory Instructions (part 1) +OFD(V128__load, "v128.load", 0xFD, 0) +OFD(V128__load8x8_s, "v128.load8x8_s", 0xFD, 1) +OFD(V128__load8x8_u, "v128.load8x8_u", 0xFD, 2) +OFD(V128__load16x4_s, "v128.load16x4_s", 0xFD, 3) +OFD(V128__load16x4_u, "v128.load16x4_u", 0xFD, 4) +OFD(V128__load32x2_s, "v128.load32x2_s", 0xFD, 5) +OFD(V128__load32x2_u, "v128.load32x2_u", 0xFD, 6) +OFD(V128__load8_splat, "v128.load8_splat", 0xFD, 7) +OFD(V128__load16_splat, "v128.load16_splat", 0xFD, 8) +OFD(V128__load32_splat, "v128.load32_splat", 0xFD, 9) +OFD(V128__load64_splat, "v128.load64_splat", 0xFD, 10) +OFD(V128__store, "v128.store", 0xFD, 11) + +// 0xFD prefix - Vector Numeric Instructions (part 1) +OFD(V128__const, "v128.const", 0xFD, 12) +OFD(I8x16__shuffle, "i8x16.shuffle", 0xFD, 13) +OFD(I8x16__swizzle, "i8x16.swizzle", 0xFD, 14) +OFD(I8x16__splat, "i8x16.splat", 0xFD, 15) +OFD(I16x8__splat, "i16x8.splat", 0xFD, 16) +OFD(I32x4__splat, "i32x4.splat", 0xFD, 17) +OFD(I64x2__splat, "i64x2.splat", 0xFD, 18) +OFD(F32x4__splat, "f32x4.splat", 0xFD, 19) +OFD(F64x2__splat, "f64x2.splat", 0xFD, 20) + +// 0xFD prefix - Vector Lane Instructions +OFD(I8x16__extract_lane_s, "i8x16.extract_lane_s", 0xFD, 21) +OFD(I8x16__extract_lane_u, "i8x16.extract_lane_u", 0xFD, 22) +OFD(I8x16__replace_lane, "i8x16.replace_lane", 0xFD, 23) +OFD(I16x8__extract_lane_s, "i16x8.extract_lane_s", 0xFD, 24) +OFD(I16x8__extract_lane_u, "i16x8.extract_lane_u", 0xFD, 25) +OFD(I16x8__replace_lane, "i16x8.replace_lane", 0xFD, 26) +OFD(I32x4__extract_lane, "i32x4.extract_lane", 0xFD, 27) +OFD(I32x4__replace_lane, "i32x4.replace_lane", 0xFD, 28) +OFD(I64x2__extract_lane, "i64x2.extract_lane", 0xFD, 29) +OFD(I64x2__replace_lane, "i64x2.replace_lane", 0xFD, 30) +OFD(F32x4__extract_lane, "f32x4.extract_lane", 0xFD, 31) +OFD(F32x4__replace_lane, "f32x4.replace_lane", 0xFD, 32) +OFD(F64x2__extract_lane, "f64x2.extract_lane", 0xFD, 33) +OFD(F64x2__replace_lane, "f64x2.replace_lane", 0xFD, 34) + +// 0xFD prefix - Vector Numeric Instructions (part 2) +OFD(I8x16__eq, "i8x16.eq", 0xFD, 35) +OFD(I8x16__ne, "i8x16.ne", 0xFD, 36) +OFD(I8x16__lt_s, "i8x16.lt_s", 0xFD, 37) +OFD(I8x16__lt_u, "i8x16.lt_u", 0xFD, 38) +OFD(I8x16__gt_s, "i8x16.gt_s", 0xFD, 39) +OFD(I8x16__gt_u, "i8x16.gt_u", 0xFD, 40) +OFD(I8x16__le_s, "i8x16.le_s", 0xFD, 41) +OFD(I8x16__le_u, "i8x16.le_u", 0xFD, 42) +OFD(I8x16__ge_s, "i8x16.ge_s", 0xFD, 43) +OFD(I8x16__ge_u, "i8x16.ge_u", 0xFD, 44) +OFD(I16x8__eq, "i16x8.eq", 0xFD, 45) +OFD(I16x8__ne, "i16x8.ne", 0xFD, 46) +OFD(I16x8__lt_s, "i16x8.lt_s", 0xFD, 47) +OFD(I16x8__lt_u, "i16x8.lt_u", 0xFD, 48) +OFD(I16x8__gt_s, "i16x8.gt_s", 0xFD, 49) +OFD(I16x8__gt_u, "i16x8.gt_u", 0xFD, 50) +OFD(I16x8__le_s, "i16x8.le_s", 0xFD, 51) +OFD(I16x8__le_u, "i16x8.le_u", 0xFD, 52) +OFD(I16x8__ge_s, "i16x8.ge_s", 0xFD, 53) +OFD(I16x8__ge_u, "i16x8.ge_u", 0xFD, 54) +OFD(I32x4__eq, "i32x4.eq", 0xFD, 55) +OFD(I32x4__ne, "i32x4.ne", 0xFD, 56) +OFD(I32x4__lt_s, "i32x4.lt_s", 0xFD, 57) +OFD(I32x4__lt_u, "i32x4.lt_u", 0xFD, 58) +OFD(I32x4__gt_s, "i32x4.gt_s", 0xFD, 59) +OFD(I32x4__gt_u, "i32x4.gt_u", 0xFD, 60) +OFD(I32x4__le_s, "i32x4.le_s", 0xFD, 61) +OFD(I32x4__le_u, "i32x4.le_u", 0xFD, 62) +OFD(I32x4__ge_s, "i32x4.ge_s", 0xFD, 63) +OFD(I32x4__ge_u, "i32x4.ge_u", 0xFD, 64) +OFD(F32x4__eq, "f32x4.eq", 0xFD, 65) +OFD(F32x4__ne, "f32x4.ne", 0xFD, 66) +OFD(F32x4__lt, "f32x4.lt", 0xFD, 67) +OFD(F32x4__gt, "f32x4.gt", 0xFD, 68) +OFD(F32x4__le, "f32x4.le", 0xFD, 69) +OFD(F32x4__ge, "f32x4.ge", 0xFD, 70) +OFD(F64x2__eq, "f64x2.eq", 0xFD, 71) +OFD(F64x2__ne, "f64x2.ne", 0xFD, 72) +OFD(F64x2__lt, "f64x2.lt", 0xFD, 73) +OFD(F64x2__gt, "f64x2.gt", 0xFD, 74) +OFD(F64x2__le, "f64x2.le", 0xFD, 75) +OFD(F64x2__ge, "f64x2.ge", 0xFD, 76) +OFD(V128__not, "v128.not", 0xFD, 77) +OFD(V128__and, "v128.and", 0xFD, 78) +OFD(V128__andnot, "v128.andnot", 0xFD, 79) +OFD(V128__or, "v128.or", 0xFD, 80) +OFD(V128__xor, "v128.xor", 0xFD, 81) +OFD(V128__bitselect, "v128.bitselect", 0xFD, 82) +OFD(V128__any_true, "v128.any_true", 0xFD, 83) + +// 0xFD prefix - Vector Memory Instructions (part 2) +OFD(V128__load8_lane, "v128.load8_lane", 0xFD, 84) +OFD(V128__load16_lane, "v128.load16_lane", 0xFD, 85) +OFD(V128__load32_lane, "v128.load32_lane", 0xFD, 86) +OFD(V128__load64_lane, "v128.load64_lane", 0xFD, 87) +OFD(V128__store8_lane, "v128.store8_lane", 0xFD, 88) +OFD(V128__store16_lane, "v128.store16_lane", 0xFD, 89) +OFD(V128__store32_lane, "v128.store32_lane", 0xFD, 90) +OFD(V128__store64_lane, "v128.store64_lane", 0xFD, 91) +OFD(V128__load32_zero, "v128.load32_zero", 0xFD, 92) +OFD(V128__load64_zero, "v128.load64_zero", 0xFD, 93) + +// 0xFD prefix - Vector Numeric Instructions (part 3) +OFD(F32x4__demote_f64x2_zero, "f32x4.demote_f64x2_zero", 0xFD, 94) +OFD(F64x2__promote_low_f32x4, "f64x2.promote_low_f32x4", 0xFD, 95) +OFD(I8x16__abs, "i8x16.abs", 0xFD, 96) +OFD(I8x16__neg, "i8x16.neg", 0xFD, 97) +OFD(I8x16__popcnt, "i8x16.popcnt", 0xFD, 98) +OFD(I8x16__all_true, "i8x16.all_true", 0xFD, 99) +OFD(I8x16__bitmask, "i8x16.bitmask", 0xFD, 100) +OFD(I8x16__narrow_i16x8_s, "i8x16.narrow_i16x8_s", 0xFD, 101) +OFD(I8x16__narrow_i16x8_u, "i8x16.narrow_i16x8_u", 0xFD, 102) +OFD(F32x4__ceil, "f32x4.ceil", 0xFD, 103) +OFD(F32x4__floor, "f32x4.floor", 0xFD, 104) +OFD(F32x4__trunc, "f32x4.trunc", 0xFD, 105) +OFD(F32x4__nearest, "f32x4.nearest", 0xFD, 106) +OFD(I8x16__shl, "i8x16.shl", 0xFD, 107) +OFD(I8x16__shr_s, "i8x16.shr_s", 0xFD, 108) +OFD(I8x16__shr_u, "i8x16.shr_u", 0xFD, 109) +OFD(I8x16__add, "i8x16.add", 0xFD, 110) +OFD(I8x16__add_sat_s, "i8x16.add_sat_s", 0xFD, 111) +OFD(I8x16__add_sat_u, "i8x16.add_sat_u", 0xFD, 112) +OFD(I8x16__sub, "i8x16.sub", 0xFD, 113) +OFD(I8x16__sub_sat_s, "i8x16.sub_sat_s", 0xFD, 114) +OFD(I8x16__sub_sat_u, "i8x16.sub_sat_u", 0xFD, 115) +OFD(F64x2__ceil, "f64x2.ceil", 0xFD, 116) +OFD(F64x2__floor, "f64x2.floor", 0xFD, 117) +OFD(I8x16__min_s, "i8x16.min_s", 0xFD, 118) +OFD(I8x16__min_u, "i8x16.min_u", 0xFD, 119) +OFD(I8x16__max_s, "i8x16.max_s", 0xFD, 120) +OFD(I8x16__max_u, "i8x16.max_u", 0xFD, 121) +OFD(F64x2__trunc, "f64x2.trunc", 0xFD, 122) +OFD(I8x16__avgr_u, "i8x16.avgr_u", 0xFD, 123) +OFD(I16x8__extadd_pairwise_i8x16_s, "i16x8.extadd_pairwise_i8x16_s", 0xFD, 124) +OFD(I16x8__extadd_pairwise_i8x16_u, "i16x8.extadd_pairwise_i8x16_u", 0xFD, 125) +OFD(I32x4__extadd_pairwise_i16x8_s, "i32x4.extadd_pairwise_i16x8_s", 0xFD, 126) +OFD(I32x4__extadd_pairwise_i16x8_u, "i32x4.extadd_pairwise_i16x8_u", 0xFD, 127) +OFD(I16x8__abs, "i16x8.abs", 0xFD, 128) +OFD(I16x8__neg, "i16x8.neg", 0xFD, 129) +OFD(I16x8__q15mulr_sat_s, "i16x8.q15mulr_sat_s", 0xFD, 130) +OFD(I16x8__all_true, "i16x8.all_true", 0xFD, 131) +OFD(I16x8__bitmask, "i16x8.bitmask", 0xFD, 132) +OFD(I16x8__narrow_i32x4_s, "i16x8.narrow_i32x4_s", 0xFD, 133) +OFD(I16x8__narrow_i32x4_u, "i16x8.narrow_i32x4_u", 0xFD, 134) +OFD(I16x8__extend_low_i8x16_s, "i16x8.extend_low_i8x16_s", 0xFD, 135) +OFD(I16x8__extend_high_i8x16_s, "i16x8.extend_high_i8x16_s", 0xFD, 136) +OFD(I16x8__extend_low_i8x16_u, "i16x8.extend_low_i8x16_u", 0xFD, 137) +OFD(I16x8__extend_high_i8x16_u, "i16x8.extend_high_i8x16_u", 0xFD, 138) +OFD(I16x8__shl, "i16x8.shl", 0xFD, 139) +OFD(I16x8__shr_s, "i16x8.shr_s", 0xFD, 140) +OFD(I16x8__shr_u, "i16x8.shr_u", 0xFD, 141) +OFD(I16x8__add, "i16x8.add", 0xFD, 142) +OFD(I16x8__add_sat_s, "i16x8.add_sat_s", 0xFD, 143) +OFD(I16x8__add_sat_u, "i16x8.add_sat_u", 0xFD, 144) +OFD(I16x8__sub, "i16x8.sub", 0xFD, 145) +OFD(I16x8__sub_sat_s, "i16x8.sub_sat_s", 0xFD, 146) +OFD(I16x8__sub_sat_u, "i16x8.sub_sat_u", 0xFD, 147) +OFD(F64x2__nearest, "f64x2.nearest", 0xFD, 148) +OFD(I16x8__mul, "i16x8.mul", 0xFD, 149) +OFD(I16x8__min_s, "i16x8.min_s", 0xFD, 150) +OFD(I16x8__min_u, "i16x8.min_u", 0xFD, 151) +OFD(I16x8__max_s, "i16x8.max_s", 0xFD, 152) +OFD(I16x8__max_u, "i16x8.max_u", 0xFD, 153) +// 0xFD 154: Reserved +OFD(I16x8__avgr_u, "i16x8.avgr_u", 0xFD, 155) +OFD(I16x8__extmul_low_i8x16_s, "i16x8.extmul_low_i8x16_s", 0xFD, 156) +OFD(I16x8__extmul_high_i8x16_s, "i16x8.extmul_high_i8x16_s", 0xFD, 157) +OFD(I16x8__extmul_low_i8x16_u, "i16x8.extmul_low_i8x16_u", 0xFD, 158) +OFD(I16x8__extmul_high_i8x16_u, "i16x8.extmul_high_i8x16_u", 0xFD, 159) +OFD(I32x4__abs, "i32x4.abs", 0xFD, 160) +OFD(I32x4__neg, "i32x4.neg", 0xFD, 161) +// 0xFD 162: Reserved +OFD(I32x4__all_true, "i32x4.all_true", 0xFD, 163) +OFD(I32x4__bitmask, "i32x4.bitmask", 0xFD, 164) +// 0xFD 165: Reserved +// 0xFD 166: Reserved +OFD(I32x4__extend_low_i16x8_s, "i32x4.extend_low_i16x8_s", 0xFD, 167) +OFD(I32x4__extend_high_i16x8_s, "i32x4.extend_high_i16x8_s", 0xFD, 168) +OFD(I32x4__extend_low_i16x8_u, "i32x4.extend_low_i16x8_u", 0xFD, 169) +OFD(I32x4__extend_high_i16x8_u, "i32x4.extend_high_i16x8_u", 0xFD, 170) +OFD(I32x4__shl, "i32x4.shl", 0xFD, 171) +OFD(I32x4__shr_s, "i32x4.shr_s", 0xFD, 172) +OFD(I32x4__shr_u, "i32x4.shr_u", 0xFD, 173) +OFD(I32x4__add, "i32x4.add", 0xFD, 174) +// 0xFD 175: Reserved +// 0xFD 176: Reserved +OFD(I32x4__sub, "i32x4.sub", 0xFD, 177) +// 0xFD 178: Reserved +// 0xFD 179: Reserved +// 0xFD 180: Reserved +OFD(I32x4__mul, "i32x4.mul", 0xFD, 181) +OFD(I32x4__min_s, "i32x4.min_s", 0xFD, 182) +OFD(I32x4__min_u, "i32x4.min_u", 0xFD, 183) +OFD(I32x4__max_s, "i32x4.max_s", 0xFD, 184) +OFD(I32x4__max_u, "i32x4.max_u", 0xFD, 185) +OFD(I32x4__dot_i16x8_s, "i32x4.dot_i16x8_s", 0xFD, 186) +// 0xFD 187: Reserved +OFD(I32x4__extmul_low_i16x8_s, "i32x4.extmul_low_i16x8_s", 0xFD, 188) +OFD(I32x4__extmul_high_i16x8_s, "i32x4.extmul_high_i16x8_s", 0xFD, 189) +OFD(I32x4__extmul_low_i16x8_u, "i32x4.extmul_low_i16x8_u", 0xFD, 190) +OFD(I32x4__extmul_high_i16x8_u, "i32x4.extmul_high_i16x8_u", 0xFD, 191) +OFD(I64x2__abs, "i64x2.abs", 0xFD, 192) +OFD(I64x2__neg, "i64x2.neg", 0xFD, 193) +// 0xFD 194: Reserved +OFD(I64x2__all_true, "i64x2.all_true", 0xFD, 195) +OFD(I64x2__bitmask, "i64x2.bitmask", 0xFD, 196) +// 0xFD 197: Reserved +// 0xFD 198: Reserved +OFD(I64x2__extend_low_i32x4_s, "i64x2.extend_low_i32x4_s", 0xFD, 199) +OFD(I64x2__extend_high_i32x4_s, "i64x2.extend_high_i32x4_s", 0xFD, 200) +OFD(I64x2__extend_low_i32x4_u, "i64x2.extend_low_i32x4_u", 0xFD, 201) +OFD(I64x2__extend_high_i32x4_u, "i64x2.extend_high_i32x4_u", 0xFD, 202) +OFD(I64x2__shl, "i64x2.shl", 0xFD, 203) +OFD(I64x2__shr_s, "i64x2.shr_s", 0xFD, 204) +OFD(I64x2__shr_u, "i64x2.shr_u", 0xFD, 205) +OFD(I64x2__add, "i64x2.add", 0xFD, 206) +// 0xFD 207: Reserved +// 0xFD 208: Reserved +OFD(I64x2__sub, "i64x2.sub", 0xFD, 209) +// 0xFD 210: Reserved +// 0xFD 211: Reserved +// 0xFD 212: Reserved +OFD(I64x2__mul, "i64x2.mul", 0xFD, 213) +OFD(I64x2__eq, "i64x2.eq", 0xFD, 214) +OFD(I64x2__ne, "i64x2.ne", 0xFD, 215) +OFD(I64x2__lt_s, "i64x2.lt_s", 0xFD, 216) +OFD(I64x2__gt_s, "i64x2.gt_s", 0xFD, 217) +OFD(I64x2__le_s, "i64x2.le_s", 0xFD, 218) +OFD(I64x2__ge_s, "i64x2.ge_s", 0xFD, 219) +OFD(I64x2__extmul_low_i32x4_s, "i64x2.extmul_low_i32x4_s", 0xFD, 220) +OFD(I64x2__extmul_high_i32x4_s, "i64x2.extmul_high_i32x4_s", 0xFD, 221) +OFD(I64x2__extmul_low_i32x4_u, "i64x2.extmul_low_i32x4_u", 0xFD, 222) +OFD(I64x2__extmul_high_i32x4_u, "i64x2.extmul_high_i32x4_u", 0xFD, 223) +OFD(F32x4__abs, "f32x4.abs", 0xFD, 224) +OFD(F32x4__neg, "f32x4.neg", 0xFD, 225) +// 0xFD 226: Reserved +OFD(F32x4__sqrt, "f32x4.sqrt", 0xFD, 227) +OFD(F32x4__add, "f32x4.add", 0xFD, 228) +OFD(F32x4__sub, "f32x4.sub", 0xFD, 229) +OFD(F32x4__mul, "f32x4.mul", 0xFD, 230) +OFD(F32x4__div, "f32x4.div", 0xFD, 231) +OFD(F32x4__min, "f32x4.min", 0xFD, 232) +OFD(F32x4__max, "f32x4.max", 0xFD, 233) +OFD(F32x4__pmin, "f32x4.pmin", 0xFD, 234) +OFD(F32x4__pmax, "f32x4.pmax", 0xFD, 235) +OFD(F64x2__abs, "f64x2.abs", 0xFD, 236) +OFD(F64x2__neg, "f64x2.neg", 0xFD, 237) +OFD(F64x2__sqrt, "f64x2.sqrt", 0xFD, 239) +OFD(F64x2__add, "f64x2.add", 0xFD, 240) +OFD(F64x2__sub, "f64x2.sub", 0xFD, 241) +OFD(F64x2__mul, "f64x2.mul", 0xFD, 242) +OFD(F64x2__div, "f64x2.div", 0xFD, 243) +OFD(F64x2__min, "f64x2.min", 0xFD, 244) +OFD(F64x2__max, "f64x2.max", 0xFD, 245) +OFD(F64x2__pmin, "f64x2.pmin", 0xFD, 246) +OFD(F64x2__pmax, "f64x2.pmax", 0xFD, 247) +OFD(I32x4__trunc_sat_f32x4_s, "i32x4.trunc_sat_f32x4_s", 0xFD, 248) +OFD(I32x4__trunc_sat_f32x4_u, "i32x4.trunc_sat_f32x4_u", 0xFD, 249) +OFD(F32x4__convert_i32x4_s, "f32x4.convert_i32x4_s", 0xFD, 250) +OFD(F32x4__convert_i32x4_u, "f32x4.convert_i32x4_u", 0xFD, 251) +OFD(I32x4__trunc_sat_f64x2_s_zero, "i32x4.trunc_sat_f64x2_s_zero", 0xFD, 252) +OFD(I32x4__trunc_sat_f64x2_u_zero, "i32x4.trunc_sat_f64x2_u_zero", 0xFD, 253) +OFD(F64x2__convert_low_i32x4_s, "f64x2.convert_low_i32x4_s", 0xFD, 254) +OFD(F64x2__convert_low_i32x4_u, "f64x2.convert_low_i32x4_u", 0xFD, 255) + +// 0xFE prefix - Relaxed SIMD Instructions (part 4) +OFD(I8x16__relaxed_swizzle, "i8x16.relaxed_swizzle", 0xFD, 256) +OFD(I32x4__relaxed_trunc_f32x4_s, "i32x4.relaxed_trunc_f32x4_s", 0xFD, 257) +OFD(I32x4__relaxed_trunc_f32x4_u, "i32x4.relaxed_trunc_f32x4_u", 0xFD, 258) +OFD(I32x4__relaxed_trunc_f64x2_s_zero, "i32x4.relaxed_trunc_f64x2_s_zero", 0xFD, + 259) +OFD(I32x4__relaxed_trunc_f64x2_u_zero, "i32x4.relaxed_trunc_f64x2_u_zero", 0xFD, + 260) +OFD(F32x4__relaxed_madd, "f32x4.relaxed_madd", 0xFD, 261) +OFD(F32x4__relaxed_nmadd, "f32x4.relaxed_nmadd", 0xFD, 262) +OFD(F64x2__relaxed_madd, "f32x4.relaxed_madd", 0xFD, 263) +OFD(F64x2__relaxed_nmadd, "f32x4.relaxed_nmadd", 0xFD, 264) +OFD(I8x16__relaxed_laneselect, "i8x16.relaxed_laneselect", 0xFD, 265) +OFD(I16x8__relaxed_laneselect, "i16x8.relaxed_laneselect", 0xFD, 266) +OFD(I32x4__relaxed_laneselect, "i32x4.relaxed_laneselect", 0xFD, 267) +OFD(I64x2__relaxed_laneselect, "i64x2.relaxed_laneselect", 0xFD, 268) +OFD(F32x4__relaxed_min, "f32x4.relaxed_min", 0xFD, 269) +OFD(F32x4__relaxed_max, "f32x4.relaxed_max", 0xFD, 270) +OFD(F64x2__relaxed_min, "f64x2.relaxed_min", 0xFD, 271) +OFD(F64x2__relaxed_max, "f64x2.relaxed_max", 0xFD, 272) +OFD(I16x8__relaxed_q15mulr_s, "i16x8.relaxed_q15mulr_s", 0xFD, 273) +OFD(I16x8__relaxed_dot_i8x16_i7x16_s, "i16x8.relaxed_dot_i8x16_i7x16_s", 0xFD, + 274) +OFD(I32x4__relaxed_dot_i8x16_i7x16_add_s, "i32x4.relaxed_dot_i8x16_i7x16_add_s", + 0xFD, 275) +// 0xFD 276 ~ 303: Reserved + +// 0xFE prefix - Atomic instructions +OFE(Memory__atomic__notify, "memory.atomic.notify", 0xFE, 0) +OFE(Memory__atomic__wait32, "memory.atomic.wait32", 0xFE, 1) +OFE(Memory__atomic__wait64, "memory.atomic.wait64", 0xFE, 2) +OFE(Atomic__fence, "atomic.fence", 0xFE, 3) +// 0xFE 4 ~ 15: Reserved +OFE(I32__atomic__load, "i32.atomic.load", 0xFE, 16) +OFE(I64__atomic__load, "i64.atomic.load", 0xFE, 17) +OFE(I32__atomic__load8_u, "i32.atomic.load8_u", 0xFE, 18) +OFE(I32__atomic__load16_u, "i32.atomic.load16_u", 0xFE, 19) +OFE(I64__atomic__load8_u, "i64.atomic.load8_u", 0xFE, 20) +OFE(I64__atomic__load16_u, "i64.atomic.load16_u", 0xFE, 21) +OFE(I64__atomic__load32_u, "i64.atomic.load32_u", 0xFE, 22) +OFE(I32__atomic__store, "i32.atomic.store", 0xFE, 23) +OFE(I64__atomic__store, "i64.atomic.store", 0xFE, 24) +OFE(I32__atomic__store8, "i32.atomic.store8", 0xFE, 25) +OFE(I32__atomic__store16, "i32.atomic.store16", 0xFE, 26) +OFE(I64__atomic__store8, "i64.atomic.store8", 0xFE, 27) +OFE(I64__atomic__store16, "i64.atomic.store16", 0xFE, 28) +OFE(I64__atomic__store32, "i64.atomic.store32", 0xFE, 29) +OFE(I32__atomic__rmw__add, "i32.atomic.rmw.add", 0xFE, 30) +OFE(I64__atomic__rmw__add, "i64.atomic.rmw.add", 0xFE, 31) +OFE(I32__atomic__rmw8__add_u, "i32.atomic.rmw8.add_u", 0xFE, 32) +OFE(I32__atomic__rmw16__add_u, "i32.atomic.rmw16.add_u", 0xFE, 33) +OFE(I64__atomic__rmw8__add_u, "i64.atomic.rmw8.add_u", 0xFE, 34) +OFE(I64__atomic__rmw16__add_u, "i64.atomic.rmw16.add_u", 0xFE, 35) +OFE(I64__atomic__rmw32__add_u, "i64.atomic.rmw32.add_u", 0xFE, 36) +OFE(I32__atomic__rmw__sub, "i32.atomic.rmw.sub", 0xFE, 37) +OFE(I64__atomic__rmw__sub, "i64.atomic.rmw.sub", 0xFE, 38) +OFE(I32__atomic__rmw8__sub_u, "i32.atomic.rmw8.sub_u", 0xFE, 39) +OFE(I32__atomic__rmw16__sub_u, "i32.atomic.rmw16.sub_u", 0xFE, 40) +OFE(I64__atomic__rmw8__sub_u, "i64.atomic.rmw8.sub_u", 0xFE, 41) +OFE(I64__atomic__rmw16__sub_u, "i64.atomic.rmw16.sub_u", 0xFE, 42) +OFE(I64__atomic__rmw32__sub_u, "i64.atomic.rmw32.sub_u", 0xFE, 43) +OFE(I32__atomic__rmw__and, "i32.atomic.rmw.and", 0xFE, 44) +OFE(I64__atomic__rmw__and, "i64.atomic.rmw.and", 0xFE, 45) +OFE(I32__atomic__rmw8__and_u, "i32.atomic.rmw8.and_u", 0xFE, 46) +OFE(I32__atomic__rmw16__and_u, "i32.atomic.rmw16.and_u", 0xFE, 47) +OFE(I64__atomic__rmw8__and_u, "i64.atomic.rmw8.and_u", 0xFE, 48) +OFE(I64__atomic__rmw16__and_u, "i64.atomic.rmw16.and_u", 0xFE, 49) +OFE(I64__atomic__rmw32__and_u, "i64.atomic.rmw32.and_u", 0xFE, 50) +OFE(I32__atomic__rmw__or, "i32.atomic.rmw.or", 0xFE, 51) +OFE(I64__atomic__rmw__or, "i64.atomic.rmw.or", 0xFE, 52) +OFE(I32__atomic__rmw8__or_u, "i32.atomic.rmw8.or_u", 0xFE, 53) +OFE(I32__atomic__rmw16__or_u, "i32.atomic.rmw16.or_u", 0xFE, 54) +OFE(I64__atomic__rmw8__or_u, "i64.atomic.rmw8.or_u", 0xFE, 55) +OFE(I64__atomic__rmw16__or_u, "i64.atomic.rmw16.or_u", 0xFE, 56) +OFE(I64__atomic__rmw32__or_u, "i64.atomic.rmw32.or_u", 0xFE, 57) +OFE(I32__atomic__rmw__xor, "i32.atomic.rmw.xor", 0xFE, 58) +OFE(I64__atomic__rmw__xor, "i64.atomic.rmw.xor", 0xFE, 59) +OFE(I32__atomic__rmw8__xor_u, "i32.atomic.rmw8.xor_u", 0xFE, 60) +OFE(I32__atomic__rmw16__xor_u, "i32.atomic.rmw16.xor_u", 0xFE, 61) +OFE(I64__atomic__rmw8__xor_u, "i64.atomic.rmw8.xor_u", 0xFE, 62) +OFE(I64__atomic__rmw16__xor_u, "i64.atomic.rmw16.xor_u", 0xFE, 63) +OFE(I64__atomic__rmw32__xor_u, "i64.atomic.rmw32.xor_u", 0xFE, 64) +OFE(I32__atomic__rmw__xchg, "i32.atomic.rmw.xchg", 0xFE, 65) +OFE(I64__atomic__rmw__xchg, "i64.atomic.rmw.xchg", 0xFE, 66) +OFE(I32__atomic__rmw8__xchg_u, "i32.atomic.rmw8.xchg_u", 0xFE, 67) +OFE(I32__atomic__rmw16__xchg_u, "i32.atomic.rmw16.xchg_u", 0xFE, 68) +OFE(I64__atomic__rmw8__xchg_u, "i64.atomic.rmw8.xchg_u", 0xFE, 69) +OFE(I64__atomic__rmw16__xchg_u, "i64.atomic.rmw16.xchg_u", 0xFE, 70) +OFE(I64__atomic__rmw32__xchg_u, "i64.atomic.rmw32.xchg_u", 0xFE, 71) +OFE(I32__atomic__rmw__cmpxchg, "i32.atomic.rmw.cmpxchg", 0xFE, 72) +OFE(I64__atomic__rmw__cmpxchg, "i64.atomic.rmw.cmpxchg", 0xFE, 73) +OFE(I32__atomic__rmw8__cmpxchg_u, "i32.atomic.rmw8.cmpxchg_u", 0xFE, 74) +OFE(I32__atomic__rmw16__cmpxchg_u, "i32.atomic.rmw16.cmpxchg_u", 0xFE, 75) +OFE(I64__atomic__rmw8__cmpxchg_u, "i64.atomic.rmw8.cmpxchg_u", 0xFE, 76) +OFE(I64__atomic__rmw16__cmpxchg_u, "i64.atomic.rmw16.cmpxchg_u", 0xFE, 77) +OFE(I64__atomic__rmw32__cmpxchg_u, "i64.atomic.rmw32.cmpxchg_u", 0xFE, 78) + +#undef O +#undef OFB +#undef OFC +#undef OFD +#undef OFE +#endif // UseOpCode + +// enum_configure.h + +#ifdef UseProposal +#define P Line +// Finished and standardized proposals +P(ImportExportMutGlobals, "Import/Export of Mutable Globals") +P(NonTrapFloatToIntConversions, "Non-trapping float-to-int Conversions") +P(SignExtensionOperators, "Sign-extension Operators") +P(MultiValue, "Multi-value") +P(BulkMemoryOperations, "Bulk Memory Operations") +P(ReferenceTypes, "Reference Types") +P(SIMD, "Fixed-width SIMD") +// Phase 4 proposals +P(TailCall, "Tail Call") +P(ExtendedConst, "Extended Const Expressions") +P(FunctionReferences, "Typed Function References") +P(GC, "Garbage Collection") +P(MultiMemories, "Multiple Memories") +P(Threads, "Threads") +P(RelaxSIMD, "Relaxed SIMD") +// Phase 3 proposals +P(Annotations, "Custom Annotation Syntax in the Text Format") +P(Memory64, "Memory64") +P(ExceptionHandling, "Exception Handling") +// Phase 1 proposals +P(Component, "Component Model") +#undef P +#endif // UseProposal + +#ifdef UseHostRegistration +#define H Line +H(Wasi) +#undef H +#endif // UseHostRegistration + +// enum_errcode.h + +#ifdef UseErrCategory +#define C Line + +C(WASM, 0x00) +C(UserLevelError, 0x01) + +#undef C +#endif // UseErrCategory + +#ifdef UseErrCode +#define E Line + +E(Success, 0x0000, "success") +// Exit and return success. +E(Terminated, 0x0001, "terminated") +// Generic runtime error. +E(RuntimeError, 0x0002, "generic runtime error") +// Exceeded cost limit (out of gas). +E(CostLimitExceeded, 0x0003, "cost limit exceeded") +// Wrong VM's workflow +E(WrongVMWorkflow, 0x0004, "wrong VM workflow") +// Wasm function not found +E(FuncNotFound, 0x0005, "wasm function not found") +// AOT runtime is disabled +E(AOTDisabled, 0x0006, "AOT runtime is disabled in this build") +// Execution interrupted +E(Interrupted, 0x0007, "execution interrupted") +// Not validated module +E(NotValidated, 0x0008, "wasm module hasn't passed validation yet") +// Non-Null value is required +E(NonNullRequired, 0x0009, "set null value into non-nullable value type") +// Unable to set value due to const +E(SetValueToConst, 0x000A, "set value into const") +// Set value failed due to mismatch value type +E(SetValueErrorType, 0x000B, "set value type mismatch") +// User defined error +E(UserDefError, 0x000C, "user defined error code") + +// Load phase +// @{ +// File not found +E(IllegalPath, 0x0100, "invalid path") +// Error when reading +E(ReadError, 0x0101, "read error") +// Reach end of file when reading +E(UnexpectedEnd, 0x0102, "unexpected end") +// Not detected magic header +E(MalformedMagic, 0x0103, "magic header not detected") +// Unsupported version +E(MalformedVersion, 0x0104, "unknown binary version") +// Malformed section ID +E(MalformedSection, 0x0105, "malformed section id") +// Section size mismatched +E(SectionSizeMismatch, 0x0106, "section size mismatch") +// Length out of bounds +E(LengthOutOfBounds, 0x0107, "length out of bounds") +// Junk sections +E(JunkSection, 0x0108, "unexpected content after last section") +// Incompatible function and code section +E(IncompatibleFuncCode, 0x0109, + "function and code section have inconsistent lengths") +// Incompatible data and datacount section +E(IncompatibleDataCount, 0x010A, + "data count and data section have inconsistent lengths") +// Datacount section required +E(DataCountRequired, 0x010B, "data count section required") +// Malformed import kind +E(MalformedImportKind, 0x010C, "malformed import kind") +// Malformed export kind +E(MalformedExportKind, 0x010D, "malformed export kind") +// Not loaded an expected zero byte +E(ExpectedZeroByte, 0x010E, "zero byte expected") +// Malformed mutability +E(InvalidMut, 0x010F, "malformed mutability") +// Local size too large +E(TooManyLocals, 0x0110, "too many locals") +// Malformed value type +E(MalformedValType, 0x0111, "malformed value type") +// Malformed element type (Bulk-mem proposal) +E(MalformedElemType, 0x0112, "malformed element type") +// Malformed reference type (Ref-types proposal) +E(MalformedRefType, 0x0113, "malformed reference type") +// Invalid utf-8 encoding +E(MalformedUTF8, 0x0114, "malformed UTF-8 encoding") +// Invalid too large integer +E(IntegerTooLarge, 0x0115, "integer too large") +// Invalid presentation too long integer +E(IntegerTooLong, 0x0116, "integer representation too long") +// Illegal OpCode +E(IllegalOpCode, 0x0117, "illegal opcode") +// END OpCode expected +E(ENDCodeExpected, 0x0118, "END opcode expected") +// Parsing error +E(IllegalGrammar, 0x0119, "invalid wasm grammar") +// Shared memory must have max +E(SharedMemoryNoMax, 0x011A, "shared memory must have maximum") +// Intrinsics table not found +E(IntrinsicsTableNotFound, 0x011B, "intrinsics table not found") +// Malformed table (Ref-types proposal) +E(MalformedTable, 0x011C, "malformed table") +// Alignment must < 64 without and < 128 with multi-memory proposal. +E(InvalidStoreAlignment, 0x011D, "invalid store alignment") +// @} + +// Validation phase +// @{ +// Alignment > natural +E(InvalidAlignment, 0x0200, "alignment must not be larger than natural") +// Got unexpected type when checking +E(TypeCheckFailed, 0x0201, "type mismatch") +// Branch to unknown label index +E(InvalidLabelIdx, 0x0202, "unknown label") +// Access unknown local index +E(InvalidLocalIdx, 0x0203, "unknown local") +// Access unknown field index +E(InvalidFieldIdx, 0x0204, "unknown field") +// Type index not defined +E(InvalidFuncTypeIdx, 0x0205, "unknown type") +// Function index not defined +E(InvalidFuncIdx, 0x0206, "unknown function") +// Table index not defined +E(InvalidTableIdx, 0x0207, "unknown table") +// Memory index not defined +E(InvalidMemoryIdx, 0x0208, "unknown memory") +// Global index not defined +E(InvalidGlobalIdx, 0x0209, "unknown global") +// Tag index not defined +E(InvalidTagIdx, 0x020A, "unknown tag") +// Element segment index not defined +E(InvalidElemIdx, 0x020B, "unknown elem segment") +// Data segment index not defined +E(InvalidDataIdx, 0x020C, "unknown data segment") +// Undeclared reference +E(InvalidRefIdx, 0x020D, "undeclared function reference") +// Should be constant expression +E(ConstExprRequired, 0x020E, "constant expression required") +// Export name conflicted +E(DupExportName, 0x020F, "duplicate export name") +// Tried to store to const global value +E(ImmutableGlobal, 0x0210, "global is immutable") +// Tried to store to const field of structure +E(ImmutableField, 0x0211, "field is immutable") +// Tried to store to const array +E(ImmutableArray, 0x0212, "array is immutable") +// Invalid result arity in select t* instruction +E(InvalidResultArity, 0x0213, "invalid result arity") +// #Tables > 1 (without Ref-types proposal) +E(MultiTables, 0x0214, "multiple tables") +// #Memories > 1 +E(MultiMemories, 0x0215, "multiple memories") +// Invalid Limit grammar +E(InvalidLimit, 0x0216, "size minimum must not be greater than maximum") +// Memory pages > 65536 +E(InvalidMemPages, 0x0217, "memory size must be at most 65536 pages (4GiB)") +// Invalid start function signature +E(InvalidStartFunc, 0x0218, "start function") +// Invalid lane index +E(InvalidLaneIdx, 0x0219, "invalid lane index") +// Invalid uninitialized local +E(InvalidUninitLocal, 0x021A, "uninitialized local") +// Defaultable field type required +E(InvalidNotDefaultableField, 0x021B, "field type is not defaultable") +// Defaultable array type required +E(InvalidNotDefaultableArray, 0x021C, "array type is not defaultable") +// Unpacked field type required, but got packed one +E(InvalidPackedField, 0x021D, "field is packed") +// Unpacked array type required, but got packed one +E(InvalidPackedArray, 0x021E, "array is packed") +// Packed field type required, but got unpacked one +E(InvalidUnpackedField, 0x021F, "field is unpacked") +// Packed array type required, but got unpacked one +E(InvalidUnpackedArray, 0x0220, "array is unpacked") +// Invalid Br ref type +E(InvalidBrRefType, 0x0221, "invalid br ref type") +// 2 array types not matched +E(ArrayTypesMismatch, 0x0222, "array types do not match") +// Should be numeric type in array type +E(ArrayTypesNumtypeRequired, 0x0223, "array type is not numeric or vector") +// Sub type matching or validation failed +E(InvalidSubType, 0x0224, "sub type") +// Invalid Tag type +E(InvalidTagResultType, 0x0225, "non-empty tag result type") +// @} + +// Instantiation phase +// @{ +// Module name conflicted when importing. +E(ModuleNameConflict, 0x0300, "module name conflict") +// Import matching failed +E(IncompatibleImportType, 0x0301, "incompatible import type") +// Unknown import instances +E(UnknownImport, 0x0302, "unknown import") +// Init failed when instantiating data segment +E(DataSegDoesNotFit, 0x0303, "data segment does not fit") +// Init failed when instantiating element segment +E(ElemSegDoesNotFit, 0x0304, "elements segment does not fit") +// Invalid core sort for component export +E(InvalidCoreSort, 0x0305, "invalid core sort") +E(InvalidCanonOption, 0x0306, "invalid canonical option") +// @} + +// Execution phase +// @{ +// Wrong access of instances addresses +E(WrongInstanceAddress, 0x0400, "wrong instance address") +// Wrong access of instances indices +E(WrongInstanceIndex, 0x0401, "wrong instance index") +// Instruction type not match +E(InstrTypeMismatch, 0x0402, "instruction type mismatch") +// Function signature not match when invoking +E(FuncSigMismatch, 0x0403, "function signature mismatch") +// Divide by zero +E(DivideByZero, 0x0404, "integer divide by zero") +// Integer overflow +E(IntegerOverflow, 0x0405, "integer overflow") +// Cannot do convert to integer +E(InvalidConvToInt, 0x0406, "invalid conversion to integer") +// Out of bounds table access +E(TableOutOfBounds, 0x0407, "out of bounds table access") +// Out of bounds memory access +E(MemoryOutOfBounds, 0x0408, "out of bounds memory access") +// Out of bounds array access +E(ArrayOutOfBounds, 0x0409, "out of bounds array access") +// Meet an unreachable instruction +E(Unreachable, 0x040A, "unreachable") +// Uninitialized element in table instance +E(UninitializedElement, 0x040B, "uninitialized element") +// Access undefined element in table instances +E(UndefinedElement, 0x040C, "undefined element") +// Func type mismatch in call_indirect +E(IndirectCallTypeMismatch, 0x040D, "indirect call type mismatch") +// Host function execution failed +E(HostFuncError, 0x040E, "host function failed") +// Reference type not match +E(RefTypeMismatch, 0x040F, "reference type mismatch") +// Unaligned atomic memory access +E(UnalignedAtomicAccess, 0x0410, "unaligned atomic") +// wait32/wait64 on unshared memory +E(ExpectSharedMemory, 0x0411, "expected shared memory") +// Cast null pointer to non null +E(CastNullToNonNull, 0x0412, "null reference") +// Access to null function reference +E(AccessNullFunc, 0x0413, "null function reference") +// Access to null structure reference +E(AccessNullStruct, 0x0414, "null structure reference") +// Access to null array reference +E(AccessNullArray, 0x0415, "null array reference") +// Access to null i31 reference +E(AccessNullI31, 0x0416, "null i31 reference") +// Access to null exception reference +E(AccessNullException, 0x0417, "null exception reference") +// Fail to cast reference +E(CastFailed, 0x0418, "cast failure") +// Uncaught Exception +E(UncaughtException, 0x0419, "uncaught exception") +// @} + +// Component model load phase +// @{ +// Malformed sort +E(MalformedSort, 0x0500, "malformed sort") +// Malformed alias target +E(MalformedAliasTarget, 0x0501, "malformed alias target") +// Malformed core instance +E(MalformedCoreInstance, 0x0502, "malformed core instance") +// Malformed instance +E(MalformedInstance, 0x0503, "malformed instance") +// Malformed defType +E(MalformedDefType, 0x0504, "malformed defined type") +// Malformed record type +E(MalformedRecordType, 0x0505, "malformed record type") +// Malformed variant type +E(MalformedVariantType, 0x0506, "malformed variant type") +// Malformed tuple type +E(MalformedTupleType, 0x0507, "malformed tuple type") +// Malformed flags type +E(MalformedFlagsType, 0x0508, "malformed flags type") +// Malformed canonical +E(MalformedCanonical, 0x0509, "malformed canonical") +// Unknown canonical option +E(UnknownCanonicalOption, 0x050A, "unknown canonical option") +// Malformed name +E(MalformedName, 0x050B, "malformed name") +// @} + +// Component model instantiation phase +// @{ +E(CoreInvalidExport, 0x0600, "invalid export in core module") +// @} + +#undef E +#endif // UseErrCode + +#ifdef UseWasmPhase +#define P Line + +P(WasmEdge, 0x00, "wasmedge runtime") +P(Loading, 0x01, "loading") +P(Validation, 0x02, "validation") +P(Instantiation, 0x03, "instantiation") +P(Execution, 0x04, "execution") +P(UserDefined, 0x05, "user defined") + +#undef P +#endif // UseWasmPhase + +// enum_errinfo.hpp + +#ifdef UsePtrType +#define P Line + +P(Index, "index") // Index of instances +P(Address, "address") // Absolute address + +#undef P +#endif // UsePtrType + +#ifdef UseMismatchCategory +#define M Line + +M(Alignment, "memory alignment") // Alignment in memory instructions +M(ValueType, "value type") // Value type +M(ValueTypes, "value types") // Value type list +M(Mutation, "mutation") // Const or Var +M(ExternalType, "external type") // External typing +M(FunctionType, "function type") // Function type +M(Table, "table") // Table instance +M(Memory, "memory") // Memory instance +M(Global, "global") // Global instance +M(Version, "version") // Versions + +#undef M +#endif // UseMismatchCategory + +#ifdef UseIndexCategory +#define I Line + +I(Label, "label") +I(Local, "local") +I(DefinedType, "defined type") +I(FunctionType, "function type") +I(Function, "function") +I(Table, "table") +I(Memory, "memory") +I(Global, "global") +I(Element, "element") +I(Data, "data") +I(Lane, "lane") +I(Field, "field") +I(TagType, "tag type") +I(Tag, "tag") + +#undef I +#endif // UseIndexCategory + +// enum_types.h + +#ifdef UseTypeCode +#define T Line + +T(TypeIndex, 0x00, "type_index") // 0x00 reserved for type index case +T(I32, 0x7F, "i32") // -0x01 for number type +T(I64, 0x7E, "i64") // -0x02 for number type +T(F32, 0x7D, "f32") // -0x03 for number type +T(F64, 0x7C, "f64") // -0x04 for number type +T(V128, 0x7B, "v128") // -0x05 for vector type +T(I8, 0x78, "i8") // -0x08 for packed type +T(I16, 0x77, "i16") // -0x09 for packed type +T(NullFuncRef, 0x73, "nofunc") // -0x0D for heap type +T(NullExternRef, 0x72, "noextern") // -0x0E for heap type +T(NullRef, 0x71, "none") // -0x0F for heap type +T(FuncRef, 0x70, "func") // -0x10 for heap type +T(ExternRef, 0x6F, "extern") // -0x11 for heap type +T(AnyRef, 0x6E, "any") // -0x12 for heap type +T(EqRef, 0x6D, "eq") // -0x13 for heap type +T(I31Ref, 0x6C, "i31") // -0x14 for heap type +T(StructRef, 0x6B, "struct") // -0x15 for heap type +T(ArrayRef, 0x6A, "array") // -0x16 for heap type +T(ExnRef, 0x69, "exn") // -0x17 for reference type +T(Ref, 0x64, "ref") // -0x1C for reference type +T(RefNull, 0x63, "ref_null") // -0x1D for reference type +T(Func, 0x60, "func") // -0x20 for composite type +T(Struct, 0x5F, "struct") // -0x21 for composite type +T(Array, 0x5E, "array") // -0x22 for composite type +T(Sub, 0x50, "sub") // -0x30 for sub type +T(SubFinal, 0x4F, "sub_final") // -0x31 for sub type +T(Rec, 0x4E, "rec") // -0x32 for recursive type +T(Epsilon, 0x40, "-") // -0x40 for result type +// component model types +T(String, 0x80, "string") // string type + +#undef T +#endif // UseTypeCode + +#ifdef UseValMut +#define M Line + +M(Const, 0x00, "const") +M(Var, 0x01, "var") + +#undef M +#endif // UseValMut + +#ifdef UseExternalType +#define E Line + +E(Function, 0x00U, "function") +E(Table, 0x01U, "table") +E(Memory, 0x02U, "memory") +E(Global, 0x03U, "global") +E(Tag, 0x04U, "tag") + +#undef E +#endif // UseExternalType diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_configure.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_configure.h new file mode 100644 index 0000000000000000000000000000000000000000..eb40f76c94c9bf0f1e1ea1751c1fa5e473f70824 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_configure.h @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_configure.h - Configure related enumerations -===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the definitions of configure related enumerations. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_CONFIGURE_H +#define WASMEDGE_C_API_ENUM_CONFIGURE_H + +/// WASM Proposal C enumeration. +enum WasmEdge_Proposal { +#define UseProposal +#define Line(NAME, STRING) WasmEdge_Proposal_##NAME, +#include "enum.inc" +#undef Line +#undef UseProposal +}; + +/// Host Module Registration C enumeration. +enum WasmEdge_HostRegistration { +#define UseHostRegistration +#define Line(NAME) WasmEdge_HostRegistration_##NAME, +#include "enum.inc" +#undef Line +#undef UseHostRegistration +}; + +/// AOT compiler optimization level C enumeration. +enum WasmEdge_CompilerOptimizationLevel { + // Disable as many optimizations as possible. + WasmEdge_CompilerOptimizationLevel_O0 = 0, + // Optimize quickly without destroying debuggability. + WasmEdge_CompilerOptimizationLevel_O1, + // Optimize for fast execution as much as possible without triggering + // significant incremental compile time or code size growth. + WasmEdge_CompilerOptimizationLevel_O2, + // Optimize for fast execution as much as possible. + WasmEdge_CompilerOptimizationLevel_O3, + // Optimize for small code size as much as possible without triggering + // significant incremental compile time or execution time slowdowns. + WasmEdge_CompilerOptimizationLevel_Os, + // Optimize for small code size as much as possible. + WasmEdge_CompilerOptimizationLevel_Oz +}; + +/// AOT compiler output binary format C enumeration. +enum WasmEdge_CompilerOutputFormat { + // Native dynamic library format. + WasmEdge_CompilerOutputFormat_Native = 0, + // WebAssembly with AOT compiled codes in custom sections. + WasmEdge_CompilerOutputFormat_Wasm +}; + +#endif // WASMEDGE_C_API_ENUM_CONFIGURE_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_errcode.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_errcode.h new file mode 100644 index 0000000000000000000000000000000000000000..68292cbcd960105fcf6f53699407657f4c5b1d13 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_errcode.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_errcode.h - Error code enumerations ----------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the enumerations of WasmEdge error code. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_ERRCODE_H +#define WASMEDGE_C_API_ENUM_ERRCODE_H + +/// Error category C enumeration. +enum WasmEdge_ErrCategory { +#define UseErrCategory +#define Line(NAME, VALUE) WasmEdge_ErrCategory_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseErrCategory +}; + +/// Error code C enumeration. +enum WasmEdge_ErrCode { +#define UseErrCode +#define Line(NAME, VALUE, STRING) WasmEdge_ErrCode_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseErrCode +}; + +#endif // WASMEDGE_C_API_ENUM_ERRCODE_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_types.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_types.h new file mode 100644 index 0000000000000000000000000000000000000000..4b89c003f2e6aaed143c22667c0a51a62315b1b8 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/enum_types.h @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_types.h - WASM types related enumerations ----===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the definitions of WASM types related enumerations. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_TYPES_H +#define WASMEDGE_C_API_ENUM_TYPES_H + +/// WASM Type code C enumeration. +enum WasmEdge_TypeCode { +#define UseTypeCode +#define Line(NAME, VALUE, STRING) WasmEdge_TypeCode_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseTypeCode +}; + +/// WASM Mutability C enumeration. +enum WasmEdge_Mutability { +#define UseValMut +#define Line(NAME, VALUE, STRING) WasmEdge_Mutability_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseValMut +}; + +/// WASM External type C enumeration. +enum WasmEdge_ExternalType { +#define UseExternalType +#define Line(NAME, VALUE, STRING) WasmEdge_ExternalType_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseExternalType +}; + +#endif // WASMEDGE_C_API_ENUM_TYPES_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/int128.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/int128.h new file mode 100644 index 0000000000000000000000000000000000000000..c4706fb22b4104231b67d381ac2aeb6a740fc84d --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/int128.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/int128.h - WasmEdge C API --------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the int128 definitions of the WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_INT128_H +#define WASMEDGE_C_API_INT128_H + +#if defined(__x86_64__) || defined(__aarch64__) || \ + (defined(__riscv) && __riscv_xlen == 64) +typedef unsigned __int128 uint128_t; +typedef __int128 int128_t; +#else +typedef struct uint128_t { + uint64_t Low; + uint64_t High; +} uint128_t; + +typedef struct int128_t { + uint64_t Low; + int64_t High; +} int128_t; +#endif + +#endif /// WASMEDGE_C_API_INT128_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/version.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/version.h new file mode 100644 index 0000000000000000000000000000000000000000..2e092f7dfa0ec2d217602a331f2c802d38757539 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/version.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/version.h - WasmEdge C API -------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the version definitions of the WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_VERSION_H +#define WASMEDGE_C_API_VERSION_H + +// WasmEdge version. +#define WASMEDGE_VERSION "0.14.1-rc.3" +#define WASMEDGE_VERSION_MAJOR 0 +#define WASMEDGE_VERSION_MINOR 14 +#define WASMEDGE_VERSION_PATCH 1 + +#define WasmEdge_Plugin_CurrentAPIVersion 4 + +#endif // WASMEDGE_C_API_VERSION_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/wasmedge.h b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/wasmedge.h new file mode 100644 index 0000000000000000000000000000000000000000..8585c2f734cb38410f316fdfbe64d48180cfcd7b --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/include/wasmedge/wasmedge.h @@ -0,0 +1,4183 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/wasmedge.h - WasmEdge C API ------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the function declarations of WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_H +#define WASMEDGE_C_API_H + +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \ + defined(__TOS_WIN__) || defined(__WINDOWS__) +#ifdef WASMEDGE_COMPILE_LIBRARY +#define WASMEDGE_CAPI_EXPORT __declspec(dllexport) +#else +#define WASMEDGE_CAPI_EXPORT __declspec(dllimport) +#endif // WASMEDGE_COMPILE_LIBRARY +#ifdef WASMEDGE_PLUGIN +#define WASMEDGE_CAPI_PLUGIN_EXPORT __declspec(dllexport) +#else +#define WASMEDGE_CAPI_PLUGIN_EXPORT __declspec(dllimport) +#endif // WASMEDGE_PLUGIN +#else +#define WASMEDGE_CAPI_EXPORT __attribute__((visibility("default"))) +#define WASMEDGE_CAPI_PLUGIN_EXPORT __attribute__((visibility("default"))) +#endif // _WIN32 + +#include +#include + +#include "wasmedge/enum_configure.h" +#include "wasmedge/enum_errcode.h" +#include "wasmedge/enum_types.h" +#include "wasmedge/int128.h" +#include "wasmedge/version.h" + +/// WasmEdge WASM value type struct. +typedef struct WasmEdge_ValType { + // This struct contains the raw data which describes the value type in WASM. + // Developers should use the corresponding `WasmEdge_ValueTypeGen` functions + // to generate this struct. + uint8_t Data[8]; +} WasmEdge_ValType; + +/// WasmEdge WASM value struct. +typedef struct WasmEdge_Value { + uint128_t Value; + // The value type `Type` is used in the parameters or returns of invoking + // functions. Developers should use the corresponding `WasmEdge_ValueGen` + // functions to generate this struct, and the `WasmEdge_ValueGet` functions to + // retrieve the value from this struct. + WasmEdge_ValType Type; +} WasmEdge_Value; + +/// WasmEdge string struct. +typedef struct WasmEdge_String { + uint32_t Length; + const char *Buf; +} WasmEdge_String; + +/// WasmEdge bytes struct. +typedef struct WasmEdge_Bytes { + uint32_t Length; + const uint8_t *Buf; +} WasmEdge_Bytes; + +/// WasmEdge result struct. +typedef struct WasmEdge_Result { + uint32_t Code; +} WasmEdge_Result; +#ifdef __cplusplus +#define WasmEdge_Result_Success (WasmEdge_Result{/* Code */ 0x00}) +#define WasmEdge_Result_Terminate (WasmEdge_Result{/* Code */ 0x01}) +#define WasmEdge_Result_Fail (WasmEdge_Result{/* Code */ 0x02}) +#else +#define WasmEdge_Result_Success ((WasmEdge_Result){.Code = 0x00}) +#define WasmEdge_Result_Terminate ((WasmEdge_Result){.Code = 0x01}) +#define WasmEdge_Result_Fail ((WasmEdge_Result){.Code = 0x02}) +#endif +/// Struct of WASM limit. +typedef struct WasmEdge_Limit { + /// Boolean to describe has max value or not. + bool HasMax; + /// Boolean to describe is shared memory or not. + bool Shared; + /// Minimum value. + uint32_t Min; + /// Maximum value. Will be ignored if the `HasMax` is false. + uint32_t Max; +} WasmEdge_Limit; + +/// Opaque struct of WasmEdge configure. +typedef struct WasmEdge_ConfigureContext WasmEdge_ConfigureContext; + +/// Opaque struct of WasmEdge statistics. +typedef struct WasmEdge_StatisticsContext WasmEdge_StatisticsContext; + +/// Opaque struct of WasmEdge AST module. +typedef struct WasmEdge_ASTModuleContext WasmEdge_ASTModuleContext; + +/// Opaque struct of WasmEdge function type. +typedef struct WasmEdge_FunctionTypeContext WasmEdge_FunctionTypeContext; + +/// Opaque struct of WasmEdge memory type. +typedef struct WasmEdge_MemoryTypeContext WasmEdge_MemoryTypeContext; + +/// Opaque struct of WasmEdge table type. +typedef struct WasmEdge_TableTypeContext WasmEdge_TableTypeContext; + +/// Opaque struct of WasmEdge tag type. +typedef struct WasmEdge_TagTypeContext WasmEdge_TagTypeContext; + +/// Opaque struct of WasmEdge global type. +typedef struct WasmEdge_GlobalTypeContext WasmEdge_GlobalTypeContext; + +/// Opaque struct of WasmEdge import type. +typedef struct WasmEdge_ImportTypeContext WasmEdge_ImportTypeContext; + +/// Opaque struct of WasmEdge export type. +typedef struct WasmEdge_ExportTypeContext WasmEdge_ExportTypeContext; + +/// Opaque struct of WasmEdge AOT compiler. +typedef struct WasmEdge_CompilerContext WasmEdge_CompilerContext; + +/// Opaque struct of WasmEdge loader. +typedef struct WasmEdge_LoaderContext WasmEdge_LoaderContext; + +/// Opaque struct of WasmEdge validator. +typedef struct WasmEdge_ValidatorContext WasmEdge_ValidatorContext; + +/// Opaque struct of WasmEdge executor. +typedef struct WasmEdge_ExecutorContext WasmEdge_ExecutorContext; + +/// Opaque struct of WasmEdge store. +typedef struct WasmEdge_StoreContext WasmEdge_StoreContext; + +/// Opaque struct of WasmEdge module instance. +typedef struct WasmEdge_ModuleInstanceContext WasmEdge_ModuleInstanceContext; + +/// Opaque struct of WasmEdge function instance. +typedef struct WasmEdge_FunctionInstanceContext + WasmEdge_FunctionInstanceContext; + +/// Opaque struct of WasmEdge table instance. +typedef struct WasmEdge_TableInstanceContext WasmEdge_TableInstanceContext; + +/// Opaque struct of WasmEdge memory instance. +typedef struct WasmEdge_MemoryInstanceContext WasmEdge_MemoryInstanceContext; + +/// Opaque struct of WasmEdge tag instance. +typedef struct WasmEdge_TagInstanceContext WasmEdge_TagInstanceContext; + +/// Opaque struct of WasmEdge global instance. +typedef struct WasmEdge_GlobalInstanceContext WasmEdge_GlobalInstanceContext; + +/// Opaque struct of WasmEdge calling frame. +typedef struct WasmEdge_CallingFrameContext WasmEdge_CallingFrameContext; + +/// Opaque struct of WasmEdge asynchronous result. +typedef struct WasmEdge_Async WasmEdge_Async; + +/// Opaque struct of WasmEdge VM. +typedef struct WasmEdge_VMContext WasmEdge_VMContext; + +/// Opaque struct of WasmEdge Plugin. +typedef struct WasmEdge_PluginContext WasmEdge_PluginContext; + +/// Type of option value. +typedef enum WasmEdge_ProgramOptionType { + /// No option value. + WasmEdge_ProgramOptionType_None, + /// Boolean value. + WasmEdge_ProgramOptionType_Toggle, + WasmEdge_ProgramOptionType_Int8, + WasmEdge_ProgramOptionType_Int16, + WasmEdge_ProgramOptionType_Int32, + WasmEdge_ProgramOptionType_Int64, + WasmEdge_ProgramOptionType_UInt8, + WasmEdge_ProgramOptionType_UInt16, + WasmEdge_ProgramOptionType_UInt32, + WasmEdge_ProgramOptionType_UInt64, + WasmEdge_ProgramOptionType_Float, + WasmEdge_ProgramOptionType_Double, + /// WasmEdge_String. + WasmEdge_ProgramOptionType_String, +} WasmEdge_ProgramOptionType; + +/// Program option for plugins. +typedef struct WasmEdge_ProgramOption { + const char *Name; + const char *Description; + WasmEdge_ProgramOptionType Type; + void *Storage; + const void *DefaultValue; +} WasmEdge_ProgramOption; + +/// Module descriptor for plugins. +typedef struct WasmEdge_ModuleDescriptor { + const char *Name; + const char *Description; + WasmEdge_ModuleInstanceContext *(*Create)( + const struct WasmEdge_ModuleDescriptor *); +} WasmEdge_ModuleDescriptor; + +/// Version data for plugins. +typedef struct WasmEdge_PluginVersionData { + uint32_t Major; + uint32_t Minor; + uint32_t Patch; + uint32_t Build; +} WasmEdge_PluginVersionData; + +/// Plugin descriptor for plugins. +typedef struct WasmEdge_PluginDescriptor { + const char *Name; + const char *Description; + uint32_t APIVersion; + WasmEdge_PluginVersionData Version; + uint32_t ModuleCount; + uint32_t ProgramOptionCount; + WasmEdge_ModuleDescriptor *ModuleDescriptions; + WasmEdge_ProgramOption *ProgramOptions; +} WasmEdge_PluginDescriptor; + +#ifdef __cplusplus +extern "C" { +#endif + +// >>>>>>>> WasmEdge version functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the version string of the WasmEdge C API. +/// +/// The returned string must __NOT__ be destroyed. +/// +/// \returns NULL-terminated C string of version. +WASMEDGE_CAPI_EXPORT extern const char *WasmEdge_VersionGet(void); + +/// Get the major version value of the WasmEdge C API. +/// +/// \returns Value of the major version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetMajor(void); + +/// Get the minor version value of the WasmEdge C API. +/// +/// \returns Value of the minor version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetMinor(void); + +/// Get the patch version value of the WasmEdge C API. +/// +/// \returns Value of the patch version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetPatch(void); + +// <<<<<<<< WasmEdge version functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge logging functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Set the logging system to filter to error level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogSetErrorLevel(void); + +/// Set the logging system to filter to debug level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogSetDebugLevel(void); + +/// Set the logging system off. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogOff(void); + +// <<<<<<<< WasmEdge logging functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge valtype functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Generate the I32 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the I32 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenI32(void); + +/// Generate the I64 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the I64 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenI64(void); + +/// Generate the F32 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the F32 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenF32(void); + +/// Generate the F64 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the F64 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenF64(void); + +/// Generate the V128 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the V128 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenV128(void); + +/// Generate the FuncRef WASM value type. +/// +/// \returns WasmEdge_ValType struct with the FuncRef value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenFuncRef(void); + +/// Generate the ExternRef WASM value type. +/// +/// \returns WasmEdge_ValType struct with the ExternRef value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenExternRef(void); + +/// Compare the two WasmEdge_ValType objects. +/// +/// \param ValType1 the first WasmEdge_ValType object to compare. +/// \param ValType2 the second WasmEdge_ValType object to compare. +/// +/// \returns true if the content of two WasmEdge_ValType objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsEqual(const WasmEdge_ValType ValType1, + const WasmEdge_ValType ValType2); + +/// Specify the WASM value type is an I32 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an I32, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsI32(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is an I64 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an I64, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsI64(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a F32 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a F32, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsF32(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a F64 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a F64, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsF64(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a V128 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a V128, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsV128(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a FuncRef or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a FuncRef, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsFuncRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is an ExternRef or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an ExternRef, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsExternRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a Ref (includes nullable and non-nullable) or +/// not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a Ref, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a nullable Ref or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a nullable Ref, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsRefNull(const WasmEdge_ValType ValType); + +// <<<<<<<< WasmEdge valtype functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge value functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Generate the I32 WASM value. +/// +/// \param Val the I32 value. +/// +/// \returns WasmEdge_Value struct with the I32 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenI32(const int32_t Val); + +/// Generate the I64 WASM value. +/// +/// \param Val the I64 value. +/// +/// \returns WasmEdge_Value struct with the I64 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenI64(const int64_t Val); + +/// Generate the F32 WASM value. +/// +/// \param Val the F32 value. +/// +/// \returns WasmEdge_Value struct with the F32 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenF32(const float Val); + +/// Generate the F64 WASM value. +/// +/// \param Val the F64 value. +/// +/// \returns WasmEdge_Value struct with the F64 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenF64(const double Val); + +/// Generate the V128 WASM value. +/// +/// \param Val the V128 value. +/// +/// \returns WasmEdge_Value struct with the V128 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenV128(const int128_t Val); + +/// Generate the function reference WASM value. +/// +/// The values generated by this function are only meaningful when the +/// `WasmEdge_Proposal_BulkMemoryOperations` or the +/// `WasmEdge_Proposal_ReferenceTypes` turns on in configuration. +/// +/// \param Cxt the function instance context to convert to the reference. +/// +/// \returns WasmEdge_Value struct with the function reference. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenFuncRef(const WasmEdge_FunctionInstanceContext *Cxt); + +/// Generate the function reference WASM value. +/// +/// The values generated by this function are only meaningful when the +/// `WasmEdge_Proposal_ReferenceTypes` turns on in configuration. +/// +/// \param Ref the reference to the external object. +/// +/// \returns WasmEdge_Value struct with the external reference. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenExternRef(void *Ref); + +/// Retrieve the I32 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns I32 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int32_t +WasmEdge_ValueGetI32(const WasmEdge_Value Val); + +/// Retrieve the I64 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns I64 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int64_t +WasmEdge_ValueGetI64(const WasmEdge_Value Val); + +/// Retrieve the F32 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns F32 value in the input struct. +WASMEDGE_CAPI_EXPORT extern float +WasmEdge_ValueGetF32(const WasmEdge_Value Val); + +/// Retrieve the F64 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns F64 value in the input struct. +WASMEDGE_CAPI_EXPORT extern double +WasmEdge_ValueGetF64(const WasmEdge_Value Val); + +/// Retrieve the V128 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns V128 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int128_t +WasmEdge_ValueGetV128(const WasmEdge_Value Val); + +/// Specify the WASM value is a null reference or not. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns true if the value is a null reference, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValueIsNullRef(const WasmEdge_Value Val); + +/// Retrieve the function instance context from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns pointer to function instance context in the input struct. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionInstanceContext * +WasmEdge_ValueGetFuncRef(const WasmEdge_Value Val); + +/// Retrieve the external reference from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns external reference in the input struct. +WASMEDGE_CAPI_EXPORT extern void * +WasmEdge_ValueGetExternRef(const WasmEdge_Value Val); + +// <<<<<<<< WasmEdge value functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge string functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_String with the C string. +/// +/// The caller owns the object and should call `WasmEdge_StringDelete` to +/// destroy it. This function only supports the C string with NULL termination. +/// If the input string may have `\0` character, please use the +/// `WasmEdge_StringCreateByBuffer` instead. +/// +/// \param Str the NULL-terminated C string to copy into the WasmEdge_String +/// object. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed or +/// the input string is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringCreateByCString(const char *Str); + +/// Creation of the WasmEdge_String with the buffer and its length. +/// +/// The caller owns the object and should call `WasmEdge_StringDelete` to +/// destroy it. +/// +/// \param Buf the buffer to wrap to the WasmEdge_String object. +/// \param Len the buffer length. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed or +/// the input buffer is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringCreateByBuffer(const char *Buf, const uint32_t Len); + +/// Create the WasmEdge_String wraps to the buffer. +/// +/// This function creates a `WasmEdge_String` object which wraps to the input +/// buffer. The caller should guarantee the life cycle of the input buffer, and +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Buf the buffer to copy into the WasmEdge_String object. +/// \param Len the buffer length. +/// +/// \returns string object refer to the input buffer with its length. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringWrap(const char *Buf, const uint32_t Len); + +/// Compare the two WasmEdge_String objects. +/// +/// \param Str1 the first WasmEdge_String object to compare. +/// \param Str2 the second WasmEdge_String object to compare. +/// +/// \returns true if the content of two WasmEdge_String objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_StringIsEqual(const WasmEdge_String Str1, const WasmEdge_String Str2); + +/// Copy the content of WasmEdge_String object to the buffer. +/// +/// This function copy at most `Len` characters from the `WasmEdge_String` +/// object to the destination buffer. If the string length is less than `Len` +/// characters long, the remainder of the buffer is filled with `\0' characters. +/// Otherwise, the destination is not terminated. +/// +/// \param Str the source WasmEdge_String object to copy. +/// \param Buf the buffer to fill the string content. +/// \param Len the buffer length. +/// +/// \returns the copied length of string. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StringCopy(const WasmEdge_String Str, char *Buf, const uint32_t Len); + +/// Deletion of the WasmEdge_String. +/// +/// After calling this function, the resources in the WasmEdge_String object +/// will be released and the object should __NOT__ be used. +/// +/// \param Str the WasmEdge_String object to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_StringDelete(WasmEdge_String Str); + +// <<<<<<<< WasmEdge string functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge bytes functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_Bytes with the buffer and its length. +/// +/// The caller owns the object and should call `WasmEdge_BytesDelete` to destroy +/// it. +/// +/// \param Buf the buffer to copy into the WasmEdge_Bytes object. +/// \param Len the buffer length. +/// +/// \returns bytes object. Length will be 0 and Buf will be NULL if failed or +/// the input buffer is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Bytes +WasmEdge_BytesCreate(const uint8_t *Buf, const uint32_t Len); + +/// Create the WasmEdge_Bytes wraps to the buffer. +/// +/// This function creates a `WasmEdge_Bytes` object which wraps to the input +/// buffer. The caller should guarantee the life cycle of the input buffer, and +/// should __NOT__ call the `WasmEdge_BytesDelete`. +/// +/// \param Buf the buffer to wrap to the WasmEdge_Bytes object. +/// \param Len the buffer length. +/// +/// \returns bytes object refer to the input buffer with its length. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Bytes +WasmEdge_BytesWrap(const uint8_t *Buf, const uint32_t Len); + +/// Deletion of the WasmEdge_Bytes. +/// +/// After calling this function, the resources in the WasmEdge_Bytes object +/// will be released and the object should __NOT__ be used. +/// +/// \param Bytes the WasmEdge_Bytes object to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_BytesDelete(WasmEdge_Bytes Bytes); + +// <<<<<<<< WasmEdge bytes functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge result functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Check the result is a success or not. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns true if the error code is WasmEdge_Result_Success or +/// WasmEdge_Result_Terminate, false for others. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ResultOK(const WasmEdge_Result Res); + +/// Generate the result with code. +/// +/// \param Category the WasmEdge_ErrCategory to specify the error category. +/// \param Code the 24-bit length error code. The data exceeds 24 bits will be +/// stripped. +/// +/// \returns WasmEdge_Result struct with the given data. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ResultGen(const enum WasmEdge_ErrCategory Category, + const uint32_t Code); + +/// Get the result code. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns result code (24-bit size data) in the WasmEdge_Result struct. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ResultGetCode(const WasmEdge_Result Res); + +/// Get the error category. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns error category in the WasmEdge_Result struct. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ErrCategory +WasmEdge_ResultGetCategory(const WasmEdge_Result Res); + +/// Get the result message. +/// +/// The returned string must __NOT__ be destroyed. +/// If the error category of the result is __NOT__ `WasmEdge_ErrCategory_WASM`, +/// the message will always be "user defined error code". +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns NULL-terminated C string of the corresponding error message. +WASMEDGE_CAPI_EXPORT extern const char * +WasmEdge_ResultGetMessage(const WasmEdge_Result Res); + +// <<<<<<<< WasmEdge result functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge limit functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Compare the two WasmEdge_Limit objects. +/// +/// \param Lim1 the first WasmEdge_Limit object to compare. +/// \param Lim2 the second WasmEdge_Limit object to compare. +/// +/// \returns true if the content of two WasmEdge_Limit objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_LimitIsEqual(const WasmEdge_Limit Lim1, const WasmEdge_Limit Lim2); + +// <<<<<<<< WasmEdge limit functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge configure functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ConfigureContext. +/// +/// The caller owns the object and should call `WasmEdge_ConfigureDelete` to +/// destroy it. +/// +/// \returns pointer to the context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ConfigureContext * +WasmEdge_ConfigureCreate(void); + +/// Add a proposal setting into the WasmEdge_ConfigureContext. +/// +/// For turning on a specific WASM proposal in VM, loader, or compiler contexts, +/// etc., you can set the proposal value into the WasmEdge_ConfigureContext and +/// create the VM, loader, or compiler contexts, etc. with this context. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_BulkMemoryOperations); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_ReferenceTypes); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_SIMD); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to add the proposal value. +/// \param Prop the proposal value. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureAddProposal(WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Remove a proposal setting in the WasmEdge_ConfigureContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to remove the proposal. +/// \param Prop the proposal value. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureRemoveProposal(WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Check if a proposal setting exists in the WasmEdge_ConfigureContext or not. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to check the proposal value. +/// \param Prop the proposal value. +/// +/// \returns true if the proposal setting exists, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureHasProposal(const WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Add a built-in host registration setting into WasmEdge_ConfigureContext. +/// +/// For turning on the Wasi support in `WasmEdge_VMContext`, you can set the +/// built-in host registration value into the `WasmEdge_ConfigureContext` and +/// create VM with this context. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddHostRegistration(Conf, WasmEdge_HostRegistration_Wasi); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to add built-in host registration. +/// \param Host the built-in host registration value. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureAddHostRegistration( + WasmEdge_ConfigureContext *Cxt, const enum WasmEdge_HostRegistration Host); + +/// Remove a built-in host registration setting in the +/// WasmEdge_ConfigureContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to remove the host +/// pre-registration. +/// \param Host the built-in host registration value. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureRemoveHostRegistration( + WasmEdge_ConfigureContext *Cxt, const enum WasmEdge_HostRegistration Host); + +/// Check if a built-in host registration setting exists in the +/// WasmEdge_ConfigureContext or not. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to check the host pre-registration. +/// \param Host the built-in host registration value. +/// +/// \returns true if the built-in host registration setting exists, false if +/// not. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureHasHostRegistration( + const WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_HostRegistration Host); + +/// Set the page limit of memory instances. +/// +/// Limit the page count (64KiB per page) in memory instances. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the maximum page count. +/// \param Page the maximum page count. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetMaxMemoryPage(WasmEdge_ConfigureContext *Cxt, + const uint32_t Page); + +/// Get the setting of the page limit of memory instances. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the maximum page count +/// setting. +/// +/// \returns the page count limitation value. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ConfigureGetMaxMemoryPage(const WasmEdge_ConfigureContext *Cxt); + +/// Set the force interpreter mode execution option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsForceInterpreter the boolean value to determine to forcibly run +/// WASM in interpreter mode or not. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetForceInterpreter(WasmEdge_ConfigureContext *Cxt, + const bool IsForceInterpreter); + +/// Get the force interpreter mode execution option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to forcibly run WASM in interpreter +/// mode or not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureIsForceInterpreter(const WasmEdge_ConfigureContext *Cxt); + +/// Set the option of enabling/disabling AF_UNIX support in the WASI socket. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param EnableAFUNIX the boolean value to determine to enable +/// the AF_UNIX support in the WASI socket or not. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetAllowAFUNIX(WasmEdge_ConfigureContext *Cxt, + const bool EnableAFUNIX); + +/// Get the AllowAFUNIX option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to enable AF_UNIX support in the +/// WASI socket or not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureIsAllowAFUNIX(const WasmEdge_ConfigureContext *Cxt); + +/// Set the optimization level of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the optimization level. +/// \param Level the AOT compiler optimization level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureCompilerSetOptimizationLevel( + WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_CompilerOptimizationLevel Level); + +/// Get the optimization level of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the optimization level. +/// +/// \returns the AOT compiler optimization level. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_CompilerOptimizationLevel +WasmEdge_ConfigureCompilerGetOptimizationLevel( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the output binary format of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the output binary format. +/// \param Format the AOT compiler output binary format. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureCompilerSetOutputFormat( + WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_CompilerOutputFormat Format); + +/// Get the output binary format of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the output binary format. +/// +/// \returns the AOT compiler output binary format. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_CompilerOutputFormat +WasmEdge_ConfigureCompilerGetOutputFormat(const WasmEdge_ConfigureContext *Cxt); + +/// Set the dump IR option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsDump the boolean value to determine to dump IR or not when +/// compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetDumpIR(WasmEdge_ConfigureContext *Cxt, + const bool IsDump); + +/// Get the dump IR option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to dump IR or not when compilation +/// in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsDumpIR(const WasmEdge_ConfigureContext *Cxt); + +/// Set the generic binary option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsGeneric the boolean value to determine to generate the generic +/// binary or not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetGenericBinary(WasmEdge_ConfigureContext *Cxt, + const bool IsGeneric); + +/// Get the generic binary option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to generate the generic binary or +/// not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsGenericBinary(const WasmEdge_ConfigureContext *Cxt); + +/// Set the interruptible option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsInterruptible the boolean value to determine to generate +/// interruptible binary or not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetInterruptible(WasmEdge_ConfigureContext *Cxt, + const bool IsInterruptible); + +/// Get the interruptible option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to generate interruptible binary or +/// not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsInterruptible(const WasmEdge_ConfigureContext *Cxt); + +/// Set the instruction counting option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsCount the boolean value to determine to support instruction +/// counting when execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetInstructionCounting( + WasmEdge_ConfigureContext *Cxt, const bool IsCount); + +/// Get the instruction counting option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support instruction counting when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureStatisticsIsInstructionCounting( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the cost measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsMeasure the boolean value to determine to support cost measuring +/// when execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetCostMeasuring(WasmEdge_ConfigureContext *Cxt, + const bool IsMeasure); + +/// Get the cost measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support cost measuring when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureStatisticsIsCostMeasuring( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the time measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsMeasure the boolean value to determine to support time when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetTimeMeasuring(WasmEdge_ConfigureContext *Cxt, + const bool IsMeasure); + +/// Get the time measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support time measuring when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureStatisticsIsTimeMeasuring( + const WasmEdge_ConfigureContext *Cxt); + +/// Deletion of the WasmEdge_ConfigureContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureDelete(WasmEdge_ConfigureContext *Cxt); + +// <<<<<<<< WasmEdge configure functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge statistics functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_StatisticsContext. +/// +/// The caller owns the object and should call `WasmEdge_StatisticsDelete` to +/// destroy it. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StatisticsContext * +WasmEdge_StatisticsCreate(void); + +/// Get the instruction count in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the instruction count in total execution. +WASMEDGE_CAPI_EXPORT extern uint64_t +WasmEdge_StatisticsGetInstrCount(const WasmEdge_StatisticsContext *Cxt); + +/// Get the instruction count per second in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the instruction count per second. +WASMEDGE_CAPI_EXPORT extern double +WasmEdge_StatisticsGetInstrPerSecond(const WasmEdge_StatisticsContext *Cxt); + +/// Get the total cost in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the total cost. +WASMEDGE_CAPI_EXPORT extern uint64_t +WasmEdge_StatisticsGetTotalCost(const WasmEdge_StatisticsContext *Cxt); + +/// Set the costs of instructions. +/// +/// \param Cxt the WasmEdge_StatisticsContext to set the cost table. +/// \param CostArr the cost table array. +/// \param Len the length of the cost table array. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsSetCostTable(WasmEdge_StatisticsContext *Cxt, + uint64_t *CostArr, const uint32_t Len); + +/// Set the cost limit in execution. +/// +/// The WASM execution will be aborted if the instruction costs exceeded the +/// limit and the ErrCode::Value::CostLimitExceeded will be returned. +/// +/// \param Cxt the WasmEdge_StatisticsContext to set the cost table. +/// \param Limit the cost limit. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsSetCostLimit(WasmEdge_StatisticsContext *Cxt, + const uint64_t Limit); + +/// Clear all data in the WasmEdge_StatisticsContext. +/// +/// \param Cxt the WasmEdge_StatisticsContext to clear. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsClear(WasmEdge_StatisticsContext *Cxt); + +/// Deletion of the WasmEdge_StatisticsContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_StatisticsContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsDelete(WasmEdge_StatisticsContext *Cxt); + +// <<<<<<<< WasmEdge statistics functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge AST module functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the length of imports list of the AST module. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// +/// \returns length of the imports list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListImportsLength(const WasmEdge_ASTModuleContext *Cxt); + +/// List the imports of the AST module. +/// +/// If the `Imports` buffer length is smaller than the result of the imports +/// list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// \param [out] Imports the import type contexts buffer. Can be NULL if import +/// types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListImports(const WasmEdge_ASTModuleContext *Cxt, + const WasmEdge_ImportTypeContext **Imports, + const uint32_t Len); + +/// Get the length of exports list of the AST module. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// +/// \returns length of the exports list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListExportsLength(const WasmEdge_ASTModuleContext *Cxt); + +/// List the exports of the AST module. +/// +/// If the `Exports` buffer length is smaller than the result of the exports +/// list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// \param [out] Exports the export type contexts buffer. Can be NULL if export +/// types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListExports(const WasmEdge_ASTModuleContext *Cxt, + const WasmEdge_ExportTypeContext **Exports, + const uint32_t Len); + +/// Deletion of the WasmEdge_ASTModuleContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ASTModuleContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ASTModuleDelete(WasmEdge_ASTModuleContext *Cxt); + +// <<<<<<<< WasmEdge AST module functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge function type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_FunctionTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_FunctionTypeDelete` to +/// destroy it. +/// +/// \param ParamList the value types list of parameters. NULL if the length is +/// 0. +/// \param ParamLen the ParamList buffer length. +/// \param ReturnList the value types list of returns. NULL if the length is 0. +/// \param ReturnLen the ReturnList buffer length. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionTypeContext * +WasmEdge_FunctionTypeCreate(const WasmEdge_ValType *ParamList, + const uint32_t ParamLen, + const WasmEdge_ValType *ReturnList, + const uint32_t ReturnLen); + +/// Get the parameter types list length from the WasmEdge_FunctionTypeContext. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// +/// \returns the parameter types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_FunctionTypeGetParametersLength( + const WasmEdge_FunctionTypeContext *Cxt); + +/// Get the parameter types list from the WasmEdge_FunctionTypeContext. +/// +/// If the `List` buffer length is smaller than the length of the parameter type +/// list, the overflowed values will be discarded. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// \param [out] List the WasmEdge_ValType buffer to fill the parameter value +/// types. +/// \param Len the value type buffer length. +/// +/// \returns the actual parameter types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetParameters(const WasmEdge_FunctionTypeContext *Cxt, + WasmEdge_ValType *List, const uint32_t Len); + +/// Get the return types list length from the WasmEdge_FunctionTypeContext. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// +/// \returns the return types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetReturnsLength(const WasmEdge_FunctionTypeContext *Cxt); + +/// Get the return types list from the WasmEdge_FunctionTypeContext. +/// +/// If the `List` buffer length is smaller than the length of the return type +/// list, the overflowed values will be discarded. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// \param [out] List the WasmEdge_ValType buffer to fill the return value +/// types. +/// \param Len the value type buffer length. +/// +/// \returns the actual return types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetReturns(const WasmEdge_FunctionTypeContext *Cxt, + WasmEdge_ValType *List, const uint32_t Len); + +/// Deletion of the WasmEdge_FunctionTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_FunctionTypeDelete(WasmEdge_FunctionTypeContext *Cxt); + +// <<<<<<<< WasmEdge function type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge table type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_TableTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_TableTypeDelete` to +/// destroy it. +/// +/// \param RefType the value type of the table type. This value type should be a +/// reference type, or this function will fail. +/// \param Limit the limit struct of the table type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableTypeContext * +WasmEdge_TableTypeCreate(const WasmEdge_ValType RefType, + const WasmEdge_Limit Limit); + +/// Get the reference type from a table type. +/// +/// \param Cxt the WasmEdge_TableTypeContext. +/// +/// \returns the value type of the table type. This value type will must be a +/// reference type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType +WasmEdge_TableTypeGetRefType(const WasmEdge_TableTypeContext *Cxt); + +/// Get the limit from a table type. +/// +/// \param Cxt the WasmEdge_TableTypeContext. +/// +/// \returns the limit struct of the table type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Limit +WasmEdge_TableTypeGetLimit(const WasmEdge_TableTypeContext *Cxt); + +/// Deletion of the WasmEdge_TableTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_TableTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_TableTypeDelete(WasmEdge_TableTypeContext *Cxt); + +// <<<<<<<< WasmEdge table type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge memory type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_MemoryTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_MemoryTypeDelete` to +/// destroy it. +/// +/// \param Limit the limit struct of the memory type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryTypeContext * +WasmEdge_MemoryTypeCreate(const WasmEdge_Limit Limit); + +/// Get the limit from a memory type. +/// +/// \param Cxt the WasmEdge_MemoryTypeContext. +/// +/// \returns the limit struct of the memory type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Limit +WasmEdge_MemoryTypeGetLimit(const WasmEdge_MemoryTypeContext *Cxt); + +/// Deletion of the WasmEdge_MemoryTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_MemoryTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_MemoryTypeDelete(WasmEdge_MemoryTypeContext *Cxt); + +// <<<<<<<< WasmEdge memory type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge tag type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the function type from a tag type. +/// +/// \param Cxt the WasmEdge_TagTypeContext. +/// +/// \returns pointer to function type context of the tag type, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_TagTypeGetFunctionType(const WasmEdge_TagTypeContext *Cxt); + +// <<<<<<<< WasmEdge tag type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge global type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_GlobalTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_GlobalTypeDelete` to +/// destroy it. +/// +/// \param ValType the value type of the global type. +/// \param Mut the mutation of the global type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalTypeContext * +WasmEdge_GlobalTypeCreate(const WasmEdge_ValType ValType, + const enum WasmEdge_Mutability Mut); + +/// Get the value type from a global type. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext. +/// +/// \returns the value type of the global type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType +WasmEdge_GlobalTypeGetValType(const WasmEdge_GlobalTypeContext *Cxt); + +/// Get the mutability from a global type. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext. +/// +/// \returns the mutability of the global type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_Mutability +WasmEdge_GlobalTypeGetMutability(const WasmEdge_GlobalTypeContext *Cxt); + +/// Deletion of the WasmEdge_GlobalTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_GlobalTypeDelete(WasmEdge_GlobalTypeContext *Cxt); + +// <<<<<<<< WasmEdge global type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge import type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the external type from an import type. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns the external type of the import type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ExternalType +WasmEdge_ImportTypeGetExternalType(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the module name from an import type. +/// +/// The returned string object is linked to the module name of the import type, +/// and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ImportTypeGetModuleName(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external name from an import type. +/// +/// The returned string object is linked to the external name of the import +/// type, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ImportTypeGetExternalName(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is function type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The function type context links to the function type in the import type +/// context and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the function type. NULL if failed or the external type of the +/// import type is not `WasmEdge_ExternalType_Function`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_ImportTypeGetFunctionType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is table type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The table type context links to the table type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the table type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Table`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_ImportTypeGetTableType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is memory type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The memory type context links to the memory type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the memory type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Memory`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_ImportTypeGetMemoryType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is tag type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The tag type context links to the tag type in the import type context +/// and the AST module context. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the tag type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_TagType`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_ImportTypeGetTagType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is global type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The global type context links to the global type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the global type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Global`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_ImportTypeGetGlobalType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +// <<<<<<<< WasmEdge import type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge export type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the external type from an export type. +/// +/// \param Cxt the WasmEdge_ExportTypeContext. +/// +/// \returns the external type of the export type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ExternalType +WasmEdge_ExportTypeGetExternalType(const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external name from an export type. +/// +/// The returned string object is linked to the external name of the export +/// type, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ExportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ExportTypeGetExternalName(const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is function type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The function type context links to the function type in the export type +/// context and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the function type. NULL if failed or the external type of the +/// export type is not `WasmEdge_ExternalType_Function`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_ExportTypeGetFunctionType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is table type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The table type context links to the table type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the table type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Table`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_ExportTypeGetTableType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is memory type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The memory type context links to the memory type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the memory type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Memory`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_ExportTypeGetMemoryType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is tag type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The tag type context links to the tag type in the export type context +/// and the AST module context. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the tag type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Tag`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_ExportTypeGetTagType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is global type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The global type context links to the global type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the global type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Global`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_ExportTypeGetGlobalType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +// <<<<<<<< WasmEdge export type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge AOT compiler functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_CompilerContext. +/// +/// The caller owns the object and should call `WasmEdge_CompilerDelete` to +/// delete it. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_CompilerContext * +WasmEdge_CompilerCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Compile the input WASM from the file path. +/// +/// The compiler compiles the WASM from file path for the ahead-of-time mode and +/// store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param InPath the input WASM file path. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_CompilerCompile(WasmEdge_CompilerContext *Cxt, const char *InPath, + const char *OutPath); + +/// Compile the input WASM from the given buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_CompilerCompileFromBytes()` API in the future. +/// +/// The compiler compiles the WASM from the given buffer for the +/// ahead-of-time mode and store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param InBuffer the input WASM binary buffer. +/// \param InBufferLen the length of the input WASM binary buffer. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_CompilerCompileFromBuffer( + WasmEdge_CompilerContext *Cxt, const uint8_t *InBuffer, + const uint64_t InBufferLen, const char *OutPath); + +/// Compile the input WASM from a WasmEdge_Bytes. +/// +/// The compiler compiles the WASM from the WasmEdge_Bytes for the +/// ahead-of-time mode and store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_CompilerCompileFromBytes(WasmEdge_CompilerContext *Cxt, + const WasmEdge_Bytes Bytes, + const char *OutPath); + +/// Deletion of the WasmEdge_CompilerContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_CompilerContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_CompilerDelete(WasmEdge_CompilerContext *Cxt); + +// <<<<<<<< WasmEdge AOT compiler functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge loader functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_LoaderContext. +/// +/// The caller owns the object and should call `WasmEdge_LoaderDelete` to +/// destroy it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of Loader. +/// NULL for the default configuration. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_LoaderContext * +WasmEdge_LoaderCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Load and parse the WASM module from a WASM file into a +/// WasmEdge_ASTModuleContext. +/// +/// Load and parse the WASM module from the file path, and return a +/// `WasmEdge_ASTModuleContext` as the result. The caller owns the +/// `WasmEdge_ASTModuleContext` object and should call +/// `WasmEdge_ASTModuleDelete` to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromFile(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const char *Path); + +/// Load and parse the WASM module from a buffer into WasmEdge_ASTModuleContext. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_LoaderParseFromBytes()` API in the future. +/// +/// Load and parse the WASM module from a buffer, and return a +/// WasmEdge_ASTModuleContext as the result. The caller owns the +/// WasmEdge_ASTModuleContext object and should call `WasmEdge_ASTModuleDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromBuffer(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const uint8_t *Buf, const uint32_t BufLen); + +/// Load and parse the WASM module from a WasmEdge_Bytes into +/// WasmEdge_ASTModuleContext. +/// +/// Load and parse the WASM module from a buffer, and return a +/// WasmEdge_ASTModuleContext as the result. The caller owns the +/// WasmEdge_ASTModuleContext object and should call `WasmEdge_ASTModuleDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromBytes(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const WasmEdge_Bytes Bytes); + +/// Serialize the WasmEdge_ASTModuleContext into WASM binary. +/// +/// Serialize the loaded WasmEdge_ASTModuleContext into the WASM binary format. +/// If the serialization succeeded, this API will allocate a new +/// `WasmEdge_Bytes` object and fill into the `Buf`. The caller owns the +/// `WasmEdge_Bytes` object and should call `WasmEdge_BytesDelete` to destroy +/// it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param ASTCxt the WasmEdge_ASTModuleContext to serialize. +/// \param [out] Buf the WasmEdge_Bytes to fill the serialized WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderSerializeASTModule(WasmEdge_LoaderContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt, + WasmEdge_Bytes *Buf); + +/// Deletion of the WasmEdge_LoaderContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_LoaderContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_LoaderDelete(WasmEdge_LoaderContext *Cxt); + +// <<<<<<<< WasmEdge loader functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge validator functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ValidatorContext. +/// +/// The caller owns the object and should call `WasmEdge_ValidatorDelete` to +/// destroy it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of +/// Validator. NULL for the default configuration. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValidatorContext * +WasmEdge_ValidatorCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Validate the WasmEdge AST Module. +/// +/// \param Cxt the WasmEdge_ValidatorContext. +/// \param ASTCxt the WasmEdge_ASTModuleContext to validate. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ValidatorValidate(WasmEdge_ValidatorContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Deletion of the WasmEdge_ValidatorContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ValidatorContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ValidatorDelete(WasmEdge_ValidatorContext *Cxt); + +// <<<<<<<< WasmEdge validator functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge executor functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ExecutorContext. +/// +/// The caller owns the object and should call `WasmEdge_ExecutorDelete` to +/// delete it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of +/// Executor. NULL for the default configuration. +/// \param StatCxt the WasmEdge_StatisticsContext as the statistics object set +/// into Executor. The statistics will refer to this context, and the life cycle +/// should be guaranteed until the executor context is deleted. NULL for not +/// doing the statistics. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_ExecutorCreate(const WasmEdge_ConfigureContext *ConfCxt, + WasmEdge_StatisticsContext *StatCxt); + +/// Instantiate an AST Module into a module instance. +/// +/// Instantiate an AST Module, and return an instantiated module instance +/// context as the result. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. Developers can use the +/// `WasmEdge_ModuleInstanceListFunction`, +/// `WasmEdge_ModuleInstanceFindFunction`, etc. APIs to retrieve the exported +/// instances from the result module instance. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param [out] ModuleCxt the output WasmEdge_ModuleInstanceContext if +/// succeeded. +/// \param StoreCxt the WasmEdge_StoreContext to link the imports. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorInstantiate( + WasmEdge_ExecutorContext *Cxt, WasmEdge_ModuleInstanceContext **ModuleCxt, + WasmEdge_StoreContext *StoreCxt, const WasmEdge_ASTModuleContext *ASTCxt); + +/// Instantiate an AST Module into a named module instance and link into store. +/// +/// Instantiate an AST Module with the module name, return the instantiated +/// module instance context as the result, and also register the module instance +/// to the store. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// Developers can use the `WasmEdge_ModuleInstanceListFunction`, +/// `WasmEdge_ModuleInstanceFindFunction`, etc. APIs to retrieve the exported +/// instances from the result module instance. +/// After calling this function, the output module instance will also be +/// registered into the store, and the other modules can import the exported +/// instances for linking when instantiation. Developers SHOULD guarantee the +/// life cycle of this output module instance, or the error will occur when in +/// execution after the module instance being destroyed if it has been imported +/// by other modules. That is, developers have the responsibility to delete the +/// output module instance even though the store being destroyed. When the +/// module instance is deleted, it will be unregistered to the store +/// automatically. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param [out] ModuleCxt the output WasmEdge_ModuleInstanceContext if +/// succeeded. +/// \param StoreCxt the WasmEdge_StoreContext to link the imports. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param ModuleName the module name WasmEdge_String for all exported +/// instances. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorRegister( + WasmEdge_ExecutorContext *Cxt, WasmEdge_ModuleInstanceContext **ModuleCxt, + WasmEdge_StoreContext *StoreCxt, const WasmEdge_ASTModuleContext *ASTCxt, + WasmEdge_String ModuleName); + +/// Register a module instance into a store with exporting its module name. +/// +/// Register an existing module into the store with its module name. +/// After calling this function, the existing module instance will be registered +/// into the store, and the other modules can import the exported instances for +/// linking when instantiation. Developers SHOULD guarantee the life cycle of +/// this existing module instance, or the error will occur when in execution +/// after the module instance being destroyed if it has been imported by other +/// modules. When the module instance is deleted, it will be unregistered to the +/// store automatically. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param StoreCxt the WasmEdge_StoreContext to store the instantiated module. +/// \param ImportCxt the WasmEdge_ModuleInstanceContext to register. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorRegisterImport( + WasmEdge_ExecutorContext *Cxt, WasmEdge_StoreContext *StoreCxt, + const WasmEdge_ModuleInstanceContext *ImportCxt); + +/// Invoke a WASM function by the function instance. +/// +/// After instantiating a WASM module, developers can get the function instance +/// context from the module instance. Then developers can invoke the function +/// through this API. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param FuncCxt the function instance context to invoke. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ExecutorInvoke(WasmEdge_ExecutorContext *Cxt, + const WasmEdge_FunctionInstanceContext *FuncCxt, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Asynchronous invoke a WASM function by the function instance. +/// +/// After instantiating a WASM module, developers can get the function instance +/// context from the module instance. Then developers can invoke the function +/// asynchronously through this API. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param FuncCxt the function instance context to invoke. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_ExecutorAsyncInvoke(WasmEdge_ExecutorContext *Cxt, + const WasmEdge_FunctionInstanceContext *FuncCxt, + const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Deletion of the WasmEdge_ExecutorContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ExecutorContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorDelete(WasmEdge_ExecutorContext *Cxt); + +// <<<<<<<< WasmEdge executor functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge store functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_StoreContext. +/// +/// The caller owns the object and should call `WasmEdge_StoreDelete` to destroy +/// it. +/// The store is the linker for multiple WASM module instances. The store will +/// not own any module instance registered into it, and the module instances +/// will automatically be unregistered if they are destroyed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StoreContext *WasmEdge_StoreCreate(void); + +/// Get the module instance context by the module name. +/// +/// After registering a WASM module, developers can call this function to find +/// and get the registered module instance context by the module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// \param Name the module name WasmEdge_String. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_StoreFindModule(const WasmEdge_StoreContext *Cxt, + const WasmEdge_String Name); + +/// Get the length of registered module list in store. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// +/// \returns length of registered named module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StoreListModuleLength(const WasmEdge_StoreContext *Cxt); + +/// List the registered module names. +/// +/// This function will list all registered module names. +/// The returned module names filled into the `Names` array are linked to the +/// registered module names in the store context, and the caller should __NOT__ +/// call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the registered +/// named module list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// \param [out] Names the output names WasmEdge_String buffer of named modules. +/// \param Len the buffer length. +/// +/// \returns actual registered named module list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StoreListModule(const WasmEdge_StoreContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Deletion of the WasmEdge_StoreContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// If there are module instances registered into this store context, they will +/// be automatically un-link to this store context. +/// +/// \param Cxt the WasmEdge_StoreContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StoreDelete(WasmEdge_StoreContext *Cxt); + +// <<<<<<<< WasmEdge store functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge module instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ModuleInstanceContext. +/// +/// Create a module instance context with exported module name for host +/// instances. Developer can use this API to create a module instance for +/// collecting host functions, tables, memories, tags, and globals. +/// The caller owns the object and should call `WasmEdge_ModuleInstanceDelete` +/// to destroy it. +/// +/// \param ModuleName the module name WasmEdge_String of this host module to +/// import. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreate(const WasmEdge_String ModuleName); + +/// Creation of the WasmEdge_ModuleInstanceContext with host data. +/// +/// Create a module instance context with exported module name, host data, and +/// host data finalizer for host instances. Developer can use this API to create +/// a module instance for collecting host functions, tables, memories, and +/// globals. When this created module instance being destroyed, the host data +/// finalizer will be invoked. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// +/// \param ModuleName the module name WasmEdge_String of this host module to +/// import. +/// \param HostData the host data to set into the module instance. When calling +/// the finalizer, this pointer will become the argument of the finalizer +/// function. +/// \param Finalizer the function to finalize the host data. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreateWithData(const WasmEdge_String ModuleName, + void *HostData, + void (*Finalizer)(void *)); + +/// Creation of the WasmEdge_ModuleInstanceContext for the WASI specification. +/// +/// This function will create a WASI host module that contains the WASI host +/// functions and initialize it. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// +/// \param Args the command line arguments. The first argument suggests being +/// the program name. NULL if the length is 0. +/// \param ArgLen the length of the command line arguments. +/// \param Envs the environment variables in the format `ENV=VALUE`. NULL if the +/// length is 0. +/// \param EnvLen the length of the environment variables. +/// \param Preopens the directory paths to preopen. String format in +/// `GUEST_PATH:HOST_PATH` means the path mapping, or the same path will be +/// mapped. NULL if the length is 0. +/// \param PreopenLen the length of the directory paths to preopen. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreateWASI(const char *const *Args, + const uint32_t ArgLen, + const char *const *Envs, + const uint32_t EnvLen, + const char *const *Preopens, + const uint32_t PreopenLen); + +/// Initialize the WasmEdge_ModuleInstanceContext for the WASI specification. +/// +/// This function will initialize the WASI host module with the parameters. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// \param Args the command line arguments. The first argument suggests being +/// the program name. NULL if the length is 0. +/// \param ArgLen the length of the command line arguments. +/// \param Envs the environment variables in the format `ENV=VALUE`. NULL if the +/// length is 0. +/// \param EnvLen the length of the environment variables. +/// \param Preopens the directory paths to preopen. String format in +/// `GUEST_PATH:HOST_PATH` means the path mapping, or the same path will be +/// mapped. NULL if the length is 0. +/// \param PreopenLen the length of the directory paths to preopen. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ModuleInstanceInitWASI( + WasmEdge_ModuleInstanceContext *Cxt, const char *const *Args, + const uint32_t ArgLen, const char *const *Envs, const uint32_t EnvLen, + const char *const *Preopens, const uint32_t PreopenLen); + +/// Get the WASI exit code. +/// +/// This function will return the exit code after running the "_start" function +/// of a `wasm32-wasi` program. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// +/// \returns the exit code after executing the "_start" function. Return +/// `EXIT_FAILURE` if the `Cxt` is NULL or not a WASI host module. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceWASIGetExitCode( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the native handler from the WASI mapped FD/Handler. +/// +/// This function will return the raw FD/Handler from a given mapped Fd +/// or Handler. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// \param Fd the WASI mapped Fd. +/// \param [out] NativeHandler the raw Fd/Handler. +/// +/// \returns the error code. Return `0` if the Native Handler is found. +/// Return `1` if the `Cxt` is `NULL`. +/// Return `2` if the given mapped Fd/handler is not found. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceWASIGetNativeHandler( + const WasmEdge_ModuleInstanceContext *Cxt, int32_t Fd, + uint64_t *NativeHandler); + +/// Initialize the WasmEdge_ModuleInstanceContext for the wasmedge_process +/// specification. +/// +/// This function will initialize the wasmedge_process host module with the +/// parameters. +/// +/// \param AllowedCmds the allowed commands white list. NULL if the +/// length is 0. +/// \param CmdsLen the length of the allowed commands white list. +/// \param AllowAll the boolean value to allow all commands. `false` is +/// suggested. If this value is `true`, the allowed commands white list will not +/// be recorded and all commands can be executed by wasmedge_process. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceInitWasmEdgeProcess(const char *const *AllowedCmds, + const uint32_t CmdsLen, + const bool AllowAll); + +/// Get the export module name of a module instance. +/// +/// The returned string object is linked to the module name of the module +/// instance, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ModuleInstanceGetModuleName(const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the host data set into the module instance when creating. +/// +/// The returned data is owned by the module instance, and will be passed into +/// the finalizer when deleting this module instance. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns host data. NULL if the module instance context is NULL or no host +/// data set into the module instance. +WASMEDGE_CAPI_EXPORT extern void * +WasmEdge_ModuleInstanceGetHostData(const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the exported function instance context of a module instance. +/// +/// The result function instance context links to the function instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_FunctionInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the function name WasmEdge_String. +/// +/// \returns pointer to the function instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_ModuleInstanceFindFunction(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported table instance context of a module instance. +/// +/// The result table instance context links to the table instance in the module +/// instance context and owned by the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_TableInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the table name WasmEdge_String. +/// +/// \returns pointer to the table instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_ModuleInstanceFindTable(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported memory instance context of a module instance. +/// +/// The result memory instance context links to the memory instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_MemoryInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the memory name WasmEdge_String. +/// +/// \returns pointer to the memory instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_ModuleInstanceFindMemory(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported tag instance context of a module instance. +/// +/// The result tag instance context links to the tag instance in the +/// module instance context and owned by the module instance context. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the tag name WasmEdge_String. +/// +/// \returns pointer to the tag instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TagInstanceContext * +WasmEdge_ModuleInstanceFindTag(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported global instance context of a module instance. +/// +/// The result global instance context links to the global instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_GlobalInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the global name WasmEdge_String. +/// +/// \returns pointer to the global instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalInstanceContext * +WasmEdge_ModuleInstanceFindGlobal(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the length of exported function list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported function list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListFunctionLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported function names of a module instance. +/// +/// The returned function names filled into the `Names` array are linked to the +/// exported names of functions of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// function list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListFunction(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported table list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported table list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListTableLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported table names of a module instance. +/// +/// The returned table names filled into the `Names` array are linked to the +/// exported names of tables of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// table list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the table names. +/// \param Len the buffer length. +/// +/// \returns actual exported table list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTable(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported memory list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported memory list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListMemoryLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported memory names of a module instance. +/// +/// The returned memory names filled into the `Names` array are linked to the +/// exported names of memories of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// memory list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the memory names. +/// \param Len the buffer length. +/// +/// \returns actual exported memory list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListMemory(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported tag list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported tag list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTagLength(const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported tag names of a module instance. +/// +/// The returned tag names filled into the `Names` array are linked to the +/// exported names of tags of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// tag list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the tag names. +/// \param Len the buffer length. +/// +/// \returns actual exported tag list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTag(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported global list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported global list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListGlobalLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported global names of a module instance. +/// +/// The returned global names filled into the `Names` array are linked to the +/// exported names of globals of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// global list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the global names. +/// \param Len the buffer length. +/// +/// \returns actual exported global list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListGlobal(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Add a function instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the function instance into the module +/// instance. The caller should __NOT__ access or destroy the function instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the function instance. +/// \param Name the export function name WasmEdge_String. +/// \param FuncCxt the WasmEdge_FunctionInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddFunction(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_FunctionInstanceContext *FuncCxt); + +/// Add a table instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the table instance into the module +/// instance. The caller should __NOT__ access or destroy the table instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the table instance. +/// \param Name the export table name WasmEdge_String. +/// \param TableCxt the WasmEdge_TableInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddTable(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_TableInstanceContext *TableCxt); + +/// Add a memory instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the memory instance into the module +/// instance. The caller should __NOT__ access or destroy the memory instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the memory instance. +/// \param Name the export memory name WasmEdge_String. +/// \param MemoryCxt the WasmEdge_MemoryInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddMemory(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_MemoryInstanceContext *MemoryCxt); + +/// Add a global instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the global instance into the module +/// instance. The caller should __NOT__ access or destroy the global instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the global instance. +/// \param Name the export global name WasmEdge_String. +/// \param GlobalCxt the WasmEdge_GlobalInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddGlobal(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_GlobalInstanceContext *GlobalCxt); + +/// Deletion of the WasmEdge_ModuleInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// If the module instance has been registered into one or more store contexts, +/// it will be automatically unregistered. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceDelete(WasmEdge_ModuleInstanceContext *Cxt); + +// <<<<<<<< WasmEdge module instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge function instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +typedef WasmEdge_Result (*WasmEdge_HostFunc_t)( + void *Data, const WasmEdge_CallingFrameContext *CallFrameCxt, + const WasmEdge_Value *Params, WasmEdge_Value *Returns); +/// Creation of the WasmEdge_FunctionInstanceContext for host functions. +/// +/// The caller owns the object and should call `WasmEdge_FunctionInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. The following is an example to create a +/// host function context. +/// ```c +/// WasmEdge_Result FuncAdd(void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *In, WasmEdge_Value *Out) { +/// // Function to return A + B. +/// int32_t A = WasmEdge_ValueGetI32(In[0]); +/// int32_t B = WasmEdge_ValueGetI32(In[1]); +/// Out[0] = WasmEdge_ValueGenI32(A + B); +/// // Return execution status +/// return WasmEdge_Result_Success; +/// } +/// +/// WasmEdge_ValType Params[2] = {WasmEdge_ValTypeGenI32(), +/// WasmEdge_ValTypeGenI32()}; +/// WasmEdge_ValType Returns[1] = {WasmEdge_ValTypeGenI32()}; +/// WasmEdge_FunctionTypeContext *FuncType = +/// WasmEdge_FunctionTypeCreate(Params, 2, Returns, 1); +/// WasmEdge_FunctionInstanceContext *HostFunc = +/// WasmEdge_FunctionInstanceCreate(FuncType, FuncAdd, NULL, 0); +/// WasmEdge_FunctionTypeDelete(FuncType); +/// ... +/// ``` +/// +/// \param Type the function type context to describe the host function +/// signature. +/// \param HostFunc the host function pointer. The host function signature must +/// be as following: +/// ```c +/// typedef WasmEdge_Result (*WasmEdge_HostFunc_t)( +/// void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *Params, +/// WasmEdge_Value *Returns); +/// ``` +/// The `Params` is the input parameters array with length guaranteed to be the +/// same as the parameter types in the `Type`. The `Returns` is the output +/// results array with length guaranteed to be the same as the result types in +/// the `Type`. The return value is `WasmEdge_Result` for the execution status. +/// \param Data the additional object, such as the pointer to a data structure, +/// to set to this host function context. The caller should guarantee the life +/// cycle of the object. NULL if the additional data object is not needed. +/// \param Cost the function cost in statistics. Pass 0 if the calculation is +/// not needed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_FunctionInstanceCreate(const WasmEdge_FunctionTypeContext *Type, + WasmEdge_HostFunc_t HostFunc, void *Data, + const uint64_t Cost); + +typedef WasmEdge_Result (*WasmEdge_WrapFunc_t)( + void *This, void *Data, const WasmEdge_CallingFrameContext *CallFrameCxt, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); +/// Creation of the WasmEdge_FunctionInstanceContext for host functions. +/// +/// This function is for the languages which cannot pass the function pointer of +/// the host function into this shared library directly. The caller owns the +/// object and should call `WasmEdge_FunctionInstanceDelete` to destroy it if +/// the returned object is not added into a `WasmEdge_ModuleInstanceContext`. +/// The following is an example to create a host function context for other +/// languages. +/// ```c +/// // `RealFunc` is the pointer to the function in other languages. +/// +/// WasmEdge_Result FuncAddWrap( +/// void *This, void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *In, const uint32_t InLen, WasmEdge_Value *Out, +/// const uint32_t OutLen) { +/// // Wrapper function of host function to return A + B. +/// +/// // `This` is the same as `RealFunc`. +/// int32_t A = WasmEdge_ValueGetI32(In[0]); +/// int32_t B = WasmEdge_ValueGetI32(In[1]); +/// +/// // Call the function of `This` in the host language ... +/// int32_t Result = ...; +/// +/// Out[0] = Result; +/// // Return the execution status. +/// return WasmEdge_Result_Success; +/// } +/// +/// WasmEdge_ValType Params[2] = {WasmEdge_ValTypeGenI32(), +/// WasmEdge_ValTypeGenI32()}; +/// WasmEdge_ValType Returns[1] = {WasmEdge_ValTypeGenI32()}; +/// WasmEdge_FunctionTypeContext *FuncType = +/// WasmEdge_FunctionTypeCreate(Params, 2, Returns, 1); +/// WasmEdge_FunctionInstanceContext *HostFunc = +/// WasmEdge_FunctionInstanceCreateBinding( +/// FuncType, FuncAddWrap, RealFunc, NULL, 0); +/// WasmEdge_FunctionTypeDelete(FuncType); +/// ... +/// ``` +/// +/// \param Type the function type context to describe the host function +/// signature. +/// \param WrapFunc the wrapper function pointer. The wrapper function signature +/// must be as following: +/// ```c +/// typedef WasmEdge_Result (*WasmEdge_WrapFunc_t)( +/// void *This, +/// void *Data, +/// WasmEdge_CallingFrameContext *FrameCxt, +/// const WasmEdge_Value *Params, +/// const uint32_t ParamLen, +/// WasmEdge_Value *Returns, +/// const uint32_t ReturnLen); +/// ``` +/// The `This` is the pointer the same as the `Binding` parameter of this +/// function. The `Params` is the input parameters array with length guaranteed +/// to be the same as the parameter types in the `Type`, and the `ParamLen` is +/// the length of the array. The `Returns` is the output results array with +/// length guaranteed to be the same as the result types in the `Type`, and the +/// `ReturnLen` is the length of the array. The return value is +/// `WasmEdge_Result` for the execution status. +/// \param Binding the `this` pointer of the host function target or the +/// function indexing maintained by the caller which can specify the host +/// function. When invoking the host function, this pointer will be the first +/// argument of the wrapper function. +/// \param Data the additional object, such as the pointer to a data structure, +/// to set to this host function context. The caller should guarantee the life +/// cycle of the object. NULL if the additional data object is not needed. +/// \param Cost the function cost in statistics. Pass 0 if the calculation is +/// not needed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_FunctionInstanceCreateBinding(const WasmEdge_FunctionTypeContext *Type, + WasmEdge_WrapFunc_t WrapFunc, + void *Binding, void *Data, + const uint64_t Cost); + +/// Get the function data field of the function instance. +/// +/// The function data is passed when creating the FunctionInstance. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext. +/// +/// \returns pointer to Data, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const void * +WasmEdge_FunctionInstanceGetData(const WasmEdge_FunctionInstanceContext *Cxt); + +/// Get the function type context of the function instance. +/// +/// The function type context links to the function type in the function +/// instance context and owned by the context. The caller should __NOT__ call +/// the `WasmEdge_FunctionTypeDelete`. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_FunctionInstanceGetFunctionType( + const WasmEdge_FunctionInstanceContext *Cxt); + +/// Deletion of the WasmEdge_FunctionInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_FunctionInstanceDelete(WasmEdge_FunctionInstanceContext *Cxt); + +// <<<<<<<< WasmEdge function instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge table instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_TableInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_TableInstanceDelete` to +/// destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// The default value of the elements in the output table instance will be null +/// references with the same reference type in the table type when table grows. +/// If the reference type of the input table type is a non-nullable value type, +/// a non-null default init value is required. In this case, please use the +/// `WasmEdge_TableInstanceCreateWithInit` API instead. +/// +/// \param TabType the table type context to initialize the table instance +/// context. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_TableInstanceCreate(const WasmEdge_TableTypeContext *TabType); + +/// Creation of the WasmEdge_TableInstanceContext with the default init value. +/// +/// The caller owns the object and should call `WasmEdge_TableInstanceDelete` to +/// destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// The value type of the default init value should compatible with the +/// reference type of the input table type, otherwise this function will fail. +/// If the reference type of the input table type is a non-nullable value type, +/// this function will fail if the default init value is a null reference. +/// +/// \param TabType the table type context to initialize the table instance +/// context. +/// \param Value the default init value for the table element when table +/// grows. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_TableInstanceCreateWithInit(const WasmEdge_TableTypeContext *TabType, + const WasmEdge_Value Value); + +/// Get the table type context from a table instance. +/// +/// The table type context links to the table type in the table instance context +/// and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_TableInstanceGetTableType(const WasmEdge_TableInstanceContext *Cxt); + +/// Get the reference value in a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param [out] Data the result reference value. +/// \param Offset the reference value offset (index) in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceGetData(const WasmEdge_TableInstanceContext *Cxt, + WasmEdge_Value *Data, const uint32_t Offset); + +/// Set the reference value into a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param Data the reference value to set into the table instance. +/// \param Offset the reference value offset (index) in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceSetData(WasmEdge_TableInstanceContext *Cxt, + WasmEdge_Value Data, const uint32_t Offset); + +/// Get the size of a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// +/// \returns the size of the table instance. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_TableInstanceGetSize(const WasmEdge_TableInstanceContext *Cxt); + +/// Grow a table instance with a size. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param Size the count of reference values to grow in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceGrow(WasmEdge_TableInstanceContext *Cxt, + const uint32_t Size); + +/// Deletion of the WasmEdge_TableInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_TableInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_TableInstanceDelete(WasmEdge_TableInstanceContext *Cxt); + +// <<<<<<<< WasmEdge table instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge memory instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_MemoryInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_MemoryInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// +/// \param MemType the memory type context to initialize the memory instance +/// context. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_MemoryInstanceCreate(const WasmEdge_MemoryTypeContext *MemType); + +/// Get the memory type context from a memory instance. +/// +/// The memory type context links to the memory type in the memory instance +/// context and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_MemoryInstanceGetMemoryType(const WasmEdge_MemoryInstanceContext *Cxt); + +/// Copy the data to the output buffer from a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param [out] Data the result data buffer of copying destination. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will failed. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceGetData(const WasmEdge_MemoryInstanceContext *Cxt, + uint8_t *Data, const uint32_t Offset, + const uint32_t Length); + +/// Copy the data into a memory instance from the input buffer. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Data the data buffer to copy. +/// \param Offset the data start offset in the memory instance. +/// \param Length the data buffer length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will failed. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceSetData(WasmEdge_MemoryInstanceContext *Cxt, + const uint8_t *Data, const uint32_t Offset, + const uint32_t Length); + +/// Get the data pointer in a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will return NULL. +/// +/// \returns the pointer to data with the start offset. NULL if failed. +WASMEDGE_CAPI_EXPORT extern uint8_t * +WasmEdge_MemoryInstanceGetPointer(WasmEdge_MemoryInstanceContext *Cxt, + const uint32_t Offset, const uint32_t Length); + +/// Get the const data pointer in a const memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will return NULL. +/// +/// \returns the pointer to data with the start offset. NULL if failed. +WASMEDGE_CAPI_EXPORT extern const uint8_t * +WasmEdge_MemoryInstanceGetPointerConst( + const WasmEdge_MemoryInstanceContext *Cxt, const uint32_t Offset, + const uint32_t Length); + +/// Get the current page size (64 KiB of each page) of a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// +/// \returns the page size of the memory instance. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_MemoryInstanceGetPageSize(const WasmEdge_MemoryInstanceContext *Cxt); + +/// Grow a memory instance with a page size. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Page the page count to grow in the memory instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceGrowPage(WasmEdge_MemoryInstanceContext *Cxt, + const uint32_t Page); + +/// Deletion of the WasmEdge_MemoryInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_MemoryInstanceDelete(WasmEdge_MemoryInstanceContext *Cxt); + +// <<<<<<<< WasmEdge memory instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge tag instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the tag type context from a tag instance. +/// +/// The tag type context links to the tag type in the tag instance +/// context and owned by the context. +/// +/// \param Cxt the WasmEdge_TagInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_TagInstanceGetTagType(const WasmEdge_TagInstanceContext *Cxt); + +// <<<<<<<< WasmEdge tag instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge global instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_GlobalInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_GlobalInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// +/// \param GlobType the global type context to initialize the global instance +/// context. +/// \param Value the initial value with its value type of the global instance. +/// This function will fail if the value type of `GlobType` and `Value` are not +/// the same. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalInstanceContext * +WasmEdge_GlobalInstanceCreate(const WasmEdge_GlobalTypeContext *GlobType, + const WasmEdge_Value Value); + +/// Get the global type context from a global instance. +/// +/// The global type context links to the global type in the global instance +/// context and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_GlobalInstanceGetGlobalType(const WasmEdge_GlobalInstanceContext *Cxt); + +/// Get the value from a global instance. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// +/// \returns the current value of the global instance. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_GlobalInstanceGetValue(const WasmEdge_GlobalInstanceContext *Cxt); + +/// Set the value into a global instance. +/// +/// This function will return error if the global context is set as the `Const` +/// mutation or the value type not matched. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// \param Value the value to set into the global context. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_GlobalInstanceSetValue(WasmEdge_GlobalInstanceContext *Cxt, + const WasmEdge_Value Value); + +/// Deletion of the WasmEdge_GlobalInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_GlobalInstanceDelete(WasmEdge_GlobalInstanceContext *Cxt); + +// <<<<<<<< WasmEdge global instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge calling frame functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the executor context from the current calling frame. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// +/// \returns the executor context, NULL if the Cxt is NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_CallingFrameGetExecutor(const WasmEdge_CallingFrameContext *Cxt); + +/// Get the module instance of the current calling frame. +/// +/// When a WASM function is executing and start to call a host function, a frame +/// with the module instance which the WASM function belongs to will be pushed +/// onto the stack. And therefore the calling frame context will record that +/// module instance. +/// So in one case that the module instance will be `NULL`: developers execute +/// the function instance which is a host function and not added into a module +/// instance. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// +/// \returns the module instance of the current calling frame. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_CallingFrameGetModuleInstance(const WasmEdge_CallingFrameContext *Cxt); + +/// Get the memory instance by index from the module instance of the current +/// calling frame. +/// +/// By default, a WASM module only have one memory instance after instantiation. +/// Therefore, developers can use: +/// `WasmEdge_CallingFrameGetMemoryInstance(Cxt, 0)` +/// to get the memory instance in host function body. +/// This extension is for the WASM multiple memories proposal. After enabling +/// the proposal, there may be greater than 1 memory instances in a WASM module. +/// So developers can use this function to access the memory instances which are +/// not in 0 index. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// \param Idx the index of memory instance in the module instance. +/// +/// \returns the memory instance, NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_CallingFrameGetMemoryInstance(const WasmEdge_CallingFrameContext *Cxt, + const uint32_t Idx); + +// <<<<<<<< WasmEdge calling frame functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Async functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Wait a WasmEdge_Async execution. +/// +/// \param Cxt the WasmEdge_ASync. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncWait(const WasmEdge_Async *Cxt); + +/// Wait a WasmEdge_Async execution with timeout. +/// +/// \param Cxt the WasmEdge_ASync. +/// \param Milliseconds times to wait. +/// +/// \returns Result of waiting, true for execution ended, false for timeout +/// occurred. +WASMEDGE_CAPI_EXPORT bool WasmEdge_AsyncWaitFor(const WasmEdge_Async *Cxt, + uint64_t Milliseconds); + +/// Cancel a WasmEdge_Async execution. +/// +/// \param Cxt the WasmEdge_ASync. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncCancel(WasmEdge_Async *Cxt); + +/// Wait and get the return list length of the WasmEdge_Async execution. +/// +/// This function will wait until the execution finished and return the return +/// value list length of the executed function. This function will return 0 if +/// the `Cxt` is NULL, the execution was failed, or the execution was canceled. +/// Developers can call the `WasmEdge_AsyncGet` to get the execution status and +/// the return values. +/// +/// \param Cxt the WasmEdge_ASync. +/// +/// \returns the return list length of the executed function. +WASMEDGE_CAPI_EXPORT uint32_t +WasmEdge_AsyncGetReturnsLength(const WasmEdge_Async *Cxt); + +/// Wait and get the result of WasmEdge_Async execution. +/// +/// This function will wait until the execution finished and return the +/// execution status and the return values. +/// If the `Returns` buffer length is smaller than the arity of the function, +/// the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASync. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT WasmEdge_Result +WasmEdge_AsyncGet(const WasmEdge_Async *Cxt, WasmEdge_Value *Returns, + const uint32_t ReturnLen); + +/// Deletion of the WasmEdge_Async. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ASync to destroy. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncDelete(WasmEdge_Async *Cxt); + +// <<<<<<<< WasmEdge Async functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge VM functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_VMContext. +/// +/// The caller owns the object and should call `WasmEdge_VMDelete` to destroy +/// it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of VM. +/// NULL for the default configuration. +/// \param StoreCxt the WasmEdge_StoreContext as the external WASM store of VM. +/// The instantiation and execution will refer to this store context, and the +/// life cycle should be ensured until the VM context is deleted. NULL for the +/// default store owned by `WasmEdge_VMContext`. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_VMContext * +WasmEdge_VMCreate(const WasmEdge_ConfigureContext *ConfCxt, + WasmEdge_StoreContext *StoreCxt); + +/// Register and instantiate WASM into the store in VM from a WASM file. +/// +/// Load a WASM file from the path, and register all exported instances and +/// instantiate them into the store into the VM with their exported name and +/// module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromFile(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const char *Path); + +/// Register and instantiate WASM into the store in VM from a buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMRegisterModuleFromBytes()` API in the future. +/// +/// Load a WASM module from a buffer, and register all exported instances and +/// instantiate them into the store into the VM with their exported name and +/// module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromBuffer(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const uint8_t *Buf, const uint32_t BufLen); + +/// Register and instantiate WASM into the store in VM from a WasmEdge_Bytes. +/// +/// Load a WASM module from a WasmEdge_Bytes, and register all exported +/// instances and instantiate them into the store into the VM with their +/// exported name and module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromBytes(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_Bytes Bytes); + +/// Instantiate and register an AST Module into a named module instance in VM. +/// +/// Load from the AST Module, and register all exported instances and +/// instantiate them into the store in VM with their exported name and module +/// name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Register a module instance into the store in VM with exporting its module +/// name. +/// +/// After calling this function, the existing module instance will be registered +/// into the store context in this VM, and the other modules can import the +/// exported instances for linking when instantiation. Developers SHOULD +/// guarantee the life cycle of this existing module instance, or the error will +/// occur when in execution after the module instance being destroyed if it has +/// been imported by other modules. That is, developers should call the +/// `WasmEdge_ModuleInstanceDelete` if this existing module instance will not be +/// used anymore or after the deletion of this VM. When the module instance is +/// deleted, it will be unregistered to the store context in this VM +/// automatically. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ImportCxt the WasmEdge_ModuleInstanceContext to register. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRegisterModuleFromImport( + WasmEdge_VMContext *Cxt, const WasmEdge_ModuleInstanceContext *ImportCxt); + +/// Instantiate the WASM module from a WASM file and invoke a function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the file path, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromFile( + WasmEdge_VMContext *Cxt, const char *Path, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a buffer and invoke a function by name. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMRunWasmFromBytes()` API in the future. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a buffer, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromBuffer( + WasmEdge_VMContext *Cxt, const uint8_t *Buf, const uint32_t BufLen, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WasmEdge_Bytes and invoke a function by +/// name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a WasmEdge_Bytes, and then invoke +/// a function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromBytes( + WasmEdge_VMContext *Cxt, const WasmEdge_Bytes Bytes, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WasmEdge AST Module and invoke a function +/// by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the WasmEdge AST Module, and then +/// invoke the function by name and parameters. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromASTModule( + WasmEdge_VMContext *Cxt, const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WASM file and asynchronous invoke a +/// function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the file path, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromFile( + WasmEdge_VMContext *Cxt, const char *Path, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen); + +/// Instantiate the WASM module from a buffer and asynchronous invoke a function +/// by name. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMAsyncRunWasmFromBytes()` API in the future. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a buffer, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromBuffer( + WasmEdge_VMContext *Cxt, const uint8_t *Buf, const uint32_t BufLen, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Instantiate the WASM module from a WasmEdge_Bytes and asynchronous invoke a +/// function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a WasmEdge_Bytes, and then invoke +/// a function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromBytes( + WasmEdge_VMContext *Cxt, const WasmEdge_Bytes Bytes, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Instantiate the WASM module from a WasmEdge AST Module and asynchronous +/// invoke a function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the WasmEdge AST Module, and then +/// invoke the function by name and parameters. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_VMAsyncRunWasmFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_String FuncName, + const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Load the WASM module from a WASM file. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from the file path. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromFile(WasmEdge_VMContext *Cxt, const char *Path); + +/// Load the WASM module from a buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMLoadWasmFromBytes()` API in the future. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from a buffer. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromBuffer(WasmEdge_VMContext *Cxt, const uint8_t *Buf, + const uint32_t BufLen); + +/// Load the WASM module from a WasmEdge_Bytes. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from a WasmEdge_Bytes. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromBytes(WasmEdge_VMContext *Cxt, + const WasmEdge_Bytes Bytes); + +/// Load the WASM module from loaded WasmEdge AST Module. +/// +/// This is the first step to invoke a WASM function step by step. +/// Copy the loaded WasmEdge AST Module context into VM. The VM context has no +/// dependency on the input AST Module context. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Validate the WASM module loaded into the VM context. +/// +/// This is the second step to invoke a WASM function step by step. +/// After loading a WASM module into VM context, You can call this function to +/// validate it. And you can then call `WasmEdge_VMInstantiate` for the next +/// step. Note that only validated WASM modules can be instantiated in the VM +/// context. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMValidate(WasmEdge_VMContext *Cxt); + +/// Instantiate the validated WASM module in the VM context. +/// +/// This is the third step to invoke a WASM function step by step. +/// After validating a WASM module in the VM context, You can call this function +/// to instantiate it. And you can then call `WasmEdge_VMExecute` for invoking +/// the exported function in this WASM module. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMInstantiate(WasmEdge_VMContext *Cxt); + +/// Invoke a WASM function by name. +/// +/// This is the final step to invoke a WASM function step by step. +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can repeatedly call this function to invoke the exported WASM functions by +/// their names until the VM context is reset or a new WASM module is registered +/// or loaded. For calling the functions in registered WASM modules with module +/// names, please use `WasmEdge_VMExecuteRegistered` instead. If the `Returns` +/// buffer length is smaller than the arity of the function, the overflowed +/// return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMExecute(WasmEdge_VMContext *Cxt, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Invoke a WASM function by its module name and function name. +/// +/// After registering a WASM module in the VM context, you can repeatedly call +/// this function to invoke exported WASM functions by their module names and +/// function names until the VM context is reset. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMExecuteRegistered( + WasmEdge_VMContext *Cxt, const WasmEdge_String ModuleName, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Asynchronous invoke a WASM function by name. +/// +/// This is the final step to invoke a WASM function step by step. +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can repeatedly call this function to invoke the exported WASM functions by +/// their names until the VM context is reset or a new WASM module is registered +/// or loaded. For calling the functions in registered WASM modules with module +/// names, please use `WasmEdge_VMAsyncExecuteRegistered` instead. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_VMAsyncExecute(WasmEdge_VMContext *Cxt, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen); + +/// Asynchronous invoke a WASM function by its module name and function name. +/// +/// After registering a WASM module in the VM context, you can repeatedly call +/// this function to invoke exported WASM functions by their module names and +/// function names until the VM context is reset. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncExecuteRegistered( + WasmEdge_VMContext *Cxt, const WasmEdge_String ModuleName, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Get the function type by function name. +/// +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can call this function to get the function type by the exported function +/// name until the VM context is reset or a new WASM module is registered or +/// loaded. For getting the function type of functions in registered WASM +/// modules with module names, please use `WasmEdge_VMGetFunctionTypeRegistered` +/// instead. +/// The returned function type context are linked to the context owned by the VM +/// context, and the caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete` to destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// +/// \returns the function type. NULL if the function not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_VMGetFunctionType(const WasmEdge_VMContext *Cxt, + const WasmEdge_String FuncName); + +/// Get the function type by function name. +/// +/// After registering a WASM module in the VM context, you can call this +/// function to get the function type by the functions' exported module names +/// and function names until the VM context is reset. +/// The returned function type context are linked to the context owned by the VM +/// context, and the caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete` to destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// +/// \returns the function type. NULL if the function not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_VMGetFunctionTypeRegistered(const WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_String FuncName); + +/// Reset of WasmEdge_VMContext. +/// +/// After calling this function, the statistics, loaded module, the instantiated +/// instances, and the registered instances except the WASI and plug-ins will +/// all be cleared. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext to reset. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_VMCleanup(WasmEdge_VMContext *Cxt); + +/// Get the length of exported function list. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns length of exported function list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMGetFunctionListLength(const WasmEdge_VMContext *Cxt); + +/// Get the exported function list. +/// +/// The returned function names filled into the `Names` array link to the +/// exported names of functions owned by the vm context, and the caller should +/// __NOT__ call the `WasmEdge_StringDelete` to destroy them. +/// The function type contexts filled into the `FuncTypes` array of the +/// corresponding function names link to the context owned by the VM context. +/// The caller should __NOT__ call the `WasmEdge_FunctionTypeDelete` to destroy +/// them. +/// If the `Names` and `FuncTypes` buffer lengths are smaller than the result of +/// the exported function list size, the overflowed return values will be +/// discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param [out] Names the output names WasmEdge_String buffer of exported +/// functions. Can be NULL if names are not needed. +/// \param [out] FuncTypes the function type contexts buffer. Can be NULL if +/// function types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VMGetFunctionList( + const WasmEdge_VMContext *Cxt, WasmEdge_String *Names, + const WasmEdge_FunctionTypeContext **FuncTypes, const uint32_t Len); + +/// Get the module instance corresponding to the WasmEdge_HostRegistration +/// settings. +/// +/// When creating the VM context with a configuration, the built-in host module +/// will be registered according to the `WasmEdge_HostRegistration` settings +/// added into the `WasmEdge_ConfigureContext`. You can call this function to +/// get the `WasmEdge_ModuleInstanceContext` corresponding to the settings. The +/// module instance context links to the context owned by the VM context. The +/// caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete`. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddHostRegistration(Conf, WasmEdge_HostRegistration_Wasi); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// WasmEdge_ModuleInstanceContext *WasiMod = +/// WasmEdge_VMGetImportModuleContext(VM, WasmEdge_HostRegistration_Wasi); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Reg the host registration value to get the import module. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetImportModuleContext(const WasmEdge_VMContext *Cxt, + const enum WasmEdge_HostRegistration Reg); + +/// Get the current instantiated module in VM. +/// +/// After instantiating a module instance into the VM, developers can call this +/// API to get the active anonymous module instance to retrieve the exported +/// instances. The module instance context links to the context owned by the VM +/// context. The caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetActiveModule(const WasmEdge_VMContext *Cxt); + +/// Get the registered module in VM by the module name. +/// +/// After registering a WASM module into the VM context, developers can call +/// this function to get the module instance by the module name. The returned +/// module instance context links to the context owned by the VM context, and +/// the caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete` to +/// destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetRegisteredModule(const WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName); + +/// Get the length of registered module list in the WasmEdge_VMContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns length of registered module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMListRegisteredModuleLength(const WasmEdge_VMContext *Cxt); + +/// List the registered module names in the WasmEdge_VMContext. +/// +/// This function will list all registered module names. +/// The returned module names filled into the `Names` array are linked to the +/// registered module names in the VM context, and the caller should __NOT__ +/// call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the registered +/// named module list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param [out] Names the output names WasmEdge_String buffer of the registered +/// modules. +/// \param Len the buffer length. +/// +/// \returns actual registered module list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMListRegisteredModule(const WasmEdge_VMContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the store context used in the WasmEdge_VMContext. +/// +/// The returned store context links to the store in the VM context and owned by +/// the VM context. This function will return NULL if error occurs. The caller +/// should __NOT__ call the `WasmEdge_StoreDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the store context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StoreContext * +WasmEdge_VMGetStoreContext(WasmEdge_VMContext *Cxt); + +/// Get the loader context used in the WasmEdge_VMContext. +/// +/// The returned loader context links to the loader in the VM context and owned +/// by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_LoaderDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the loader context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_LoaderContext * +WasmEdge_VMGetLoaderContext(WasmEdge_VMContext *Cxt); + +/// Get the validator context used in the WasmEdge_VMContext. +/// +/// The returned validator context links to the validator in the VM context and +/// owned by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_ValidatorDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the validator context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValidatorContext * +WasmEdge_VMGetValidatorContext(WasmEdge_VMContext *Cxt); + +/// Get the executor context used in the WasmEdge_VMContext. +/// +/// The returned executor context links to the executor in the VM context and +/// owned by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_ExecutorDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the executor context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_VMGetExecutorContext(WasmEdge_VMContext *Cxt); + +/// Get the statistics context used in the WasmEdge_VMContext. +/// +/// The statistics context links to the statistics in the VM context and owned +/// by the VM context. The caller should __NOT__ call the +/// `WasmEdge_StatisticsDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the statistics context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StatisticsContext * +WasmEdge_VMGetStatisticsContext(WasmEdge_VMContext *Cxt); + +/// Deletion of the WasmEdge_VMContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_VMContext to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_VMDelete(WasmEdge_VMContext *Cxt); + +// <<<<<<<< WasmEdge VM functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Driver functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \ + defined(__TOS_WIN__) || defined(__WINDOWS__) +/// Convert UTF16 Args to UTF8 Args +/// +/// This function is an argument converter for Windows platforms. +/// The caller owns the vector and should call `WasmEdge_Driver_ArgvDelete` to +/// destroy it. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns Allocated argument vector. +WASMEDGE_CAPI_EXPORT extern const char ** +WasmEdge_Driver_ArgvCreate(int Argc, const wchar_t *Argv[]); + +/// Deletion of the argument vector +/// +/// \param Argv the argument vector. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_Driver_ArgvDelete(const char *Argv[]); + +/// Set console output code page to UTF-8 on windows. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_Driver_SetConsoleOutputCPtoUTF8(void); +#endif + +/// Entrypoint for the compiler tool. +/// +/// This function provides an entrypoint to the WasmEdge AOT compiler tool with +/// the command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_Compiler(int Argc, + const char *Argv[]); + +/// Entrypoint for the runtime tool. +/// +/// This function provides an entrypoint to the WasmEdge runtime tool with the +/// command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_Tool(int Argc, + const char *Argv[]); + +#ifdef WASMEDGE_BUILD_WASI_NN_RPC +/// Entrypoint for the Wasi-NN RPC server tool. +/// +/// This function provides an entrypoint to the WasmEdge Wasi-NN RPC server tool +/// with the command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int +WasmEdge_Driver_WasiNNRPCServer(int Argc, const char *Argv[]); +#endif + +/// Entrypoint for the unified tool. +/// +/// This function provides an entrypoint to the WasmEdge unified tool with the +/// command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_UniTool(int Argc, + const char *Argv[]); + +// <<<<<<<< WasmEdge Driver functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Plugin functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Load plugins with the default search paths. +/// +/// The default paths are: +/// 1. The environment variable "WASMEDGE_PLUGIN_PATH". +/// 2. The "../plugin/" directory related to the WasmEdge installation path. +/// 3. The "wasmedge/" directory under the library path if the WasmEdge is +/// installed under the "/usr". +WASMEDGE_CAPI_EXPORT extern void WasmEdge_PluginLoadWithDefaultPaths(void); + +/// Load the plugin with the given file or directory. +/// +/// For the given file path, this function will load the plug-in. +/// For the given directory path, this function will load the plug-ins under the +/// directory recursively. +/// +/// \param Path the path to plug-in file or directory. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_PluginLoadFromPath(const char *Path); + +/// Get the length of loaded plug-in list. +/// +/// \returns length of loaded plug-in list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_PluginListPluginsLength(void); + +/// List the loaded plug-ins with their names. +/// +/// The returned plug-in names filled into the `Names` array are owned by the +/// internal WasmEdge plug-in storage, and the caller should __NOT__ call the +/// `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the loaded +/// plug-in list size, the overflowed return values will be discarded. +/// +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual loaded plug-in list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListPlugins(WasmEdge_String *Names, const uint32_t Len); + +/// Find the loaded plug-in context by name. +/// +/// After loading the plug-ins from default paths or the given path, developers +/// can use this API to retrieve the plug-in context by name. Then developers +/// can create the module instance from the plug-in contexts. +/// +/// \param Name the plug-in name WasmEdge_String. +/// +/// \returns pointer to the plug-in context. NULL if the plug-in not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_PluginContext * +WasmEdge_PluginFind(const WasmEdge_String Name); + +/// Get the plug-in name of the plug-in context. +/// +/// The returned string object is linked to the plug-in name of the plug-in +/// context, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_PluginContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_PluginGetPluginName(const WasmEdge_PluginContext *Cxt); + +/// Get the length of module list in the plug-in context. +/// +/// There may be several modules in a plug-in. Developers can use this function +/// to get the length of the module list in a plug-in. +/// +/// \param Cxt the WasmEdge_PluginContext to get the length of the module list. +/// +/// \returns length of module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListModuleLength(const WasmEdge_PluginContext *Cxt); + +/// List the modules in the plug-in context with their names. +/// +/// The returned module names filled into the `Names` array are owned by the +/// internal WasmEdge plug-in storage, and the caller should __NOT__ call the +/// `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the loaded +/// plug-in list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_PluginContext to list the modules. +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual module list size of the plug-in. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListModule(const WasmEdge_PluginContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Create the module instance in the plug-in by the module name. +/// +/// By giving the module name, developers can retrieve the module in the plug-in +/// and create the module instance. +/// The caller owns the object and should call `WasmEdge_ModuleInstanceDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_PluginContext to retrieve and create module. +/// \param ModuleName the module name to retrieve. +/// +/// \returns pointer to the module instance context, NULL if the module name not +/// found in the plug-in or the plug-in is not valid. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_PluginCreateModule(const WasmEdge_PluginContext *Cxt, + const WasmEdge_String ModuleName); + +/// Initialize the wasi_nn plug-in. +/// +/// This function will initialize the wasi_nn plug-in with the preloads string +/// list. Only available after loading the wasi_nn plug-in and before creating +/// the module instance from the plug-in. +/// +/// \param NNPreloads the preload string list. NULL if the length is 0. +/// \param PreloadsLen the length of the preload list. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_PluginInitWASINN(const char *const *NNPreloads, + const uint32_t PreloadsLen); + +/// Implement by plugins for returning the plugin descriptor. +/// +/// \returns the plugin descriptor. +WASMEDGE_CAPI_PLUGIN_EXPORT extern const WasmEdge_PluginDescriptor * +WasmEdge_Plugin_GetDescriptor(void); + +// <<<<<<<< WasmEdge Pluginfunctions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Experimental functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Register a host function that will be invoked before executing any host +/// functions. +/// +/// There is only one pre-host-function. After calling this function, the +/// previous registered host function will be replaced. This is a experimental +/// feature. Use it at your own risk. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param Data the host data to set into the given host function. When calling +/// the Func, this pointer will be the argument of the Func function. +/// \param Func the function to be invoked before executing any other host +/// functions. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorExperimentalRegisterPreHostFunction( + WasmEdge_ExecutorContext *Cxt, void *Data, void (*Func)(void *)); + +/// Register a host function that will be invoked after executing any host +/// functions. +/// +/// There is only one post-host-function. After calling this function, the +/// previous registered host function will be replaced. This is a experimental +/// feature. Use it at your own risk. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Data the host data to set into the given host function. When calling +/// the Func, this pointer will be the argument of the Func function. +/// \param Func the function to be invoked after executing any other host +/// functions. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorExperimentalRegisterPostHostFunction( + WasmEdge_ExecutorContext *Cxt, void *Data, void (*Func)(void *)); + +// <<<<<<<< WasmEdge Experimental Functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +#ifdef __cplusplus +} /// extern "C" +#endif + +#endif /// WASMEDGE_C_API_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so new file mode 120000 index 0000000000000000000000000000000000000000..145d5a021c32a26423bac2fecffd6a174664a3b3 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so @@ -0,0 +1 @@ +libwasmedge.so.0 \ No newline at end of file diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0 b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0 new file mode 120000 index 0000000000000000000000000000000000000000..6639f000114eaf75d312c5ce1153d5b25b079a87 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0 @@ -0,0 +1 @@ +libwasmedge.so.0.1.0 \ No newline at end of file diff --git a/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0.1.0 b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0.1.0 new file mode 100755 index 0000000000000000000000000000000000000000..1e4332be599d9e6e7fb798450b9dd53ef0638437 Binary files /dev/null and b/wasmedge/lib-0.14.1-manylinux2014/aarch64/lib/libwasmedge.so.0.1.0 differ diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum.inc b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum.inc new file mode 100644 index 0000000000000000000000000000000000000000..bf1c8f7c78cadc318de23d5319956d6bc6ce427d --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum.inc @@ -0,0 +1,1201 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum.inc - Enumerations ---------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains all enumerations of WasmEdge. +/// +//===----------------------------------------------------------------------===// + +#ifndef Line +#error "this header file must not be included directly" +#endif + +// enum_ast.hpp + +#ifdef UseASTNodeAttr +#define A Line + +A(Component, "component") +A(Sec_CoreMod, "component core:module section") +A(Sec_CoreInstance, "component core:instance section") +A(Sec_Alias, "component alias section") +A(Sec_Comp, "nested component section") +A(Sec_Instance, "component instance section") +A(Sec_CompType, "component type section") +A(Sec_Canon, "component canonical section") +A(Sec_CompStart, "component start section") +A(Sec_CompImport, "component import section") +A(Sec_CompExport, "component export section") +A(ImportExportName, "import/export name") +A(Import, "import") +A(Export, "export") +A(Canonical, "canonical") +A(Alias, "alias") +A(DefType, "component defined type") +A(InstanceDecl, "instance decl") +A(ExternDesc, "extern desc") +A(Name, "import/export name") +A(AliasTarget, "alias target") +A(Sort, "sort") +A(Instance, "instance expr") +A(CoreInstance, "core:instance expr") +A(Module, "module") +A(Sec_Custom, "custom section") +A(Sec_Type, "type section") +A(Sec_Import, "import section") +A(Sec_Function, "function section") +A(Sec_Table, "table section") +A(Sec_Memory, "memory section") +A(Sec_Global, "global section") +A(Sec_Export, "export section") +A(Sec_Start, "start section") +A(Sec_Element, "element section") +A(Sec_Code, "code section") +A(Sec_Data, "data section") +A(Sec_DataCount, "data count section") +A(Sec_Tag, "tag section") +A(Desc_Import, "import description") +A(Desc_Export, "export description") +A(Seg_Table, "table segment") +A(Seg_Global, "global segment") +A(Seg_Element, "element segment") +A(Seg_Code, "code segment") +A(Seg_Data, "data segment") +A(Type_Module, "module type") +A(Type_Rec, "recursive type") +A(Type_Sub, "sub type") +A(Type_Limit, "limit") +A(Type_Function, "function type") +A(Type_Memory, "memory type") +A(Type_Table, "table type") +A(Type_Global, "global type") +A(Type_Instance, "instance type") +A(Type_Component, "component type") +A(Expression, "expression") +A(Instruction, "instruction") +A(Sec_AOT, "aot section") + +#undef A +#endif // UseASTNodeAttr + +#ifdef UseOpCode +#define O Line +#define OFB Line_FB +#define OFC Line_FC +#define OFD Line_FD +#define OFE Line_FE + +// OpCode: +// NAME | STRING | CODE [ | EXTEND ] + +// Control instructions (part 1) +O(Unreachable, "unreachable", 0x00) +O(Nop, "nop", 0x01) +O(Block, "block", 0x02) +O(Loop, "loop", 0x03) +O(If, "if", 0x04) +O(Else, "else", 0x05) +O(Try, "try", 0x06) // For legacy EH proposal +O(Catch, "catch", 0x07) // For legacy EH proposal +O(Throw, "throw", 0x08) +O(Rethrow, "rethrow", 0x09) // For legacy EH proposal +O(Throw_ref, "throw_ref", 0x0A) +O(End, "end", 0x0B) +O(Br, "br", 0x0C) +O(Br_if, "br_if", 0x0D) +O(Br_table, "br_table", 0x0E) +O(Return, "return", 0x0F) +O(Call, "call", 0x10) +O(Call_indirect, "call_indirect", 0x11) +O(Return_call, "return_call", 0x12) +O(Return_call_indirect, "return_call_indirect", 0x13) +O(Call_ref, "call_ref", 0x14) +O(Return_call_ref, "return_call_ref", 0x15) +// 0x16: Reserved +// 0x17: Reserved +O(Delegate, "delegate", 0x18) // For legacy EH proposal +O(Catch_all, "catch_all", 0x19) // For legacy EH proposal + +// Parametric Instructions +O(Drop, "drop", 0x1A) +O(Select, "select", 0x1B) +O(Select_t, "select", 0x1C) +// 0x1D: Reserved +// 0x1E: Reserved + +// Control instructions (part 2) +O(Try_table, "try_table", 0x1F) + +// Variable Instructions +O(Local__get, "local.get", 0x20) +O(Local__set, "local.set", 0x21) +O(Local__tee, "local.tee", 0x22) +O(Global__get, "global.get", 0x23) +O(Global__set, "global.set", 0x24) + +// Table Instructions (part 1) +O(Table__get, "table.get", 0x25) +O(Table__set, "table.set", 0x26) +// 0x27: Reserved + +// Memory Instructions (part 1) +O(I32__load, "i32.load", 0x28) +O(I64__load, "i64.load", 0x29) +O(F32__load, "f32.load", 0x2A) +O(F64__load, "f64.load", 0x2B) +O(I32__load8_s, "i32.load8_s", 0x2C) +O(I32__load8_u, "i32.load8_u", 0x2D) +O(I32__load16_s, "i32.load16_s", 0x2E) +O(I32__load16_u, "i32.load16_u", 0x2F) +O(I64__load8_s, "i64.load8_s", 0x30) +O(I64__load8_u, "i64.load8_u", 0x31) +O(I64__load16_s, "i64.load16_s", 0x32) +O(I64__load16_u, "i64.load16_u", 0x33) +O(I64__load32_s, "i64.load32_s", 0x34) +O(I64__load32_u, "i64.load32_u", 0x35) +O(I32__store, "i32.store", 0x36) +O(I64__store, "i64.store", 0x37) +O(F32__store, "f32.store", 0x38) +O(F64__store, "f64.store", 0x39) +O(I32__store8, "i32.store8", 0x3A) +O(I32__store16, "i32.store16", 0x3B) +O(I64__store8, "i64.store8", 0x3C) +O(I64__store16, "i64.store16", 0x3D) +O(I64__store32, "i64.store32", 0x3E) +O(Memory__size, "memory.size", 0x3F) +O(Memory__grow, "memory.grow", 0x40) + +// Const numeric instructions +O(I32__const, "i32.const", 0x41) +O(I64__const, "i64.const", 0x42) +O(F32__const, "f32.const", 0x43) +O(F64__const, "f64.const", 0x44) + +// Numeric instructions +O(I32__eqz, "i32.eqz", 0x45) +O(I32__eq, "i32.eq", 0x46) +O(I32__ne, "i32.ne", 0x47) +O(I32__lt_s, "i32.lt_s", 0x48) +O(I32__lt_u, "i32.lt_u", 0x49) +O(I32__gt_s, "i32.gt_s", 0x4A) +O(I32__gt_u, "i32.gt_u", 0x4B) +O(I32__le_s, "i32.le_s", 0x4C) +O(I32__le_u, "i32.le_u", 0x4D) +O(I32__ge_s, "i32.ge_s", 0x4E) +O(I32__ge_u, "i32.ge_u", 0x4F) +O(I64__eqz, "i64.eqz", 0x50) +O(I64__eq, "i64.eq", 0x51) +O(I64__ne, "i64.ne", 0x52) +O(I64__lt_s, "i64.lt_s", 0x53) +O(I64__lt_u, "i64.lt_u", 0x54) +O(I64__gt_s, "i64.gt_s", 0x55) +O(I64__gt_u, "i64.gt_u", 0x56) +O(I64__le_s, "i64.le_s", 0x57) +O(I64__le_u, "i64.le_u", 0x58) +O(I64__ge_s, "i64.ge_s", 0x59) +O(I64__ge_u, "i64.ge_u", 0x5A) +O(F32__eq, "f32.eq", 0x5B) +O(F32__ne, "f32.ne", 0x5C) +O(F32__lt, "f32.lt", 0x5D) +O(F32__gt, "f32.gt", 0x5E) +O(F32__le, "f32.le", 0x5F) +O(F32__ge, "f32.ge", 0x60) +O(F64__eq, "f64.eq", 0x61) +O(F64__ne, "f64.ne", 0x62) +O(F64__lt, "f64.lt", 0x63) +O(F64__gt, "f64.gt", 0x64) +O(F64__le, "f64.le", 0x65) +O(F64__ge, "f64.ge", 0x66) +O(I32__clz, "i32.clz", 0x67) +O(I32__ctz, "i32.ctz", 0x68) +O(I32__popcnt, "i32.popcnt", 0x69) +O(I32__add, "i32.add", 0x6A) +O(I32__sub, "i32.sub", 0x6B) +O(I32__mul, "i32.mul", 0x6C) +O(I32__div_s, "i32.div_s", 0x6D) +O(I32__div_u, "i32.div_u", 0x6E) +O(I32__rem_s, "i32.rem_s", 0x6F) +O(I32__rem_u, "i32.rem_u", 0x70) +O(I32__and, "i32.and", 0x71) +O(I32__or, "i32.or", 0x72) +O(I32__xor, "i32.xor", 0x73) +O(I32__shl, "i32.shl", 0x74) +O(I32__shr_s, "i32.shr_s", 0x75) +O(I32__shr_u, "i32.shr_u", 0x76) +O(I32__rotl, "i32.rotl", 0x77) +O(I32__rotr, "i32.rotr", 0x78) +O(I64__clz, "i64.clz", 0x79) +O(I64__ctz, "i64.ctz", 0x7A) +O(I64__popcnt, "i64.popcnt", 0x7B) +O(I64__add, "i64.add", 0x7C) +O(I64__sub, "i64.sub", 0x7D) +O(I64__mul, "i64.mul", 0x7E) +O(I64__div_s, "i64.div_s", 0x7F) +O(I64__div_u, "i64.div_u", 0x80) +O(I64__rem_s, "i64.rem_s", 0x81) +O(I64__rem_u, "i64.rem_u", 0x82) +O(I64__and, "i64.and", 0x83) +O(I64__or, "i64.or", 0x84) +O(I64__xor, "i64.xor", 0x85) +O(I64__shl, "i64.shl", 0x86) +O(I64__shr_s, "i64.shr_s", 0x87) +O(I64__shr_u, "i64.shr_u", 0x88) +O(I64__rotl, "i64.rotl", 0x89) +O(I64__rotr, "i64.rotr", 0x8A) +O(F32__abs, "f32.abs", 0x8B) +O(F32__neg, "f32.neg", 0x8C) +O(F32__ceil, "f32.ceil", 0x8D) +O(F32__floor, "f32.floor", 0x8E) +O(F32__trunc, "f32.trunc", 0x8F) +O(F32__nearest, "f32.nearest", 0x90) +O(F32__sqrt, "f32.sqrt", 0x91) +O(F32__add, "f32.add", 0x92) +O(F32__sub, "f32.sub", 0x93) +O(F32__mul, "f32.mul", 0x94) +O(F32__div, "f32.div", 0x95) +O(F32__min, "f32.min", 0x96) +O(F32__max, "f32.max", 0x97) +O(F32__copysign, "f32.copysign", 0x98) +O(F64__abs, "f64.abs", 0x99) +O(F64__neg, "f64.neg", 0x9A) +O(F64__ceil, "f64.ceil", 0x9B) +O(F64__floor, "f64.floor", 0x9C) +O(F64__trunc, "f64.trunc", 0x9D) +O(F64__nearest, "f64.nearest", 0x9E) +O(F64__sqrt, "f64.sqrt", 0x9F) +O(F64__add, "f64.add", 0xA0) +O(F64__sub, "f64.sub", 0xA1) +O(F64__mul, "f64.mul", 0xA2) +O(F64__div, "f64.div", 0xA3) +O(F64__min, "f64.min", 0xA4) +O(F64__max, "f64.max", 0xA5) +O(F64__copysign, "f64.copysign", 0xA6) +O(I32__wrap_i64, "i32.wrap_i64", 0xA7) +O(I32__trunc_f32_s, "i32.trunc_f32_s", 0xA8) +O(I32__trunc_f32_u, "i32.trunc_f32_u", 0xA9) +O(I32__trunc_f64_s, "i32.trunc_f64_s", 0xAA) +O(I32__trunc_f64_u, "i32.trunc_f64_u", 0xAB) +O(I64__extend_i32_s, "i64.extend_i32_s", 0xAC) +O(I64__extend_i32_u, "i64.extend_i32_u", 0xAD) +O(I64__trunc_f32_s, "i64.trunc_f32_s", 0xAE) +O(I64__trunc_f32_u, "i64.trunc_f32_u", 0xAF) +O(I64__trunc_f64_s, "i64.trunc_f64_s", 0xB0) +O(I64__trunc_f64_u, "i64.trunc_f64_u", 0xB1) +O(F32__convert_i32_s, "f32.convert_i32_s", 0xB2) +O(F32__convert_i32_u, "f32.convert_i32_u", 0xB3) +O(F32__convert_i64_s, "f32.convert_i64_s", 0xB4) +O(F32__convert_i64_u, "f32.convert_i64_u", 0xB5) +O(F32__demote_f64, "f32.demote_f64", 0xB6) +O(F64__convert_i32_s, "f64.convert_i32_s", 0xB7) +O(F64__convert_i32_u, "f64.convert_i32_u", 0xB8) +O(F64__convert_i64_s, "f64.convert_i64_s", 0xB9) +O(F64__convert_i64_u, "f64.convert_i64_u", 0xBA) +O(F64__promote_f32, "f64.promote_f32", 0xBB) +O(I32__reinterpret_f32, "i32.reinterpret_f32", 0xBC) +O(I64__reinterpret_f64, "i64.reinterpret_f64", 0xBD) +O(F32__reinterpret_i32, "f32.reinterpret_i32", 0xBE) +O(F64__reinterpret_i64, "f64.reinterpret_i64", 0xBF) +O(I32__extend8_s, "i32.extend8_s", 0xC0) +O(I32__extend16_s, "i32.extend16_s", 0xC1) +O(I64__extend8_s, "i64.extend8_s", 0xC2) +O(I64__extend16_s, "i64.extend16_s", 0xC3) +O(I64__extend32_s, "i64.extend32_s", 0xC4) +// 0xC5 ~ 0xCF: Reserved + +// Reference Instructions +O(Ref__null, "ref.null", 0xD0) +O(Ref__is_null, "ref.is_null", 0xD1) +O(Ref__func, "ref.func", 0xD2) +O(Ref__eq, "ref.eq", 0xD3) +O(Ref__as_non_null, "ref.as_non_null", 0xD4) + +// Control Instructions (part 3) +O(Br_on_null, "br_on_null", 0xD5) +O(Br_on_non_null, "br_on_non_null", 0xD6) +// 0xD7 ~ 0xFA: Reserved + +// 0xFB prefix - GC Instructions +OFB(Struct__new, "struct.new", 0xFB, 0) +OFB(Struct__new_default, "struct.new_default", 0xFB, 1) +OFB(Struct__get, "struct.get", 0xFB, 2) +OFB(Struct__get_s, "struct.get_s", 0xFB, 3) +OFB(Struct__get_u, "struct.get_u", 0xFB, 4) +OFB(Struct__set, "struct.set", 0xFB, 5) +OFB(Array__new, "array.new", 0xFB, 6) +OFB(Array__new_default, "array.new_default", 0xFB, 7) +OFB(Array__new_fixed, "array.new_fixed", 0xFB, 8) +OFB(Array__new_data, "array.new_data", 0xFB, 9) +OFB(Array__new_elem, "array.new_elem", 0xFB, 10) +OFB(Array__get, "array.get", 0xFB, 11) +OFB(Array__get_s, "array.get_s", 0xFB, 12) +OFB(Array__get_u, "array.get_u", 0xFB, 13) +OFB(Array__set, "array.set", 0xFB, 14) +OFB(Array__len, "array.len", 0xFB, 15) +OFB(Array__fill, "array.fill", 0xFB, 16) +OFB(Array__copy, "array.copy", 0xFB, 17) +OFB(Array__init_data, "array.init_data", 0xFB, 18) +OFB(Array__init_elem, "array.init_elem", 0xFB, 19) +OFB(Ref__test, "ref.test (ref)", 0xFB, 20) +OFB(Ref__test_null, "ref.test (ref.null)", 0xFB, 21) +OFB(Ref__cast, "ref.cast (ref)", 0xFB, 22) +OFB(Ref__cast_null, "ref.cast (ref.null)", 0xFB, 23) +OFB(Br_on_cast, "br_on_cast", 0xFB, 24) +OFB(Br_on_cast_fail, "br_on_cast_fail", 0xFB, 25) +OFB(Any__convert_extern, "any.convert_extern", 0xFB, 26) +OFB(Extern__convert_any, "extern.convert_any", 0xFB, 27) +OFB(Ref__i31, "ref.i31", 0xFB, 28) +OFB(I31__get_s, "i31.get_s", 0xFB, 29) +OFB(I31__get_u, "i31.get_u", 0xFB, 30) + +// 0xFC prefix - Saturating Truncation Instructions +OFC(I32__trunc_sat_f32_s, "i32.trunc_sat_f32_s", 0xFC, 0) +OFC(I32__trunc_sat_f32_u, "i32.trunc_sat_f32_u", 0xFC, 1) +OFC(I32__trunc_sat_f64_s, "i32.trunc_sat_f64_s", 0xFC, 2) +OFC(I32__trunc_sat_f64_u, "i32.trunc_sat_f64_u", 0xFC, 3) +OFC(I64__trunc_sat_f32_s, "i64.trunc_sat_f32_s", 0xFC, 4) +OFC(I64__trunc_sat_f32_u, "i64.trunc_sat_f32_u", 0xFC, 5) +OFC(I64__trunc_sat_f64_s, "i64.trunc_sat_f64_s", 0xFC, 6) +OFC(I64__trunc_sat_f64_u, "i64.trunc_sat_f64_u", 0xFC, 7) + +// 0xFC prefix - Memory Instructions (part 2) +OFC(Memory__init, "memory.init", 0xFC, 8) +OFC(Data__drop, "data.drop", 0xFC, 9) +OFC(Memory__copy, "memory.copy", 0xFC, 10) +OFC(Memory__fill, "memory.fill", 0xFC, 11) + +// 0xFC prefix - Table Instructions (part 2) +OFC(Table__init, "table.init", 0xFC, 12) +OFC(Elem__drop, "elem.drop", 0xFC, 13) +OFC(Table__copy, "table.copy", 0xFC, 14) +OFC(Table__grow, "table.grow", 0xFC, 15) +OFC(Table__size, "table.size", 0xFC, 16) +OFC(Table__fill, "table.fill", 0xFC, 17) + +// 0xFD prefix - Vector Memory Instructions (part 1) +OFD(V128__load, "v128.load", 0xFD, 0) +OFD(V128__load8x8_s, "v128.load8x8_s", 0xFD, 1) +OFD(V128__load8x8_u, "v128.load8x8_u", 0xFD, 2) +OFD(V128__load16x4_s, "v128.load16x4_s", 0xFD, 3) +OFD(V128__load16x4_u, "v128.load16x4_u", 0xFD, 4) +OFD(V128__load32x2_s, "v128.load32x2_s", 0xFD, 5) +OFD(V128__load32x2_u, "v128.load32x2_u", 0xFD, 6) +OFD(V128__load8_splat, "v128.load8_splat", 0xFD, 7) +OFD(V128__load16_splat, "v128.load16_splat", 0xFD, 8) +OFD(V128__load32_splat, "v128.load32_splat", 0xFD, 9) +OFD(V128__load64_splat, "v128.load64_splat", 0xFD, 10) +OFD(V128__store, "v128.store", 0xFD, 11) + +// 0xFD prefix - Vector Numeric Instructions (part 1) +OFD(V128__const, "v128.const", 0xFD, 12) +OFD(I8x16__shuffle, "i8x16.shuffle", 0xFD, 13) +OFD(I8x16__swizzle, "i8x16.swizzle", 0xFD, 14) +OFD(I8x16__splat, "i8x16.splat", 0xFD, 15) +OFD(I16x8__splat, "i16x8.splat", 0xFD, 16) +OFD(I32x4__splat, "i32x4.splat", 0xFD, 17) +OFD(I64x2__splat, "i64x2.splat", 0xFD, 18) +OFD(F32x4__splat, "f32x4.splat", 0xFD, 19) +OFD(F64x2__splat, "f64x2.splat", 0xFD, 20) + +// 0xFD prefix - Vector Lane Instructions +OFD(I8x16__extract_lane_s, "i8x16.extract_lane_s", 0xFD, 21) +OFD(I8x16__extract_lane_u, "i8x16.extract_lane_u", 0xFD, 22) +OFD(I8x16__replace_lane, "i8x16.replace_lane", 0xFD, 23) +OFD(I16x8__extract_lane_s, "i16x8.extract_lane_s", 0xFD, 24) +OFD(I16x8__extract_lane_u, "i16x8.extract_lane_u", 0xFD, 25) +OFD(I16x8__replace_lane, "i16x8.replace_lane", 0xFD, 26) +OFD(I32x4__extract_lane, "i32x4.extract_lane", 0xFD, 27) +OFD(I32x4__replace_lane, "i32x4.replace_lane", 0xFD, 28) +OFD(I64x2__extract_lane, "i64x2.extract_lane", 0xFD, 29) +OFD(I64x2__replace_lane, "i64x2.replace_lane", 0xFD, 30) +OFD(F32x4__extract_lane, "f32x4.extract_lane", 0xFD, 31) +OFD(F32x4__replace_lane, "f32x4.replace_lane", 0xFD, 32) +OFD(F64x2__extract_lane, "f64x2.extract_lane", 0xFD, 33) +OFD(F64x2__replace_lane, "f64x2.replace_lane", 0xFD, 34) + +// 0xFD prefix - Vector Numeric Instructions (part 2) +OFD(I8x16__eq, "i8x16.eq", 0xFD, 35) +OFD(I8x16__ne, "i8x16.ne", 0xFD, 36) +OFD(I8x16__lt_s, "i8x16.lt_s", 0xFD, 37) +OFD(I8x16__lt_u, "i8x16.lt_u", 0xFD, 38) +OFD(I8x16__gt_s, "i8x16.gt_s", 0xFD, 39) +OFD(I8x16__gt_u, "i8x16.gt_u", 0xFD, 40) +OFD(I8x16__le_s, "i8x16.le_s", 0xFD, 41) +OFD(I8x16__le_u, "i8x16.le_u", 0xFD, 42) +OFD(I8x16__ge_s, "i8x16.ge_s", 0xFD, 43) +OFD(I8x16__ge_u, "i8x16.ge_u", 0xFD, 44) +OFD(I16x8__eq, "i16x8.eq", 0xFD, 45) +OFD(I16x8__ne, "i16x8.ne", 0xFD, 46) +OFD(I16x8__lt_s, "i16x8.lt_s", 0xFD, 47) +OFD(I16x8__lt_u, "i16x8.lt_u", 0xFD, 48) +OFD(I16x8__gt_s, "i16x8.gt_s", 0xFD, 49) +OFD(I16x8__gt_u, "i16x8.gt_u", 0xFD, 50) +OFD(I16x8__le_s, "i16x8.le_s", 0xFD, 51) +OFD(I16x8__le_u, "i16x8.le_u", 0xFD, 52) +OFD(I16x8__ge_s, "i16x8.ge_s", 0xFD, 53) +OFD(I16x8__ge_u, "i16x8.ge_u", 0xFD, 54) +OFD(I32x4__eq, "i32x4.eq", 0xFD, 55) +OFD(I32x4__ne, "i32x4.ne", 0xFD, 56) +OFD(I32x4__lt_s, "i32x4.lt_s", 0xFD, 57) +OFD(I32x4__lt_u, "i32x4.lt_u", 0xFD, 58) +OFD(I32x4__gt_s, "i32x4.gt_s", 0xFD, 59) +OFD(I32x4__gt_u, "i32x4.gt_u", 0xFD, 60) +OFD(I32x4__le_s, "i32x4.le_s", 0xFD, 61) +OFD(I32x4__le_u, "i32x4.le_u", 0xFD, 62) +OFD(I32x4__ge_s, "i32x4.ge_s", 0xFD, 63) +OFD(I32x4__ge_u, "i32x4.ge_u", 0xFD, 64) +OFD(F32x4__eq, "f32x4.eq", 0xFD, 65) +OFD(F32x4__ne, "f32x4.ne", 0xFD, 66) +OFD(F32x4__lt, "f32x4.lt", 0xFD, 67) +OFD(F32x4__gt, "f32x4.gt", 0xFD, 68) +OFD(F32x4__le, "f32x4.le", 0xFD, 69) +OFD(F32x4__ge, "f32x4.ge", 0xFD, 70) +OFD(F64x2__eq, "f64x2.eq", 0xFD, 71) +OFD(F64x2__ne, "f64x2.ne", 0xFD, 72) +OFD(F64x2__lt, "f64x2.lt", 0xFD, 73) +OFD(F64x2__gt, "f64x2.gt", 0xFD, 74) +OFD(F64x2__le, "f64x2.le", 0xFD, 75) +OFD(F64x2__ge, "f64x2.ge", 0xFD, 76) +OFD(V128__not, "v128.not", 0xFD, 77) +OFD(V128__and, "v128.and", 0xFD, 78) +OFD(V128__andnot, "v128.andnot", 0xFD, 79) +OFD(V128__or, "v128.or", 0xFD, 80) +OFD(V128__xor, "v128.xor", 0xFD, 81) +OFD(V128__bitselect, "v128.bitselect", 0xFD, 82) +OFD(V128__any_true, "v128.any_true", 0xFD, 83) + +// 0xFD prefix - Vector Memory Instructions (part 2) +OFD(V128__load8_lane, "v128.load8_lane", 0xFD, 84) +OFD(V128__load16_lane, "v128.load16_lane", 0xFD, 85) +OFD(V128__load32_lane, "v128.load32_lane", 0xFD, 86) +OFD(V128__load64_lane, "v128.load64_lane", 0xFD, 87) +OFD(V128__store8_lane, "v128.store8_lane", 0xFD, 88) +OFD(V128__store16_lane, "v128.store16_lane", 0xFD, 89) +OFD(V128__store32_lane, "v128.store32_lane", 0xFD, 90) +OFD(V128__store64_lane, "v128.store64_lane", 0xFD, 91) +OFD(V128__load32_zero, "v128.load32_zero", 0xFD, 92) +OFD(V128__load64_zero, "v128.load64_zero", 0xFD, 93) + +// 0xFD prefix - Vector Numeric Instructions (part 3) +OFD(F32x4__demote_f64x2_zero, "f32x4.demote_f64x2_zero", 0xFD, 94) +OFD(F64x2__promote_low_f32x4, "f64x2.promote_low_f32x4", 0xFD, 95) +OFD(I8x16__abs, "i8x16.abs", 0xFD, 96) +OFD(I8x16__neg, "i8x16.neg", 0xFD, 97) +OFD(I8x16__popcnt, "i8x16.popcnt", 0xFD, 98) +OFD(I8x16__all_true, "i8x16.all_true", 0xFD, 99) +OFD(I8x16__bitmask, "i8x16.bitmask", 0xFD, 100) +OFD(I8x16__narrow_i16x8_s, "i8x16.narrow_i16x8_s", 0xFD, 101) +OFD(I8x16__narrow_i16x8_u, "i8x16.narrow_i16x8_u", 0xFD, 102) +OFD(F32x4__ceil, "f32x4.ceil", 0xFD, 103) +OFD(F32x4__floor, "f32x4.floor", 0xFD, 104) +OFD(F32x4__trunc, "f32x4.trunc", 0xFD, 105) +OFD(F32x4__nearest, "f32x4.nearest", 0xFD, 106) +OFD(I8x16__shl, "i8x16.shl", 0xFD, 107) +OFD(I8x16__shr_s, "i8x16.shr_s", 0xFD, 108) +OFD(I8x16__shr_u, "i8x16.shr_u", 0xFD, 109) +OFD(I8x16__add, "i8x16.add", 0xFD, 110) +OFD(I8x16__add_sat_s, "i8x16.add_sat_s", 0xFD, 111) +OFD(I8x16__add_sat_u, "i8x16.add_sat_u", 0xFD, 112) +OFD(I8x16__sub, "i8x16.sub", 0xFD, 113) +OFD(I8x16__sub_sat_s, "i8x16.sub_sat_s", 0xFD, 114) +OFD(I8x16__sub_sat_u, "i8x16.sub_sat_u", 0xFD, 115) +OFD(F64x2__ceil, "f64x2.ceil", 0xFD, 116) +OFD(F64x2__floor, "f64x2.floor", 0xFD, 117) +OFD(I8x16__min_s, "i8x16.min_s", 0xFD, 118) +OFD(I8x16__min_u, "i8x16.min_u", 0xFD, 119) +OFD(I8x16__max_s, "i8x16.max_s", 0xFD, 120) +OFD(I8x16__max_u, "i8x16.max_u", 0xFD, 121) +OFD(F64x2__trunc, "f64x2.trunc", 0xFD, 122) +OFD(I8x16__avgr_u, "i8x16.avgr_u", 0xFD, 123) +OFD(I16x8__extadd_pairwise_i8x16_s, "i16x8.extadd_pairwise_i8x16_s", 0xFD, 124) +OFD(I16x8__extadd_pairwise_i8x16_u, "i16x8.extadd_pairwise_i8x16_u", 0xFD, 125) +OFD(I32x4__extadd_pairwise_i16x8_s, "i32x4.extadd_pairwise_i16x8_s", 0xFD, 126) +OFD(I32x4__extadd_pairwise_i16x8_u, "i32x4.extadd_pairwise_i16x8_u", 0xFD, 127) +OFD(I16x8__abs, "i16x8.abs", 0xFD, 128) +OFD(I16x8__neg, "i16x8.neg", 0xFD, 129) +OFD(I16x8__q15mulr_sat_s, "i16x8.q15mulr_sat_s", 0xFD, 130) +OFD(I16x8__all_true, "i16x8.all_true", 0xFD, 131) +OFD(I16x8__bitmask, "i16x8.bitmask", 0xFD, 132) +OFD(I16x8__narrow_i32x4_s, "i16x8.narrow_i32x4_s", 0xFD, 133) +OFD(I16x8__narrow_i32x4_u, "i16x8.narrow_i32x4_u", 0xFD, 134) +OFD(I16x8__extend_low_i8x16_s, "i16x8.extend_low_i8x16_s", 0xFD, 135) +OFD(I16x8__extend_high_i8x16_s, "i16x8.extend_high_i8x16_s", 0xFD, 136) +OFD(I16x8__extend_low_i8x16_u, "i16x8.extend_low_i8x16_u", 0xFD, 137) +OFD(I16x8__extend_high_i8x16_u, "i16x8.extend_high_i8x16_u", 0xFD, 138) +OFD(I16x8__shl, "i16x8.shl", 0xFD, 139) +OFD(I16x8__shr_s, "i16x8.shr_s", 0xFD, 140) +OFD(I16x8__shr_u, "i16x8.shr_u", 0xFD, 141) +OFD(I16x8__add, "i16x8.add", 0xFD, 142) +OFD(I16x8__add_sat_s, "i16x8.add_sat_s", 0xFD, 143) +OFD(I16x8__add_sat_u, "i16x8.add_sat_u", 0xFD, 144) +OFD(I16x8__sub, "i16x8.sub", 0xFD, 145) +OFD(I16x8__sub_sat_s, "i16x8.sub_sat_s", 0xFD, 146) +OFD(I16x8__sub_sat_u, "i16x8.sub_sat_u", 0xFD, 147) +OFD(F64x2__nearest, "f64x2.nearest", 0xFD, 148) +OFD(I16x8__mul, "i16x8.mul", 0xFD, 149) +OFD(I16x8__min_s, "i16x8.min_s", 0xFD, 150) +OFD(I16x8__min_u, "i16x8.min_u", 0xFD, 151) +OFD(I16x8__max_s, "i16x8.max_s", 0xFD, 152) +OFD(I16x8__max_u, "i16x8.max_u", 0xFD, 153) +// 0xFD 154: Reserved +OFD(I16x8__avgr_u, "i16x8.avgr_u", 0xFD, 155) +OFD(I16x8__extmul_low_i8x16_s, "i16x8.extmul_low_i8x16_s", 0xFD, 156) +OFD(I16x8__extmul_high_i8x16_s, "i16x8.extmul_high_i8x16_s", 0xFD, 157) +OFD(I16x8__extmul_low_i8x16_u, "i16x8.extmul_low_i8x16_u", 0xFD, 158) +OFD(I16x8__extmul_high_i8x16_u, "i16x8.extmul_high_i8x16_u", 0xFD, 159) +OFD(I32x4__abs, "i32x4.abs", 0xFD, 160) +OFD(I32x4__neg, "i32x4.neg", 0xFD, 161) +// 0xFD 162: Reserved +OFD(I32x4__all_true, "i32x4.all_true", 0xFD, 163) +OFD(I32x4__bitmask, "i32x4.bitmask", 0xFD, 164) +// 0xFD 165: Reserved +// 0xFD 166: Reserved +OFD(I32x4__extend_low_i16x8_s, "i32x4.extend_low_i16x8_s", 0xFD, 167) +OFD(I32x4__extend_high_i16x8_s, "i32x4.extend_high_i16x8_s", 0xFD, 168) +OFD(I32x4__extend_low_i16x8_u, "i32x4.extend_low_i16x8_u", 0xFD, 169) +OFD(I32x4__extend_high_i16x8_u, "i32x4.extend_high_i16x8_u", 0xFD, 170) +OFD(I32x4__shl, "i32x4.shl", 0xFD, 171) +OFD(I32x4__shr_s, "i32x4.shr_s", 0xFD, 172) +OFD(I32x4__shr_u, "i32x4.shr_u", 0xFD, 173) +OFD(I32x4__add, "i32x4.add", 0xFD, 174) +// 0xFD 175: Reserved +// 0xFD 176: Reserved +OFD(I32x4__sub, "i32x4.sub", 0xFD, 177) +// 0xFD 178: Reserved +// 0xFD 179: Reserved +// 0xFD 180: Reserved +OFD(I32x4__mul, "i32x4.mul", 0xFD, 181) +OFD(I32x4__min_s, "i32x4.min_s", 0xFD, 182) +OFD(I32x4__min_u, "i32x4.min_u", 0xFD, 183) +OFD(I32x4__max_s, "i32x4.max_s", 0xFD, 184) +OFD(I32x4__max_u, "i32x4.max_u", 0xFD, 185) +OFD(I32x4__dot_i16x8_s, "i32x4.dot_i16x8_s", 0xFD, 186) +// 0xFD 187: Reserved +OFD(I32x4__extmul_low_i16x8_s, "i32x4.extmul_low_i16x8_s", 0xFD, 188) +OFD(I32x4__extmul_high_i16x8_s, "i32x4.extmul_high_i16x8_s", 0xFD, 189) +OFD(I32x4__extmul_low_i16x8_u, "i32x4.extmul_low_i16x8_u", 0xFD, 190) +OFD(I32x4__extmul_high_i16x8_u, "i32x4.extmul_high_i16x8_u", 0xFD, 191) +OFD(I64x2__abs, "i64x2.abs", 0xFD, 192) +OFD(I64x2__neg, "i64x2.neg", 0xFD, 193) +// 0xFD 194: Reserved +OFD(I64x2__all_true, "i64x2.all_true", 0xFD, 195) +OFD(I64x2__bitmask, "i64x2.bitmask", 0xFD, 196) +// 0xFD 197: Reserved +// 0xFD 198: Reserved +OFD(I64x2__extend_low_i32x4_s, "i64x2.extend_low_i32x4_s", 0xFD, 199) +OFD(I64x2__extend_high_i32x4_s, "i64x2.extend_high_i32x4_s", 0xFD, 200) +OFD(I64x2__extend_low_i32x4_u, "i64x2.extend_low_i32x4_u", 0xFD, 201) +OFD(I64x2__extend_high_i32x4_u, "i64x2.extend_high_i32x4_u", 0xFD, 202) +OFD(I64x2__shl, "i64x2.shl", 0xFD, 203) +OFD(I64x2__shr_s, "i64x2.shr_s", 0xFD, 204) +OFD(I64x2__shr_u, "i64x2.shr_u", 0xFD, 205) +OFD(I64x2__add, "i64x2.add", 0xFD, 206) +// 0xFD 207: Reserved +// 0xFD 208: Reserved +OFD(I64x2__sub, "i64x2.sub", 0xFD, 209) +// 0xFD 210: Reserved +// 0xFD 211: Reserved +// 0xFD 212: Reserved +OFD(I64x2__mul, "i64x2.mul", 0xFD, 213) +OFD(I64x2__eq, "i64x2.eq", 0xFD, 214) +OFD(I64x2__ne, "i64x2.ne", 0xFD, 215) +OFD(I64x2__lt_s, "i64x2.lt_s", 0xFD, 216) +OFD(I64x2__gt_s, "i64x2.gt_s", 0xFD, 217) +OFD(I64x2__le_s, "i64x2.le_s", 0xFD, 218) +OFD(I64x2__ge_s, "i64x2.ge_s", 0xFD, 219) +OFD(I64x2__extmul_low_i32x4_s, "i64x2.extmul_low_i32x4_s", 0xFD, 220) +OFD(I64x2__extmul_high_i32x4_s, "i64x2.extmul_high_i32x4_s", 0xFD, 221) +OFD(I64x2__extmul_low_i32x4_u, "i64x2.extmul_low_i32x4_u", 0xFD, 222) +OFD(I64x2__extmul_high_i32x4_u, "i64x2.extmul_high_i32x4_u", 0xFD, 223) +OFD(F32x4__abs, "f32x4.abs", 0xFD, 224) +OFD(F32x4__neg, "f32x4.neg", 0xFD, 225) +// 0xFD 226: Reserved +OFD(F32x4__sqrt, "f32x4.sqrt", 0xFD, 227) +OFD(F32x4__add, "f32x4.add", 0xFD, 228) +OFD(F32x4__sub, "f32x4.sub", 0xFD, 229) +OFD(F32x4__mul, "f32x4.mul", 0xFD, 230) +OFD(F32x4__div, "f32x4.div", 0xFD, 231) +OFD(F32x4__min, "f32x4.min", 0xFD, 232) +OFD(F32x4__max, "f32x4.max", 0xFD, 233) +OFD(F32x4__pmin, "f32x4.pmin", 0xFD, 234) +OFD(F32x4__pmax, "f32x4.pmax", 0xFD, 235) +OFD(F64x2__abs, "f64x2.abs", 0xFD, 236) +OFD(F64x2__neg, "f64x2.neg", 0xFD, 237) +OFD(F64x2__sqrt, "f64x2.sqrt", 0xFD, 239) +OFD(F64x2__add, "f64x2.add", 0xFD, 240) +OFD(F64x2__sub, "f64x2.sub", 0xFD, 241) +OFD(F64x2__mul, "f64x2.mul", 0xFD, 242) +OFD(F64x2__div, "f64x2.div", 0xFD, 243) +OFD(F64x2__min, "f64x2.min", 0xFD, 244) +OFD(F64x2__max, "f64x2.max", 0xFD, 245) +OFD(F64x2__pmin, "f64x2.pmin", 0xFD, 246) +OFD(F64x2__pmax, "f64x2.pmax", 0xFD, 247) +OFD(I32x4__trunc_sat_f32x4_s, "i32x4.trunc_sat_f32x4_s", 0xFD, 248) +OFD(I32x4__trunc_sat_f32x4_u, "i32x4.trunc_sat_f32x4_u", 0xFD, 249) +OFD(F32x4__convert_i32x4_s, "f32x4.convert_i32x4_s", 0xFD, 250) +OFD(F32x4__convert_i32x4_u, "f32x4.convert_i32x4_u", 0xFD, 251) +OFD(I32x4__trunc_sat_f64x2_s_zero, "i32x4.trunc_sat_f64x2_s_zero", 0xFD, 252) +OFD(I32x4__trunc_sat_f64x2_u_zero, "i32x4.trunc_sat_f64x2_u_zero", 0xFD, 253) +OFD(F64x2__convert_low_i32x4_s, "f64x2.convert_low_i32x4_s", 0xFD, 254) +OFD(F64x2__convert_low_i32x4_u, "f64x2.convert_low_i32x4_u", 0xFD, 255) + +// 0xFE prefix - Relaxed SIMD Instructions (part 4) +OFD(I8x16__relaxed_swizzle, "i8x16.relaxed_swizzle", 0xFD, 256) +OFD(I32x4__relaxed_trunc_f32x4_s, "i32x4.relaxed_trunc_f32x4_s", 0xFD, 257) +OFD(I32x4__relaxed_trunc_f32x4_u, "i32x4.relaxed_trunc_f32x4_u", 0xFD, 258) +OFD(I32x4__relaxed_trunc_f64x2_s_zero, "i32x4.relaxed_trunc_f64x2_s_zero", 0xFD, + 259) +OFD(I32x4__relaxed_trunc_f64x2_u_zero, "i32x4.relaxed_trunc_f64x2_u_zero", 0xFD, + 260) +OFD(F32x4__relaxed_madd, "f32x4.relaxed_madd", 0xFD, 261) +OFD(F32x4__relaxed_nmadd, "f32x4.relaxed_nmadd", 0xFD, 262) +OFD(F64x2__relaxed_madd, "f32x4.relaxed_madd", 0xFD, 263) +OFD(F64x2__relaxed_nmadd, "f32x4.relaxed_nmadd", 0xFD, 264) +OFD(I8x16__relaxed_laneselect, "i8x16.relaxed_laneselect", 0xFD, 265) +OFD(I16x8__relaxed_laneselect, "i16x8.relaxed_laneselect", 0xFD, 266) +OFD(I32x4__relaxed_laneselect, "i32x4.relaxed_laneselect", 0xFD, 267) +OFD(I64x2__relaxed_laneselect, "i64x2.relaxed_laneselect", 0xFD, 268) +OFD(F32x4__relaxed_min, "f32x4.relaxed_min", 0xFD, 269) +OFD(F32x4__relaxed_max, "f32x4.relaxed_max", 0xFD, 270) +OFD(F64x2__relaxed_min, "f64x2.relaxed_min", 0xFD, 271) +OFD(F64x2__relaxed_max, "f64x2.relaxed_max", 0xFD, 272) +OFD(I16x8__relaxed_q15mulr_s, "i16x8.relaxed_q15mulr_s", 0xFD, 273) +OFD(I16x8__relaxed_dot_i8x16_i7x16_s, "i16x8.relaxed_dot_i8x16_i7x16_s", 0xFD, + 274) +OFD(I32x4__relaxed_dot_i8x16_i7x16_add_s, "i32x4.relaxed_dot_i8x16_i7x16_add_s", + 0xFD, 275) +// 0xFD 276 ~ 303: Reserved + +// 0xFE prefix - Atomic instructions +OFE(Memory__atomic__notify, "memory.atomic.notify", 0xFE, 0) +OFE(Memory__atomic__wait32, "memory.atomic.wait32", 0xFE, 1) +OFE(Memory__atomic__wait64, "memory.atomic.wait64", 0xFE, 2) +OFE(Atomic__fence, "atomic.fence", 0xFE, 3) +// 0xFE 4 ~ 15: Reserved +OFE(I32__atomic__load, "i32.atomic.load", 0xFE, 16) +OFE(I64__atomic__load, "i64.atomic.load", 0xFE, 17) +OFE(I32__atomic__load8_u, "i32.atomic.load8_u", 0xFE, 18) +OFE(I32__atomic__load16_u, "i32.atomic.load16_u", 0xFE, 19) +OFE(I64__atomic__load8_u, "i64.atomic.load8_u", 0xFE, 20) +OFE(I64__atomic__load16_u, "i64.atomic.load16_u", 0xFE, 21) +OFE(I64__atomic__load32_u, "i64.atomic.load32_u", 0xFE, 22) +OFE(I32__atomic__store, "i32.atomic.store", 0xFE, 23) +OFE(I64__atomic__store, "i64.atomic.store", 0xFE, 24) +OFE(I32__atomic__store8, "i32.atomic.store8", 0xFE, 25) +OFE(I32__atomic__store16, "i32.atomic.store16", 0xFE, 26) +OFE(I64__atomic__store8, "i64.atomic.store8", 0xFE, 27) +OFE(I64__atomic__store16, "i64.atomic.store16", 0xFE, 28) +OFE(I64__atomic__store32, "i64.atomic.store32", 0xFE, 29) +OFE(I32__atomic__rmw__add, "i32.atomic.rmw.add", 0xFE, 30) +OFE(I64__atomic__rmw__add, "i64.atomic.rmw.add", 0xFE, 31) +OFE(I32__atomic__rmw8__add_u, "i32.atomic.rmw8.add_u", 0xFE, 32) +OFE(I32__atomic__rmw16__add_u, "i32.atomic.rmw16.add_u", 0xFE, 33) +OFE(I64__atomic__rmw8__add_u, "i64.atomic.rmw8.add_u", 0xFE, 34) +OFE(I64__atomic__rmw16__add_u, "i64.atomic.rmw16.add_u", 0xFE, 35) +OFE(I64__atomic__rmw32__add_u, "i64.atomic.rmw32.add_u", 0xFE, 36) +OFE(I32__atomic__rmw__sub, "i32.atomic.rmw.sub", 0xFE, 37) +OFE(I64__atomic__rmw__sub, "i64.atomic.rmw.sub", 0xFE, 38) +OFE(I32__atomic__rmw8__sub_u, "i32.atomic.rmw8.sub_u", 0xFE, 39) +OFE(I32__atomic__rmw16__sub_u, "i32.atomic.rmw16.sub_u", 0xFE, 40) +OFE(I64__atomic__rmw8__sub_u, "i64.atomic.rmw8.sub_u", 0xFE, 41) +OFE(I64__atomic__rmw16__sub_u, "i64.atomic.rmw16.sub_u", 0xFE, 42) +OFE(I64__atomic__rmw32__sub_u, "i64.atomic.rmw32.sub_u", 0xFE, 43) +OFE(I32__atomic__rmw__and, "i32.atomic.rmw.and", 0xFE, 44) +OFE(I64__atomic__rmw__and, "i64.atomic.rmw.and", 0xFE, 45) +OFE(I32__atomic__rmw8__and_u, "i32.atomic.rmw8.and_u", 0xFE, 46) +OFE(I32__atomic__rmw16__and_u, "i32.atomic.rmw16.and_u", 0xFE, 47) +OFE(I64__atomic__rmw8__and_u, "i64.atomic.rmw8.and_u", 0xFE, 48) +OFE(I64__atomic__rmw16__and_u, "i64.atomic.rmw16.and_u", 0xFE, 49) +OFE(I64__atomic__rmw32__and_u, "i64.atomic.rmw32.and_u", 0xFE, 50) +OFE(I32__atomic__rmw__or, "i32.atomic.rmw.or", 0xFE, 51) +OFE(I64__atomic__rmw__or, "i64.atomic.rmw.or", 0xFE, 52) +OFE(I32__atomic__rmw8__or_u, "i32.atomic.rmw8.or_u", 0xFE, 53) +OFE(I32__atomic__rmw16__or_u, "i32.atomic.rmw16.or_u", 0xFE, 54) +OFE(I64__atomic__rmw8__or_u, "i64.atomic.rmw8.or_u", 0xFE, 55) +OFE(I64__atomic__rmw16__or_u, "i64.atomic.rmw16.or_u", 0xFE, 56) +OFE(I64__atomic__rmw32__or_u, "i64.atomic.rmw32.or_u", 0xFE, 57) +OFE(I32__atomic__rmw__xor, "i32.atomic.rmw.xor", 0xFE, 58) +OFE(I64__atomic__rmw__xor, "i64.atomic.rmw.xor", 0xFE, 59) +OFE(I32__atomic__rmw8__xor_u, "i32.atomic.rmw8.xor_u", 0xFE, 60) +OFE(I32__atomic__rmw16__xor_u, "i32.atomic.rmw16.xor_u", 0xFE, 61) +OFE(I64__atomic__rmw8__xor_u, "i64.atomic.rmw8.xor_u", 0xFE, 62) +OFE(I64__atomic__rmw16__xor_u, "i64.atomic.rmw16.xor_u", 0xFE, 63) +OFE(I64__atomic__rmw32__xor_u, "i64.atomic.rmw32.xor_u", 0xFE, 64) +OFE(I32__atomic__rmw__xchg, "i32.atomic.rmw.xchg", 0xFE, 65) +OFE(I64__atomic__rmw__xchg, "i64.atomic.rmw.xchg", 0xFE, 66) +OFE(I32__atomic__rmw8__xchg_u, "i32.atomic.rmw8.xchg_u", 0xFE, 67) +OFE(I32__atomic__rmw16__xchg_u, "i32.atomic.rmw16.xchg_u", 0xFE, 68) +OFE(I64__atomic__rmw8__xchg_u, "i64.atomic.rmw8.xchg_u", 0xFE, 69) +OFE(I64__atomic__rmw16__xchg_u, "i64.atomic.rmw16.xchg_u", 0xFE, 70) +OFE(I64__atomic__rmw32__xchg_u, "i64.atomic.rmw32.xchg_u", 0xFE, 71) +OFE(I32__atomic__rmw__cmpxchg, "i32.atomic.rmw.cmpxchg", 0xFE, 72) +OFE(I64__atomic__rmw__cmpxchg, "i64.atomic.rmw.cmpxchg", 0xFE, 73) +OFE(I32__atomic__rmw8__cmpxchg_u, "i32.atomic.rmw8.cmpxchg_u", 0xFE, 74) +OFE(I32__atomic__rmw16__cmpxchg_u, "i32.atomic.rmw16.cmpxchg_u", 0xFE, 75) +OFE(I64__atomic__rmw8__cmpxchg_u, "i64.atomic.rmw8.cmpxchg_u", 0xFE, 76) +OFE(I64__atomic__rmw16__cmpxchg_u, "i64.atomic.rmw16.cmpxchg_u", 0xFE, 77) +OFE(I64__atomic__rmw32__cmpxchg_u, "i64.atomic.rmw32.cmpxchg_u", 0xFE, 78) + +#undef O +#undef OFB +#undef OFC +#undef OFD +#undef OFE +#endif // UseOpCode + +// enum_configure.h + +#ifdef UseProposal +#define P Line +// Finished and standardized proposals +P(ImportExportMutGlobals, "Import/Export of Mutable Globals") +P(NonTrapFloatToIntConversions, "Non-trapping float-to-int Conversions") +P(SignExtensionOperators, "Sign-extension Operators") +P(MultiValue, "Multi-value") +P(BulkMemoryOperations, "Bulk Memory Operations") +P(ReferenceTypes, "Reference Types") +P(SIMD, "Fixed-width SIMD") +// Phase 4 proposals +P(TailCall, "Tail Call") +P(ExtendedConst, "Extended Const Expressions") +P(FunctionReferences, "Typed Function References") +P(GC, "Garbage Collection") +P(MultiMemories, "Multiple Memories") +P(Threads, "Threads") +P(RelaxSIMD, "Relaxed SIMD") +// Phase 3 proposals +P(Annotations, "Custom Annotation Syntax in the Text Format") +P(Memory64, "Memory64") +P(ExceptionHandling, "Exception Handling") +// Phase 1 proposals +P(Component, "Component Model") +#undef P +#endif // UseProposal + +#ifdef UseHostRegistration +#define H Line +H(Wasi) +#undef H +#endif // UseHostRegistration + +// enum_errcode.h + +#ifdef UseErrCategory +#define C Line + +C(WASM, 0x00) +C(UserLevelError, 0x01) + +#undef C +#endif // UseErrCategory + +#ifdef UseErrCode +#define E Line + +E(Success, 0x0000, "success") +// Exit and return success. +E(Terminated, 0x0001, "terminated") +// Generic runtime error. +E(RuntimeError, 0x0002, "generic runtime error") +// Exceeded cost limit (out of gas). +E(CostLimitExceeded, 0x0003, "cost limit exceeded") +// Wrong VM's workflow +E(WrongVMWorkflow, 0x0004, "wrong VM workflow") +// Wasm function not found +E(FuncNotFound, 0x0005, "wasm function not found") +// AOT runtime is disabled +E(AOTDisabled, 0x0006, "AOT runtime is disabled in this build") +// Execution interrupted +E(Interrupted, 0x0007, "execution interrupted") +// Not validated module +E(NotValidated, 0x0008, "wasm module hasn't passed validation yet") +// Non-Null value is required +E(NonNullRequired, 0x0009, "set null value into non-nullable value type") +// Unable to set value due to const +E(SetValueToConst, 0x000A, "set value into const") +// Set value failed due to mismatch value type +E(SetValueErrorType, 0x000B, "set value type mismatch") +// User defined error +E(UserDefError, 0x000C, "user defined error code") + +// Load phase +// @{ +// File not found +E(IllegalPath, 0x0100, "invalid path") +// Error when reading +E(ReadError, 0x0101, "read error") +// Reach end of file when reading +E(UnexpectedEnd, 0x0102, "unexpected end") +// Not detected magic header +E(MalformedMagic, 0x0103, "magic header not detected") +// Unsupported version +E(MalformedVersion, 0x0104, "unknown binary version") +// Malformed section ID +E(MalformedSection, 0x0105, "malformed section id") +// Section size mismatched +E(SectionSizeMismatch, 0x0106, "section size mismatch") +// Length out of bounds +E(LengthOutOfBounds, 0x0107, "length out of bounds") +// Junk sections +E(JunkSection, 0x0108, "unexpected content after last section") +// Incompatible function and code section +E(IncompatibleFuncCode, 0x0109, + "function and code section have inconsistent lengths") +// Incompatible data and datacount section +E(IncompatibleDataCount, 0x010A, + "data count and data section have inconsistent lengths") +// Datacount section required +E(DataCountRequired, 0x010B, "data count section required") +// Malformed import kind +E(MalformedImportKind, 0x010C, "malformed import kind") +// Malformed export kind +E(MalformedExportKind, 0x010D, "malformed export kind") +// Not loaded an expected zero byte +E(ExpectedZeroByte, 0x010E, "zero byte expected") +// Malformed mutability +E(InvalidMut, 0x010F, "malformed mutability") +// Local size too large +E(TooManyLocals, 0x0110, "too many locals") +// Malformed value type +E(MalformedValType, 0x0111, "malformed value type") +// Malformed element type (Bulk-mem proposal) +E(MalformedElemType, 0x0112, "malformed element type") +// Malformed reference type (Ref-types proposal) +E(MalformedRefType, 0x0113, "malformed reference type") +// Invalid utf-8 encoding +E(MalformedUTF8, 0x0114, "malformed UTF-8 encoding") +// Invalid too large integer +E(IntegerTooLarge, 0x0115, "integer too large") +// Invalid presentation too long integer +E(IntegerTooLong, 0x0116, "integer representation too long") +// Illegal OpCode +E(IllegalOpCode, 0x0117, "illegal opcode") +// END OpCode expected +E(ENDCodeExpected, 0x0118, "END opcode expected") +// Parsing error +E(IllegalGrammar, 0x0119, "invalid wasm grammar") +// Shared memory must have max +E(SharedMemoryNoMax, 0x011A, "shared memory must have maximum") +// Intrinsics table not found +E(IntrinsicsTableNotFound, 0x011B, "intrinsics table not found") +// Malformed table (Ref-types proposal) +E(MalformedTable, 0x011C, "malformed table") +// Alignment must < 64 without and < 128 with multi-memory proposal. +E(InvalidStoreAlignment, 0x011D, "invalid store alignment") +// @} + +// Validation phase +// @{ +// Alignment > natural +E(InvalidAlignment, 0x0200, "alignment must not be larger than natural") +// Got unexpected type when checking +E(TypeCheckFailed, 0x0201, "type mismatch") +// Branch to unknown label index +E(InvalidLabelIdx, 0x0202, "unknown label") +// Access unknown local index +E(InvalidLocalIdx, 0x0203, "unknown local") +// Access unknown field index +E(InvalidFieldIdx, 0x0204, "unknown field") +// Type index not defined +E(InvalidFuncTypeIdx, 0x0205, "unknown type") +// Function index not defined +E(InvalidFuncIdx, 0x0206, "unknown function") +// Table index not defined +E(InvalidTableIdx, 0x0207, "unknown table") +// Memory index not defined +E(InvalidMemoryIdx, 0x0208, "unknown memory") +// Global index not defined +E(InvalidGlobalIdx, 0x0209, "unknown global") +// Tag index not defined +E(InvalidTagIdx, 0x020A, "unknown tag") +// Element segment index not defined +E(InvalidElemIdx, 0x020B, "unknown elem segment") +// Data segment index not defined +E(InvalidDataIdx, 0x020C, "unknown data segment") +// Undeclared reference +E(InvalidRefIdx, 0x020D, "undeclared function reference") +// Should be constant expression +E(ConstExprRequired, 0x020E, "constant expression required") +// Export name conflicted +E(DupExportName, 0x020F, "duplicate export name") +// Tried to store to const global value +E(ImmutableGlobal, 0x0210, "global is immutable") +// Tried to store to const field of structure +E(ImmutableField, 0x0211, "field is immutable") +// Tried to store to const array +E(ImmutableArray, 0x0212, "array is immutable") +// Invalid result arity in select t* instruction +E(InvalidResultArity, 0x0213, "invalid result arity") +// #Tables > 1 (without Ref-types proposal) +E(MultiTables, 0x0214, "multiple tables") +// #Memories > 1 +E(MultiMemories, 0x0215, "multiple memories") +// Invalid Limit grammar +E(InvalidLimit, 0x0216, "size minimum must not be greater than maximum") +// Memory pages > 65536 +E(InvalidMemPages, 0x0217, "memory size must be at most 65536 pages (4GiB)") +// Invalid start function signature +E(InvalidStartFunc, 0x0218, "start function") +// Invalid lane index +E(InvalidLaneIdx, 0x0219, "invalid lane index") +// Invalid uninitialized local +E(InvalidUninitLocal, 0x021A, "uninitialized local") +// Defaultable field type required +E(InvalidNotDefaultableField, 0x021B, "field type is not defaultable") +// Defaultable array type required +E(InvalidNotDefaultableArray, 0x021C, "array type is not defaultable") +// Unpacked field type required, but got packed one +E(InvalidPackedField, 0x021D, "field is packed") +// Unpacked array type required, but got packed one +E(InvalidPackedArray, 0x021E, "array is packed") +// Packed field type required, but got unpacked one +E(InvalidUnpackedField, 0x021F, "field is unpacked") +// Packed array type required, but got unpacked one +E(InvalidUnpackedArray, 0x0220, "array is unpacked") +// Invalid Br ref type +E(InvalidBrRefType, 0x0221, "invalid br ref type") +// 2 array types not matched +E(ArrayTypesMismatch, 0x0222, "array types do not match") +// Should be numeric type in array type +E(ArrayTypesNumtypeRequired, 0x0223, "array type is not numeric or vector") +// Sub type matching or validation failed +E(InvalidSubType, 0x0224, "sub type") +// Invalid Tag type +E(InvalidTagResultType, 0x0225, "non-empty tag result type") +// @} + +// Instantiation phase +// @{ +// Module name conflicted when importing. +E(ModuleNameConflict, 0x0300, "module name conflict") +// Import matching failed +E(IncompatibleImportType, 0x0301, "incompatible import type") +// Unknown import instances +E(UnknownImport, 0x0302, "unknown import") +// Init failed when instantiating data segment +E(DataSegDoesNotFit, 0x0303, "data segment does not fit") +// Init failed when instantiating element segment +E(ElemSegDoesNotFit, 0x0304, "elements segment does not fit") +// Invalid core sort for component export +E(InvalidCoreSort, 0x0305, "invalid core sort") +E(InvalidCanonOption, 0x0306, "invalid canonical option") +// @} + +// Execution phase +// @{ +// Wrong access of instances addresses +E(WrongInstanceAddress, 0x0400, "wrong instance address") +// Wrong access of instances indices +E(WrongInstanceIndex, 0x0401, "wrong instance index") +// Instruction type not match +E(InstrTypeMismatch, 0x0402, "instruction type mismatch") +// Function signature not match when invoking +E(FuncSigMismatch, 0x0403, "function signature mismatch") +// Divide by zero +E(DivideByZero, 0x0404, "integer divide by zero") +// Integer overflow +E(IntegerOverflow, 0x0405, "integer overflow") +// Cannot do convert to integer +E(InvalidConvToInt, 0x0406, "invalid conversion to integer") +// Out of bounds table access +E(TableOutOfBounds, 0x0407, "out of bounds table access") +// Out of bounds memory access +E(MemoryOutOfBounds, 0x0408, "out of bounds memory access") +// Out of bounds array access +E(ArrayOutOfBounds, 0x0409, "out of bounds array access") +// Meet an unreachable instruction +E(Unreachable, 0x040A, "unreachable") +// Uninitialized element in table instance +E(UninitializedElement, 0x040B, "uninitialized element") +// Access undefined element in table instances +E(UndefinedElement, 0x040C, "undefined element") +// Func type mismatch in call_indirect +E(IndirectCallTypeMismatch, 0x040D, "indirect call type mismatch") +// Host function execution failed +E(HostFuncError, 0x040E, "host function failed") +// Reference type not match +E(RefTypeMismatch, 0x040F, "reference type mismatch") +// Unaligned atomic memory access +E(UnalignedAtomicAccess, 0x0410, "unaligned atomic") +// wait32/wait64 on unshared memory +E(ExpectSharedMemory, 0x0411, "expected shared memory") +// Cast null pointer to non null +E(CastNullToNonNull, 0x0412, "null reference") +// Access to null function reference +E(AccessNullFunc, 0x0413, "null function reference") +// Access to null structure reference +E(AccessNullStruct, 0x0414, "null structure reference") +// Access to null array reference +E(AccessNullArray, 0x0415, "null array reference") +// Access to null i31 reference +E(AccessNullI31, 0x0416, "null i31 reference") +// Access to null exception reference +E(AccessNullException, 0x0417, "null exception reference") +// Fail to cast reference +E(CastFailed, 0x0418, "cast failure") +// Uncaught Exception +E(UncaughtException, 0x0419, "uncaught exception") +// @} + +// Component model load phase +// @{ +// Malformed sort +E(MalformedSort, 0x0500, "malformed sort") +// Malformed alias target +E(MalformedAliasTarget, 0x0501, "malformed alias target") +// Malformed core instance +E(MalformedCoreInstance, 0x0502, "malformed core instance") +// Malformed instance +E(MalformedInstance, 0x0503, "malformed instance") +// Malformed defType +E(MalformedDefType, 0x0504, "malformed defined type") +// Malformed record type +E(MalformedRecordType, 0x0505, "malformed record type") +// Malformed variant type +E(MalformedVariantType, 0x0506, "malformed variant type") +// Malformed tuple type +E(MalformedTupleType, 0x0507, "malformed tuple type") +// Malformed flags type +E(MalformedFlagsType, 0x0508, "malformed flags type") +// Malformed canonical +E(MalformedCanonical, 0x0509, "malformed canonical") +// Unknown canonical option +E(UnknownCanonicalOption, 0x050A, "unknown canonical option") +// Malformed name +E(MalformedName, 0x050B, "malformed name") +// @} + +// Component model instantiation phase +// @{ +E(CoreInvalidExport, 0x0600, "invalid export in core module") +// @} + +#undef E +#endif // UseErrCode + +#ifdef UseWasmPhase +#define P Line + +P(WasmEdge, 0x00, "wasmedge runtime") +P(Loading, 0x01, "loading") +P(Validation, 0x02, "validation") +P(Instantiation, 0x03, "instantiation") +P(Execution, 0x04, "execution") +P(UserDefined, 0x05, "user defined") + +#undef P +#endif // UseWasmPhase + +// enum_errinfo.hpp + +#ifdef UsePtrType +#define P Line + +P(Index, "index") // Index of instances +P(Address, "address") // Absolute address + +#undef P +#endif // UsePtrType + +#ifdef UseMismatchCategory +#define M Line + +M(Alignment, "memory alignment") // Alignment in memory instructions +M(ValueType, "value type") // Value type +M(ValueTypes, "value types") // Value type list +M(Mutation, "mutation") // Const or Var +M(ExternalType, "external type") // External typing +M(FunctionType, "function type") // Function type +M(Table, "table") // Table instance +M(Memory, "memory") // Memory instance +M(Global, "global") // Global instance +M(Version, "version") // Versions + +#undef M +#endif // UseMismatchCategory + +#ifdef UseIndexCategory +#define I Line + +I(Label, "label") +I(Local, "local") +I(DefinedType, "defined type") +I(FunctionType, "function type") +I(Function, "function") +I(Table, "table") +I(Memory, "memory") +I(Global, "global") +I(Element, "element") +I(Data, "data") +I(Lane, "lane") +I(Field, "field") +I(TagType, "tag type") +I(Tag, "tag") + +#undef I +#endif // UseIndexCategory + +// enum_types.h + +#ifdef UseTypeCode +#define T Line + +T(TypeIndex, 0x00, "type_index") // 0x00 reserved for type index case +T(I32, 0x7F, "i32") // -0x01 for number type +T(I64, 0x7E, "i64") // -0x02 for number type +T(F32, 0x7D, "f32") // -0x03 for number type +T(F64, 0x7C, "f64") // -0x04 for number type +T(V128, 0x7B, "v128") // -0x05 for vector type +T(I8, 0x78, "i8") // -0x08 for packed type +T(I16, 0x77, "i16") // -0x09 for packed type +T(NullFuncRef, 0x73, "nofunc") // -0x0D for heap type +T(NullExternRef, 0x72, "noextern") // -0x0E for heap type +T(NullRef, 0x71, "none") // -0x0F for heap type +T(FuncRef, 0x70, "func") // -0x10 for heap type +T(ExternRef, 0x6F, "extern") // -0x11 for heap type +T(AnyRef, 0x6E, "any") // -0x12 for heap type +T(EqRef, 0x6D, "eq") // -0x13 for heap type +T(I31Ref, 0x6C, "i31") // -0x14 for heap type +T(StructRef, 0x6B, "struct") // -0x15 for heap type +T(ArrayRef, 0x6A, "array") // -0x16 for heap type +T(ExnRef, 0x69, "exn") // -0x17 for reference type +T(Ref, 0x64, "ref") // -0x1C for reference type +T(RefNull, 0x63, "ref_null") // -0x1D for reference type +T(Func, 0x60, "func") // -0x20 for composite type +T(Struct, 0x5F, "struct") // -0x21 for composite type +T(Array, 0x5E, "array") // -0x22 for composite type +T(Sub, 0x50, "sub") // -0x30 for sub type +T(SubFinal, 0x4F, "sub_final") // -0x31 for sub type +T(Rec, 0x4E, "rec") // -0x32 for recursive type +T(Epsilon, 0x40, "-") // -0x40 for result type +// component model types +T(String, 0x80, "string") // string type + +#undef T +#endif // UseTypeCode + +#ifdef UseValMut +#define M Line + +M(Const, 0x00, "const") +M(Var, 0x01, "var") + +#undef M +#endif // UseValMut + +#ifdef UseExternalType +#define E Line + +E(Function, 0x00U, "function") +E(Table, 0x01U, "table") +E(Memory, 0x02U, "memory") +E(Global, 0x03U, "global") +E(Tag, 0x04U, "tag") + +#undef E +#endif // UseExternalType diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_configure.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_configure.h new file mode 100644 index 0000000000000000000000000000000000000000..eb40f76c94c9bf0f1e1ea1751c1fa5e473f70824 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_configure.h @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_configure.h - Configure related enumerations -===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the definitions of configure related enumerations. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_CONFIGURE_H +#define WASMEDGE_C_API_ENUM_CONFIGURE_H + +/// WASM Proposal C enumeration. +enum WasmEdge_Proposal { +#define UseProposal +#define Line(NAME, STRING) WasmEdge_Proposal_##NAME, +#include "enum.inc" +#undef Line +#undef UseProposal +}; + +/// Host Module Registration C enumeration. +enum WasmEdge_HostRegistration { +#define UseHostRegistration +#define Line(NAME) WasmEdge_HostRegistration_##NAME, +#include "enum.inc" +#undef Line +#undef UseHostRegistration +}; + +/// AOT compiler optimization level C enumeration. +enum WasmEdge_CompilerOptimizationLevel { + // Disable as many optimizations as possible. + WasmEdge_CompilerOptimizationLevel_O0 = 0, + // Optimize quickly without destroying debuggability. + WasmEdge_CompilerOptimizationLevel_O1, + // Optimize for fast execution as much as possible without triggering + // significant incremental compile time or code size growth. + WasmEdge_CompilerOptimizationLevel_O2, + // Optimize for fast execution as much as possible. + WasmEdge_CompilerOptimizationLevel_O3, + // Optimize for small code size as much as possible without triggering + // significant incremental compile time or execution time slowdowns. + WasmEdge_CompilerOptimizationLevel_Os, + // Optimize for small code size as much as possible. + WasmEdge_CompilerOptimizationLevel_Oz +}; + +/// AOT compiler output binary format C enumeration. +enum WasmEdge_CompilerOutputFormat { + // Native dynamic library format. + WasmEdge_CompilerOutputFormat_Native = 0, + // WebAssembly with AOT compiled codes in custom sections. + WasmEdge_CompilerOutputFormat_Wasm +}; + +#endif // WASMEDGE_C_API_ENUM_CONFIGURE_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_errcode.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_errcode.h new file mode 100644 index 0000000000000000000000000000000000000000..68292cbcd960105fcf6f53699407657f4c5b1d13 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_errcode.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_errcode.h - Error code enumerations ----------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the enumerations of WasmEdge error code. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_ERRCODE_H +#define WASMEDGE_C_API_ENUM_ERRCODE_H + +/// Error category C enumeration. +enum WasmEdge_ErrCategory { +#define UseErrCategory +#define Line(NAME, VALUE) WasmEdge_ErrCategory_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseErrCategory +}; + +/// Error code C enumeration. +enum WasmEdge_ErrCode { +#define UseErrCode +#define Line(NAME, VALUE, STRING) WasmEdge_ErrCode_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseErrCode +}; + +#endif // WASMEDGE_C_API_ENUM_ERRCODE_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_types.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_types.h new file mode 100644 index 0000000000000000000000000000000000000000..4b89c003f2e6aaed143c22667c0a51a62315b1b8 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/enum_types.h @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/common/enum_types.h - WASM types related enumerations ----===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the definitions of WASM types related enumerations. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_ENUM_TYPES_H +#define WASMEDGE_C_API_ENUM_TYPES_H + +/// WASM Type code C enumeration. +enum WasmEdge_TypeCode { +#define UseTypeCode +#define Line(NAME, VALUE, STRING) WasmEdge_TypeCode_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseTypeCode +}; + +/// WASM Mutability C enumeration. +enum WasmEdge_Mutability { +#define UseValMut +#define Line(NAME, VALUE, STRING) WasmEdge_Mutability_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseValMut +}; + +/// WASM External type C enumeration. +enum WasmEdge_ExternalType { +#define UseExternalType +#define Line(NAME, VALUE, STRING) WasmEdge_ExternalType_##NAME = VALUE, +#include "enum.inc" +#undef Line +#undef UseExternalType +}; + +#endif // WASMEDGE_C_API_ENUM_TYPES_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/int128.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/int128.h new file mode 100644 index 0000000000000000000000000000000000000000..c4706fb22b4104231b67d381ac2aeb6a740fc84d --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/int128.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/int128.h - WasmEdge C API --------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the int128 definitions of the WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_INT128_H +#define WASMEDGE_C_API_INT128_H + +#if defined(__x86_64__) || defined(__aarch64__) || \ + (defined(__riscv) && __riscv_xlen == 64) +typedef unsigned __int128 uint128_t; +typedef __int128 int128_t; +#else +typedef struct uint128_t { + uint64_t Low; + uint64_t High; +} uint128_t; + +typedef struct int128_t { + uint64_t Low; + int64_t High; +} int128_t; +#endif + +#endif /// WASMEDGE_C_API_INT128_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/version.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/version.h new file mode 100644 index 0000000000000000000000000000000000000000..2e092f7dfa0ec2d217602a331f2c802d38757539 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/version.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/version.h - WasmEdge C API -------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the version definitions of the WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_VERSION_H +#define WASMEDGE_C_API_VERSION_H + +// WasmEdge version. +#define WASMEDGE_VERSION "0.14.1-rc.3" +#define WASMEDGE_VERSION_MAJOR 0 +#define WASMEDGE_VERSION_MINOR 14 +#define WASMEDGE_VERSION_PATCH 1 + +#define WasmEdge_Plugin_CurrentAPIVersion 4 + +#endif // WASMEDGE_C_API_VERSION_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/wasmedge.h b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/wasmedge.h new file mode 100644 index 0000000000000000000000000000000000000000..8585c2f734cb38410f316fdfbe64d48180cfcd7b --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/include/wasmedge/wasmedge.h @@ -0,0 +1,4183 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2019-2024 Second State INC + +//===-- wasmedge/wasmedge.h - WasmEdge C API ------------------------------===// +// +// Part of the WasmEdge Project. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the function declarations of WasmEdge C API. +/// +//===----------------------------------------------------------------------===// + +#ifndef WASMEDGE_C_API_H +#define WASMEDGE_C_API_H + +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \ + defined(__TOS_WIN__) || defined(__WINDOWS__) +#ifdef WASMEDGE_COMPILE_LIBRARY +#define WASMEDGE_CAPI_EXPORT __declspec(dllexport) +#else +#define WASMEDGE_CAPI_EXPORT __declspec(dllimport) +#endif // WASMEDGE_COMPILE_LIBRARY +#ifdef WASMEDGE_PLUGIN +#define WASMEDGE_CAPI_PLUGIN_EXPORT __declspec(dllexport) +#else +#define WASMEDGE_CAPI_PLUGIN_EXPORT __declspec(dllimport) +#endif // WASMEDGE_PLUGIN +#else +#define WASMEDGE_CAPI_EXPORT __attribute__((visibility("default"))) +#define WASMEDGE_CAPI_PLUGIN_EXPORT __attribute__((visibility("default"))) +#endif // _WIN32 + +#include +#include + +#include "wasmedge/enum_configure.h" +#include "wasmedge/enum_errcode.h" +#include "wasmedge/enum_types.h" +#include "wasmedge/int128.h" +#include "wasmedge/version.h" + +/// WasmEdge WASM value type struct. +typedef struct WasmEdge_ValType { + // This struct contains the raw data which describes the value type in WASM. + // Developers should use the corresponding `WasmEdge_ValueTypeGen` functions + // to generate this struct. + uint8_t Data[8]; +} WasmEdge_ValType; + +/// WasmEdge WASM value struct. +typedef struct WasmEdge_Value { + uint128_t Value; + // The value type `Type` is used in the parameters or returns of invoking + // functions. Developers should use the corresponding `WasmEdge_ValueGen` + // functions to generate this struct, and the `WasmEdge_ValueGet` functions to + // retrieve the value from this struct. + WasmEdge_ValType Type; +} WasmEdge_Value; + +/// WasmEdge string struct. +typedef struct WasmEdge_String { + uint32_t Length; + const char *Buf; +} WasmEdge_String; + +/// WasmEdge bytes struct. +typedef struct WasmEdge_Bytes { + uint32_t Length; + const uint8_t *Buf; +} WasmEdge_Bytes; + +/// WasmEdge result struct. +typedef struct WasmEdge_Result { + uint32_t Code; +} WasmEdge_Result; +#ifdef __cplusplus +#define WasmEdge_Result_Success (WasmEdge_Result{/* Code */ 0x00}) +#define WasmEdge_Result_Terminate (WasmEdge_Result{/* Code */ 0x01}) +#define WasmEdge_Result_Fail (WasmEdge_Result{/* Code */ 0x02}) +#else +#define WasmEdge_Result_Success ((WasmEdge_Result){.Code = 0x00}) +#define WasmEdge_Result_Terminate ((WasmEdge_Result){.Code = 0x01}) +#define WasmEdge_Result_Fail ((WasmEdge_Result){.Code = 0x02}) +#endif +/// Struct of WASM limit. +typedef struct WasmEdge_Limit { + /// Boolean to describe has max value or not. + bool HasMax; + /// Boolean to describe is shared memory or not. + bool Shared; + /// Minimum value. + uint32_t Min; + /// Maximum value. Will be ignored if the `HasMax` is false. + uint32_t Max; +} WasmEdge_Limit; + +/// Opaque struct of WasmEdge configure. +typedef struct WasmEdge_ConfigureContext WasmEdge_ConfigureContext; + +/// Opaque struct of WasmEdge statistics. +typedef struct WasmEdge_StatisticsContext WasmEdge_StatisticsContext; + +/// Opaque struct of WasmEdge AST module. +typedef struct WasmEdge_ASTModuleContext WasmEdge_ASTModuleContext; + +/// Opaque struct of WasmEdge function type. +typedef struct WasmEdge_FunctionTypeContext WasmEdge_FunctionTypeContext; + +/// Opaque struct of WasmEdge memory type. +typedef struct WasmEdge_MemoryTypeContext WasmEdge_MemoryTypeContext; + +/// Opaque struct of WasmEdge table type. +typedef struct WasmEdge_TableTypeContext WasmEdge_TableTypeContext; + +/// Opaque struct of WasmEdge tag type. +typedef struct WasmEdge_TagTypeContext WasmEdge_TagTypeContext; + +/// Opaque struct of WasmEdge global type. +typedef struct WasmEdge_GlobalTypeContext WasmEdge_GlobalTypeContext; + +/// Opaque struct of WasmEdge import type. +typedef struct WasmEdge_ImportTypeContext WasmEdge_ImportTypeContext; + +/// Opaque struct of WasmEdge export type. +typedef struct WasmEdge_ExportTypeContext WasmEdge_ExportTypeContext; + +/// Opaque struct of WasmEdge AOT compiler. +typedef struct WasmEdge_CompilerContext WasmEdge_CompilerContext; + +/// Opaque struct of WasmEdge loader. +typedef struct WasmEdge_LoaderContext WasmEdge_LoaderContext; + +/// Opaque struct of WasmEdge validator. +typedef struct WasmEdge_ValidatorContext WasmEdge_ValidatorContext; + +/// Opaque struct of WasmEdge executor. +typedef struct WasmEdge_ExecutorContext WasmEdge_ExecutorContext; + +/// Opaque struct of WasmEdge store. +typedef struct WasmEdge_StoreContext WasmEdge_StoreContext; + +/// Opaque struct of WasmEdge module instance. +typedef struct WasmEdge_ModuleInstanceContext WasmEdge_ModuleInstanceContext; + +/// Opaque struct of WasmEdge function instance. +typedef struct WasmEdge_FunctionInstanceContext + WasmEdge_FunctionInstanceContext; + +/// Opaque struct of WasmEdge table instance. +typedef struct WasmEdge_TableInstanceContext WasmEdge_TableInstanceContext; + +/// Opaque struct of WasmEdge memory instance. +typedef struct WasmEdge_MemoryInstanceContext WasmEdge_MemoryInstanceContext; + +/// Opaque struct of WasmEdge tag instance. +typedef struct WasmEdge_TagInstanceContext WasmEdge_TagInstanceContext; + +/// Opaque struct of WasmEdge global instance. +typedef struct WasmEdge_GlobalInstanceContext WasmEdge_GlobalInstanceContext; + +/// Opaque struct of WasmEdge calling frame. +typedef struct WasmEdge_CallingFrameContext WasmEdge_CallingFrameContext; + +/// Opaque struct of WasmEdge asynchronous result. +typedef struct WasmEdge_Async WasmEdge_Async; + +/// Opaque struct of WasmEdge VM. +typedef struct WasmEdge_VMContext WasmEdge_VMContext; + +/// Opaque struct of WasmEdge Plugin. +typedef struct WasmEdge_PluginContext WasmEdge_PluginContext; + +/// Type of option value. +typedef enum WasmEdge_ProgramOptionType { + /// No option value. + WasmEdge_ProgramOptionType_None, + /// Boolean value. + WasmEdge_ProgramOptionType_Toggle, + WasmEdge_ProgramOptionType_Int8, + WasmEdge_ProgramOptionType_Int16, + WasmEdge_ProgramOptionType_Int32, + WasmEdge_ProgramOptionType_Int64, + WasmEdge_ProgramOptionType_UInt8, + WasmEdge_ProgramOptionType_UInt16, + WasmEdge_ProgramOptionType_UInt32, + WasmEdge_ProgramOptionType_UInt64, + WasmEdge_ProgramOptionType_Float, + WasmEdge_ProgramOptionType_Double, + /// WasmEdge_String. + WasmEdge_ProgramOptionType_String, +} WasmEdge_ProgramOptionType; + +/// Program option for plugins. +typedef struct WasmEdge_ProgramOption { + const char *Name; + const char *Description; + WasmEdge_ProgramOptionType Type; + void *Storage; + const void *DefaultValue; +} WasmEdge_ProgramOption; + +/// Module descriptor for plugins. +typedef struct WasmEdge_ModuleDescriptor { + const char *Name; + const char *Description; + WasmEdge_ModuleInstanceContext *(*Create)( + const struct WasmEdge_ModuleDescriptor *); +} WasmEdge_ModuleDescriptor; + +/// Version data for plugins. +typedef struct WasmEdge_PluginVersionData { + uint32_t Major; + uint32_t Minor; + uint32_t Patch; + uint32_t Build; +} WasmEdge_PluginVersionData; + +/// Plugin descriptor for plugins. +typedef struct WasmEdge_PluginDescriptor { + const char *Name; + const char *Description; + uint32_t APIVersion; + WasmEdge_PluginVersionData Version; + uint32_t ModuleCount; + uint32_t ProgramOptionCount; + WasmEdge_ModuleDescriptor *ModuleDescriptions; + WasmEdge_ProgramOption *ProgramOptions; +} WasmEdge_PluginDescriptor; + +#ifdef __cplusplus +extern "C" { +#endif + +// >>>>>>>> WasmEdge version functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the version string of the WasmEdge C API. +/// +/// The returned string must __NOT__ be destroyed. +/// +/// \returns NULL-terminated C string of version. +WASMEDGE_CAPI_EXPORT extern const char *WasmEdge_VersionGet(void); + +/// Get the major version value of the WasmEdge C API. +/// +/// \returns Value of the major version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetMajor(void); + +/// Get the minor version value of the WasmEdge C API. +/// +/// \returns Value of the minor version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetMinor(void); + +/// Get the patch version value of the WasmEdge C API. +/// +/// \returns Value of the patch version. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VersionGetPatch(void); + +// <<<<<<<< WasmEdge version functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge logging functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Set the logging system to filter to error level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogSetErrorLevel(void); + +/// Set the logging system to filter to debug level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogSetDebugLevel(void); + +/// Set the logging system off. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_LogOff(void); + +// <<<<<<<< WasmEdge logging functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge valtype functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Generate the I32 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the I32 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenI32(void); + +/// Generate the I64 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the I64 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenI64(void); + +/// Generate the F32 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the F32 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenF32(void); + +/// Generate the F64 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the F64 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenF64(void); + +/// Generate the V128 WASM value type. +/// +/// \returns WasmEdge_ValType struct with the V128 value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenV128(void); + +/// Generate the FuncRef WASM value type. +/// +/// \returns WasmEdge_ValType struct with the FuncRef value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenFuncRef(void); + +/// Generate the ExternRef WASM value type. +/// +/// \returns WasmEdge_ValType struct with the ExternRef value type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType WasmEdge_ValTypeGenExternRef(void); + +/// Compare the two WasmEdge_ValType objects. +/// +/// \param ValType1 the first WasmEdge_ValType object to compare. +/// \param ValType2 the second WasmEdge_ValType object to compare. +/// +/// \returns true if the content of two WasmEdge_ValType objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsEqual(const WasmEdge_ValType ValType1, + const WasmEdge_ValType ValType2); + +/// Specify the WASM value type is an I32 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an I32, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsI32(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is an I64 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an I64, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsI64(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a F32 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a F32, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsF32(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a F64 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a F64, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsF64(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a V128 or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a V128, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsV128(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a FuncRef or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a FuncRef, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsFuncRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is an ExternRef or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is an ExternRef, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsExternRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a Ref (includes nullable and non-nullable) or +/// not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a Ref, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsRef(const WasmEdge_ValType ValType); + +/// Specify the WASM value type is a nullable Ref or not. +/// +/// \param ValType the WasmEdge_ValType object to check. +/// +/// \returns true if the value type is a nullable Ref, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValTypeIsRefNull(const WasmEdge_ValType ValType); + +// <<<<<<<< WasmEdge valtype functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge value functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Generate the I32 WASM value. +/// +/// \param Val the I32 value. +/// +/// \returns WasmEdge_Value struct with the I32 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenI32(const int32_t Val); + +/// Generate the I64 WASM value. +/// +/// \param Val the I64 value. +/// +/// \returns WasmEdge_Value struct with the I64 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenI64(const int64_t Val); + +/// Generate the F32 WASM value. +/// +/// \param Val the F32 value. +/// +/// \returns WasmEdge_Value struct with the F32 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenF32(const float Val); + +/// Generate the F64 WASM value. +/// +/// \param Val the F64 value. +/// +/// \returns WasmEdge_Value struct with the F64 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenF64(const double Val); + +/// Generate the V128 WASM value. +/// +/// \param Val the V128 value. +/// +/// \returns WasmEdge_Value struct with the V128 value. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenV128(const int128_t Val); + +/// Generate the function reference WASM value. +/// +/// The values generated by this function are only meaningful when the +/// `WasmEdge_Proposal_BulkMemoryOperations` or the +/// `WasmEdge_Proposal_ReferenceTypes` turns on in configuration. +/// +/// \param Cxt the function instance context to convert to the reference. +/// +/// \returns WasmEdge_Value struct with the function reference. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenFuncRef(const WasmEdge_FunctionInstanceContext *Cxt); + +/// Generate the function reference WASM value. +/// +/// The values generated by this function are only meaningful when the +/// `WasmEdge_Proposal_ReferenceTypes` turns on in configuration. +/// +/// \param Ref the reference to the external object. +/// +/// \returns WasmEdge_Value struct with the external reference. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_ValueGenExternRef(void *Ref); + +/// Retrieve the I32 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns I32 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int32_t +WasmEdge_ValueGetI32(const WasmEdge_Value Val); + +/// Retrieve the I64 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns I64 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int64_t +WasmEdge_ValueGetI64(const WasmEdge_Value Val); + +/// Retrieve the F32 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns F32 value in the input struct. +WASMEDGE_CAPI_EXPORT extern float +WasmEdge_ValueGetF32(const WasmEdge_Value Val); + +/// Retrieve the F64 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns F64 value in the input struct. +WASMEDGE_CAPI_EXPORT extern double +WasmEdge_ValueGetF64(const WasmEdge_Value Val); + +/// Retrieve the V128 value from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns V128 value in the input struct. +WASMEDGE_CAPI_EXPORT extern int128_t +WasmEdge_ValueGetV128(const WasmEdge_Value Val); + +/// Specify the WASM value is a null reference or not. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns true if the value is a null reference, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ValueIsNullRef(const WasmEdge_Value Val); + +/// Retrieve the function instance context from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns pointer to function instance context in the input struct. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionInstanceContext * +WasmEdge_ValueGetFuncRef(const WasmEdge_Value Val); + +/// Retrieve the external reference from the WASM value. +/// +/// \param Val the WasmEdge_Value struct. +/// +/// \returns external reference in the input struct. +WASMEDGE_CAPI_EXPORT extern void * +WasmEdge_ValueGetExternRef(const WasmEdge_Value Val); + +// <<<<<<<< WasmEdge value functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge string functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_String with the C string. +/// +/// The caller owns the object and should call `WasmEdge_StringDelete` to +/// destroy it. This function only supports the C string with NULL termination. +/// If the input string may have `\0` character, please use the +/// `WasmEdge_StringCreateByBuffer` instead. +/// +/// \param Str the NULL-terminated C string to copy into the WasmEdge_String +/// object. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed or +/// the input string is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringCreateByCString(const char *Str); + +/// Creation of the WasmEdge_String with the buffer and its length. +/// +/// The caller owns the object and should call `WasmEdge_StringDelete` to +/// destroy it. +/// +/// \param Buf the buffer to wrap to the WasmEdge_String object. +/// \param Len the buffer length. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed or +/// the input buffer is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringCreateByBuffer(const char *Buf, const uint32_t Len); + +/// Create the WasmEdge_String wraps to the buffer. +/// +/// This function creates a `WasmEdge_String` object which wraps to the input +/// buffer. The caller should guarantee the life cycle of the input buffer, and +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Buf the buffer to copy into the WasmEdge_String object. +/// \param Len the buffer length. +/// +/// \returns string object refer to the input buffer with its length. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_StringWrap(const char *Buf, const uint32_t Len); + +/// Compare the two WasmEdge_String objects. +/// +/// \param Str1 the first WasmEdge_String object to compare. +/// \param Str2 the second WasmEdge_String object to compare. +/// +/// \returns true if the content of two WasmEdge_String objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_StringIsEqual(const WasmEdge_String Str1, const WasmEdge_String Str2); + +/// Copy the content of WasmEdge_String object to the buffer. +/// +/// This function copy at most `Len` characters from the `WasmEdge_String` +/// object to the destination buffer. If the string length is less than `Len` +/// characters long, the remainder of the buffer is filled with `\0' characters. +/// Otherwise, the destination is not terminated. +/// +/// \param Str the source WasmEdge_String object to copy. +/// \param Buf the buffer to fill the string content. +/// \param Len the buffer length. +/// +/// \returns the copied length of string. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StringCopy(const WasmEdge_String Str, char *Buf, const uint32_t Len); + +/// Deletion of the WasmEdge_String. +/// +/// After calling this function, the resources in the WasmEdge_String object +/// will be released and the object should __NOT__ be used. +/// +/// \param Str the WasmEdge_String object to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_StringDelete(WasmEdge_String Str); + +// <<<<<<<< WasmEdge string functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge bytes functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_Bytes with the buffer and its length. +/// +/// The caller owns the object and should call `WasmEdge_BytesDelete` to destroy +/// it. +/// +/// \param Buf the buffer to copy into the WasmEdge_Bytes object. +/// \param Len the buffer length. +/// +/// \returns bytes object. Length will be 0 and Buf will be NULL if failed or +/// the input buffer is a NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Bytes +WasmEdge_BytesCreate(const uint8_t *Buf, const uint32_t Len); + +/// Create the WasmEdge_Bytes wraps to the buffer. +/// +/// This function creates a `WasmEdge_Bytes` object which wraps to the input +/// buffer. The caller should guarantee the life cycle of the input buffer, and +/// should __NOT__ call the `WasmEdge_BytesDelete`. +/// +/// \param Buf the buffer to wrap to the WasmEdge_Bytes object. +/// \param Len the buffer length. +/// +/// \returns bytes object refer to the input buffer with its length. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Bytes +WasmEdge_BytesWrap(const uint8_t *Buf, const uint32_t Len); + +/// Deletion of the WasmEdge_Bytes. +/// +/// After calling this function, the resources in the WasmEdge_Bytes object +/// will be released and the object should __NOT__ be used. +/// +/// \param Bytes the WasmEdge_Bytes object to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_BytesDelete(WasmEdge_Bytes Bytes); + +// <<<<<<<< WasmEdge bytes functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge result functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Check the result is a success or not. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns true if the error code is WasmEdge_Result_Success or +/// WasmEdge_Result_Terminate, false for others. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ResultOK(const WasmEdge_Result Res); + +/// Generate the result with code. +/// +/// \param Category the WasmEdge_ErrCategory to specify the error category. +/// \param Code the 24-bit length error code. The data exceeds 24 bits will be +/// stripped. +/// +/// \returns WasmEdge_Result struct with the given data. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ResultGen(const enum WasmEdge_ErrCategory Category, + const uint32_t Code); + +/// Get the result code. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns result code (24-bit size data) in the WasmEdge_Result struct. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ResultGetCode(const WasmEdge_Result Res); + +/// Get the error category. +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns error category in the WasmEdge_Result struct. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ErrCategory +WasmEdge_ResultGetCategory(const WasmEdge_Result Res); + +/// Get the result message. +/// +/// The returned string must __NOT__ be destroyed. +/// If the error category of the result is __NOT__ `WasmEdge_ErrCategory_WASM`, +/// the message will always be "user defined error code". +/// +/// \param Res the WasmEdge_Result struct. +/// +/// \returns NULL-terminated C string of the corresponding error message. +WASMEDGE_CAPI_EXPORT extern const char * +WasmEdge_ResultGetMessage(const WasmEdge_Result Res); + +// <<<<<<<< WasmEdge result functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge limit functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Compare the two WasmEdge_Limit objects. +/// +/// \param Lim1 the first WasmEdge_Limit object to compare. +/// \param Lim2 the second WasmEdge_Limit object to compare. +/// +/// \returns true if the content of two WasmEdge_Limit objects are the same, +/// false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_LimitIsEqual(const WasmEdge_Limit Lim1, const WasmEdge_Limit Lim2); + +// <<<<<<<< WasmEdge limit functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge configure functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ConfigureContext. +/// +/// The caller owns the object and should call `WasmEdge_ConfigureDelete` to +/// destroy it. +/// +/// \returns pointer to the context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ConfigureContext * +WasmEdge_ConfigureCreate(void); + +/// Add a proposal setting into the WasmEdge_ConfigureContext. +/// +/// For turning on a specific WASM proposal in VM, loader, or compiler contexts, +/// etc., you can set the proposal value into the WasmEdge_ConfigureContext and +/// create the VM, loader, or compiler contexts, etc. with this context. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_BulkMemoryOperations); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_ReferenceTypes); +/// WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_SIMD); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to add the proposal value. +/// \param Prop the proposal value. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureAddProposal(WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Remove a proposal setting in the WasmEdge_ConfigureContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to remove the proposal. +/// \param Prop the proposal value. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureRemoveProposal(WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Check if a proposal setting exists in the WasmEdge_ConfigureContext or not. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to check the proposal value. +/// \param Prop the proposal value. +/// +/// \returns true if the proposal setting exists, false if not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureHasProposal(const WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_Proposal Prop); + +/// Add a built-in host registration setting into WasmEdge_ConfigureContext. +/// +/// For turning on the Wasi support in `WasmEdge_VMContext`, you can set the +/// built-in host registration value into the `WasmEdge_ConfigureContext` and +/// create VM with this context. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddHostRegistration(Conf, WasmEdge_HostRegistration_Wasi); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to add built-in host registration. +/// \param Host the built-in host registration value. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureAddHostRegistration( + WasmEdge_ConfigureContext *Cxt, const enum WasmEdge_HostRegistration Host); + +/// Remove a built-in host registration setting in the +/// WasmEdge_ConfigureContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to remove the host +/// pre-registration. +/// \param Host the built-in host registration value. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureRemoveHostRegistration( + WasmEdge_ConfigureContext *Cxt, const enum WasmEdge_HostRegistration Host); + +/// Check if a built-in host registration setting exists in the +/// WasmEdge_ConfigureContext or not. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to check the host pre-registration. +/// \param Host the built-in host registration value. +/// +/// \returns true if the built-in host registration setting exists, false if +/// not. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureHasHostRegistration( + const WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_HostRegistration Host); + +/// Set the page limit of memory instances. +/// +/// Limit the page count (64KiB per page) in memory instances. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the maximum page count. +/// \param Page the maximum page count. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetMaxMemoryPage(WasmEdge_ConfigureContext *Cxt, + const uint32_t Page); + +/// Get the setting of the page limit of memory instances. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the maximum page count +/// setting. +/// +/// \returns the page count limitation value. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ConfigureGetMaxMemoryPage(const WasmEdge_ConfigureContext *Cxt); + +/// Set the force interpreter mode execution option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsForceInterpreter the boolean value to determine to forcibly run +/// WASM in interpreter mode or not. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetForceInterpreter(WasmEdge_ConfigureContext *Cxt, + const bool IsForceInterpreter); + +/// Get the force interpreter mode execution option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to forcibly run WASM in interpreter +/// mode or not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureIsForceInterpreter(const WasmEdge_ConfigureContext *Cxt); + +/// Set the option of enabling/disabling AF_UNIX support in the WASI socket. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param EnableAFUNIX the boolean value to determine to enable +/// the AF_UNIX support in the WASI socket or not. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureSetAllowAFUNIX(WasmEdge_ConfigureContext *Cxt, + const bool EnableAFUNIX); + +/// Get the AllowAFUNIX option. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to enable AF_UNIX support in the +/// WASI socket or not. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureIsAllowAFUNIX(const WasmEdge_ConfigureContext *Cxt); + +/// Set the optimization level of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the optimization level. +/// \param Level the AOT compiler optimization level. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureCompilerSetOptimizationLevel( + WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_CompilerOptimizationLevel Level); + +/// Get the optimization level of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the optimization level. +/// +/// \returns the AOT compiler optimization level. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_CompilerOptimizationLevel +WasmEdge_ConfigureCompilerGetOptimizationLevel( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the output binary format of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the output binary format. +/// \param Format the AOT compiler output binary format. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ConfigureCompilerSetOutputFormat( + WasmEdge_ConfigureContext *Cxt, + const enum WasmEdge_CompilerOutputFormat Format); + +/// Get the output binary format of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the output binary format. +/// +/// \returns the AOT compiler output binary format. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_CompilerOutputFormat +WasmEdge_ConfigureCompilerGetOutputFormat(const WasmEdge_ConfigureContext *Cxt); + +/// Set the dump IR option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsDump the boolean value to determine to dump IR or not when +/// compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetDumpIR(WasmEdge_ConfigureContext *Cxt, + const bool IsDump); + +/// Get the dump IR option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to dump IR or not when compilation +/// in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsDumpIR(const WasmEdge_ConfigureContext *Cxt); + +/// Set the generic binary option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsGeneric the boolean value to determine to generate the generic +/// binary or not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetGenericBinary(WasmEdge_ConfigureContext *Cxt, + const bool IsGeneric); + +/// Get the generic binary option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to generate the generic binary or +/// not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsGenericBinary(const WasmEdge_ConfigureContext *Cxt); + +/// Set the interruptible option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsInterruptible the boolean value to determine to generate +/// interruptible binary or not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureCompilerSetInterruptible(WasmEdge_ConfigureContext *Cxt, + const bool IsInterruptible); + +/// Get the interruptible option of the AOT compiler. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to generate interruptible binary or +/// not when compilation in AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureCompilerIsInterruptible(const WasmEdge_ConfigureContext *Cxt); + +/// Set the instruction counting option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsCount the boolean value to determine to support instruction +/// counting when execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetInstructionCounting( + WasmEdge_ConfigureContext *Cxt, const bool IsCount); + +/// Get the instruction counting option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support instruction counting when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool +WasmEdge_ConfigureStatisticsIsInstructionCounting( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the cost measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsMeasure the boolean value to determine to support cost measuring +/// when execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetCostMeasuring(WasmEdge_ConfigureContext *Cxt, + const bool IsMeasure); + +/// Get the cost measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support cost measuring when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureStatisticsIsCostMeasuring( + const WasmEdge_ConfigureContext *Cxt); + +/// Set the time measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to set the boolean value. +/// \param IsMeasure the boolean value to determine to support time when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureStatisticsSetTimeMeasuring(WasmEdge_ConfigureContext *Cxt, + const bool IsMeasure); + +/// Get the time measuring option for the statistics. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to get the boolean value. +/// +/// \returns the boolean value to determine to support time measuring when +/// execution or not after compilation by the AOT compiler. +WASMEDGE_CAPI_EXPORT extern bool WasmEdge_ConfigureStatisticsIsTimeMeasuring( + const WasmEdge_ConfigureContext *Cxt); + +/// Deletion of the WasmEdge_ConfigureContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ConfigureContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ConfigureDelete(WasmEdge_ConfigureContext *Cxt); + +// <<<<<<<< WasmEdge configure functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge statistics functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_StatisticsContext. +/// +/// The caller owns the object and should call `WasmEdge_StatisticsDelete` to +/// destroy it. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StatisticsContext * +WasmEdge_StatisticsCreate(void); + +/// Get the instruction count in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the instruction count in total execution. +WASMEDGE_CAPI_EXPORT extern uint64_t +WasmEdge_StatisticsGetInstrCount(const WasmEdge_StatisticsContext *Cxt); + +/// Get the instruction count per second in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the instruction count per second. +WASMEDGE_CAPI_EXPORT extern double +WasmEdge_StatisticsGetInstrPerSecond(const WasmEdge_StatisticsContext *Cxt); + +/// Get the total cost in execution. +/// +/// \param Cxt the WasmEdge_StatisticsContext to get data. +/// +/// \returns the total cost. +WASMEDGE_CAPI_EXPORT extern uint64_t +WasmEdge_StatisticsGetTotalCost(const WasmEdge_StatisticsContext *Cxt); + +/// Set the costs of instructions. +/// +/// \param Cxt the WasmEdge_StatisticsContext to set the cost table. +/// \param CostArr the cost table array. +/// \param Len the length of the cost table array. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsSetCostTable(WasmEdge_StatisticsContext *Cxt, + uint64_t *CostArr, const uint32_t Len); + +/// Set the cost limit in execution. +/// +/// The WASM execution will be aborted if the instruction costs exceeded the +/// limit and the ErrCode::Value::CostLimitExceeded will be returned. +/// +/// \param Cxt the WasmEdge_StatisticsContext to set the cost table. +/// \param Limit the cost limit. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsSetCostLimit(WasmEdge_StatisticsContext *Cxt, + const uint64_t Limit); + +/// Clear all data in the WasmEdge_StatisticsContext. +/// +/// \param Cxt the WasmEdge_StatisticsContext to clear. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsClear(WasmEdge_StatisticsContext *Cxt); + +/// Deletion of the WasmEdge_StatisticsContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_StatisticsContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StatisticsDelete(WasmEdge_StatisticsContext *Cxt); + +// <<<<<<<< WasmEdge statistics functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge AST module functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the length of imports list of the AST module. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// +/// \returns length of the imports list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListImportsLength(const WasmEdge_ASTModuleContext *Cxt); + +/// List the imports of the AST module. +/// +/// If the `Imports` buffer length is smaller than the result of the imports +/// list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// \param [out] Imports the import type contexts buffer. Can be NULL if import +/// types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListImports(const WasmEdge_ASTModuleContext *Cxt, + const WasmEdge_ImportTypeContext **Imports, + const uint32_t Len); + +/// Get the length of exports list of the AST module. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// +/// \returns length of the exports list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListExportsLength(const WasmEdge_ASTModuleContext *Cxt); + +/// List the exports of the AST module. +/// +/// If the `Exports` buffer length is smaller than the result of the exports +/// list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASTModuleContext. +/// \param [out] Exports the export type contexts buffer. Can be NULL if export +/// types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ASTModuleListExports(const WasmEdge_ASTModuleContext *Cxt, + const WasmEdge_ExportTypeContext **Exports, + const uint32_t Len); + +/// Deletion of the WasmEdge_ASTModuleContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ASTModuleContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ASTModuleDelete(WasmEdge_ASTModuleContext *Cxt); + +// <<<<<<<< WasmEdge AST module functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge function type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_FunctionTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_FunctionTypeDelete` to +/// destroy it. +/// +/// \param ParamList the value types list of parameters. NULL if the length is +/// 0. +/// \param ParamLen the ParamList buffer length. +/// \param ReturnList the value types list of returns. NULL if the length is 0. +/// \param ReturnLen the ReturnList buffer length. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionTypeContext * +WasmEdge_FunctionTypeCreate(const WasmEdge_ValType *ParamList, + const uint32_t ParamLen, + const WasmEdge_ValType *ReturnList, + const uint32_t ReturnLen); + +/// Get the parameter types list length from the WasmEdge_FunctionTypeContext. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// +/// \returns the parameter types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_FunctionTypeGetParametersLength( + const WasmEdge_FunctionTypeContext *Cxt); + +/// Get the parameter types list from the WasmEdge_FunctionTypeContext. +/// +/// If the `List` buffer length is smaller than the length of the parameter type +/// list, the overflowed values will be discarded. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// \param [out] List the WasmEdge_ValType buffer to fill the parameter value +/// types. +/// \param Len the value type buffer length. +/// +/// \returns the actual parameter types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetParameters(const WasmEdge_FunctionTypeContext *Cxt, + WasmEdge_ValType *List, const uint32_t Len); + +/// Get the return types list length from the WasmEdge_FunctionTypeContext. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// +/// \returns the return types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetReturnsLength(const WasmEdge_FunctionTypeContext *Cxt); + +/// Get the return types list from the WasmEdge_FunctionTypeContext. +/// +/// If the `List` buffer length is smaller than the length of the return type +/// list, the overflowed values will be discarded. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext. +/// \param [out] List the WasmEdge_ValType buffer to fill the return value +/// types. +/// \param Len the value type buffer length. +/// +/// \returns the actual return types list length. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_FunctionTypeGetReturns(const WasmEdge_FunctionTypeContext *Cxt, + WasmEdge_ValType *List, const uint32_t Len); + +/// Deletion of the WasmEdge_FunctionTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_FunctionTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_FunctionTypeDelete(WasmEdge_FunctionTypeContext *Cxt); + +// <<<<<<<< WasmEdge function type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge table type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_TableTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_TableTypeDelete` to +/// destroy it. +/// +/// \param RefType the value type of the table type. This value type should be a +/// reference type, or this function will fail. +/// \param Limit the limit struct of the table type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableTypeContext * +WasmEdge_TableTypeCreate(const WasmEdge_ValType RefType, + const WasmEdge_Limit Limit); + +/// Get the reference type from a table type. +/// +/// \param Cxt the WasmEdge_TableTypeContext. +/// +/// \returns the value type of the table type. This value type will must be a +/// reference type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType +WasmEdge_TableTypeGetRefType(const WasmEdge_TableTypeContext *Cxt); + +/// Get the limit from a table type. +/// +/// \param Cxt the WasmEdge_TableTypeContext. +/// +/// \returns the limit struct of the table type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Limit +WasmEdge_TableTypeGetLimit(const WasmEdge_TableTypeContext *Cxt); + +/// Deletion of the WasmEdge_TableTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_TableTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_TableTypeDelete(WasmEdge_TableTypeContext *Cxt); + +// <<<<<<<< WasmEdge table type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge memory type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_MemoryTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_MemoryTypeDelete` to +/// destroy it. +/// +/// \param Limit the limit struct of the memory type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryTypeContext * +WasmEdge_MemoryTypeCreate(const WasmEdge_Limit Limit); + +/// Get the limit from a memory type. +/// +/// \param Cxt the WasmEdge_MemoryTypeContext. +/// +/// \returns the limit struct of the memory type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Limit +WasmEdge_MemoryTypeGetLimit(const WasmEdge_MemoryTypeContext *Cxt); + +/// Deletion of the WasmEdge_MemoryTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_MemoryTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_MemoryTypeDelete(WasmEdge_MemoryTypeContext *Cxt); + +// <<<<<<<< WasmEdge memory type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge tag type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the function type from a tag type. +/// +/// \param Cxt the WasmEdge_TagTypeContext. +/// +/// \returns pointer to function type context of the tag type, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_TagTypeGetFunctionType(const WasmEdge_TagTypeContext *Cxt); + +// <<<<<<<< WasmEdge tag type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge global type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_GlobalTypeContext. +/// +/// The caller owns the object and should call `WasmEdge_GlobalTypeDelete` to +/// destroy it. +/// +/// \param ValType the value type of the global type. +/// \param Mut the mutation of the global type. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalTypeContext * +WasmEdge_GlobalTypeCreate(const WasmEdge_ValType ValType, + const enum WasmEdge_Mutability Mut); + +/// Get the value type from a global type. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext. +/// +/// \returns the value type of the global type. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValType +WasmEdge_GlobalTypeGetValType(const WasmEdge_GlobalTypeContext *Cxt); + +/// Get the mutability from a global type. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext. +/// +/// \returns the mutability of the global type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_Mutability +WasmEdge_GlobalTypeGetMutability(const WasmEdge_GlobalTypeContext *Cxt); + +/// Deletion of the WasmEdge_GlobalTypeContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_GlobalTypeContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_GlobalTypeDelete(WasmEdge_GlobalTypeContext *Cxt); + +// <<<<<<<< WasmEdge global type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge import type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the external type from an import type. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns the external type of the import type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ExternalType +WasmEdge_ImportTypeGetExternalType(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the module name from an import type. +/// +/// The returned string object is linked to the module name of the import type, +/// and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ImportTypeGetModuleName(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external name from an import type. +/// +/// The returned string object is linked to the external name of the import +/// type, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ImportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ImportTypeGetExternalName(const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is function type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The function type context links to the function type in the import type +/// context and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the function type. NULL if failed or the external type of the +/// import type is not `WasmEdge_ExternalType_Function`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_ImportTypeGetFunctionType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is table type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The table type context links to the table type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the table type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Table`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_ImportTypeGetTableType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is memory type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The memory type context links to the memory type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the memory type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Memory`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_ImportTypeGetMemoryType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is tag type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The tag type context links to the tag type in the import type context +/// and the AST module context. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the tag type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_TagType`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_ImportTypeGetTagType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +/// Get the external value (which is global type) from an import type. +/// +/// The import type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The global type context links to the global type in the import type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ImportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the global type. NULL if failed or the external type of the import +/// type is not `WasmEdge_ExternalType_Global`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_ImportTypeGetGlobalType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ImportTypeContext *Cxt); + +// <<<<<<<< WasmEdge import type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge export type functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the external type from an export type. +/// +/// \param Cxt the WasmEdge_ExportTypeContext. +/// +/// \returns the external type of the export type. +WASMEDGE_CAPI_EXPORT extern enum WasmEdge_ExternalType +WasmEdge_ExportTypeGetExternalType(const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external name from an export type. +/// +/// The returned string object is linked to the external name of the export +/// type, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ExportTypeContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ExportTypeGetExternalName(const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is function type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The function type context links to the function type in the export type +/// context and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the function type. NULL if failed or the external type of the +/// export type is not `WasmEdge_ExternalType_Function`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_ExportTypeGetFunctionType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is table type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The table type context links to the table type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the table type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Table`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_ExportTypeGetTableType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is memory type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The memory type context links to the memory type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the memory type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Memory`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_ExportTypeGetMemoryType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is tag type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The tag type context links to the tag type in the export type context +/// and the AST module context. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the tag type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Tag`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_ExportTypeGetTagType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +/// Get the external value (which is global type) from an export type. +/// +/// The export type context should be the one queried from the AST module +/// context, or this function will cause unexpected error. +/// The global type context links to the global type in the export type context +/// and the AST module context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param ASTCxt the WasmEdge_ASTModuleContext. +/// \param Cxt the WasmEdge_ExportTypeContext which queried from the `ASTCxt`. +/// +/// \returns the global type. NULL if failed or the external type of the export +/// type is not `WasmEdge_ExternalType_Global`. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_ExportTypeGetGlobalType(const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_ExportTypeContext *Cxt); + +// <<<<<<<< WasmEdge export type functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge AOT compiler functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_CompilerContext. +/// +/// The caller owns the object and should call `WasmEdge_CompilerDelete` to +/// delete it. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_CompilerContext * +WasmEdge_CompilerCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Compile the input WASM from the file path. +/// +/// The compiler compiles the WASM from file path for the ahead-of-time mode and +/// store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param InPath the input WASM file path. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_CompilerCompile(WasmEdge_CompilerContext *Cxt, const char *InPath, + const char *OutPath); + +/// Compile the input WASM from the given buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_CompilerCompileFromBytes()` API in the future. +/// +/// The compiler compiles the WASM from the given buffer for the +/// ahead-of-time mode and store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param InBuffer the input WASM binary buffer. +/// \param InBufferLen the length of the input WASM binary buffer. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_CompilerCompileFromBuffer( + WasmEdge_CompilerContext *Cxt, const uint8_t *InBuffer, + const uint64_t InBufferLen, const char *OutPath); + +/// Compile the input WASM from a WasmEdge_Bytes. +/// +/// The compiler compiles the WASM from the WasmEdge_Bytes for the +/// ahead-of-time mode and store the result to the output file path. +/// +/// \param Cxt the WasmEdge_CompilerContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param OutPath the output WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_CompilerCompileFromBytes(WasmEdge_CompilerContext *Cxt, + const WasmEdge_Bytes Bytes, + const char *OutPath); + +/// Deletion of the WasmEdge_CompilerContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_CompilerContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_CompilerDelete(WasmEdge_CompilerContext *Cxt); + +// <<<<<<<< WasmEdge AOT compiler functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge loader functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_LoaderContext. +/// +/// The caller owns the object and should call `WasmEdge_LoaderDelete` to +/// destroy it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of Loader. +/// NULL for the default configuration. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_LoaderContext * +WasmEdge_LoaderCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Load and parse the WASM module from a WASM file into a +/// WasmEdge_ASTModuleContext. +/// +/// Load and parse the WASM module from the file path, and return a +/// `WasmEdge_ASTModuleContext` as the result. The caller owns the +/// `WasmEdge_ASTModuleContext` object and should call +/// `WasmEdge_ASTModuleDelete` to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromFile(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const char *Path); + +/// Load and parse the WASM module from a buffer into WasmEdge_ASTModuleContext. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_LoaderParseFromBytes()` API in the future. +/// +/// Load and parse the WASM module from a buffer, and return a +/// WasmEdge_ASTModuleContext as the result. The caller owns the +/// WasmEdge_ASTModuleContext object and should call `WasmEdge_ASTModuleDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromBuffer(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const uint8_t *Buf, const uint32_t BufLen); + +/// Load and parse the WASM module from a WasmEdge_Bytes into +/// WasmEdge_ASTModuleContext. +/// +/// Load and parse the WASM module from a buffer, and return a +/// WasmEdge_ASTModuleContext as the result. The caller owns the +/// WasmEdge_ASTModuleContext object and should call `WasmEdge_ASTModuleDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param [out] Module the output WasmEdge_ASTModuleContext if succeeded. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderParseFromBytes(WasmEdge_LoaderContext *Cxt, + WasmEdge_ASTModuleContext **Module, + const WasmEdge_Bytes Bytes); + +/// Serialize the WasmEdge_ASTModuleContext into WASM binary. +/// +/// Serialize the loaded WasmEdge_ASTModuleContext into the WASM binary format. +/// If the serialization succeeded, this API will allocate a new +/// `WasmEdge_Bytes` object and fill into the `Buf`. The caller owns the +/// `WasmEdge_Bytes` object and should call `WasmEdge_BytesDelete` to destroy +/// it. +/// +/// \param Cxt the WasmEdge_LoaderContext. +/// \param ASTCxt the WasmEdge_ASTModuleContext to serialize. +/// \param [out] Buf the WasmEdge_Bytes to fill the serialized WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_LoaderSerializeASTModule(WasmEdge_LoaderContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt, + WasmEdge_Bytes *Buf); + +/// Deletion of the WasmEdge_LoaderContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_LoaderContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_LoaderDelete(WasmEdge_LoaderContext *Cxt); + +// <<<<<<<< WasmEdge loader functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge validator functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ValidatorContext. +/// +/// The caller owns the object and should call `WasmEdge_ValidatorDelete` to +/// destroy it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of +/// Validator. NULL for the default configuration. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValidatorContext * +WasmEdge_ValidatorCreate(const WasmEdge_ConfigureContext *ConfCxt); + +/// Validate the WasmEdge AST Module. +/// +/// \param Cxt the WasmEdge_ValidatorContext. +/// \param ASTCxt the WasmEdge_ASTModuleContext to validate. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ValidatorValidate(WasmEdge_ValidatorContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Deletion of the WasmEdge_ValidatorContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ValidatorContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ValidatorDelete(WasmEdge_ValidatorContext *Cxt); + +// <<<<<<<< WasmEdge validator functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge executor functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ExecutorContext. +/// +/// The caller owns the object and should call `WasmEdge_ExecutorDelete` to +/// delete it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of +/// Executor. NULL for the default configuration. +/// \param StatCxt the WasmEdge_StatisticsContext as the statistics object set +/// into Executor. The statistics will refer to this context, and the life cycle +/// should be guaranteed until the executor context is deleted. NULL for not +/// doing the statistics. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_ExecutorCreate(const WasmEdge_ConfigureContext *ConfCxt, + WasmEdge_StatisticsContext *StatCxt); + +/// Instantiate an AST Module into a module instance. +/// +/// Instantiate an AST Module, and return an instantiated module instance +/// context as the result. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. Developers can use the +/// `WasmEdge_ModuleInstanceListFunction`, +/// `WasmEdge_ModuleInstanceFindFunction`, etc. APIs to retrieve the exported +/// instances from the result module instance. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param [out] ModuleCxt the output WasmEdge_ModuleInstanceContext if +/// succeeded. +/// \param StoreCxt the WasmEdge_StoreContext to link the imports. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorInstantiate( + WasmEdge_ExecutorContext *Cxt, WasmEdge_ModuleInstanceContext **ModuleCxt, + WasmEdge_StoreContext *StoreCxt, const WasmEdge_ASTModuleContext *ASTCxt); + +/// Instantiate an AST Module into a named module instance and link into store. +/// +/// Instantiate an AST Module with the module name, return the instantiated +/// module instance context as the result, and also register the module instance +/// to the store. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// Developers can use the `WasmEdge_ModuleInstanceListFunction`, +/// `WasmEdge_ModuleInstanceFindFunction`, etc. APIs to retrieve the exported +/// instances from the result module instance. +/// After calling this function, the output module instance will also be +/// registered into the store, and the other modules can import the exported +/// instances for linking when instantiation. Developers SHOULD guarantee the +/// life cycle of this output module instance, or the error will occur when in +/// execution after the module instance being destroyed if it has been imported +/// by other modules. That is, developers have the responsibility to delete the +/// output module instance even though the store being destroyed. When the +/// module instance is deleted, it will be unregistered to the store +/// automatically. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param [out] ModuleCxt the output WasmEdge_ModuleInstanceContext if +/// succeeded. +/// \param StoreCxt the WasmEdge_StoreContext to link the imports. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param ModuleName the module name WasmEdge_String for all exported +/// instances. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorRegister( + WasmEdge_ExecutorContext *Cxt, WasmEdge_ModuleInstanceContext **ModuleCxt, + WasmEdge_StoreContext *StoreCxt, const WasmEdge_ASTModuleContext *ASTCxt, + WasmEdge_String ModuleName); + +/// Register a module instance into a store with exporting its module name. +/// +/// Register an existing module into the store with its module name. +/// After calling this function, the existing module instance will be registered +/// into the store, and the other modules can import the exported instances for +/// linking when instantiation. Developers SHOULD guarantee the life cycle of +/// this existing module instance, or the error will occur when in execution +/// after the module instance being destroyed if it has been imported by other +/// modules. When the module instance is deleted, it will be unregistered to the +/// store automatically. +/// +/// \param Cxt the WasmEdge_ExecutorContext to instantiate the module. +/// \param StoreCxt the WasmEdge_StoreContext to store the instantiated module. +/// \param ImportCxt the WasmEdge_ModuleInstanceContext to register. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_ExecutorRegisterImport( + WasmEdge_ExecutorContext *Cxt, WasmEdge_StoreContext *StoreCxt, + const WasmEdge_ModuleInstanceContext *ImportCxt); + +/// Invoke a WASM function by the function instance. +/// +/// After instantiating a WASM module, developers can get the function instance +/// context from the module instance. Then developers can invoke the function +/// through this API. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param FuncCxt the function instance context to invoke. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_ExecutorInvoke(WasmEdge_ExecutorContext *Cxt, + const WasmEdge_FunctionInstanceContext *FuncCxt, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Asynchronous invoke a WASM function by the function instance. +/// +/// After instantiating a WASM module, developers can get the function instance +/// context from the module instance. Then developers can invoke the function +/// asynchronously through this API. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param FuncCxt the function instance context to invoke. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_ExecutorAsyncInvoke(WasmEdge_ExecutorContext *Cxt, + const WasmEdge_FunctionInstanceContext *FuncCxt, + const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Deletion of the WasmEdge_ExecutorContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ExecutorContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorDelete(WasmEdge_ExecutorContext *Cxt); + +// <<<<<<<< WasmEdge executor functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge store functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_StoreContext. +/// +/// The caller owns the object and should call `WasmEdge_StoreDelete` to destroy +/// it. +/// The store is the linker for multiple WASM module instances. The store will +/// not own any module instance registered into it, and the module instances +/// will automatically be unregistered if they are destroyed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StoreContext *WasmEdge_StoreCreate(void); + +/// Get the module instance context by the module name. +/// +/// After registering a WASM module, developers can call this function to find +/// and get the registered module instance context by the module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// \param Name the module name WasmEdge_String. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_StoreFindModule(const WasmEdge_StoreContext *Cxt, + const WasmEdge_String Name); + +/// Get the length of registered module list in store. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// +/// \returns length of registered named module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StoreListModuleLength(const WasmEdge_StoreContext *Cxt); + +/// List the registered module names. +/// +/// This function will list all registered module names. +/// The returned module names filled into the `Names` array are linked to the +/// registered module names in the store context, and the caller should __NOT__ +/// call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the registered +/// named module list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_StoreContext. +/// \param [out] Names the output names WasmEdge_String buffer of named modules. +/// \param Len the buffer length. +/// +/// \returns actual registered named module list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_StoreListModule(const WasmEdge_StoreContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Deletion of the WasmEdge_StoreContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// If there are module instances registered into this store context, they will +/// be automatically un-link to this store context. +/// +/// \param Cxt the WasmEdge_StoreContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_StoreDelete(WasmEdge_StoreContext *Cxt); + +// <<<<<<<< WasmEdge store functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge module instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_ModuleInstanceContext. +/// +/// Create a module instance context with exported module name for host +/// instances. Developer can use this API to create a module instance for +/// collecting host functions, tables, memories, tags, and globals. +/// The caller owns the object and should call `WasmEdge_ModuleInstanceDelete` +/// to destroy it. +/// +/// \param ModuleName the module name WasmEdge_String of this host module to +/// import. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreate(const WasmEdge_String ModuleName); + +/// Creation of the WasmEdge_ModuleInstanceContext with host data. +/// +/// Create a module instance context with exported module name, host data, and +/// host data finalizer for host instances. Developer can use this API to create +/// a module instance for collecting host functions, tables, memories, and +/// globals. When this created module instance being destroyed, the host data +/// finalizer will be invoked. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// +/// \param ModuleName the module name WasmEdge_String of this host module to +/// import. +/// \param HostData the host data to set into the module instance. When calling +/// the finalizer, this pointer will become the argument of the finalizer +/// function. +/// \param Finalizer the function to finalize the host data. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreateWithData(const WasmEdge_String ModuleName, + void *HostData, + void (*Finalizer)(void *)); + +/// Creation of the WasmEdge_ModuleInstanceContext for the WASI specification. +/// +/// This function will create a WASI host module that contains the WASI host +/// functions and initialize it. The caller owns the object and should call +/// `WasmEdge_ModuleInstanceDelete` to destroy it. +/// +/// \param Args the command line arguments. The first argument suggests being +/// the program name. NULL if the length is 0. +/// \param ArgLen the length of the command line arguments. +/// \param Envs the environment variables in the format `ENV=VALUE`. NULL if the +/// length is 0. +/// \param EnvLen the length of the environment variables. +/// \param Preopens the directory paths to preopen. String format in +/// `GUEST_PATH:HOST_PATH` means the path mapping, or the same path will be +/// mapped. NULL if the length is 0. +/// \param PreopenLen the length of the directory paths to preopen. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_ModuleInstanceCreateWASI(const char *const *Args, + const uint32_t ArgLen, + const char *const *Envs, + const uint32_t EnvLen, + const char *const *Preopens, + const uint32_t PreopenLen); + +/// Initialize the WasmEdge_ModuleInstanceContext for the WASI specification. +/// +/// This function will initialize the WASI host module with the parameters. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// \param Args the command line arguments. The first argument suggests being +/// the program name. NULL if the length is 0. +/// \param ArgLen the length of the command line arguments. +/// \param Envs the environment variables in the format `ENV=VALUE`. NULL if the +/// length is 0. +/// \param EnvLen the length of the environment variables. +/// \param Preopens the directory paths to preopen. String format in +/// `GUEST_PATH:HOST_PATH` means the path mapping, or the same path will be +/// mapped. NULL if the length is 0. +/// \param PreopenLen the length of the directory paths to preopen. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_ModuleInstanceInitWASI( + WasmEdge_ModuleInstanceContext *Cxt, const char *const *Args, + const uint32_t ArgLen, const char *const *Envs, const uint32_t EnvLen, + const char *const *Preopens, const uint32_t PreopenLen); + +/// Get the WASI exit code. +/// +/// This function will return the exit code after running the "_start" function +/// of a `wasm32-wasi` program. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// +/// \returns the exit code after executing the "_start" function. Return +/// `EXIT_FAILURE` if the `Cxt` is NULL or not a WASI host module. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceWASIGetExitCode( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the native handler from the WASI mapped FD/Handler. +/// +/// This function will return the raw FD/Handler from a given mapped Fd +/// or Handler. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext of WASI import object. +/// \param Fd the WASI mapped Fd. +/// \param [out] NativeHandler the raw Fd/Handler. +/// +/// \returns the error code. Return `0` if the Native Handler is found. +/// Return `1` if the `Cxt` is `NULL`. +/// Return `2` if the given mapped Fd/handler is not found. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceWASIGetNativeHandler( + const WasmEdge_ModuleInstanceContext *Cxt, int32_t Fd, + uint64_t *NativeHandler); + +/// Initialize the WasmEdge_ModuleInstanceContext for the wasmedge_process +/// specification. +/// +/// This function will initialize the wasmedge_process host module with the +/// parameters. +/// +/// \param AllowedCmds the allowed commands white list. NULL if the +/// length is 0. +/// \param CmdsLen the length of the allowed commands white list. +/// \param AllowAll the boolean value to allow all commands. `false` is +/// suggested. If this value is `true`, the allowed commands white list will not +/// be recorded and all commands can be executed by wasmedge_process. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceInitWasmEdgeProcess(const char *const *AllowedCmds, + const uint32_t CmdsLen, + const bool AllowAll); + +/// Get the export module name of a module instance. +/// +/// The returned string object is linked to the module name of the module +/// instance, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_ModuleInstanceGetModuleName(const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the host data set into the module instance when creating. +/// +/// The returned data is owned by the module instance, and will be passed into +/// the finalizer when deleting this module instance. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns host data. NULL if the module instance context is NULL or no host +/// data set into the module instance. +WASMEDGE_CAPI_EXPORT extern void * +WasmEdge_ModuleInstanceGetHostData(const WasmEdge_ModuleInstanceContext *Cxt); + +/// Get the exported function instance context of a module instance. +/// +/// The result function instance context links to the function instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_FunctionInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the function name WasmEdge_String. +/// +/// \returns pointer to the function instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_ModuleInstanceFindFunction(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported table instance context of a module instance. +/// +/// The result table instance context links to the table instance in the module +/// instance context and owned by the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_TableInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the table name WasmEdge_String. +/// +/// \returns pointer to the table instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_ModuleInstanceFindTable(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported memory instance context of a module instance. +/// +/// The result memory instance context links to the memory instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_MemoryInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the memory name WasmEdge_String. +/// +/// \returns pointer to the memory instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_ModuleInstanceFindMemory(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported tag instance context of a module instance. +/// +/// The result tag instance context links to the tag instance in the +/// module instance context and owned by the module instance context. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the tag name WasmEdge_String. +/// +/// \returns pointer to the tag instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TagInstanceContext * +WasmEdge_ModuleInstanceFindTag(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the exported global instance context of a module instance. +/// +/// The result global instance context links to the global instance in the +/// module instance context and owned by the module instance context, and the +/// caller should __NOT__ call the `WasmEdge_GlobalInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param Name the global name WasmEdge_String. +/// +/// \returns pointer to the global instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalInstanceContext * +WasmEdge_ModuleInstanceFindGlobal(const WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name); + +/// Get the length of exported function list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported function list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListFunctionLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported function names of a module instance. +/// +/// The returned function names filled into the `Names` array are linked to the +/// exported names of functions of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// function list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListFunction(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported table list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported table list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListTableLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported table names of a module instance. +/// +/// The returned table names filled into the `Names` array are linked to the +/// exported names of tables of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// table list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the table names. +/// \param Len the buffer length. +/// +/// \returns actual exported table list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTable(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported memory list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported memory list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListMemoryLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported memory names of a module instance. +/// +/// The returned memory names filled into the `Names` array are linked to the +/// exported names of memories of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// memory list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the memory names. +/// \param Len the buffer length. +/// +/// \returns actual exported memory list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListMemory(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported tag list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported tag list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTagLength(const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported tag names of a module instance. +/// +/// The returned tag names filled into the `Names` array are linked to the +/// exported names of tags of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// tag list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the tag names. +/// \param Len the buffer length. +/// +/// \returns actual exported tag list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListTag(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the length of exported global list of a module instance. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// +/// \returns length of the exported global list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_ModuleInstanceListGlobalLength( + const WasmEdge_ModuleInstanceContext *Cxt); + +/// List the exported global names of a module instance. +/// +/// The returned global names filled into the `Names` array are linked to the +/// exported names of globals of the module instance context, and the caller +/// should __NOT__ call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the exported +/// global list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext. +/// \param [out] Names the output WasmEdge_String buffer of the global names. +/// \param Len the buffer length. +/// +/// \returns actual exported global list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_ModuleInstanceListGlobal(const WasmEdge_ModuleInstanceContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Add a function instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the function instance into the module +/// instance. The caller should __NOT__ access or destroy the function instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the function instance. +/// \param Name the export function name WasmEdge_String. +/// \param FuncCxt the WasmEdge_FunctionInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddFunction(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_FunctionInstanceContext *FuncCxt); + +/// Add a table instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the table instance into the module +/// instance. The caller should __NOT__ access or destroy the table instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the table instance. +/// \param Name the export table name WasmEdge_String. +/// \param TableCxt the WasmEdge_TableInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddTable(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_TableInstanceContext *TableCxt); + +/// Add a memory instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the memory instance into the module +/// instance. The caller should __NOT__ access or destroy the memory instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the memory instance. +/// \param Name the export memory name WasmEdge_String. +/// \param MemoryCxt the WasmEdge_MemoryInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddMemory(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_MemoryInstanceContext *MemoryCxt); + +/// Add a global instance context into a WasmEdge_ModuleInstanceContext. +/// +/// Export and move the ownership of the global instance into the module +/// instance. The caller should __NOT__ access or destroy the global instance +/// context after calling this function. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to add the global instance. +/// \param Name the export global name WasmEdge_String. +/// \param GlobalCxt the WasmEdge_GlobalInstanceContext to add. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceAddGlobal(WasmEdge_ModuleInstanceContext *Cxt, + const WasmEdge_String Name, + WasmEdge_GlobalInstanceContext *GlobalCxt); + +/// Deletion of the WasmEdge_ModuleInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// If the module instance has been registered into one or more store contexts, +/// it will be automatically unregistered. +/// +/// \param Cxt the WasmEdge_ModuleInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ModuleInstanceDelete(WasmEdge_ModuleInstanceContext *Cxt); + +// <<<<<<<< WasmEdge module instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge function instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +typedef WasmEdge_Result (*WasmEdge_HostFunc_t)( + void *Data, const WasmEdge_CallingFrameContext *CallFrameCxt, + const WasmEdge_Value *Params, WasmEdge_Value *Returns); +/// Creation of the WasmEdge_FunctionInstanceContext for host functions. +/// +/// The caller owns the object and should call `WasmEdge_FunctionInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. The following is an example to create a +/// host function context. +/// ```c +/// WasmEdge_Result FuncAdd(void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *In, WasmEdge_Value *Out) { +/// // Function to return A + B. +/// int32_t A = WasmEdge_ValueGetI32(In[0]); +/// int32_t B = WasmEdge_ValueGetI32(In[1]); +/// Out[0] = WasmEdge_ValueGenI32(A + B); +/// // Return execution status +/// return WasmEdge_Result_Success; +/// } +/// +/// WasmEdge_ValType Params[2] = {WasmEdge_ValTypeGenI32(), +/// WasmEdge_ValTypeGenI32()}; +/// WasmEdge_ValType Returns[1] = {WasmEdge_ValTypeGenI32()}; +/// WasmEdge_FunctionTypeContext *FuncType = +/// WasmEdge_FunctionTypeCreate(Params, 2, Returns, 1); +/// WasmEdge_FunctionInstanceContext *HostFunc = +/// WasmEdge_FunctionInstanceCreate(FuncType, FuncAdd, NULL, 0); +/// WasmEdge_FunctionTypeDelete(FuncType); +/// ... +/// ``` +/// +/// \param Type the function type context to describe the host function +/// signature. +/// \param HostFunc the host function pointer. The host function signature must +/// be as following: +/// ```c +/// typedef WasmEdge_Result (*WasmEdge_HostFunc_t)( +/// void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *Params, +/// WasmEdge_Value *Returns); +/// ``` +/// The `Params` is the input parameters array with length guaranteed to be the +/// same as the parameter types in the `Type`. The `Returns` is the output +/// results array with length guaranteed to be the same as the result types in +/// the `Type`. The return value is `WasmEdge_Result` for the execution status. +/// \param Data the additional object, such as the pointer to a data structure, +/// to set to this host function context. The caller should guarantee the life +/// cycle of the object. NULL if the additional data object is not needed. +/// \param Cost the function cost in statistics. Pass 0 if the calculation is +/// not needed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_FunctionInstanceCreate(const WasmEdge_FunctionTypeContext *Type, + WasmEdge_HostFunc_t HostFunc, void *Data, + const uint64_t Cost); + +typedef WasmEdge_Result (*WasmEdge_WrapFunc_t)( + void *This, void *Data, const WasmEdge_CallingFrameContext *CallFrameCxt, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); +/// Creation of the WasmEdge_FunctionInstanceContext for host functions. +/// +/// This function is for the languages which cannot pass the function pointer of +/// the host function into this shared library directly. The caller owns the +/// object and should call `WasmEdge_FunctionInstanceDelete` to destroy it if +/// the returned object is not added into a `WasmEdge_ModuleInstanceContext`. +/// The following is an example to create a host function context for other +/// languages. +/// ```c +/// // `RealFunc` is the pointer to the function in other languages. +/// +/// WasmEdge_Result FuncAddWrap( +/// void *This, void *Data, +/// const WasmEdge_CallingFrameContext *CallFrameCxt, +/// const WasmEdge_Value *In, const uint32_t InLen, WasmEdge_Value *Out, +/// const uint32_t OutLen) { +/// // Wrapper function of host function to return A + B. +/// +/// // `This` is the same as `RealFunc`. +/// int32_t A = WasmEdge_ValueGetI32(In[0]); +/// int32_t B = WasmEdge_ValueGetI32(In[1]); +/// +/// // Call the function of `This` in the host language ... +/// int32_t Result = ...; +/// +/// Out[0] = Result; +/// // Return the execution status. +/// return WasmEdge_Result_Success; +/// } +/// +/// WasmEdge_ValType Params[2] = {WasmEdge_ValTypeGenI32(), +/// WasmEdge_ValTypeGenI32()}; +/// WasmEdge_ValType Returns[1] = {WasmEdge_ValTypeGenI32()}; +/// WasmEdge_FunctionTypeContext *FuncType = +/// WasmEdge_FunctionTypeCreate(Params, 2, Returns, 1); +/// WasmEdge_FunctionInstanceContext *HostFunc = +/// WasmEdge_FunctionInstanceCreateBinding( +/// FuncType, FuncAddWrap, RealFunc, NULL, 0); +/// WasmEdge_FunctionTypeDelete(FuncType); +/// ... +/// ``` +/// +/// \param Type the function type context to describe the host function +/// signature. +/// \param WrapFunc the wrapper function pointer. The wrapper function signature +/// must be as following: +/// ```c +/// typedef WasmEdge_Result (*WasmEdge_WrapFunc_t)( +/// void *This, +/// void *Data, +/// WasmEdge_CallingFrameContext *FrameCxt, +/// const WasmEdge_Value *Params, +/// const uint32_t ParamLen, +/// WasmEdge_Value *Returns, +/// const uint32_t ReturnLen); +/// ``` +/// The `This` is the pointer the same as the `Binding` parameter of this +/// function. The `Params` is the input parameters array with length guaranteed +/// to be the same as the parameter types in the `Type`, and the `ParamLen` is +/// the length of the array. The `Returns` is the output results array with +/// length guaranteed to be the same as the result types in the `Type`, and the +/// `ReturnLen` is the length of the array. The return value is +/// `WasmEdge_Result` for the execution status. +/// \param Binding the `this` pointer of the host function target or the +/// function indexing maintained by the caller which can specify the host +/// function. When invoking the host function, this pointer will be the first +/// argument of the wrapper function. +/// \param Data the additional object, such as the pointer to a data structure, +/// to set to this host function context. The caller should guarantee the life +/// cycle of the object. NULL if the additional data object is not needed. +/// \param Cost the function cost in statistics. Pass 0 if the calculation is +/// not needed. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_FunctionInstanceContext * +WasmEdge_FunctionInstanceCreateBinding(const WasmEdge_FunctionTypeContext *Type, + WasmEdge_WrapFunc_t WrapFunc, + void *Binding, void *Data, + const uint64_t Cost); + +/// Get the function data field of the function instance. +/// +/// The function data is passed when creating the FunctionInstance. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext. +/// +/// \returns pointer to Data, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const void * +WasmEdge_FunctionInstanceGetData(const WasmEdge_FunctionInstanceContext *Cxt); + +/// Get the function type context of the function instance. +/// +/// The function type context links to the function type in the function +/// instance context and owned by the context. The caller should __NOT__ call +/// the `WasmEdge_FunctionTypeDelete`. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_FunctionInstanceGetFunctionType( + const WasmEdge_FunctionInstanceContext *Cxt); + +/// Deletion of the WasmEdge_FunctionInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_FunctionInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_FunctionInstanceDelete(WasmEdge_FunctionInstanceContext *Cxt); + +// <<<<<<<< WasmEdge function instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge table instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_TableInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_TableInstanceDelete` to +/// destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// The default value of the elements in the output table instance will be null +/// references with the same reference type in the table type when table grows. +/// If the reference type of the input table type is a non-nullable value type, +/// a non-null default init value is required. In this case, please use the +/// `WasmEdge_TableInstanceCreateWithInit` API instead. +/// +/// \param TabType the table type context to initialize the table instance +/// context. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_TableInstanceCreate(const WasmEdge_TableTypeContext *TabType); + +/// Creation of the WasmEdge_TableInstanceContext with the default init value. +/// +/// The caller owns the object and should call `WasmEdge_TableInstanceDelete` to +/// destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// The value type of the default init value should compatible with the +/// reference type of the input table type, otherwise this function will fail. +/// If the reference type of the input table type is a non-nullable value type, +/// this function will fail if the default init value is a null reference. +/// +/// \param TabType the table type context to initialize the table instance +/// context. +/// \param Value the default init value for the table element when table +/// grows. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * +WasmEdge_TableInstanceCreateWithInit(const WasmEdge_TableTypeContext *TabType, + const WasmEdge_Value Value); + +/// Get the table type context from a table instance. +/// +/// The table type context links to the table type in the table instance context +/// and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_TableTypeDelete`. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TableTypeContext * +WasmEdge_TableInstanceGetTableType(const WasmEdge_TableInstanceContext *Cxt); + +/// Get the reference value in a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param [out] Data the result reference value. +/// \param Offset the reference value offset (index) in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceGetData(const WasmEdge_TableInstanceContext *Cxt, + WasmEdge_Value *Data, const uint32_t Offset); + +/// Set the reference value into a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param Data the reference value to set into the table instance. +/// \param Offset the reference value offset (index) in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceSetData(WasmEdge_TableInstanceContext *Cxt, + WasmEdge_Value Data, const uint32_t Offset); + +/// Get the size of a table instance. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// +/// \returns the size of the table instance. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_TableInstanceGetSize(const WasmEdge_TableInstanceContext *Cxt); + +/// Grow a table instance with a size. +/// +/// \param Cxt the WasmEdge_TableInstanceContext. +/// \param Size the count of reference values to grow in the table instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_TableInstanceGrow(WasmEdge_TableInstanceContext *Cxt, + const uint32_t Size); + +/// Deletion of the WasmEdge_TableInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_TableInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_TableInstanceDelete(WasmEdge_TableInstanceContext *Cxt); + +// <<<<<<<< WasmEdge table instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge memory instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_MemoryInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_MemoryInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// +/// \param MemType the memory type context to initialize the memory instance +/// context. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_MemoryInstanceCreate(const WasmEdge_MemoryTypeContext *MemType); + +/// Get the memory type context from a memory instance. +/// +/// The memory type context links to the memory type in the memory instance +/// context and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_MemoryTypeDelete`. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_MemoryTypeContext * +WasmEdge_MemoryInstanceGetMemoryType(const WasmEdge_MemoryInstanceContext *Cxt); + +/// Copy the data to the output buffer from a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param [out] Data the result data buffer of copying destination. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will failed. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceGetData(const WasmEdge_MemoryInstanceContext *Cxt, + uint8_t *Data, const uint32_t Offset, + const uint32_t Length); + +/// Copy the data into a memory instance from the input buffer. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Data the data buffer to copy. +/// \param Offset the data start offset in the memory instance. +/// \param Length the data buffer length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will failed. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceSetData(WasmEdge_MemoryInstanceContext *Cxt, + const uint8_t *Data, const uint32_t Offset, + const uint32_t Length); + +/// Get the data pointer in a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will return NULL. +/// +/// \returns the pointer to data with the start offset. NULL if failed. +WASMEDGE_CAPI_EXPORT extern uint8_t * +WasmEdge_MemoryInstanceGetPointer(WasmEdge_MemoryInstanceContext *Cxt, + const uint32_t Offset, const uint32_t Length); + +/// Get the const data pointer in a const memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Offset the data start offset in the memory instance. +/// \param Length the requested data length. If the `Offset + Length` is larger +/// than the data size in the memory instance, this function will return NULL. +/// +/// \returns the pointer to data with the start offset. NULL if failed. +WASMEDGE_CAPI_EXPORT extern const uint8_t * +WasmEdge_MemoryInstanceGetPointerConst( + const WasmEdge_MemoryInstanceContext *Cxt, const uint32_t Offset, + const uint32_t Length); + +/// Get the current page size (64 KiB of each page) of a memory instance. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// +/// \returns the page size of the memory instance. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_MemoryInstanceGetPageSize(const WasmEdge_MemoryInstanceContext *Cxt); + +/// Grow a memory instance with a page size. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext. +/// \param Page the page count to grow in the memory instance. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_MemoryInstanceGrowPage(WasmEdge_MemoryInstanceContext *Cxt, + const uint32_t Page); + +/// Deletion of the WasmEdge_MemoryInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_MemoryInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_MemoryInstanceDelete(WasmEdge_MemoryInstanceContext *Cxt); + +// <<<<<<<< WasmEdge memory instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge tag instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the tag type context from a tag instance. +/// +/// The tag type context links to the tag type in the tag instance +/// context and owned by the context. +/// +/// \param Cxt the WasmEdge_TagInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_TagTypeContext * +WasmEdge_TagInstanceGetTagType(const WasmEdge_TagInstanceContext *Cxt); + +// <<<<<<<< WasmEdge tag instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge global instance functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_GlobalInstanceContext. +/// +/// The caller owns the object and should call `WasmEdge_GlobalInstanceDelete` +/// to destroy it if the returned object is not added into a +/// `WasmEdge_ModuleInstanceContext`. +/// +/// \param GlobType the global type context to initialize the global instance +/// context. +/// \param Value the initial value with its value type of the global instance. +/// This function will fail if the value type of `GlobType` and `Value` are not +/// the same. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_GlobalInstanceContext * +WasmEdge_GlobalInstanceCreate(const WasmEdge_GlobalTypeContext *GlobType, + const WasmEdge_Value Value); + +/// Get the global type context from a global instance. +/// +/// The global type context links to the global type in the global instance +/// context and owned by the context. The caller should __NOT__ call the +/// `WasmEdge_GlobalTypeDelete`. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_GlobalTypeContext * +WasmEdge_GlobalInstanceGetGlobalType(const WasmEdge_GlobalInstanceContext *Cxt); + +/// Get the value from a global instance. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// +/// \returns the current value of the global instance. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Value +WasmEdge_GlobalInstanceGetValue(const WasmEdge_GlobalInstanceContext *Cxt); + +/// Set the value into a global instance. +/// +/// This function will return error if the global context is set as the `Const` +/// mutation or the value type not matched. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext. +/// \param Value the value to set into the global context. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_GlobalInstanceSetValue(WasmEdge_GlobalInstanceContext *Cxt, + const WasmEdge_Value Value); + +/// Deletion of the WasmEdge_GlobalInstanceContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_GlobalInstanceContext to destroy. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_GlobalInstanceDelete(WasmEdge_GlobalInstanceContext *Cxt); + +// <<<<<<<< WasmEdge global instance functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge calling frame functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Get the executor context from the current calling frame. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// +/// \returns the executor context, NULL if the Cxt is NULL. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_CallingFrameGetExecutor(const WasmEdge_CallingFrameContext *Cxt); + +/// Get the module instance of the current calling frame. +/// +/// When a WASM function is executing and start to call a host function, a frame +/// with the module instance which the WASM function belongs to will be pushed +/// onto the stack. And therefore the calling frame context will record that +/// module instance. +/// So in one case that the module instance will be `NULL`: developers execute +/// the function instance which is a host function and not added into a module +/// instance. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// +/// \returns the module instance of the current calling frame. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_CallingFrameGetModuleInstance(const WasmEdge_CallingFrameContext *Cxt); + +/// Get the memory instance by index from the module instance of the current +/// calling frame. +/// +/// By default, a WASM module only have one memory instance after instantiation. +/// Therefore, developers can use: +/// `WasmEdge_CallingFrameGetMemoryInstance(Cxt, 0)` +/// to get the memory instance in host function body. +/// This extension is for the WASM multiple memories proposal. After enabling +/// the proposal, there may be greater than 1 memory instances in a WASM module. +/// So developers can use this function to access the memory instances which are +/// not in 0 index. +/// +/// \param Cxt the WasmEdge_CallingFrameContext. +/// \param Idx the index of memory instance in the module instance. +/// +/// \returns the memory instance, NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_MemoryInstanceContext * +WasmEdge_CallingFrameGetMemoryInstance(const WasmEdge_CallingFrameContext *Cxt, + const uint32_t Idx); + +// <<<<<<<< WasmEdge calling frame functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Async functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Wait a WasmEdge_Async execution. +/// +/// \param Cxt the WasmEdge_ASync. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncWait(const WasmEdge_Async *Cxt); + +/// Wait a WasmEdge_Async execution with timeout. +/// +/// \param Cxt the WasmEdge_ASync. +/// \param Milliseconds times to wait. +/// +/// \returns Result of waiting, true for execution ended, false for timeout +/// occurred. +WASMEDGE_CAPI_EXPORT bool WasmEdge_AsyncWaitFor(const WasmEdge_Async *Cxt, + uint64_t Milliseconds); + +/// Cancel a WasmEdge_Async execution. +/// +/// \param Cxt the WasmEdge_ASync. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncCancel(WasmEdge_Async *Cxt); + +/// Wait and get the return list length of the WasmEdge_Async execution. +/// +/// This function will wait until the execution finished and return the return +/// value list length of the executed function. This function will return 0 if +/// the `Cxt` is NULL, the execution was failed, or the execution was canceled. +/// Developers can call the `WasmEdge_AsyncGet` to get the execution status and +/// the return values. +/// +/// \param Cxt the WasmEdge_ASync. +/// +/// \returns the return list length of the executed function. +WASMEDGE_CAPI_EXPORT uint32_t +WasmEdge_AsyncGetReturnsLength(const WasmEdge_Async *Cxt); + +/// Wait and get the result of WasmEdge_Async execution. +/// +/// This function will wait until the execution finished and return the +/// execution status and the return values. +/// If the `Returns` buffer length is smaller than the arity of the function, +/// the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_ASync. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT WasmEdge_Result +WasmEdge_AsyncGet(const WasmEdge_Async *Cxt, WasmEdge_Value *Returns, + const uint32_t ReturnLen); + +/// Deletion of the WasmEdge_Async. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_ASync to destroy. +WASMEDGE_CAPI_EXPORT void WasmEdge_AsyncDelete(WasmEdge_Async *Cxt); + +// <<<<<<<< WasmEdge Async functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge VM functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Creation of the WasmEdge_VMContext. +/// +/// The caller owns the object and should call `WasmEdge_VMDelete` to destroy +/// it. +/// +/// \param ConfCxt the WasmEdge_ConfigureContext as the configuration of VM. +/// NULL for the default configuration. +/// \param StoreCxt the WasmEdge_StoreContext as the external WASM store of VM. +/// The instantiation and execution will refer to this store context, and the +/// life cycle should be ensured until the VM context is deleted. NULL for the +/// default store owned by `WasmEdge_VMContext`. +/// +/// \returns pointer to context, NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_VMContext * +WasmEdge_VMCreate(const WasmEdge_ConfigureContext *ConfCxt, + WasmEdge_StoreContext *StoreCxt); + +/// Register and instantiate WASM into the store in VM from a WASM file. +/// +/// Load a WASM file from the path, and register all exported instances and +/// instantiate them into the store into the VM with their exported name and +/// module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromFile(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const char *Path); + +/// Register and instantiate WASM into the store in VM from a buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMRegisterModuleFromBytes()` API in the future. +/// +/// Load a WASM module from a buffer, and register all exported instances and +/// instantiate them into the store into the VM with their exported name and +/// module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromBuffer(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const uint8_t *Buf, const uint32_t BufLen); + +/// Register and instantiate WASM into the store in VM from a WasmEdge_Bytes. +/// +/// Load a WASM module from a WasmEdge_Bytes, and register all exported +/// instances and instantiate them into the store into the VM with their +/// exported name and module name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromBytes(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_Bytes Bytes); + +/// Instantiate and register an AST Module into a named module instance in VM. +/// +/// Load from the AST Module, and register all exported instances and +/// instantiate them into the store in VM with their exported name and module +/// name. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ModuleName the WasmEdge_String of module name for all exported +/// instances. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMRegisterModuleFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Register a module instance into the store in VM with exporting its module +/// name. +/// +/// After calling this function, the existing module instance will be registered +/// into the store context in this VM, and the other modules can import the +/// exported instances for linking when instantiation. Developers SHOULD +/// guarantee the life cycle of this existing module instance, or the error will +/// occur when in execution after the module instance being destroyed if it has +/// been imported by other modules. That is, developers should call the +/// `WasmEdge_ModuleInstanceDelete` if this existing module instance will not be +/// used anymore or after the deletion of this VM. When the module instance is +/// deleted, it will be unregistered to the store context in this VM +/// automatically. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext which contains the store. +/// \param ImportCxt the WasmEdge_ModuleInstanceContext to register. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRegisterModuleFromImport( + WasmEdge_VMContext *Cxt, const WasmEdge_ModuleInstanceContext *ImportCxt); + +/// Instantiate the WASM module from a WASM file and invoke a function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the file path, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromFile( + WasmEdge_VMContext *Cxt, const char *Path, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a buffer and invoke a function by name. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMRunWasmFromBytes()` API in the future. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a buffer, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromBuffer( + WasmEdge_VMContext *Cxt, const uint8_t *Buf, const uint32_t BufLen, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WasmEdge_Bytes and invoke a function by +/// name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a WasmEdge_Bytes, and then invoke +/// a function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromBytes( + WasmEdge_VMContext *Cxt, const WasmEdge_Bytes Bytes, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WasmEdge AST Module and invoke a function +/// by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the WasmEdge AST Module, and then +/// invoke the function by name and parameters. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMRunWasmFromASTModule( + WasmEdge_VMContext *Cxt, const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Instantiate the WASM module from a WASM file and asynchronous invoke a +/// function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the file path, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromFile( + WasmEdge_VMContext *Cxt, const char *Path, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen); + +/// Instantiate the WASM module from a buffer and asynchronous invoke a function +/// by name. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMAsyncRunWasmFromBytes()` API in the future. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a buffer, and then invoke a +/// function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromBuffer( + WasmEdge_VMContext *Cxt, const uint8_t *Buf, const uint32_t BufLen, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Instantiate the WASM module from a WasmEdge_Bytes and asynchronous invoke a +/// function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from a WasmEdge_Bytes, and then invoke +/// a function by name and parameters. If the `Returns` buffer length is smaller +/// than the arity of the function, the overflowed return values will be +/// discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncRunWasmFromBytes( + WasmEdge_VMContext *Cxt, const WasmEdge_Bytes Bytes, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Instantiate the WASM module from a WasmEdge AST Module and asynchronous +/// invoke a function by name. +/// +/// This is the function to invoke a WASM function rapidly. +/// Load and instantiate the WASM module from the WasmEdge AST Module, and then +/// invoke the function by name and parameters. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// The caller owns the object and should call `WasmEdge_AsyncDelete` to destroy +/// it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_VMAsyncRunWasmFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt, + const WasmEdge_String FuncName, + const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Load the WASM module from a WASM file. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from the file path. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Path the NULL-terminated C string of the WASM file path. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromFile(WasmEdge_VMContext *Cxt, const char *Path); + +/// Load the WASM module from a buffer. +/// +/// CAUTION: This function will be deprecated and replaced by +/// `WasmEdge_VMLoadWasmFromBytes()` API in the future. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from a buffer. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Buf the buffer of WASM binary. +/// \param BufLen the length of the buffer. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromBuffer(WasmEdge_VMContext *Cxt, const uint8_t *Buf, + const uint32_t BufLen); + +/// Load the WASM module from a WasmEdge_Bytes. +/// +/// This is the first step to invoke a WASM function step by step. +/// Load and parse the WASM module from a WasmEdge_Bytes. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Bytes the WasmEdge_Bytes of WASM binary. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromBytes(WasmEdge_VMContext *Cxt, + const WasmEdge_Bytes Bytes); + +/// Load the WASM module from loaded WasmEdge AST Module. +/// +/// This is the first step to invoke a WASM function step by step. +/// Copy the loaded WasmEdge AST Module context into VM. The VM context has no +/// dependency on the input AST Module context. You can then call +/// `WasmEdge_VMValidate` for the next step. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ASTCxt the WasmEdge AST Module context generated by loader or +/// compiler. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMLoadWasmFromASTModule(WasmEdge_VMContext *Cxt, + const WasmEdge_ASTModuleContext *ASTCxt); + +/// Validate the WASM module loaded into the VM context. +/// +/// This is the second step to invoke a WASM function step by step. +/// After loading a WASM module into VM context, You can call this function to +/// validate it. And you can then call `WasmEdge_VMInstantiate` for the next +/// step. Note that only validated WASM modules can be instantiated in the VM +/// context. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMValidate(WasmEdge_VMContext *Cxt); + +/// Instantiate the validated WASM module in the VM context. +/// +/// This is the third step to invoke a WASM function step by step. +/// After validating a WASM module in the VM context, You can call this function +/// to instantiate it. And you can then call `WasmEdge_VMExecute` for invoking +/// the exported function in this WASM module. +/// After calling this function, a new anonymous module instance owned by VM is +/// instantiated, and the old one will be destroyed. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMInstantiate(WasmEdge_VMContext *Cxt); + +/// Invoke a WASM function by name. +/// +/// This is the final step to invoke a WASM function step by step. +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can repeatedly call this function to invoke the exported WASM functions by +/// their names until the VM context is reset or a new WASM module is registered +/// or loaded. For calling the functions in registered WASM modules with module +/// names, please use `WasmEdge_VMExecuteRegistered` instead. If the `Returns` +/// buffer length is smaller than the arity of the function, the overflowed +/// return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result +WasmEdge_VMExecute(WasmEdge_VMContext *Cxt, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen, + WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Invoke a WASM function by its module name and function name. +/// +/// After registering a WASM module in the VM context, you can repeatedly call +/// this function to invoke exported WASM functions by their module names and +/// function names until the VM context is reset. If the `Returns` buffer length +/// is smaller than the arity of the function, the overflowed return values will +/// be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// \param [out] Returns the WasmEdge_Value buffer to fill the return values. +/// \param ReturnLen the return buffer length. +/// +/// \returns WasmEdge_Result. Call `WasmEdge_ResultGetMessage` for the error +/// message. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Result WasmEdge_VMExecuteRegistered( + WasmEdge_VMContext *Cxt, const WasmEdge_String ModuleName, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen, WasmEdge_Value *Returns, const uint32_t ReturnLen); + +/// Asynchronous invoke a WASM function by name. +/// +/// This is the final step to invoke a WASM function step by step. +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can repeatedly call this function to invoke the exported WASM functions by +/// their names until the VM context is reset or a new WASM module is registered +/// or loaded. For calling the functions in registered WASM modules with module +/// names, please use `WasmEdge_VMAsyncExecuteRegistered` instead. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async * +WasmEdge_VMAsyncExecute(WasmEdge_VMContext *Cxt, const WasmEdge_String FuncName, + const WasmEdge_Value *Params, const uint32_t ParamLen); + +/// Asynchronous invoke a WASM function by its module name and function name. +/// +/// After registering a WASM module in the VM context, you can repeatedly call +/// this function to invoke exported WASM functions by their module names and +/// function names until the VM context is reset. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// \param Params the WasmEdge_Value buffer with the parameter values. +/// \param ParamLen the parameter buffer length. +/// +/// \returns WasmEdge_Async. Call `WasmEdge_AsyncGet` for the result, and call +/// `WasmEdge_AsyncDelete` to destroy this object. +WASMEDGE_CAPI_EXPORT extern WasmEdge_Async *WasmEdge_VMAsyncExecuteRegistered( + WasmEdge_VMContext *Cxt, const WasmEdge_String ModuleName, + const WasmEdge_String FuncName, const WasmEdge_Value *Params, + const uint32_t ParamLen); + +/// Get the function type by function name. +/// +/// After instantiating a WASM module in the VM context, the WASM module is +/// registered into the store in the VM context as an anonymous module. Then you +/// can call this function to get the function type by the exported function +/// name until the VM context is reset or a new WASM module is registered or +/// loaded. For getting the function type of functions in registered WASM +/// modules with module names, please use `WasmEdge_VMGetFunctionTypeRegistered` +/// instead. +/// The returned function type context are linked to the context owned by the VM +/// context, and the caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete` to destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param FuncName the function name WasmEdge_String. +/// +/// \returns the function type. NULL if the function not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_VMGetFunctionType(const WasmEdge_VMContext *Cxt, + const WasmEdge_String FuncName); + +/// Get the function type by function name. +/// +/// After registering a WASM module in the VM context, you can call this +/// function to get the function type by the functions' exported module names +/// and function names until the VM context is reset. +/// The returned function type context are linked to the context owned by the VM +/// context, and the caller should __NOT__ call the +/// `WasmEdge_FunctionTypeDelete` to destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// \param FuncName the function name WasmEdge_String. +/// +/// \returns the function type. NULL if the function not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_FunctionTypeContext * +WasmEdge_VMGetFunctionTypeRegistered(const WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName, + const WasmEdge_String FuncName); + +/// Reset of WasmEdge_VMContext. +/// +/// After calling this function, the statistics, loaded module, the instantiated +/// instances, and the registered instances except the WASI and plug-ins will +/// all be cleared. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext to reset. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_VMCleanup(WasmEdge_VMContext *Cxt); + +/// Get the length of exported function list. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns length of exported function list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMGetFunctionListLength(const WasmEdge_VMContext *Cxt); + +/// Get the exported function list. +/// +/// The returned function names filled into the `Names` array link to the +/// exported names of functions owned by the vm context, and the caller should +/// __NOT__ call the `WasmEdge_StringDelete` to destroy them. +/// The function type contexts filled into the `FuncTypes` array of the +/// corresponding function names link to the context owned by the VM context. +/// The caller should __NOT__ call the `WasmEdge_FunctionTypeDelete` to destroy +/// them. +/// If the `Names` and `FuncTypes` buffer lengths are smaller than the result of +/// the exported function list size, the overflowed return values will be +/// discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param [out] Names the output names WasmEdge_String buffer of exported +/// functions. Can be NULL if names are not needed. +/// \param [out] FuncTypes the function type contexts buffer. Can be NULL if +/// function types are not needed. +/// \param Len the buffer length. +/// +/// \returns actual exported function list size. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_VMGetFunctionList( + const WasmEdge_VMContext *Cxt, WasmEdge_String *Names, + const WasmEdge_FunctionTypeContext **FuncTypes, const uint32_t Len); + +/// Get the module instance corresponding to the WasmEdge_HostRegistration +/// settings. +/// +/// When creating the VM context with a configuration, the built-in host module +/// will be registered according to the `WasmEdge_HostRegistration` settings +/// added into the `WasmEdge_ConfigureContext`. You can call this function to +/// get the `WasmEdge_ModuleInstanceContext` corresponding to the settings. The +/// module instance context links to the context owned by the VM context. The +/// caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete`. +/// +/// ```c +/// WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); +/// WasmEdge_ConfigureAddHostRegistration(Conf, WasmEdge_HostRegistration_Wasi); +/// WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); +/// WasmEdge_ModuleInstanceContext *WasiMod = +/// WasmEdge_VMGetImportModuleContext(VM, WasmEdge_HostRegistration_Wasi); +/// ``` +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Reg the host registration value to get the import module. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetImportModuleContext(const WasmEdge_VMContext *Cxt, + const enum WasmEdge_HostRegistration Reg); + +/// Get the current instantiated module in VM. +/// +/// After instantiating a module instance into the VM, developers can call this +/// API to get the active anonymous module instance to retrieve the exported +/// instances. The module instance context links to the context owned by the VM +/// context. The caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetActiveModule(const WasmEdge_VMContext *Cxt); + +/// Get the registered module in VM by the module name. +/// +/// After registering a WASM module into the VM context, developers can call +/// this function to get the module instance by the module name. The returned +/// module instance context links to the context owned by the VM context, and +/// the caller should __NOT__ call the `WasmEdge_ModuleInstanceDelete` to +/// destroy it. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param ModuleName the module name WasmEdge_String. +/// +/// \returns pointer to the module instance context. NULL if not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_ModuleInstanceContext * +WasmEdge_VMGetRegisteredModule(const WasmEdge_VMContext *Cxt, + const WasmEdge_String ModuleName); + +/// Get the length of registered module list in the WasmEdge_VMContext. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns length of registered module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMListRegisteredModuleLength(const WasmEdge_VMContext *Cxt); + +/// List the registered module names in the WasmEdge_VMContext. +/// +/// This function will list all registered module names. +/// The returned module names filled into the `Names` array are linked to the +/// registered module names in the VM context, and the caller should __NOT__ +/// call the `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the registered +/// named module list size, the overflowed return values will be discarded. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param [out] Names the output names WasmEdge_String buffer of the registered +/// modules. +/// \param Len the buffer length. +/// +/// \returns actual registered module list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_VMListRegisteredModule(const WasmEdge_VMContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Get the store context used in the WasmEdge_VMContext. +/// +/// The returned store context links to the store in the VM context and owned by +/// the VM context. This function will return NULL if error occurs. The caller +/// should __NOT__ call the `WasmEdge_StoreDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the store context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StoreContext * +WasmEdge_VMGetStoreContext(WasmEdge_VMContext *Cxt); + +/// Get the loader context used in the WasmEdge_VMContext. +/// +/// The returned loader context links to the loader in the VM context and owned +/// by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_LoaderDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the loader context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_LoaderContext * +WasmEdge_VMGetLoaderContext(WasmEdge_VMContext *Cxt); + +/// Get the validator context used in the WasmEdge_VMContext. +/// +/// The returned validator context links to the validator in the VM context and +/// owned by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_ValidatorDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the validator context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ValidatorContext * +WasmEdge_VMGetValidatorContext(WasmEdge_VMContext *Cxt); + +/// Get the executor context used in the WasmEdge_VMContext. +/// +/// The returned executor context links to the executor in the VM context and +/// owned by the VM context. This function will return NULL if error occurs. The +/// caller should __NOT__ call the `WasmEdge_ExecutorDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the executor context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ExecutorContext * +WasmEdge_VMGetExecutorContext(WasmEdge_VMContext *Cxt); + +/// Get the statistics context used in the WasmEdge_VMContext. +/// +/// The statistics context links to the statistics in the VM context and owned +/// by the VM context. The caller should __NOT__ call the +/// `WasmEdge_StatisticsDelete`. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// +/// \returns pointer to the statistics context. +WASMEDGE_CAPI_EXPORT extern WasmEdge_StatisticsContext * +WasmEdge_VMGetStatisticsContext(WasmEdge_VMContext *Cxt); + +/// Deletion of the WasmEdge_VMContext. +/// +/// After calling this function, the context will be destroyed and should +/// __NOT__ be used. +/// +/// \param Cxt the WasmEdge_VMContext to destroy. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_VMDelete(WasmEdge_VMContext *Cxt); + +// <<<<<<<< WasmEdge VM functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Driver functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \ + defined(__TOS_WIN__) || defined(__WINDOWS__) +/// Convert UTF16 Args to UTF8 Args +/// +/// This function is an argument converter for Windows platforms. +/// The caller owns the vector and should call `WasmEdge_Driver_ArgvDelete` to +/// destroy it. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns Allocated argument vector. +WASMEDGE_CAPI_EXPORT extern const char ** +WasmEdge_Driver_ArgvCreate(int Argc, const wchar_t *Argv[]); + +/// Deletion of the argument vector +/// +/// \param Argv the argument vector. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_Driver_ArgvDelete(const char *Argv[]); + +/// Set console output code page to UTF-8 on windows. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_Driver_SetConsoleOutputCPtoUTF8(void); +#endif + +/// Entrypoint for the compiler tool. +/// +/// This function provides an entrypoint to the WasmEdge AOT compiler tool with +/// the command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_Compiler(int Argc, + const char *Argv[]); + +/// Entrypoint for the runtime tool. +/// +/// This function provides an entrypoint to the WasmEdge runtime tool with the +/// command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_Tool(int Argc, + const char *Argv[]); + +#ifdef WASMEDGE_BUILD_WASI_NN_RPC +/// Entrypoint for the Wasi-NN RPC server tool. +/// +/// This function provides an entrypoint to the WasmEdge Wasi-NN RPC server tool +/// with the command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int +WasmEdge_Driver_WasiNNRPCServer(int Argc, const char *Argv[]); +#endif + +/// Entrypoint for the unified tool. +/// +/// This function provides an entrypoint to the WasmEdge unified tool with the +/// command line arguments. +/// +/// \param Argc the argument count. +/// \param Argv the argument vector. +/// +/// \returns the execution status. +WASMEDGE_CAPI_EXPORT extern int WasmEdge_Driver_UniTool(int Argc, + const char *Argv[]); + +// <<<<<<<< WasmEdge Driver functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Plugin functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Load plugins with the default search paths. +/// +/// The default paths are: +/// 1. The environment variable "WASMEDGE_PLUGIN_PATH". +/// 2. The "../plugin/" directory related to the WasmEdge installation path. +/// 3. The "wasmedge/" directory under the library path if the WasmEdge is +/// installed under the "/usr". +WASMEDGE_CAPI_EXPORT extern void WasmEdge_PluginLoadWithDefaultPaths(void); + +/// Load the plugin with the given file or directory. +/// +/// For the given file path, this function will load the plug-in. +/// For the given directory path, this function will load the plug-ins under the +/// directory recursively. +/// +/// \param Path the path to plug-in file or directory. +WASMEDGE_CAPI_EXPORT extern void WasmEdge_PluginLoadFromPath(const char *Path); + +/// Get the length of loaded plug-in list. +/// +/// \returns length of loaded plug-in list. +WASMEDGE_CAPI_EXPORT extern uint32_t WasmEdge_PluginListPluginsLength(void); + +/// List the loaded plug-ins with their names. +/// +/// The returned plug-in names filled into the `Names` array are owned by the +/// internal WasmEdge plug-in storage, and the caller should __NOT__ call the +/// `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the loaded +/// plug-in list size, the overflowed return values will be discarded. +/// +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual loaded plug-in list size. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListPlugins(WasmEdge_String *Names, const uint32_t Len); + +/// Find the loaded plug-in context by name. +/// +/// After loading the plug-ins from default paths or the given path, developers +/// can use this API to retrieve the plug-in context by name. Then developers +/// can create the module instance from the plug-in contexts. +/// +/// \param Name the plug-in name WasmEdge_String. +/// +/// \returns pointer to the plug-in context. NULL if the plug-in not found. +WASMEDGE_CAPI_EXPORT extern const WasmEdge_PluginContext * +WasmEdge_PluginFind(const WasmEdge_String Name); + +/// Get the plug-in name of the plug-in context. +/// +/// The returned string object is linked to the plug-in name of the plug-in +/// context, and the caller should __NOT__ call the `WasmEdge_StringDelete`. +/// +/// \param Cxt the WasmEdge_PluginContext. +/// +/// \returns string object. Length will be 0 and Buf will be NULL if failed. +WASMEDGE_CAPI_EXPORT extern WasmEdge_String +WasmEdge_PluginGetPluginName(const WasmEdge_PluginContext *Cxt); + +/// Get the length of module list in the plug-in context. +/// +/// There may be several modules in a plug-in. Developers can use this function +/// to get the length of the module list in a plug-in. +/// +/// \param Cxt the WasmEdge_PluginContext to get the length of the module list. +/// +/// \returns length of module list. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListModuleLength(const WasmEdge_PluginContext *Cxt); + +/// List the modules in the plug-in context with their names. +/// +/// The returned module names filled into the `Names` array are owned by the +/// internal WasmEdge plug-in storage, and the caller should __NOT__ call the +/// `WasmEdge_StringDelete`. +/// If the `Names` buffer length is smaller than the result of the loaded +/// plug-in list size, the overflowed return values will be discarded. +/// +/// \param Cxt the WasmEdge_PluginContext to list the modules. +/// \param [out] Names the output WasmEdge_String buffer of the function names. +/// \param Len the buffer length. +/// +/// \returns actual module list size of the plug-in. +WASMEDGE_CAPI_EXPORT extern uint32_t +WasmEdge_PluginListModule(const WasmEdge_PluginContext *Cxt, + WasmEdge_String *Names, const uint32_t Len); + +/// Create the module instance in the plug-in by the module name. +/// +/// By giving the module name, developers can retrieve the module in the plug-in +/// and create the module instance. +/// The caller owns the object and should call `WasmEdge_ModuleInstanceDelete` +/// to destroy it. +/// +/// \param Cxt the WasmEdge_PluginContext to retrieve and create module. +/// \param ModuleName the module name to retrieve. +/// +/// \returns pointer to the module instance context, NULL if the module name not +/// found in the plug-in or the plug-in is not valid. +WASMEDGE_CAPI_EXPORT extern WasmEdge_ModuleInstanceContext * +WasmEdge_PluginCreateModule(const WasmEdge_PluginContext *Cxt, + const WasmEdge_String ModuleName); + +/// Initialize the wasi_nn plug-in. +/// +/// This function will initialize the wasi_nn plug-in with the preloads string +/// list. Only available after loading the wasi_nn plug-in and before creating +/// the module instance from the plug-in. +/// +/// \param NNPreloads the preload string list. NULL if the length is 0. +/// \param PreloadsLen the length of the preload list. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_PluginInitWASINN(const char *const *NNPreloads, + const uint32_t PreloadsLen); + +/// Implement by plugins for returning the plugin descriptor. +/// +/// \returns the plugin descriptor. +WASMEDGE_CAPI_PLUGIN_EXPORT extern const WasmEdge_PluginDescriptor * +WasmEdge_Plugin_GetDescriptor(void); + +// <<<<<<<< WasmEdge Pluginfunctions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +// >>>>>>>> WasmEdge Experimental functions >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +/// Register a host function that will be invoked before executing any host +/// functions. +/// +/// There is only one pre-host-function. After calling this function, the +/// previous registered host function will be replaced. This is a experimental +/// feature. Use it at your own risk. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_ExecutorContext. +/// \param Data the host data to set into the given host function. When calling +/// the Func, this pointer will be the argument of the Func function. +/// \param Func the function to be invoked before executing any other host +/// functions. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorExperimentalRegisterPreHostFunction( + WasmEdge_ExecutorContext *Cxt, void *Data, void (*Func)(void *)); + +/// Register a host function that will be invoked after executing any host +/// functions. +/// +/// There is only one post-host-function. After calling this function, the +/// previous registered host function will be replaced. This is a experimental +/// feature. Use it at your own risk. +/// +/// This function is thread-safe. +/// +/// \param Cxt the WasmEdge_VMContext. +/// \param Data the host data to set into the given host function. When calling +/// the Func, this pointer will be the argument of the Func function. +/// \param Func the function to be invoked after executing any other host +/// functions. +WASMEDGE_CAPI_EXPORT extern void +WasmEdge_ExecutorExperimentalRegisterPostHostFunction( + WasmEdge_ExecutorContext *Cxt, void *Data, void (*Func)(void *)); + +// <<<<<<<< WasmEdge Experimental Functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +#ifdef __cplusplus +} /// extern "C" +#endif + +#endif /// WASMEDGE_C_API_H diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so new file mode 120000 index 0000000000000000000000000000000000000000..145d5a021c32a26423bac2fecffd6a174664a3b3 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so @@ -0,0 +1 @@ +libwasmedge.so.0 \ No newline at end of file diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0 b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0 new file mode 120000 index 0000000000000000000000000000000000000000..6639f000114eaf75d312c5ce1153d5b25b079a87 --- /dev/null +++ b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0 @@ -0,0 +1 @@ +libwasmedge.so.0.1.0 \ No newline at end of file diff --git a/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0.1.0 b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0.1.0 new file mode 100755 index 0000000000000000000000000000000000000000..e85e06a4229b8dcbd0e395c3768a6d060e0e405d Binary files /dev/null and b/wasmedge/lib-0.14.1-manylinux2014/x86_64/lib/libwasmedge.so.0.1.0 differ diff --git a/wasmedge/make b/wasmedge/make new file mode 100644 index 0000000000000000000000000000000000000000..fdecd5b1a3853632ba9f94ea590c137fa13693d4 --- /dev/null +++ b/wasmedge/make @@ -0,0 +1,26 @@ +case "$CC" in + bcc32) + +cat << END + +$0: error: not allow build use bcc32 + +END + + ;; + + *) + CMAKE="cmake" + if command -v cmake3 > /dev/null; then + CMAKE="cmake3" + fi + cat << END >> $NJT_MAKEFILE + +$WASMEDGE/build/include/wasmedge/wasmedge.h: + cd $WASMEDGE \\ + && mkdir -p build \\ + && cp -r lib-0.14.1-manylinux2014/$wasm_arch/* build +END + ;; + +esac