From 3c19adda78114804ebcc8d923b155b43f229b99f Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Mon, 16 Oct 2023 23:09:56 +0300 Subject: [PATCH] * moved the code that converts branch numbers to labels in the cpupi unit and call it from resolve_labels_complex --- compiler/wasm32/aasmcpu.pas | 36 ------------------------------------ compiler/wasm32/cpupi.pas | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/compiler/wasm32/aasmcpu.pas b/compiler/wasm32/aasmcpu.pas index e25551b7e4..1f93e76e76 100644 --- a/compiler/wasm32/aasmcpu.pas +++ b/compiler/wasm32/aasmcpu.pas @@ -2681,42 +2681,6 @@ uses blockstack.free; end; - type - TNumberToLabelConverter = class - function Convert(ai: tai; blockstack: twasmstruc_stack): tai; - end; - - function TNumberToLabelConverter.Convert(ai: tai; blockstack: twasmstruc_stack): tai; - var - instr: taicpu; - bl: taicpu_wasm_structured_instruction; - l: TAsmLabel; - begin - result:=ai; - if ai.typ<>ait_instruction then - exit; - instr:=taicpu(ai); - if not (instr.opcode in [a_br,a_br_if]) then - exit; - if instr.ops<>1 then - internalerror(2023101601); - if instr.oper[0]^.typ<>top_const then - exit; - bl:=blockstack[instr.oper[0]^.val]; - l:=bl.getlabel; - instr.loadsymbol(0,l,0); - end; - - - procedure convert_numbers_to_labels(l: TAsmList); - var - n: TNumberToLabelConverter; - begin - n:=TNumberToLabelConverter.Create; - map_structured_asmlist(l,@n.Convert); - n.free; - end; - initialization cai_cpu:=taicpu; diff --git a/compiler/wasm32/cpupi.pas b/compiler/wasm32/cpupi.pas index 2f9df417fa..3cec78cf58 100644 --- a/compiler/wasm32/cpupi.pas +++ b/compiler/wasm32/cpupi.pas @@ -26,7 +26,7 @@ unit cpupi; interface uses - cutils,globtype,aasmdata, + cutils,globtype,aasmdata,aasmcpu,aasmtai, procinfo,cpuinfo, symtype,aasmbase,cgbase, psub, cclasses; @@ -35,6 +35,8 @@ interface { tcpuprocinfo } tcpuprocinfo=class(tcgprocinfo) + private + function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): tai; public { label to the nearest local exception handler } CurrRaiseLabel : tasmlabel; @@ -50,7 +52,7 @@ interface implementation uses - systems,verbose,globals,cpubase,tgcpu,aasmcpu,aasmtai,cgexcept, + systems,verbose,globals,cpubase,tgcpu,cgexcept, tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase, fmodule,hlcgobj,hlcgcpu,defutil; @@ -348,6 +350,27 @@ implementation tcpuprocinfo *****************************************************************************} + function tcpuprocinfo.ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): tai; + var + instr: taicpu; + bl: taicpu_wasm_structured_instruction; + l: TAsmLabel; + begin + result:=ai; + if ai.typ<>ait_instruction then + exit; + instr:=taicpu(ai); + if not (instr.opcode in [a_br,a_br_if]) then + exit; + if instr.ops<>1 then + internalerror(2023101601); + if instr.oper[0]^.typ<>top_const then + exit; + bl:=blockstack[instr.oper[0]^.val]; + l:=bl.getlabel; + instr.loadsymbol(0,l,0); + end; + constructor tcpuprocinfo.create(aparent: tprocinfo); begin inherited create(aparent); @@ -605,6 +628,8 @@ implementation wasm_convert_to_structured_asmlist(asmlist,l2); asmlist.Free; asmlist:=l2; + + map_structured_asmlist(asmlist,@ConvertBranchTargetNumbersToLabels); end; var