mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 16:58:34 +00:00
Add functions to expose module import/export info
This commit is contained in:
parent
0fa0beba94
commit
859ead7185
|
@ -3597,6 +3597,103 @@ static union {
|
||||||
|
|
||||||
#define is_little_endian() (__ue.b == 1) /* NOLINT */
|
#define is_little_endian() (__ue.b == 1) /* NOLINT */
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
wasm_runtime_import_count(const wasm_module_t module)
|
||||||
|
{
|
||||||
|
if (!module) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WASMModule *wasm_module = (const WASMModule *)module;
|
||||||
|
|
||||||
|
return wasm_module->import_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_import_info(const wasm_module_t module, uint32_t import_index,
|
||||||
|
wasm_import_info_t *import_info)
|
||||||
|
{
|
||||||
|
if (!import_info) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(import_info, 0, sizeof(wasm_import_info_t));
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const WASMModule *wasm_module = (const WASMModule *)module;
|
||||||
|
|
||||||
|
if (import_index >= wasm_module->import_count) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
import_info->module_name =
|
||||||
|
wasm_module->imports[import_index].u.names.module_name;
|
||||||
|
import_info->name = wasm_module->imports[import_index].u.names.field_name;
|
||||||
|
import_info->kind = wasm_module->imports[import_index].kind;
|
||||||
|
switch (import_info->kind) {
|
||||||
|
case WASM_IMPORT_EXPORT_KIND_FUNC:
|
||||||
|
import_info->linked =
|
||||||
|
wasm_module->imports[import_index].u.function.func_ptr_linked;
|
||||||
|
break;
|
||||||
|
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
|
||||||
|
import_info->linked =
|
||||||
|
wasm_module->imports[import_index].u.global.is_linked;
|
||||||
|
break;
|
||||||
|
case WASM_IMPORT_EXPORT_KIND_TABLE:
|
||||||
|
import_info->linked = true; /* is this correct? */
|
||||||
|
break;
|
||||||
|
case WASM_IMPORT_EXPORT_KIND_MEMORY:
|
||||||
|
import_info->linked = true; /* is this correct? */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bh_assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
wasm_runtime_export_count(const wasm_module_t module)
|
||||||
|
{
|
||||||
|
if (!module) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WASMModule *wasm_module = (const WASMModule *)module;
|
||||||
|
|
||||||
|
return wasm_module->export_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_export_info(const wasm_module_t module, uint32_t export_index,
|
||||||
|
wasm_export_info_t *export_info)
|
||||||
|
{
|
||||||
|
if (!export_info) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(export_info, 0, sizeof(wasm_export_info_t));
|
||||||
|
|
||||||
|
if (!module) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const WASMModule *wasm_module = (const WASMModule *)module;
|
||||||
|
|
||||||
|
if (export_index >= wasm_module->export_count) {
|
||||||
|
bh_assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
export_info->name = wasm_module->exports[export_index].name;
|
||||||
|
export_info->kind = wasm_module->exports[export_index].kind;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wasm_runtime_register_natives(const char *module_name,
|
wasm_runtime_register_natives(const char *module_name,
|
||||||
NativeSymbol *native_symbols,
|
NativeSymbol *native_symbols,
|
||||||
|
|
|
@ -63,6 +63,30 @@ struct WASMModuleCommon;
|
||||||
typedef struct WASMModuleCommon *wasm_module_t;
|
typedef struct WASMModuleCommon *wasm_module_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WASM_IMPORT_EXPORT_KIND_FUNC,
|
||||||
|
WASM_IMPORT_EXPORT_KIND_GLOBAL,
|
||||||
|
WASM_IMPORT_EXPORT_KIND_TABLE,
|
||||||
|
WASM_IMPORT_EXPORT_KIND_MEMORY,
|
||||||
|
} wasm_import_export_kind_t;
|
||||||
|
|
||||||
|
typedef struct wasm_import_info_t
|
||||||
|
{
|
||||||
|
const char * module_name;
|
||||||
|
const char * name;
|
||||||
|
wasm_import_export_kind_t kind;
|
||||||
|
bool linked;
|
||||||
|
} wasm_import_info_t;
|
||||||
|
|
||||||
|
typedef struct wasm_export_info_t
|
||||||
|
{
|
||||||
|
const char * name;
|
||||||
|
wasm_import_export_kind_t kind;
|
||||||
|
} wasm_export_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Instantiated WASM module */
|
/* Instantiated WASM module */
|
||||||
struct WASMModuleInstanceCommon;
|
struct WASMModuleInstanceCommon;
|
||||||
typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
|
typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
|
||||||
|
@ -1157,6 +1181,21 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
|
||||||
uint8_t **p_native_start_addr,
|
uint8_t **p_native_start_addr,
|
||||||
uint8_t **p_native_end_addr);
|
uint8_t **p_native_end_addr);
|
||||||
|
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_import_count(const wasm_module_t module);
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_import_info(const wasm_module_t module,
|
||||||
|
uint32_t import_index,
|
||||||
|
wasm_import_info_t * import_info);
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_export_count(const wasm_module_t module);
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_export_info(const wasm_module_t module,
|
||||||
|
uint32_t export_index,
|
||||||
|
wasm_export_info_t * export_info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register native functions with same module name
|
* Register native functions with same module name
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user