mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 04:26:13 +02:00
* moved the code that converts branch numbers to labels in the cpupi unit and call it from resolve_labels_complex
This commit is contained in:
parent
c48a8ad31f
commit
3c19adda78
@ -2681,42 +2681,6 @@ uses
|
|||||||
blockstack.free;
|
blockstack.free;
|
||||||
end;
|
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
|
initialization
|
||||||
cai_cpu:=taicpu;
|
cai_cpu:=taicpu;
|
||||||
|
@ -26,7 +26,7 @@ unit cpupi;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
cutils,globtype,aasmdata,
|
cutils,globtype,aasmdata,aasmcpu,aasmtai,
|
||||||
procinfo,cpuinfo, symtype,aasmbase,cgbase,
|
procinfo,cpuinfo, symtype,aasmbase,cgbase,
|
||||||
psub, cclasses;
|
psub, cclasses;
|
||||||
|
|
||||||
@ -35,6 +35,8 @@ interface
|
|||||||
{ tcpuprocinfo }
|
{ tcpuprocinfo }
|
||||||
|
|
||||||
tcpuprocinfo=class(tcgprocinfo)
|
tcpuprocinfo=class(tcgprocinfo)
|
||||||
|
private
|
||||||
|
function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): tai;
|
||||||
public
|
public
|
||||||
{ label to the nearest local exception handler }
|
{ label to the nearest local exception handler }
|
||||||
CurrRaiseLabel : tasmlabel;
|
CurrRaiseLabel : tasmlabel;
|
||||||
@ -50,7 +52,7 @@ interface
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
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,
|
tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase,
|
||||||
fmodule,hlcgobj,hlcgcpu,defutil;
|
fmodule,hlcgobj,hlcgcpu,defutil;
|
||||||
|
|
||||||
@ -348,6 +350,27 @@ implementation
|
|||||||
tcpuprocinfo
|
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);
|
constructor tcpuprocinfo.create(aparent: tprocinfo);
|
||||||
begin
|
begin
|
||||||
inherited create(aparent);
|
inherited create(aparent);
|
||||||
@ -605,6 +628,8 @@ implementation
|
|||||||
wasm_convert_to_structured_asmlist(asmlist,l2);
|
wasm_convert_to_structured_asmlist(asmlist,l2);
|
||||||
asmlist.Free;
|
asmlist.Free;
|
||||||
asmlist:=l2;
|
asmlist:=l2;
|
||||||
|
|
||||||
|
map_structured_asmlist(asmlist,@ConvertBranchTargetNumbersToLabels);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user