- Main Page
- Modules
- Data Structures
- Files

- Search for |

- File List
- Globals

# xed-util.h

Go to the documentation of this file.

    00001 /*BEGIN_LEGAL
    00002 Intel Open Source License
    00003
    00004 Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
    00005
    00006 Redistribution and use in source and binary forms, with or without
    00007 modification, are permitted provided that the following conditions are
    00008 met:
    00009
    00010 Redistributions of source code must retain the above copyright notice,
    00011 this list of conditions and the following disclaimer.  Redistributions
    00012 in binary form must reproduce the above copyright notice, this list of
    00013 conditions and the following disclaimer in the documentation and/or
    00014 other materials provided with the distribution.  Neither the name of
    00015 the Intel Corporation nor the names of its contributors may be used to
    00016 endorse or promote products derived from this software without
    00017 specific prior written permission.
    00018
    00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00020 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
    00023 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00024 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00025 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    00026 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    00027 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00029 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030 END_LEGAL */
    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 // DEFINES
    00047 extern int xed_verbose;
    00048 #if XED_MESSAGES==1
    00049 # include <stdio.h>
    00050 extern  FILE* xed_log_file;
    00051 #endif
    00052 #define XED_EMIT_MESSAGES  (XED_MESSAGES==1 && xed_verbose >= 1)
    00053 #define XED_INFO_VERBOSE   (XED_MESSAGES==1 && xed_verbose >= 2)
    00054 #define XED_INFO2_VERBOSE  (XED_MESSAGES==1 && xed_verbose >= 3)
    00055 #define XED_VERBOSE        (XED_MESSAGES==1 && xed_verbose >= 4)
    00056 #define XED_MORE_VERBOSE   (XED_MESSAGES==1 && xed_verbose >= 5)
    00057 #define XED_VERY_VERBOSE   (XED_MESSAGES==1 && xed_verbose >= 6)
    00058
    00059 #if defined(__GNUC__)
    00060 # define XED_FUNCNAME __func__
    00061 #else
    00062 # define XED_FUNCNAME ""
    00063 #endif
    00064
    00065 #if XED_MESSAGES==1
    00066 #define XED2IMSG(x)                                             \
    00067     do {                                                        \
    00068         if (XED_EMIT_MESSAGES) {                                \
    00069             if (XED_VERY_VERBOSE) {                             \
    00070                 fprintf(xed_log_file,"%s:%d:%s: ",              \
    00071                         __FILE__, __LINE__, XED_FUNCNAME);      \
    00072             }                                                   \
    00073             fprintf x;                                          \
    00074             fflush(xed_log_file);                               \
    00075         }                                                       \
    00076     } while(0)
    00077
    00078 #define XED2TMSG(x)                                             \
    00079     do {                                                        \
    00080         if (XED_VERBOSE) {                                      \
    00081             if (XED_VERY_VERBOSE) {                             \
    00082                 fprintf(xed_log_file,"%s:%d:%s: ",              \
    00083                         __FILE__, __LINE__, XED_FUNCNAME);      \
    00084             }                                                   \
    00085             fprintf x;                                          \
    00086             fflush(xed_log_file);                               \
    00087         }                                                       \
    00088     } while(0)
    00089
    00090 #define XED2VMSG(x)                                             \
    00091     do {                                                        \
    00092         if (XED_VERY_VERBOSE) {                                 \
    00093             fprintf(xed_log_file,"%s:%d:%s: ",                  \
    00094                     __FILE__, __LINE__, XED_FUNCNAME);          \
    00095             fprintf x;                                          \
    00096             fflush(xed_log_file);                               \
    00097         }                                                       \
    00098     } while(0)
    00099
    00100 #define XED2DIE(x)                                              \
    00101     do {                                                        \
    00102         if (XED_EMIT_MESSAGES) {                                \
    00103             fprintf(xed_log_file,"%s:%d:%s: ",                  \
    00104                              __FILE__, __LINE__, XED_FUNCNAME); \
    00105             fprintf x;                                          \
    00106             fflush(xed_log_file);                               \
    00107         }                                                       \
    00108         xed_assert(0);                                          \
    00109     } while(0)
    00110
    00111
    00112
    00113 #else
    00114 # define XED2IMSG(x)
    00115 # define XED2TMSG(x)
    00116 # define XED2VMSG(x)
    00117 # define XED2DIE(x) do { xed_assert(0); } while(0)
    00118 #endif
    00119
    00120 #if defined(XED_ASSERTS)
    00121 #  define xed_assert(x)  do { if (( x )== 0) xed_internal_assert( #x, __FILE__, __LINE__); } while(0)
    00122 #else
    00123 #  define xed_assert(x)  do {  } while(0)
    00124 #endif
    00125 XED_NORETURN XED_NOINLINE XED_DLL_EXPORT void xed_internal_assert(const char* s, const char* file, int line);
    00126
    00127 typedef void (*xed_user_abort_function_t)(const char* msg,
    00128                                           const char* file,
    00129                                           int line,
    00130                                           void* other);
    00131
    00151 XED_DLL_EXPORT void xed_register_abort_function(xed_user_abort_function_t fn,
    00152                                                 void* other);
    00153
    00154
    00156 // PROTOTYPES
    00158 char* xed_downcase_buf(char* s);
    00159
    00160 /* copy from src to dst, downcasing bytes as the copy proceeds. len is the
    00161  * available space in the buffer*/
    00162 int xed_strncat_lower(char* dst, const char* src, int len);
    00163
    00164 XED_DLL_EXPORT int xed_itoa(char* buf,
    00165                             xed_uint64_t f,
    00166                             int buflen);
    00167
    00168 int xed_itoa_hex_zeros(char* buf,
    00169                        xed_uint64_t f,
    00170                        xed_uint_t xed_bits_to_print,
    00171                        xed_bool_t leading_zeros,
    00172                        int buflen);
    00173
    00174 XED_DLL_EXPORT int xed_itoa_hex(char* buf,
    00175                                 xed_uint64_t f,
    00176                                 xed_uint_t xed_bits_to_print,
    00177                                 int buflen);
    00178
    00179 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
    00180
    00181 char xed_to_ascii_hex_nibble(xed_uint_t x);
    00182
    00183 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
    00184 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
    00185 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
    00186 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
    00187 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
    00188 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
    00189 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
    00190 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
    00191 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
    00192 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
    00193 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
    00194 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
    00195
    00198 XED_DLL_EXPORT void xed_set_log_file(void* o);
    00199
    00200
    00202 XED_DLL_EXPORT void xed_set_verbosity(int v);
    00203
    00204 void xed_derror(const char* s);
    00205 void xed_dwarn(const char* s);
    00206
    00207 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
    00208 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
    00209 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
    00210
    00211 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
    00212 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
    00213
    00214 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
    00215
    00217 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
    00218
    00220 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
    00221
    00222
    00223 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
    00224 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
    00225 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
    00226
    00227 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
    00228 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
    00229
    00230 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
    00231
    00232 #if defined(XED_LITTLE_ENDIAN_SWAPPING)
    00233 XED_DLL_EXPORT xed_int32_t
    00234 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
    00235
    00236 XED_DLL_EXPORT xed_int64_t
    00237 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
    00238 XED_DLL_EXPORT xed_uint64_t
    00239 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
    00240
    00241 XED_DLL_EXPORT xed_int64_t
    00242 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
    00243 XED_DLL_EXPORT xed_uint64_t
    00244 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
    00245 #endif
    00246
    00247 XED_DLL_EXPORT xed_uint8_t
    00248 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
    00249
    00250 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
    00251     xed_union64_t y;
    00252     y.s.lo32= lo;
    00253     y.s.hi32= hi;
    00254     return y.u64;
    00255 }
    00256 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
    00257     xed_union64_t y;
    00258     y.s.lo32= lo;
    00259     y.s.hi32= hi;
    00260     return y.i64;
    00261 }
    00262
    00269 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
    00270
    00276 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
    00277
    00279 // GLOBALS
    00281
    00283 #endif