00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00033
00034
00035
00036 #ifndef _XED_UTIL_H_
00037 # define _XED_UTIL_H_
00038
00039 #include "xed-common-hdrs.h"
00040 #include "xed-types.h"
00041 #include "xed-portability.h"
00042
00043
00045
00047 extern int xed_verbose;
00048 #if defined(XED_MESSAGES)
00049 # include <stdio.h>
00050 extern FILE* xed_log_file;
00051 # define XED_EMIT_MESSAGES (xed_verbose >= 1)
00052 # define XED_INFO_VERBOSE (xed_verbose >= 2)
00053 # define XED_INFO2_VERBOSE (xed_verbose >= 3)
00054 # define XED_VERBOSE (xed_verbose >= 4)
00055 # define XED_MORE_VERBOSE (xed_verbose >= 5)
00056 # define XED_VERY_VERBOSE (xed_verbose >= 6)
00057 #else
00058 # define XED_EMIT_MESSAGES (0)
00059 # define XED_INFO_VERBOSE (0)
00060 # define XED_INFO2_VERBOSE (0)
00061 # define XED_VERBOSE (0)
00062 # define XED_MORE_VERBOSE (0)
00063 # define XED_VERY_VERBOSE (0)
00064 #endif
00065
00066 #if defined(__GNUC__)
00067 # define XED_FUNCNAME __func__
00068 #else
00069 # define XED_FUNCNAME ""
00070 #endif
00071
00072 #if defined(XED_MESSAGES)
00073 #define XED2IMSG(x) \
00074 do { \
00075 if (XED_EMIT_MESSAGES) { \
00076 if (XED_VERY_VERBOSE) { \
00077 fprintf(xed_log_file,"%s:%d:%s: ", \
00078 __FILE__, __LINE__, XED_FUNCNAME); \
00079 } \
00080 fprintf x; \
00081 fflush(xed_log_file); \
00082 } \
00083 } while(0)
00084
00085 #define XED2TMSG(x) \
00086 do { \
00087 if (XED_VERBOSE) { \
00088 if (XED_VERY_VERBOSE) { \
00089 fprintf(xed_log_file,"%s:%d:%s: ", \
00090 __FILE__, __LINE__, XED_FUNCNAME); \
00091 } \
00092 fprintf x; \
00093 fflush(xed_log_file); \
00094 } \
00095 } while(0)
00096
00097 #define XED2VMSG(x) \
00098 do { \
00099 if (XED_VERY_VERBOSE) { \
00100 fprintf(xed_log_file,"%s:%d:%s: ", \
00101 __FILE__, __LINE__, XED_FUNCNAME); \
00102 fprintf x; \
00103 fflush(xed_log_file); \
00104 } \
00105 } while(0)
00106
00107 #define XED2DIE(x) \
00108 do { \
00109 if (XED_EMIT_MESSAGES) { \
00110 fprintf(xed_log_file,"%s:%d:%s: ", \
00111 __FILE__, __LINE__, XED_FUNCNAME); \
00112 fprintf x; \
00113 fflush(xed_log_file); \
00114 } \
00115 xed_assert(0); \
00116 } while(0)
00117
00118
00119
00120 #else
00121 # define XED2IMSG(x)
00122 # define XED2TMSG(x)
00123 # define XED2VMSG(x)
00124 # define XED2DIE(x) do { xed_assert(0); } while(0)
00125 #endif
00126
00127 #if defined(XED_ASSERTS)
00128 # define xed_assert(x) do { if (( x )== 0) xed_internal_assert( #x, __FILE__, __LINE__); } while(0)
00129 #else
00130 # define xed_assert(x) do { } while(0)
00131 #endif
00132 XED_NORETURN XED_NOINLINE XED_DLL_EXPORT void xed_internal_assert(const char* s, const char* file, int line);
00133
00134 typedef void (*xed_user_abort_function_t)(const char* msg,
00135 const char* file,
00136 int line,
00137 void* other);
00138
00158 XED_DLL_EXPORT void xed_register_abort_function(xed_user_abort_function_t fn,
00159 void* other);
00160
00161
00163
00165 char* xed_downcase_buf(char* s);
00166
00167
00168
00169 int xed_strncat_lower(char* dst, const char* src, int len);
00170
00171 XED_DLL_EXPORT int xed_itoa(char* buf,
00172 xed_uint64_t f,
00173 int buflen);
00174
00175 int xed_itoa_hex_zeros(char* buf,
00176 xed_uint64_t f,
00177 xed_uint_t xed_bits_to_print,
00178 xed_bool_t leading_zeros,
00179 int buflen);
00180
00181 XED_DLL_EXPORT int xed_itoa_hex(char* buf,
00182 xed_uint64_t f,
00183 xed_uint_t xed_bits_to_print,
00184 int buflen);
00185
00186 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
00187
00188 char xed_to_ascii_hex_nibble(xed_uint_t x);
00189
00190 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
00191 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
00192 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
00193 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
00194 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
00195 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
00196 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
00197 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
00198 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
00199 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
00200 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
00201 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
00202
00205 XED_DLL_EXPORT void xed_set_log_file(void* o);
00206
00207
00209 XED_DLL_EXPORT void xed_set_verbosity(int v);
00210
00211 void xed_derror(const char* s);
00212 void xed_dwarn(const char* s);
00213
00214 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
00215 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
00216 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
00217
00218 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
00219 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
00220
00221 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
00222
00224 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
00225
00227 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
00228
00229
00230 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
00231 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
00232 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
00233
00234 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
00235 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
00236
00237 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
00238
00239 #if defined(XED_LITTLE_ENDIAN_SWAPPING)
00240 XED_DLL_EXPORT xed_int32_t
00241 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
00242
00243 XED_DLL_EXPORT xed_int64_t
00244 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
00245 XED_DLL_EXPORT xed_uint64_t
00246 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
00247
00248 XED_DLL_EXPORT xed_int64_t
00249 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00250 XED_DLL_EXPORT xed_uint64_t
00251 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00252 #endif
00253
00254 XED_DLL_EXPORT xed_uint8_t
00255 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
00256
00257 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
00258 xed_union64_t y;
00259 y.s.lo32= lo;
00260 y.s.hi32= hi;
00261 return y.u64;
00262 }
00263 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
00264 xed_union64_t y;
00265 y.s.lo32= lo;
00266 y.s.hi32= hi;
00267 return y.i64;
00268 }
00269
00276 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
00277
00283 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
00284
00286
00288
00290 #endif