Separate decode and execute steps

This commit is contained in:
Yoshi Askharoun
2023-10-09 14:46:51 -05:00
parent be78b55a30
commit b5837bd3b8
8 changed files with 191 additions and 47 deletions
@@ -1,5 +1,4 @@
using Microsoft.Iris.Markup;
using System;
using System;
using System.Collections.Generic;
using System.Text;
@@ -15,27 +14,26 @@ public class InterpreterEntry : IComparable<InterpreterEntry>
Instruction = instruction;
}
public InterpreterInstruction Instruction { get; }
public InterpreterInstruction Instruction { get; set; }
public List<InterpreterObject> Parameters { get; } = new();
public List<InterpreterObject> ReturnValues { get; } = new();
public string InstructionString => ToInstructionString();
public override string ToString()
{
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Parameters)})");
StringBuilder sb = new($"[{Instruction.LoadUri} @ 0x{Instruction.Offset:X}] " +
$"{Instruction.OpCode}({string.Join(", ", Parameters)})");
if (ReturnValues.Count > 0)
{
sb.Append(" -> ");
if (ReturnValues.Count <= 0)
return sb.ToString();
sb.Append(" -> ");
if (ReturnValues.Count == 1)
sb.Append(ReturnValues[0]);
else
sb.Append($"[{string.Join(", ", ReturnValues)}]");
}
if (ReturnValues.Count == 1)
sb.Append(ReturnValues[0]);
else
sb.Append($"[{string.Join(", ", ReturnValues)}]");
return sb.ToString();
}
@@ -1,11 +1,14 @@
using Microsoft.Iris.Markup;
using System;
using System.Collections.Generic;
namespace Microsoft.Iris.Debug.Data;
[Serializable]
public class InterpreterInstruction : IComparable<InterpreterInstruction>
{
public InterpreterInstruction() { }
public InterpreterInstruction(OpCode opCode, uint offset, string loadUri)
{
OpCode = opCode;
@@ -19,11 +22,15 @@ public class InterpreterInstruction : IComparable<InterpreterInstruction>
public string LoadUri { get; set; }
public List<object> Operands { get; } = new();
public int CompareTo(InterpreterInstruction other)
{
int stringCmp = LoadUri.CompareTo(other.LoadUri);
var stringCmp = string.Compare(LoadUri, other.LoadUri, StringComparison.Ordinal);
return stringCmp != 0
? stringCmp
: Offset.CompareTo(other.Offset);
}
public override string ToString() => $"[0x{Offset:X}] {OpCode} {string.Join(", ", Operands)}";
}
@@ -4,7 +4,8 @@ public enum DebuggerMessageType : int
{
Null = 0,
InterpreterOpCode,
InterpreterDecode,
InterpreterExecute,
DispatcherStep,
UpdateBreakpoint,
+7 -2
View File
@@ -15,9 +15,14 @@ public interface IDebuggerClient
event Action<InterpreterCommand> InterpreterStateChanged;
/// <summary>
/// Fired when the UIX interpreter steps forward.
/// Fired when the UIX interpreter decodes an instruction.
/// </summary>
event EventHandler<InterpreterEntry> InterpreterStep;
event EventHandler<InterpreterInstruction> InterpreterDecode;
/// <summary>
/// Fired when the UIX interpreter executes an instruction.
/// </summary>
event EventHandler<InterpreterEntry> InterpreterExecute;
/// <summary>
/// Fired when the UIX dispatcher executes another call from the queue.
+8 -2
View File
@@ -7,10 +7,16 @@ internal interface IDebuggerServer
InterpreterCommand DebuggerCommand { get; set; }
/// <summary>
/// Logs the context, opcode, and arguments of an instruction
/// Logs the context, opcode, and operands of an instruction
/// decoded by <c>Microsoft.Iris.Markup.Interpreter</c>.
/// </summary>
void LogInterpreterDecode(object context, InterpreterInstruction instruction);
/// <summary>
/// Logs the context, opcode, arguments, and results of an instruction
/// executed by <c>Microsoft.Iris.Markup.Interpreter</c>.
/// </summary>
void LogInterpreterOpCode(object context, InterpreterEntry entry);
void LogInterpreterExecute(object context, InterpreterEntry entry);
/// <summary>
/// Logs the string representation of a dispatcher step.
@@ -27,7 +27,8 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
}
}
public event EventHandler<InterpreterEntry> InterpreterStep;
public event EventHandler<InterpreterInstruction> InterpreterDecode;
public event EventHandler<InterpreterEntry> InterpreterExecute;
public event Action<string> DispatcherStep;
public event Action<InterpreterCommand> InterpreterStateChanged;
@@ -75,9 +76,14 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
switch (frame.Type)
{
case DebuggerMessageType.InterpreterOpCode:
var entry = frame.DeserializeData<InterpreterEntry>(_formatter);
InterpreterStep?.Invoke(this, entry);
case DebuggerMessageType.InterpreterDecode:
var decEntry = frame.DeserializeData<InterpreterInstruction>(_formatter);
InterpreterDecode?.Invoke(this, decEntry);
break;
case DebuggerMessageType.InterpreterExecute:
var execEntry = frame.DeserializeData<InterpreterEntry>(_formatter);
InterpreterExecute?.Invoke(this, execEntry);
break;
case DebuggerMessageType.DispatcherStep:
@@ -91,7 +97,7 @@ public class NetDebuggerClient : IDebuggerClient, IDisposable
break;
default:
Trace.WriteLine(TraceCategory.MarkupDebug, "Recieved unknown debugger message of type '{0}'.", frame.Type);
Trace.WriteLine(TraceCategory.MarkupDebug, "Received unknown debugger message of type '{0}'.", frame.Type);
break;
}
}
@@ -49,9 +49,14 @@ internal class NetDebuggerServer : IDebuggerServer, IDisposable
Current = this;
}
public void LogInterpreterOpCode(object context, InterpreterEntry entry)
public void LogInterpreterDecode(object context, InterpreterInstruction instruction)
{
QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterOpCode, entry.Serialize(_formatter)));
QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterDecode, instruction.Serialize(_formatter)));
}
public void LogInterpreterExecute(object context, InterpreterEntry entry)
{
QueueDebuggerMessage(new(0, DebuggerMessageType.InterpreterExecute, entry.Serialize(_formatter)));
}
public void LogDispatcher(string message)