Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)

* Implement memory profiler, optimize memory usage, modify code indent

* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default

* Add a new extension library: connection

* Fix bug of reading magic number and version in big endian platform

* Re-org platform APIs: move most platform APIs from iwasm to shared-lib

* Enhance wasm loader to fix some security issues

* Fix issue about illegal load of EXC_RETURN into PC on stm32 board

* Updates that let a restricted version of the interpreter run in SGX

* Enable native/app address validation and conversion for wasm app

* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused

* Refine binary size and fix several minor issues

Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c

* Add more strict security checks for libc wrapper API's

* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files

* Enhance security of libc strcpy/sprintf wrapper function

* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions

* Remove get_module_inst() and fix issue of call native

* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate

* Refine interpreter call native process, refine memory boudary check

* Fix issues of invokeNative function of arm/mips/general version

* Add a switch to build simple sample without gui support

* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code

* Re-org shared lib header files, remove unused info; fix compile issues of vxworks

* Add build target general

* Remove unused files

* Update license header

* test push

* Restore file

* Sync up with internal/feature

* Sync up with internal/feature

* Rename build_wamr_app to build_wasm_app

* Fix small issues of README

* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc

* Sync up with internal/feature

* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue

* Sync up with internal/feature

* Fix bug of config.h and rename wasi config.h to ssp_config.h

* Sync up with internal/feature

* Import wamr aot

* update document

* update document

* Update document, disable WASI in 32bit

* update document

* remove files

* update document

* Update document

* update document

* update document

* update samples

* Sync up with internal repo
This commit is contained in:
wenyongh
2020-01-21 13:26:14 +08:00
committed by Wang Xin
parent 2a4528c749
commit 46b93b9d22
464 changed files with 25137 additions and 7911 deletions

View File

