5 // Jb Evain (jbevain@gmail.com)
7 // Copyright (c) 2008 - 2010 Jb Evain
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 namespace Mono.Cecil.Cil {
31 public enum FlowControl {
43 public enum OpCodeType {
52 public enum OperandType {
75 public enum StackBehaviour {
107 public struct OpCode {
112 readonly byte flow_control;
113 readonly byte opcode_type;
114 readonly byte operand_type;
115 readonly byte stack_behavior_pop;
116 readonly byte stack_behavior_push;
119 get { return OpCodeNames.names [op1 == 0xff ? op2 : op2 + 256]; }
123 get { return op1 == 0xff ? 1 : 2; }
135 get { return (short) ((op1 << 8) | op2); }
139 get { return (Code) code; }
142 public FlowControl FlowControl {
143 get { return (FlowControl) flow_control; }
146 public OpCodeType OpCodeType {
147 get { return (OpCodeType) opcode_type; }
150 public OperandType OperandType {
151 get { return (OperandType) operand_type; }
154 public StackBehaviour StackBehaviourPop {
155 get { return (StackBehaviour) stack_behavior_pop; }
158 public StackBehaviour StackBehaviourPush {
159 get { return (StackBehaviour) stack_behavior_push; }
162 internal OpCode (int x, int y)
164 this.op1 = (byte) ((x >> 0) & 0xff);
165 this.op2 = (byte) ((x >> 8) & 0xff);
166 this.code = (byte) ((x >> 16) & 0xff);
167 this.flow_control = (byte) ((x >> 24) & 0xff);
169 this.opcode_type = (byte) ((y >> 0) & 0xff);
170 this.operand_type = (byte) ((y >> 8) & 0xff);
171 this.stack_behavior_pop = (byte) ((y >> 16) & 0xff);
172 this.stack_behavior_push = (byte) ((y >> 24) & 0xff);
175 OpCodes.OneByteOpCode [op2] = this;
177 OpCodes.TwoBytesOpCode [op2] = this;
180 public override int GetHashCode ()
185 public override bool Equals (object obj)
187 if (!(obj is OpCode))
190 var opcode = (OpCode) obj;
191 return op1 == opcode.op1 && op2 == opcode.op2;
194 public bool Equals (OpCode opcode)
196 return op1 == opcode.op1 && op2 == opcode.op2;
199 public static bool operator == (OpCode one, OpCode other)
201 return one.op1 == other.op1 && one.op2 == other.op2;
204 public static bool operator != (OpCode one, OpCode other)
206 return one.op1 != other.op1 || one.op2 != other.op2;
209 public override string ToString ()
215 static class OpCodeNames {
217 internal static readonly string [] names = {
499 "no.", // added by spouliot to match Cecil existing definitions
504 "readonly.", // added by spouliot to match Cecil existing definitions