summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/Opcode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/Opcode.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/Opcode.cs271
1 files changed, 138 insertions, 133 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/Opcode.cs b/src/mscorlib/src/System/Reflection/Emit/Opcode.cs
index 74a9de16b6..37768be9d7 100644
--- a/src/mscorlib/src/System/Reflection/Emit/Opcode.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/Opcode.cs
@@ -2,191 +2,196 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-namespace System.Reflection.Emit {
using System;
using System.Threading;
using System.Diagnostics.Contracts;
-public struct OpCode
+namespace System.Reflection.Emit
{
- //
- // Use packed bitfield for flags to avoid code bloat
- //
-
- internal const int OperandTypeMask = 0x1F; // 000000000000000000000000000XXXXX
-
- internal const int FlowControlShift = 5; // 00000000000000000000000XXXX00000
- internal const int FlowControlMask = 0x0F;
+ public struct OpCode
+ {
+ //
+ // Use packed bitfield for flags to avoid code bloat
+ //
- internal const int OpCodeTypeShift = 9; // 00000000000000000000XXX000000000
- internal const int OpCodeTypeMask = 0x07;
+ internal const int OperandTypeMask = 0x1F; // 000000000000000000000000000XXXXX
- internal const int StackBehaviourPopShift = 12; // 000000000000000XXXXX000000000000
- internal const int StackBehaviourPushShift = 17; // 0000000000XXXXX00000000000000000
- internal const int StackBehaviourMask = 0x1F;
+ internal const int FlowControlShift = 5; // 00000000000000000000000XXXX00000
+ internal const int FlowControlMask = 0x0F;
- internal const int SizeShift = 22; // 00000000XX0000000000000000000000
- internal const int SizeMask = 0x03;
+ internal const int OpCodeTypeShift = 9; // 00000000000000000000XXX000000000
+ internal const int OpCodeTypeMask = 0x07;
- internal const int EndsUncondJmpBlkFlag = 0x01000000; // 0000000X000000000000000000000000
+ internal const int StackBehaviourPopShift = 12; // 000000000000000XXXXX000000000000
+ internal const int StackBehaviourPushShift = 17; // 0000000000XXXXX00000000000000000
+ internal const int StackBehaviourMask = 0x1F;
- // unused // 0000XXX0000000000000000000000000
+ internal const int SizeShift = 22; // 00000000XX0000000000000000000000
+ internal const int SizeMask = 0x03;
- internal const int StackChangeShift = 28; // XXXX0000000000000000000000000000
+ internal const int EndsUncondJmpBlkFlag = 0x01000000; // 0000000X000000000000000000000000
- private OpCodeValues m_value;
- private int m_flags;
+ // unused // 0000XXX0000000000000000000000000
- internal OpCode(OpCodeValues value, int flags)
- {
- m_value = value;
- m_flags = flags;
- }
+ internal const int StackChangeShift = 28; // XXXX0000000000000000000000000000
- internal bool EndsUncondJmpBlk()
- {
- return (m_flags & EndsUncondJmpBlkFlag) != 0;
- }
-
- internal int StackChange()
- {
- return (m_flags >> StackChangeShift);
- }
+ private OpCodeValues m_value;
+ private int m_flags;
- public OperandType OperandType
- {
- get
+ internal OpCode(OpCodeValues value, int flags)
{
- return (OperandType)(m_flags & OperandTypeMask);
+ m_value = value;
+ m_flags = flags;
}
- }
- public FlowControl FlowControl
- {
- get
+ internal bool EndsUncondJmpBlk()
{
- return (FlowControl)((m_flags >> FlowControlShift) & FlowControlMask);
+ return (m_flags & EndsUncondJmpBlkFlag) != 0;
}
- }
- public OpCodeType OpCodeType
- {
- get
+ internal int StackChange()
{
- return (OpCodeType)((m_flags >> OpCodeTypeShift) & OpCodeTypeMask);
+ return (m_flags >> StackChangeShift);
}
- }
- public StackBehaviour StackBehaviourPop
- {
- get
+ public OperandType OperandType
{
- return (StackBehaviour)((m_flags >> StackBehaviourPopShift) & StackBehaviourMask);
+ get
+ {
+ return (OperandType)(m_flags & OperandTypeMask);
+ }
}
- }
- public StackBehaviour StackBehaviourPush
- {
- get
+ public FlowControl FlowControl
{
- return (StackBehaviour)((m_flags >> StackBehaviourPushShift) & StackBehaviourMask);
+ get
+ {
+ return (FlowControl)((m_flags >> FlowControlShift) & FlowControlMask);
+ }
}
- }
- public int Size
- {
- get
+ public OpCodeType OpCodeType
{
- return (m_flags >> SizeShift) & SizeMask;
+ get
+ {
+ return (OpCodeType)((m_flags >> OpCodeTypeShift) & OpCodeTypeMask);
+ }
}
- }
- public short Value
- {
- get
+ public StackBehaviour StackBehaviourPop
{
- return (short)m_value;
+ get
+ {
+ return (StackBehaviour)((m_flags >> StackBehaviourPopShift) & StackBehaviourMask);
+ }
}
- }
- private static volatile string[] g_nameCache;
+ public StackBehaviour StackBehaviourPush
+ {
+ get
+ {
+ return (StackBehaviour)((m_flags >> StackBehaviourPushShift) & StackBehaviourMask);
+ }
+ }
- public String Name
- {
- get
+ public int Size
{
- if (Size == 0)
- return null;
+ get
+ {
+ return (m_flags >> SizeShift) & SizeMask;
+ }
+ }
- // Create and cache the opcode names lazily. They should be rarely used (only for logging, etc.)
- // Note that we do not any locks here because of we always get the same names. The last one wins.
- string[] nameCache = g_nameCache;
- if (nameCache == null) {
- nameCache = new String[0x11f];
- g_nameCache = nameCache;
+ public short Value
+ {
+ get
+ {
+ return (short)m_value;
}
+ }
- OpCodeValues opCodeValue = (OpCodeValues)(ushort)Value;
+ private static volatile string[] g_nameCache;
- int idx = (int)opCodeValue;
- if (idx > 0xFF) {
- if (idx >= 0xfe00 && idx <= 0xfe1e) {
- // Transform two byte opcode value to lower range that's suitable
- // for array index
- idx = 0x100 + (idx - 0xfe00);
- }
- else {
- // Unknown opcode
+ public String Name
+ {
+ get
+ {
+ if (Size == 0)
return null;
+
+ // Create and cache the opcode names lazily. They should be rarely used (only for logging, etc.)
+ // Note that we do not any locks here because of we always get the same names. The last one wins.
+ string[] nameCache = g_nameCache;
+ if (nameCache == null)
+ {
+ nameCache = new String[0x11f];
+ g_nameCache = nameCache;
}
- }
- String name = Volatile.Read(ref nameCache[idx]);
- if (name != null)
- return name;
+ OpCodeValues opCodeValue = (OpCodeValues)(ushort)Value;
+
+ int idx = (int)opCodeValue;
+ if (idx > 0xFF)
+ {
+ if (idx >= 0xfe00 && idx <= 0xfe1e)
+ {
+ // Transform two byte opcode value to lower range that's suitable
+ // for array index
+ idx = 0x100 + (idx - 0xfe00);
+ }
+ else
+ {
+ // Unknown opcode
+ return null;
+ }
+ }
- // Create ilasm style name from the enum value name.
- name = Enum.GetName(typeof(OpCodeValues), opCodeValue).ToLowerInvariant().Replace("_", ".");
- Volatile.Write(ref nameCache[idx], name);
- return name;
+ String name = Volatile.Read(ref nameCache[idx]);
+ if (name != null)
+ return name;
+
+ // Create ilasm style name from the enum value name.
+ name = Enum.GetName(typeof(OpCodeValues), opCodeValue).ToLowerInvariant().Replace("_", ".");
+ Volatile.Write(ref nameCache[idx], name);
+ return name;
+ }
}
- }
- [Pure]
- public override bool Equals(Object obj)
- {
- if (obj is OpCode)
- return Equals((OpCode)obj);
- else
- return false;
- }
+ [Pure]
+ public override bool Equals(Object obj)
+ {
+ if (obj is OpCode)
+ return Equals((OpCode)obj);
+ else
+ return false;
+ }
- [Pure]
- public bool Equals(OpCode obj)
- {
- return obj.Value == Value;
- }
+ [Pure]
+ public bool Equals(OpCode obj)
+ {
+ return obj.Value == Value;
+ }
- [Pure]
- public static bool operator ==(OpCode a, OpCode b)
- {
- return a.Equals(b);
- }
+ [Pure]
+ public static bool operator ==(OpCode a, OpCode b)
+ {
+ return a.Equals(b);
+ }
- [Pure]
- public static bool operator !=(OpCode a, OpCode b)
- {
- return !(a == b);
- }
+ [Pure]
+ public static bool operator !=(OpCode a, OpCode b)
+ {
+ return !(a == b);
+ }
- public override int GetHashCode()
- {
- return Value;
- }
+ public override int GetHashCode()
+ {
+ return Value;
+ }
- public override String ToString()
- {
- return Name;
+ public override String ToString()
+ {
+ return Name;
+ }
}
}
-}