+ check whether all br instructions, generated by goto point to a pascal goto label

This commit is contained in:
Nikolay Nikolov 2023-10-22 05:23:04 +03:00
parent 31dff18a61
commit 3defa34470
3 changed files with 35 additions and 3 deletions

View File

@ -56,6 +56,8 @@ uses
{ taicpu }
taicpu = class(tai_cpu_abstract_sym)
is_br_generated_by_goto: boolean;
constructor op_none(op : tasmop);
constructor op_reg(op : tasmop;_op1 : tregister);

View File

@ -59,7 +59,7 @@ interface
procedure postprocess_code; override;
procedure set_first_temp_offset;override;
procedure add_goto_target(l : tasmlabel);
function is_goto_target(l : tasmlabel): Boolean;
function is_goto_target(l : tasmsymbol): Boolean;
end;
implementation
@ -918,10 +918,36 @@ implementation
end;
end;
procedure check_goto_br_instructions(list: TAsmList);
var
hp: tai;
begin
hp:=tai(list.first);
while assigned(hp) do
begin
if (hp.typ=ait_instruction) and (taicpu(hp).is_br_generated_by_goto) then
begin
if (taicpu(hp).opcode<>a_br) or
(taicpu(hp).ops<>1) or
(taicpu(hp).oper[0]^.typ<>top_ref) or
(taicpu(hp).oper[0]^.ref^.offset<>0) or
(taicpu(hp).oper[0]^.ref^.base<>NR_NO) or
(taicpu(hp).oper[0]^.ref^.index<>NR_NO) or
(taicpu(hp).oper[0]^.ref^.symbol=nil) then
internalerror(2023102203);
if not is_goto_target(taicpu(hp).oper[0]^.ref^.symbol) then
internalerror(2023102204);
end;
hp:=tai(hp.next);
end;
end;
var
localslist: TAsmList;
labels_resolved: Boolean;
begin
check_goto_br_instructions(aktproccode);
localslist:=prepare_locals;
replace_local_frame_pointer(aktproccode);
@ -963,7 +989,7 @@ implementation
FGotoTargets.Add(l.Name,l);
end;
function tcpuprocinfo.is_goto_target(l: tasmlabel): Boolean;
function tcpuprocinfo.is_goto_target(l: tasmsymbol): Boolean;
begin
result:=FGotoTargets.FindIndexOf(l.Name)<>-1;
end;

View File

@ -1934,8 +1934,12 @@ implementation
end;
procedure thlcgwasm.a_jmp_always_pascal_goto(list: TAsmList; l: tasmlabel);
var
br_ins: taicpu;
begin
list.concat(taicpu.op_sym(a_br,l));
br_ins:=taicpu.op_sym(a_br,l);
br_ins.is_br_generated_by_goto:=true;
list.concat(br_ins);
end;
procedure thlcgwasm.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);