@ -0,0 +1,13 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (IWASM_INTERP_DIR ${CMAKE_CURRENT_LIST_DIR})
add_definitions (-DWASM_ENABLE_INTERP=1)
include_directories(${IWASM_INTERP_DIR})
file (GLOB_RECURSE source_all ${IWASM_INTERP_DIR}/*.c)
set (IWASM_INTERP_SOURCE ${source_all})

View File

@ -0,0 +1,407 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_H_
#define _WASM_H_
#include "bh_platform.h"
#include "bh_hashmap.h"
#include "bh_assert.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Value Type */
#define VALUE_TYPE_I32 0x7F
#define VALUE_TYPE_I64 0X7E
#define VALUE_TYPE_F32 0x7D
#define VALUE_TYPE_F64 0x7C
#define VALUE_TYPE_VOID 0x40
/* Used by AOT */
#define VALUE_TYPE_I1 0x41
/* Table Element Type */
#define TABLE_ELEM_TYPE_ANY_FUNC 0x70
#define MaxMemoryPages 65536
#define MaxTableElems UINT32_MAX
#define NumBytesPerPage 65536
#define NumBytesPerPageLog2 16
#define MaxReturnValues 16
#define INIT_EXPR_TYPE_I32_CONST 0x41
#define INIT_EXPR_TYPE_I64_CONST 0x42
#define INIT_EXPR_TYPE_F32_CONST 0x43
#define INIT_EXPR_TYPE_F64_CONST 0x44
#define INIT_EXPR_TYPE_GET_GLOBAL 0x23
#define INIT_EXPR_TYPE_ERROR 0xff
#define WASM_MAGIC_NUMBER 0x6d736100
#define WASM_CURRENT_VERSION 1
#define SECTION_TYPE_USER 0
#define SECTION_TYPE_TYPE 1
#define SECTION_TYPE_IMPORT 2
#define SECTION_TYPE_FUNC 3
#define SECTION_TYPE_TABLE 4
#define SECTION_TYPE_MEMORY 5
#define SECTION_TYPE_GLOBAL 6
#define SECTION_TYPE_EXPORT 7
#define SECTION_TYPE_START 8
#define SECTION_TYPE_ELEM 9
#define SECTION_TYPE_CODE 10
#define SECTION_TYPE_DATA 11
#define IMPORT_KIND_FUNC 0
#define IMPORT_KIND_TABLE 1
#define IMPORT_KIND_MEMORY 2
#define IMPORT_KIND_GLOBAL 3
#define EXPORT_KIND_FUNC 0
#define EXPORT_KIND_TABLE 1
#define EXPORT_KIND_MEMORY 2
#define EXPORT_KIND_GLOBAL 3
#define BLOCK_TYPE_BLOCK 0
#define BLOCK_TYPE_LOOP 1
#define BLOCK_TYPE_IF 2
#define BLOCK_TYPE_FUNCTION 3
typedef union WASMValue {
int32 i32;
uint32 u32;
int64 i64;
uint64 u64;
float32 f32;
float64 f64;
uintptr_t addr;
} WASMValue;
typedef struct InitializerExpression {
/* type of INIT_EXPR_TYPE_XXX */
uint8 init_expr_type;
union {
int32 i32;
int64 i64;
float32 f32;
float64 f64;
uint32 global_index;
} u;
} InitializerExpression;
typedef struct WASMType {
uint32 param_count;
/* only one result is supported currently */
uint32 result_count;
/* types of params and results */
uint8 types[1];
} WASMType;
typedef struct WASMTable {
uint8 elem_type;
uint32 flags;
uint32 init_size;
/* specified if (flags & 1), else it is 0x10000 */
uint32 max_size;
} WASMTable;
typedef struct WASMMemory {
uint32 flags;
/* 64 kbytes one page by default */
uint32 init_page_count;
uint32 max_page_count;
} WASMMemory;
typedef struct WASMTableImport {
char *module_name;
char *field_name;
uint8 elem_type;
uint32 flags;
uint32 init_size;
/* specified if (flags & 1), else it is 0x10000 */
uint32 max_size;
} WASMTableImport;
typedef struct WASMMemoryImport {
char *module_name;
char *field_name;
uint32 flags;
/* 64 kbytes one page by default */
uint32 init_page_count;
uint32 max_page_count;
} WASMMemoryImport;
typedef struct WASMFunctionImport {
char *module_name;
char *field_name;
/* function type */
WASMType *func_type;
/* function pointer after linked */
void *func_ptr_linked;
} WASMFunctionImport;
typedef struct WASMGlobalImport {
char *module_name;
char *field_name;
uint8 type;
bool is_mutable;
/* global data after linked */
WASMValue global_data_linked;
} WASMGlobalImport;
typedef struct WASMImport {
uint8 kind;
union {
WASMFunctionImport function;
WASMTableImport table;
WASMMemoryImport memory;
WASMGlobalImport global;
struct {
char *module_name;
char *field_name;
} names;
} u;
} WASMImport;
typedef struct WASMFunction {
/* the type of function */
WASMType *func_type;
uint32 local_count;
uint8 *local_types;
uint32 max_stack_cell_num;
uint32 max_block_num;
/* Whether function has opcode memory.grow */
bool has_op_memory_grow;
/* Whether function has opcode call or
call_indirect */
bool has_op_func_call;
uint32 code_size;
uint8 *code;
} WASMFunction;
typedef struct WASMGlobal {
uint8 type;
bool is_mutable;
InitializerExpression init_expr;
} WASMGlobal;
typedef struct WASMExport {
char *name;
uint8 kind;
uint32 index;
} WASMExport;
typedef struct WASMTableSeg {
uint32 table_index;
InitializerExpression base_offset;
uint32 function_count;
uint32 *func_indexes;
} WASMTableSeg;
typedef struct WASMDataSeg {
uint32 memory_index;
InitializerExpression base_offset;
uint32 data_length;
uint8 *data;
} WASMDataSeg;
typedef struct BlockAddr {
const uint8 *start_addr;
uint8 *else_addr;
uint8 *end_addr;
} BlockAddr;
#define BLOCK_ADDR_CACHE_SIZE 64
#define BLOCK_ADDR_CONFLICT_SIZE 4
#if WASM_ENABLE_LIBC_WASI != 0
typedef struct WASIArguments {
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;
} WASIArguments;
#endif
typedef struct WASMModule {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode;
for module loaded from AOT file, this field is
Wasm_Module_AoT, and this structure should be treated as
AOTModule structure. */
uint32 module_type;
uint32 type_count;
uint32 import_count;
uint32 function_count;
uint32 table_count;
uint32 memory_count;
uint32 global_count;
uint32 export_count;
uint32 table_seg_count;
uint32 data_seg_count;
uint32 import_function_count;
uint32 import_table_count;
uint32 import_memory_count;
uint32 import_global_count;
WASMImport *import_functions;
WASMImport *import_tables;
WASMImport *import_memories;
WASMImport *import_globals;
WASMType **types;
WASMImport *imports;
WASMFunction **functions;
WASMTable *tables;
WASMMemory *memories;
WASMGlobal *globals;
WASMExport *exports;
WASMTableSeg *table_segments;
WASMDataSeg **data_segments;
uint32 start_function;
/* Whether there is possible memory grow, e.g.
memory.grow opcode or call enlargeMemory */
bool possible_memory_grow;
HashMap *const_str_set;
BlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];
#if WASM_ENABLE_LIBC_WASI != 0
WASIArguments wasi_args;
bool is_wasi_module;
#endif
} WASMModule;
typedef struct WASMBranchBlock {
uint8 block_type;
uint8 return_type;
uint8 *start_addr;
uint8 *end_addr;
uint32 *frame_sp;
} WASMBranchBlock;
/* Execution environment, e.g. stack info */
/**
* Align an unsigned value on a alignment boundary.
*
* @param v the value to be aligned
* @param b the alignment boundary (2, 4, 8, ...)
*
* @return the aligned value
*/
inline static unsigned
align_uint (unsigned v, unsigned b)
{
unsigned m = b - 1;
return (v + m) & ~m;
}
/**
* Return the hash value of c string.
*/
inline static uint32
wasm_string_hash(const char *str)
{
unsigned h = (unsigned)strlen(str);
const uint8 *p = (uint8*)str;
const uint8 *end = p + h;
while (p != end)
h = ((h << 5) - h) + *p++;
return h;
}
/**
* Whether two c strings are equal.
*/
inline static bool
wasm_string_equal(const char *s1, const char *s2)
{
return strcmp(s1, s2) == 0 ? true : false;
}
/**
* Return the byte size of value type.
*
*/
inline static uint32
wasm_value_type_size(uint8 value_type)
{
switch (value_type) {
case VALUE_TYPE_I32:
case VALUE_TYPE_F32:
return sizeof(int32);
case VALUE_TYPE_I64:
case VALUE_TYPE_F64:
return sizeof(int64);
default:
bh_assert(0);
}
return 0;
}
inline static uint16
wasm_value_type_cell_num(uint8 value_type)
{
switch (value_type) {
case VALUE_TYPE_I32:
case VALUE_TYPE_F32:
return 1;
case VALUE_TYPE_I64:
case VALUE_TYPE_F64:
return 2;
default:
bh_assert(0);
}
return 0;
}
inline static uint16
wasm_get_cell_num(const uint8 *types, uint32 type_count)
{
uint32 cell_num = 0;
uint32 i;
for (i = 0; i < type_count; i++)
cell_num += wasm_value_type_cell_num(types[i]);
return (uint16)cell_num;
}
inline static uint16
wasm_type_param_cell_num(const WASMType *type)
{
return wasm_get_cell_num(type->types, type->param_count);
}
inline static uint16
wasm_type_return_cell_num(const WASMType *type)
{
return wasm_get_cell_num(type->types + type->param_count,
type->result_count);
}
inline static bool
wasm_type_equal(const WASMType *type1, const WASMType *type2)
{
return (type1->param_count == type2->param_count
&& type1->result_count == type2->result_count
&& memcmp(type1->types, type2->types,
type1->param_count + type1->result_count) == 0)
? true : false;
}
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* end of _WASM_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_INTERP_H
#define _WASM_INTERP_H
#include "wasm.h"
#ifdef __cplusplus
extern "C" {
#endif
struct WASMModuleInstance;
struct WASMFunctionInstance;
struct WASMExecEnv;
typedef struct WASMInterpFrame {
/* The frame of the caller that are calling the current function. */
struct WASMInterpFrame *prev_frame;
/* The current WASM function. */
struct WASMFunctionInstance *function;
/* Instruction pointer of the bytecode array. */
uint8 *ip;
/* Operand stack top pointer of the current frame. The bottom of
the stack is the next cell after the last local variable. */
uint32 *sp_bottom;
uint32 *sp_boundary;
uint32 *sp;
WASMBranchBlock *csp_bottom;
WASMBranchBlock *csp_boundary;
WASMBranchBlock *csp;
/* Frame data, the layout is:
lp: param_cell_count + local_cell_count
sp_bottom to sp_boundary: stack of data
csp_bottom to csp_boundary: stack of block
ref to frame end: data types of local vairables and stack data
*/
uint32 lp[1];
} WASMInterpFrame;
/**
* Calculate the size of interpreter area of frame of a function.
*
* @param all_cell_num number of all cells including local variables
* and the working stack slots
*
* @return the size of interpreter area of the frame
*/
static inline unsigned
wasm_interp_interp_frame_size(unsigned all_cell_num)
{
return align_uint((uint32)offsetof(WASMInterpFrame, lp)
+ all_cell_num * 5, 4);
}
void
wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
struct WASMExecEnv *exec_env,
struct WASMFunctionInstance *function,
uint32 argc, uint32 argv[]);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASM_INTERP_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_LOADER_H
#define _WASM_LOADER_H
#include "wasm.h"
#include "bh_hashmap.h"
#include "../common/wasm_runtime_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Load a WASM module from a specified byte buffer.
*
* @param buf the byte buffer which contains the WASM binary data
* @param size the size of the buffer
* @param error_buf output of the exception info
* @param error_buf_size the size of the exception string
*
* @return return module loaded, NULL if failed
*/
WASMModule*
wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size);
/**
* Load a WASM module from a specified WASM section list.
*
* @param section_list the section list which contains each section data
* @param error_buf output of the exception info
* @param error_buf_size the size of the exception string
*
* @return return WASM module loaded, NULL if failed
*/
WASMModule*
wasm_loader_load_from_sections(WASMSection *section_list,
char *error_buf, uint32 error_buf_size);
/**
* Unload a WASM module.
*
* @param module the module to be unloaded
*/
void
wasm_loader_unload(WASMModule *module);
/**
* Find address of related else opcode and end opcode of opcode block/loop/if
* according to the start address of opcode.
*
* @param module the module to find
* @param start_addr the next address of opcode block/loop/if
* @param code_end_addr the end address of function code block
* @param block_type the type of block, 0/1/2 denotes block/loop/if
* @param p_else_addr returns the else addr if found
* @param p_end_addr returns the end addr if found
* @param error_buf returns the error log for this function
* @param error_buf_size returns the error log string length
*
* @return true if success, false otherwise
*/
bool
wasm_loader_find_block_addr(WASMModule *module,
const uint8 *start_addr,
const uint8 *code_end_addr,
uint8 block_type,
uint8 **p_else_addr,
uint8 **p_end_addr,
char *error_buf,
uint32 error_buf_size);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASM_LOADER_H */

