xed-util.h

Go to the documentation of this file.
00001 /*BEGIN_LEGAL 
00002 Copyright (c) 2004-2008, Intel Corp.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are
00007 met:
00008 
00009     * Redistributions of source code must retain the above copyright
00010       notice, this list of conditions and the following disclaimer.
00011 
00012     * Redistributions in binary form must reproduce the above
00013       copyright notice, this list of conditions and the following
00014       disclaimer in the documentation and/or other materials provided
00015       with the distribution.
00016 
00017     * Neither the name of Intel Corporation nor the names of its
00018       contributors may be used to endorse or promote products derived
00019       from this software without specific prior written permission.
00020 
00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 END_LEGAL */
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 // DEFINES
00049 extern int xed_verbose;
00050 #if defined(XED_MESSAGES)
00051 # include <stdio.h> // only with XED_MESSAGES defined
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 // PROTOTYPES
00156 char* xed_downcase_buf(char* s);
00157 
00158 /* copy from src to dst, downcasing bytes as the copy proceeds. len is the available space in the buffer*/
00159 int xed_strncat_lower(char* dst, const char* src, int len);
00160 
00161 int xed_itoa(char* buf, xed_uint64_t f, int buflen);
00162 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);
00163 int xed_itoa_hex(char* buf, xed_uint64_t f, xed_uint_t xed_bits_to_print, int buflen);
00164 int xed_itoa_signed(char* buf, xed_int64_t f, int buflen);
00165 
00166 char xed_to_ascii_hex_nibble(xed_uint_t x);
00167 
00168 int xed_sprintf_uint8_hex(char* buf, xed_uint8_t x, int buflen);
00169 int xed_sprintf_uint16_hex(char* buf, xed_uint16_t x, int buflen);
00170 int xed_sprintf_uint32_hex(char* buf, xed_uint32_t x, int buflen);
00171 int xed_sprintf_uint64_hex(char* buf, xed_uint64_t x, int buflen);
00172 int xed_sprintf_uint8(char* buf, xed_uint8_t x, int buflen);
00173 int xed_sprintf_uint16(char* buf, xed_uint16_t x, int buflen);
00174 int xed_sprintf_uint32(char* buf, xed_uint32_t x, int buflen);
00175 int xed_sprintf_uint64(char* buf, xed_uint64_t x, int buflen);
00176 int xed_sprintf_int8(char* buf, xed_int8_t x, int buflen);
00177 int xed_sprintf_int16(char* buf, xed_int16_t x, int buflen);
00178 int xed_sprintf_int32(char* buf, xed_int32_t x, int buflen);
00179 int xed_sprintf_int64(char* buf, xed_int64_t x, int buflen);
00180 
00181 
00183 XED_DLL_EXPORT void xed_set_log_file(FILE* o);
00184 
00185 
00187 XED_DLL_EXPORT void xed_set_verbosity(int v);
00188 
00189 void xed_derror(const char* s);
00190 void xed_dwarn(const char* s);
00191 
00192 XED_DLL_EXPORT xed_int64_t xed_sign_extend32_64(xed_int32_t x);
00193 XED_DLL_EXPORT xed_int64_t xed_sign_extend16_64(xed_int16_t x);
00194 XED_DLL_EXPORT xed_int64_t xed_sign_extend8_64(xed_int8_t x);
00195 
00196 XED_DLL_EXPORT xed_int32_t xed_sign_extend16_32(xed_int16_t x);
00197 XED_DLL_EXPORT xed_int32_t xed_sign_extend8_32(xed_int8_t x);
00198 
00199 XED_DLL_EXPORT xed_int16_t xed_sign_extend8_16(xed_int8_t x);
00200 
00202 XED_DLL_EXPORT xed_int32_t xed_sign_extend_arbitrary_to_32(xed_uint32_t x, unsigned int bits);
00203 
00205 XED_DLL_EXPORT xed_int64_t xed_sign_extend_arbitrary_to_64(xed_uint64_t x, unsigned int bits);
00206 
00207 
00208 XED_DLL_EXPORT xed_uint64_t xed_zero_extend32_64(xed_uint32_t x);
00209 XED_DLL_EXPORT xed_uint64_t xed_zero_extend16_64(xed_uint16_t x);
00210 XED_DLL_EXPORT xed_uint64_t xed_zero_extend8_64(xed_uint8_t x);
00211 
00212 XED_DLL_EXPORT xed_uint32_t xed_zero_extend16_32(xed_uint16_t x);
00213 XED_DLL_EXPORT xed_uint32_t xed_zero_extend8_32(xed_uint8_t x);
00214 
00215 XED_DLL_EXPORT xed_uint16_t xed_zero_extend8_16(xed_uint8_t x);
00216 
00217 #if defined(XED_LITTLE_ENDIAN_SWAPPING)
00218 XED_DLL_EXPORT xed_int32_t 
00219 xed_little_endian_to_int32(xed_uint64_t x, unsigned int len);
00220 
00221 XED_DLL_EXPORT xed_int64_t 
00222 xed_little_endian_to_int64(xed_uint64_t x, unsigned int len);
00223 XED_DLL_EXPORT xed_uint64_t 
00224 xed_little_endian_to_uint64(xed_uint64_t x, unsigned int len);
00225 
00226 XED_DLL_EXPORT xed_int64_t 
00227 xed_little_endian_hilo_to_int64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00228 XED_DLL_EXPORT xed_uint64_t 
00229 xed_little_endian_hilo_to_uint64(xed_uint32_t hi_le, xed_uint32_t lo_le, unsigned int len);
00230 #endif
00231 
00232 XED_DLL_EXPORT xed_uint8_t
00233 xed_get_byte(xed_uint64_t x, unsigned int i, unsigned int len);
00234 
00235 static XED_INLINE xed_uint64_t xed_make_uint64(xed_uint32_t hi, xed_uint32_t lo) {
00236     xed_uint64_t x,y;
00237     x=hi;
00238     y= (x<<32) | lo;
00239     return y;
00240 }
00241 static XED_INLINE xed_int64_t xed_make_int64(xed_uint32_t hi, xed_uint32_t lo) {
00242     xed_uint64_t x,y;
00243     x=hi;
00244     y= (x<<32) | lo;
00245     return STATIC_CAST(xed_int64_t,y);
00246 }
00247 
00254 XED_DLL_EXPORT xed_uint_t xed_shortest_width_unsigned(xed_uint64_t x, xed_uint8_t legal_widths);
00255 
00261 XED_DLL_EXPORT xed_uint_t xed_shortest_width_signed(xed_int64_t x, xed_uint8_t legal_widths);
00262 
00264 // GLOBALS
00266 
00268 #endif
00269 //Local Variables:
00270 //pref: "../../xed-util.c"
00271 //End:

Generated on Mon Oct 6 20:12:22 2008 for XED2 by  doxygen 1.4.6