Fix some coding style issues, fix doc typo and refine some codes (#392)

This commit is contained in:
Wenyong Huang
2020-09-20 08:20:45 +08:00
committed by GitHub
parent 7c8ccc7c26
commit e501a6963b
20 changed files with 155 additions and 227 deletions

View File

@ -2202,9 +2202,9 @@ interp_process_export(wasm_store_t *store,
external = wasm_global_as_extern(global);
break;
// TODO:
case EXPORT_KIND_MEMORY:
case EXPORT_KIND_TABLE:
/* TODO: */
break;
default:
goto failed;

View File

@ -31,9 +31,9 @@ typedef enum runtime_mode_e {
} runtime_mode_e;
struct wasm_engine_t {
// support one store for now
/* support one store for now */
wasm_store_vec_t *stores;
// Interpreter by deault
/* Interpreter by deault */
runtime_mode_e mode;
};
@ -49,21 +49,21 @@ struct wasm_valtype_t {
struct wasm_functype_t {
uint32 extern_kind;
// gona to new and delete own
/* gona to new and delete own */
wasm_valtype_vec_t *params;
wasm_valtype_vec_t *results;
};
struct wasm_globaltype_t {
uint32 extern_kind;
// gona to new and delete own
/* gona to new and delete own */
wasm_valtype_t *val_type;
wasm_mutability_t mutability;
};
struct wasm_tabletype_t {
uint32 extern_kind;
// always be WASM_FUNCREF
/* always be WASM_FUNCREF */
wasm_valtype_t *type;
wasm_limits_t *limits;
};

View File

@ -791,6 +791,7 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env)
wasm_exec_env_destroy(exec_env);
}
#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_MEMORY_TRACING != 0)
void
wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module)
{
@ -872,7 +873,6 @@ wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env)
os_printf(" stack size: %u\n", exec_env->wasm_stack_size);
}
#if WASM_ENABLE_MEMORY_PROFILING != 0
uint32
gc_get_heap_highmark_size(void *heap);
@ -951,7 +951,8 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
os_printf("Total app heap used: %u\n", app_heap_peak_size);
}
#endif
#endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0)
|| (WASM_ENABLE_MEMORY_TRACING != 0) */
WASMModuleInstanceCommon *
wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
@ -2645,7 +2646,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
}
}
ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;
fail:
if (argv1 != argv_buf)
@ -2900,7 +2901,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;
ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;
fail:
if (argv1 != argv_buf)
@ -3053,7 +3054,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;
ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;
fail:
if (argv1 != argv_buf)
@ -3231,7 +3232,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;
ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;
fail:
if (argv1 != argv_buf)
wasm_runtime_free(argv1);

View File

@ -175,7 +175,7 @@ typedef struct WASMGlobalImport {
WASMValue global_data_linked;
#if WASM_ENABLE_MULTI_MODULE != 0
/* imported function pointer after linked */
// TODO: remove if not necessary
/* TODO: remove if not needed */
WASMModule *import_module;
WASMGlobal *import_global_linked;
#endif

View File

@ -3269,7 +3269,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
WASMFunctionInstance *function,
uint32 argc, uint32 argv[])
{
// TODO: since module_inst = exec_env->module_inst, shall we remove the 1st arg?
WASMRuntimeFrame *prev_frame = wasm_exec_env_get_cur_frame(exec_env);
WASMInterpFrame *frame, *outs_area;

View File

@ -1117,7 +1117,7 @@ wasm_interp_dump_op_count()
#if WASM_ENABLE_LABELS_AS_VALUES != 0
//#define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode
/* #define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode */
#if WASM_ENABLE_OPCODE_COUNTER != 0
#define HANDLE_OP(opcode) HANDLE_##opcode:opcode_table[opcode].count++;h_##opcode
#else

View File

@ -3961,7 +3961,7 @@ fail:
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)
// drop local.get / const / block / loop / end
/* drop local.get / const / block / loop / end */
#define skip_label() do { \
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
LOG_OP("\ndelete last op\n"); \
@ -4334,7 +4334,7 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
if (type == VALUE_TYPE_VOID)
return true;
// only check memory overflow in first traverse
/* only check memory overflow in first traverse */
if (ctx->p_code_compiled == NULL) {
if (!check_offset_push(ctx, error_buf, error_buf_size))
return false;
@ -5695,7 +5695,7 @@ handle_op_block_and_loop:
+ func->func_type->param_count + idx);
POP_TYPE(ret_type);
#if WASM_ENABLE_FAST_INTERP != 0
// emit the offset after return opcode
/* emit the offset after return opcode */
POP_OFFSET_TYPE(ret_type);
#endif
}
@ -5714,7 +5714,7 @@ handle_op_block_and_loop:
read_leb_uint32(p, p_end, func_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, func_idx);
#endif
@ -5769,7 +5769,7 @@ handle_op_block_and_loop:
read_leb_uint32(p, p_end, type_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, type_idx);
#endif

