- don't generate any WebAssembly native exception handling instructions, nor

relocations, when compiling in branchful exceptions mode. This produces a
  currently not working, but accepted by wasmtime binary (otherwise, it
  complains it doesn't support exceptions and refuses to try to run it).
This commit is contained in:
Nikolay Nikolov 2021-10-05 01:01:24 +03:00
parent 30b503abc4
commit 6599f1d898
2 changed files with 23 additions and 24 deletions

View File

@ -575,8 +575,8 @@ implementation
//flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions]; //flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions];
cexceptionstatehandler.new_exception(current_asmdata.CurrAsmList,excepttemps,tek_except,trystate); cexceptionstatehandler.new_exception(current_asmdata.CurrAsmList,excepttemps,tek_except,trystate);
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock; //thlcgwasm(hlcg).incblock;
{ try block } { try block }
secondpass(left); secondpass(left);
@ -587,7 +587,7 @@ implementation
//flowcontrol:=exceptionstate.oldflowcontrol; //flowcontrol:=exceptionstate.oldflowcontrol;
cexceptionstatehandler.end_try_block(current_asmdata.CurrAsmList,tek_except,excepttemps,trystate,nil); cexceptionstatehandler.end_try_block(current_asmdata.CurrAsmList,tek_except,excepttemps,trystate,nil);
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); //current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
flowcontrol:=[fc_inflowcontrol]+trystate.oldflowcontrol*[fc_catching_exceptions]; flowcontrol:=[fc_inflowcontrol]+trystate.oldflowcontrol*[fc_catching_exceptions];
{ on statements } { on statements }
@ -626,19 +626,19 @@ implementation
flowcontrol+ flowcontrol+
afteronflowcontrol; afteronflowcontrol;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock; //thlcgwasm(hlcg).incblock;
secondpass(t1); secondpass(t1);
hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_doneexception',[],nil).resetiftemp; hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_doneexception',[],nil).resetiftemp;
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); //current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_raise_nested',[],nil).resetiftemp; hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_raise_nested',[],nil).resetiftemp;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock; //thlcgwasm(hlcg).decblock;
end end
else else
begin begin
@ -648,12 +648,12 @@ implementation
end end
else else
begin begin
current_asmdata.CurrAsmList.concat(taicpu.op_const(a_rethrow,0)); //current_asmdata.CurrAsmList.concat(taicpu.op_const(a_rethrow,0));
doobjectdestroyandreraisestate.newflowcontrol:=afteronflowcontrol; doobjectdestroyandreraisestate.newflowcontrol:=afteronflowcontrol;
end; end;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock; //thlcgwasm(hlcg).decblock;
errorexit: errorexit:
{ return all used control flow statements } { return all used control flow statements }
@ -1118,7 +1118,7 @@ implementation
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if)); current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
thlcgwasm(hlcg).incblock; thlcgwasm(hlcg).incblock;
thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1); thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); //current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if)); current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if));
thlcgwasm(hlcg).decblock; thlcgwasm(hlcg).decblock;
end; end;
@ -1190,8 +1190,8 @@ implementation
end; end;
{ the inner 'try..end_try' block } { the inner 'try..end_try' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock; //thlcgwasm(hlcg).incblock;
{ try code } { try code }
if assigned(left) then if assigned(left) then
@ -1210,14 +1210,14 @@ implementation
hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,0,excepttemps.reasonbuf); 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_const(a_br,4)); // jump to the 'finally' section
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); //current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
{ exceptionreason:=1 (exception) } { exceptionreason:=1 (exception) }
hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,1,excepttemps.reasonbuf); hlcg.g_exception_reason_save_const(current_asmdata.CurrAsmList,exceptionreasontype,1,excepttemps.reasonbuf);
current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,4)); // jump to the 'finally' section current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,4)); // jump to the 'finally' section
{ exit the inner 'try..end_try' block } { exit the inner 'try..end_try' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock; //thlcgwasm(hlcg).decblock;
{ exit the 'continue' block } { exit the 'continue' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_block)); current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_block));
@ -1399,8 +1399,8 @@ implementation
{ in the case that another exception is risen { in the case that another exception is risen
we've to destroy the old one, so create a new we've to destroy the old one, so create a new
exception frame for the catch-handler } exception frame for the catch-handler }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock; //thlcgwasm(hlcg).incblock;
if assigned(right) then if assigned(right) then
secondpass(right); secondpass(right);
@ -1408,12 +1408,12 @@ implementation
hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_doneexception',[],nil).resetiftemp; hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_doneexception',[],nil).resetiftemp;
current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,2)); current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,2));
current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG))); //current_asmdata.CurrAsmList.concat(taicpu.op_sym(a_catch,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_raise_nested',[],nil).resetiftemp; hlcg.g_call_system_proc(current_asmdata.CurrAsmList,'fpc_raise_nested',[],nil).resetiftemp;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try)); //current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock; //thlcgwasm(hlcg).decblock;
{ clear some stuff } { clear some stuff }
if assigned(exceptvarsym) then if assigned(exceptvarsym) then

View File

@ -71,8 +71,7 @@ implementation
list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32,false)); list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32,false));
if (ts_wasm_native_exceptions in current_settings.targetswitches) or if ts_wasm_native_exceptions in current_settings.targetswitches then
(ts_wasm_bf_exceptions in current_settings.targetswitches) then
begin begin
list.Concat(tai_tagtype.create(FPC_EXCEPTION_TAG_SYM, [])); list.Concat(tai_tagtype.create(FPC_EXCEPTION_TAG_SYM, []));
list.Concat(tai_symbol.Create_Weak(current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG),0)); list.Concat(tai_symbol.Create_Weak(current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG),0));