Clean up style issues

This commit is contained in:
Benbuck Nason 2024-04-19 17:25:58 -07:00
parent 6ec840d3e3
commit 2e7d41770e
2 changed files with 66 additions and 50 deletions

View File

@ -3597,8 +3597,8 @@ static union {
#define is_little_endian() (__ue.b == 1) /* NOLINT */ #define is_little_endian() (__ue.b == 1) /* NOLINT */
int32_t int32
wasm_runtime_get_import_count(const wasm_module_t module) wasm_runtime_get_import_count(WASMModuleCommon *const module)
{ {
if (!module) { if (!module) {
bh_assert(0); bh_assert(0);
@ -3608,16 +3608,16 @@ wasm_runtime_get_import_count(const wasm_module_t module)
#if WASM_ENABLE_AOT != 0 #if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT) { if (module->module_type == Wasm_Module_AoT) {
const AOTModule *aot_module = (const AOTModule *)module; const AOTModule *aot_module = (const AOTModule *)module;
return (int32_t)(aot_module->import_func_count return (int32)(aot_module->import_func_count
+ aot_module->import_global_count + aot_module->import_global_count
+ aot_module->import_table_count + aot_module->import_table_count
+ aot_module->import_memory_count); + aot_module->import_memory_count);
} }
#endif #endif
#if WASM_ENABLE_INTERP != 0 #if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode) { if (module->module_type == Wasm_Module_Bytecode) {
const WASMModule *wasm_module = (const WASMModule *)module; const WASMModule *wasm_module = (const WASMModule *)module;
return (int32_t)wasm_module->import_count; return (int32)wasm_module->import_count;
} }
#endif #endif
@ -3625,7 +3625,7 @@ wasm_runtime_get_import_count(const wasm_module_t module)
} }
void void
wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index, wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index,
wasm_import_type *import_type) wasm_import_type *import_type)
{ {
if (!import_type) { if (!import_type) {
@ -3644,12 +3644,7 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
if (module->module_type == Wasm_Module_AoT) { if (module->module_type == Wasm_Module_AoT) {
const AOTModule *aot_module = (const AOTModule *)module; const AOTModule *aot_module = (const AOTModule *)module;
if (import_index < 0) { uint32 func_index = (uint32)import_index;
bh_assert(0);
return;
}
uint32_t func_index = (uint32_t)import_index;
if (func_index < aot_module->import_func_count) { if (func_index < aot_module->import_func_count) {
const AOTImportFunc *aot_import_func = const AOTImportFunc *aot_import_func =
&aot_module->import_funcs[func_index]; &aot_module->import_funcs[func_index];
@ -3661,7 +3656,7 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
return; return;
} }
uint32_t global_index = func_index - aot_module->import_func_count; uint32 global_index = func_index - aot_module->import_func_count;
if (global_index < aot_module->import_global_count) { if (global_index < aot_module->import_global_count) {
const AOTImportGlobal *aot_import_global = const AOTImportGlobal *aot_import_global =
&aot_module->import_globals[global_index]; &aot_module->import_globals[global_index];
@ -3672,7 +3667,7 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
return; return;
} }
uint32_t table_index = global_index - aot_module->import_global_count; uint32 table_index = global_index - aot_module->import_global_count;
if (table_index < aot_module->import_table_count) { if (table_index < aot_module->import_table_count) {
const AOTImportTable *aot_import_table = const AOTImportTable *aot_import_table =
&aot_module->import_tables[table_index]; &aot_module->import_tables[table_index];
@ -3683,7 +3678,7 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
return; return;
} }
uint32_t memory_index = table_index - aot_module->import_table_count; uint32 memory_index = table_index - aot_module->import_table_count;
if (memory_index < aot_module->import_memory_count) { if (memory_index < aot_module->import_memory_count) {
const AOTImportMemory *aot_import_memory = const AOTImportMemory *aot_import_memory =
&aot_module->import_memories[memory_index]; &aot_module->import_memories[memory_index];
@ -3702,8 +3697,7 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
if (module->module_type == Wasm_Module_Bytecode) { if (module->module_type == Wasm_Module_Bytecode) {
const WASMModule *wasm_module = (const WASMModule *)module; const WASMModule *wasm_module = (const WASMModule *)module;
if ((import_index < 0) if ((uint32)import_index >= wasm_module->import_count) {
|| ((uint32_t)import_index >= wasm_module->import_count)) {
bh_assert(0); bh_assert(0);
return; return;
} }
@ -3738,8 +3732,8 @@ wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
#endif #endif
} }
int32_t int32
wasm_runtime_get_export_count(const wasm_module_t module) wasm_runtime_get_export_count(WASMModuleCommon *const module)
{ {
if (!module) { if (!module) {
bh_assert(0); bh_assert(0);
@ -3749,13 +3743,13 @@ wasm_runtime_get_export_count(const wasm_module_t module)
#if WASM_ENABLE_AOT != 0 #if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT) { if (module->module_type == Wasm_Module_AoT) {
const AOTModule *aot_module = (const AOTModule *)module; const AOTModule *aot_module = (const AOTModule *)module;
return (int32_t)aot_module->export_count; return (int32)aot_module->export_count;
} }
#endif #endif
#if WASM_ENABLE_INTERP != 0 #if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode) { if (module->module_type == Wasm_Module_Bytecode) {
const WASMModule *wasm_module = (const WASMModule *)module; const WASMModule *wasm_module = (const WASMModule *)module;
return (int32_t)wasm_module->export_count; return (int32)wasm_module->export_count;
} }
#endif #endif
@ -3763,7 +3757,7 @@ wasm_runtime_get_export_count(const wasm_module_t module)
} }
void void
wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index, wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
wasm_export_type *export_type) wasm_export_type *export_type)
{ {
if (!export_type) { if (!export_type) {
@ -3782,8 +3776,7 @@ wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index,
if (module->module_type == Wasm_Module_AoT) { if (module->module_type == Wasm_Module_AoT) {
const AOTModule *aot_module = (const AOTModule *)module; const AOTModule *aot_module = (const AOTModule *)module;
if ((export_index < 0) if ((uint32)export_index >= aot_module->export_count) {
|| ((uint32_t)export_index >= aot_module->export_count)) {
bh_assert(0); bh_assert(0);
return; return;
} }
@ -3798,8 +3791,7 @@ wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index,
if (module->module_type == Wasm_Module_Bytecode) { if (module->module_type == Wasm_Module_Bytecode) {
const WASMModule *wasm_module = (const WASMModule *)module; const WASMModule *wasm_module = (const WASMModule *)module;
if ((export_index < 0) if ((uint32)export_index >= wasm_module->export_count) {
|| ((uint32_t)export_index >= wasm_module->export_count)) {
bh_assert(0); bh_assert(0);
return; return;
} }

View File

@ -63,25 +63,22 @@ struct WASMModuleCommon;
typedef struct WASMModuleCommon *wasm_module_t; typedef struct WASMModuleCommon *wasm_module_t;
#endif #endif
typedef enum typedef enum {
{ WASM_IMPORT_EXPORT_KIND_FUNC,
WASM_IMPORT_EXPORT_KIND_FUNC, WASM_IMPORT_EXPORT_KIND_TABLE,
WASM_IMPORT_EXPORT_KIND_TABLE, WASM_IMPORT_EXPORT_KIND_MEMORY,
WASM_IMPORT_EXPORT_KIND_MEMORY, WASM_IMPORT_EXPORT_KIND_GLOBAL
WASM_IMPORT_EXPORT_KIND_GLOBAL
} wasm_import_export_kind_t; } wasm_import_export_kind_t;
typedef struct wasm_import_type typedef struct wasm_import_type {
{ const char *module_name;
const char * module_name; const char *name;
const char * name;
wasm_import_export_kind_t kind; wasm_import_export_kind_t kind;
bool linked; bool linked;
} wasm_import_type; } wasm_import_type;
typedef struct wasm_export_type typedef struct wasm_export_type {
{ const char *name;
const char * name;
wasm_import_export_kind_t kind; wasm_import_export_kind_t kind;
} wasm_export_type; } wasm_export_type;
@ -1179,20 +1176,47 @@ 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);
/**
* Get the number of import items for a WASM module
*
* @param module the WASM module
*
* @return the number of imports (zero for none), or -1 for failure
*/
WASM_RUNTIME_API_EXTERN int32_t
wasm_runtime_get_import_count(const wasm_module_t module);
WASM_RUNTIME_API_EXTERN int32_t wasm_runtime_get_import_count(const wasm_module_t module); /**
* Get information about a specific WASM module import
*
* @param module the WASM module
* @param import_index the desired import index
* @param import_type the location to store information about the import
*/
WASM_RUNTIME_API_EXTERN void WASM_RUNTIME_API_EXTERN void
wasm_runtime_get_import_type(const wasm_module_t module, wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
int32_t import_index, wasm_import_type *import_type);
wasm_import_type * import_type);
WASM_RUNTIME_API_EXTERN int32_t wasm_runtime_get_export_count(const wasm_module_t module); /**
* Get the number of export items for a WASM module
*
* @param module the WASM module
*
* @return the number of exports (zero for none), or -1 for failure
*/
WASM_RUNTIME_API_EXTERN int32_t
wasm_runtime_get_export_count(const wasm_module_t module);
/**
* Get information about a specific WASM module export
*
* @param module the WASM module
* @param export_index the desired export index
* @param export_type the location to store information about the export
*/
WASM_RUNTIME_API_EXTERN void WASM_RUNTIME_API_EXTERN void
wasm_runtime_get_export_type(const wasm_module_t module, wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index,
int32_t export_index, wasm_export_type *export_type);
wasm_export_type * export_type);
/** /**
* Register native functions with same module name * Register native functions with same module name