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:
@ -105,32 +105,30 @@ foreach(EX ${EXAMPLES})
|
||||
if (MSVC)
|
||||
target_compile_definitions(${EX} PRIVATE WASM_API_EXTERN=)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# wat to wasm
|
||||
foreach(EX ${EXAMPLES})
|
||||
set(SRC ${CMAKE_CURRENT_LIST_DIR}/src/${EX}.wat)
|
||||
# wat to wasm
|
||||
set(WAT ${CMAKE_CURRENT_LIST_DIR}/src/${EX}.wat)
|
||||
|
||||
add_custom_target(${EX}_WASM ALL
|
||||
COMMAND ${WAT2WASM} ${SRC} -o ${PROJECT_BINARY_DIR}/${EX}.wasm
|
||||
DEPENDS ${SRC}
|
||||
add_custom_target(${EX}_WASM
|
||||
COMMAND ${WAT2WASM} ${WAT} -o ${PROJECT_BINARY_DIR}/${EX}.wasm
|
||||
DEPENDS ${WAT}
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/${EX}.wasm
|
||||
VERBATIM
|
||||
SOURCES ${SRC}
|
||||
)
|
||||
add_dependencies(${EX} ${EX}_WASM)
|
||||
|
||||
# generate .aot file
|
||||
if(${WAMR_BUILD_AOT} EQUAL 1)
|
||||
if(EXISTS ${WAMRC})
|
||||
add_custom_target(${EX}_AOT ALL
|
||||
add_custom_target(${EX}_AOT
|
||||
COMMAND ${WAMRC} -o ${PROJECT_BINARY_DIR}/${EX}.aot
|
||||
${PROJECT_BINARY_DIR}/${EX}.wasm
|
||||
DEPENDS ${PROJECT_BINARY_DIR}/${EX}.wasm
|
||||
DEPENDS ${EX}_WASM
|
||||
BYPRODUCTS ${PROJECT_BINARY_DIR}/${EX}.aot
|
||||
VERBATIM
|
||||
SOURCES ${SRC}
|
||||
COMMENT "generate a aot file ${PROJECT_BINARY_DIR}/${EX}.aot"
|
||||
)
|
||||
add_dependencies(${EX} ${EX}_AOT)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@ -83,7 +83,7 @@ DEFINE_FUNCTION(log)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (data[length.of.i32]) {
|
||||
if (data[length.of.i32 - 1]) {
|
||||
printf("> Error terminated character\n");
|
||||
return NULL;
|
||||
}
|
||||
@ -188,7 +188,11 @@ main(int argc, const char *argv[])
|
||||
|
||||
// Load binary.
|
||||
printf("Loading binary...\n");
|
||||
#if WASM_ENABLE_AOT != 0 && WASM_ENABLE_INTERP == 0
|
||||
FILE *file = fopen("callback_chain.aot", "rb");
|
||||
#else
|
||||
FILE *file = fopen("callback_chain.wasm", "rb");
|
||||
#endif
|
||||
if (!file) {
|
||||
printf("> Error loading module!\n");
|
||||
return 1;
|
||||
|
||||
@ -56,15 +56,26 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
wasm_byte_vec_delete(&binary);
|
||||
|
||||
// Create external print functions.
|
||||
printf("Creating callback...\n");
|
||||
own wasm_functype_t* hello_type = wasm_functype_new_0_0();
|
||||
own wasm_func_t* hello_func =
|
||||
wasm_func_new(store, hello_type, hello_callback);
|
||||
|
||||
wasm_functype_delete(hello_type);
|
||||
|
||||
// Instantiate.
|
||||
printf("Instantiating module...\n");
|
||||
const wasm_extern_t* imports[] = { wasm_func_as_extern(hello_func) };
|
||||
own wasm_instance_t* instance =
|
||||
wasm_instance_new(store, module, NULL, NULL);
|
||||
wasm_instance_new(store, module, imports, NULL);
|
||||
if (!instance) {
|
||||
printf("> Error instantiating module!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wasm_func_delete(hello_func);
|
||||
|
||||
// Extract export.
|
||||
printf("Extracting export...\n");
|
||||
own wasm_extern_vec_t exports;
|
||||
@ -74,9 +85,22 @@ int main(int argc, const char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const wasm_func_t* run_func = wasm_extern_as_func(exports.data[0]);
|
||||
if (run_func == NULL) {
|
||||
printf("> Error accessing export!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wasm_module_delete(module);
|
||||
wasm_instance_delete(instance);
|
||||
|
||||
// Call.
|
||||
printf("Calling export...\n");
|
||||
if (wasm_func_call(run_func, NULL, NULL)) {
|
||||
printf("> Error calling function!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wasm_extern_vec_delete(&exports);
|
||||
|
||||
// Shut down.
|
||||
|
||||
Reference in New Issue
Block a user