/// <summary> /// Formats a single operand /// </summary> /// <param name="src">The source operand</param> public static string Format(this AsmOperandInfo src) { var fmt = src.ImmInfo.Map(i => $"{i.Value.FormatHex(false,true,false,false)}:{i.Label}", () => string.Empty); fmt += src.Register.Map(r => r.RegisterName, () => string.Empty); fmt += src.Memory.Map(r => r.Format(), () => string.Empty); fmt += src.Branch.Map(b => b.Format(), () => string.Empty); if (string.IsNullOrWhiteSpace(fmt)) { fmt = src.Kind; } return(fmt); }
/// <summary> /// Extracts operand information from an instruction /// </summary> /// <param name="inx">The source instruction</param> static AsmOperandInfo[] DistillOperands(this Instruction inx, MethodAsmBody asm) { var args = new AsmOperandInfo[inx.OpCount]; for (byte j = 0; j < inx.OpCount; j++) { var operandKind = inx.GetOpKind(j); var imm = inx.ImmediateInfo(j); var reg = operandKind == AsmOpKind.Register ? inx.RegisterInfo(j) : null; var mem = operandKind.IsMemory() ? inx.MemoryInfo(j) : null; var branch = operandKind.IsBranch() ? inx.BranchInfo(j, asm.StartAddress) : null; args[j] = new AsmOperandInfo(j, operandKind.ToString(), imm, mem, reg, branch); } return(args); }