re-org platform APIs, simplify porting process (#201)

Co-authored-by: Xu Jun <jun1.xu@intel.com>
This commit is contained in:
Xu Jun
2020-03-16 16:43:57 +08:00
committed by GitHub
parent ef5ceffe71
commit f1a0e75ab7
177 changed files with 2954 additions and 7904 deletions

View File

@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "config.h"
#include "bh_platform.h"
#include "bh_common.h"
#include "bh_assert.h"
@ -30,14 +29,10 @@ wasm_runtime_env_init()
if (bh_platform_init() != 0)
return false;
if (bh_log_init() != 0)
return false;
if (vm_thread_sys_init() != 0)
return false;
if (wasm_native_init() == false)
if (wasm_native_init() == false) {
bh_platform_destroy();
return false;
}
return true;
}
@ -60,7 +55,7 @@ void
wasm_runtime_destroy()
{
wasm_native_destroy();
vm_thread_sys_destroy();
bh_platform_destroy();
wasm_runtime_memory_destroy();
}
@ -273,7 +268,7 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env,
return false;
}
exec_env->handle = vm_self_thread();
exec_env->handle = os_self_thread();
#if WASM_ENABLE_INTERP != 0
if (exec_env->module_inst->module_type == Wasm_Module_Bytecode)
@ -1375,7 +1370,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
/* print return value */
switch (type->types[type->param_count]) {
case VALUE_TYPE_I32:
bh_printf("0x%x:i32", argv1[0]);
os_printf("0x%x:i32", argv1[0]);
break;
case VALUE_TYPE_I64:
{
@ -1387,22 +1382,22 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
snprintf(buf, sizeof(buf), "%s", "0x%llx:i64");
else
snprintf(buf, sizeof(buf), "%s", "0x%lx:i64");
bh_printf(buf, u.val);
os_printf(buf, u.val);
break;
}
case VALUE_TYPE_F32:
bh_printf("%.7g:f32", *(float32*)argv1);
os_printf("%.7g:f32", *(float32*)argv1);
break;
case VALUE_TYPE_F64:
{
union { float64 val; uint32 parts[2]; } u;
u.parts[0] = argv1[0];
u.parts[1] = argv1[1];
bh_printf("%.7g:f64", u.val);
os_printf("%.7g:f64", u.val);
break;
}
}
bh_printf("\n");
os_printf("\n");
wasm_runtime_free(argv1);
return true;
@ -1413,7 +1408,7 @@ fail:
exception = wasm_runtime_get_exception(module_inst);
bh_assert(exception);
bh_printf("%s\n", exception);
os_printf("%s\n", exception);
return false;
}