Browse Source

+ support the native exception instructions in TWasmValidationStacks.Validate

Nikolay Nikolov 1 year ago
parent
commit
6a28ac53da
1 changed files with 20 additions and 1 deletions
  1. 20 1
      compiler/wasm32/aasmcpu.pas

+ 20 - 1
compiler/wasm32/aasmcpu.pas

@@ -1048,7 +1048,8 @@ uses
             end;
             end;
           a_if,
           a_if,
           a_block,
           a_block,
-          a_loop:
+          a_loop,
+          a_try:
             begin
             begin
               if a.opcode=a_if then
               if a.opcode=a_if then
                 PopVal(wbt_i32);
                 PopVal(wbt_i32);
@@ -1071,6 +1072,13 @@ uses
                 internalerror(2024022512);
                 internalerror(2024022512);
               PushCtrl(a_else,frame.start_types,frame.end_types);
               PushCtrl(a_else,frame.start_types,frame.end_types);
             end;
             end;
+          a_catch:
+            begin
+              frame:=PopCtrl;
+              if (frame.opcode<>a_try) and (frame.opcode<>a_catch) then
+                internalerror(2024022701);
+              PushCtrl(a_catch,frame.start_types,frame.end_types);
+            end;
           a_end_if:
           a_end_if:
             begin
             begin
               frame:=PopCtrl;
               frame:=PopCtrl;
@@ -1092,6 +1100,13 @@ uses
                 internalerror(2024022515);
                 internalerror(2024022515);
               PushVals(frame.end_types);
               PushVals(frame.end_types);
             end;
             end;
+          a_end_try:
+            begin
+              frame:=PopCtrl;
+              if (frame.opcode<>a_try) and (frame.opcode<>a_catch) then
+                internalerror(2024022702);
+              PushVals(frame.end_types);
+            end;
           a_br:
           a_br:
             begin
             begin
               if a.ops<>1 then
               if a.ops<>1 then
@@ -1117,6 +1132,10 @@ uses
               PopVals(label_types(FCtrlStack[n]));
               PopVals(label_types(FCtrlStack[n]));
               PushVals(label_types(FCtrlStack[n]));
               PushVals(label_types(FCtrlStack[n]));
             end;
             end;
+          a_throw:
+            Unreachable;
+          a_rethrow:
+            Unreachable;
           a_return:
           a_return:
             begin
             begin
               PopVals(FFuncType.results);
               PopVals(FFuncType.results);