Browse Source

+ support a_catch,a_catch_ref,a_catch_all and a_catch_all_ref in tcpuprocinfo.ConvertBranchTargetNumbersToLabels

Nikolay Nikolov 2 days ago
parent
commit
5be2acb757
1 changed files with 20 additions and 7 deletions
  1. 20 7
      compiler/wasm32/cpupi.pas

+ 20 - 7
compiler/wasm32/cpupi.pas

@@ -411,20 +411,33 @@ implementation
         instr: taicpu;
         instr: taicpu;
         bl: taicpu_wasm_structured_instruction;
         bl: taicpu_wasm_structured_instruction;
         l: TAsmLabel;
         l: TAsmLabel;
+        lblopidx: Integer;
       begin
       begin
         result.typ:=amfrtNoChange;
         result.typ:=amfrtNoChange;
         if ai.typ<>ait_instruction then
         if ai.typ<>ait_instruction then
           exit;
           exit;
         instr:=taicpu(ai);
         instr:=taicpu(ai);
-        if not (instr.opcode in [a_br,a_br_if]) then
-          exit;
-        if instr.ops<>1 then
-          internalerror(2023101601);
-        if instr.oper[0]^.typ<>top_const then
+        case instr.opcode of
+          a_br,a_br_if,a_catch_all,a_catch_all_ref:
+            begin
+              if instr.ops<>1 then
+                internalerror(2023101601);
+              lblopidx:=0;
+            end;
+          a_catch,a_catch_ref:
+            begin
+              if instr.ops<>2 then
+                internalerror(2023101601);
+              lblopidx:=1;
+            end;
+          else
+            exit;
+        end;
+        if instr.oper[lblopidx]^.typ<>top_const then
           exit;
           exit;
-        bl:=blockstack[instr.oper[0]^.val];
+        bl:=blockstack[instr.oper[lblopidx]^.val];
         l:=bl.getlabel;
         l:=bl.getlabel;
-        instr.loadsymbol(0,l,0);
+        instr.loadsymbol(lblopidx,l,0);
       end;
       end;
 
 
     function tcpuprocinfo.ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
     function tcpuprocinfo.ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;