Browse Source

[PATCH 44/83] update initialization of the callee side parameters - marking them as local with their proper offset

From c851f0796dbb7c0143d69db8caeb2c45d812fa6a Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Wed, 18 Sep 2019 23:17:14 -0400

git-svn-id: branches/wasm@45921 -
nickysn 5 years ago
parent
commit
d95c63ed88
2 changed files with 28 additions and 9 deletions
  1. 1 6
      compiler/wasm/cpupara.pas
  2. 27 3
      compiler/wasm/hlcgcpu.pas

+ 1 - 6
compiler/wasm/cpupara.pas

@@ -302,12 +302,7 @@ implementation
                 ;
             end;
             { 2 slots for 64 bit integers and floats, 1 slot for the rest }
-            if not(is_64bit(paradef) or
-                   ((paradef.typ=floatdef) and
-                    (tfloatdef(paradef).floattype=s64real))) then
-              inc(paraofs)
-            else
-              inc(paraofs,2);
+            inc(paraofs);
           end;
         parasize:=paraofs;
       end;

+ 27 - 3
compiler/wasm/hlcgcpu.pas

@@ -42,8 +42,13 @@ uses
       fevalstackheight,
       fmaxevalstackheight: longint;
      public
+      blocks: integer;
+
       constructor create;
 
+      procedure incblock;
+      procedure decblock;
+
       procedure incstack(list : TAsmList;slots: longint);
       procedure decstack(list : TAsmList;slots: longint);
 
@@ -234,6 +239,7 @@ uses
       procedure concatcopy_set(list: TAsmList; size: tdef; const source, dest: treference);
       procedure concatcopy_shortstring(list: TAsmList; size: tdef; const source, dest: treference);
 
+      procedure paravarsym_set_initialloc_to_paraloc(vs: tparavarsym); override;
     end;
 
 implementation
@@ -259,7 +265,7 @@ implementation
       A_None,      {OP_NOT,  simple logical not       } // not = xor - 1
       a_i32_or,    {OP_OR,   simple logical or        }
       a_i32_shr_s, {OP_SAR,  arithmetic shift-right   }
-      a_i32_shr_s, {OP_SHL,  logical shift left       }
+      a_i32_shl,   {OP_SHL,  logical shift left       }
       a_i32_shr_u, {OP_SHR,  logical shift right      }
       a_i32_sub,   {OP_SUB,  simple subtraction       }
       a_i32_xor,   {OP_XOR,  simple exclusive or      }
@@ -279,7 +285,7 @@ implementation
       A_None,      {OP_NOT,  simple logical not       } // not = xor - 1
       a_i64_or,    {OP_OR,   simple logical or        }
       a_i64_shr_s, {OP_SAR,  arithmetic shift-right   }
-      a_i64_shr_s, {OP_SHL,  logical shift left       }
+      a_i64_shl,   {OP_SHL,  logical shift left       }
       a_i64_shr_u, {OP_SHR,  logical shift right      }
       a_i64_sub,   {OP_SUB,  simple subtraction       }
       a_i64_xor,   {OP_XOR,  simple exclusive or      }
@@ -293,7 +299,18 @@ implementation
       fmaxevalstackheight:=0;
     end;
 
-  procedure thlcgwasm.incstack(list: TasmList;slots: longint);
+  procedure thlcgwasm.incblock;
+  begin
+    inc(blocks);
+  end;
+
+  procedure thlcgwasm.decblock;
+  begin
+    dec(blocks);
+    if blocks<0 then Internalerror(2019091807); // out of block
+  end;
+
+    procedure thlcgwasm.incstack(list: TAsmList; slots: longint);
     begin
       if slots=0 then
         exit;
@@ -1490,6 +1507,13 @@ implementation
         decstack(list,2);
       end;
 
+    procedure thlcgwasm.paravarsym_set_initialloc_to_paraloc(vs: tparavarsym);
+      begin
+        // mark all callee side parameters AS local!
+        inherited paravarsym_set_initialloc_to_paraloc(vs);
+        if (vs.initialloc.loc = LOC_REFERENCE) then
+          vs.initialloc.reference.islocal := true;
+      end;
 
   procedure thlcgwasm.g_concatcopy(list: TAsmList; size: tdef; const source, dest: treference);
     var