2 // System.Reflection.Emit.OpCode
5 // Duncan Mak (duncan@ximian.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
31 using System.Reflection;
32 using System.Reflection.Emit;
33 using System.Runtime.InteropServices;
35 namespace System.Reflection.Emit {
38 public struct OpCode {
40 internal byte op1, op2;
41 byte push, pop, size, type, args, flow;
45 // Op1, Op2, StackBehaviourPush, StackBehaviourPop
46 // Size, OpCodeType, OperandType, FlowControl
48 internal OpCode (int p, int q)
51 op1 = (byte) ((p >> 0) & 0xFF);
52 op2 = (byte) ((p >> 8) & 0xFF);
53 push = (byte) ((p >> 16) & 0xFF);
54 pop = (byte) ((p >> 24) & 0xFF);
56 size = (byte) ((q >> 0) & 0xFF);
57 type = (byte) ((q >> 8) & 0xFF);
58 args = (byte) ((q >> 16) & 0xFF);
59 flow = (byte) ((q >> 24) & 0xFF);
63 public override int GetHashCode ()
65 return Name.GetHashCode ();
68 public override bool Equals (Object obj)
70 if (obj == null || !(obj is OpCode))
73 OpCode v = (OpCode) obj;
75 return v.op1 == op1 && v.op2 == op2;
78 public bool Equals (OpCode obj)
80 return obj.op1 == op1 && obj.op2 == op2;
83 public override string ToString ()
91 return OpCodeNames.names [op2];
93 return OpCodeNames.names [256 + op2];
103 public OpCodeType OpCodeType {
105 return (OpCodeType) type;
109 public OperandType OperandType {
111 return (OperandType) args;
115 public FlowControl FlowControl {
117 return (FlowControl) flow;
121 public StackBehaviour StackBehaviourPop {
123 return (StackBehaviour) pop;
127 public StackBehaviour StackBehaviourPush {
129 return (StackBehaviour) push;
138 // two byte instruction - combine
139 // Some old MS betas returned (op1 << 2) | op2 here...
140 return (short) ((op1 << 8) | op2);
145 public static bool operator == (OpCode a, OpCode b)
147 return a.op1 == b.op1 && a.op2 == b.op2;
150 public static bool operator != (OpCode a, OpCode b)
152 return a.op1 != b.op1 || a.op2 != b.op2;