From 0ae014a98f254bbbdc2387d45ea061c553cd74e3 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Sun, 25 Feb 2024 13:52:34 +0200 Subject: [PATCH] + support the BR and BR_IF instructions in TWasmValidationStacks.Validate --- compiler/wasm32/aasmcpu.pas | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compiler/wasm32/aasmcpu.pas b/compiler/wasm32/aasmcpu.pas index 5c6e4a8aee..b6698e9b22 100644 --- a/compiler/wasm32/aasmcpu.pas +++ b/compiler/wasm32/aasmcpu.pas @@ -641,6 +641,7 @@ uses var frame: TWasmControlFrame; + n: TCGInt; begin case a.opcode of a_nop: @@ -1084,6 +1085,31 @@ uses internalerror(2024022515); PushVals(frame.end_types); end; + a_br: + begin + if a.ops<>1 then + internalerror(2024022516); + if a.oper[0]^.typ<>top_const then + internalerror(2024022517); + n:=a.oper[0]^.val; + if FCtrlStack.Count < n then + internalerror(2024022518); + PopVals(label_types(FCtrlStack[n])); + Unreachable; + end; + a_br_if: + begin + if a.ops<>1 then + internalerror(2024022519); + if a.oper[0]^.typ<>top_const then + internalerror(2024022520); + n:=a.oper[0]^.val; + if FCtrlStack.Count < n then + internalerror(2024022521); + PopVal(wbt_i32); + PopVals(label_types(FCtrlStack[n])); + PushVals(label_types(FCtrlStack[n])); + end; else internalerror(2024030502); end;