mscorlib(4.0.0.0) API with additions
OpCode.cs
2 using System.Threading;
3 
5 {
7  [ComVisible(true)]
8  [__DynamicallyInvokable]
9  public struct OpCode
10  {
11  internal const int OperandTypeMask = 31;
12 
13  internal const int FlowControlShift = 5;
14 
15  internal const int FlowControlMask = 15;
16 
17  internal const int OpCodeTypeShift = 9;
18 
19  internal const int OpCodeTypeMask = 7;
20 
21  internal const int StackBehaviourPopShift = 12;
22 
23  internal const int StackBehaviourPushShift = 17;
24 
25  internal const int StackBehaviourMask = 31;
26 
27  internal const int SizeShift = 22;
28 
29  internal const int SizeMask = 3;
30 
31  internal const int EndsUncondJmpBlkFlag = 16777216;
32 
33  internal const int StackChangeShift = 28;
34 
35  private string m_stringname;
36 
37  private StackBehaviour m_pop;
38 
39  private StackBehaviour m_push;
40 
41  private OperandType m_operand;
42 
43  private OpCodeType m_type;
44 
45  private int m_size;
46 
47  private byte m_s1;
48 
49  private byte m_s2;
50 
51  private FlowControl m_ctrl;
52 
53  private bool m_endsUncondJmpBlk;
54 
55  private int m_stackChange;
56 
57  private static volatile string[] g_nameCache;
58 
61  [__DynamicallyInvokable]
63  {
64  [__DynamicallyInvokable]
65  get
66  {
67  return m_operand;
68  }
69  }
70 
73  [__DynamicallyInvokable]
75  {
76  [__DynamicallyInvokable]
77  get
78  {
79  return m_ctrl;
80  }
81  }
82 
85  [__DynamicallyInvokable]
86  public OpCodeType OpCodeType
87  {
88  [__DynamicallyInvokable]
89  get
90  {
91  return m_type;
92  }
93  }
94 
97  [__DynamicallyInvokable]
99  {
100  [__DynamicallyInvokable]
101  get
102  {
103  return m_pop;
104  }
105  }
106 
109  [__DynamicallyInvokable]
111  {
112  [__DynamicallyInvokable]
113  get
114  {
115  return m_push;
116  }
117  }
118 
121  [__DynamicallyInvokable]
122  public int Size
123  {
124  [__DynamicallyInvokable]
125  get
126  {
127  return m_size;
128  }
129  }
130 
133  [__DynamicallyInvokable]
134  public short Value
135  {
136  [__DynamicallyInvokable]
137  get
138  {
139  if (m_size == 2)
140  {
141  return (short)((m_s1 << 8) | m_s2);
142  }
143  return m_s2;
144  }
145  }
146 
149  [__DynamicallyInvokable]
150  public string Name
151  {
152  [__DynamicallyInvokable]
153  get
154  {
155  if (Size == 0)
156  {
157  return null;
158  }
159  string[] array = g_nameCache;
160  if (array == null)
161  {
162  array = (g_nameCache = new string[287]);
163  }
164  OpCodeValues opCodeValues = (OpCodeValues)(ushort)Value;
165  int num = (int)opCodeValues;
166  if (num > 255)
167  {
168  if (num < 65024 || num > 65054)
169  {
170  return null;
171  }
172  num = 256 + (num - 65024);
173  }
174  string text = Volatile.Read(ref array[num]);
175  if (text != null)
176  {
177  return text;
178  }
179  text = Enum.GetName(typeof(OpCodeValues), opCodeValues).ToLowerInvariant().Replace("_", ".");
180  Volatile.Write(ref array[num], text);
181  return text;
182  }
183  }
184 
185  internal OpCode(OpCodeValues value, int flags)
186  {
187  m_stringname = null;
188  m_pop = (StackBehaviour)((flags >> 12) & 0x1F);
189  m_push = (StackBehaviour)((flags >> 17) & 0x1F);
190  m_operand = (OperandType)(flags & 0x1F);
191  m_type = (OpCodeType)((flags >> 9) & 7);
192  m_size = ((flags >> 22) & 3);
193  m_s1 = (byte)((int)value >> 8);
194  m_s2 = (byte)value;
195  m_ctrl = (FlowControl)((flags >> 5) & 0xF);
196  m_endsUncondJmpBlk = ((flags & 0x1000000) != 0);
197  m_stackChange = flags >> 28;
198  }
199 
200  internal bool EndsUncondJmpBlk()
201  {
202  return m_endsUncondJmpBlk;
203  }
204 
205  internal int StackChange()
206  {
207  return m_stackChange;
208  }
209 
214  [__DynamicallyInvokable]
215  public override bool Equals(object obj)
216  {
217  if (obj is OpCode)
218  {
219  return Equals((OpCode)obj);
220  }
221  return false;
222  }
223 
228  [__DynamicallyInvokable]
229  public bool Equals(OpCode obj)
230  {
231  return obj.Value == Value;
232  }
233 
239  [__DynamicallyInvokable]
240  public static bool operator ==(OpCode a, OpCode b)
241  {
242  return a.Equals(b);
243  }
244 
250  [__DynamicallyInvokable]
251  public static bool operator !=(OpCode a, OpCode b)
252  {
253  return !(a == b);
254  }
255 
258  [__DynamicallyInvokable]
259  public override int GetHashCode()
260  {
261  return Value;
262  }
263 
266  [__DynamicallyInvokable]
267  public override string ToString()
268  {
269  return Name;
270  }
271  }
272 }
static string GetName(Type enumType, object value)
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition: Enum.cs:482
OperandType OperandType
The operand type of an intermediate language (IL) instruction.
Definition: OpCode.cs:63
FlowControl FlowControl
The flow control characteristics of the intermediate language (IL) instruction.
Definition: OpCode.cs:75
override int GetHashCode()
Returns the generated hash code for this Opcode.
Definition: OpCode.cs:259
static void Write(ref bool location, bool value)
Writes the specified value to the specified field. On systems that require it, inserts a memory barri...
Definition: Volatile.cs:186
string Name
The name of the intermediate language (IL) instruction.
Definition: OpCode.cs:151
OperandType
Describes the operand type of Microsoft intermediate language (MSIL) instruction.
Definition: OperandType.cs:9
Definition: __Canon.cs:3
StackBehaviour StackBehaviourPush
How the intermediate language (IL) instruction pushes operand onto the stack.
Definition: OpCode.cs:111
override bool Equals(object obj)
Tests whether the given object is equal to this Opcode.
Definition: OpCode.cs:215
static bool operator==(OpCode a, OpCode b)
Indicates whether two T:System.Reflection.Emit.OpCode structures are equal.
Definition: OpCode.cs:240
short Value
Gets the numeric value of the intermediate language (IL) instruction.
Definition: OpCode.cs:135
bool Equals(OpCode obj)
Indicates whether the current instance is equal to the specified T:System.Reflection....
Definition: OpCode.cs:229
Provides the base class for enumerations.
Definition: Enum.cs:14
int Size
The size of the intermediate language (IL) instruction.
Definition: OpCode.cs:123
FlowControl
Describes how an instruction alters the flow of control.
Definition: FlowControl.cs:9
Contains methods for performing volatile memory operations.
Definition: Volatile.cs:8
OpCodeType
Describes the types of the Microsoft intermediate language (MSIL) instructions.
Definition: OpCodeType.cs:9
static bool Read(ref bool location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
Definition: Volatile.cs:15
override string ToString()
Returns this Opcode as a T:System.String.
Definition: OpCode.cs:267
StackBehaviour StackBehaviourPop
How the intermediate language (IL) instruction pops the stack.
Definition: OpCode.cs:99
Describes an intermediate language (IL) instruction.
Definition: OpCode.cs:9
StackBehaviour
Describes how values are pushed onto a stack or popped off a stack.
static bool operator !=(OpCode a, OpCode b)
Indicates whether two T:System.Reflection.Emit.OpCode structures are not equal.
Definition: OpCode.cs:251
OpCodeType OpCodeType
The type of intermediate language (IL) instruction.
Definition: OpCode.cs:87