2 * dis-cil.c: Disassembles CIL byte codes
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
38 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
46 * we are not really using any of the following:
52 static opcode_t opcodes [300] = {
53 #include "mono/cil/opcode.def"
57 * Strings on the US heap are encoded using UTF-16. Poor man's
58 * UTF-16 to UTF-8. I know its broken, use libunicode later.
61 get_encoded_user_string (const char *ptr)
66 ptr = get_blob_encoded_size (ptr, &len);
67 res = g_malloc (len + 1);
70 * I should really use some kind of libunicode here
72 for (i = 0, j = 0; i < len; j++, i += 2)
81 dissasemble_cil (metadata_t *m, const unsigned char *start, int size)
83 const unsigned char *end = start + size;
84 const unsigned char *ptr = start;
90 entry = &opcodes [*ptr + 256];
92 entry = &opcodes [*ptr];
94 fprintf (output, "\tIL_%04x: %s ", (int) (ptr - start), entry->name);
96 switch (entry->argument){
97 case InlineBrTarget: {
98 gint target = *(gint32 *) ptr;
99 fprintf (output, "IL_%04x", ((int) (ptr - start)) + 4 + target);
105 guint32 token = *(guint32 *) ptr;
106 fprintf (output, "fieldref-0x%08x", token);
112 int value = *(int *) ptr;
114 fprintf (output, "%d", value);
120 gint64 top = *(guint64 *) ptr;
122 fprintf (output, "%lld", (long long) top);
128 guint32 token = *(guint32 *) ptr;
129 fprintf (output, "method-0x%08x", token);
138 double r = *(double *) ptr;
139 fprintf (output, "%g", r);
145 guint32 token = *(guint32 *) ptr;
146 fprintf (output, "signature-0x%08x", token);
152 guint32 token = *(guint32 *) ptr;
154 char *s = get_encoded_user_string (
155 mono_metadata_user_string (m, token & 0xffffff));
158 * See section 23.1.4 on the encoding of the #US heap
160 fprintf (output, "\"%s\"", s);
167 guint32 count = *(guint32 *) ptr;
171 fprintf (output, "(\n\t\t\t");
172 for (i = 0; i < count; i++){
173 fprintf (output, "IL_%x", *(guint32 *) ptr);
176 fprintf (output, "\t\t\t)");
181 guint32 token = *(guint32 *) ptr;
183 fprintf (output, "TOKEN_%08x", token);
189 guint32 token = *(guint32 *) ptr;
191 fprintf (output, "Type-%08x", token);
197 gint16 var_idx = *(gint16 *) ptr;
199 fprintf (output, "variable-%d\n", var_idx);
204 case ShortInlineBrTarget: {
205 signed char x = *ptr;
207 fprintf (output, "IL_%04x", ptr - start + 1 + x);
215 fprintf (output, "0x%02x", x);
221 float f = *(float *) ptr;
223 fprintf (output, "%g", (double) f);
228 case ShortInlineVar: {
229 signed char x = *ptr;
231 fprintf (output, "V_%d", (int) x);
238 fprintf (output, "\n");