3 * Assorted utilities for the disassembler
6 * Miguel de Icaza (miguel@ximian.com)
8 * (C) 2001 Ximian, Inc (http://www.ximian.com)
16 #include "mono/utils/mono-compiler.h"
23 * \param code code to lookup in table
24 * \param table table to decode code
26 * Warning: returns static buffer.
29 map (guint32 code
, dis_map_t
*table
)
33 for (i
= 0; table
[i
].str
!= NULL
; i
++)
34 if (table
[i
].code
== code
)
36 return "invalid-flags";
40 * \param code bitfield
41 * \param table table to decode bitfield
43 * Warning: returns static buffer.
46 flags (guint32 code
, dis_map_t
*table
)
48 static char buffer
[1024];
53 for (i
= 0; code
&& table
[i
].str
!= NULL
; i
++)
54 if (table
[i
].code
& code
) {
55 code
&= ~table
[i
].code
;
56 strcat (buffer
, table
[i
].str
);
60 sprintf (buffer
+ strlen (buffer
), "unknown-flag-%2x ", code
);
67 * @buffer: pointer to buffer to dump
68 * @base: numbering base to use
69 * @count: number of bytes to dump
72 hex_dump (const char *buffer
, int base
, int count
)
82 for (i
= 0; i
< count
; i
++){
85 printf ("\n0x%08X: ", (unsigned char) base
+ i
);
87 printf ("%02X ", (unsigned char) (buffer
[i
]));
93 data_dump (const char *data
, int len
, const char* prefix
) {
97 return g_strdup (" ()\n");
98 str
= g_string_new (" (");
99 for (i
= 0; i
+ 15 < len
; i
+= 16) {
101 g_string_append_printf (str
, "\n");
102 g_string_append_printf (str
, "%s", prefix
);
103 for (j
= 0; j
< 16; ++j
)
104 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
+ j
]));
105 g_string_append_printf (str
, i
== len
- 16? ") // ": " // ");
106 for (j
= 0; j
< 16; ++j
)
107 g_string_append_printf (str
, "%c", data
[i
+ j
] >= 32 && data
[i
+ j
] <= 126? data
[i
+ j
]: '.');
108 g_string_append_printf (str
, "\n");
111 return g_string_free (str
, FALSE
);
113 g_string_append_printf (str
, "%s", prefix
);
116 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
]));
119 int count
= 16 - (len
% 16);
120 for (i
= 0; i
< count
; ++i
)
121 g_string_append_printf (str
, " ");
123 g_string_append_printf (str
, ") // ");
124 for (i
= j
; i
< len
; ++i
)
125 g_string_append_printf (str
, "%c", data
[i
] >= 32 && data
[i
] <= 126? data
[i
]: '.');
126 g_string_append_printf (str
, "\n");
127 return g_string_free (str
, FALSE
);
131 dis_isinf (double num
)
135 #elif defined(HAVE_IEEEFP_H)
138 klass
= fpclass (num
);
139 if (klass
== FP_NINF
)
142 if (klass
== FP_PINF
)
146 #elif defined(HAVE__FINITE)
147 return _finite (num
) ? 0 : 1;
149 #error "Don't know how to implement isinf for this platform."
154 dis_isnan (double num
)
156 #ifdef __MINGW32_VERSION