Add opcodes XML file
[mono.git] / mono / metadata / metadata.h
1
2 typedef struct {
3         guint32  sh_offset;
4         guint32  sh_size;
5 } stream_header_t;
6
7 typedef enum {
8         META_TABLE_MODULE,
9         META_TABLE_TYPEREF,
10         META_TABLE_TYPEDEF,
11         META_TABLE_UNUSED1,
12         META_TABLE_FIELD,
13         META_TABLE_UNUSED2,
14         META_TABLE_METHOD,
15         META_TABLE_UNUSED3,
16         META_TABLE_PARAM,
17         META_TABLE_INTERFACEIMPL,
18         META_TABLE_MEMBERREF,
19         META_TABLE_CONSTANT,
20         META_TABLE_CUSTOMATTRIBUTE,
21         META_TABLE_FIELDMARSHAL,
22         META_TABLE_DECLSECURITY,
23         META_TABLE_CLASSLAYOUT,
24         META_TABLE_FIELDLAYOUT,
25         META_TABLE_STANDALONESIG,
26         META_TABLE_EVENTMAP,
27         META_TABLE_UNUSED4,
28         META_TABLE_EVENT,
29         META_TABLE_PROPERTYMAP,
30         META_TABLE_UNUSED5,
31         META_TABLE_PROPERTY,
32         META_TABLE_METHODSEMANTICS,
33         META_TABLE_METHODIMPL,
34         META_TABLE_MODULEREF,
35         META_TABLE_TYPESPEC,
36         META_TABLE_IMPLMAP,
37         META_TABLE_FIELDRVA,
38         META_TABLE_UNUSED6,
39         META_TABLE_UNUSED7,
40         META_TABLE_ASSEMBLY,
41         META_TABLE_ASSEMBLYPROCESSOR,
42         META_TABLE_ASSEMBLYOS,
43         META_TABLE_ASSEMBLYREF,
44         META_TABLE_ASSEMBLYREFPROCESSOR,
45         META_TABLE_ASSEMBLYREFOS,
46         META_TABLE_FILE,
47         META_TABLE_EXPORTEDTYPE,
48         META_TABLE_MANIFESTRESOURCE,
49         META_TABLE_NESTEDCLASS,
50
51 #define META_TABLE_LAST META_TABLE_NESTEDCLASS
52 } MetaTableEnum;
53
54 typedef struct {
55         guint32   rows, row_size;
56         char     *base;
57
58         /*
59          * Tables contain up to 9 rows and the possible sizes of the
60          * fields in the documentation are 1, 2 and 4 bytes.  So we
61          * can encode in 2 bits the size.
62          *
63          * A 32 bit value can encode the resulting size
64          *
65          * The top eight bits encode the number of columns in the table.
66          * we only need 4, but 8 is aligned no shift required. 
67          */
68         guint32   size_bitfield;
69 } metadata_tableinfo_t;
70
71 /*
72  * This macro is used to extract the size of the table encoded in
73  * the size_bitfield of metadata_tableinfo_t.
74  */
75 #define meta_table_size(bitfield,table) ((((bitfield) >> ((table)*2)) & 0x3) + 1)
76 #define meta_table_count(bitfield) ((bitfield) >> 24)
77
78 typedef struct {
79         char                *raw_metadata;
80                             
81         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
82                             
83         stream_header_t      heap_strings;
84         stream_header_t      heap_us;
85         stream_header_t      heap_blob;
86         stream_header_t      heap_guid;
87         stream_header_t      heap_tables;
88                             
89         char                *tables_base;
90
91         metadata_tableinfo_t tables [64];
92 } metadata_t;
93
94 /*
95  * This enumeration is used to describe the data types in the metadata
96  * tables
97  */
98 enum {
99         MONO_MT_END,
100
101         /* Sized elements */
102         MONO_MT_UINT32,
103         MONO_MT_UINT16,
104         MONO_MT_UINT8,
105
106         /* Index into Blob heap */
107         MONO_MT_BLOB_IDX,
108
109         /* Index into String heap */
110         MONO_MT_STRING_IDX,
111
112         /* GUID index */
113         MONO_MT_GUID_IDX,
114
115         /* Pointer into a table */
116         MONO_MT_TABLE_IDX,
117
118         /* HasConstant:Parent pointer (Param, Field or Property) */
119         MONO_MT_CONST_IDX,
120
121         /* HasCustomAttribute index.  Indexes any table except CustomAttribute */
122         MONO_MT_HASCAT_IDX,
123         
124         /* CustomAttributeType encoded index */
125         MONO_MT_CAT_IDX,
126
127         /* HasDeclSecurity index: TypeDef Method or Assembly */
128         MONO_MT_HASDEC_IDX,
129
130         /* Implementation coded index: File, Export AssemblyRef */
131         MONO_MT_IMPL_IDX,
132
133         /* HasFieldMarshal coded index: Field or Param table */
134         MONO_MT_HFM_IDX,
135
136         /* MemberForwardedIndex: Field or Method */
137         MONO_MT_MF_IDX,
138
139         /* TypeDefOrRef coded index: typedef, typeref, typespec */
140         MONO_MT_TDOR_IDX,
141
142         /* MemberRefParent coded index: typeref, moduleref, method, memberref, typesepc, typedef */
143         MONO_MT_MRP_IDX,
144
145         /* MethodDefOrRef coded index: Method or Member Ref table */
146         MONO_MT_MDOR_IDX,
147
148         /* HasSemantic coded index: Event or Property */
149         MONO_MT_HS_IDX,
150
151         /* ResolutionScope coded index: Module, ModuleRef, AssemblytRef, TypeRef */
152         MONO_MT_RS_IDX
153 };
154
155 typedef struct {
156         int   code;
157         char *def;
158 } MonoMetaTable;
159
160 const char *mono_meta_table_name (int table);
161
162 /* Internal functions */
163 void           mono_metadata_compute_table_bases (metadata_t *meta);
164
165 MonoMetaTable *mono_metadata_get_table    (MetaTableEnum table);
166
167 /*
168  *
169  */
170 char          *mono_metadata_locate       (metadata_t *meta, int table, int idx);
171 char          *mono_metadata_locate_token (metadata_t *meta, guint32 token);
172
173 const char    *mono_metadata_string_heap  (metadata_t *meta, guint32 index);
174 const char    *mono_metadata_blob_heap    (metadata_t *meta, guint32 index);
175
176 typedef enum {
177         MONO_META_EXCEPTION_CLAUSE_NONE,
178         MONO_META_EXCEPTION_CLAUSE_FILTER,
179         MONO_META_EXCEPTION_CLAUSE_FINALLY,
180         MONO_META_EXCEPTION_CLAUSE_FAULT
181 } MonoMetaExceptionEnum;
182
183
184 typedef struct {
185         MonoMetaExceptionEnum kind;
186         int n_clauses;
187         void **clauses;
188 } MonoMetaExceptionHandler;
189
190 typedef struct {
191         guint32     code_size;
192         const char *code;
193         short       max_stack;
194         guint32     local_var_sig_tok;
195
196         /* if local_var_sig_tok != 0, then the following apply: */
197         unsigned int init_locals : 1;
198
199         GList      *exception_handler_list;
200 } MonoMetaMethodHeader;
201
202 MonoMetaMethodHeader *mono_metadata_parse_mh (const char *ptr);
203 void                  mono_metadata_free_mh  (MonoMetaMethodHeader *mh);