Browse Source

* use a functype operand for a_if, instead of hardcoding

git-svn-id: branches/wasm@48028 -
nickysn 4 years ago
parent
commit
b6735179ed

+ 1 - 3
compiler/wasm32/agllvmmc.pas

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

+ 11 - 2
compiler/wasm32/cpubase.pas

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

+ 1 - 1
compiler/wasm32/nwasmadd.pas

@@ -261,7 +261,7 @@ interface
             (nf_short_bool in flags)) then
         begin
           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
               andn :

+ 1 - 1
compiler/wasm32/nwasmflw.pas

@@ -152,7 +152,7 @@ begin
 
   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;
 
   secondpass(right); // then branchs

+ 1 - 1
compiler/wasm32/symcpu.pas

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