+ functype creation moved to tcpuprocdef.create_functype

git-svn-id: branches/wasm@47964 -
This commit is contained in:
nickysn 2021-01-02 12:06:05 +00:00
parent 763ca253c1
commit 56f65799d3
3 changed files with 63 additions and 55 deletions

View File

@ -115,7 +115,7 @@ uses
tai_functype = class(tai)
funcname: string;
functype: TWasmFuncType;
constructor create(const afuncname: string = '');
constructor create(const afuncname: string; afunctype: TWasmFuncType);
destructor destroy;override;
end;
@ -129,12 +129,12 @@ implementation
{ tai_functype }
constructor tai_functype.create(const afuncname: string = '');
constructor tai_functype.create(const afuncname: string; afunctype: TWasmFuncType);
begin
inherited Create;
typ:=ait_functype;
funcname:=afuncname;
functype:=TWasmFuncType.Create;
functype:=afunctype;
end;

View File

@ -2044,56 +2044,10 @@ implementation
internalerror(2012090206);
end;
procedure thlcgwasm.g_procdef(list: TAsmList; pd: tprocdef);
var
functype: tai_functype;
i: integer;
prm: tcpuparavarsym;
bt: TWasmBasicType;
begin
functype:=tai_functype.create(pd.mangledname);
if Assigned(pd.paras) and (pd.paras.Count>0) then
begin
for i:=0 to pd.paras.Count-1 do
begin
prm := tcpuparavarsym(pd.paras[i]);
case prm.paraloc[callerside].Size of
OS_8..OS_32, OS_S8..OS_S32:
functype.functype.add_param(wbt_i32);
OS_64, OS_S64:
functype.functype.add_param(wbt_i64);
OS_F32:
functype.functype.add_param(wbt_f32);
OS_F64:
functype.functype.add_param(wbt_f64);
else
begin
{$ifdef EXTDEBUG}
Writeln('Unsupported caller side parameter type: ', prm.paraloc[callerside].Size);
{$endif EXTDEBUG}
// unsupported calleeside parameter type
Internalerror(2019093001);
end;
end;
end;
end;
if Assigned(pd.returndef) and (pd.returndef.size>0) then
begin
if not defToWasmBasic(pd.returndef,bt) then
bt:=wbt_i32;
case bt of
wbt_i64:
functype.functype.add_result(wbt_i64);
wbt_f32:
functype.functype.add_result(wbt_f32);
wbt_f64:
functype.functype.add_result(wbt_f64);
else
functype.functype.add_result(wbt_i32);
end;
end;
list.Concat(functype);
end;
procedure thlcgwasm.g_procdef(list: TAsmList; pd: tprocdef);
begin
list.Concat(tai_functype.create(pd.mangledname,tcpuprocdef(pd).create_functype));
end;
procedure thlcgwasm.a_load_stack_reg(list: TAsmList; size: tdef; reg: tregister);
var

View File

@ -27,6 +27,7 @@ interface
uses
globtype,
cpubase,
aasmdata,
symtype,
symdef,symsym,
@ -105,6 +106,7 @@ type
easily write out all methods grouped per class }
exprasmlist : TAsmList;
destructor destroy; override;
function create_functype: TWasmFuncType;
end;
tcpuprocdefclass = class of tcpuprocdef;
@ -201,11 +203,12 @@ const
implementation
uses
verbose,cutils,cclasses,globals,
verbose,cutils,cclasses,globals,cgbase,
symconst,symbase,symtable,symcreat,wasmdef,
pdecsub,pparautl,paramgr,
// high-level code generator is needed to get access to type index for ncall
hlcgobj,hlcgcpu
hlcgobj,hlcgcpu,
tgcpu
;
@ -264,6 +267,57 @@ implementation
inherited destroy;
end;
function tcpuprocdef.create_functype: TWasmFuncType;
var
i: Integer;
prm: tcpuparavarsym;
bt: TWasmBasicType;
begin
result:=TWasmFuncType.Create;
if Assigned(paras) and (paras.Count>0) then
begin
for i:=0 to paras.Count-1 do
begin
prm := tcpuparavarsym(paras[i]);
case prm.paraloc[callerside].Size of
OS_8..OS_32, OS_S8..OS_S32:
result.add_param(wbt_i32);
OS_64, OS_S64:
result.add_param(wbt_i64);
OS_F32:
result.add_param(wbt_f32);
OS_F64:
result.add_param(wbt_f64);
else
begin
{$ifdef EXTDEBUG}
Writeln('Unsupported caller side parameter type: ', prm.paraloc[callerside].Size);
{$endif EXTDEBUG}
// unsupported calleeside parameter type
Internalerror(2019093001);
end;
end;
end;
end;
if Assigned(returndef) and (returndef.size>0) then
begin
if not defToWasmBasic(returndef,bt) then
bt:=wbt_i32;
case bt of
wbt_i64:
result.add_result(wbt_i64);
wbt_f32:
result.add_result(wbt_f32);
wbt_f64:
result.add_result(wbt_f64);
else
result.add_result(wbt_i32);
end;
end;
end;
{****************************************************************************
tcpuprocvardef
****************************************************************************}