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
00031
00032
00035
00036
00037
00038 #ifndef _XED_UTIL_H_
00039 # define _XED_UTIL_H_
00040
00041 #include "xed-common-hdrs.h"
00042 #include "xed-types.h"
00043 #include "xed-portability.h"
00044
00045
00047
00049 extern int xed_verbose;
00050 #if defined(XED_MESSAGES)
00051 # include <stdio.h>
00052 extern FILE* xed_log_file;
00053 #endif
00054 #define XED_EMIT_MESSAGES (XED_MESSAGES==1 && xed_verbose >= 1)
00055 #define XED_INFO_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 2)
00056 #define XED_INFO2_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 3)
00057 #define XED_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 4)
00058 #define XED_MORE_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 5)
00059 #define XED_VERY_VERBOSE (XED_MESSAGES==1 && xed_verbose >= 6)
00060
00061 #if defined(__GNUC__)
00062 # define XED_FUNCNAME __func__
00063 #else
00064 # define XED_FUNCNAME ""
00065 #endif
00066
00067 #if XED_MESSAGES==1
00068 #define XED2IMSG(x) \
00069 do { \
00070 if (XED_EMIT_MESSAGES) { \
00071 if (XED_VERY_VERBOSE) { \
00072 fprintf(xed_log_file,"%s:%d:%s: ", \
00073 __FILE__, __LINE__, XED_FUNCNAME); \
00074 } \
00075 fprintf x; \
00076 fflush(xed_log_file); \
00077 } \
00078 } while(0)
00079
00080 #define XED2TMSG(x) \
00081 do { \
00082 if (XED_VERBOSE) { \
00083 if (XED_VERY_VERBOSE) { \
00084 fprintf(xed_log_file,"%s:%d:%s: ", \
00085 __FILE__, __LINE__, XED_FUNCNAME); \
00086 } \
00087 fprintf x; \
00088 fflush(xed_log_file); \
00089 } \
00090 } while(0)
00091
00092 #define XED2VMSG(x) \
00093 do { \
00094 if (XED_VERY_VERBOSE) { \
00095 fprintf(xed_log_file,"%s:%d:%s: ", \
00096 __FILE__, __LINE__, XED_FUNCNAME); \
00097 fprintf x; \
00098 fflush(xed_log_file); \
00099 } \
00100 } while(0)
00101
00102 #define XED2DIE(x) \
00103 do { \
00104 if (XED_EMIT_MESSAGES) { \
00105 fprintf(xed_log_file,"%s:%d:%s: ", \
00106 __FILE__, __LINE__, XED_FUNCNAME); \
00107 fprintf x; \
00108 fflush(xed_log_file); \
00109 } \
00110 xed_assert(0); \
00111 } while(0)
00112
00113
00114
00115 #else
00116 # define XED2IMSG(x)
00117 # define XED2TMSG(x)
00118 # define XED2VMSG(x)
00119 # define XED2DIE(x) do { xed_assert(0); } while(0)
00120 #endif
00121
00122 #if defined(XED_ASSERTS)
00123 # define xed_assert(x) do { if (( x )== 0) xed_internal_assert( #x, __FILE__, __LINE__); } while(0)
00124 #else
00125 # define xed_assert(x) do { } while(0)
00126 #endif
00127 XED_NORETURN XED_NOINLINE XED_DLL_EXPORT void xed_internal_assert(const char* s, const char* file, int line);
00128
00148 XED_DLL_EXPORT void xed_register_abort_function(void (*fn)(const char* msg,
00149 const char* file, int line, void* other),
00150 void* other);
00151
00152
00154
00156 char* xed_downcase_buf(char* s);
00157
00158 int xed_itoa(char* buf, xed_uint64_t f, int buflen);
00159 int xed_itoa_hex_zeros(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, xed_bool_t leading_zeros, int buflen);
00160 int xed_itoa_hex(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, int buflen);
00161 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
00162
00163 char xed_to_ascii_hex_nibble(xed_uint_t x);
00164
00165 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
00166 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
00167 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
00168 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
00169 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
00170 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
00171 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
00172 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
00173 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
00174 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
00175 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
00176 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
00177
00178
00180 XED_DLL_EXPORT void xed_set_log_file(FILE* o);
00181
00182
00184 XED_DLL_EXPORT void xed_set_verbosity(int v);
00185
00186 void xed_derror(const char* s);
00187 void xed_dwarn(const char* s);
00188
00189 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
00190 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
00191 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
00192
00193 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
00194 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
00195
00196 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
00197
00199 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
00200
00202 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
00203
00204
00205 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
00206 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
00207 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
00208
00209 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
00210 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
00211
00212 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
00213
00214 XED_DLL_EXPORT xed_int32_t
00215 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
00216
00217 XED_DLL_EXPORT xed_int64_t
00218 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
00219 XED_DLL_EXPORT xed_uint64_t
00220 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
00221
00222 XED_DLL_EXPORT xed_int64_t
00223 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00224 XED_DLL_EXPORT xed_uint64_t
00225 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00226
00227 XED_DLL_EXPORT xed_uint8_t
00228 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
00229
00230 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
00231 xed_uint64_t x,y;
00232 x=hi;
00233 y= (x<<32) | lo;
00234 return y;
00235 }
00236 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
00237 xed_uint64_t x,y;
00238 x=hi;
00239 y= (x<<32) | lo;
00240 return STATIC_CAST(xed_int64_t,y);
00241 }
00242
00249 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
00250
00256 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
00257
00259
00261
00263 #endif
00264
00265
00266