In Test/System.Windows.Forms:
[mono-project.git] / mcs / class / corlib / System.Reflection.Emit / OpCode.cs
bloba496505d04faf5cc79b775ab7c9d8a084928f37d
1 //
2 // System.Reflection.Emit.OpCode
3 //
4 // Author:
5 // Duncan Mak (duncan@ximian.com)
6 //
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:
14 //
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 //
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)
29 using System;
30 using System.Reflection;
31 using System.Reflection.Emit;
32 using System.Runtime.InteropServices;
34 namespace System.Reflection.Emit {
36 #if NET_2_0
37 [ComVisible (true)]
38 #endif
39 public struct OpCode {
41 internal byte op1, op2;
42 byte push, pop, size, type, args, flow;
45 // The order is:
46 // Op1, Op2, StackBehaviourPush, StackBehaviourPop
47 // Size, OpCodeType, OperandType, FlowControl
49 internal OpCode (int p, int q)
52 op1 = (byte) ((p >> 0) & 0xFF);
53 op2 = (byte) ((p >> 8) & 0xFF);
54 push = (byte) ((p >> 16) & 0xFF);
55 pop = (byte) ((p >> 24) & 0xFF);
57 size = (byte) ((q >> 0) & 0xFF);
58 type = (byte) ((q >> 8) & 0xFF);
59 args = (byte) ((q >> 16) & 0xFF);
60 flow = (byte) ((q >> 24) & 0xFF);
64 public override int GetHashCode ()
66 return Value;
69 public override bool Equals (Object obj)
71 if (obj == null || !(obj is OpCode))
72 return false;
74 OpCode v = (OpCode) obj;
76 return v.op1 == op1 && v.op2 == op2;
79 #if NET_2_0
80 public bool Equals (OpCode obj)
82 return obj.op1 == op1 && obj.op2 == op2;
84 #endif
86 public override string ToString ()
88 return Name;
91 public string Name {
92 get {
93 if (op1 == 0xFF)
94 return OpCodeNames.names [op2];
96 return OpCodeNames.names [256 + op2];
100 public int Size {
101 get {
102 return (int) size;
106 public OpCodeType OpCodeType {
107 get {
108 return (OpCodeType) type;
112 public OperandType OperandType {
113 get {
114 return (OperandType) args;
118 public FlowControl FlowControl {
119 get {
120 return (FlowControl) flow;
124 public StackBehaviour StackBehaviourPop {
125 get {
126 return (StackBehaviour) pop;
130 public StackBehaviour StackBehaviourPush {
131 get {
132 return (StackBehaviour) push;
136 public short Value {
137 get {
138 if (size == 1) {
139 return op2;
140 } else {
141 // two byte instruction - combine
142 // Some old MS betas returned (op1 << 2) | op2 here...
143 return (short) ((op1 << 8) | op2);