Added Mono.Tasklets test
[mono.git] / mcs / class / corlib / System.Reflection.Emit / OpCode.cs
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.
25 //
26 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
27 //
28
29 #if !FULL_AOT_RUNTIME || IOS_REFLECTION
30
31 using System.Runtime.InteropServices;
32
33 namespace System.Reflection.Emit {
34
35         [ComVisible (true)]
36         public struct OpCode {
37
38                 internal byte op1, op2;
39                 byte push, pop, size, type, args, flow;
40
41                 //
42                 // The order is:
43                 //       Op1, Op2, StackBehaviourPush, StackBehaviourPop
44                 //       Size, OpCodeType, OperandType, FlowControl
45                 //
46                 internal OpCode (int p, int q)
47                 {
48
49                         op1  = (byte) ((p >> 0)  & 0xFF);
50                         op2  = (byte) ((p >> 8)  & 0xFF);
51                         push = (byte) ((p >> 16) & 0xFF);
52                         pop  = (byte) ((p >> 24) & 0xFF);
53
54                         size = (byte) ((q >> 0)  & 0xFF);
55                         type = (byte) ((q >> 8)  & 0xFF);
56                         args = (byte) ((q >> 16) & 0xFF);
57                         flow = (byte) ((q >> 24) & 0xFF);
58                 }
59
60
61                 public override int GetHashCode ()
62                 {
63                         return Name.GetHashCode ();
64                 }
65
66                 public override bool Equals (Object obj)
67                 {
68                         if (obj == null || !(obj is OpCode))
69                                 return false;
70
71                         OpCode v = (OpCode) obj;
72
73                         return v.op1 == op1 && v.op2 == op2;
74                 }
75
76                 public bool Equals (OpCode obj)
77                 {
78                         return obj.op1 == op1 && obj.op2 == op2;
79                 }
80
81                 public override string ToString ()
82                 {
83                         return Name;
84                 }
85
86                 public string Name {
87                         get {
88                                 if (op1 == 0xFF)
89                                         return OpCodeNames.names [op2];
90
91                                 return OpCodeNames.names [256 + op2];
92                         }
93                 }
94
95                 public int Size {
96                         get {
97                                 return (int) size;
98                         }
99                 }
100
101                 public OpCodeType OpCodeType {
102                         get {
103                                 return (OpCodeType) type;
104                         }
105                 }
106
107                 public OperandType OperandType {
108                         get {
109                                 return (OperandType) args;
110                         }
111                 }
112
113                 public FlowControl FlowControl {
114                         get {
115                                 return (FlowControl) flow;
116                         }
117                 }
118
119                 public StackBehaviour StackBehaviourPop {
120                         get {
121                                 return (StackBehaviour) pop;
122                         }
123                 }
124
125                 public StackBehaviour StackBehaviourPush {
126                         get {
127                                 return (StackBehaviour) push;
128                         }
129                 }
130
131                 public short Value {
132                         get {
133                                 if (size == 1) {
134                                         return op2;
135                                 } else {
136                                         // two byte instruction - combine
137                                         // Some old MS betas returned (op1 << 2) | op2 here...
138                                         return (short) ((op1 << 8) | op2);
139                                 }
140                         }
141                 }
142
143                 public static bool operator == (OpCode a, OpCode b)
144                 {
145                         return a.op1 == b.op1 && a.op2 == b.op2;
146                 }
147
148                 public static bool operator != (OpCode a, OpCode b)
149                 {
150                         return a.op1 != b.op1 || a.op2 != b.op2;
151                 }
152         }
153
154 #endif