Skip to content

Commit b86c98e

Browse files
committed
add initial draft to support of exception handling proposal phase 3 in classic interpreter (bytecodealliance#1884)
1 parent f558887 commit b86c98e

File tree

9 files changed

+1522
-65
lines changed

9 files changed

+1522
-65
lines changed

Diff for: build-scripts/config_common.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ else ()
312312
endif ()
313313
if (WAMR_BUILD_EXCE_HANDLING EQUAL 1)
314314
add_definitions (-DWASM_ENABLE_EXCE_HANDLING=1)
315+
add_definitions (-DWASM_ENABLE_TAGS=1)
315316
message (" Exception Handling enabled")
316317
endif ()
317318
if (DEFINED WAMR_BH_VPRINTF)

Diff for: core/iwasm/interpreter/wasm.h

+62
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
extern "C" {
1515
#endif
1616

17+
18+
#if WASM_ENABLE_EXCE_HANDLING != 0
19+
#define _EXCEWARNING LOG_WARNING /* for exception handling misbehavior logging */
20+
#define _EXCEDEBUG LOG_VERBOSE /* for exception handling debugging */
21+
#define _EXCEVERBOSE LOG_VERBOSE /* more excessive tracing of tagbrowsing and stack pointers */
22+
#endif
23+
1724
/** Value Type */
1825
#define VALUE_TYPE_I32 0x7F
1926
#define VALUE_TYPE_I64 0X7E
@@ -65,6 +72,9 @@ extern "C" {
6572
#if WASM_ENABLE_BULK_MEMORY != 0
6673
#define SECTION_TYPE_DATACOUNT 12
6774
#endif
75+
#if WASM_ENABLE_TAGS != 0
76+
#define SECTION_TYPE_TAG 13
77+
#endif
6878

6979
#define SUB_SECTION_TYPE_MODULE 0
7080
#define SUB_SECTION_TYPE_FUNC 1
@@ -74,20 +84,34 @@ extern "C" {
7484
#define IMPORT_KIND_TABLE 1
7585
#define IMPORT_KIND_MEMORY 2
7686
#define IMPORT_KIND_GLOBAL 3
87+
#if WASM_ENABLE_TAGS != 0
88+
#define IMPORT_KIND_TAG 4
89+
#endif
7790

7891
#define EXPORT_KIND_FUNC 0
7992
#define EXPORT_KIND_TABLE 1
8093
#define EXPORT_KIND_MEMORY 2
8194
#define EXPORT_KIND_GLOBAL 3
95+
#if WASM_ENABLE_TAGS != 0
96+
#define EXPORT_KIND_TAG 4
97+
#endif
8298

8399
#define LABEL_TYPE_BLOCK 0
84100
#define LABEL_TYPE_LOOP 1
85101
#define LABEL_TYPE_IF 2
86102
#define LABEL_TYPE_FUNCTION 3
103+
#if WASM_ENABLE_EXCE_HANDLING != 0
104+
#define LABEL_TYPE_TRY 4
105+
#define LABEL_TYPE_CATCH 5
106+
#define LABEL_TYPE_CATCH_ALL 6
107+
#endif
87108

88109
typedef struct WASMModule WASMModule;
89110
typedef struct WASMFunction WASMFunction;
90111
typedef struct WASMGlobal WASMGlobal;
112+
#if WASM_ENABLE_TAGS != 0
113+
typedef struct WASMTag WASMTag;
114+
#endif
91115

92116
typedef union V128 {
93117
int8 i8x16[16];
@@ -197,6 +221,13 @@ typedef struct WASMFunctionImport {
197221
bool call_conv_wasm_c_api;
198222
} WASMFunctionImport;
199223

224+
#if WASM_ENABLE_TAGS != 0
225+
typedef struct WASMTagImport {
226+
uint8 attribute; /* the type of the tag (numerical) */
227+
uint32 type; /* the type of the catch function (numerical)*/
228+
} WASMTagImport;
229+
#endif
230+
200231
typedef struct WASMGlobalImport {
201232
char *module_name;
202233
char *field_name;
@@ -223,6 +254,9 @@ typedef struct WASMImport {
223254
WASMFunctionImport function;
224255
WASMTableImport table;
225256
WASMMemoryImport memory;
257+
#if WASM_ENABLE_TAGS != 0
258+
WASMTagImport tag;
259+
#endif
226260
WASMGlobalImport global;
227261
struct {
228262
char *module_name;
@@ -261,6 +295,10 @@ struct WASMFunction {
261295
uint32 const_cell_num;
262296
#endif
263297

298+
#if WASM_ENABLE_EXCE_HANDLING != 0
299+
uint32 exception_handler_count;
300+
#endif
301+
264302
#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
265303
|| WASM_ENABLE_WAMR_COMPILER != 0
266304
/* Whether function has opcode memory.grow */
@@ -290,6 +328,13 @@ struct WASMFunction {
290328
#endif
291329
};
292330

331+
#if WASM_ENABLE_TAGS != 0
332+
struct WASMTag {
333+
uint8 attribute; /* the attribute property of the tag (expected to be 0) */
334+
uint32 type; /* the type of the tag (expected valid inden in type table) */
335+
};
336+
#endif
337+
293338
struct WASMGlobal {
294339
uint8 type;
295340
bool is_mutable;
@@ -417,6 +462,9 @@ struct WASMModule {
417462
uint32 function_count;
418463
uint32 table_count;
419464
uint32 memory_count;
465+
#if WASM_ENABLE_TAGS != 0
466+
uint32 tag_count;
467+
#endif
420468
uint32 global_count;
421469
uint32 export_count;
422470
uint32 table_seg_count;
@@ -430,18 +478,28 @@ struct WASMModule {
430478
uint32 import_function_count;
431479
uint32 import_table_count;
432480
uint32 import_memory_count;
481+
#if WASM_ENABLE_TAGS != 0
482+
uint32 import_tag_count;
483+
#endif
433484
uint32 import_global_count;
434485

435486
WASMImport *import_functions;
436487
WASMImport *import_tables;
437488
WASMImport *import_memories;
489+
#if WASM_ENABLE_TAGS != 0
490+
WASMImport *import_tags;
491+
#endif
438492
WASMImport *import_globals;
439493

494+
440495
WASMType **types;
441496
WASMImport *imports;
442497
WASMFunction **functions;
443498
WASMTable *tables;
444499
WASMMemory *memories;
500+
#if WASM_ENABLE_TAGS != 0
501+
WASMTag *tags;
502+
#endif
445503
WASMGlobal *globals;
446504
WASMExport *exports;
447505
WASMTableSeg *table_segments;
@@ -625,6 +683,10 @@ typedef struct WASMBranchBlock {
625683
uint8 *target_addr;
626684
uint32 *frame_sp;
627685
uint32 cell_num;
686+
#if WASM_ENABLE_EXCE_HANDLING != 0
687+
/* in exception handling, label_type needs to be stored to lookup exception handlers */
688+
uint8 label_type;
689+
#endif
628690
} WASMBranchBlock;
629691

630692
/* Execution environment, e.g. stack info */

Diff for: core/iwasm/interpreter/wasm_interp.h

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ typedef struct WASMInterpFrame {
3434
uint64 time_started;
3535
#endif
3636

37+
#if WASM_ENABLE_EXCE_HANDLING != 0
38+
/* set to true if the callee returns an exception rather than
39+
* result values on the stack
40+
*/
41+
bool exception_raised;
42+
uint32_t tag_index;
43+
#endif
44+
3745
#if WASM_ENABLE_FAST_INTERP != 0
3846
/* Return offset of the first return value of current frame,
3947
the callee will put return values here continuously */

0 commit comments

Comments
 (0)