7using System.Diagnostics.CodeAnalysis;
12 internal readonly
struct OpCode : IEquatable<OpCode>
18 internal const int OperandTypeMask = 0x1F;
20 internal const int FlowControlShift = 5;
21 internal const int FlowControlMask = 0x0F;
23 internal const int OpCodeTypeShift = 9;
24 internal const int OpCodeTypeMask = 0x07;
26 internal const int StackBehaviourPopShift = 12;
27 internal const int StackBehaviourPushShift = 17;
28 internal const int StackBehaviourMask = 0x1F;
30 internal const int SizeShift = 22;
31 internal const int SizeMask = 0x03;
33 internal const int EndsUncondJmpBlkFlag = 0x01000000;
37 internal const int StackChangeShift = 28;
39 private readonly OpCodeValues m_value;
40 private readonly
int m_flags;
42 internal OpCode(OpCodeValues value,
int flags)
48 internal bool EndsUncondJmpBlk() =>
49 (m_flags & EndsUncondJmpBlkFlag) != 0;
51 internal int StackChange() =>
52 m_flags >> StackChangeShift;
54 public OperandType OperandType => (OperandType)(m_flags & OperandTypeMask);
56 public FlowControl FlowControl => (FlowControl)((m_flags >> FlowControlShift) & FlowControlMask);
58 public OpCodeType OpCodeType => (OpCodeType)((m_flags >> OpCodeTypeShift) & OpCodeTypeMask);
60 public StackBehaviour StackBehaviourPop => (StackBehaviour)((m_flags >> StackBehaviourPopShift) & StackBehaviourMask);
62 public StackBehaviour StackBehaviourPush => (StackBehaviour)((m_flags >> StackBehaviourPushShift) & StackBehaviourMask);
64 public int Size => (m_flags >> SizeShift) & SizeMask;
66 public short Value => (short)m_value;
68 private static volatile string[]? g_nameCache;
79 string[]? nameCache = g_nameCache;
80 if (nameCache ==
null)
82 nameCache =
new string[0x11f];
83 g_nameCache = nameCache;
86 OpCodeValues opCodeValue = (OpCodeValues)(ushort)Value;
88 int idx = (int)opCodeValue;
91 if (idx >= 0xfe00 && idx <= 0xfe1e)
95 idx = 0x100 + (idx - 0xfe00);
109 name = GetEnumName(opCodeValue)!.ToLowerInvariant().Replace(
'_',
'.');
115 string? GetEnumName<T>(T value) where T :
struct,
Enum
118 return Enum.GetName(typeof(T), value);
120 return Enum.GetName(value);
124 public override bool Equals(
object? obj) =>
125 obj is OpCode other && Equals(other);
127 public bool Equals(OpCode obj) => obj.Value == Value;
129 public static bool operator ==(OpCode a, OpCode b) => a.Equals(b);
131 public static bool operator !=(OpCode a, OpCode b) => !(a == b);
133 public override int GetHashCode() => Value;
135 public override string? ToString() =>
Name;
global::java.lang.invoke.LambdaForm.Name Name