From 9f45104c510ba2ec08c3b76c3bd42eca0264df8a Mon Sep 17 00:00:00 2001 From: Kelvin Nishikawa Date: Tue, 26 Nov 2024 15:23:35 -0800 Subject: [PATCH 1/4] Fixing ComputePointerPath --- Wacs.Core/Runtime/ExecContext.cs | 40 ++++++++++++++++---------------- Wacs.Core/Runtime/Frame.cs | 14 +++++++++++ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Wacs.Core/Runtime/ExecContext.cs b/Wacs.Core/Runtime/ExecContext.cs index 8c71764..25e5530 100644 --- a/Wacs.Core/Runtime/ExecContext.cs +++ b/Wacs.Core/Runtime/ExecContext.cs @@ -334,26 +334,26 @@ public void FunctionReturn() Stack<(string, int)> ascent = new(); int idx = _sequenceIndex; - // foreach (var label in Frame.Labels) - // { - // var pointer = (label.Instruction.GetMnemonic(), idx); - // ascent.Push(pointer); - // - // idx = label.ContinuationAddress.Index; - // - // switch ((OpCode)label.Instruction) - // { - // case OpCode.If: ascent.Push(("InstIf", 0)); - // break; - // case OpCode.Else: ascent.Push(("InstElse", 1)); - // break; - // case OpCode.Block: ascent.Push(("InstBlock", 0)); - // break; - // case OpCode.Loop: ascent.Push(("InstLoop", 0)); - // break; - // } - // - // } + foreach (var label in Frame.EnumerateLabels()) + { + var pointer = (label.Instruction.GetMnemonic(), idx); + ascent.Push(pointer); + + idx = label.ContinuationAddress.Index; + + switch ((OpCode)label.Instruction) + { + case OpCode.If: ascent.Push(("InstIf", 0)); + break; + case OpCode.Else: ascent.Push(("InstElse", 1)); + break; + case OpCode.Block: ascent.Push(("InstBlock", 0)); + break; + case OpCode.Loop: ascent.Push(("InstLoop", 0)); + break; + } + + } ascent.Push(("Function", (int)Frame.Index.Value)); diff --git a/Wacs.Core/Runtime/Frame.cs b/Wacs.Core/Runtime/Frame.cs index cca966f..46d0314 100644 --- a/Wacs.Core/Runtime/Frame.cs +++ b/Wacs.Core/Runtime/Frame.cs @@ -15,6 +15,8 @@ // */ using System.Buffers; +using System.Collections; +using System.Collections.Generic; using System.IO; using Wacs.Core.Instructions; using Wacs.Core.OpCodes; @@ -125,5 +127,17 @@ public InstructionPointer PopLabels(int idx) return oldLabel.Label.ContinuationAddress; } + + public IEnumerable