xed-util.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Intel Open Source License 
00003 
00004 Copyright (c) 2002-2011 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 
00146 XED_DLL_EXPORT void xed_register_abort_function(void (*fn)(const char* msg,
00147                                                            const char* file, int line, void* other),
00148                                                 void* other);
00149 
00150 
00152 // PROTOTYPES
00154 char* xed_downcase_buf(char* s);
00155 
00156 /* copy from src to dst, downcasing bytes as the copy proceeds. len is the available space in the buffer*/
00157 int xed_strncat_lower(char* dst, const char* src, int len);
00158 
00159 int xed_itoa(char* buf, xed_uint64_t f, int buflen);
00160 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);
00161 int xed_itoa_hex(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, int buflen);
00162 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
00163 
00164 char xed_to_ascii_hex_nibble(xed_uint_t x);
00165 
00166 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
00167 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
00168 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
00169 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
00170 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
00171 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
00172 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
00173 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
00174 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
00175 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
00176 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
00177 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
00178 
00181 XED_DLL_EXPORT void xed_set_log_file(void* o);
00182 
00183 
00185 XED_DLL_EXPORT void xed_set_verbosity(int v);
00186 
00187 void xed_derror(const char* s);
00188 void xed_dwarn(const char* s);
00189 
00190 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
00191 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
00192 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
00193 
00194 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
00195 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
00196 
00197 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
00198 
00200 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
00201 
00203 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
00204 
00205 
00206 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
00207 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
00208 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
00209 
00210 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
00211 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
00212 
00213 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
00214 
00215 #if defined(XED_LITTLE_ENDIAN_SWAPPING)
00216 XED_DLL_EXPORT xed_int32_t 
00217 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
00218 
00219 XED_DLL_EXPORT xed_int64_t 
00220 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
00221 XED_DLL_EXPORT xed_uint64_t 
00222 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
00223 
00224 XED_DLL_EXPORT xed_int64_t 
00225 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00226 XED_DLL_EXPORT xed_uint64_t 
00227 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00228 #endif
00229 
00230 XED_DLL_EXPORT xed_uint8_t
00231 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
00232 
00233 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
00234     xed_union64_t y;
00235     y.s.lo32= lo;
00236     y.s.hi32= hi;
00237     return y.u64;
00238 }
00239 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
00240     xed_union64_t y;
00241     y.s.lo32= lo;
00242     y.s.hi32= hi;
00243     return y.i64;
00244 }
00245 
00252 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
00253 
00259 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
00260 
00262 // GLOBALS
00264 
00266 #endif
00267 //Local Variables:
00268 //pref: "../../xed-util.c"
00269 //End:

Generated on Tue Nov 22 12:27:53 2011 for XED2 by  doxygen 1.4.6