re-org bh_definition.c && introduce wamr fast interpreter (#189)
Co-authored-by: Xu Jun
This commit is contained in:
@ -7,18 +7,13 @@
|
||||
#define _WASM_NATIVE_H
|
||||
|
||||
#include "bh_common.h"
|
||||
#include "../include/wasm_export.h"
|
||||
#include "../interpreter/wasm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct NativeSymbol {
|
||||
const char *symbol;
|
||||
void *func_ptr;
|
||||
const char *signature;
|
||||
} NativeSymbol;
|
||||
|
||||
typedef struct NativeSymbolsNode {
|
||||
struct NativeSymbolsNode *next;
|
||||
const char *module_name;
|
||||
|
||||
@ -50,6 +50,49 @@ wasm_runtime_destroy()
|
||||
vm_thread_sys_destroy();
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_runtime_full_init(RuntimeInitArgs *init_args)
|
||||
{
|
||||
if (init_args->mem_alloc_type == Alloc_With_Pool) {
|
||||
void *heap_buf = init_args->mem_alloc.pool.heap_buf;
|
||||
uint32 heap_size = init_args->mem_alloc.pool.heap_size;
|
||||
if (bh_memory_init_with_pool(heap_buf, heap_size) != 0)
|
||||
return false;
|
||||
}
|
||||
else if (init_args->mem_alloc_type == Alloc_With_Allocator) {
|
||||
void *malloc_func = init_args->mem_alloc.allocator.malloc_func;
|
||||
void *free_func = init_args->mem_alloc.allocator.free_func;
|
||||
if (bh_memory_init_with_allocator(malloc_func, free_func) != 0)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
if (!wasm_runtime_init())
|
||||
goto fail1;
|
||||
|
||||
if (init_args->n_native_symbols > 0
|
||||
&& !wasm_runtime_register_natives(init_args->native_module_name,
|
||||
init_args->native_symbols,
|
||||
init_args->n_native_symbols))
|
||||
goto fail2;
|
||||
|
||||
return true;
|
||||
|
||||
fail2:
|
||||
wasm_runtime_destroy();
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
wasm_runtime_full_destroy()
|
||||
{
|
||||
wasm_runtime_destroy();
|
||||
bh_memory_destroy();
|
||||
}
|
||||
|
||||
PackageType
|
||||
get_package_type(const uint8 *buf, uint32 size)
|
||||
{
|
||||
@ -202,7 +245,7 @@ wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
|
||||
}
|
||||
|
||||
WASMFunctionInstanceCommon *
|
||||
wasm_runtime_lookup_function(const WASMModuleInstanceCommon *module_inst,
|
||||
wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst,
|
||||
const char *name,
|
||||
const char *signature)
|
||||
{
|
||||
@ -339,7 +382,7 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst)
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
return ((WASMModuleInstance*)module_inst)->custom_data;
|
||||
#endif
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT)
|
||||
return ((AOTModuleInstance*)module_inst)->custom_data.ptr;
|
||||
@ -619,7 +662,7 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env_list[], uint32 env_count,
|
||||
const char *argv[], uint32 argc)
|
||||
char *argv[], int argc)
|
||||
{
|
||||
WASIArguments *wasi_args = NULL;
|
||||
|
||||
@ -649,7 +692,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *argv[], uint32 argc,
|
||||
char *argv[], uint32 argc,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
WASIContext *wasi_ctx;
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "bh_thread.h"
|
||||
#include "wasm_exec_env.h"
|
||||
#include "wasm_native.h"
|
||||
#include "../include/wasm_export.h"
|
||||
#include "../interpreter/wasm.h"
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
#include "wasmtime_ssp.h"
|
||||
@ -24,13 +25,6 @@ extern "C" {
|
||||
#define wasm_malloc bh_malloc
|
||||
#define wasm_free bh_free
|
||||
|
||||
/* Package Type */
|
||||
typedef enum {
|
||||
Wasm_Module_Bytecode = 0,
|
||||
Wasm_Module_AoT,
|
||||
Package_Type_Unknown = 0xFFFF
|
||||
} PackageType;
|
||||
|
||||
typedef struct WASMModuleCommon {
|
||||
/* Module type, for module loaded from WASM bytecode binary,
|
||||
this field is Wasm_Module_Bytecode, and this structure should
|
||||
@ -53,19 +47,6 @@ typedef struct WASMModuleInstanceCommon {
|
||||
uint8 module_inst_data[1];
|
||||
} WASMModuleInstanceCommon;
|
||||
|
||||
typedef void WASMFunctionInstanceCommon;
|
||||
|
||||
/* WASM section */
|
||||
typedef struct WASMSection {
|
||||
struct WASMSection *next;
|
||||
/* section type */
|
||||
int section_type;
|
||||
/* section body, not include type and size */
|
||||
const uint8 *section_body;
|
||||
/* section body size */
|
||||
uint32 section_body_size;
|
||||
} WASMSection, AOTSection;
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
typedef struct WASIContext {
|
||||
struct fd_table *curfds;
|
||||
@ -74,6 +55,9 @@ typedef struct WASIContext {
|
||||
} WASIContext;
|
||||
#endif
|
||||
|
||||
typedef package_type_t PackageType;
|
||||
typedef wasm_section_t WASMSection, AOTSection;
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
wasm_runtime_init();
|
||||
@ -82,6 +66,14 @@ wasm_runtime_init();
|
||||
void
|
||||
wasm_runtime_destroy();
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
wasm_runtime_full_init(RuntimeInitArgs *init_args);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
void
|
||||
wasm_runtime_full_destroy();
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
PackageType
|
||||
get_package_type(const uint8 *buf, uint32 size);
|
||||
@ -112,7 +104,7 @@ wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASMFunctionInstanceCommon *
|
||||
wasm_runtime_lookup_function(const WASMModuleInstanceCommon *module_inst,
|
||||
wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst,
|
||||
const char *name, const char *signature);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
@ -245,7 +237,7 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env_list[], uint32 env_count,
|
||||
const char *argv[], uint32 argc);
|
||||
char *argv[], int argc);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
bool
|
||||
@ -260,7 +252,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||
const char *dir_list[], uint32 dir_count,
|
||||
const char *map_dir_list[], uint32 map_dir_count,
|
||||
const char *env[], uint32 env_count,
|
||||
const char *argv[], uint32 argc,
|
||||
char *argv[], uint32 argc,
|
||||
char *error_buf, uint32 error_buf_size);
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user