From 4abf288c9431224dfef410bc972feac6dbdb2bc6 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Mon, 29 Apr 2024 17:57:49 -0700 Subject: [PATCH 001/198] Fix typo for 'native' in wasm_export.h (#3376) Trivial spelling fix. --- core/iwasm/include/wasm_export.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index c7513396f..130225681 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1602,7 +1602,7 @@ wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch); /** * Check whether an import func `(import (func ...))` - * is linked or not with runtime registered natvie functions + * is linked or not with runtime registered native functions */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_func_linked(const char *module_name, @@ -1610,7 +1610,7 @@ wasm_runtime_is_import_func_linked(const char *module_name, /** * Check whether an import global `(import - * (global ...))` is linked or not with runtime registered natvie globals + * (global ...))` is linked or not with runtime registered native globals */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, From 163f29e51ba656b3a7d275c3e252345878a00958 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 1 May 2024 16:15:17 +0900 Subject: [PATCH 002/198] Add some more comments on WASM_STACK_GUARD_SIZE (#3380) --- core/config.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/config.h b/core/config.h index 0a77ec949..874276666 100644 --- a/core/config.h +++ b/core/config.h @@ -470,8 +470,23 @@ * 200 bytes (release build, macOS/amd64) * 2600 bytes (debug build, macOS/amd64) * - * libc snprintf (used by eg. wasm_runtime_set_exception) consumes about - * 1600 bytes stack on macOS/amd64, about 2000 bytes on Ubuntu amd64 20.04. + * - platform-provided functions (eg. libc) + * + * the following are examples of the stack consumptions observed for + * host APIs. + * + * snprintf: (used by eg. wasm_runtime_set_exception) + * - about 1600 bytes on macOS/amd64 + * - about 2000 bytes on Ubuntu amd64 20.04 + * + * gethostbyname: + * - 3KB-6KB on macOS/amd64 + * - 10KB on Ubuntu amd64 20.04 + * + * getaddrinfo: + * - 4KB-17KB on macOS/amd64 + * - 12KB on Ubuntu amd64 20.04 + * - 0.3-1.5KB on NuttX/esp32s3 * * - stack check wrapper functions generated by the aot compiler * (--stack-bounds-checks=1) @@ -480,6 +495,9 @@ * "precheck functions themselves consume relatively large amount of stack" * when it detects wrapper functions requiring more than 1KB. * + * - the ABI-defined red zone. eg. 128 bytes for SYSV x86-64 ABI. + * cf. https://en.wikipedia.org/wiki/Red_zone_(computing) + * * Note: on platforms with lazy function binding, don't forget to consider * the symbol resolution overhead on the first call. For example, * on Ubuntu amd64 20.04, it seems to consume about 1500 bytes. From 835188cc53373159165423debc48242ad15548d6 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Wed, 1 May 2024 21:40:52 +0800 Subject: [PATCH 003/198] aot compiler: Fix the length type passed to aot_memmove/aot_memset (#3378) The current length type of aot_memmove/aot_memset is size_t, and on a 64 bit host it is uint64, while what the aot code passes to it is uint32, this might lead to unexpected behavior. ps. https://github.com/bytecodealliance/wasm-micro-runtime/pull/3376. --- core/iwasm/compilation/aot_compiler.h | 1 + core/iwasm/compilation/aot_emit_memory.c | 22 ++++++++++++++++++++-- core/iwasm/compilation/aot_llvm.c | 2 ++ core/iwasm/compilation/aot_llvm.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/iwasm/compilation/aot_compiler.h b/core/iwasm/compilation/aot_compiler.h index 5038a4130..08e9db7bf 100644 --- a/core/iwasm/compilation/aot_compiler.h +++ b/core/iwasm/compilation/aot_compiler.h @@ -603,6 +603,7 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type) #define INT8_TYPE comp_ctx->basic_types.int8_type #define INT16_TYPE comp_ctx->basic_types.int16_type #define INTPTR_T_TYPE comp_ctx->basic_types.intptr_t_type +#define SIZE_T_TYPE comp_ctx->basic_types.size_t_type #define MD_TYPE comp_ctx->basic_types.meta_data_type #define INT8_PTR_TYPE comp_ctx->basic_types.int8_ptr_type #define INT16_PTR_TYPE comp_ctx->basic_types.int16_ptr_type diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index eedc5420a..4f741effe 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -1090,6 +1090,15 @@ aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) if (!(dst_addr = check_bulk_memory_overflow(comp_ctx, func_ctx, dst, len))) return false; + if (comp_ctx->pointer_size == sizeof(uint64)) { + /* zero extend to uint64 if the target is 64-bit */ + len = LLVMBuildZExt(comp_ctx->builder, len, I64_TYPE, "len64"); + if (!len) { + aot_set_last_error("llvm build zero extend failed."); + return false; + } + } + call_aot_memmove = comp_ctx->is_indirect_mode || comp_ctx->is_jit_mode; if (call_aot_memmove) { LLVMTypeRef param_types[3], ret_type, func_type, func_ptr_type; @@ -1097,7 +1106,7 @@ aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) param_types[0] = INT8_PTR_TYPE; param_types[1] = INT8_PTR_TYPE; - param_types[2] = I32_TYPE; + param_types[2] = SIZE_T_TYPE; ret_type = INT8_PTR_TYPE; if (!(func_type = LLVMFunctionType(ret_type, param_types, 3, false))) { @@ -1172,9 +1181,18 @@ aot_compile_op_memory_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) if (!(dst_addr = check_bulk_memory_overflow(comp_ctx, func_ctx, dst, len))) return false; + if (comp_ctx->pointer_size == sizeof(uint64)) { + /* zero extend to uint64 if the target is 64-bit */ + len = LLVMBuildZExt(comp_ctx->builder, len, I64_TYPE, "len64"); + if (!len) { + aot_set_last_error("llvm build zero extend failed."); + return false; + } + } + param_types[0] = INT8_PTR_TYPE; param_types[1] = I32_TYPE; - param_types[2] = I32_TYPE; + param_types[2] = SIZE_T_TYPE; ret_type = INT8_PTR_TYPE; if (!(func_type = LLVMFunctionType(ret_type, param_types, 3, false))) { diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 3af56e8b6..9c3acf753 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1973,10 +1973,12 @@ aot_set_llvm_basic_types(AOTLLVMTypes *basic_types, LLVMContextRef context, if (pointer_size == 4) { basic_types->intptr_t_type = basic_types->int32_type; basic_types->intptr_t_ptr_type = basic_types->int32_ptr_type; + basic_types->size_t_type = basic_types->int32_type; } else { basic_types->intptr_t_type = basic_types->int64_type; basic_types->intptr_t_ptr_type = basic_types->int64_ptr_type; + basic_types->size_t_type = basic_types->int64_type; } basic_types->gc_ref_type = basic_types->int8_ptr_type; diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index a47c054c9..d30c56f7d 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -262,6 +262,7 @@ typedef struct AOTLLVMTypes { LLVMTypeRef int32_type; LLVMTypeRef int64_type; LLVMTypeRef intptr_t_type; + LLVMTypeRef size_t_type; LLVMTypeRef float32_type; LLVMTypeRef float64_type; LLVMTypeRef void_type; From 3e5361f76d15aa011ac021e1866ab18a670a7d3c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 3 May 2024 10:16:35 +0900 Subject: [PATCH 004/198] samples/native-stack-overflow: Examine native functions with signature (#3382) Note: wamrc chooses different methods to call native functions with and without signatures. --- samples/native-stack-overflow/build.sh | 32 ++++++++++++++++-- samples/native-stack-overflow/run.sh | 8 +++++ samples/native-stack-overflow/src/signature.c | 33 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 samples/native-stack-overflow/src/signature.c diff --git a/samples/native-stack-overflow/build.sh b/samples/native-stack-overflow/build.sh index ac9f410f4..de91f2695 100755 --- a/samples/native-stack-overflow/build.sh +++ b/samples/native-stack-overflow/build.sh @@ -41,6 +41,11 @@ if [ $? != 0 ];then fi cp -a native-stack-overflow ${OUT_DIR}/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK +echo "##################### signature shared lib" +cd ${CURR_DIR} +cc -I ../../core/iwasm/include -shared -o ${OUT_DIR}/signature.so \ +src/signature.c + echo echo "##################### build wasm apps" @@ -69,7 +74,30 @@ echo "#################### build wasm apps done" echo "#################### aot-compile" WAMRC=${WAMR_DIR}/wamr-compiler/build/wamrc -${WAMRC} -o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot --size-level=0 ${OUT_DIR}/wasm-apps/${OUT_FILE} +${WAMRC} \ +-o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot \ +--size-level=0 \ +${OUT_DIR}/wasm-apps/${OUT_FILE} + +echo "#################### aot-compile w/ signature" +WAMRC=${WAMR_DIR}/wamr-compiler/build/wamrc +${WAMRC} \ +-o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot.signature \ +--size-level=0 \ +--native-lib=${OUT_DIR}/signature.so \ +${OUT_DIR}/wasm-apps/${OUT_FILE} echo "#################### aot-compile (--bounds-checks=1)" -${WAMRC} -o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot.bounds-checks --size-level=0 --bounds-checks=1 ${OUT_DIR}/wasm-apps/${OUT_FILE} +${WAMRC} \ +-o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot.bounds-checks \ +--size-level=0 \ +--bounds-checks=1 \ +${OUT_DIR}/wasm-apps/${OUT_FILE} + +echo "#################### aot-compile (--bounds-checks=1) w/ signature" +${WAMRC} \ +-o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot.signature.bounds-checks \ +--size-level=0 \ +--native-lib=${OUT_DIR}/signature.so \ +--bounds-checks=1 \ +${OUT_DIR}/wasm-apps/${OUT_FILE} diff --git a/samples/native-stack-overflow/run.sh b/samples/native-stack-overflow/run.sh index 3386ea1ef..3ba48980a 100755 --- a/samples/native-stack-overflow/run.sh +++ b/samples/native-stack-overflow/run.sh @@ -15,6 +15,14 @@ echo echo "====== AOT ${NAME}" out/native-stack-overflow out/wasm-apps/testapp.wasm.aot ${NAME} +echo +echo "====== AOT w/ signature ${NAME}" +out/native-stack-overflow out/wasm-apps/testapp.wasm.aot.signature ${NAME} + echo echo "====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1 ${NAME}" out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm.aot.bounds-checks ${NAME} + +echo +echo "====== AOT w/ signature WAMR_DISABLE_HW_BOUND_CHECK=1 ${NAME}" +out/native-stack-overflow.WAMR_DISABLE_HW_BOUND_CHECK out/wasm-apps/testapp.wasm.aot.signature.bounds-checks ${NAME} diff --git a/samples/native-stack-overflow/src/signature.c b/samples/native-stack-overflow/src/signature.c new file mode 100644 index 000000000..65dc2043f --- /dev/null +++ b/samples/native-stack-overflow/src/signature.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include + +#include "wasm_export.h" + +static int +dummy(wasm_exec_env_t exec_env) +{ + return 0; +} + +/* clang-format off */ +#define REG_NATIVE_FUNC(func_name, signature) \ + { #func_name, dummy, signature, NULL } + +static NativeSymbol native_symbols[] = { + REG_NATIVE_FUNC(host_consume_stack_and_call_indirect, "(iii)i"), + REG_NATIVE_FUNC(host_consume_stack, "(i)i"), +}; +/* clang-format on */ + +uint32_t +get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols) +{ + *p_module_name = "env"; + *p_native_symbols = native_symbols; + return sizeof(native_symbols) / sizeof(NativeSymbol); +} From c0e33f08b04a5e03220ef74c2a9dbea8f1f35996 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Thu, 2 May 2024 18:41:08 -0700 Subject: [PATCH 005/198] Expose API to get import/export function's param/result valkind (#3363) Export API: ```C wasm_func_type_get_param_count wasm_func_type_get_param_valkind wasm_func_type_get_result_count wasm_func_type_get_result_valkind ``` And change wasm_import_type/wasm_export_type to wasm_import_t/wasm_export_t. --- core/iwasm/common/gc/gc_common.c | 12 --- core/iwasm/common/wasm_runtime_common.c | 107 +++++++++++++++++++++++- core/iwasm/include/gc_export.h | 20 ----- core/iwasm/include/wasm_export.h | 65 ++++++++++++-- 4 files changed, 162 insertions(+), 42 deletions(-) diff --git a/core/iwasm/common/gc/gc_common.c b/core/iwasm/common/gc/gc_common.c index 99fca86d4..5cc869a65 100644 --- a/core/iwasm/common/gc/gc_common.c +++ b/core/iwasm/common/gc/gc_common.c @@ -176,12 +176,6 @@ wasm_defined_type_is_array_type(WASMType *const def_type) return wasm_type_is_array_type(def_type); } -uint32 -wasm_func_type_get_param_count(WASMFuncType *const func_type) -{ - return func_type->param_count; -} - wasm_ref_type_t wasm_func_type_get_param_type(WASMFuncType *const func_type, uint32 param_idx) { @@ -202,12 +196,6 @@ wasm_func_type_get_param_type(WASMFuncType *const func_type, uint32 param_idx) return ref_type; } -uint32 -wasm_func_type_get_result_count(WASMFuncType *const func_type) -{ - return (uint32)func_type->result_count; -} - wasm_ref_type_t wasm_func_type_get_result_type(WASMFuncType *const func_type, uint32 result_idx) { diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 2b481710c..fe5b2baed 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3756,14 +3756,14 @@ wasm_runtime_get_import_count(WASMModuleCommon *const module) void wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index, - wasm_import_type *import_type) + wasm_import_t *import_type) { if (!import_type) { bh_assert(0); return; } - memset(import_type, 0, sizeof(wasm_import_type)); + memset(import_type, 0, sizeof(wasm_import_t)); if (!module) { bh_assert(0); @@ -3783,6 +3783,7 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index, import_type->kind = WASM_IMPORT_EXPORT_KIND_FUNC; import_type->linked = aot_import_func->func_ptr_linked ? true : false; + import_type->u.func_type = aot_import_func->func_type; return; } @@ -3840,6 +3841,7 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index, switch (import_type->kind) { case WASM_IMPORT_EXPORT_KIND_FUNC: import_type->linked = wasm_import->u.function.func_ptr_linked; + import_type->u.func_type = wasm_import->u.function.func_type; break; case WASM_IMPORT_EXPORT_KIND_GLOBAL: import_type->linked = wasm_import->u.global.is_linked; @@ -3888,14 +3890,14 @@ wasm_runtime_get_export_count(WASMModuleCommon *const module) void wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index, - wasm_export_type *export_type) + wasm_export_t *export_type) { if (!export_type) { bh_assert(0); return; } - memset(export_type, 0, sizeof(wasm_export_type)); + memset(export_type, 0, sizeof(wasm_export_t)); if (!module) { bh_assert(0); @@ -3914,6 +3916,12 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index, const AOTExport *aot_export = &aot_module->exports[export_index]; export_type->name = aot_export->name; export_type->kind = aot_export->kind; + if (export_type->kind == EXPORT_KIND_FUNC) { + export_type->u.func_type = + (AOTFuncType *)aot_module->types + [aot_module->func_type_indexes + [aot_export->index - aot_module->import_func_count]]; + } return; } #endif @@ -3929,11 +3937,102 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index, const WASMExport *wasm_export = &wasm_module->exports[export_index]; export_type->name = wasm_export->name; export_type->kind = wasm_export->kind; + if (wasm_export->kind == EXPORT_KIND_FUNC) { + export_type->u.func_type = + wasm_module + ->functions[wasm_export->index + - wasm_module->import_function_count] + ->func_type; + } return; } #endif } +uint32 +wasm_func_type_get_param_count(WASMFuncType *const func_type) +{ + bh_assert(func_type); + + return func_type->param_count; +} + +wasm_valkind_t +wasm_func_type_get_param_valkind(WASMFuncType *const func_type, + uint32 param_index) +{ + if (!func_type || (param_index >= func_type->param_count)) { + bh_assert(0); + return (wasm_valkind_t)-1; + } + + switch (func_type->types[param_index]) { + case VALUE_TYPE_I32: + return WASM_I32; + case VALUE_TYPE_I64: + return WASM_I64; + case VALUE_TYPE_F32: + return WASM_F32; + case VALUE_TYPE_F64: + return WASM_F64; + case VALUE_TYPE_FUNCREF: + return WASM_FUNCREF; + + case VALUE_TYPE_V128: + case VALUE_TYPE_EXTERNREF: + case VALUE_TYPE_VOID: + default: + { + bh_assert(0); + return (wasm_valkind_t)-1; + } + } +} + +uint32 +wasm_func_type_get_result_count(WASMFuncType *const func_type) +{ + bh_assert(func_type); + + return func_type->result_count; +} + +wasm_valkind_t +wasm_func_type_get_result_valkind(WASMFuncType *const func_type, + uint32 result_index) +{ + if (!func_type || (result_index >= func_type->result_count)) { + bh_assert(0); + return (wasm_valkind_t)-1; + } + + switch (func_type->types[func_type->param_count + result_index]) { + case VALUE_TYPE_I32: + return WASM_I32; + case VALUE_TYPE_I64: + return WASM_I64; + case VALUE_TYPE_F32: + return WASM_F32; + case VALUE_TYPE_F64: + return WASM_F64; + case VALUE_TYPE_FUNCREF: + return WASM_FUNCREF; + +#if WASM_ENABLE_SIMD != 0 + case VALUE_TYPE_V128: +#endif +#if WASM_ENABLE_REF_TYPES != 0 + case VALUE_TYPE_EXTERNREF: +#endif + case VALUE_TYPE_VOID: + default: + { + bh_assert(0); + return (wasm_valkind_t)-1; + } + } +} + bool wasm_runtime_register_natives(const char *module_name, NativeSymbol *native_symbols, diff --git a/core/iwasm/include/gc_export.h b/core/iwasm/include/gc_export.h index 777551edc..a9cdd148f 100644 --- a/core/iwasm/include/gc_export.h +++ b/core/iwasm/include/gc_export.h @@ -230,16 +230,6 @@ wasm_defined_type_is_struct_type(const wasm_defined_type_t def_type); WASM_RUNTIME_API_EXTERN bool wasm_defined_type_is_array_type(const wasm_defined_type_t def_type); -/** - * Get parameter count of a function type - * - * @param func_type the specified function type - * - * @return the param count of the specified function type - */ -WASM_RUNTIME_API_EXTERN uint32_t -wasm_func_type_get_param_count(const wasm_func_type_t func_type); - /** * Get type of a specified parameter of a function type * @@ -253,16 +243,6 @@ WASM_RUNTIME_API_EXTERN wasm_ref_type_t wasm_func_type_get_param_type(const wasm_func_type_t func_type, uint32_t param_idx); -/** - * Get result count of a function type - * - * @param func_type the specified function type - * - * @return the result count of the specified function type - */ -WASM_RUNTIME_API_EXTERN uint32_t -wasm_func_type_get_result_count(const wasm_func_type_t func_type); - /** * Get type of a specified result of a function type * diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 130225681..024c1eda3 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -72,17 +72,26 @@ typedef enum { WASM_IMPORT_EXPORT_KIND_GLOBAL } wasm_import_export_kind_t; -typedef struct wasm_import_type { +struct WASMFuncType; +typedef struct WASMFuncType *wasm_func_type_t; + +typedef struct wasm_import_t { const char *module_name; const char *name; wasm_import_export_kind_t kind; bool linked; -} wasm_import_type; + union { + wasm_func_type_t func_type; + } u; +} wasm_import_t; -typedef struct wasm_export_type { +typedef struct wasm_export_t { const char *name; wasm_import_export_kind_t kind; -} wasm_export_type; + union { + wasm_func_type_t func_type; + } u; +} wasm_export_t; /* Instantiated WASM module */ struct WASMModuleInstanceCommon; @@ -1234,7 +1243,7 @@ wasm_runtime_get_import_count(const wasm_module_t module); */ WASM_RUNTIME_API_EXTERN void wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index, - wasm_import_type *import_type); + wasm_import_t *import_type); /** * Get the number of export items for a WASM module @@ -1255,7 +1264,51 @@ wasm_runtime_get_export_count(const wasm_module_t module); */ WASM_RUNTIME_API_EXTERN void wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index, - wasm_export_type *export_type); + wasm_export_t *export_type); + +/** + * Get the number of parameters for a function type + * + * @param func_type the function type + * + * @return the number of parameters for the function type + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_func_type_get_param_count(wasm_func_type_t const func_type); + +/** + * Get the kind of a parameter for a function type + * + * @param func_type the function type + * @param param_index the index of the parameter to get + * + * @return the kind of the parameter if successful, -1 otherwise + */ +WASM_RUNTIME_API_EXTERN wasm_valkind_t +wasm_func_type_get_param_valkind(wasm_func_type_t const func_type, + uint32_t param_index); + +/** + * Get the number of results for a function type + * + * @param func_type the function type + * + * @return the number of results for the function type + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_func_type_get_result_count(wasm_func_type_t const func_type); + +/** + * Get the kind of a result for a function type + * + * @param func_type the function type + * @param result_index the index of the result to get + * + * @return the kind of the result if successful, -1 otherwise + */ +WASM_RUNTIME_API_EXTERN wasm_valkind_t +wasm_func_type_get_result_valkind(wasm_func_type_t const func_type, + uint32_t result_index); /** * Register native functions with same module name From ca61184ced7d885395bc2425c87f0d063935dd1e Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Sun, 5 May 2024 16:56:48 -0700 Subject: [PATCH 006/198] Fix some spelling issues (#3385) Fix some of the spelling issues found by CSpell. --- .github/workflows/build_llvm_libraries.yml | 2 +- ci/coding_guidelines_check.py | 4 ++-- core/config.h | 8 ++++---- core/iwasm/aot/aot_loader.c | 14 +++++++------- core/iwasm/aot/aot_runtime.c | 16 ++++++++-------- core/iwasm/aot/aot_runtime.h | 4 ++-- core/iwasm/common/gc/gc_object.h | 4 ++-- core/iwasm/common/wasm_application.c | 6 +++--- core/iwasm/common/wasm_c_api.c | 14 +++++++------- core/iwasm/common/wasm_c_api_internal.h | 4 ++-- core/iwasm/common/wasm_exec_env.c | 2 +- core/iwasm/common/wasm_native.c | 8 ++++---- core/iwasm/common/wasm_runtime_common.c | 16 ++++++++-------- core/iwasm/common/wasm_runtime_common.h | 2 +- core/iwasm/compilation/aot_emit_aot_file.c | 6 +++--- core/iwasm/compilation/simd/simd_conversions.c | 2 +- core/iwasm/include/gc_export.h | 4 ++-- core/iwasm/include/wasm_c_api.h | 4 ++-- core/iwasm/include/wasm_export.h | 16 ++++++++-------- core/iwasm/interpreter/wasm.h | 8 ++++---- core/iwasm/interpreter/wasm_runtime.c | 10 +++++----- core/iwasm/libraries/thread-mgr/thread_manager.c | 2 +- core/iwasm/libraries/thread-mgr/thread_manager.h | 4 ++-- core/shared/utils/bh_log.c | 2 +- .../python/wasm-c-api/docs/design.md | 8 ++++---- product-mini/README.md | 2 +- .../linux-sgx/enclave-sample/Enclave/Enclave.cpp | 4 ++-- product-mini/platforms/posix/main.c | 5 +++-- product-mini/platforms/windows/main.c | 5 +++-- samples/multi-module/src/main.c | 7 ++++--- samples/wasm-c-api/src/clone.c | 8 ++++---- 31 files changed, 102 insertions(+), 99 deletions(-) diff --git a/.github/workflows/build_llvm_libraries.yml b/.github/workflows/build_llvm_libraries.yml index 67eaf614d..80abf57ec 100644 --- a/.github/workflows/build_llvm_libraries.yml +++ b/.github/workflows/build_llvm_libraries.yml @@ -43,7 +43,7 @@ jobs: run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages working-directory: build-scripts - - name: retrive the last commit ID + - name: retrieve the last commit ID id: get_last_commit run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT working-directory: build-scripts diff --git a/ci/coding_guidelines_check.py b/ci/coding_guidelines_check.py index 924a24280..f3f378b91 100644 --- a/ci/coding_guidelines_check.py +++ b/ci/coding_guidelines_check.py @@ -57,7 +57,7 @@ def pre_flight_check(root: pathlib) -> bool: def check_aspell(root): return True - def check_clang_foramt(root: pathlib) -> bool: + def check_clang_format(root: pathlib) -> bool: if not locate_command(CLANG_FORMAT_CMD): return False @@ -74,7 +74,7 @@ def pre_flight_check(root: pathlib) -> bool: def check_git_clang_format() -> bool: return locate_command(GIT_CLANG_FORMAT_CMD) - return check_aspell(root) and check_clang_foramt(root) and check_git_clang_format() + return check_aspell(root) and check_clang_format(root) and check_git_clang_format() def run_clang_format(file_path: pathlib, root: pathlib) -> bool: diff --git a/core/config.h b/core/config.h index 874276666..3f754ce1f 100644 --- a/core/config.h +++ b/core/config.h @@ -304,7 +304,7 @@ #define WASM_DISABLE_STACK_HW_BOUND_CHECK 0 #endif -/* Disable SIMD unless it is manualy enabled somewhere */ +/* Disable SIMD unless it is manually enabled somewhere */ #ifndef WASM_ENABLE_SIMD #define WASM_ENABLE_SIMD 0 #endif @@ -445,7 +445,7 @@ #endif /* Reserved bytes to the native thread stack boundary, throw native - * stack overflow exception if the guard boudary is reached + * stack overflow exception if the guard boundary is reached * * WASM_STACK_GUARD_SIZE needs to be large enough for: * @@ -461,7 +461,7 @@ * - aot runtime functions * eg. aot_enlarge_memory. * - * - w/o hw bound check, the intepreter loop + * - w/o hw bound check, the interpreter loop * * the stack consumption heavily depends on compiler settings, * especially for huge functions like the classic interpreter's @@ -514,7 +514,7 @@ /* * Use a larger default for platforms like macOS/Linux. * - * For example, the classic intepreter loop which ended up with a trap + * For example, the classic interpreter loop which ended up with a trap * (wasm_runtime_set_exception) would consume about 2KB stack on x86-64 * macOS. On Ubuntu amd64 20.04, it seems to consume a bit more. * diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 7db0db7cc..d635e59d7 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -94,7 +94,7 @@ check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length, { if ((uintptr_t)buf + length < (uintptr_t)buf || (uintptr_t)buf + length > (uintptr_t)buf_end) { - set_error_buf(error_buf, error_buf_size, "unexpect end"); + set_error_buf(error_buf, error_buf_size, "unexpected end"); return false; } return true; @@ -323,13 +323,13 @@ load_string(uint8 **p_buf, const uint8 *buf_end, AOTModule *module, #endif else if (is_load_from_file_buf) { /* The string is always terminated with '\0', use it directly. - * In this case, the file buffer can be reffered to after loading. + * In this case, the file buffer can be referred to after loading. */ bh_assert(p[str_len - 1] == '\0'); str = (char *)p; } else { - /* Load from sections, the file buffer cannot be reffered to + /* Load from sections, the file buffer cannot be referred to after loading, we must create another string and insert it into const string set */ bh_assert(p[str_len - 1] == '\0'); @@ -2518,7 +2518,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module, #if defined(BUILD_TARGET_XTENSA) /* * For Xtensa XIP, real func_count is doubled, including aot_func and - * aot_func_internal, so need to multipy func_count by 2 here. + * aot_func_internal, so need to multiply func_count by 2 here. */ if (module->is_indirect_mode) { func_count *= 2; @@ -3912,7 +3912,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode, p += 8; while (p < p_end) { read_uint32(p, p_end, section_type); - if (section_type <= AOT_SECTION_TYPE_SIGANATURE) { + if (section_type <= AOT_SECTION_TYPE_SIGNATURE) { read_uint32(p, p_end, section_size); CHECK_BUF(p, p_end, section_size); if (section_type == AOT_SECTION_TYPE_TARGET_INFO) { @@ -3927,7 +3927,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode, break; } } - else { /* section_type > AOT_SECTION_TYPE_SIGANATURE */ + else { /* section_type > AOT_SECTION_TYPE_SIGNATURE */ set_error_buf(error_buf, error_buf_size, "resolve execute mode failed"); break; @@ -3966,7 +3966,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, p += 8; while (p < p_end) { read_uint32(p, p_end, section_type); - if (section_type < AOT_SECTION_TYPE_SIGANATURE + if (section_type < AOT_SECTION_TYPE_SIGNATURE || section_type == AOT_SECTION_TYPE_CUSTOM) { read_uint32(p, p_end, section_size); CHECK_BUF(p, p_end, section_size); diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index f34decb5e..a0d7f1088 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1119,7 +1119,7 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module, #if defined(BUILD_TARGET_XTENSA) /* * For Xtensa XIP, real func_count is doubled, including aot_func and - * aot_func_internal, so need to multipy func_count by 2 here. + * aot_func_internal, so need to multiply func_count by 2 here. */ if (module->is_indirect_mode) { func_count *= 2; @@ -1166,7 +1166,7 @@ init_func_type_indexes(AOTModuleInstance *module_inst, AOTModule *module, #if defined(BUILD_TARGET_XTENSA) /* * For Xtensa XIP, real func_count is doubled, including aot_func and - * aot_func_internal, so need to multipy func_count by 2 here. + * aot_func_internal, so need to multiply func_count by 2 here. */ if (module->is_indirect_mode) { func_count *= 2; @@ -1394,7 +1394,7 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst, } #endif - /* Execute start function for both main insance and sub instance */ + /* Execute start function for both main instance and sub instance */ if (module->start_function) { AOTFunctionInstance start_func = { 0 }; uint32 func_type_idx; @@ -2221,8 +2221,8 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, #if WASM_ENABLE_AOT_STACK_FRAME != 0 /* Free all frames allocated, note that some frames - may be allocated in AOT code and havent' been - freed if exception occured */ + may be allocated in AOT code and haven't been + freed if exception occurred */ while (exec_env->cur_frame != prev_frame) aot_free_frame(exec_env); #endif @@ -2291,8 +2291,8 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, #if WASM_ENABLE_AOT_STACK_FRAME != 0 /* Free all frames allocated, note that some frames - may be allocated in AOT code and havent' been - freed if exception occured */ + may be allocated in AOT code and haven't been + freed if exception occurred */ while (exec_env->cur_frame != prev_frame) aot_free_frame(exec_env); #endif @@ -4296,7 +4296,7 @@ aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf, LLVMProfileData_64 *prof_data_64 = (LLVMProfileData_64 *)buf; /* Convert LLVMProfileData to LLVMProfileData_64, the pointer width - in the output file is alawys 8 bytes */ + in the output file is always 8 bytes */ prof_data = (LLVMProfileData *)module->data_sections[i].data; prof_data_64->func_md5 = prof_data->func_md5; prof_data_64->func_hash = prof_data->func_hash; diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index 63f8c872a..0dbf9a5ea 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -43,7 +43,7 @@ typedef enum AOTSectionType { AOT_SECTION_TYPE_FUNCTION = 3, AOT_SECTION_TYPE_EXPORT = 4, AOT_SECTION_TYPE_RELOCATION = 5, - AOT_SECTION_TYPE_SIGANATURE = 6, + AOT_SECTION_TYPE_SIGNATURE = 6, AOT_SECTION_TYPE_CUSTOM = 100, } AOTSectionType; @@ -420,7 +420,7 @@ typedef struct LLVMProfileData { uint16 num_value_sites[2]; } LLVMProfileData; -/* The profiling data for writting to the output file, the width of +/* The profiling data for writing to the output file, the width of pointer is 8 bytes suppose we always use wamrc and llvm-profdata with 64-bit mode */ typedef struct LLVMProfileData_64 { diff --git a/core/iwasm/common/gc/gc_object.h b/core/iwasm/common/gc/gc_object.h index 2d1336881..75fdbef5d 100644 --- a/core/iwasm/common/gc/gc_object.h +++ b/core/iwasm/common/gc/gc_object.h @@ -13,7 +13,7 @@ extern "C" { #endif /** - * Object header of a WASM object, as the adddress of allocated memory + * Object header of a WASM object, as the address of allocated memory * must be 8-byte aligned, the lowest 3 bits are zero, we use them to * mark the object: * bits[0] is 1: the object is an externref object @@ -85,7 +85,7 @@ typedef struct WASMArrayObject { /* Must be pointer of WASMRttObject of array type */ WASMObjectHeader header; /* ( << 2) | , - * elem_count = lenght >> 2 + * elem_count = length >> 2 * elem_size = 2 ^ (length & 0x3) */ uint32 length; diff --git a/core/iwasm/common/wasm_application.c b/core/iwasm/common/wasm_application.c index f19cb00e4..b7e64460a 100644 --- a/core/iwasm/common/wasm_application.c +++ b/core/iwasm/common/wasm_application.c @@ -127,7 +127,7 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) #if WASM_ENABLE_THREAD_MGR != 0 if (ret) { /* On a successful return from the `_start` function, - we terminate other threads by mimicing wasi:proc_exit(0). + we terminate other threads by mimicking wasi:proc_exit(0). Note: - A return from the `main` function is an equivalent of @@ -516,11 +516,11 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, case VALUE_TYPE_V128: { /* it likes 0x123\0x234 or 123\234 */ - /* retrive first i64 */ + /* retrieve first i64 */ *(uint64 *)(argv1 + p) = strtoull(argv[i], &endptr, 0); /* skip \ */ endptr++; - /* retrive second i64 */ + /* retrieve second i64 */ *(uint64 *)(argv1 + p + 2) = strtoull(endptr, &endptr, 0); p += 4; break; diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 456ce505e..9005d711e 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -536,7 +536,7 @@ search_thread_local_store_num(Vector *stores_by_tid, korp_tid tid, #endif static unsigned -retrive_thread_local_store_num(Vector *stores_by_tid, korp_tid tid) +retrieve_thread_local_store_num(Vector *stores_by_tid, korp_tid tid) { #ifndef os_thread_local_attribute unsigned i = 0; @@ -664,8 +664,8 @@ wasm_store_new(wasm_engine_t *engine) if (!engine || singleton_engine != engine) return NULL; - if (!retrive_thread_local_store_num(&engine->stores_by_tid, - os_self_thread())) { + if (!retrieve_thread_local_store_num(&engine->stores_by_tid, + os_self_thread())) { if (!wasm_runtime_init_thread_env()) { LOG_ERROR("init thread environment failed"); return NULL; @@ -734,8 +734,8 @@ wasm_store_delete(wasm_store_t *store) if (decrease_thread_local_store_num(&singleton_engine->stores_by_tid, os_self_thread())) { - if (!retrive_thread_local_store_num(&singleton_engine->stores_by_tid, - os_self_thread())) { + if (!retrieve_thread_local_store_num(&singleton_engine->stores_by_tid, + os_self_thread())) { wasm_runtime_destroy_thread_env(); } } @@ -2263,7 +2263,7 @@ wasm_module_new_ex(wasm_store_t *store, const wasm_byte_vec_t *binary, result = result || (pkg_type == Wasm_Module_AoT); #endif if (!result) { - LOG_VERBOSE("current building isn't compatiable with the module," + LOG_VERBOSE("current building isn't compatible with the module," "may need recompile"); goto quit; } @@ -3386,7 +3386,7 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params, } } - /* copy parametes */ + /* copy parameters */ if (param_count && !params_to_argv(params, wasm_functype_params(func->type), argv, &argc)) { diff --git a/core/iwasm/common/wasm_c_api_internal.h b/core/iwasm/common/wasm_c_api_internal.h index 3967bb274..49a17a964 100644 --- a/core/iwasm/common/wasm_c_api_internal.h +++ b/core/iwasm/common/wasm_c_api_internal.h @@ -71,7 +71,7 @@ struct wasm_memorytype_t { struct wasm_externtype_t { uint32 extern_kind; - /* reservered space */ + /* reserved space */ uint8 data[1]; }; @@ -205,7 +205,7 @@ struct wasm_extern_t { wasm_name_t *module_name; wasm_name_t *name; wasm_externkind_t kind; - /* reservered space */ + /* reserved space */ uint8 data[1]; }; diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index 373ac463b..7128b4c63 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -202,7 +202,7 @@ wasm_exec_env_destroy(WASMExecEnv *exec_env) wasm_cluster_wait_for_all_except_self(cluster, exec_env); #if WASM_ENABLE_DEBUG_INTERP != 0 /* Must fire exit event after other threads exits, otherwise - the stopped thread will be overrided by other threads */ + the stopped thread will be overriden by other threads */ wasm_cluster_thread_exited(exec_env); #endif /* We have waited for other threads, this is the only alive thread, so diff --git a/core/iwasm/common/wasm_native.c b/core/iwasm/common/wasm_native.c index 394dfd2b5..7f2c6f8e8 100644 --- a/core/iwasm/common/wasm_native.c +++ b/core/iwasm/common/wasm_native.c @@ -71,7 +71,7 @@ uint32 get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis); static bool -compare_type_with_signautre(uint8 type, const char signature) +compare_type_with_signature(uint8 type, const char signature) { const char num_sig_map[] = { 'F', 'f', 'I', 'i' }; @@ -122,10 +122,10 @@ check_symbol_signature(const WASMFuncType *type, const char *signature) sig = *p++; /* a f64/f32/i64/i32/externref parameter */ - if (compare_type_with_signautre(type->types[i], sig)) + if (compare_type_with_signature(type->types[i], sig)) continue; - /* a pointer/string paramter */ + /* a pointer/string parameter */ if (type->types[i] != VALUE_TYPE_I32) /* pointer and string must be i32 type */ return false; @@ -156,7 +156,7 @@ check_symbol_signature(const WASMFuncType *type, const char *signature) return false; /* result types includes: f64,f32,i64,i32,externref */ - if (!compare_type_with_signautre(type->types[i], *p)) + if (!compare_type_with_signature(type->types[i], *p)) return false; p++; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index fe5b2baed..cfbbdd7ef 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -922,7 +922,7 @@ wasm_runtime_is_xip_file(const uint8 *buf, uint32 size) read_uint16(p, p_end, e_type); return (e_type == E_TYPE_XIP) ? true : false; } - else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) { + else if (section_type >= AOT_SECTION_TYPE_SIGNATURE) { return false; } p += section_size; @@ -1034,7 +1034,7 @@ wasm_runtime_register_module_internal(const char *module_name, } } else { - /* module has empyt name, reset it */ + /* module has empty name, reset it */ node->module_name = module_name; return true; } @@ -2150,7 +2150,7 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env, bh_assert((argv && ret_argv) || (argc == 0)); if (argv == ret_argv) { - /* no need to transfrom externref results */ + /* no need to transform externref results */ return true; } @@ -2823,7 +2823,7 @@ void wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst, bool enable) { - /* Alwary disable bounds checks if hw bounds checks enabled */ + /* Always disable bounds checks if hw bounds checks is enabled */ #ifdef OS_ENABLE_HW_BOUND_CHECK enable = false; #endif @@ -5892,7 +5892,7 @@ wasm_externref_ref2obj(uint32 externref_idx, void **p_extern_obj) { ExternRefMapNode *node; - /* catch a `ref.null` vairable */ + /* catch a `ref.null` variable */ if (externref_idx == NULL_REF) { *p_extern_obj = NULL; return true; @@ -6866,7 +6866,7 @@ wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module, goto delete_loading_module; } if (get_package_type(buffer, buffer_size) != parent_module->module_type) { - LOG_DEBUG("moudle %s type error", sub_module_name); + LOG_DEBUG("module %s type error", sub_module_name); goto destroy_file_buffer; } @@ -7130,7 +7130,7 @@ wasm_runtime_detect_native_stack_overflow(WASMExecEnv *exec_env) uint8 *boundary = exec_env->native_stack_boundary; RECORD_STACK_USAGE(exec_env, (uint8 *)&boundary); if (boundary == NULL) { - /* the platfrom doesn't support os_thread_get_stack_boundary */ + /* the platform doesn't support os_thread_get_stack_boundary */ return true; } #if defined(OS_ENABLE_HW_BOUND_CHECK) && WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 @@ -7153,7 +7153,7 @@ wasm_runtime_detect_native_stack_overflow_size(WASMExecEnv *exec_env, uint8 *boundary = exec_env->native_stack_boundary; RECORD_STACK_USAGE(exec_env, (uint8 *)&boundary); if (boundary == NULL) { - /* the platfrom doesn't support os_thread_get_stack_boundary */ + /* the platform doesn't support os_thread_get_stack_boundary */ return true; } #if defined(OS_ENABLE_HW_BOUND_CHECK) && WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index abaa33011..dc41f72dd 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -909,7 +909,7 @@ WASMExport * loader_find_export(const WASMModuleCommon *module, const char *module_name, const char *field_name, uint8 export_kind, char *error_buf, uint32 error_buf_size); -#endif /* WASM_ENALBE_MULTI_MODULE */ +#endif /* WASM_ENABLE_MULTI_MODULE */ bool wasm_runtime_is_built_in_module(const char *module_name); diff --git a/core/iwasm/compilation/aot_emit_aot_file.c b/core/iwasm/compilation/aot_emit_aot_file.c index 426171984..28b059683 100644 --- a/core/iwasm/compilation/aot_emit_aot_file.c +++ b/core/iwasm/compilation/aot_emit_aot_file.c @@ -3090,7 +3090,7 @@ aot_resolve_target_info(AOTCompContext *comp_ctx, AOTObjectData *obj_data) && bin_type != LLVMBinaryTypeMachO32B && bin_type != LLVMBinaryTypeMachO64L && bin_type != LLVMBinaryTypeMachO64B) { - aot_set_last_error("invaid llvm binary bin_type."); + aot_set_last_error("invalid llvm binary bin_type."); return false; } @@ -3166,13 +3166,13 @@ aot_resolve_target_info(AOTCompContext *comp_ctx, AOTObjectData *obj_data) else if (bin_type == LLVMBinaryTypeMachO32L || bin_type == LLVMBinaryTypeMachO32B) { /* TODO: parse file type of Mach-O 32 */ - aot_set_last_error("invaid llvm binary bin_type."); + aot_set_last_error("invalid llvm binary bin_type."); return false; } else if (bin_type == LLVMBinaryTypeMachO64L || bin_type == LLVMBinaryTypeMachO64B) { /* TODO: parse file type of Mach-O 64 */ - aot_set_last_error("invaid llvm binary bin_type."); + aot_set_last_error("invalid llvm binary bin_type."); return false; } diff --git a/core/iwasm/compilation/simd/simd_conversions.c b/core/iwasm/compilation/simd/simd_conversions.c index 042e28089..afa6d4722 100644 --- a/core/iwasm/compilation/simd/simd_conversions.c +++ b/core/iwasm/compilation/simd/simd_conversions.c @@ -261,7 +261,7 @@ simd_integer_extension(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - /* retrive the low or high half */ + /* retrieve the low or high half */ if (!(sub_vector = LLVMBuildShuffleVector(comp_ctx->builder, vector, undef[itype], mask, "half"))) { HANDLE_FAILURE("LLVMBuildShuffleVector"); diff --git a/core/iwasm/include/gc_export.h b/core/iwasm/include/gc_export.h index a9cdd148f..a9f65448e 100644 --- a/core/iwasm/include/gc_export.h +++ b/core/iwasm/include/gc_export.h @@ -707,7 +707,7 @@ wasm_externref_obj_to_internal_obj(const wasm_externref_obj_t externref_obj); * @param exec_env the execution environment * @param internal_obj the internal object * - * @return wasm_externref_obj_t if create success, NULL othersise + * @return wasm_externref_obj_t if create success, NULL otherwise */ WASM_RUNTIME_API_EXTERN wasm_externref_obj_t wasm_internal_obj_to_externref_obj(wasm_exec_env_t exec_env, @@ -757,7 +757,7 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_unpin_object(wasm_exec_env_t exec_env, wasm_obj_t obj); /** - * Check whether an object is a struct objectc + * Check whether an object is a struct object * * @param obj the object to check * diff --git a/core/iwasm/include/wasm_c_api.h b/core/iwasm/include/wasm_c_api.h index 63d18f3ae..873913edf 100644 --- a/core/iwasm/include/wasm_c_api.h +++ b/core/iwasm/include/wasm_c_api.h @@ -96,7 +96,7 @@ typedef double float64_t; // Vectors // size: capacity // num_elems: current number of elements -// size_of_elem: size of one elemen +// size_of_elem: size of one element #define WASM_DECLARE_VEC(name, ptr_or_none) \ typedef struct wasm_##name##_vec_t { \ size_t size; \ @@ -183,7 +183,7 @@ typedef union MemAllocOption { } MemAllocOption; #endif /* MEM_ALLOC_OPTION_DEFINED */ -/* Runtime configration */ +/* Runtime configuration */ struct wasm_config_t { mem_alloc_type_t mem_alloc_type; MemAllocOption mem_alloc_option; diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 024c1eda3..03c0e2fbe 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -428,7 +428,7 @@ wasm_runtime_register_module(const char *module_name, wasm_module_t module, /** * Check if there is already a loaded module named module_name in the - * runtime. Repeately loading a module with the same name is not allowed. + * runtime. Repeatedly loading a module with the same name is not allowed. * * @param module_name indicate a name * @@ -451,7 +451,7 @@ wasm_runtime_find_module_registered(const char *module_name); * @param buf the byte buffer which contains the WASM/AOT binary data, * note that the byte buffer must be writable since runtime may * change its content for footprint and performance purpose, and - * it must be referencable until wasm_runtime_unload is called + * it must be referenceable until wasm_runtime_unload is called * @param size the size of the buffer * @param error_buf output of the exception info * @param error_buf_size the size of the exception string @@ -921,7 +921,7 @@ wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env, * @param exec_env the execution environment to call the function * which must be created from wasm_create_exec_env() * @param element_index the function reference index, usually - * prvovided by the caller of a registed native function + * provided by the caller of a registered native function * @param argc the number of arguments * @param argv the arguments. If the function method has return value, * the first (or first two in case 64-bit return value) element of @@ -1169,7 +1169,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst, * stable.) * * @param module_inst the WASM module instance - * @param app_offset the app adress + * @param app_offset the app address * * @return the native address converted */ @@ -1439,7 +1439,7 @@ WASM_RUNTIME_API_EXTERN double wasm_runtime_sum_wasm_exec_time(wasm_module_inst_t module_inst); /** - * Return execution time in ms of a given wasm funciton with + * Return execution time in ms of a given wasm function with * func_name. If the function is not found, return 0. * * @param module_inst the WASM module instance to profile @@ -1706,7 +1706,7 @@ wasm_runtime_set_enlarge_mem_error_callback( * to all threads in the cluster. * It's an undefined behavior if multiple threads in a cluster call * wasm_runtime_set_context_spread on the same key - * simultaneously. It's a caller's resposibility to perform necessary + * simultaneously. It's a caller's responsibility to perform necessary * serialization if necessary. For example: * * if (wasm_runtime_get_context(inst, key) == NULL) { @@ -1726,7 +1726,7 @@ wasm_runtime_set_enlarge_mem_error_callback( * * Note: dynamic key create/destroy while instances are live is not * implemented as of writing this. - * it's caller's resposibility to ensure destorying all module instances + * it's caller's responsibility to ensure destroying all module instances * before calling wasm_runtime_create_context_key or * wasm_runtime_destroy_context_key. * otherwise, it's an undefined behavior. @@ -1787,7 +1787,7 @@ wasm_runtime_get_context(wasm_module_inst_t inst, void *key); * * The actual wake up mechanism used by `os_wakeup_blocking_op` is * platform-dependent. It might impose some platform-dependent restrictions - * on the implementation of the blocking opearation. + * on the implementation of the blocking operation. * * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is * used. The signal delivery configurations (eg. signal handler, signal mask, diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 5c436cbfa..26d57d409 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -85,8 +85,8 @@ extern "C" { /** * Used by wamr compiler to represent object ref types, * including func object ref, externref object ref, - * internal object ref, eq obect ref, i31 object ref, - * struct object ref, array obect ref + * internal object ref, eq object ref, i31 object ref, + * struct object ref, array object ref */ #define VALUE_TYPE_GC_REF 0x43 @@ -762,7 +762,7 @@ typedef struct WASIArguments { uint32 map_dir_count; const char **env; uint32 env_count; - /* in CIDR noation */ + /* in CIDR notation */ const char **addr_pool; uint32 addr_count; const char **ns_lookup_pool; @@ -1021,7 +1021,7 @@ struct WASMModule { /** * func pointers of LLVM JITed (un-imported) functions * for non Multi-Tier JIT mode: - * each pointer is set to the lookuped llvm jit func ptr, note that it + * each pointer is set to the looked up llvm jit func ptr, note that it * is a stub and will trigger the actual compilation when it is called * for Multi-Tier JIT mode: * each pointer is inited as call_to_fast_jit code block, when the llvm diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index a17d07327..fd290afa5 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1355,7 +1355,7 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, } } - /* Execute start function for both main insance and sub instance */ + /* Execute start function for both main instance and sub instance */ if (start_func && !wasm_call_function(exec_env, start_func, 0, NULL)) { goto fail; } @@ -2022,7 +2022,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, * (module->import_memory_count + module->memory_count); #if WASM_ENABLE_JIT != 0 - /* If the module dosen't have memory, reserve one mem_info space + /* If the module doesn't have memory, reserve one mem_info space with empty content to align with llvm jit compiler */ if (module_inst_mem_inst_size == 0) module_inst_mem_inst_size = (uint64)sizeof(WASMMemoryInstance); @@ -3791,13 +3791,13 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst, mem_conspn->app_heap_size += memory->heap_data_end - memory->heap_data; /* size of app heap structure */ mem_conspn->memories_size += mem_allocator_get_heap_struct_size(); - /* Module instance structures have been appened into the end of + /* Module instance structures have been appended into the end of module instance */ } mem_conspn->tables_size = sizeof(WASMTableInstance *) * module_inst->table_count; - /* Table instance structures and table elements have been appened into + /* Table instance structures and table elements have been appended into the end of module instance */ mem_conspn->functions_size = @@ -3805,7 +3805,7 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst, mem_conspn->globals_size = sizeof(WASMGlobalInstance) * module_inst->e->global_count; - /* Global data has been appened into the end of module instance */ + /* Global data has been appended into the end of module instance */ mem_conspn->exports_size = sizeof(WASMExportFuncInstance) * module_inst->export_func_count; diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.c b/core/iwasm/libraries/thread-mgr/thread_manager.c index ac4deb92c..ebb56ba7c 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -1194,7 +1194,7 @@ wait_for_thread_visitor(void *node, void *user_data) } void -wams_cluster_wait_for_all(WASMCluster *cluster) +wasm_cluster_wait_for_all(WASMCluster *cluster) { os_mutex_lock(&cluster->lock); cluster->processing = true; diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.h b/core/iwasm/libraries/thread-mgr/thread_manager.h index ee2383a33..0cbba888f 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.h +++ b/core/iwasm/libraries/thread-mgr/thread_manager.h @@ -45,7 +45,7 @@ struct WASMCluster { * requests. This is a short-lived state, must be cleared immediately once * the processing finished. * This is used to avoid dead lock when one thread waiting another thread - * with lock, see wams_cluster_wait_for_all and wasm_cluster_terminate_all + * with lock, see wasm_cluster_wait_for_all and wasm_cluster_terminate_all */ bool processing; #if WASM_ENABLE_DEBUG_INTERP != 0 @@ -135,7 +135,7 @@ wasm_cluster_terminate_all_except_self(WASMCluster *cluster, WASMExecEnv *exec_env); void -wams_cluster_wait_for_all(WASMCluster *cluster); +wasm_cluster_wait_for_all(WASMCluster *cluster); void wasm_cluster_wait_for_all_except_self(WASMCluster *cluster, diff --git a/core/shared/utils/bh_log.c b/core/shared/utils/bh_log.c index 1ffd9b764..a73c24deb 100644 --- a/core/shared/utils/bh_log.c +++ b/core/shared/utils/bh_log.c @@ -7,7 +7,7 @@ /** * The verbose level of the log system. Only those verbose logs whose - * levels are less than or equal to this value are outputed. + * levels are less than or equal to this value are output. */ static uint32 log_verbose_level = BH_LOG_LEVEL_WARNING; diff --git a/language-bindings/python/wasm-c-api/docs/design.md b/language-bindings/python/wasm-c-api/docs/design.md index 78bf56df0..a952731d2 100644 --- a/language-bindings/python/wasm-c-api/docs/design.md +++ b/language-bindings/python/wasm-c-api/docs/design.md @@ -70,11 +70,11 @@ Create a corresponding concept for every native structured data type includes #### Enum types -For example, if there is a `enum wams_mutability_enum` in native. +For example, if there is a `enum wasm_mutability_enum` in native. ```c -typedef uint8_t wams_mutability_t; -enum wams_mutability_enum { +typedef uint8_t wasm_mutability_t; +enum wasm_mutability_enum { WASM_CONST, WASM_VAR }; @@ -83,7 +83,7 @@ enum wams_mutability_enum { Use `ctypes.int`(or any integer types in ctypes) to represents its value directly. ```python -# represents enum wams_mutability_enum +# represents enum wasm_mutability_enum wasm_mutability_t = c_uint8 WASM_CONST = 0 diff --git a/product-mini/README.md b/product-mini/README.md index 18813bef5..1e7a1f3cf 100644 --- a/product-mini/README.md +++ b/product-mini/README.md @@ -2,7 +2,7 @@ iwasm is the executable binary built with WAMR VMcore supports WASI and command line interface. Refer to [**how to build wamr vmcore**](../doc/build_wamr.md) for all the supported CMAKE compilation variables. -If you are building for ARM architecture on a X86 development machine, you can use the `CMAKE_TOOLCHAIN_FILE` to set the toolchain file for cross compling. +If you are building for ARM architecture on a X86 development machine, you can use the `CMAKE_TOOLCHAIN_FILE` to set the toolchain file for cross compiling. ``` cmake .. -DCMAKE_TOOLCHAIN_FILE=$TOOL_CHAIN_FILE \ diff --git a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp index 27e12d378..91f03a979 100644 --- a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp +++ b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp @@ -157,7 +157,7 @@ align_ptr(const uint8 *p, uint32 b) } #define AOT_SECTION_TYPE_TARGET_INFO 0 -#define AOT_SECTION_TYPE_SIGANATURE 6 +#define AOT_SECTION_TYPE_SIGNATURE 6 #define E_TYPE_XIP 4 #define CHECK_BUF(buf, buf_end, length) \ @@ -205,7 +205,7 @@ is_xip_file(const uint8 *buf, uint32 size) read_uint16(p, p_end, e_type); return (e_type == E_TYPE_XIP) ? true : false; } - else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) { + else if (section_type >= AOT_SECTION_TYPE_SIGNATURE) { return false; } p += section_size; diff --git a/product-mini/platforms/posix/main.c b/product-mini/platforms/posix/main.c index cb0581ce2..e4a9404bd 100644 --- a/product-mini/platforms/posix/main.c +++ b/product-mini/platforms/posix/main.c @@ -429,7 +429,7 @@ module_reader_callback(package_type_t module_type, const char *module_name, } static void -moudle_destroyer(uint8 *buffer, uint32 size) +module_destroyer_callback(uint8 *buffer, uint32 size) { if (!buffer) { return; @@ -906,7 +906,8 @@ main(int argc, char *argv[]) #endif #if WASM_ENABLE_MULTI_MODULE != 0 - wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer); + wasm_runtime_set_module_reader(module_reader_callback, + module_destroyer_callback); #endif /* load WASM module */ diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index 35a489721..f51c9dcc5 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -246,7 +246,7 @@ module_reader_callback(package_type_t module_type, const char *module_name, } static void -moudle_destroyer(uint8 *buffer, uint32 size) +module_destroyer_callback(uint8 *buffer, uint32 size) { if (!buffer) { return; @@ -506,7 +506,8 @@ main(int argc, char *argv[]) #endif #if WASM_ENABLE_MULTI_MODULE != 0 - wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer); + wasm_runtime_set_module_reader(module_reader_callback, + module_destroyer_callback); #endif /* load WASM module */ diff --git a/samples/multi-module/src/main.c b/samples/multi-module/src/main.c index c63cf6b8c..29b623daa 100644 --- a/samples/multi-module/src/main.c +++ b/samples/multi-module/src/main.c @@ -38,7 +38,7 @@ module_reader_callback(package_type_t module_type, const char *module_name, } static void -moudle_destroyer(uint8 *buffer, uint32 size) +module_destroyer_callback(uint8 *buffer, uint32 size) { if (!buffer) { return; @@ -89,7 +89,8 @@ main(int argc, char *argv[]) #if WASM_ENABLE_MULTI_MODULE != 0 printf("- wasm_runtime_set_module_reader\n"); /* set module reader and destroyer */ - wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer); + wasm_runtime_set_module_reader(module_reader_callback, + module_destroyer_callback); #endif /* load WASM byte buffer from WASM bin file */ @@ -163,7 +164,7 @@ UNLOAD_MODULE: printf("- wasm_runtime_unload\n"); wasm_runtime_unload(module); RELEASE_BINARY: - moudle_destroyer(file_buf, file_buf_size); + module_destroyer_callback(file_buf, file_buf_size); RELEASE_RUNTIME: printf("- wasm_runtime_destroy\n"); wasm_runtime_destroy(); diff --git a/samples/wasm-c-api/src/clone.c b/samples/wasm-c-api/src/clone.c index da83b3790..7759afee4 100644 --- a/samples/wasm-c-api/src/clone.c +++ b/samples/wasm-c-api/src/clone.c @@ -181,13 +181,13 @@ vm_clone_from_instance(const wasm_vm_t *base) { /** * if do a clone of the level instantiated_module, need to malloc and - * initialie - * - global. WASMGlobalIntance and global data - * - memory. WAAMMemoryInstance, memory_data and heap + * initialize + * - global. WASMGlobalInstance and global data + * - memory. WASMMemoryInstance, memory_data and heap * - table. WASMTableInstance, table_data * - exports. all global, memory and table * - * it is almost everything in wasm_instantiate() except funciton. + * it is almost everything in wasm_instantiate() except function. */ (void)base; printf("Unsupported\n"); From 1c2a8fca4e9bf969ae27240a0918ee8164dfd598 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 7 May 2024 18:30:29 -0700 Subject: [PATCH 007/198] Fix some more spelling issues (#3393) --- .github/workflows/build_iwasm_release.yml | 2 +- .../compilation_on_android_ubuntu.yml | 6 +-- .github/workflows/compilation_on_macos.yml | 4 +- .github/workflows/compilation_on_sgx.yml | 2 +- .github/workflows/nightly_run.yml | 10 ++--- core/iwasm/aot/aot_intrinsic.c | 8 ++-- core/iwasm/common/wasm_shared_memory.c | 2 +- core/iwasm/compilation/aot_compiler.c | 6 +-- core/iwasm/compilation/aot_emit_function.c | 2 +- core/iwasm/compilation/aot_emit_gc.c | 2 +- core/iwasm/compilation/aot_emit_memory.c | 4 +- core/iwasm/compilation/aot_emit_numberic.c | 2 +- core/iwasm/compilation/aot_emit_table.c | 2 +- core/iwasm/compilation/aot_llvm.c | 2 +- core/iwasm/compilation/aot_llvm.h | 4 +- core/iwasm/compilation/aot_orc_extra.cpp | 2 +- core/iwasm/compilation/aot_orc_extra.h | 2 +- core/iwasm/compilation/aot_orc_extra2.cpp | 2 +- .../compilation/debug/dwarf_extractor.cpp | 32 +++++++------- .../compilation/simd/simd_access_lanes.c | 4 +- .../compilation/simd/simd_bitmask_extracts.c | 2 +- .../iwasm/compilation/simd/simd_comparisons.c | 12 +++--- .../iwasm/compilation/simd/simd_conversions.c | 6 +-- core/iwasm/doc/wasm_function.MD | 28 ++++++------- core/iwasm/interpreter/wasm_interp_classic.c | 10 ++--- core/iwasm/interpreter/wasm_loader.c | 42 +++++++++---------- core/iwasm/interpreter/wasm_mini_loader.c | 2 +- core/iwasm/interpreter/wasm_opcode.h | 4 +- doc/build_wamr.md | 8 ++-- doc/embed_wamr.md | 4 +- doc/export_native_api.md | 32 +++++++------- doc/memory_usage.md | 2 +- doc/pthread_library.md | 2 +- doc/semantic_version.md | 2 +- doc/source_debugging.md | 4 +- doc/wasm_c_api.md | 2 +- samples/wasm-c-api/src/callback_chain.c | 6 +-- 37 files changed, 134 insertions(+), 134 deletions(-) diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index 86e50ede9..887020853 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -11,7 +11,7 @@ on: required: false default: x86_64 cwd: - description: workfing directory + description: working directory type: string required: true llvm_cache_key: diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 21437ffc0..e0c9326b5 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -150,8 +150,8 @@ jobs: os: [ubuntu-22.04] platform: [android, linux] exclude: - # uncompatiable feature and platform - # uncompatiable mode and feature + # incompatible feature and platform + # incompatible mode and feature # MULTI_MODULE only on INTERP mode and AOT mode - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1" @@ -542,7 +542,7 @@ jobs: running_mode: aot test_option: $WAMR_COMPILER_TEST_OPTIONS exclude: - # uncompatiable modes and features + # incompatible modes and features # classic-interp and fast-interp don't support simd - running_mode: "classic-interp" test_option: $SIMD_TEST_OPTIONS diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index d9598a00b..3b92f4525 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -134,8 +134,8 @@ jobs: os: [macos-13] platform: [darwin] exclude: - # uncompatiable feature and platform - # uncompatiable mode and feature + # incompatible feature and platform + # incompatible mode and feature # MULTI_MODULE only on INTERP mode and AOT mode - make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1" diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index 030c76524..a533e1839 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -99,7 +99,7 @@ jobs: os: [ubuntu-20.04] platform: [linux-sgx] exclude: - # uncompatiable mode and feature + # incompatible mode and feature # MINI_LOADER only on INTERP mode - make_options_run_mode: $AOT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 3e4e89caf..c99175a4f 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -135,8 +135,8 @@ jobs: os: [ubuntu-20.04] platform: [android, linux] exclude: - # uncompatiable feature and platform - # uncompatiable mode and feature + # incompatible feature and platform + # incompatible mode and feature # MULTI_MODULE only on INTERP mode and AOT mode - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1" @@ -290,8 +290,8 @@ jobs: "-DWAMR_BUILD_MEMORY64=1", ] exclude: - # uncompatiable feature and platform - # uncompatiable mode and feature + # incompatible feature and platform + # incompatible mode and feature # MULTI_MODULE only on INTERP mode and AOT mode - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1" @@ -619,7 +619,7 @@ jobs: ubuntu_version: "22.04" exclude: - # uncompatiable modes and features + # incompatible modes and features - os: ubuntu-20.04 sanitizer: tsan # asan works only for aot now diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index 7b455cbb0..245c7a651 100644 --- a/core/iwasm/aot/aot_intrinsic.c +++ b/core/iwasm/aot/aot_intrinsic.c @@ -685,7 +685,7 @@ add_f64xi64_intrinsics(AOTCompContext *comp_ctx) } static void -add_common_float_integer_convertion(AOTCompContext *comp_ctx) +add_common_float_integer_conversion(AOTCompContext *comp_ctx) { add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_TO_F32); add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U32_TO_F32); @@ -851,7 +851,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) add_f32_common_intrinsics(comp_ctx); add_f64_common_intrinsics(comp_ctx); add_i64_common_intrinsics(comp_ctx); - add_common_float_integer_convertion(comp_ctx); + add_common_float_integer_conversion(comp_ctx); } } else if (!strncmp(comp_ctx->target_arch, "riscv", 5)) { @@ -862,7 +862,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) */ add_f32_common_intrinsics(comp_ctx); add_f64_common_intrinsics(comp_ctx); - add_common_float_integer_convertion(comp_ctx); + add_common_float_integer_conversion(comp_ctx); if (!strncmp(comp_ctx->target_arch, "riscv32", 7)) { add_i64_common_intrinsics(comp_ctx); } @@ -876,7 +876,7 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) add_i32_common_intrinsics(comp_ctx); add_f64_common_intrinsics(comp_ctx); add_i64_common_intrinsics(comp_ctx); - add_common_float_integer_convertion(comp_ctx); + add_common_float_integer_conversion(comp_ctx); add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST); add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST); diff --git a/core/iwasm/common/wasm_shared_memory.c b/core/iwasm/common/wasm_shared_memory.c index 3856b7d19..9cfdd0926 100644 --- a/core/iwasm/common/wasm_shared_memory.c +++ b/core/iwasm/common/wasm_shared_memory.c @@ -333,7 +333,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, while (1) { if (timeout < 0) { - /* wait forever until it is notified or terminatied + /* wait forever until it is notified or terminated here we keep waiting and checking every second */ os_cond_reltimedwait(&wait_node->wait_cond, lock, (uint64)timeout_1sec); diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 5c257742a..694307aeb 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -3966,7 +3966,7 @@ aot_compile_wasm(AOTCompContext *comp_ctx) orc_main_dylib = LLVMOrcLLLazyJITGetMainJITDylib(comp_ctx->orc_jit); if (!orc_main_dylib) { aot_set_last_error( - "failed to get orc orc_jit main dynmaic library"); + "failed to get orc orc_jit main dynamic library"); return false; } @@ -4191,7 +4191,7 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) /* * move the temporary .su file to the specified location. * - * Note: the former is automatimally inferred from the output + * Note: the former is automatically inferred from the output * filename (file_name here) by clang. * * Note: the latter might be user-specified. @@ -4247,7 +4247,7 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) #endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */ if (!strncmp(LLVMGetTargetName(target), "arc", 3)) - /* Emit to assmelby file instead for arc target + /* Emit to assembly file instead for arc target as it cannot emit to object file */ file_type = LLVMAssemblyFile; diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index cf3824e9a..8f6e3e456 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2125,7 +2125,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (!(table_size_const = LLVMBuildBitCast(comp_ctx->builder, table_size_const, - INT32_PTR_TYPE, "cur_siuze_i32p"))) { + INT32_PTR_TYPE, "cur_size_i32p"))) { HANDLE_FAILURE("LLVMBuildBitCast"); goto fail; } diff --git a/core/iwasm/compilation/aot_emit_gc.c b/core/iwasm/compilation/aot_emit_gc.c index 55f14710f..7bd7affc3 100644 --- a/core/iwasm/compilation/aot_emit_gc.c +++ b/core/iwasm/compilation/aot_emit_gc.c @@ -569,7 +569,7 @@ aot_compile_op_struct_new(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, SET_BUILDER_POS(check_struct_obj_succ); - /* For WASM_OP_STRUCT_NEW, init filed with poped value */ + /* For WASM_OP_STRUCT_NEW, init field with poped value */ if (!init_with_default && !struct_new_canon_init_fields(comp_ctx, func_ctx, type_index, struct_obj)) { diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 4f741effe..4582cdd0a 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -145,7 +145,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, * Note: not throw the integer-overflow-exception here since it must * have been thrown when converting float to integer before */ - /* return addres directly if constant offset and inside memory space */ + /* return address directly if constant offset and inside memory space */ if (LLVMIsEfficientConstInt(addr)) { uint64 mem_offset = (uint64)LLVMConstIntGetZExtValue(addr) + (uint64)offset; @@ -1410,7 +1410,7 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx, LLVMSetVolatile(result, true); /* CmpXchg return {i32, i1} structure, - we need to extrack the previous_value from the structure */ + we need to extract the previous_value from the structure */ if (!(result = LLVMBuildExtractValue(comp_ctx->builder, result, 0, "previous_value"))) { goto fail; diff --git a/core/iwasm/compilation/aot_emit_numberic.c b/core/iwasm/compilation/aot_emit_numberic.c index 8b6ec02d6..acd2645b7 100644 --- a/core/iwasm/compilation/aot_emit_numberic.c +++ b/core/iwasm/compilation/aot_emit_numberic.c @@ -554,7 +554,7 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } else { - /* Check divied by zero */ + /* Check divided by zero */ LLVM_BUILD_ICMP(LLVMIntEQ, right, is_i32 ? I32_ZERO : I64_ZERO, cmp_div_zero, "cmp_div_zero"); ADD_BASIC_BLOCK(check_div_zero_succ, "check_div_zero_success"); diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index 6ce3295fa..f968bacdd 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -147,7 +147,7 @@ aot_check_table_access(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } if (!(tbl_sz = LLVMBuildBitCast(comp_ctx->builder, tbl_sz, INT32_PTR_TYPE, - "cur_siuze_i32p"))) { + "cur_size_i32p"))) { HANDLE_FAILURE("LLVMBuildBitCast"); goto fail; } diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 9c3acf753..9889d034e 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2418,7 +2418,7 @@ orc_jit_create(AOTCompContext *comp_ctx) } if (comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation) - LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( + LLVMOrcLLJITBuilderSetCompileFunctionCreatorWithStackSizesCallback( builder, jit_stack_size_callback, comp_ctx); err = LLVMOrcJITTargetMachineBuilderDetectHost(&jtmb); diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index d30c56f7d..f412d482a 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -374,7 +374,7 @@ typedef struct AOTCompContext { char target_arch[16]; unsigned pointer_size; - /* Hardware intrinsic compability flags */ + /* Hardware intrinsic compatibility flags */ uint64 flags[8]; /* required by JIT */ @@ -441,7 +441,7 @@ typedef struct AOTCompContext { /* Use profile file collected by LLVM PGO */ char *use_prof_file; - /* Enable to use segument register as the base addr + /* Enable to use segment register as the base addr of linear memory for load/store operations */ bool enable_segue_i32_load; bool enable_segue_i64_load; diff --git a/core/iwasm/compilation/aot_orc_extra.cpp b/core/iwasm/compilation/aot_orc_extra.cpp index 90dafe097..4f7a55d94 100644 --- a/core/iwasm/compilation/aot_orc_extra.cpp +++ b/core/iwasm/compilation/aot_orc_extra.cpp @@ -203,7 +203,7 @@ PartitionFunction(GlobalValueSet Requested) * if the jit wrapper (which has "_wrapper" suffix in * the name) is requested, compile others in the group too. * otherwise, only compile the requested one. - * (and possibly the correspondig wrapped function, + * (and possibly the corresponding wrapped function, * which has AOT_FUNC_INTERNAL_PREFIX.) */ wrapper = strstr(gvname + prefix_len, "_wrapper"); diff --git a/core/iwasm/compilation/aot_orc_extra.h b/core/iwasm/compilation/aot_orc_extra.h index 32ece4de4..d94fd8c1b 100644 --- a/core/iwasm/compilation/aot_orc_extra.h +++ b/core/iwasm/compilation/aot_orc_extra.h @@ -72,7 +72,7 @@ LLVMOrcObjectTransformLayerRef LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J); void -LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( +LLVMOrcLLJITBuilderSetCompileFunctionCreatorWithStackSizesCallback( LLVMOrcLLLazyJITBuilderRef Builder, void (*cb)(void *, const char *, size_t, size_t), void *cb_data); diff --git a/core/iwasm/compilation/aot_orc_extra2.cpp b/core/iwasm/compilation/aot_orc_extra2.cpp index 515f7209f..180e54050 100644 --- a/core/iwasm/compilation/aot_orc_extra2.cpp +++ b/core/iwasm/compilation/aot_orc_extra2.cpp @@ -130,7 +130,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::LLLazyJITBuilder, LLVMOrcLLLazyJITBuilderRef) void -LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( +LLVMOrcLLJITBuilderSetCompileFunctionCreatorWithStackSizesCallback( LLVMOrcLLLazyJITBuilderRef Builder, void (*cb)(void *, const char *, size_t, size_t), void *cb_data) { diff --git a/core/iwasm/compilation/debug/dwarf_extractor.cpp b/core/iwasm/compilation/debug/dwarf_extractor.cpp index e2e515ba0..251bd696b 100644 --- a/core/iwasm/compilation/debug/dwarf_extractor.cpp +++ b/core/iwasm/compilation/debug/dwarf_extractor.cpp @@ -37,7 +37,7 @@ typedef struct dwarf_extractor { #define TO_HANDLE(extractor) (dwarf_extractor_handle_t)(extractor) -#define TO_EXTACTOR(handle) (dwarf_extractor *)(handle) +#define TO_EXTRACTOR(handle) (dwarf_extractor *)(handle) static bool is_debugger_initialized; @@ -103,7 +103,7 @@ fail3: void destroy_dwarf_extractor(dwarf_extractor_handle_t handle) { - dwarf_extractor *extractor = TO_EXTACTOR(handle); + dwarf_extractor *extractor = TO_EXTRACTOR(handle); if (!extractor) return; extractor->debugger.DeleteTarget(extractor->target); @@ -122,7 +122,7 @@ dwarf_gen_file_info(const AOTCompContext *comp_ctx) const char *file_name; const char *dir_name; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; units_number = extractor->module.GetNumCompileUnits(); @@ -198,7 +198,7 @@ dwarf_gen_comp_unit_info(const AOTCompContext *comp_ctx) int units_number; LLVMMetadataRef comp_unit = NULL; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; units_number = extractor->module.GetNumCompileUnits(); @@ -312,12 +312,12 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx, case eLanguageTypeC17: break; default: - LOG_WARNING("func %s has unsuppoted language_type 0x%x", + LOG_WARNING("func %s has unsupported language_type 0x%x", function_name, (int)language_type); return NULL; } - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; LLVMDIBuilderRef DIB = comp_ctx->debug_builder; @@ -389,7 +389,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx, function.GetBlock().GetVariables(extractor->target, true, false, false); if (num_function_args != variable_list.GetSize()) { LOG_ERROR( - "function args number dismatch!:value number=%d, function args=%d", + "function args number mismatch!:value number=%d, function args=%d", variable_list.GetSize(), num_function_args); } @@ -399,13 +399,13 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx, // TODO:change to void * or WasmExenv * ? LLVMMetadataRef voidtype = LLVMDIBuilderCreateBasicType(DIB, "void", 4, 0, 0, LLVMDIFlagZero); - LLVMMetadataRef voidpionter = + LLVMMetadataRef voidpointer = LLVMDIBuilderCreatePointerType(DIB, voidtype, 64, 0, 0, "void *", 6); LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable( DIB, FunctionMetadata, "exenv", 5, 1, File, // starts form 1, and 1 is exenv, - line_entry.GetLine(), voidpionter, true, LLVMDIFlagZero); + line_entry.GetLine(), voidpointer, true, LLVMDIFlagZero); LLVMValueRef Param = LLVMGetParam(func_ctx->func, 0); LLVMBasicBlockRef block_curr = LLVMGetEntryBasicBlock(func_ctx->func); LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar, ParamExpression, @@ -447,13 +447,13 @@ dwarf_gen_func_info(const AOTCompContext *comp_ctx, uint64_t vm_offset; AOTFunc *func = func_ctx->aot_func; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; // A code address in DWARF for WebAssembly is the offset of an // instruction relative within the Code section of the WebAssembly file. // For this reason Section::GetFileAddress() must return zero for the - // Code section. (refert to ObjectFileWasm.cpp) + // Code section. (refer to ObjectFileWasm.cpp) vm_offset = func->code - comp_ctx->comp_data->wasm_module->buf_code; auto sbaddr = extractor->target.ResolveFileAddress(vm_offset); @@ -479,13 +479,13 @@ dwarf_get_func_name(const AOTCompContext *comp_ctx, name[0] = '\0'; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return; // A code address in DWARF for WebAssembly is the offset of an // instruction relative within the Code section of the WebAssembly file. // For this reason Section::GetFileAddress() must return zero for the - // Code section. (refert to ObjectFileWasm.cpp) + // Code section. (refer to ObjectFileWasm.cpp) vm_offset = func->code - comp_ctx->comp_data->wasm_module->buf_code; auto sbaddr = extractor->target.ResolveFileAddress(vm_offset); @@ -509,7 +509,7 @@ dwarf_gen_location(const AOTCompContext *comp_ctx, if (func_ctx->debug_func == NULL) return NULL; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; auto sbaddr = extractor->target.ResolveFileAddress(vm_offset); @@ -550,13 +550,13 @@ dwarf_gen_func_ret_location(const AOTCompContext *comp_ctx, AOTFunc *func = func_ctx->aot_func; LLVMMetadataRef location_info = NULL; - if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) + if (!(extractor = TO_EXTRACTOR(comp_ctx->comp_data->extractor))) return NULL; // A code address in DWARF for WebAssembly is the offset of an // instruction relative within the Code section of the WebAssembly file. // For this reason Section::GetFileAddress() must return zero for the - // Code section. (refert to ObjectFileWasm.cpp) + // Code section. (refer to ObjectFileWasm.cpp) vm_offset = (func->code + func->code_size - 1) - comp_ctx->comp_data->wasm_module->buf_code; location_info = dwarf_gen_location(comp_ctx, func_ctx, vm_offset); diff --git a/core/iwasm/compilation/simd/simd_access_lanes.c b/core/iwasm/compilation/simd/simd_access_lanes.c index 4f43c35a9..16b0f7b6a 100644 --- a/core/iwasm/compilation/simd/simd_access_lanes.c +++ b/core/iwasm/compilation/simd/simd_access_lanes.c @@ -85,7 +85,7 @@ aot_compile_simd_swizzle_x86(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) if (!(condition = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, mask, max_lanes, "compare_with_16"))) { - HANDLE_FAILURE("LLVMBuldICmp"); + HANDLE_FAILURE("LLVMBuildICmp"); goto fail; } @@ -363,7 +363,7 @@ aot_compile_simd_replace(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "reesult"); + return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "result"); fail: return false; diff --git a/core/iwasm/compilation/simd/simd_bitmask_extracts.c b/core/iwasm/compilation/simd/simd_bitmask_extracts.c index 67d965426..3b1e32584 100644 --- a/core/iwasm/compilation/simd/simd_bitmask_extracts.c +++ b/core/iwasm/compilation/simd/simd_bitmask_extracts.c @@ -45,7 +45,7 @@ simd_build_bitmask(const AOTCompContext *comp_ctx, goto fail; } - /* fill every bit in a lange with its sign bit */ + /* fill every bit in a lane with its sign bit */ if (!(ashr_distance = simd_build_splat_const_integer_vector( comp_ctx, element_type[itype], lane_bits[itype] - 1, lanes[itype]))) { diff --git a/core/iwasm/compilation/simd/simd_comparisons.c b/core/iwasm/compilation/simd/simd_comparisons.c index 8a87ab25b..b7888c6dc 100644 --- a/core/iwasm/compilation/simd/simd_comparisons.c +++ b/core/iwasm/compilation/simd/simd_comparisons.c @@ -86,8 +86,8 @@ fail: } static bool -interger_vector_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - IntCond cond, LLVMTypeRef vector_type) +integer_vector_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + IntCond cond, LLVMTypeRef vector_type) { LLVMValueRef vec1, vec2, result; LLVMIntPredicate int_pred; @@ -138,28 +138,28 @@ bool aot_compile_simd_i8x16_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, IntCond cond) { - return interger_vector_compare(comp_ctx, func_ctx, cond, V128_i8x16_TYPE); + return integer_vector_compare(comp_ctx, func_ctx, cond, V128_i8x16_TYPE); } bool aot_compile_simd_i16x8_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, IntCond cond) { - return interger_vector_compare(comp_ctx, func_ctx, cond, V128_i16x8_TYPE); + return integer_vector_compare(comp_ctx, func_ctx, cond, V128_i16x8_TYPE); } bool aot_compile_simd_i32x4_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, IntCond cond) { - return interger_vector_compare(comp_ctx, func_ctx, cond, V128_i32x4_TYPE); + return integer_vector_compare(comp_ctx, func_ctx, cond, V128_i32x4_TYPE); } bool aot_compile_simd_i64x2_compare(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, IntCond cond) { - return interger_vector_compare(comp_ctx, func_ctx, cond, V128_i64x2_TYPE); + return integer_vector_compare(comp_ctx, func_ctx, cond, V128_i64x2_TYPE); } static bool diff --git a/core/iwasm/compilation/simd/simd_conversions.c b/core/iwasm/compilation/simd/simd_conversions.c index afa6d4722..56cfe2ad1 100644 --- a/core/iwasm/compilation/simd/simd_conversions.c +++ b/core/iwasm/compilation/simd/simd_conversions.c @@ -12,7 +12,7 @@ static bool simd_integer_narrow_x86(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMTypeRef in_vector_type, LLVMTypeRef out_vector_type, - const char *instrinsic) + const char *intrinsic) { LLVMValueRef vector1, vector2, result; LLVMTypeRef param_types[2] = { in_vector_type, in_vector_type }; @@ -24,7 +24,7 @@ simd_integer_narrow_x86(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - if (!(result = aot_call_llvm_intrinsic(comp_ctx, func_ctx, instrinsic, + if (!(result = aot_call_llvm_intrinsic(comp_ctx, func_ctx, intrinsic, out_vector_type, param_types, 2, vector1, vector2))) { HANDLE_FAILURE("LLVMBuildCall"); @@ -659,7 +659,7 @@ aot_compile_simd_i16x8_q15mulr_sat(AOTCompContext *comp_ctx, if (!(result = LLVMBuildTrunc(comp_ctx->builder, result, V128_i16x8_TYPE, "down_to_v8i16"))) { - HANDLE_FAILURE("LLVMBuidlTrunc"); + HANDLE_FAILURE("LLVMBuildTrunc"); return false; } diff --git a/core/iwasm/doc/wasm_function.MD b/core/iwasm/doc/wasm_function.MD index da4dac239..016e46f77 100644 --- a/core/iwasm/doc/wasm_function.MD +++ b/core/iwasm/doc/wasm_function.MD @@ -1,36 +1,36 @@ -# Wasm Function +# Wasm Function ## Internal data structure ![](./images/wasm_function.svg) ## Module level data (function) -**WASMModule**: Data structure created for loading a module. +**WASMModule**: Data structure created for loading a module. - `WASMImport *import_functions`: initialized from the Wasm file function section -- `WASMImport *import_functions`: initialized from the Wasm file import section. The runtime will try to solve the imports from the native API registration, refer to [Export native API to WASM application](../../../doc/export_native_api.md). +- `WASMImport *import_functions`: initialized from the Wasm file import section. The runtime will try to solve the imports from the native API registration, refer to [Export native API to WASM application](../../../doc/export_native_api.md). -**WASMFunction**: represent a Wasm function located in Wasm file code section. Track the links to the compiled function body. +**WASMFunction**: represent a Wasm function located in Wasm file code section. Track the links to the compiled function body. **WASMImport**: represent a imported Wasm function which can be a solved as a native function or another Wasm module exported function. ## Instance level data (function) **WASMModuleInstance**: Data structure created for instantiating a module - `WASMModuleInstanceExtra::functions`: combined the imported and internal functions into single array of structure `WASMFunctionInstance` -- `WASMModuleInstance::import_func_ptrs`: pointer array for solved function imports. This array is referred during calling imported native function. Note it is initialzed with the module level solved imports, but may points to different native function later due to c-api calls. - +- `WASMModuleInstance::import_func_ptrs`: pointer array for solved function imports. This array is referred during calling imported native function. Note it is initialized with the module level solved imports, but may points to different native function later due to c-api calls. + ## Execution paths **Interpreter**: - Execute internal bytecode function: ``` - WASMModuleInstance::e - -> WASMModuleInstanceExtra::functions[..] - -> WASMFunctionInstance::func + WASMModuleInstance::e + -> WASMModuleInstanceExtra::functions[..] + -> WASMFunctionInstance::func -> WASMFunction::code ``` - Execute imported function from other module: ``` - WASMModuleInstance::e - -> WASMModuleInstanceExtra::functions[..] + WASMModuleInstance::e + -> WASMModuleInstanceExtra::functions[..] (WASMFunctionInstance flag indicates an import) -> WASMFunctionInstance::import_func_inst -> WASMModuleInstance(second)::func @@ -39,9 +39,9 @@ - Execute imported native function: ``` - WASMModuleInstance::e - -> WASMModuleInstanceExtra::functions[..] + WASMModuleInstance::e + -> WASMModuleInstanceExtra::functions[..] (flag indicates imported native) WASMModuleInstance::import_func_ptrs[..] -> native function - ``` \ No newline at end of file + ``` diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 2763bc2be..3bc6d68ce 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1584,7 +1584,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint32 *tgtframe_sp = tgtframe->frame_sp; - /* frame sp of tgtframe points to catched exception */ + /* frame sp of tgtframe points to caught exception */ exception_tag_index = *((uint32 *)tgtframe_sp); tgtframe_sp++; @@ -1655,7 +1655,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, * BLOCK, IF and LOOP do not contain handlers and * cannot catch exceptions. * blocks marked as CATCH or - * CATCH_ALL did already caugth an exception and can + * CATCH_ALL did already caught an exception and can * only be a target for RETHROW, but cannot catch an * exception again */ @@ -1787,7 +1787,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, } handler_number++; } - /* exception not catched in this frame */ + /* exception not caught in this frame */ break; } case LABEL_TYPE_FUNCTION: @@ -6411,7 +6411,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, } } /* - * excange the thrown exception (index valid in submodule) + * exchange the thrown exception (index valid in submodule) * with the imported exception index (valid in this module) * if the module did not import the exception, * that results in a "INVALID_TAGINDEX", that triggers @@ -6468,7 +6468,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, goto find_a_catch_handler; } - /* when throw hits the end of a function it signalles with a + /* when throw hits the end of a function it signals with a * "uncaught wasm exception" trap */ if (has_exception && strstr(uncaught_exception, "uncaught wasm exception")) { diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index aa92f96ee..508826ce7 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -1143,14 +1143,14 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end, case WASM_OP_ANY_CONVERT_EXTERN: { set_error_buf(error_buf, error_buf_size, - "unsuppoted constant expression of " + "unsupported constant expression of " "extern.internalize"); goto fail; } case WASM_OP_EXTERN_CONVERT_ANY: { set_error_buf(error_buf, error_buf_size, - "unsuppoted constant expression of " + "unsupported constant expression of " "extern.externalize"); goto fail; } @@ -5433,7 +5433,7 @@ orcjit_thread_callback(void *arg) uint32 i; #if WASM_ENABLE_FAST_JIT != 0 - /* Compile fast jit funcitons of this group */ + /* Compile fast jit functions of this group */ for (i = group_idx; i < func_count; i += group_stride) { if (!jit_compiler_compile(module, i + module->import_function_count)) { LOG_ERROR("failed to compile fast jit function %u\n", i); @@ -5547,7 +5547,7 @@ orcjit_thread_callback(void *arg) i + j * group_stride + module->import_function_count, (void *)func_addr); - /* Try to switch to call this llvm jit funtion instead of + /* Try to switch to call this llvm jit function instead of fast jit function from fast jit jitted code */ jit_compiler_set_call_to_llvm_jit( module, @@ -6431,7 +6431,7 @@ check_wasi_abi_compatibility(const WASMModule *module, { /** * be careful with: - * wasi compatiable modules(command/reactor) which don't import any wasi + * wasi compatible modules(command/reactor) which don't import any wasi * APIs. Usually, a command has to import a "prox_exit" at least, but a * reactor can depend on nothing. At the same time, each has its own entry * point. @@ -6508,7 +6508,7 @@ check_wasi_abi_compatibility(const WASMModule *module, } } - /* filter out non-wasi compatiable modules */ + /* filter out non-wasi compatible modules */ if (!module->import_wasi_api && !start && !initialize) { return true; } @@ -6521,7 +6521,7 @@ check_wasi_abi_compatibility(const WASMModule *module, /* * there is at least one of `_start` and `_initialize` in below cases. - * according to the assumption, they should be all wasi compatiable + * according to the assumption, they should be all wasi compatible */ #if WASM_ENABLE_MULTI_MODULE != 0 @@ -6786,7 +6786,7 @@ wasm_loader_unload(WASMModule *module) WASMRegisteredModule *next = bh_list_elem_next(node); bh_list_remove(module->import_module_list, node); /* - * unload(sub_module) will be trigged during runtime_destroy(). + * unload(sub_module) will be triggered during runtime_destroy(). * every module in the global module list will be unloaded one by * one. so don't worry. */ @@ -7049,9 +7049,9 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, break; case WASM_OP_BR_TABLE: - read_leb_uint32(p, p_end, count); /* lable num */ + read_leb_uint32(p, p_end, count); /* label num */ #if WASM_ENABLE_FAST_INTERP != 0 - for (i = 0; i <= count; i++) /* lableidxs */ + for (i = 0; i <= count; i++) /* labelidxs */ skip_leb_uint32(p, p_end); #else p += count + 1; @@ -7062,7 +7062,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, #if WASM_ENABLE_FAST_INTERP == 0 case EXT_OP_BR_TABLE_CACHE: - read_leb_uint32(p, p_end, count); /* lable num */ + read_leb_uint32(p, p_end, count); /* label num */ while (*p == WASM_OP_NOP) p++; break; @@ -7086,7 +7086,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, #if WASM_ENABLE_REF_TYPES == 0 && WASM_ENABLE_GC == 0 u8 = read_uint8(p); /* 0x00 */ #else - skip_leb_uint32(p, p_end); /* talbeidx */ + skip_leb_uint32(p, p_end); /* tableidx */ #endif break; @@ -7661,7 +7661,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, { WASMDebugInstance *debug_instance = wasm_exec_env_get_instance(exec_env); - char orignal_opcode[1]; + char original_opcode[1]; uint64 size = 1; WASMModuleInstance *module_inst = (WASMModuleInstance *)exec_env->module_inst; @@ -7670,12 +7670,12 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, : ~0; if (debug_instance) { if (wasm_debug_instance_get_obj_mem(debug_instance, offset, - orignal_opcode, &size) + original_opcode, &size) && size == 1) { LOG_VERBOSE("WASM loader find OP_BREAK , recover it " "with %02x: ", - orignal_opcode[0]); - opcode = orignal_opcode[0]; + original_opcode[0]); + opcode = original_opcode[0]; goto op_break_retry; } } @@ -9373,7 +9373,7 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value, sizeof(float64)); ctx->const_cell_num += 2; /* The const buf will be reversed, we use the second cell */ - /* of the i64/f64 const so the finnal offset is corrent */ + /* of the i64/f64 const so the final offset is correct */ operand_offset++; break; case VALUE_TYPE_I64: @@ -9405,7 +9405,7 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value, LOG_OP("#### new const [%d]: %ld\n", ctx->num_const, (int64)c->value.i64); } - /* use negetive index for const */ + /* use negative index for const */ operand_offset = -(operand_offset + 1); *offset = operand_offset; return true; @@ -11300,7 +11300,7 @@ re_scan: * CATCH Blocks */ RESET_STACK(); - /* push types on the stack according to catched type */ + /* push types on the stack according to caught type */ if (BLOCK_HAS_PARAM(new_block_type)) { for (i = 0; i < new_block_type.u.type->param_count; i++) PUSH_TYPE(new_block_type.u.type->types[i]); @@ -13643,7 +13643,7 @@ re_scan: if (u32 >= module->data_seg_count) { set_error_buf(error_buf, error_buf_size, - "unknown data segement"); + "unknown data segment"); goto fail; } @@ -13662,7 +13662,7 @@ re_scan: if (u32 >= module->table_seg_count) { set_error_buf(error_buf, error_buf_size, - "unknown element segement"); + "unknown element segment"); goto fail; } if (!wasm_reftype_is_subtype_of( diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index fa4cd0881..ac085fe8e 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2311,7 +2311,7 @@ orcjit_thread_callback(void *arg) uint32 i; #if WASM_ENABLE_FAST_JIT != 0 - /* Compile fast jit funcitons of this group */ + /* Compile fast jit functions of this group */ for (i = group_idx; i < func_count; i += group_stride) { if (!jit_compiler_compile(module, i + module->import_function_count)) { LOG_ERROR("failed to compile fast jit function %u\n", i); diff --git a/core/iwasm/interpreter/wasm_opcode.h b/core/iwasm/interpreter/wasm_opcode.h index db5e5e40b..76647454b 100644 --- a/core/iwasm/interpreter/wasm_opcode.h +++ b/core/iwasm/interpreter/wasm_opcode.h @@ -86,7 +86,7 @@ typedef enum WASMOpcode { WASM_OP_I32_STORE8 = 0x3a, /* i32.store8 */ WASM_OP_I32_STORE16 = 0x3b, /* i32.store16 */ WASM_OP_I64_STORE8 = 0x3c, /* i64.store8 */ - WASM_OP_I64_STORE16 = 0x3d, /* i64.sotre16 */ + WASM_OP_I64_STORE16 = 0x3d, /* i64.store16 */ WASM_OP_I64_STORE32 = 0x3e, /* i64.store32 */ WASM_OP_MEMORY_SIZE = 0x3f, /* memory.size */ WASM_OP_MEMORY_GROW = 0x40, /* memory.grow */ @@ -325,7 +325,7 @@ typedef enum WASMGCEXTOpcode { WASM_OP_I31_GET_S = 0x1D, /* i31.get_s */ WASM_OP_I31_GET_U = 0x1E, /* i31.get_u */ - /* stringref related opcoded */ + /* stringref related opcodes */ WASM_OP_STRING_NEW_UTF8 = 0x80, /* string.new_utf8 */ WASM_OP_STRING_NEW_WTF16 = 0x81, /* string.new_wtf16 */ WASM_OP_STRING_CONST = 0x82, /* string.const */ diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 5598ea364..e8b6ad478 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -79,7 +79,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM #### **Enable memory64 feature** - **WAMR_BUILD_MEMORY64**=1/0, default to disable if not set -> Note: Currently, the memory64 feature is only supported in classic interpreter running mode. +> Note: Currently, the memory64 feature is only supported in classic interpreter running mode. #### **Enable thread manager** - **WAMR_BUILD_THREAD_MGR**=1/0, default to disable if not set @@ -137,7 +137,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM #### **Enable Exception Handling** - **WAMR_BUILD_EXCE_HANDLING**=1/0, default to disable if not set -> Note: Currently, the exception handling feature is only supported in classic interpreter running mode. +> Note: Currently, the exception handling feature is only supported in classic interpreter running mode. #### **Enable Garbage Collection** - **WAMR_BUILD_GC**=1/0, default to disable if not set @@ -210,7 +210,7 @@ Currently we only profile the memory consumption of module, module_instance and > } > ``` > -> and then use `cmake -DWAMR_BH_VPRINTF=my_vprintf ..` to pass the callback function, or add `BH_VPRINTF=my_vprintf` macro for the compiler, e.g. add line `add_defintions(-DBH_VPRINTF=my_vprintf)` in CMakeListst.txt. See [basic sample](../samples/basic/src/main.c) for a usage example. +> and then use `cmake -DWAMR_BH_VPRINTF=my_vprintf ..` to pass the callback function, or add `BH_VPRINTF=my_vprintf` macro for the compiler, e.g. add line `add_definitions(-DBH_VPRINTF=my_vprintf)` in CMakeLists.txt. See [basic sample](../samples/basic/src/main.c) for a usage example. #### **WAMR_BH_LOG**=, default to disable if not set > Note: if the log_callback function is provided by the developer, WAMR logs are redirected to such callback. For example: @@ -285,7 +285,7 @@ Currently we only profile the memory consumption of module, module_instance and - **WAMR_BUILD_AOT_INTRINSICS**=1/0, enable the AOT intrinsic functions, default to enable if not set. These functions can be called from the AOT code when `--disable-llvm-intrinsics` flag or `--enable-builtin-intrinsics=` flag is used by wamrc to generate the AOT file. > Note: See [Tuning the XIP intrinsic functions](./xip.md#tuning-the-xip-intrinsic-functions) for more details. -#### **Configurale memory access boundary check** +#### **Configurable memory access boundary check** - **WAMR_CONFIGUABLE_BOUNDS_CHECKS**=1/0, default to disable if not set > Note: If it is enabled, allow to run `iwasm --disable-bounds-checks` to disable the memory access boundary checks for interpreter mode. diff --git a/doc/embed_wamr.md b/doc/embed_wamr.md index 5e4e3a512..9a6f685c7 100644 --- a/doc/embed_wamr.md +++ b/doc/embed_wamr.md @@ -207,7 +207,7 @@ There are two runtime APIs available for this purpose. /** * malloc a buffer from instance's private memory space. * - * return: the buffer address in instance's memory space (pass to the WASM funciton) + * return: the buffer address in instance's memory space (pass to the WASM function) * p_native_addr: return the native address of allocated memory * size: the buffer size to allocate */ @@ -219,7 +219,7 @@ wasm_runtime_module_malloc(wasm_module_inst_t module_inst, * malloc a buffer from instance's private memory space, * and copy the data from another native buffer to it. * - * return: the buffer address in instance's memory space (pass to the WASM funciton) + * return: the buffer address in instance's memory space (pass to the WASM function) * src: the native buffer address * size: the size of buffer to be allocated and copy data */ diff --git a/doc/export_native_api.md b/doc/export_native_api.md index 0f7f1669d..7f3e92db6 100644 --- a/doc/export_native_api.md +++ b/doc/export_native_api.md @@ -36,7 +36,7 @@ void foo2(wasm_exec_env_t exec_env, char * msg, uint8 * buffer, int buf_len) } ``` -The first parameter exec_env must be defined using type **wasm_exec_env_t** which is the calling convention by WAMR. +The first parameter exec_env must be defined using type **wasm_exec_env_t** which is the calling convention by WAMR. The rest parameters should be in the same types as the parameters of WASM function foo(), but there are a few special cases that are explained in section "Buffer address conversion and boundary check". Regarding the parameter names, they don't have to be the same, but we would suggest using the same names for easy maintenance. @@ -47,10 +47,10 @@ The rest parameters should be in the same types as the parameters of WASM functi Register the native APIs in the runtime, then everything is fine. It is ready to build the runtime software. ``` C -// Define an array of NativeSymbol for the APIs to be exported. +// Define an array of NativeSymbol for the APIs to be exported. // Note: the array must be static defined since runtime // will keep it after registration -static NativeSymbol native_symbols[] = +static NativeSymbol native_symbols[] = { { "foo", // the name of WASM function name @@ -61,7 +61,7 @@ static NativeSymbol native_symbols[] = "foo2", // the name of WASM function name foo2, // the native function pointer "($*~)" // the function prototype signature - } + } }; // initialize the runtime before registering the native functions @@ -69,12 +69,12 @@ wasm_runtime_init(); int n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol); if (!wasm_runtime_register_natives("env", - native_symbols, + native_symbols, n_native_symbols)) { goto fail1; } -// natives registeration must be done before loading WASM modules +// natives registration must be done before loading WASM modules module = wasm_runtime_load(buffer, size, error_buf, sizeof(error_buf)); ``` @@ -86,7 +86,7 @@ The function signature field in **NativeSymbol** structure is a string for descr Each letter in the "()" represents a parameter type, and the one following after ")" represents the return value type. The meaning of each letter: - '**i**': i32 -- '**I**': i64 +- '**I**': i64 - '**f**': f32 - '**F**': f64 - '**r**': externref (has to be the value of a `uintptr_t` variable), or all kinds of GC reference types when GC feature is enabled @@ -101,13 +101,13 @@ The signature can defined as NULL, then all function parameters are assumed as i The `NativeSymbol` element for `foo2 ` above can be also defined with macro EXPORT_WASM_API_WITH_SIG. This macro can be used when the native function name is the same as the WASM symbol name. ```c -static NativeSymbol native_symbols[] = +static NativeSymbol native_symbols[] = { EXPORT_WASM_API_WITH_SIG(foo2, "($*~)") // wasm symbol name will be "foo2" }; ``` -​ +​ ## Call exported API in WASM application @@ -124,7 +124,7 @@ int main(int argc, char **argv) int c = foo(a, b); // call into native foo_native() foo2(msg, buffer, sizeof(buffer)); // call into native foo2() - + return 0; } ``` @@ -157,9 +157,9 @@ As function parameters are always passed in 32 bits numbers, you can also use 'i // for buffer address or string parameters, here // is how to do address conversion and boundary check manually // -void foo2(wasm_exec_env_t exec_env, - uint32 msg_offset, - uint32 buffer_offset, +void foo2(wasm_exec_env_t exec_env, + uint32 msg_offset, + uint32 buffer_offset, int32 buf_len) { wasm_module_inst_t module_inst = get_module_inst(exec_env); @@ -169,7 +169,7 @@ void foo2(wasm_exec_env_t exec_env, // do boundary check if (!wasm_runtime_validate_app_str_add(msg_offset)) return 0; - + if (!wasm_runtime_validate_app_addr((uint64)buffer_offset, (uint64)buf_len)) return; @@ -187,7 +187,7 @@ void foo2(wasm_exec_env_t exec_env, ## Sandbox security attention -The runtime builder should ensure not broking the memory sandbox when exporting the native function to WASM. +The runtime builder should ensure not broking the memory sandbox when exporting the native function to WASM. A ground rule: @@ -196,7 +196,7 @@ A ground rule: A few recommendations: - Never pass any structure/class object pointer to native (do data serialization instead) -- Never pass a function pointer to the native +- Never pass a function pointer to the native Note: while not recommended here, nothing prevents you from passing structure/function pointers as far as the native API is aware of diff --git a/doc/memory_usage.md b/doc/memory_usage.md index 88b792f0c..cc3ba2ea6 100644 --- a/doc/memory_usage.md +++ b/doc/memory_usage.md @@ -48,7 +48,7 @@ A WASM linear memory is either shared or non-shared. A WASM linear memory has `min` and `max` sizes. (They correspond to `wasm-ld`'s `--init-memory` and `--max-memory` options.) They are in the number of WASM pages, each of which is of 65536 bytes. -The `max` is optional for non-shared memory. When omitted, it effectivily +The `max` is optional for non-shared memory. When omitted, it effectively means unlimited. The linear memory is allocated via `os_mmap` and `os_mem_commit`/`os_mprotect`. diff --git a/doc/pthread_library.md b/doc/pthread_library.md index ba43ee1c0..602f16d53 100644 --- a/doc/pthread_library.md +++ b/doc/pthread_library.md @@ -132,7 +132,7 @@ make ``` -## Aux stack seperation +## Aux stack separation The compiler may use some spaces in the linear memory as an auxiliary stack. When pthread is enabled, every thread should have its own aux stack space, so the total aux stack space reserved by the compiler will be divided into N + 1 parts, where N is the maximum number of threads that can be created by the user code. The default value of N is 4, which means you can create 4 threads at most. This value can be changed by an option if you are using product-mini: diff --git a/doc/semantic_version.md b/doc/semantic_version.md index d0d46a5e2..9fdd65d60 100644 --- a/doc/semantic_version.md +++ b/doc/semantic_version.md @@ -13,7 +13,7 @@ There are three parts in the new version string: ## Legacy versions -All legacy versions(tags) will keep their current status. No existed releasings names +All legacy versions(tags) will keep their current status. No existing release names and links will be changed. ## Reference diff --git a/doc/source_debugging.md b/doc/source_debugging.md index bfa62f6c2..3e21c401c 100644 --- a/doc/source_debugging.md +++ b/doc/source_debugging.md @@ -13,8 +13,8 @@ llvm-dwarfdump-12 test.wasm ## Debugging with interpreter -See [Debuggging with interpreter](source_debugging_interpreter.md). +See [Debugging with interpreter](source_debugging_interpreter.md). ## Debugging with AOT -See [Debuggging with AOT](source_debugging_aot.md). +See [Debugging with AOT](source_debugging_aot.md). diff --git a/doc/wasm_c_api.md b/doc/wasm_c_api.md index 131adadd0..03d5cffd4 100644 --- a/doc/wasm_c_api.md +++ b/doc/wasm_c_api.md @@ -31,7 +31,7 @@ are helpful. - call `wasm_engine_new` or `wasm_engine_delete` multiple times in different threads -## unspported list +## unsupported list Currently WAMR supports most of the APIs, the unsupported APIs are listed as below: diff --git a/samples/wasm-c-api/src/callback_chain.c b/samples/wasm-c-api/src/callback_chain.c index e4f5801dc..440cf2a8b 100644 --- a/samples/wasm-c-api/src/callback_chain.c +++ b/samples/wasm-c-api/src/callback_chain.c @@ -252,10 +252,10 @@ main(int argc, const char *argv[]) return 1; } -#define DESTROY_WASM_FUNCITON(name, index, ...) \ +#define DESTROY_WASM_FUNCTION(name, index, ...) \ wasm_func_delete(function_##name); - IMPORT_FUNCTION_LIST(DESTROY_WASM_FUNCITON) -#undef DESTROY_WASM_FUNCITON + IMPORT_FUNCTION_LIST(DESTROY_WASM_FUNCTION) +#undef DESTROY_WASM_FUNCTION // Extract export. printf("Extracting export...\n"); From 07eae7c424a7bdf57be2345763901db6810abad4 Mon Sep 17 00:00:00 2001 From: GanJingSaiyan <130947810+Shanks0224@users.noreply.github.com> Date: Wed, 8 May 2024 16:31:39 +0800 Subject: [PATCH 008/198] Add aot binary analysis tool aot-analyzer (#3379) Add aot binary analysis tool aot-analyzer, samples: ```bash # parse example.aot, and print basic information about AoT file $ ./aot-analyzer -i example.aot # parse example.aot, and print the size of text section of the AoT file $ ./aot-analyzer -t example.aot # compare these two files, and show the difference in function size between them $ ./aot-analyzer -c example.aot example.wasm ``` Signed-off-by: ganjing --- test-tools/aot-analyzer/CMakeLists.txt | 88 +++ test-tools/aot-analyzer/README.md | 55 ++ .../aot-analyzer/include/analyzer_error.h | 52 ++ test-tools/aot-analyzer/include/aot_file.h | 32 + test-tools/aot-analyzer/include/binary_file.h | 67 ++ test-tools/aot-analyzer/include/common.h | 100 +++ test-tools/aot-analyzer/include/config.h | 168 +++++ .../aot-analyzer/include/option_parser.h | 78 +++ .../aot-analyzer/include/string_format.h | 56 ++ test-tools/aot-analyzer/include/wasm_file.h | 22 + test-tools/aot-analyzer/src/aot_file.cc | 259 +++++++ test-tools/aot-analyzer/src/binary_file.cc | 115 +++ test-tools/aot-analyzer/src/main.cc | 663 ++++++++++++++++++ test-tools/aot-analyzer/src/option_parser.cc | 345 +++++++++ test-tools/aot-analyzer/src/wasm_file.cc | 27 + 15 files changed, 2127 insertions(+) create mode 100644 test-tools/aot-analyzer/CMakeLists.txt create mode 100644 test-tools/aot-analyzer/README.md create mode 100644 test-tools/aot-analyzer/include/analyzer_error.h create mode 100644 test-tools/aot-analyzer/include/aot_file.h create mode 100644 test-tools/aot-analyzer/include/binary_file.h create mode 100644 test-tools/aot-analyzer/include/common.h create mode 100644 test-tools/aot-analyzer/include/config.h create mode 100644 test-tools/aot-analyzer/include/option_parser.h create mode 100644 test-tools/aot-analyzer/include/string_format.h create mode 100644 test-tools/aot-analyzer/include/wasm_file.h create mode 100644 test-tools/aot-analyzer/src/aot_file.cc create mode 100644 test-tools/aot-analyzer/src/binary_file.cc create mode 100644 test-tools/aot-analyzer/src/main.cc create mode 100644 test-tools/aot-analyzer/src/option_parser.cc create mode 100644 test-tools/aot-analyzer/src/wasm_file.cc diff --git a/test-tools/aot-analyzer/CMakeLists.txt b/test-tools/aot-analyzer/CMakeLists.txt new file mode 100644 index 000000000..b1a11b549 --- /dev/null +++ b/test-tools/aot-analyzer/CMakeLists.txt @@ -0,0 +1,88 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +project (aot-analyzer) + +set (CMAKE_CXX_STANDARD 17) + +################ runtime settings ################ +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if (APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif () + +# Reset default linker flags +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +set (WAMR_STRINGREF_IMPL_SOURCE "STUB") + +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif () + +if (NOT DEFINED WAMR_BUILD_INTERP) + # Enable Interpreter by default + set (WAMR_BUILD_INTERP 1) +endif () + +if (NOT DEFINED WAMR_BUILD_AOT) + # Enable AOT by default. + set (WAMR_BUILD_AOT 1) +endif () + +if (NOT DEFINED WAMR_BUILD_MEMORY_PROFILING) + # Enable reference types by default + set (WAMR_BUILD_MEMORY_PROFILING 1) +endif () + +if (NOT DEFINED WAMR_BIG_ENDIAN) + set (WAMR_BIG_ENDIAN 0) +endif () + +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter") +# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") + +if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") + endif () +endif () + +# build out vmlib +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +################ application related ################ +include_directories(./include) +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + +add_executable (aot-analyzer src/main.cc src/aot_file.cc src/binary_file.cc src/option_parser.cc src/wasm_file.cc ${UNCOMMON_SHARED_SOURCE}) + +target_link_libraries (aot-analyzer vmlib -lm -ldl -lpthread -lrt) \ No newline at end of file diff --git a/test-tools/aot-analyzer/README.md b/test-tools/aot-analyzer/README.md new file mode 100644 index 000000000..1ae3ca7b5 --- /dev/null +++ b/test-tools/aot-analyzer/README.md @@ -0,0 +1,55 @@ +# AoT-Analyzer: The AoT Binary analysis tool + + +## Cloning + +Clone as normal: + +```console +$ git clone +$ cd aot-analyzer +``` + +## Building using CMake directly + +You'll need [CMake](https://cmake.org). You can then run CMake, the normal way: + +```console +$ mkdir build +$ cd build +$ cmake .. +$ cmake --build . +``` + +To analyze AoT files with GC feature enabled, you need to enable GC feature when compiling this tool: + +```console +$ mkdir build +$ cd build +$ cmake -DWAMR_BUILD_GC=1 .. +$ cmake --build . +``` + +## Running aot-analyzer + +Some examples: + +```sh +# parse example.aot, and print basic information about AoT file +$ ./aot-analyzer -i example.aot + +# parse example.aot, and print the size of text section of the AoT file +$ ./aot-analyzer -t example.aot + +# compare these two files, and show the difference in function size between them +$ ./aot-analyzer -c example.aot example.wasm +``` + +**NOTE**: Using `-c` for file comparison, must ensure that the AoT file is generated based on this Wasm file. + + +You can use `--help` to get additional help: + +```console +$ ./aot-analyzer --help +``` \ No newline at end of file diff --git a/test-tools/aot-analyzer/include/analyzer_error.h b/test-tools/aot-analyzer/include/analyzer_error.h new file mode 100644 index 000000000..62126fdf7 --- /dev/null +++ b/test-tools/aot-analyzer/include/analyzer_error.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef ANALYZER_ERROR_H_ +#define ANALYZER_ERROR_H_ + +#include +#include +#include + +#include "config.h" + +namespace analyzer { + +enum class ErrorLevel { + Warning, + Error, +}; + +static inline const char * +GetErrorLevelName(ErrorLevel error_level) +{ + switch (error_level) { + case ErrorLevel::Warning: + return "warning"; + case ErrorLevel::Error: + return "error"; + } + ANALYZER_UNREACHABLE; +} + +class Error +{ + public: + Error() + : error_level_(ErrorLevel::Error) + {} + Error(ErrorLevel error_level, std::string_view message) + : error_level_(error_level) + , message_(message) + {} + + ErrorLevel error_level_; + std::string message_; +}; + +using Errors = std::vector; + +} // namespace analyzer +#endif \ No newline at end of file diff --git a/test-tools/aot-analyzer/include/aot_file.h b/test-tools/aot-analyzer/include/aot_file.h new file mode 100644 index 000000000..fdb9c87f1 --- /dev/null +++ b/test-tools/aot-analyzer/include/aot_file.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef AOT_FILE_H_ +#define AOT_FILE_H_ + +#include "binary_file.h" + +namespace analyzer { + +class AoTFile : public BinaryFile +{ + public: + AoTFile(const char *file_name); + + Result Scan(); + + Result ParseTargetInfo(); + AOTTargetInfo GetTargetInfo(); + + std::string GetBinTypeName(uint16_t bin_type); + std::string GetExectuionTypeName(uint16_t e_type); + std::string GetExectuionMachineName(uint16_t e_machine); + + private: + AOTTargetInfo target_info_; +}; + +} // namespace analyzer +#endif diff --git a/test-tools/aot-analyzer/include/binary_file.h b/test-tools/aot-analyzer/include/binary_file.h new file mode 100644 index 000000000..d0cf00347 --- /dev/null +++ b/test-tools/aot-analyzer/include/binary_file.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef BINARY_FILE_H_ +#define BINARY_FILE_H_ + +#include "aot_runtime.h" +#include "bh_read_file.h" +#include "common.h" +#include "config.h" +#include "wasm_export.h" + +namespace analyzer { + +class BinaryFile +{ + public: + BinaryFile(const char *file_name); + ~BinaryFile(); + + Result ReadModule(); + + virtual Result Scan(); + + void ANALYZER_PRINTF_FORMAT(2, 3) PrintError(const char *format, ...); + Result UpdateCurrentPos(uint32_t steps); + + const char *GetFileName() { return file_name_; } + uint8_t *GetFileData() { return file_data_; } + uint32_t GetFileSize() { return file_size_; } + size_t GetCurrentPos() { return current_pos_; } + wasm_module_t GetModule() { return module_; } + WASMModuleMemConsumption GetMemConsumption() { return mem_conspn_; } + + private: + const char *file_name_; + uint8_t *file_data_; + uint32_t file_size_; + size_t current_pos_; + wasm_module_t module_; + WASMModuleMemConsumption mem_conspn_; +}; + +template +Result +ReadT(T *out_value, BinaryFile *file, const char *type_name) +{ + if (file == NULL + || file->GetCurrentPos() + sizeof(T) > file->GetFileSize()) { + return Result::Error; + } +#if WAMR_BIG_ENDIAN + uint8_t tmp[sizeof(T)]; + memcpy(tmp, file->GetFileData() + file->GetCurrentPos(), sizeof(tmp)); + SwapBytesSized(tmp, sizeof(tmp)); + memcpy(out_value, tmp, sizeof(T)); +#else + memcpy(out_value, file->GetFileData() + file->GetCurrentPos(), sizeof(T)); +#endif + file->UpdateCurrentPos(sizeof(T)); + return Result::Ok; +} + +} // namespace analyzer +#endif diff --git a/test-tools/aot-analyzer/include/common.h b/test-tools/aot-analyzer/include/common.h new file mode 100644 index 000000000..c4d25bc76 --- /dev/null +++ b/test-tools/aot-analyzer/include/common.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef COMMON_H_ +#define COMMON_H_ + +#include "string_format.h" + +#define ANALYZER_FATAL(...) fprintf(stderr, __VA_ARGS__), exit(1) + +#if WITH_EXCEPTIONS +#define ANALYZER_TRY try { +#define ANALYZER_CATCH_BAD_ALLOC \ + } \ + catch (std::bad_alloc &) {} +#define ANALYZER_CATCH_BAD_ALLOC_AND_EXIT \ + } \ + catch (std::bad_alloc &) { ANALYZER_FATAL("Memory allocation failure.\n"); } +#else +#define ANALYZER_TRY +#define ANALYZER_CATCH_BAD_ALLOC +#define ANALYZER_CATCH_BAD_ALLOC_AND_EXIT +#endif + +namespace analyzer { + +struct ObjdumpOptions { + bool info; + bool text_size; + bool details; + bool compare; + const char *file_name; +}; + +struct Result { + enum Enum { + Ok, + Error, + }; + + Result() + : Result(Ok) + {} + Result(Enum e) + : enum_(e) + {} + operator Enum() const { return enum_; } + Result &operator|=(Result rhs); + + private: + Enum enum_; +}; + +inline Result +operator|(Result lhs, Result rhs) +{ + return (lhs == Result::Error || rhs == Result::Error) ? Result::Error + : Result::Ok; +} + +inline Result & +Result::operator|=(Result rhs) +{ + enum_ = *this | rhs; + return *this; +} + +inline bool +Succeeded(Result result) +{ + return result == Result::Ok; +} + +inline bool +Failed(Result result) +{ + return result == Result::Error; +} + +#define CHECK_RESULT(expr) \ + do { \ + if (Failed(expr)) { \ + return Result::Error; \ + } \ + } while (0) + +#define ERROR_IF(expr, ...) \ + do { \ + if (expr) { \ + PrintError(__VA_ARGS__); \ + return Result::Error; \ + } \ + } while (0) + +#define ERROR_UNLESS(expr, ...) ERROR_IF(!(expr), __VA_ARGS__) + +} // namespace analyzer +#endif diff --git a/test-tools/aot-analyzer/include/config.h b/test-tools/aot-analyzer/include/config.h new file mode 100644 index 000000000..546b5b167 --- /dev/null +++ b/test-tools/aot-analyzer/include/config.h @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef CONFIG_H_ +#define CONFIG_H_ + +#include +#include + +#define ANALYZER_VERSION_STRING "1.0.0" + +#define WASM_MAGIC_NUMBER 0x6d736100 +#define WASM_CURRENT_VERSION 1 + +#define AOT_MAGIC_NUMBER 0x746f6100 +#define AOT_CURRENT_VERSION 3 + +/* Legal values for bin_type */ +#define BIN_TYPE_ELF32L 0 /* 32-bit little endian */ +#define BIN_TYPE_ELF32B 1 /* 32-bit big endian */ +#define BIN_TYPE_ELF64L 2 /* 64-bit little endian */ +#define BIN_TYPE_ELF64B 3 /* 64-bit big endian */ +#define BIN_TYPE_COFF32 4 /* 32-bit little endian */ +#define BIN_TYPE_COFF64 6 /* 64-bit little endian */ + +/* Legal values for e_type (object file type). */ +#define E_TYPE_NONE 0 /* No file type */ +#define E_TYPE_REL 1 /* Relocatable file */ +#define E_TYPE_EXEC 2 /* Executable file */ +#define E_TYPE_DYN 3 /* Shared object file */ +#define E_TYPE_XIP 4 /* eXecute In Place file */ + +/* Legal values for e_machine (architecture). */ +#define E_MACHINE_386 3 /* Intel 80386 */ +#define E_MACHINE_MIPS 8 /* MIPS R3000 big-endian */ +#define E_MACHINE_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ +#define E_MACHINE_ARM 40 /* ARM/Thumb */ +#define E_MACHINE_AARCH64 183 /* AArch64 */ +#define E_MACHINE_ARC 45 /* Argonaut RISC Core */ +#define E_MACHINE_IA_64 50 /* Intel Merced */ +#define E_MACHINE_MIPS_X 51 /* Stanford MIPS-X */ +#define E_MACHINE_X86_64 62 /* AMD x86-64 architecture */ +#define E_MACHINE_ARC_COMPACT 93 /* ARC International ARCompact */ +#define E_MACHINE_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */ +#define E_MACHINE_XTENSA 94 /* Tensilica Xtensa Architecture */ +#define E_MACHINE_RISCV 243 /* RISC-V 32/64 */ +#define E_MACHINE_WIN_I386 0x14c /* Windows i386 architecture */ +#define E_MACHINE_WIN_X86_64 0x8664 /* Windows x86-64 architecture */ + +/* Whether is available */ +#define HAVE_ALLOCA_H 1 + +/* Whether snprintf is defined by stdio.h */ +#define HAVE_SNPRINTF 1 + +/* Whether ssize_t is defined by stddef.h */ +#define HAVE_SSIZE_T 1 + +/* Whether strcasecmp is defined by strings.h */ +#define HAVE_STRCASECMP 1 + +#define COMPILER_IS_CLANG 0 +#define COMPILER_IS_GNU 1 +#define COMPILER_IS_MSVC 0 + +#define WITH_EXCEPTIONS 0 + +#define SIZEOF_SIZE_T 8 + +#if HAVE_ALLOCA_H +#include +#elif COMPILER_IS_MSVC +#include +#define alloca _alloca +#elif defined(__MINGW32__) +#include +#endif + +#if COMPILER_IS_CLANG || COMPILER_IS_GNU + +#if __MINGW32__ +#define ANALYZER_PRINTF_FORMAT(format_arg, first_arg) \ + __attribute__((format(gnu_printf, (format_arg), (first_arg)))) +#else +#define ANALYZER_PRINTF_FORMAT(format_arg, first_arg) \ + __attribute__((format(printf, (format_arg), (first_arg)))) +#endif + +#ifdef __cplusplus +#define ANALYZER_STATIC_ASSERT(x) static_assert((x), #x) +#else +#define ANALYZER_STATIC_ASSERT(x) _Static_assert((x), #x) +#endif + +#elif COMPILER_IS_MSVC + +#include +#include + +#define ANALYZER_STATIC_ASSERT(x) _STATIC_ASSERT(x) +#define ANALYZER_PRINTF_FORMAT(format_arg, first_arg) + +#else + +#error unknown compiler + +#endif + +#define ANALYZER_UNREACHABLE abort() + +#ifdef __cplusplus + +#if COMPILER_IS_MSVC + +#elif COMPILER_IS_CLANG || COMPILER_IS_GNU + +/* print format specifier for size_t */ +#define PRIzd "zd" +#define PRIzx "zx" + +#else + +#error unknown compiler + +#endif + +#if HAVE_SNPRINTF +#define analyzer_snprintf snprintf +#elif COMPILER_IS_MSVC +#include +int +analyzer_snprintf(char *str, size_t size, const char *format, ...); +#else +#error no snprintf +#endif + +#if COMPILER_IS_MSVC +int +analyzer_vsnprintf(char *str, size_t size, const char *format, va_list ap); +#else +#define analyzer_vsnprintf vsnprintf +#endif + +#if !HAVE_SSIZE_T +#if COMPILER_IS_MSVC +#if defined(_WIN64) +typedef signed __int64 ssize_t; +#else +typedef signed int ssize_t; +#endif +#else +typedef long ssize_t; +#endif +#endif + +#if !HAVE_STRCASECMP +#if COMPILER_IS_MSVC +#define strcasecmp _stricmp +#else +#error no strcasecmp +#endif +#endif + +#endif + +#endif diff --git a/test-tools/aot-analyzer/include/option_parser.h b/test-tools/aot-analyzer/include/option_parser.h new file mode 100644 index 000000000..a3e0f7d55 --- /dev/null +++ b/test-tools/aot-analyzer/include/option_parser.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef OPTION_PARSER_H_ +#define OPTION_PARSER_H_ + +#include +#include +#include + +#include "config.h" + +namespace analyzer { + +class OptionParser +{ + public: + enum class HasArgument { No, Yes }; + enum class ArgumentCount { One, OneOrMore, ZeroOrMore }; + + struct Option; + using Callback = std::function; + using NullCallback = std::function; + + struct Option { + Option(char short_name, const std::string &long_name, + const std::string &metavar, HasArgument has_argument, + const std::string &help, const Callback &); + + char short_name; + std::string long_name; + std::string metavar; + bool has_argument; + std::string help; + Callback callback; + }; + + struct Argument { + Argument(const std::string &name, ArgumentCount, const Callback &); + + std::string name; + ArgumentCount count; + Callback callback; + int handled_count = 0; + }; + + explicit OptionParser(const char *program_name, const char *description); + + void AddOption(const Option &); + void AddOption(char short_name, const char *long_name, const char *help, + const NullCallback &); + void AddOption(const char *long_name, const char *help, + const NullCallback &); + void AddOption(char short_name, const char *long_name, const char *metavar, + const char *help, const Callback &); + + void AddArgument(const std::string &name, ArgumentCount, const Callback &); + void SetErrorCallback(const Callback &); + void Parse(int argc, char *argv[]); + void PrintHelp(); + + private: + static int Match(const char *s, const std::string &full, bool has_argument); + void ANALYZER_PRINTF_FORMAT(2, 3) Errorf(const char *format, ...); + void HandleArgument(size_t *arg_index, const char *arg_value); + void DefaultError(const std::string &); + + std::string program_name_; + std::string description_; + std::vector