2023-05-24 10:14:07 -05:00
|
|
|
using Microsoft.Iris.Markup;
|
|
|
|
|
using System;
|
2022-06-07 14:30:29 -05:00
|
|
|
using System.Collections.Generic;
|
2023-05-24 16:24:48 -05:00
|
|
|
using System.Text;
|
2022-06-07 01:00:15 -05:00
|
|
|
|
2023-05-22 18:04:22 -05:00
|
|
|
namespace Microsoft.Iris.Debug.Data;
|
|
|
|
|
|
2023-05-24 10:14:07 -05:00
|
|
|
[Serializable]
|
2023-08-22 02:04:19 -05:00
|
|
|
public class InterpreterEntry : IComparable<InterpreterEntry>
|
2022-06-07 01:00:15 -05:00
|
|
|
{
|
2023-05-25 21:01:48 -05:00
|
|
|
public InterpreterEntry() { }
|
|
|
|
|
|
|
|
|
|
public InterpreterEntry(OpCode opCode, uint offset, string loadUri)
|
2022-06-07 01:00:15 -05:00
|
|
|
{
|
2023-05-22 18:04:22 -05:00
|
|
|
OpCode = opCode;
|
2023-05-24 16:24:48 -05:00
|
|
|
Offset = offset;
|
|
|
|
|
LoadUri = loadUri;
|
2022-06-07 01:00:15 -05:00
|
|
|
}
|
|
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public OpCode OpCode { get; set; }
|
2023-05-24 16:24:48 -05:00
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public uint Offset { get; set; }
|
2023-05-24 16:24:48 -05:00
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public string LoadUri { get; set; }
|
2023-05-24 16:24:48 -05:00
|
|
|
|
2023-08-22 02:04:19 -05:00
|
|
|
public string InstructionString => ToInstructionString();
|
|
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public List<InterpreterObject> Parameters { get; } = new();
|
2023-05-24 16:24:48 -05:00
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public List<InterpreterObject> ReturnValues { get; } = new();
|
2023-05-22 18:04:22 -05:00
|
|
|
|
|
|
|
|
public override string ToString()
|
2022-06-07 01:00:15 -05:00
|
|
|
{
|
2023-05-25 01:01:57 -05:00
|
|
|
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Parameters)})");
|
2023-05-24 16:24:48 -05:00
|
|
|
|
|
|
|
|
if (ReturnValues.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(" -> ");
|
|
|
|
|
|
|
|
|
|
if (ReturnValues.Count == 1)
|
|
|
|
|
sb.Append(ReturnValues[0]);
|
|
|
|
|
else
|
|
|
|
|
sb.Append($"[{string.Join(", ", ReturnValues)}]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
2022-06-07 01:00:15 -05:00
|
|
|
}
|
2023-08-22 02:04:19 -05:00
|
|
|
|
|
|
|
|
public string ToInstructionString()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
sb.AppendFormat("0x{0:X4}", Offset);
|
|
|
|
|
sb.Append('\t');
|
|
|
|
|
sb.Append(OpCode);
|
|
|
|
|
sb.Append(' ', 2);
|
|
|
|
|
|
|
|
|
|
for (int p = 0; p < Parameters.Count; ++p)
|
|
|
|
|
{
|
|
|
|
|
var param = Parameters[p];
|
|
|
|
|
|
|
|
|
|
if (p != 0)
|
|
|
|
|
sb.Append(", ");
|
|
|
|
|
|
|
|
|
|
if (param.Source == InstructionObjectSource.Inline)
|
|
|
|
|
sb.Append(param.Value ?? "NULL");
|
|
|
|
|
else
|
|
|
|
|
sb.Append(param.Source);
|
|
|
|
|
|
|
|
|
|
if (param.TableIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
sb.Append('[');
|
|
|
|
|
sb.Append(param.TableIndex);
|
|
|
|
|
sb.Append(']');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CompareTo(InterpreterEntry other)
|
|
|
|
|
{
|
|
|
|
|
int stringCmp = LoadUri.CompareTo(other.LoadUri);
|
|
|
|
|
return stringCmp != 0
|
|
|
|
|
? stringCmp
|
|
|
|
|
: Offset.CompareTo(other.Offset);
|
|
|
|
|
}
|
2022-06-07 01:00:15 -05:00
|
|
|
}
|