瀏覽代碼

+ implemented TWasmValueStack.GetCount
+ implemented TWasmControlStack.GetCount
+ implemented TWasmValidationStacks.PopVal

Nikolay Nikolov 1 年之前
父節點
當前提交
1786875319
共有 1 個文件被更改,包括 28 次插入0 次删除
  1. 28 0
      compiler/wasm32/aasmcpu.pas

+ 28 - 0
compiler/wasm32/aasmcpu.pas

@@ -47,12 +47,14 @@ uses
       TWasmValueStack = class
       private
         FValStack: array of TWasmBasicType;
+        function GetCount: Integer;
         function GetItems(AIndex: Integer): TWasmBasicType;
         procedure SetItems(AIndex: Integer; AValue: TWasmBasicType);
       public
         procedure Push(wbt: TWasmBasicType);
         function Pop: TWasmBasicType;
         property Items[AIndex: Integer]: TWasmBasicType read GetItems write SetItems; default;
+        property Count: Integer read GetCount;
       end;
 
       { TWasmControlFrame }
@@ -70,12 +72,14 @@ uses
       TWasmControlStack = class
       private
         FControlStack: array of TWasmControlFrame;
+        function GetCount: Integer;
         function GetItems(AIndex: Integer): TWasmControlFrame;
         procedure SetItems(AIndex: Integer; const AValue: TWasmControlFrame);
       public
         procedure Push(const wcf: TWasmControlFrame);
         function Pop: TWasmControlFrame;
         property Items[AIndex: Integer]: TWasmControlFrame read GetItems write SetItems; default;
+        property Count: Integer read GetCount;
       end;
 
       { TWasmValidationStacks }
@@ -89,6 +93,7 @@ uses
         destructor Destroy; override;
 
         procedure PushVal(vt: TWasmBasicType);
+        function PopVal: TWasmBasicType;
       end;
 
       twasmstruc_stack = class;
@@ -364,6 +369,11 @@ uses
         Result:=FValStack[I];
       end;
 
+    function TWasmValueStack.GetCount: Integer;
+      begin
+        Result:=Length(FValStack);
+      end;
+
     procedure TWasmValueStack.SetItems(AIndex: Integer; AValue: TWasmBasicType);
       var
         I: Integer;
@@ -400,6 +410,11 @@ uses
         Result:=FControlStack[I];
       end;
 
+    function TWasmControlStack.GetCount: Integer;
+      begin
+        Result:=Length(FControlStack);
+      end;
+
     procedure TWasmControlStack.SetItems(AIndex: Integer; const AValue: TWasmControlFrame);
       var
         I: Integer;
@@ -444,6 +459,19 @@ uses
         FValueStack.Push(vt);
       end;
 
+    function TWasmValidationStacks.PopVal: TWasmBasicType;
+      begin
+        if FValueStack.Count = FCtrlStack[0].height then
+          begin
+            if FCtrlStack[0].unreachable then
+              Result:=wbt_Unknown
+            else
+              internalerror(2024013104);
+          end
+        else
+          Result:=FValueStack.Pop;
+      end;
+
     { twasmstruc_stack }
 
     function twasmstruc_stack.Get(Index: Integer): taicpu_wasm_structured_instruction;