Enable call wasm-c-api native func directly from interpreter (#656)

And update loader error messages for latest spec cases, fix aot compiler build error based on latest LLVM code base.
This commit is contained in:
Wenyong Huang
2021-06-28 11:59:49 +08:00
committed by GitHub
parent c6783ef258
commit cba4c78273
13 changed files with 249 additions and 364 deletions

View File

@ -186,6 +186,8 @@ typedef struct WASMFunctionImport {
WASMModule *import_module;
WASMFunction *import_func_linked;
#endif
bool call_conv_wasm_c_api;
bool wasm_c_api_with_env;
} WASMFunctionImport;
typedef struct WASMGlobalImport {

View File

@ -753,7 +753,18 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
return;
}
if (!func_import->call_conv_raw) {
if (func_import->call_conv_wasm_c_api) {
ret = wasm_runtime_invoke_c_api_native(
(WASMModuleInstanceCommon *)module_inst,
func_import->func_ptr_linked, func_import->func_type,
cur_func->param_cell_num, frame->lp,
func_import->wasm_c_api_with_env, func_import->attachment);
if (ret) {
argv_ret[0] = frame->lp[0];
argv_ret[1] = frame->lp[1];
}
}
else if (!func_import->call_conv_raw) {
ret = wasm_runtime_invoke_native(exec_env, func_import->func_ptr_linked,
func_import->func_type, func_import->signature,
func_import->attachment,

View File

@ -826,7 +826,18 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
return;
}
if (!func_import->call_conv_raw) {
if (func_import->call_conv_wasm_c_api) {
ret = wasm_runtime_invoke_c_api_native(
(WASMModuleInstanceCommon *)module_inst,
func_import->func_ptr_linked, func_import->func_type,
cur_func->param_cell_num, frame->lp,
func_import->wasm_c_api_with_env, func_import->attachment);
if (ret) {
argv_ret[0] = frame->lp[0];
argv_ret[1] = frame->lp[1];
}
}
else if (!func_import->call_conv_raw) {
ret = wasm_runtime_invoke_native(exec_env, func_import->func_ptr_linked,
func_import->func_type, func_import->signature,
func_import->attachment,

View File

@ -2304,7 +2304,7 @@ check_table_index(const WASMModule *module, uint32 table_index,
!wasm_get_ref_types_flag() &&
#endif
table_index != 0) {
set_error_buf(error_buf, error_buf_size, "zero flag expected");
set_error_buf(error_buf, error_buf_size, "zero byte expected");
return false;
}
@ -7472,13 +7472,8 @@ handle_op_block_and_loop:
CHECK_MEMORY();
/* reserved byte 0x00 */
if (*p++ != 0x00) {
#if WASM_ENABLE_REF_TYPES != 0
set_error_buf(error_buf, error_buf_size,
"zero byte expected");
#else
set_error_buf(error_buf, error_buf_size,
"zero flag expected");
#endif
goto fail;
}
PUSH_I32();
@ -7490,13 +7485,8 @@ handle_op_block_and_loop:
CHECK_MEMORY();
/* reserved byte 0x00 */
if (*p++ != 0x00) {
#if WASM_ENABLE_REF_TYPES != 0
set_error_buf(error_buf, error_buf_size,
"zero byte expected");
#else
set_error_buf(error_buf, error_buf_size,
"zero flag expected");
#endif
goto fail;
}
POP_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_I32);
@ -7811,7 +7801,7 @@ handle_op_block_and_loop:
goto fail_unknown_memory;
if (*p++ != 0x00)
goto fail_zero_flag_expected;
goto fail_zero_byte_expected;
if (data_seg_idx >= module->data_seg_count) {
set_error_buf_v(error_buf, error_buf_size,
@ -7848,7 +7838,7 @@ handle_op_block_and_loop:
{
/* both src and dst memory index should be 0 */
if (*(int16*)p != 0x0000)
goto fail_zero_flag_expected;
goto fail_zero_byte_expected;
p += 2;
if (module->import_memory_count == 0 && module->memory_count == 0)
@ -7862,7 +7852,7 @@ handle_op_block_and_loop:
case WASM_OP_MEMORY_FILL:
{
if (*p++ != 0x00) {
goto fail_zero_flag_expected;
goto fail_zero_byte_expected;
}
if (module->import_memory_count == 0 && module->memory_count == 0) {
goto fail_unknown_memory;
@ -7872,9 +7862,9 @@ handle_op_block_and_loop:
POP_I32();
POP_I32();
break;
fail_zero_flag_expected:
fail_zero_byte_expected:
set_error_buf(error_buf, error_buf_size,
"zero flag expected");
"zero byte expected");
goto fail;
fail_unknown_memory:
@ -8460,7 +8450,7 @@ fail_data_cnt_sec_require:
/* reserved byte 0x00 */
if (*p++ != 0x00) {
set_error_buf(error_buf, error_buf_size,
"zero flag expected");
"zero byte expected");
goto fail;
}
break;