32 * dis-cil.c: Disassembles CIL byte codes
35 * Miguel de Icaza (miguel@ximian.com)
37 * (C) 2001 Ximian, Inc.
96 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
97 { b, c, d, e, g, h, i },
104 unsigned char o1
, o2
;
107 static opcode_t opcodes
[300] = {
108 #include "mono/cil/opcode.def"
112 disassemble_cil (MonoMetadata
*m
, const unsigned char *start
, int size
)
114 const unsigned char *end
= start
+ size
;
115 const unsigned char *ptr
= start
;
121 entry
= &opcodes
[*ptr
+ 256];
123 entry
= &opcodes
[*ptr
];
127 fprintf (output
, "\tIL_%04x: %s ", ptr
- start
, entry
->name
);
128 switch (entry
->argument
){
129 case InlineBrTarget
: {
130 gint target
= *(gint32
*) ptr
;
131 fprintf (output
, "IL_%04x", ptr
+ 4 + target
);
137 token
= *(guint32
*) ptr
;
138 fprintf (output
, "fieldref-0x%08x", token
);
144 int value
= *(int *) ptr
;
146 fprintf (output
, "%d", value
);
152 gint64 top
= *(guint64
*) value
;
154 fprintf (output
, "%ld", top
);
160 token
= *(guint32
*) ptr
;
161 fprintf (output
, "method-0x%08x", token
);
170 double r
= *(double *) ptr
;
171 fprintf (output
, "%g", r
);
177 guint32 token
= *(guint32
*) ptr
;
178 fprintf (output
, "signature-0x%08x", token
);
184 guint32 token
= *(guint32
*) ptr
;
186 fprintf (output
, "string-%0x08x", token
);
192 guint32 count
= *(guint32
*) ptr
;
196 fprintf (output
, "(\n\t\t\t");
197 for (i
= 0; i
< count
; i
++){
198 fprintf (output
, "IL_%x", *(guint32
*) ptr
);
201 fprintf (output
, "\t\t\t)");
206 guint32 token
= *(guint32
*) ptr
;
208 fprintf (output
, "TOKEN_%08x", token
);
214 guint32 token
= *(guint32
*) ptr
;
216 fprintf (output
, "Type-%08x", token
);
222 gint16 var_idx
= *(gint16
*) ptr
;
224 fprintf (output
, "variable-%d\n", var_idx
);
229 case ShortInlineBrTarget
: {
230 signed char x
= *ptr
;
232 fprintf (output
, "IL_%04x", ptr
- start
+ 1 + x
);
240 fprintf (output
, "0x%02x", x
);
246 float f
= *(float *) ptr
;
248 fprintf (output
, "%g", (double) f
);
253 case ShortInlineVar
: {
254 signed char x
= *ptr
;
256 fprintf (output
, "Varidx-%d", (int) x
);
263 fprintf (output
, "\n");