Przeglądaj źródła

* convert loop..end_loop blocks to flat list + branch instruction

Nikolay Nikolov 1 rok temu
rodzic
commit
ce742b5b4d
2 zmienionych plików z 21 dodań i 0 usunięć
  1. 8 0
      compiler/wasm32/aasmcpu.pas
  2. 13 0
      compiler/wasm32/cpupi.pas

+ 8 - 0
compiler/wasm32/aasmcpu.pas

@@ -135,6 +135,7 @@ uses
         destructor Destroy; override;
         function getcopy:TLinkedListItem;override;
         procedure Map(f: TAsmMapFunc; blockstack: twasmstruc_stack);override;
+        procedure ConvertToBr(list: TAsmList);
         procedure ConvertToFlatList(l: TAsmList);override;
       end;
 
@@ -659,6 +660,13 @@ uses
         blockstack.pop;
       end;
 
+    procedure tai_wasmstruc_loop.ConvertToBr(list: TAsmList);
+      begin
+        list.concat(tai_label.create(GetLabel));
+        list.concatList(inner_asmlist);
+        list.concat(taicpu.op_sym(a_br,GetLabel));
+      end;
+
     procedure tai_wasmstruc_loop.ConvertToFlatList(l: TAsmList);
       begin
         l.Concat(loop_instr);

+ 13 - 0
compiler/wasm32/cpupi.pas

@@ -41,6 +41,7 @@ interface
 
       function ConvertBranchTargetNumbersToLabels(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
       function ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
+      function ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
 
       { used for allocating locals during the postprocess_code stage (i.e. after register allocation) }
       function AllocWasmLocal(wbt: TWasmBasicType): Integer;
@@ -389,6 +390,17 @@ implementation
           end;
       end;
 
+    function tcpuprocinfo.ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
+      begin
+        result.typ:=amfrtNoChange;
+        if (ai.typ=ait_wasm_structured_instruction) and (ai is tai_wasmstruc_loop) then
+          begin
+            result.typ:=amfrtNewList;
+            result.newlist:=TAsmList.Create;
+            tai_wasmstruc_loop(ai).ConvertToBr(result.newlist);
+          end;
+      end;
+
     function tcpuprocinfo.AllocWasmLocal(wbt: TWasmBasicType): Integer;
       begin
         SetLength(FAllocatedLocals,Length(FAllocatedLocals)+1);
@@ -656,6 +668,7 @@ implementation
 
           map_structured_asmlist(asmlist,@ConvertBranchTargetNumbersToLabels);
           map_structured_asmlist(asmlist,@ConvertIfToBrIf);
+          map_structured_asmlist(asmlist,@ConvertLoopToBr);
 
           l2:=TAsmList.Create;
           wasm_convert_to_flat_asmlist(asmlist,l2);