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

@ -81,7 +81,9 @@ endif ()
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
add_executable (iwasm main.c)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
install (TARGETS iwasm DESTINATION bin)

View File

@ -11,6 +11,7 @@
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_read_file.h"
#include "wasm_export.h"
static int app_argc;
@ -18,25 +19,25 @@ static char **app_argv;
static int print_help()
{
bh_printf("Usage: iwasm [-options] wasm_file [args...]\n");
bh_printf("options:\n");
bh_printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
printf("Usage: iwasm [-options] wasm_file [args...]\n");
printf("options:\n");
printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
#if WASM_ENABLE_LOG != 0
bh_printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
#endif
bh_printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
bh_printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
bh_printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of `FUNC ARG...`\n");
printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of `FUNC ARG...`\n");
#if WASM_ENABLE_LIBC_WASI != 0
bh_printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
bh_printf(" --dir=<dir> Grant wasi access to the given host directories\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --dir=<dir1> --dir=<dir2>\n");
printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
printf(" to the program, for example:\n");
printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
printf(" --dir=<dir> Grant wasi access to the given host directories\n");
printf(" to the program, for example:\n");
printf(" --dir=<dir1> --dir=<dir2>\n");
#endif
return 1;
@ -49,7 +50,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -100,7 +101,7 @@ app_instance_repl(wasm_module_inst_t module_inst)
size_t len = 0;
ssize_t n;
while ((bh_printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
bh_assert(n > 0);
if (cmd[n - 1] == '\n') {
if (n == 1)
@ -204,8 +205,8 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (dir_list_size >= sizeof(dir_list) / sizeof(char*)) {
bh_printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
return -1;
}
dir_list[dir_list_size++] = argv[0] + 6;
@ -216,16 +217,16 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (env_list_size >= sizeof(env_list) / sizeof(char*)) {
bh_printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
return -1;
}
tmp_env = argv[0] + 6;
if (validate_env_str(tmp_env))
env_list[env_list_size++] = tmp_env;
else {
bh_printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
return print_help();
}
}
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return -1;
}
@ -270,7 +271,7 @@ int main(int argc, char *argv[])
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}
@ -288,7 +289,7 @@ int main(int argc, char *argv[])
heap_size,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail3;
}