Kaynağa Gözat

[PATCH 19/83] adding condition generation of the while and repeat loop

From 63404ec50a9b967e6ebd065dc6c6f17ddf45271c Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Wed, 11 Sep 2019 09:42:45 -0400

git-svn-id: branches/wasm@45896 -
nickysn 5 yıl önce
ebeveyn
işleme
82ddd1370c
1 değiştirilmiş dosya ile 18 ekleme ve 7 silme
  1. 18 7
      compiler/wasm/nwasmflw.pas

+ 18 - 7
compiler/wasm/nwasmflw.pas

@@ -24,6 +24,7 @@ type
 
    twasmwhilerepeatnode = class(tcgwhilerepeatnode)
    public
+     procedure pass_generate_code_condition;
      procedure pass_generate_code;override;
    end;
 
@@ -40,22 +41,32 @@ uses
 
 { twasmwhilerepeatnode }
 
-procedure twasmwhilerepeatnode.pass_generate_code;
+procedure twasmwhilerepeatnode.pass_generate_code_condition;
 begin
-  current_asmdata.CurrAsmList.concat(taicpu.op_none(a_block));
-  current_asmdata.CurrAsmList.concat(taicpu.op_none(a_loop));
-
   secondpass(left);
 
   // reversing the condition
   // todo: there should be a better approach
-  current_asmdata.CurrAsmList.concat(taicpu.op_const(a_i32_const,1) );
-  current_asmdata.CurrAsmList.concat(taicpu.op_none(a_i32_xor) );
-
+  if not (lnf_checknegate in loopflags) then begin
+    current_asmdata.CurrAsmList.concat(taicpu.op_const(a_i32_const,1) );
+    current_asmdata.CurrAsmList.concat(taicpu.op_none(a_i32_xor) );
+  end;
   current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br_if,1) );
+end;
+
+procedure twasmwhilerepeatnode.pass_generate_code;
+begin
+  current_asmdata.CurrAsmList.concat(taicpu.op_none(a_block));
+  current_asmdata.CurrAsmList.concat(taicpu.op_none(a_loop));
+
+  if lnf_testatbegin in loopflags then
+    pass_generate_code_condition;
 
   secondpass(right);
 
+  if not (lnf_testatbegin in loopflags) then
+    pass_generate_code_condition;
+
   current_asmdata.CurrAsmList.concat(taicpu.op_const(a_br,0) );
 
   current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end));