| 1 |
// |
| 2 |
// OpCode.cs |
| 3 |
// |
| 4 |
// Author: |
| 5 |
// Jb Evain ([email protected]) |
| 6 |
// |
| 7 |
// (C) 2005 Jb Evain |
| 8 |
// |
| 9 |
// Permission is hereby granted, free of charge, to any person obtaining |
| 10 |
// a copy of this software and associated documentation files (the |
| 11 |
// "Software"), to deal in the Software without restriction, including |
| 12 |
// without limitation the rights to use, copy, modify, merge, publish, |
| 13 |
// distribute, sublicense, and/or sell copies of the Software, and to |
| 14 |
// permit persons to whom the Software is furnished to do so, subject to |
| 15 |
// the following conditions: |
| 16 |
// |
| 17 |
// The above copyright notice and this permission notice shall be |
| 18 |
// included in all copies or substantial portions of the Software. |
| 19 |
// |
| 20 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 24 |
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 25 |
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 26 |
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 27 |
// |
| 28 |
|
| 29 |
namespace Mono.Cecil.Cil { |
| 30 |
|
| 31 |
internal struct OpCode { |
| 32 |
short m_value; |
| 33 |
byte m_code; |
| 34 |
byte m_flowControl; |
| 35 |
byte m_opCodeType; |
| 36 |
byte m_operandType; |
| 37 |
byte m_stackBehaviourPop; |
| 38 |
byte m_stackBehaviourPush; |
| 39 |
|
| 40 |
public string Name { |
| 41 |
get { |
| 42 |
int index = (Size == 1) ? Op2 : (Op2 + 256); |
| 43 |
return OpCodeNames.names [index]; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public int Size { |
| 48 |
get { return ((m_value & 0xff00) == 0xff00) ? 1 : 2; } |
| 49 |
} |
| 50 |
|
| 51 |
public byte Op1 { |
| 52 |
get { return (byte) (m_value >> 8); } |
| 53 |
} |
| 54 |
|
| 55 |
public byte Op2 { |
| 56 |
get { return (byte) m_value; } |
| 57 |
} |
| 58 |
|
| 59 |
public short Value { |
| 60 |
get { return (Size == 1) ? Op2 : m_value; } |
| 61 |
} |
| 62 |
|
| 63 |
public Code Code { |
| 64 |
get { return (Code) m_code; } |
| 65 |
} |
| 66 |
|
| 67 |
public FlowControl FlowControl { |
| 68 |
get { return (FlowControl) m_flowControl; } |
| 69 |
} |
| 70 |
|
| 71 |
public OpCodeType OpCodeType { |
| 72 |
get { return (OpCodeType) m_opCodeType; } |
| 73 |
} |
| 74 |
|
| 75 |
public OperandType OperandType { |
| 76 |
get { return (OperandType) m_operandType; } |
| 77 |
} |
| 78 |
|
| 79 |
public StackBehaviour StackBehaviourPop { |
| 80 |
get { return (StackBehaviour) m_stackBehaviourPop; } |
| 81 |
} |
| 82 |
|
| 83 |
public StackBehaviour StackBehaviourPush { |
| 84 |
get { return (StackBehaviour) m_stackBehaviourPush; } |
| 85 |
} |
| 86 |
|
| 87 |
internal OpCode (byte op1, byte op2, |
| 88 |
Code code, FlowControl flowControl, |
| 89 |
OpCodeType opCodeType, OperandType operandType, |
| 90 |
StackBehaviour pop, StackBehaviour push) |
| 91 |
{ |
| 92 |
m_value = (short) ((op1 << 8) | op2); |
| 93 |
m_code = (byte) code; |
| 94 |
m_flowControl = (byte) flowControl; |
| 95 |
m_opCodeType = (byte) opCodeType; |
| 96 |
m_operandType = (byte) operandType; |
| 97 |
m_stackBehaviourPop = (byte) pop; |
| 98 |
m_stackBehaviourPush = (byte) push; |
| 99 |
|
| 100 |
if (op1 == 0xff) |
| 101 |
OpCodes.OneByteOpCode [op2] = this; |
| 102 |
else |
| 103 |
OpCodes.TwoBytesOpCode [op2] = this; |
| 104 |
} |
| 105 |
|
| 106 |
public override int GetHashCode () |
| 107 |
{ |
| 108 |
return m_value; |
| 109 |
} |
| 110 |
|
| 111 |
public override bool Equals (object obj) |
| 112 |
{ |
| 113 |
if (!(obj is OpCode)) |
| 114 |
return false; |
| 115 |
OpCode v = (OpCode) obj; |
| 116 |
return v.m_value == m_value; |
| 117 |
} |
| 118 |
|
| 119 |
public bool Equals (OpCode opcode) |
| 120 |
{ |
| 121 |
return (m_value == opcode.m_value); |
| 122 |
} |
| 123 |
|
| 124 |
public static bool operator == (OpCode one, OpCode other) |
| 125 |
{ |
| 126 |
return (one.m_value == other.m_value); |
| 127 |
} |
| 128 |
|
| 129 |
public static bool operator != (OpCode one, OpCode other) |
| 130 |
{ |
| 131 |
return (one.m_value != other.m_value); |
| 132 |
} |
| 133 |
|
| 134 |
public override string ToString () |
| 135 |
{ |
| 136 |
return Name; |
| 137 |
} |
| 138 |
} |
| 139 |
} |