View File

@ -0,0 +1,461 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_OPCODE_H
#define _WASM_OPCODE_H
#include "wasm.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum WASMOpcode {
/* control instructions */
WASM_OP_UNREACHABLE = 0x00, /* unreachable */
WASM_OP_NOP = 0x01, /* nop */
WASM_OP_BLOCK = 0x02, /* block */
WASM_OP_LOOP = 0x03, /* loop */
WASM_OP_IF = 0x04, /* if */
WASM_OP_ELSE = 0x05, /* else */
WASM_OP_UNUSED_0x06 = 0x06,
WASM_OP_UNUSED_0x07 = 0x07,
WASM_OP_UNUSED_0x08 = 0x08,
WASM_OP_UNUSED_0x09 = 0x09,
WASM_OP_UNUSED_0x0a = 0x0a,
WASM_OP_END = 0x0b, /* end */
WASM_OP_BR = 0x0c, /* br */
WASM_OP_BR_IF = 0x0d, /* br if */
WASM_OP_BR_TABLE = 0x0e, /* br table */
WASM_OP_RETURN = 0x0f, /* return */
WASM_OP_CALL = 0x10, /* call */
WASM_OP_CALL_INDIRECT = 0x11, /* call_indirect */
WASM_OP_UNUSED_0x12 = 0x12,
WASM_OP_UNUSED_0x13 = 0x13,
WASM_OP_UNUSED_0x14 = 0x14,
WASM_OP_UNUSED_0x15 = 0x15,
WASM_OP_UNUSED_0x16 = 0x16,
WASM_OP_UNUSED_0x17 = 0x17,
WASM_OP_UNUSED_0x18 = 0x18,
WASM_OP_UNUSED_0x19 = 0x19,
/* parametric instructions */
WASM_OP_DROP = 0x1a, /* drop */
WASM_OP_SELECT = 0x1b, /* select */
WASM_OP_UNUSED_0x1c = 0x1c,
WASM_OP_UNUSED_0x1d = 0x1d,
WASM_OP_UNUSED_0x1e = 0x1e,
WASM_OP_UNUSED_0x1f = 0x1f,
/* variable instructions */
WASM_OP_GET_LOCAL = 0x20, /* get_local */
WASM_OP_SET_LOCAL = 0x21, /* set_local */
WASM_OP_TEE_LOCAL = 0x22, /* tee_local */
WASM_OP_GET_GLOBAL = 0x23, /* get_global */
WASM_OP_SET_GLOBAL = 0x24, /* set_global */
WASM_OP_UNUSED_0x25 = 0x25,
WASM_OP_UNUSED_0x26 = 0x26,
WASM_OP_UNUSED_0x27 = 0x27,
/* memory instructions */
WASM_OP_I32_LOAD = 0x28, /* i32.load */
WASM_OP_I64_LOAD = 0x29, /* i64.load */
WASM_OP_F32_LOAD = 0x2a, /* f32.load */
WASM_OP_F64_LOAD = 0x2b, /* f64.load */
WASM_OP_I32_LOAD8_S = 0x2c, /* i32.load8_s */
WASM_OP_I32_LOAD8_U = 0x2d, /* i32.load8_u */
WASM_OP_I32_LOAD16_S = 0x2e, /* i32.load16_s */
WASM_OP_I32_LOAD16_U = 0x2f, /* i32.load16_u */
WASM_OP_I64_LOAD8_S = 0x30, /* i64.load8_s */
WASM_OP_I64_LOAD8_U = 0x31, /* i64.load8_u */
WASM_OP_I64_LOAD16_S = 0x32, /* i64.load16_s */
WASM_OP_I64_LOAD16_U = 0x33, /* i64.load16_u */
WASM_OP_I64_LOAD32_S = 0x34, /* i32.load32_s */
WASM_OP_I64_LOAD32_U = 0x35, /* i32.load32_u */
WASM_OP_I32_STORE = 0x36, /* i32.store */
WASM_OP_I64_STORE = 0x37, /* i64.store */
WASM_OP_F32_STORE = 0x38, /* f32.store */
WASM_OP_F64_STORE = 0x39, /* f64.store */
WASM_OP_I32_STORE8 = 0x3a, /* i32.store8 */
WASM_OP_I32_STORE16 = 0x3b, /* i32.store16 */
WASM_OP_I64_STORE8 = 0x3c, /* i64.store8 */
WASM_OP_I64_STORE16 = 0x3d, /* i64.sotre16 */
WASM_OP_I64_STORE32 = 0x3e, /* i64.store32 */
WASM_OP_MEMORY_SIZE = 0x3f, /* memory.size */
WASM_OP_MEMORY_GROW = 0x40, /* memory.grow */
/* constant instructions */
WASM_OP_I32_CONST = 0x41, /* i32.const */
WASM_OP_I64_CONST = 0x42, /* i64.const */
WASM_OP_F32_CONST = 0x43, /* f32.const */
WASM_OP_F64_CONST = 0x44, /* f64.const */
/* comparison instructions */
WASM_OP_I32_EQZ = 0x45, /* i32.eqz */
WASM_OP_I32_EQ = 0x46, /* i32.eq */
WASM_OP_I32_NE = 0x47, /* i32.ne */
WASM_OP_I32_LT_S = 0x48, /* i32.lt_s */
WASM_OP_I32_LT_U = 0x49, /* i32.lt_u */
WASM_OP_I32_GT_S = 0x4a, /* i32.gt_s */
WASM_OP_I32_GT_U = 0x4b, /* i32.gt_u */
WASM_OP_I32_LE_S = 0x4c, /* i32.le_s */
WASM_OP_I32_LE_U = 0x4d, /* i32.le_u */
WASM_OP_I32_GE_S = 0x4e, /* i32.ge_s */
WASM_OP_I32_GE_U = 0x4f, /* i32.ge_u */
WASM_OP_I64_EQZ = 0x50, /* i64.eqz */
WASM_OP_I64_EQ = 0x51, /* i64.eq */
WASM_OP_I64_NE = 0x52, /* i64.ne */
WASM_OP_I64_LT_S = 0x53, /* i64.lt_s */
WASM_OP_I64_LT_U = 0x54, /* i64.lt_u */
WASM_OP_I64_GT_S = 0x55, /* i64.gt_s */
WASM_OP_I64_GT_U = 0x56, /* i64.gt_u */
WASM_OP_I64_LE_S = 0x57, /* i64.le_s */
WASM_OP_I64_LE_U = 0x58, /* i64.le_u */
WASM_OP_I64_GE_S = 0x59, /* i64.ge_s */
WASM_OP_I64_GE_U = 0x5a, /* i64.ge_u */
WASM_OP_F32_EQ = 0x5b, /* f32.eq */
WASM_OP_F32_NE = 0x5c, /* f32.ne */
WASM_OP_F32_LT = 0x5d, /* f32.lt */
WASM_OP_F32_GT = 0x5e, /* f32.gt */
WASM_OP_F32_LE = 0x5f, /* f32.le */
WASM_OP_F32_GE = 0x60, /* f32.ge */
WASM_OP_F64_EQ = 0x61, /* f64.eq */
WASM_OP_F64_NE = 0x62, /* f64.ne */
WASM_OP_F64_LT = 0x63, /* f64.lt */
WASM_OP_F64_GT = 0x64, /* f64.gt */
WASM_OP_F64_LE = 0x65, /* f64.le */
WASM_OP_F64_GE = 0x66, /* f64.ge */
/* numeric operators */
WASM_OP_I32_CLZ = 0x67, /* i32.clz */
WASM_OP_I32_CTZ = 0x68, /* i32.ctz */
WASM_OP_I32_POPCNT = 0x69, /* i32.popcnt */
WASM_OP_I32_ADD = 0x6a, /* i32.add */
WASM_OP_I32_SUB = 0x6b, /* i32.sub */
WASM_OP_I32_MUL = 0x6c, /* i32.mul */
WASM_OP_I32_DIV_S = 0x6d, /* i32.div_s */
WASM_OP_I32_DIV_U = 0x6e, /* i32.div_u */
WASM_OP_I32_REM_S = 0x6f, /* i32.rem_s */
WASM_OP_I32_REM_U = 0x70, /* i32.rem_u */
WASM_OP_I32_AND = 0x71, /* i32.and */
WASM_OP_I32_OR = 0x72, /* i32.or */
WASM_OP_I32_XOR = 0x73, /* i32.xor */
WASM_OP_I32_SHL = 0x74, /* i32.shl */
WASM_OP_I32_SHR_S = 0x75, /* i32.shr_s */
WASM_OP_I32_SHR_U = 0x76, /* i32.shr_u */
WASM_OP_I32_ROTL = 0x77, /* i32.rotl */
WASM_OP_I32_ROTR = 0x78, /* i32.rotr */
WASM_OP_I64_CLZ = 0x79, /* i64.clz */
WASM_OP_I64_CTZ = 0x7a, /* i64.ctz */
WASM_OP_I64_POPCNT = 0x7b, /* i64.popcnt */
WASM_OP_I64_ADD = 0x7c, /* i64.add */
WASM_OP_I64_SUB = 0x7d, /* i64.sub */
WASM_OP_I64_MUL = 0x7e, /* i64.mul */
WASM_OP_I64_DIV_S = 0x7f, /* i64.div_s */
WASM_OP_I64_DIV_U = 0x80, /* i64.div_u */
WASM_OP_I64_REM_S = 0x81, /* i64.rem_s */
WASM_OP_I64_REM_U = 0x82, /* i64.rem_u */
WASM_OP_I64_AND = 0x83, /* i64.and */
WASM_OP_I64_OR = 0x84, /* i64.or */
WASM_OP_I64_XOR = 0x85, /* i64.xor */
WASM_OP_I64_SHL = 0x86, /* i64.shl */
WASM_OP_I64_SHR_S = 0x87, /* i64.shr_s */
WASM_OP_I64_SHR_U = 0x88, /* i64.shr_u */
WASM_OP_I64_ROTL = 0x89, /* i64.rotl */
WASM_OP_I64_ROTR = 0x8a, /* i64.rotr */
WASM_OP_F32_ABS = 0x8b, /* f32.abs */
WASM_OP_F32_NEG = 0x8c, /* f32.neg */
WASM_OP_F32_CEIL = 0x8d, /* f32.ceil */
WASM_OP_F32_FLOOR = 0x8e, /* f32.floor */
WASM_OP_F32_TRUNC = 0x8f, /* f32.trunc */
WASM_OP_F32_NEAREST = 0x90, /* f32.nearest */
WASM_OP_F32_SQRT = 0x91, /* f32.sqrt */
WASM_OP_F32_ADD = 0x92, /* f32.add */
WASM_OP_F32_SUB = 0x93, /* f32.sub */
WASM_OP_F32_MUL = 0x94, /* f32.mul */
WASM_OP_F32_DIV = 0x95, /* f32.div */
WASM_OP_F32_MIN = 0x96, /* f32.min */
WASM_OP_F32_MAX = 0x97, /* f32.max */
WASM_OP_F32_COPYSIGN = 0x98, /* f32.copysign */
WASM_OP_F64_ABS = 0x99, /* f64.abs */
WASM_OP_F64_NEG = 0x9a, /* f64.neg */
WASM_OP_F64_CEIL = 0x9b, /* f64.ceil */
WASM_OP_F64_FLOOR = 0x9c, /* f64.floor */
WASM_OP_F64_TRUNC = 0x9d, /* f64.trunc */
WASM_OP_F64_NEAREST = 0x9e, /* f64.nearest */
WASM_OP_F64_SQRT = 0x9f, /* f64.sqrt */
WASM_OP_F64_ADD = 0xa0, /* f64.add */
WASM_OP_F64_SUB = 0xa1, /* f64.sub */
WASM_OP_F64_MUL = 0xa2, /* f64.mul */
WASM_OP_F64_DIV = 0xa3, /* f64.div */
WASM_OP_F64_MIN = 0xa4, /* f64.min */
WASM_OP_F64_MAX = 0xa5, /* f64.max */
WASM_OP_F64_COPYSIGN = 0xa6, /* f64.copysign */
/* conversions */
WASM_OP_I32_WRAP_I64 = 0xa7, /* i32.wrap/i64 */
WASM_OP_I32_TRUNC_S_F32 = 0xa8, /* i32.trunc_s/f32 */
WASM_OP_I32_TRUNC_U_F32 = 0xa9, /* i32.trunc_u/f32 */
WASM_OP_I32_TRUNC_S_F64 = 0xaa, /* i32.trunc_s/f64 */
WASM_OP_I32_TRUNC_U_F64 = 0xab, /* i32.trunc_u/f64 */
WASM_OP_I64_EXTEND_S_I32 = 0xac, /* i64.extend_s/i32 */
WASM_OP_I64_EXTEND_U_I32 = 0xad, /* i64.extend_u/i32 */
WASM_OP_I64_TRUNC_S_F32 = 0xae, /* i64.trunc_s/f32 */
WASM_OP_I64_TRUNC_U_F32 = 0xaf, /* i64.trunc_u/f32 */
WASM_OP_I64_TRUNC_S_F64 = 0xb0, /* i64.trunc_s/f64 */
WASM_OP_I64_TRUNC_U_F64 = 0xb1, /* i64.trunc_u/f64 */
WASM_OP_F32_CONVERT_S_I32 = 0xb2, /* f32.convert_s/i32 */
WASM_OP_F32_CONVERT_U_I32 = 0xb3, /* f32.convert_u/i32 */
WASM_OP_F32_CONVERT_S_I64 = 0xb4, /* f32.convert_s/i64 */
WASM_OP_F32_CONVERT_U_I64 = 0xb5, /* f32.convert_u/i64 */
WASM_OP_F32_DEMOTE_F64 = 0xb6, /* f32.demote/f64 */
WASM_OP_F64_CONVERT_S_I32 = 0xb7, /* f64.convert_s/i32 */
WASM_OP_F64_CONVERT_U_I32 = 0xb8, /* f64.convert_u/i32 */
WASM_OP_F64_CONVERT_S_I64 = 0xb9, /* f64.convert_s/i64 */
WASM_OP_F64_CONVERT_U_I64 = 0xba, /* f64.convert_u/i64 */
WASM_OP_F64_PROMOTE_F32 = 0xbb, /* f64.promote/f32 */
/* reinterpretations */
WASM_OP_I32_REINTERPRET_F32 = 0xbc, /* i32.reinterpret/f32 */
WASM_OP_I64_REINTERPRET_F64 = 0xbd, /* i64.reinterpret/f64 */
WASM_OP_F32_REINTERPRET_I32 = 0xbe, /* f32.reinterpret/i32 */
WASM_OP_F64_REINTERPRET_I64 = 0xbf, /* f64.reinterpret/i64 */
/* drop/select specified types*/
WASM_OP_DROP_32 = 0xc0,
WASM_OP_DROP_64 = 0xc1,
WASM_OP_SELECT_32 = 0xc2,
WASM_OP_SELECT_64 = 0xc3,
WASM_OP_IMPDEP1 = WASM_OP_SELECT_64 + 1,
WASM_OP_IMPDEP2 = WASM_OP_IMPDEP1 + 1
} WASMOpcode;
#ifdef __cplusplus
}
#endif
/*
* Macro used to generate computed goto tables for the C interpreter.
*/
#define WASM_INSTRUCTION_NUM 256
#define DEFINE_GOTO_TABLE(_name) \
static const void *_name[WASM_INSTRUCTION_NUM] = { \
HANDLE_OPCODE (WASM_OP_UNREACHABLE), /* 0x00 */ \
HANDLE_OPCODE (WASM_OP_NOP), /* 0x01 */ \
HANDLE_OPCODE (WASM_OP_BLOCK), /* 0x02 */ \
HANDLE_OPCODE (WASM_OP_LOOP), /* 0x03 */ \
HANDLE_OPCODE (WASM_OP_IF), /* 0x04 */ \
HANDLE_OPCODE (WASM_OP_ELSE), /* 0x05 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x06), /* 0x06 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x07), /* 0x07 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x08), /* 0x08 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x09), /* 0x09 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x0a), /* 0x0a */ \
HANDLE_OPCODE (WASM_OP_END), /* 0x0b */ \
HANDLE_OPCODE (WASM_OP_BR), /* 0x0c */ \
HANDLE_OPCODE (WASM_OP_BR_IF), /* 0x0d */ \
HANDLE_OPCODE (WASM_OP_BR_TABLE), /* 0x0e */ \
HANDLE_OPCODE (WASM_OP_RETURN), /* 0x0f */ \
HANDLE_OPCODE (WASM_OP_CALL), /* 0x10 */ \
HANDLE_OPCODE (WASM_OP_CALL_INDIRECT), /* 0x11 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x12), /* 0x12 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x13), /* 0x13 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x14), /* 0x14 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x15), /* 0x15 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x16), /* 0x16 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x17), /* 0x17 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x18), /* 0x18 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x19), /* 0x19 */ \
HANDLE_OPCODE (WASM_OP_DROP), /* 0x1a */ \
HANDLE_OPCODE (WASM_OP_SELECT), /* 0x1b */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x1c), /* 0x1c */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x1d), /* 0x1d */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x1e), /* 0x1e */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x1f), /* 0x1f */ \
HANDLE_OPCODE (WASM_OP_GET_LOCAL), /* 0x20 */ \
HANDLE_OPCODE (WASM_OP_SET_LOCAL), /* 0x21 */ \
HANDLE_OPCODE (WASM_OP_TEE_LOCAL), /* 0x22 */ \
HANDLE_OPCODE (WASM_OP_GET_GLOBAL), /* 0x23 */ \
HANDLE_OPCODE (WASM_OP_SET_GLOBAL), /* 0x24 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x25), /* 0x25 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x26), /* 0x26 */ \
HANDLE_OPCODE (WASM_OP_UNUSED_0x27), /* 0x27 */ \
HANDLE_OPCODE (WASM_OP_I32_LOAD), /* 0x28 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD), /* 0x29 */ \
HANDLE_OPCODE (WASM_OP_F32_LOAD), /* 0x2a */ \
HANDLE_OPCODE (WASM_OP_F64_LOAD), /* 0x2b */ \
HANDLE_OPCODE (WASM_OP_I32_LOAD8_S), /* 0x2c */ \
HANDLE_OPCODE (WASM_OP_I32_LOAD8_U), /* 0x2d */ \
HANDLE_OPCODE (WASM_OP_I32_LOAD16_S), /* 0x2e */ \
HANDLE_OPCODE (WASM_OP_I32_LOAD16_U), /* 0x2f */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD8_S), /* 0x30 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD8_U), /* 0x31 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD16_S), /* 0x32 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD16_U), /* 0x33 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD32_S), /* 0x34 */ \
HANDLE_OPCODE (WASM_OP_I64_LOAD32_U), /* 0x35 */ \
HANDLE_OPCODE (WASM_OP_I32_STORE), /* 0x36 */ \
HANDLE_OPCODE (WASM_OP_I64_STORE), /* 0x37 */ \
HANDLE_OPCODE (WASM_OP_F32_STORE), /* 0x38 */ \
HANDLE_OPCODE (WASM_OP_F64_STORE), /* 0x39 */ \
HANDLE_OPCODE (WASM_OP_I32_STORE8), /* 0x3a */ \
HANDLE_OPCODE (WASM_OP_I32_STORE16), /* 0x3b */ \
HANDLE_OPCODE (WASM_OP_I64_STORE8), /* 0x3c */ \
HANDLE_OPCODE (WASM_OP_I64_STORE16), /* 0x3d */ \
HANDLE_OPCODE (WASM_OP_I64_STORE32), /* 0x3e */ \
HANDLE_OPCODE (WASM_OP_MEMORY_SIZE), /* 0x3f */ \
HANDLE_OPCODE (WASM_OP_MEMORY_GROW), /* 0x40 */ \
HANDLE_OPCODE (WASM_OP_I32_CONST), /* 0x41 */ \
HANDLE_OPCODE (WASM_OP_I64_CONST), /* 0x42 */ \
HANDLE_OPCODE (WASM_OP_F32_CONST), /* 0x43 */ \
HANDLE_OPCODE (WASM_OP_F64_CONST), /* 0x44 */ \
HANDLE_OPCODE (WASM_OP_I32_EQZ), /* 0x45 */ \
HANDLE_OPCODE (WASM_OP_I32_EQ), /* 0x46 */ \
HANDLE_OPCODE (WASM_OP_I32_NE), /* 0x47 */ \
HANDLE_OPCODE (WASM_OP_I32_LT_S), /* 0x48 */ \
HANDLE_OPCODE (WASM_OP_I32_LT_U), /* 0x49 */ \
HANDLE_OPCODE (WASM_OP_I32_GT_S), /* 0x4a */ \
HANDLE_OPCODE (WASM_OP_I32_GT_U), /* 0x4b */ \
HANDLE_OPCODE (WASM_OP_I32_LE_S), /* 0x4c */ \
HANDLE_OPCODE (WASM_OP_I32_LE_U), /* 0x4d */ \
HANDLE_OPCODE (WASM_OP_I32_GE_S), /* 0x4e */ \
HANDLE_OPCODE (WASM_OP_I32_GE_U), /* 0x4f */ \
HANDLE_OPCODE (WASM_OP_I64_EQZ), /* 0x50 */ \
HANDLE_OPCODE (WASM_OP_I64_EQ), /* 0x51 */ \
HANDLE_OPCODE (WASM_OP_I64_NE), /* 0x52 */ \
HANDLE_OPCODE (WASM_OP_I64_LT_S), /* 0x53 */ \
HANDLE_OPCODE (WASM_OP_I64_LT_U), /* 0x54 */ \
HANDLE_OPCODE (WASM_OP_I64_GT_S), /* 0x55 */ \
HANDLE_OPCODE (WASM_OP_I64_GT_U), /* 0x56 */ \
HANDLE_OPCODE (WASM_OP_I64_LE_S), /* 0x57 */ \
HANDLE_OPCODE (WASM_OP_I64_LE_U), /* 0x58 */ \
HANDLE_OPCODE (WASM_OP_I64_GE_S), /* 0x59 */ \
HANDLE_OPCODE (WASM_OP_I64_GE_U), /* 0x5a */ \
HANDLE_OPCODE (WASM_OP_F32_EQ), /* 0x5b */ \
HANDLE_OPCODE (WASM_OP_F32_NE), /* 0x5c */ \
HANDLE_OPCODE (WASM_OP_F32_LT), /* 0x5d */ \
HANDLE_OPCODE (WASM_OP_F32_GT), /* 0x5e */ \
HANDLE_OPCODE (WASM_OP_F32_LE), /* 0x5f */ \
HANDLE_OPCODE (WASM_OP_F32_GE), /* 0x60 */ \
HANDLE_OPCODE (WASM_OP_F64_EQ), /* 0x61 */ \
HANDLE_OPCODE (WASM_OP_F64_NE), /* 0x62 */ \
HANDLE_OPCODE (WASM_OP_F64_LT), /* 0x63 */ \
HANDLE_OPCODE (WASM_OP_F64_GT), /* 0x64 */ \
HANDLE_OPCODE (WASM_OP_F64_LE), /* 0x65 */ \
HANDLE_OPCODE (WASM_OP_F64_GE), /* 0x66 */ \
HANDLE_OPCODE (WASM_OP_I32_CLZ), /* 0x67 */ \
HANDLE_OPCODE (WASM_OP_I32_CTZ), /* 0x68 */ \
HANDLE_OPCODE (WASM_OP_I32_POPCNT), /* 0x69 */ \
HANDLE_OPCODE (WASM_OP_I32_ADD), /* 0x6a */ \
HANDLE_OPCODE (WASM_OP_I32_SUB), /* 0x6b */ \
HANDLE_OPCODE (WASM_OP_I32_MUL), /* 0x6c */ \
HANDLE_OPCODE (WASM_OP_I32_DIV_S), /* 0x6d */ \
HANDLE_OPCODE (WASM_OP_I32_DIV_U), /* 0x6e */ \
HANDLE_OPCODE (WASM_OP_I32_REM_S), /* 0x6f */ \
HANDLE_OPCODE (WASM_OP_I32_REM_U), /* 0x70 */ \
HANDLE_OPCODE (WASM_OP_I32_AND), /* 0x71 */ \
HANDLE_OPCODE (WASM_OP_I32_OR), /* 0x72 */ \
HANDLE_OPCODE (WASM_OP_I32_XOR), /* 0x73 */ \
HANDLE_OPCODE (WASM_OP_I32_SHL), /* 0x74 */ \
HANDLE_OPCODE (WASM_OP_I32_SHR_S), /* 0x75 */ \
HANDLE_OPCODE (WASM_OP_I32_SHR_U), /* 0x76 */ \
HANDLE_OPCODE (WASM_OP_I32_ROTL), /* 0x77 */ \
HANDLE_OPCODE (WASM_OP_I32_ROTR), /* 0x78 */ \
HANDLE_OPCODE (WASM_OP_I64_CLZ), /* 0x79 */ \
HANDLE_OPCODE (WASM_OP_I64_CTZ), /* 0x7a */ \
HANDLE_OPCODE (WASM_OP_I64_POPCNT), /* 0x7b */ \
HANDLE_OPCODE (WASM_OP_I64_ADD), /* 0x7c */ \
HANDLE_OPCODE (WASM_OP_I64_SUB), /* 0x7d */ \
HANDLE_OPCODE (WASM_OP_I64_MUL), /* 0x7e */ \
HANDLE_OPCODE (WASM_OP_I64_DIV_S), /* 0x7f */ \
HANDLE_OPCODE (WASM_OP_I64_DIV_U), /* 0x80 */ \
HANDLE_OPCODE (WASM_OP_I64_REM_S), /* 0x81 */ \
HANDLE_OPCODE (WASM_OP_I64_REM_U), /* 0x82 */ \
HANDLE_OPCODE (WASM_OP_I64_AND), /* 0x83 */ \
HANDLE_OPCODE (WASM_OP_I64_OR), /* 0x84 */ \
HANDLE_OPCODE (WASM_OP_I64_XOR), /* 0x85 */ \
HANDLE_OPCODE (WASM_OP_I64_SHL), /* 0x86 */ \
HANDLE_OPCODE (WASM_OP_I64_SHR_S), /* 0x87 */ \
HANDLE_OPCODE (WASM_OP_I64_SHR_U), /* 0x88 */ \
HANDLE_OPCODE (WASM_OP_I64_ROTL), /* 0x89 */ \
HANDLE_OPCODE (WASM_OP_I64_ROTR), /* 0x8a */ \
HANDLE_OPCODE (WASM_OP_F32_ABS), /* 0x8b */ \
HANDLE_OPCODE (WASM_OP_F32_NEG), /* 0x8c */ \
HANDLE_OPCODE (WASM_OP_F32_CEIL), /* 0x8d */ \
HANDLE_OPCODE (WASM_OP_F32_FLOOR), /* 0x8e */ \
HANDLE_OPCODE (WASM_OP_F32_TRUNC), /* 0x8f */ \
HANDLE_OPCODE (WASM_OP_F32_NEAREST), /* 0x90 */ \
HANDLE_OPCODE (WASM_OP_F32_SQRT), /* 0x91 */ \
HANDLE_OPCODE (WASM_OP_F32_ADD), /* 0x92 */ \
HANDLE_OPCODE (WASM_OP_F32_SUB), /* 0x93 */ \
HANDLE_OPCODE (WASM_OP_F32_MUL), /* 0x94 */ \
HANDLE_OPCODE (WASM_OP_F32_DIV), /* 0x95 */ \
HANDLE_OPCODE (WASM_OP_F32_MIN), /* 0x96 */ \
HANDLE_OPCODE (WASM_OP_F32_MAX), /* 0x97 */ \
HANDLE_OPCODE (WASM_OP_F32_COPYSIGN), /* 0x98 */ \
HANDLE_OPCODE (WASM_OP_F64_ABS), /* 0x99 */ \
HANDLE_OPCODE (WASM_OP_F64_NEG), /* 0x9a */ \
HANDLE_OPCODE (WASM_OP_F64_CEIL), /* 0x9b */ \
HANDLE_OPCODE (WASM_OP_F64_FLOOR), /* 0x9c */ \
HANDLE_OPCODE (WASM_OP_F64_TRUNC), /* 0x9d */ \
HANDLE_OPCODE (WASM_OP_F64_NEAREST), /* 0x9e */ \
HANDLE_OPCODE (WASM_OP_F64_SQRT), /* 0x9f */ \
HANDLE_OPCODE (WASM_OP_F64_ADD), /* 0xa0 */ \
HANDLE_OPCODE (WASM_OP_F64_SUB), /* 0xa1 */ \
HANDLE_OPCODE (WASM_OP_F64_MUL), /* 0xa2 */ \
HANDLE_OPCODE (WASM_OP_F64_DIV), /* 0xa3 */ \
HANDLE_OPCODE (WASM_OP_F64_MIN), /* 0xa4 */ \
HANDLE_OPCODE (WASM_OP_F64_MAX), /* 0xa5 */ \
HANDLE_OPCODE (WASM_OP_F64_COPYSIGN), /* 0xa6 */ \
HANDLE_OPCODE (WASM_OP_I32_WRAP_I64), /* 0xa7 */ \
HANDLE_OPCODE (WASM_OP_I32_TRUNC_S_F32), /* 0xa8 */ \
HANDLE_OPCODE (WASM_OP_I32_TRUNC_U_F32), /* 0xa9 */ \
HANDLE_OPCODE (WASM_OP_I32_TRUNC_S_F64), /* 0xaa */ \
HANDLE_OPCODE (WASM_OP_I32_TRUNC_U_F64), /* 0xab */ \
HANDLE_OPCODE (WASM_OP_I64_EXTEND_S_I32), /* 0xac */ \
HANDLE_OPCODE (WASM_OP_I64_EXTEND_U_I32), /* 0xad */ \
HANDLE_OPCODE (WASM_OP_I64_TRUNC_S_F32), /* 0xae */ \
HANDLE_OPCODE (WASM_OP_I64_TRUNC_U_F32), /* 0xaf */ \
HANDLE_OPCODE (WASM_OP_I64_TRUNC_S_F64), /* 0xb0 */ \
HANDLE_OPCODE (WASM_OP_I64_TRUNC_U_F64), /* 0xb1 */ \
HANDLE_OPCODE (WASM_OP_F32_CONVERT_S_I32), /* 0xb2 */ \
HANDLE_OPCODE (WASM_OP_F32_CONVERT_U_I32), /* 0xb3 */ \
HANDLE_OPCODE (WASM_OP_F32_CONVERT_S_I64), /* 0xb4 */ \
HANDLE_OPCODE (WASM_OP_F32_CONVERT_U_I64), /* 0xb5 */ \
HANDLE_OPCODE (WASM_OP_F32_DEMOTE_F64), /* 0xb6 */ \
HANDLE_OPCODE (WASM_OP_F64_CONVERT_S_I32), /* 0xb7 */ \
HANDLE_OPCODE (WASM_OP_F64_CONVERT_U_I32), /* 0xb8 */ \
HANDLE_OPCODE (WASM_OP_F64_CONVERT_S_I64), /* 0xb9 */ \
HANDLE_OPCODE (WASM_OP_F64_CONVERT_U_I64), /* 0xba */ \
HANDLE_OPCODE (WASM_OP_F64_PROMOTE_F32), /* 0xbb */ \
HANDLE_OPCODE (WASM_OP_I32_REINTERPRET_F32), /* 0xbc */ \
HANDLE_OPCODE (WASM_OP_I64_REINTERPRET_F64), /* 0xbd */ \
HANDLE_OPCODE (WASM_OP_F32_REINTERPRET_I32), /* 0xbe */ \
HANDLE_OPCODE (WASM_OP_F64_REINTERPRET_I64), /* 0xbf */ \
HANDLE_OPCODE (WASM_OP_DROP_32), /* 0xc0 */ \
HANDLE_OPCODE (WASM_OP_DROP_64), /* 0xc1 */ \
HANDLE_OPCODE (WASM_OP_SELECT_32), /* 0xc2 */ \
HANDLE_OPCODE (WASM_OP_SELECT_64), /* 0xc3 */ \
HANDLE_OPCODE (WASM_OP_IMPDEP1), /* 0xc4 */ \
HANDLE_OPCODE (WASM_OP_IMPDEP2), /* 0xc5 */ \
}
#endif /* end of _WASM_OPCODE_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,272 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASM_RUNTIME_H
#define _WASM_RUNTIME_H
#include "wasm.h"
#include "bh_hashmap.h"
#include "../common/wasm_runtime_common.h"
#include "../common/wasm_exec_env.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct WASMMemoryInstance {
/* Current page count */
uint32 cur_page_count;
/* Maximum page count */
uint32 max_page_count;
/* Heap data base address */
uint8 *heap_data;
/* Heap data end address */
uint8 *heap_data_end;
/* The heap created */
void *heap_handle;
/* Heap base offset of wasm app */
int32 heap_base_offset;
/* Memory data */
uint8 *memory_data;
/* Global data of global instances */
uint8 *global_data;
uint32 global_data_size;
/* End address of memory */
uint8 *end_addr;
/* Base address, the layout is:
thunk_argv data + thunk arg offsets +
memory data + global data
memory data init size is: NumBytesPerPage * cur_page_count
global data size is calculated in module instantiating
Note: when memory is re-allocated, the thunk argv data, thunk
argv offsets and memory data must be copied to new memory also.
*/
uint8 base_addr[1];
} WASMMemoryInstance;
typedef struct WASMTableInstance {
/* The element type, TABLE_ELEM_TYPE_ANY_FUNC currently */
uint8 elem_type;
/* Current size */
uint32 cur_size;
/* Maximum size */
uint32 max_size;
/* Base address */
uint8 base_addr[1];
} WASMTableInstance;
typedef struct WASMGlobalInstance {
/* value type, VALUE_TYPE_I32/I64/F32/F64 */
uint8 type;
/* mutable or constant */
bool is_mutable;
/* data offset to base_addr of WASMMemoryInstance */
uint32 data_offset;
/* initial value */
WASMValue initial_value;
} WASMGlobalInstance;
typedef struct WASMFunctionInstance {
/* whether it is import function or WASM function */
bool is_import_func;
/* parameter count */
uint16 param_count;
/* local variable count, 0 for import function */
uint16 local_count;
/* cell num of parameters */
uint16 param_cell_num;
/* cell num of return type */
uint16 ret_cell_num;
/* cell num of local variables, 0 for import function */
uint16 local_cell_num;
uint16 *local_offsets;
/* parameter types */
uint8 *param_types;
/* local types, NULL for import function */
uint8 *local_types;
union {
WASMFunctionImport *func_import;
WASMFunction *func;
} u;
} WASMFunctionInstance;
typedef struct WASMExportFuncInstance {
char *name;
WASMFunctionInstance *function;
} WASMExportFuncInstance;
typedef struct WASMModuleInstance {
/* Module instance type, for module instance loaded from
WASM bytecode binary, this field is Wasm_Module_Bytecode;
for module instance loaded from AOT file, this field is
Wasm_Module_AoT, and this structure should be treated as
AOTModuleInstance structure. */
uint32 module_type;
uint32 memory_count;
uint32 table_count;
uint32 global_count;
uint32 function_count;
uint32 export_func_count;
WASMMemoryInstance **memories;
WASMTableInstance **tables;
WASMGlobalInstance *globals;
WASMFunctionInstance *functions;
WASMExportFuncInstance *export_functions;
WASMMemoryInstance *default_memory;
WASMTableInstance *default_table;
WASMFunctionInstance *start_function;
WASMModule *module;
#if WASM_ENABLE_LIBC_WASI != 0
WASIContext *wasi_ctx;
#endif
uint32 DYNAMICTOP_PTR_offset;
uint32 temp_ret;
uint32 llvm_stack;
/* Default WASM stack size of threads of this Module instance. */
uint32 default_wasm_stack_size;
/* The exception buffer of wasm interpreter for current thread. */
char cur_exception[128];
/* The custom data that can be set/get by
* wasm_set_custom_data/wasm_get_custom_data */
void *custom_data;
/* Main exec env */
WASMExecEnv *main_exec_env;
} WASMModuleInstance;
struct WASMInterpFrame;
typedef struct WASMInterpFrame WASMRuntimeFrame;
/**
* Return the code block of a function.
*
* @param func the WASM function instance
*
* @return the code block of the function
*/
static inline uint8*
wasm_get_func_code(WASMFunctionInstance *func)
{
return func->is_import_func ? NULL : func->u.func->code;
}
/**
* Return the code block end of a function.
*
* @param func the WASM function instance
*
* @return the code block end of the function
*/
static inline uint8*
wasm_get_func_code_end(WASMFunctionInstance *func)
{
return func->is_import_func
? NULL : func->u.func->code + func->u.func->code_size;
}
WASMModule *
wasm_load(const uint8 *buf, uint32 size,
char *error_buf, uint32 error_buf_size);
WASMModule *
wasm_load_from_sections(WASMSection *section_list,
char *error_buf, uint32_t error_buf_size);
void
wasm_unload(WASMModule *module);
WASMModuleInstance *
wasm_instantiate(WASMModule *module,
uint32 stack_size, uint32 heap_size,
char *error_buf, uint32 error_buf_size);
void
wasm_deinstantiate(WASMModuleInstance *module_inst);
WASMFunctionInstance *
wasm_lookup_function(const WASMModuleInstance *module_inst,
const char *name, const char *signature);
bool
wasm_call_function(WASMExecEnv *exec_env,
WASMFunctionInstance *function,
unsigned argc, uint32 argv[]);
bool
wasm_create_exec_env_and_call_function(WASMModuleInstance *module_inst,
WASMFunctionInstance *function,
unsigned argc, uint32 argv[]);
void
wasm_set_exception(WASMModuleInstance *module, const char *exception);
const char*
wasm_get_exception(WASMModuleInstance *module);
int32
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size);
void
wasm_module_free(WASMModuleInstance *module_inst, int32 ptr);
int32
wasm_module_dup_data(WASMModuleInstance *module_inst,
const char *src, uint32 size);
bool
wasm_validate_app_addr(WASMModuleInstance *module_inst,
int32 app_offset, uint32 size);
bool
wasm_validate_app_str_addr(WASMModuleInstance *module_inst,
int32 app_offset);
bool
wasm_validate_native_addr(WASMModuleInstance *module_inst,
void *native_ptr, uint32 size);
void *
wasm_addr_app_to_native(WASMModuleInstance *module_inst,
int32 app_offset);
int32
wasm_addr_native_to_app(WASMModuleInstance *module_inst,
void *native_ptr);
bool
wasm_get_app_addr_range(WASMModuleInstance *module_inst,
int32 app_offset,
int32 *p_app_start_offset,
int32 *p_app_end_offset);
bool
wasm_get_native_addr_range(WASMModuleInstance *module_inst,
uint8_t *native_ptr,
uint8_t **p_native_start_addr,
uint8_t **p_native_end_addr);
bool
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASM_RUNTIME_H */