mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Add more information to interpreter entries and objects
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Microsoft.Iris.Markup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Iris.Debug.Data;
|
||||
@@ -9,16 +8,16 @@ namespace Microsoft.Iris.Debug.Data;
|
||||
[Serializable]
|
||||
public class InterpreterEntry
|
||||
{
|
||||
public InterpreterEntry(OpCode opCode, uint offset, string loadUri, params OpCodeArgument[] args)
|
||||
public InterpreterEntry(OpCode opCode, uint offset, string loadUri, params InterpreterObject[] args)
|
||||
{
|
||||
OpCode = opCode;
|
||||
Offset = offset;
|
||||
LoadUri = loadUri;
|
||||
|
||||
if (args != null && args.Length > 0)
|
||||
Arguments = args;
|
||||
Parameters = args;
|
||||
else
|
||||
Arguments = new List<OpCodeArgument>();
|
||||
Parameters = new List<InterpreterObject>();
|
||||
}
|
||||
|
||||
public OpCode OpCode { get; }
|
||||
@@ -27,13 +26,13 @@ public class InterpreterEntry
|
||||
|
||||
public string LoadUri { get; }
|
||||
|
||||
public IList<OpCodeArgument> Arguments { get; }
|
||||
public IList<InterpreterObject> Parameters { get; }
|
||||
|
||||
public IList<object> ReturnValues { get; } = new List<object>();
|
||||
public IList<InterpreterObject> ReturnValues { get; } = new List<InterpreterObject>();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Arguments)})");
|
||||
StringBuilder sb = new($"[{LoadUri} @ 0x{Offset:X}] {OpCode}({string.Join(", ", Parameters)})");
|
||||
|
||||
if (ReturnValues.Count > 0)
|
||||
{
|
||||
@@ -48,40 +47,3 @@ public class InterpreterEntry
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class OpCodeArgument : ISerializable
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
protected bool CanSerializeValue => Value is ISerializable;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value?.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.Iris.Debug.Data;
|
||||
|
||||
[Serializable]
|
||||
public class InterpreterObject : ISerializable
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public Type Type { get; set; }
|
||||
|
||||
public object Value { get; set; }
|
||||
|
||||
public InstructionObjectSource Source { get; set; }
|
||||
|
||||
public int TableIndex { get; set; } = -1;
|
||||
|
||||
protected bool CanSerializeValue => Value is ISerializable;
|
||||
|
||||
public InterpreterObject(string name, Type type, object value, InstructionObjectSource source, int tableIndex = -1)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
Value = value;
|
||||
Source = source;
|
||||
TableIndex = tableIndex;
|
||||
}
|
||||
|
||||
public InterpreterObject(object value) : this(null, value?.GetType() ?? typeof(object), value, InstructionObjectSource.Dynamic)
|
||||
{
|
||||
}
|
||||
|
||||
protected InterpreterObject(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
Name = info.GetString(nameof(Name));
|
||||
Type = Type.GetType(info.GetString(nameof(Type)), false);
|
||||
Source = (InstructionObjectSource)info.GetByte(nameof(Source));
|
||||
TableIndex = info.GetInt32(nameof(TableIndex));
|
||||
|
||||
bool canSerializeValue = info.GetBoolean(nameof(CanSerializeValue));
|
||||
Type valueSerializeType = canSerializeValue ? Type : typeof(string);
|
||||
Value = info.GetValue(nameof(Value), valueSerializeType);
|
||||
}
|
||||
|
||||
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(Source), (byte)Source);
|
||||
info.AddValue(nameof(TableIndex), TableIndex);
|
||||
info.AddValue(nameof(CanSerializeValue), CanSerializeValue);
|
||||
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value?.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates where the argument value came from.
|
||||
/// </summary>
|
||||
public enum InstructionObjectSource : byte
|
||||
{
|
||||
Dynamic,
|
||||
Stack,
|
||||
Inline,
|
||||
Exports,
|
||||
Alias,
|
||||
DataMappings,
|
||||
BinaryData,
|
||||
Constants,
|
||||
SymbolReference,
|
||||
|
||||
Imports = 1 << 4,
|
||||
TypeImports = Imports | 1,
|
||||
ConstructorImports = Imports | 2,
|
||||
PropertyImports = Imports | 3,
|
||||
MethodImports = Imports | 4,
|
||||
EventImports = Imports | 5,
|
||||
}
|
||||
Reference in New Issue
Block a user