Bläddra i källkod

[PATCH 49/83] update the different continue-branching depending on the loop condition check placement

From df5168d5dc713daba089fad84bcdb1904d94afea Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Fri, 20 Sep 2019 00:20:20 -0400

git-svn-id: branches/wasm@45926 -
nickysn 5 år sedan
förälder
incheckning
bafec93cef
2 ändrade filer med 13 tillägg och 1 borttagningar
  1. 4 1
      compiler/wasm/hlcgcpu.pas
  2. 9 0
      compiler/wasm/nwasmflw.pas

+ 4 - 1
compiler/wasm/hlcgcpu.pas

@@ -43,6 +43,9 @@ uses
       fmaxevalstackheight: longint;
      public
       blocks: integer;
+      loopContBr: integer; // the value is different depending of the condition test
+                           // if it's in the beggning the jump should be done to the loop (1)
+                           // if the condition at the end, the jump should done to the end of block (0)
 
       constructor create;
 
@@ -1356,7 +1359,7 @@ implementation
         list.concat(taicpu.op_const(a_br,2+blocks))
       end else if l = current_procinfo.CurrContinueLabel then begin
         list.concat(taicpu.op_const(a_i32_const, 0));
-        list.concat(taicpu.op_const(a_br,1+blocks))
+        list.concat(taicpu.op_const(a_br,loopContBr+blocks))
       end else begin
         //Internalerror(2019091806); // unexpected jump
         Internalerror(2019091806); // unexpected jump

+ 9 - 0
compiler/wasm/nwasmflw.pas

@@ -81,6 +81,7 @@ var
    oldclabel,oldblabel : tasmlabel;
    truelabel,falselabel : tasmlabel;
    oldflowcontrol : tflowcontrol;
+   oldloopbroffset: Integer;
 begin
   location_reset(location,LOC_VOID,OS_NO);
 
@@ -89,6 +90,8 @@ begin
   current_asmdata.getjumplabel(lbreak);
 
   oldflowcontrol:=flowcontrol;
+
+  oldloopbroffset:=thlcgwasm(hlcg).loopContBr;
   oldclabel:=current_procinfo.CurrContinueLabel;
   oldblabel:=current_procinfo.CurrBreakLabel;
 
@@ -99,7 +102,11 @@ begin
   current_asmdata.CurrAsmList.concat(taicpu.op_none(a_loop));
 
   if lnf_testatbegin in loopflags then
+  begin
     pass_generate_code_condition;
+    thlcgwasm(hlcg).loopContBr:=1;
+  end else
+    thlcgwasm(hlcg).loopContBr:=0;
 
   current_asmdata.CurrAsmList.concat(taicpu.op_none(a_block));
 
@@ -122,6 +129,8 @@ begin
 
   current_procinfo.CurrContinueLabel:=oldclabel;
   current_procinfo.CurrBreakLabel:=oldblabel;
+  thlcgwasm(hlcg).loopContBr:=oldloopbroffset;
+
   { a break/continue in a while/repeat block can't be seen outside }
   flowcontrol:=oldflowcontrol+(flowcontrol-[fc_break,fc_continue,fc_inflowcontrol]);