View File

@ -2890,7 +2890,7 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx,
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)
// drop local.get / const / block / loop / end
/* drop local.get / const / block / loop / end */
#define skip_label() do { \
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
LOG_OP("\ndelete last op\n"); \
@ -3264,7 +3264,7 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
if (type == VALUE_TYPE_VOID)
return true;
// only check memory overflow in first traverse
/* only check memory overflow in first traverse */
if (ctx->p_code_compiled == NULL) {
if (!check_offset_push(ctx, error_buf, error_buf_size))
return false;
@ -4525,7 +4525,7 @@ handle_op_block_and_loop:
+ func->func_type->param_count + idx);
POP_TYPE(ret_type);
#if WASM_ENABLE_FAST_INTERP != 0
// emit the offset after return opcode
/* emit the offset after return opcode */
POP_OFFSET_TYPE(ret_type);
#endif
}
@ -4544,7 +4544,7 @@ handle_op_block_and_loop:
read_leb_uint32(p, p_end, func_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, func_idx);
#endif
@ -4592,7 +4592,7 @@ handle_op_block_and_loop:
read_leb_uint32(p, p_end, type_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, type_idx);
#endif

View File

@ -330,15 +330,15 @@ memories_instantiate(const WASMModule *module,
#if WASM_ENABLE_MULTI_MODULE != 0
WASMMemoryInstance *memory_inst_linked = NULL;
if (import->u.memory.import_module != NULL) {
WASMModuleInstance *module_inst_linked;
LOG_DEBUG("(%s, %s) is a memory of a sub-module",
import->u.memory.module_name,
import->u.memory.field_name);
// TODO: how about native memory ?
WASMModuleInstance *module_inst_linked =
get_sub_module_inst(
module_inst,
import->u.memory.import_module);
module_inst_linked =
get_sub_module_inst(module_inst,
import->u.memory.import_module);
bh_assert(module_inst_linked);
memory_inst_linked =

View File

@ -112,38 +112,24 @@ int os_mutex_destroy(korp_mutex *mutex)
return ret == 0 ? BHT_OK : BHT_ERROR;
}
/* Returned error (EINVAL, EAGAIN and EDEADLK) from
locking the mutex indicates some logic error present in
the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_lock(korp_mutex *mutex)
{
int ret;
assert(mutex);
ret = pthread_mutex_lock(mutex);
if (0 != ret) {
os_printf("vm mutex lock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
return ret == 0 ? BHT_OK : BHT_ERROR;
}
/* Returned error (EINVAL, EAGAIN and EPERM) from
unlocking the mutex indicates some logic error present
in the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_unlock(korp_mutex *mutex)
{
int ret;
assert(mutex);
ret = pthread_mutex_unlock(mutex);
if (0 != ret) {
os_printf("vm mutex unlock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
return ret == 0 ? BHT_OK : BHT_ERROR;
}
int os_cond_init(korp_cond *cond)

View File

@ -36,11 +36,8 @@ os_mutex_lock(korp_mutex *mutex)
assert(mutex);
ret = pthread_mutex_lock(mutex);
if (0 != ret) {
os_printf("vm mutex lock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
return ret == 0 ? BHT_OK : BHT_ERROR;
}
int
@ -50,11 +47,8 @@ os_mutex_unlock(korp_mutex *mutex)
assert(mutex);
ret = pthread_mutex_unlock(mutex);
if (0 != ret) {
os_printf("vm mutex unlock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;
return ret == 0 ? BHT_OK : BHT_ERROR;
}
uint8 *

View File

@ -61,19 +61,11 @@ int os_mutex_destroy(korp_mutex *mutex)
return BHT_OK;
}
/* Returned error (EINVAL, EAGAIN and EDEADLK) from
locking the mutex indicates some logic error present in
the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_lock(korp_mutex *mutex)
{
return BHT_ERROR;
}
/* Returned error (EINVAL, EAGAIN and EPERM) from
unlocking the mutex indicates some logic error present
in the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_unlock(korp_mutex *mutex)
{
return BHT_OK;