Files
MicrosoftIris/UIX/Microsoft/Iris/Debug/Data/InterpreterEntry.cs
T

88 lines
2.4 KiB
C#
Raw Normal View History

using Microsoft.Iris.Markup;
using System;
2022-06-07 14:30:29 -05:00
using System.Collections.Generic;
using System.Runtime.Serialization;
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;
[Serializable]
2023-05-22 18:04:22 -05:00
public class InterpreterEntry
2022-06-07 01:00:15 -05:00
{
2023-05-24 16:24:48 -05:00
public InterpreterEntry(OpCode opCode, uint offset, string loadUri, params OpCodeArgument[] args)
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 14:30:29 -05:00
2023-05-22 18:04:22 -05:00
if (args != null && args.Length > 0)
Arguments = args;
else
Arguments = new List<OpCodeArgument>();
2022-06-07 01:00:15 -05:00
}
public OpCode OpCode { get; }
2023-05-24 16:24:48 -05:00
public uint Offset { get; }
public string LoadUri { get; }
2023-05-22 18:04:22 -05:00
public IList<OpCodeArgument> Arguments { get; }
2023-05-24 16:24:48 -05:00
2023-05-22 18:04:22 -05:00
public IList<object> ReturnValues { get; } = new List<object>();
public override string ToString()
2022-06-07 01:00:15 -05:00
{
2023-05-24 16:24:48 -05:00
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Arguments)})");
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-05-22 18:04:22 -05:00
[Serializable]
public class OpCodeArgument : ISerializable
2023-05-22 18:04:22 -05:00
{
public string Name { get; set; }
public Type Type { get; set; }
public object Value { get; set; }
protected bool CanSerializeValue => Value is ISerializable;
2023-05-22 18:04:22 -05:00
public OpCodeArgument(string name, Type type, object value)
{
Name = name;
Type = type;
Value = value;
}
protected OpCodeArgument(SerializationInfo info, StreamingContext context)
{
Name = info.GetString(nameof(Name));
Type = Type.GetType(info.GetString(nameof(Type)), false);
bool canSerializeValue = info.GetBoolean(nameof(CanSerializeValue));
Type valueSerializeType = canSerializeValue ? Type : typeof(string);
Value = info.GetValue(nameof(Value), valueSerializeType);
}
2023-05-22 18:04:22 -05:00
public override string ToString() => $"{Type} {Value}";
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Name), Name);
info.AddValue(nameof(Type), Type.FullName);
info.AddValue(nameof(CanSerializeValue), CanSerializeValue);
2023-05-24 15:32:09 -05:00
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value?.ToString());
}
2023-05-22 18:04:22 -05:00
}