- 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];
cexceptionstatehandler.new_exception(current_asmdata.CurrAsmList,excepttemps,tek_except,trystate);
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
//thlcgwasm(hlcg).incblock;
{ try block }
secondpass(left);
@ -587,7 +587,7 @@ implementation
//flowcontrol:=exceptionstate.oldflowcontrol;
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];
{ on statements }
@ -626,19 +626,19 @@ implementation
flowcontrol+
afteronflowcontrol;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
//thlcgwasm(hlcg).incblock;
secondpass(t1);
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;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
//thlcgwasm(hlcg).decblock;
end
else
begin
@ -648,12 +648,12 @@ implementation
end
else
begin
current_asmdata.CurrAsmList.concat(taicpu.op_const(a_rethrow,0));
//current_asmdata.CurrAsmList.concat(taicpu.op_const(a_rethrow,0));
doobjectdestroyandreraisestate.newflowcontrol:=afteronflowcontrol;
end;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
//thlcgwasm(hlcg).decblock;
errorexit:
{ return all used control flow statements }
@ -1118,7 +1118,7 @@ implementation
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
thlcgwasm(hlcg).incblock;
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));
thlcgwasm(hlcg).decblock;
end;
@ -1190,8 +1190,8 @@ implementation
end;
{ the inner 'try..end_try' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
//thlcgwasm(hlcg).incblock;
{ try code }
if assigned(left) then
@ -1210,14 +1210,14 @@ 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_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) }
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
{ exit the inner 'try..end_try' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
//thlcgwasm(hlcg).decblock;
{ exit the 'continue' block }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_block));
@ -1399,8 +1399,8 @@ implementation
{ in the case that another exception is risen
we've to destroy the old one, so create a new
exception frame for the catch-handler }
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
thlcgwasm(hlcg).incblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_try));
//thlcgwasm(hlcg).incblock;
if assigned(right) then
secondpass(right);
@ -1408,12 +1408,12 @@ implementation
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_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;
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
thlcgwasm(hlcg).decblock;
//current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_try));
//thlcgwasm(hlcg).decblock;
{ clear some stuff }
if assigned(exceptvarsym) then

View File

@ -71,8 +71,7 @@ implementation
list.Concat(tai_globaltype.create(STACK_POINTER_SYM,wbt_i32,false));
if (ts_wasm_native_exceptions in current_settings.targetswitches) or
(ts_wasm_bf_exceptions in current_settings.targetswitches) then
if ts_wasm_native_exceptions in current_settings.targetswitches then
begin
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));