2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / Mono.Cecil / Mono.Cecil.Cil / Instruction.cs
blob7e9a5defddfc5dad0b5666b77aa581bdd4ea170f
1 //
2 // Instruction.cs
3 //
4 // Author:
5 // Jb Evain (jbevain@gmail.com)
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:
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 sealed class Instruction : ICodeVisitable {
33 int m_offset;
34 OpCode m_opCode;
35 object m_operand;
37 Instruction m_previous;
38 Instruction m_next;
40 SequencePoint m_sequencePoint;
42 public int Offset {
43 get { return m_offset; }
44 set { m_offset = value; }
47 public OpCode OpCode {
48 get { return m_opCode; }
49 set { m_opCode = value; }
52 public object Operand {
53 get { return m_operand; }
54 set { m_operand = value; }
57 public Instruction Previous {
58 get { return m_previous; }
59 set { m_previous = value; }
62 public Instruction Next {
63 get { return m_next; }
64 set { m_next = value; }
67 public SequencePoint SequencePoint {
68 get { return m_sequencePoint; }
69 set { m_sequencePoint = value; }
72 internal Instruction (int offset, OpCode opCode, object operand) : this (offset, opCode)
74 m_operand = operand;
77 internal Instruction (int offset, OpCode opCode)
79 m_offset = offset;
80 m_opCode = opCode;
83 internal Instruction (OpCode opCode, object operand) : this (0, opCode, operand)
87 internal Instruction (OpCode opCode) : this (0, opCode)
91 public int GetSize ()
93 int size = m_opCode.Size;
95 switch (m_opCode.OperandType) {
96 case OperandType.InlineSwitch:
97 size += (1 + ((Instruction []) m_operand).Length) * 4;
98 break;
99 case OperandType.InlineI8:
100 case OperandType.InlineR:
101 size += 8;
102 break;
103 case OperandType.InlineBrTarget:
104 case OperandType.InlineField:
105 case OperandType.InlineI:
106 case OperandType.InlineMethod:
107 case OperandType.InlineString:
108 case OperandType.InlineTok:
109 case OperandType.InlineType:
110 case OperandType.ShortInlineR:
111 size += 4;
112 break;
113 case OperandType.InlineParam:
114 case OperandType.InlineVar:
115 size += 2;
116 break;
117 case OperandType.ShortInlineBrTarget:
118 case OperandType.ShortInlineI:
119 case OperandType.ShortInlineParam:
120 case OperandType.ShortInlineVar:
121 size += 1;
122 break;
125 return size;
128 public void Accept (ICodeVisitor visitor)
130 visitor.VisitInstruction (this);