Skip to content

Commit

Permalink
add initial draft to support of exception handling proposal phase 3 i…
Browse files Browse the repository at this point in the history
…n classic interpreter (bytecodealliance#1884)
  • Loading branch information
ermler committed Jul 17, 2023
1 parent f558887 commit b86c98e
Show file tree
Hide file tree
Showing 9 changed files with 1,522 additions and 65 deletions.
1 change: 1 addition & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ else ()
endif ()
if (WAMR_BUILD_EXCE_HANDLING EQUAL 1)
add_definitions (-DWASM_ENABLE_EXCE_HANDLING=1)
add_definitions (-DWASM_ENABLE_TAGS=1)
message (" Exception Handling enabled")
endif ()
if (DEFINED WAMR_BH_VPRINTF)
Expand Down
62 changes: 62 additions & 0 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
extern "C" {
#endif


#if WASM_ENABLE_EXCE_HANDLING != 0
#define _EXCEWARNING LOG_WARNING /* for exception handling misbehavior logging */
#define _EXCEDEBUG LOG_VERBOSE /* for exception handling debugging */
#define _EXCEVERBOSE LOG_VERBOSE /* more excessive tracing of tagbrowsing and stack pointers */
#endif

/** Value Type */
#define VALUE_TYPE_I32 0x7F
#define VALUE_TYPE_I64 0X7E
Expand Down Expand Up @@ -65,6 +72,9 @@ extern "C" {
#if WASM_ENABLE_BULK_MEMORY != 0
#define SECTION_TYPE_DATACOUNT 12
#endif
#if WASM_ENABLE_TAGS != 0
#define SECTION_TYPE_TAG 13
#endif

#define SUB_SECTION_TYPE_MODULE 0
#define SUB_SECTION_TYPE_FUNC 1
Expand All @@ -74,20 +84,34 @@ extern "C" {
#define IMPORT_KIND_TABLE 1
#define IMPORT_KIND_MEMORY 2
#define IMPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define IMPORT_KIND_TAG 4
#endif

#define EXPORT_KIND_FUNC 0
#define EXPORT_KIND_TABLE 1
#define EXPORT_KIND_MEMORY 2
#define EXPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define EXPORT_KIND_TAG 4
#endif

#define LABEL_TYPE_BLOCK 0
#define LABEL_TYPE_LOOP 1
#define LABEL_TYPE_IF 2
#define LABEL_TYPE_FUNCTION 3
#if WASM_ENABLE_EXCE_HANDLING != 0
#define LABEL_TYPE_TRY 4
#define LABEL_TYPE_CATCH 5
#define LABEL_TYPE_CATCH_ALL 6
#endif

typedef struct WASMModule WASMModule;
typedef struct WASMFunction WASMFunction;
typedef struct WASMGlobal WASMGlobal;
#if WASM_ENABLE_TAGS != 0
typedef struct WASMTag WASMTag;
#endif

typedef union V128 {
int8 i8x16[16];
Expand Down Expand Up @@ -197,6 +221,13 @@ typedef struct WASMFunctionImport {
bool call_conv_wasm_c_api;
} WASMFunctionImport;

#if WASM_ENABLE_TAGS != 0
typedef struct WASMTagImport {
uint8 attribute; /* the type of the tag (numerical) */
uint32 type; /* the type of the catch function (numerical)*/
} WASMTagImport;
#endif

typedef struct WASMGlobalImport {
char *module_name;
char *field_name;
Expand All @@ -223,6 +254,9 @@ typedef struct WASMImport {
WASMFunctionImport function;
WASMTableImport table;
WASMMemoryImport memory;
#if WASM_ENABLE_TAGS != 0
WASMTagImport tag;
#endif
WASMGlobalImport global;
struct {
char *module_name;
Expand Down Expand Up @@ -261,6 +295,10 @@ struct WASMFunction {
uint32 const_cell_num;
#endif

#if WASM_ENABLE_EXCE_HANDLING != 0
uint32 exception_handler_count;
#endif

#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
|| WASM_ENABLE_WAMR_COMPILER != 0
/* Whether function has opcode memory.grow */
Expand Down Expand Up @@ -290,6 +328,13 @@ struct WASMFunction {
#endif
};

#if WASM_ENABLE_TAGS != 0
struct WASMTag {
uint8 attribute; /* the attribute property of the tag (expected to be 0) */
uint32 type; /* the type of the tag (expected valid inden in type table) */
};
#endif

struct WASMGlobal {
uint8 type;
bool is_mutable;
Expand Down Expand Up @@ -417,6 +462,9 @@ struct WASMModule {
uint32 function_count;
uint32 table_count;
uint32 memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 tag_count;
#endif
uint32 global_count;
uint32 export_count;
uint32 table_seg_count;
Expand All @@ -430,18 +478,28 @@ struct WASMModule {
uint32 import_function_count;
uint32 import_table_count;
uint32 import_memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 import_tag_count;
#endif
uint32 import_global_count;

WASMImport *import_functions;
WASMImport *import_tables;
WASMImport *import_memories;
#if WASM_ENABLE_TAGS != 0
WASMImport *import_tags;
#endif
WASMImport *import_globals;


WASMType **types;
WASMImport *imports;
WASMFunction **functions;
WASMTable *tables;
WASMMemory *memories;
#if WASM_ENABLE_TAGS != 0
WASMTag *tags;
#endif
WASMGlobal *globals;
WASMExport *exports;
WASMTableSeg *table_segments;
Expand Down Expand Up @@ -625,6 +683,10 @@ typedef struct WASMBranchBlock {
uint8 *target_addr;
uint32 *frame_sp;
uint32 cell_num;
#if WASM_ENABLE_EXCE_HANDLING != 0
/* in exception handling, label_type needs to be stored to lookup exception handlers */
uint8 label_type;
#endif
} WASMBranchBlock;

/* Execution environment, e.g. stack info */
Expand Down
8 changes: 8 additions & 0 deletions core/iwasm/interpreter/wasm_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ typedef struct WASMInterpFrame {
uint64 time_started;
#endif

#if WASM_ENABLE_EXCE_HANDLING != 0
/* set to true if the callee returns an exception rather than
* result values on the stack
*/
bool exception_raised;
uint32_t tag_index;
#endif

#if WASM_ENABLE_FAST_INTERP != 0
/* Return offset of the first return value of current frame,
the callee will put return values here continuously */
Expand Down
Loading

0 comments on commit b86c98e

Please sign in to comment.