* use a functype operand for a_if, instead of hardcoding

git-svn-id: branches/wasm@48028 -
This commit is contained in:
nickysn 2021-01-04 11:01:18 +00:00
parent 07c1783e24
commit b6735179ed
5 changed files with 15 additions and 8 deletions

View File

@ -304,9 +304,7 @@ implementation
writer.AsmWrite(#9#9); writer.AsmWrite(#9#9);
writer.AsmWrite(gas_op2str[cpu.opcode]); writer.AsmWrite(gas_op2str[cpu.opcode]);
if (cpu.opcode = a_if) then if cpu.ops<>0 then
writer.AsmWrite(' i32') //todo: this is a hardcode, but shouldn't
else if cpu.ops<>0 then
begin begin
for i:=0 to cpu.ops-1 do for i:=0 to cpu.ops-1 do
begin begin

View File

@ -87,12 +87,14 @@ uses
); );
TWasmBasicType = (wbt_i32, wbt_i64, wbt_f32, wbt_f64); TWasmBasicType = (wbt_i32, wbt_i64, wbt_f32, wbt_f64);
TWasmResultType = array of TWasmBasicType;
{ TWasmFuncType } { TWasmFuncType }
TWasmFuncType = class TWasmFuncType = class
params: array of TWasmBasicType; params: TWasmResultType;
results: array of TWasmBasicType; results: TWasmResultType;
constructor Create(aparams, aresults: TWasmResultType);
procedure add_param(param: TWasmBasicType); procedure add_param(param: TWasmBasicType);
procedure add_result(res: TWasmBasicType); procedure add_result(res: TWasmBasicType);
end; end;
@ -390,6 +392,13 @@ uses
TWasmFuncType TWasmFuncType
*****************************************************************************} *****************************************************************************}
constructor TWasmFuncType.Create(aparams, aresults: TWasmResultType);
begin
inherited Create;
params:=aparams;
results:=aresults;
end;
procedure TWasmFuncType.add_param(param: TWasmBasicType); procedure TWasmFuncType.add_param(param: TWasmBasicType);
begin begin
SetLength(params,Length(params)+1); SetLength(params,Length(params)+1);

View File

@ -261,7 +261,7 @@ interface
(nf_short_bool in flags)) then (nf_short_bool in flags)) then
begin begin
secondpass(left); secondpass(left);
current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_if) ); current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
case nodetype of case nodetype of
andn : andn :

View File

@ -152,7 +152,7 @@ begin
secondpass(left); // condition exprssions secondpass(left); // condition exprssions
current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if)); // IF current_asmdata.CurrAsmList.concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
thlcgwasm(hlcg).incblock; thlcgwasm(hlcg).incblock;
secondpass(right); // then branchs secondpass(right); // then branchs

View File

@ -274,7 +274,7 @@ implementation
prm: tcpuparavarsym; prm: tcpuparavarsym;
bt: TWasmBasicType; bt: TWasmBasicType;
begin begin
result:=TWasmFuncType.Create; result:=TWasmFuncType.Create([],[]);
if Assigned(paras) and (paras.Count>0) then if Assigned(paras) and (paras.Count>0) then
begin begin
for i:=0 to paras.Count-1 do for i:=0 to paras.Count-1 do