+ introduced the TWasmFuncType class - used to hold a Wasm function signature

git-svn-id: branches/wasm@47963 -
This commit is contained in:
nickysn 2021-01-02 11:54:41 +00:00
parent bb42589829
commit 763ca253c1
4 changed files with 55 additions and 30 deletions

View File

@ -808,16 +808,14 @@ implementation
end;
{$ifdef WASM}
procedure WriteFuncType(hp:tai_functype);
procedure WriteFuncType(functype: TWasmFuncType);
var
wasm_basic_typ: TWasmBasicType;
first: boolean;
begin
writer.AsmWrite(#9'.functype'#9);
writer.AsmWrite(tai_functype(hp).funcname);
writer.AsmWrite(' (');
writer.AsmWrite('(');
first:=true;
for wasm_basic_typ in tai_functype(hp).params do
for wasm_basic_typ in functype.params do
begin
if first then
first:=false
@ -827,7 +825,7 @@ implementation
end;
writer.AsmWrite(') -> (');
first:=true;
for wasm_basic_typ in tai_functype(hp).results do
for wasm_basic_typ in functype.results do
begin
if first then
first:=false
@ -835,7 +833,17 @@ implementation
writer.AsmWrite(',');
writer.AsmWrite(gas_wasm_basic_type_str[wasm_basic_typ]);
end;
writer.AsmWriteLn(')');
writer.AsmWrite(')');
end;
procedure WriteFuncTypeDirective(hp:tai_functype);
begin
writer.AsmWrite(#9'.functype'#9);
writer.AsmWrite(hp.funcname);
writer.AsmWrite(' ');
WriteFuncType(hp.functype);
writer.AsmLn;
end;
@ -1627,7 +1635,7 @@ implementation
writer.AsmLn;
end;
ait_functype:
WriteFuncType(tai_functype(hp));
WriteFuncTypeDirective(tai_functype(hp));
ait_importexport:
WriteImportExport(tai_impexp(hp));
{$endif WASM}

View File

@ -114,11 +114,9 @@ uses
tai_functype = class(tai)
funcname: string;
params: array of TWasmBasicType;
results: array of TWasmBasicType;
functype: TWasmFuncType;
constructor create(const afuncname: string = '');
procedure add_param(param: TWasmBasicType);
procedure add_result(res: TWasmBasicType);
destructor destroy;override;
end;
procedure InitAsm;
@ -136,20 +134,14 @@ implementation
inherited Create;
typ:=ait_functype;
funcname:=afuncname;
functype:=TWasmFuncType.Create;
end;
procedure tai_functype.add_param(param: TWasmBasicType);
destructor tai_functype.destroy;
begin
SetLength(params,Length(params)+1);
params[High(params)]:=param;
end;
procedure tai_functype.add_result(res: TWasmBasicType);
begin
SetLength(results,Length(results)+1);
results[High(results)]:=res;
functype.free;
inherited;
end;
{ tai_local }

View File

@ -87,6 +87,15 @@ uses
TWasmBasicType = (wbt_i32, wbt_i64, wbt_f32, wbt_f64);
{ TWasmFuncType }
TWasmFuncType = class
params: array of TWasmBasicType;
results: array of TWasmBasicType;
procedure add_param(param: TWasmBasicType);
procedure add_result(res: TWasmBasicType);
end;
{# This should define the array of instructions as string }
op2strtable=array[tasmop] of string[31];
@ -376,4 +385,20 @@ uses
internalerror(2015082701);
end;
{*****************************************************************************
TWasmFuncType
*****************************************************************************}
procedure TWasmFuncType.add_param(param: TWasmBasicType);
begin
SetLength(params,Length(params)+1);
params[High(params)]:=param;
end;
procedure TWasmFuncType.add_result(res: TWasmBasicType);
begin
SetLength(results,Length(results)+1);
results[High(results)]:=res;
end;
end.

View File

@ -2059,13 +2059,13 @@ implementation
prm := tcpuparavarsym(pd.paras[i]);
case prm.paraloc[callerside].Size of
OS_8..OS_32, OS_S8..OS_S32:
functype.add_param(wbt_i32);
functype.functype.add_param(wbt_i32);
OS_64, OS_S64:
functype.add_param(wbt_i64);
functype.functype.add_param(wbt_i64);
OS_F32:
functype.add_param(wbt_f32);
functype.functype.add_param(wbt_f32);
OS_F64:
functype.add_param(wbt_f64);
functype.functype.add_param(wbt_f64);
else
begin
{$ifdef EXTDEBUG}
@ -2083,13 +2083,13 @@ implementation
bt:=wbt_i32;
case bt of
wbt_i64:
functype.add_result(wbt_i64);
functype.functype.add_result(wbt_i64);
wbt_f32:
functype.add_result(wbt_f32);
functype.functype.add_result(wbt_f32);
wbt_f64:
functype.add_result(wbt_f64);
functype.functype.add_result(wbt_f64);
else
functype.add_result(wbt_i32);
functype.functype.add_result(wbt_i32);
end;
end;
list.Concat(functype);