mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Add offset and index to instructions and operands
This commit is contained in:
@@ -267,51 +267,8 @@ public class Disassembler
|
||||
// Insert a label to mark the start of the object section.
|
||||
yield return new SectionDirective("object");
|
||||
|
||||
while (reader.CurrentOffset < reader.Size)
|
||||
{
|
||||
if (_offsetLabelMap.TryGetValue(reader.CurrentOffset, out var labels))
|
||||
foreach (var label in labels)
|
||||
yield return label;
|
||||
|
||||
var opCode = (OpCode)reader.ReadByte();
|
||||
|
||||
var instSchema = InstructionSet.InstructionSchema[opCode];
|
||||
Operand[] operands = new Operand[instSchema.Length];
|
||||
|
||||
for (int i = 0; i < instSchema.Length; i++)
|
||||
{
|
||||
var operandDataType = instSchema[i];
|
||||
Operand operand;
|
||||
|
||||
if (operandDataType == LiteralDataType.ConstantIndex)
|
||||
{
|
||||
// Refer to the constant by name rather than index
|
||||
var constantIndex = reader.ReadUInt16();
|
||||
|
||||
// TODO: Only generate name if not using a shared binary table
|
||||
operand = new OperandReference($"const{constantIndex}");
|
||||
}
|
||||
else
|
||||
{
|
||||
object literalValue = OperandLiteral.ReduceDataType(operandDataType) switch
|
||||
{
|
||||
LiteralDataType.Byte => reader.ReadByte(),
|
||||
LiteralDataType.UInt16 => reader.ReadUInt16(),
|
||||
LiteralDataType.UInt32 => reader.ReadUInt32(),
|
||||
LiteralDataType.Int32 => reader.ReadInt32(),
|
||||
_ => throw new InvalidOperationException($"Unexpected operand data type '{operandDataType}'")
|
||||
};
|
||||
|
||||
operand = new OperandLiteral(literalValue, operandDataType);
|
||||
}
|
||||
|
||||
operands[i] = operand;
|
||||
}
|
||||
|
||||
yield return new Instruction(opCode, operands);
|
||||
}
|
||||
|
||||
yield break;
|
||||
foreach (var codeItem in ObjectSection.Decode(reader, _offsetLabelMap))
|
||||
yield return codeItem;
|
||||
}
|
||||
|
||||
private QualifiedTypeName GetQualifiedName(TypeSchema schema)
|
||||
|
||||
Reference in New Issue
Block a user