From 82b6450f198b15bd2823554d47a275eb836c9933 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Mon, 27 Sep 2021 17:49:30 +0300 Subject: [PATCH] + introduced the AT_WASM_EXCEPTION_TAG asm symbol type, use that for specifying the parameter to the 'throw' and 'catch' instructions --- compiler/aasmbase.pas | 5 ++++- compiler/wasm32/itcpugas.pas | 2 +- compiler/wasm32/nwasmflw.pas | 2 +- compiler/wasm32/nwasminl.pas | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/aasmbase.pas b/compiler/aasmbase.pas index 6a6479e9dd..b1621e5c4f 100644 --- a/compiler/aasmbase.pas +++ b/compiler/aasmbase.pas @@ -72,7 +72,10 @@ interface { GNU indirect function (ELF targets) } AT_GNU_IFUNC, { WebAssembly global variable } - AT_WASM_GLOBAL + AT_WASM_GLOBAL, + { WebAssembly exception tag (used as a parameter for the 'throw' and + 'catch' instructions) } + AT_WASM_EXCEPTION_TAG ); { is the label only there for getting an DataOffset (e.g. for i/o diff --git a/compiler/wasm32/itcpugas.pas b/compiler/wasm32/itcpugas.pas index f588bbf4c9..9a754837da 100644 --- a/compiler/wasm32/itcpugas.pas +++ b/compiler/wasm32/itcpugas.pas @@ -84,7 +84,7 @@ interface // additional memory 'memory.grow 0', 'memory.size 0', // exceptions - 'try','catch __FPC_exception','catch_all','delegate','throw __FPC_exception','rethrow','end_try' + 'try','catch','catch_all','delegate','throw','rethrow','end_try' ); gas_wasm_basic_type_str : array [TWasmBasicType] of string = ('i32','i64','f32','f64'); diff --git a/compiler/wasm32/nwasmflw.pas b/compiler/wasm32/nwasmflw.pas index cbc44f4335..ffe8a49825 100644 --- a/compiler/wasm32/nwasmflw.pas +++ b/compiler/wasm32/nwasmflw.pas @@ -691,7 +691,7 @@ implementation hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,0,excepttemps.reasonbuf); current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,4)); // jump to the 'finally' section - current_asmdata.CurrAsmList.concat(taicpu.op_none(a_catch)); + current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.RefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); thlcgwasm(hlcg).decblock; { exceptionreason:=1 (exception) } hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,1,excepttemps.reasonbuf); diff --git a/compiler/wasm32/nwasminl.pas b/compiler/wasm32/nwasminl.pas index dbc635fbfd..f0f294eed4 100644 --- a/compiler/wasm32/nwasminl.pas +++ b/compiler/wasm32/nwasminl.pas @@ -159,7 +159,7 @@ implementation procedure twasminlinenode.second_throw_fpcexception; begin location_reset(location,LOC_VOID,OS_NO); - current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_throw)); + current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.RefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); end;