+ added support for the handling of singleton record and array types in

defToWasmBasic
This commit is contained in:
Nikolay Nikolov 2021-10-14 09:34:00 +03:00
parent 3511b80972
commit df92d88f39
2 changed files with 40 additions and 1 deletions

View File

@ -328,7 +328,7 @@ implementation
exit(false);
end;
end;
result:=true;
result:=(fields=1);
end;

View File

@ -97,6 +97,9 @@ unit tgcpu;
hlcgobj,hlcgcpu, procinfo;
function defToWasmBasic(def: tdef; var wbt: TWasmBasicType): Boolean;
var
fields, i: Integer;
wbt_candidate: TWasmBasicType;
begin
Result := assigned(def);
if not Result then
@ -120,6 +123,42 @@ unit tgcpu;
else
wbt := wbt_f64; // real/double/extended
end
else if def.typ=recorddef then
begin
if not (def.size in [1,2,4,8]) then
exit(false);
fields:=0;
wbt_candidate:=Default(TWasmBasicType);
for i:=0 to trecorddef(def).symtable.symlist.count-1 do
begin
if (tsym(trecorddef(def).symtable.symlist[i]).typ<>fieldvarsym) or
(sp_static in tsym(trecorddef(def).symtable.symlist[i]).symoptions) then
continue;
if assigned(tfieldvarsym(trecorddef(def).symtable.symlist[i]).vardef) then
begin
Inc(fields);
if fields>1 then
exit(false);
{ search recursively }
if not defToWasmBasic(tfieldvarsym(trecorddef(def).symtable.symlist[i]).vardef,wbt_candidate) then
exit(false);
end;
end;
if fields=1 then
begin
wbt:=wbt_candidate;
result:=true;
end
else
result:=false;
end
else if def.typ=arraydef then
begin
if (def.size in [1,2,4,8]) and (tarraydef(def).elecount=1) then
result:=defToWasmBasic(tarraydef(def).elementdef,wbt)
else
result:=false;
end
else
Result := false;
end;