2 * util.c: Assorted utilities for the disassembler
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc (http://www.ximian.com)
15 #include "mono/utils/mono-compiler.h"
23 * @code: code to lookup in table
24 * @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";
42 * @table: table to decode bitfield
44 * Warning: returns static buffer.
47 flags (guint32 code
, dis_map_t
*table
)
49 static char buffer
[1024];
54 for (i
= 0; code
&& table
[i
].str
!= NULL
; i
++)
55 if (table
[i
].code
& code
) {
56 code
&= ~table
[i
].code
;
57 strcat (buffer
, table
[i
].str
);
61 sprintf (buffer
+ strlen (buffer
), "unknown-flag-%2x ", code
);
68 * @buffer: pointer to buffer to dump
69 * @base: numbering base to use
70 * @count: number of bytes to dump
73 hex_dump (const char *buffer
, int base
, int count
)
83 for (i
= 0; i
< count
; i
++){
86 printf ("\n0x%08X: ", (unsigned char) base
+ i
);
88 printf ("%02X ", (unsigned char) (buffer
[i
]));
94 data_dump (const char *data
, int len
, const char* prefix
) {
98 return g_strdup (" ()\n");
99 str
= g_string_new (" (");
100 for (i
= 0; i
+ 15 < len
; i
+= 16) {
102 g_string_append_printf (str
, "\n");
103 g_string_append_printf (str
, "%s", prefix
);
104 for (j
= 0; j
< 16; ++j
)
105 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
+ j
]));
106 g_string_append_printf (str
, i
== len
- 16? ") // ": " // ");
107 for (j
= 0; j
< 16; ++j
)
108 g_string_append_printf (str
, "%c", data
[i
+ j
] >= 32 && data
[i
+ j
] <= 126? data
[i
+ j
]: '.');
109 g_string_append_printf (str
, "\n");
112 return g_string_free (str
, FALSE
);
114 g_string_append_printf (str
, "%s", prefix
);
117 g_string_append_printf (str
, "%02X ", (unsigned char) (data
[i
]));
120 int count
= 16 - (len
% 16);
121 for (i
= 0; i
< count
; ++i
)
122 g_string_append_printf (str
, " ");
124 g_string_append_printf (str
, ") // ");
125 for (i
= j
; i
< len
; ++i
)
126 g_string_append_printf (str
, "%c", data
[i
] >= 32 && data
[i
] <= 126? data
[i
]: '.');
127 g_string_append_printf (str
, "\n");
128 return g_string_free (str
, FALSE
);
132 dis_isinf (double num
)
136 #elif defined(HAVE_IEEEFP_H)
139 klass
= fpclass (num
);
140 if (klass
== FP_NINF
)
143 if (klass
== FP_PINF
)
147 #elif defined(HAVE__FINITE)
148 return _finite (num
) ? 0 : 1;
150 #error "Don't know how to implement isinf for this platform."
155 dis_isnan (double num
)
157 #ifdef __MINGW32_VERSION