InterpreterEntry refinements

This commit is contained in:
Yoshi Askharoun
2023-08-22 02:04:19 -05:00
parent d0b65a58d7
commit a4c47e611a
3 changed files with 58 additions and 3 deletions
@@ -6,7 +6,7 @@ using System.Text;
namespace Microsoft.Iris.Debug.Data;
[Serializable]
public class InterpreterEntry
public class InterpreterEntry : IComparable<InterpreterEntry>
{
public InterpreterEntry() { }
@@ -23,6 +23,8 @@ public class InterpreterEntry
public string LoadUri { get; set; }
public string InstructionString => ToInstructionString();
public List<InterpreterObject> Parameters { get; } = new();
public List<InterpreterObject> ReturnValues { get; } = new();
@@ -43,4 +45,43 @@ public class InterpreterEntry
return sb.ToString();
}
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);
}
}
@@ -5,11 +5,25 @@ namespace Microsoft.Iris.Debug.Data;
[Serializable]
public class InterpreterObject
{
private object _value;
public string Name { get; set; }
public Type Type { get; set; }
public object Value { get; set; }
public object Value
{
get => _value;
set
{
if (Type == typeof(uint))
_value = BitConverter.ToUInt32((byte[])value, 0);
else if (Type == typeof(ulong))
_value = BitConverter.ToUInt64((byte[])value, 0);
else
_value = value;
}
}
public InstructionObjectSource Source { get; set; }
+1 -1
View File
@@ -100,7 +100,7 @@ namespace Microsoft.Iris.Markup
int typeIndex = reader.ReadUInt16();
TypeSchema typeSchema = importTables.TypeImports[typeIndex];
entry.Parameters.Add(new InterpreterObject("type", typeof(TypeSchema),
typeSchema, InstructionObjectSource.TypeImports));
typeSchema, InstructionObjectSource.TypeImports, typeIndex));
object newObj = typeSchema.ConstructDefault();