~ubuntu-branches/ubuntu/warty/monodevelop/warty

« back to all changes in this revision

Viewing changes to src/Libraries/SharpAssembly/src/SharpAssembly/Metadata/MethodBody.cs

  • Committer: Bazaar Package Importer
  • Author(s): Brandon Hale
  • Date: 2004-10-07 11:51:11 UTC
  • Revision ID: james.westby@ubuntu.com-20041007115111-pxcqnwfxyq5mhcx5
Tags: 0.5.1-3
Use dh_netdeps in debian/rules and debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Assembly.cs
 
2
// Copyright (C) 2003 Mike Krueger
 
3
// 
 
4
// This library is free software; you can redistribute it and/or
 
5
// modify it under the terms of the GNU Lesser General Public
 
6
// License as published by the Free Software Foundation; either
 
7
// version 2.1 of the License, or (at your option) any later version.
 
8
// 
 
9
// This library is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
// Lesser General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU Lesser General Public
 
15
// License along with this library; if not, write to the Free Software
 
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
using System;
 
19
using System.IO;
 
20
 
 
21
namespace MonoDevelop.SharpAssembly.Metadata.Rows
 
22
{
 
23
        
 
24
        public class MethodBody
 
25
        {
 
26
                public const byte CorILMethod_Fat        = 0x3;
 
27
                public const byte CorILMethod_TinyFormat = 0x2;
 
28
                public const byte CorILMethod_MoreSects  = 0x8;
 
29
                public const byte CorILMethod_InitLocals = 0x10;
 
30
                
 
31
                uint   flags          = 0;
 
32
                uint   headerSize     = 0;
 
33
                ushort maxStack       = 8;
 
34
                uint   codeSize       = 0;
 
35
                uint   localVarSigTok = 0;
 
36
                
 
37
                byte[] methodData;
 
38
                
 
39
                public uint Flags {
 
40
                        get {
 
41
                                return flags;
 
42
                        }
 
43
                        set {
 
44
                                flags = value;
 
45
                        }
 
46
                }
 
47
                public uint HeaderSize {
 
48
                        get {
 
49
                                return headerSize;
 
50
                        }
 
51
                        set {
 
52
                                headerSize = value;
 
53
                        }
 
54
                }
 
55
                public ushort MaxStack {
 
56
                        get {
 
57
                                return maxStack;
 
58
                        }
 
59
                        set {
 
60
                                maxStack = value;
 
61
                        }
 
62
                }
 
63
                public uint CodeSize {
 
64
                        get {
 
65
                                return codeSize;
 
66
                        }
 
67
                        set {
 
68
                                codeSize = value;
 
69
                        }
 
70
                }
 
71
                public uint LocalVarSigTok {
 
72
                        get {
 
73
                                return localVarSigTok;
 
74
                        }
 
75
                        set {
 
76
                                localVarSigTok = value;
 
77
                        }
 
78
                }
 
79
                public byte[] MethodData {
 
80
                        get {
 
81
                                return methodData;
 
82
                        }
 
83
                        set {
 
84
                                methodData = value;
 
85
                        }
 
86
                }
 
87
                
 
88
                
 
89
                public void Load(BinaryReader reader)
 
90
                {
 
91
                        byte flagByte = reader.ReadByte();
 
92
                        Console.Write("flagByte : " + flagByte.ToString("X"));
 
93
                        
 
94
                        switch (flagByte & 0x03) {
 
95
                                case CorILMethod_Fat:
 
96
                                        byte nextByte       = reader.ReadByte();
 
97
                                        Console.WriteLine("  nextByte : " + nextByte.ToString("X"));
 
98
                                
 
99
                                        flags        = (uint)(flagByte & ((nextByte & 0x0F) << 8));
 
100
                                        headerSize   = (uint)(nextByte >> 4);
 
101
                                        maxStack     = reader.ReadUInt16();
 
102
                                        codeSize     = reader.ReadUInt32();
 
103
                                        localVarSigTok = reader.ReadUInt32();
 
104
                                        // TODO : CorILMethod_MoreSects
 
105
                                        break;
 
106
                                case CorILMethod_TinyFormat:
 
107
                                        flags      = (uint)flagByte & 0x03;
 
108
                                        codeSize   = (uint)flagByte >> 2;
 
109
                                        break;
 
110
                                default:
 
111
                                        throw new System.NotSupportedException("not supported method body flag " + flagByte);
 
112
                        }
 
113
                        methodData = new byte[codeSize];
 
114
                        reader.Read(methodData, 0, (int)codeSize);
 
115
                }
 
116
        }
 
117
}