Add two apis for wasm function call (#375)

Add below two apis:

bool wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
                                                      WASMFunctionInstanceCommon *function,
                                                      uint32 num_results, wasm_val_t results[],
                                                      uint32 num_args, wasm_val_t args[])

bool wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
                                                      WASMFunctionInstanceCommon *function,
                                                      uint32 num_results, wasm_val_t results[],
                                                      uint32 num_args, ...)

Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com>
This commit is contained in:
Xiaokang Qin
2020-09-08 13:03:35 +08:00
committed by GitHub
parent 2135badc54
commit 5418e09712
5 changed files with 359 additions and 3 deletions

View File

@ -165,6 +165,8 @@ static const uint32_t wasm_limits_max_default = 0xffffffff;
WASM_DECLARE_TYPE(valtype)
#ifndef WASM_VALKIND_T_DEFINED
#define WASM_VALKIND_T_DEFINED
typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
WASM_I32,
@ -174,6 +176,7 @@ enum wasm_valkind_enum {
WASM_ANYREF = 128,
WASM_FUNCREF,
};
#endif
WASM_API_EXTERN own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t);
@ -299,6 +302,8 @@ WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exportt
// Values
#ifndef WASM_VAL_T_DEFINED
#define WASM_VAL_T_DEFINED
struct wasm_ref_t;
typedef struct wasm_val_t {
@ -311,6 +316,7 @@ typedef struct wasm_val_t {
struct wasm_ref_t* ref;
} of;
} wasm_val_t;
#endif
WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);

View File

@ -120,6 +120,35 @@ typedef struct RuntimeInitArgs {
uint32_t max_thread_num;
} RuntimeInitArgs;
#ifndef WASM_VALKIND_T_DEFINED
#define WASM_VALKIND_T_DEFINED
typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
WASM_I32,
WASM_I64,
WASM_F32,
WASM_F64,
WASM_ANYREF = 128,
WASM_FUNCREF,
};
#endif
#ifndef WASM_VAL_T_DEFINED
#define WASM_VAL_T_DEFINED
struct wasm_ref_t;
typedef struct wasm_val_t {
wasm_valkind_t kind;
union {
int32_t i32;
int64_t i64;
float f32;
double f64;
struct wasm_ref_t* ref;
} of;
} wasm_val_t;
#endif
/**
* Initialize the WASM runtime environment, and also initialize
* the memory allocator with system allocator, which calls os_malloc
@ -385,6 +414,50 @@ wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
wasm_function_inst_t function,
uint32_t argc, uint32_t argv[]);
/**
* Call the given WASM function of a WASM module instance with
* provided results space and arguments (bytecode and AoT).
*
* @param exec_env the execution environment to call the function,
* which must be created from wasm_create_exec_env()
* @param function the function to call
* @param num_results the number of results
* @param results the pre-alloced pointer to get the results
* @param num_args the number of arguments
* @param args the arguments
*
* @return true if success, false otherwise and exception will be thrown,
* the caller can call wasm_runtime_get_exception to get the exception
* info.
*/
bool
wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
wasm_function_inst_t function,
uint32_t num_results, wasm_val_t results[],
uint32_t num_args, wasm_val_t *args);
/**
* Call the given WASM function of a WASM module instance with
* provided results space and variant arguments (bytecode and AoT).
*
* @param exec_env the execution environment to call the function,
* which must be created from wasm_create_exec_env()
* @param function the function to call
* @param num_results the number of results
* @param results the pre-alloced pointer to get the results
* @param num_args the number of arguments
* @param ... the variant arguments
*
* @return true if success, false otherwise and exception will be thrown,
* the caller can call wasm_runtime_get_exception to get the exception
* info.
*/
bool
wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
wasm_function_inst_t function,
uint32_t num_results, wasm_val_t results[],
uint32_t num_args, ...);
/**
* Find the unique main function from a WASM module instance
* and execute that function.