فهرست منبع

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

git-svn-id: branches/wasm@47963 -
nickysn 4 سال پیش
والد
کامیت
763ca253c1
4فایلهای تغییر یافته به همراه55 افزوده شده و 30 حذف شده
  1. 16 8
      compiler/aggas.pas
  2. 6 14
      compiler/wasm32/aasmcpu.pas
  3. 25 0
      compiler/wasm32/cpubase.pas
  4. 8 8
      compiler/wasm32/hlcgcpu.pas

+ 16 - 8
compiler/aggas.pas

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

+ 6 - 14
compiler/wasm32/aasmcpu.pas

@@ -114,11 +114,9 @@ uses
 
 
       tai_functype = class(tai)
       tai_functype = class(tai)
         funcname: string;
         funcname: string;
-        params: array of TWasmBasicType;
-        results: array of TWasmBasicType;
+        functype: TWasmFuncType;
         constructor create(const afuncname: string = '');
         constructor create(const afuncname: string = '');
-        procedure add_param(param: TWasmBasicType);
-        procedure add_result(res: TWasmBasicType);
+        destructor destroy;override;
       end;
       end;
 
 
     procedure InitAsm;
     procedure InitAsm;
@@ -136,20 +134,14 @@ implementation
         inherited Create;
         inherited Create;
         typ:=ait_functype;
         typ:=ait_functype;
         funcname:=afuncname;
         funcname:=afuncname;
+        functype:=TWasmFuncType.Create;
       end;
       end;
 
 
 
 
-    procedure tai_functype.add_param(param: TWasmBasicType);
+    destructor tai_functype.destroy;
       begin
       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;
       end;
 
 
     { tai_local }
     { tai_local }

+ 25 - 0
compiler/wasm32/cpubase.pas

@@ -87,6 +87,15 @@ uses
 
 
       TWasmBasicType = (wbt_i32, wbt_i64, wbt_f32, wbt_f64);
       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 }
       {# This should define the array of instructions as string }
       op2strtable=array[tasmop] of string[31];
       op2strtable=array[tasmop] of string[31];
 
 
@@ -376,4 +385,20 @@ uses
         internalerror(2015082701);
         internalerror(2015082701);
       end;
       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.
 end.

+ 8 - 8
compiler/wasm32/hlcgcpu.pas

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