From: Julian Seward Date: Mon, 17 Jan 2005 18:34:34 +0000 (+0000) Subject: Rename some functions and types in the top level interface to be more X-Git-Tag: svn/VALGRIND_3_0_1^2~616 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1073520b669148ade3c42dc57e28563eabddd267;p=thirdparty%2Fvalgrind.git Rename some functions and types in the top level interface to be more consistent. Also make private some functions that Valgrind never used. git-svn-id: svn://svn.valgrind.org/vex/trunk@718 --- diff --git a/VEX/priv/ir/irmatch.h b/VEX/priv/ir/irmatch.h index 2bf124dd34..890d5fda9f 100644 --- a/VEX/priv/ir/irmatch.h +++ b/VEX/priv/ir/irmatch.h @@ -52,11 +52,11 @@ #define DEFINE_PATTERN(_patt,_expr) \ do { \ if (!(_patt)) { \ - vassert(LibVEX_GetAllocMode() == AllocModeTEMPORARY); \ - LibVEX_SetAllocMode(AllocModePERMANENT); \ + vassert(vexGetAllocMode() == VexAllocModeTEMP); \ + vexSetAllocMode(VexAllocModePERM); \ _patt = (_expr); \ - LibVEX_SetAllocMode(AllocModeTEMPORARY); \ - vassert(LibVEX_GetAllocMode() == AllocModeTEMPORARY); \ + vexSetAllocMode(VexAllocModeTEMP); \ + vassert(vexGetAllocMode() == VexAllocModeTEMP); \ } \ } while (0) diff --git a/VEX/priv/main/vex_main.c b/VEX/priv/main/vex_main.c index c41b87b5a5..9cacd13381 100644 --- a/VEX/priv/main/vex_main.c +++ b/VEX/priv/main/vex_main.c @@ -55,7 +55,7 @@ /* Exported to library client. */ -HChar* LibVEX_Version ( void ) +const HChar* LibVEX_Version ( void ) { return #include "main/vex_svnversion.h" @@ -146,7 +146,7 @@ void LibVEX_Init ( vex_valgrind_support = valgrind_support; vex_control = *vcon; vex_initdone = True; - LibVEX_SetAllocMode ( AllocModeTEMPORARY ); + vexSetAllocMode ( VexAllocModeTEMP ); } @@ -154,7 +154,7 @@ void LibVEX_Init ( /* Exported to library client. */ -TranslateResult LibVEX_Translate ( +VexTranslateResult LibVEX_Translate ( /* The instruction sets we are translating from and to. */ VexArch arch_guest, VexSubArch subarch_guest, @@ -232,7 +232,7 @@ TranslateResult LibVEX_Translate ( vex_traceflags = traceflags; vassert(vex_initdone); - LibVEX_ClearTemporary(False); + vexClearTEMP(); /* First off, check that the guest and host insn sets @@ -314,9 +314,9 @@ TranslateResult LibVEX_Translate ( if (irbb == NULL) { /* Access failure. */ - LibVEX_ClearTemporary(False); + vexClearTEMP(); vex_traceflags = 0; - return TransAccessFail; + return VexTransAccessFail; } /* If debugging, show the raw guest bytes for this bb. */ @@ -454,9 +454,9 @@ TranslateResult LibVEX_Translate ( vex_printf("\n\n"); } if (out_used + j > host_bytes_size) { - LibVEX_ClearTemporary(False); + vexClearTEMP(); vex_traceflags = 0; - return TransOutputFull; + return VexTransOutputFull; } for (k = 0; k < j; k++) { host_bytes[out_used] = insn_bytes[k]; @@ -466,10 +466,10 @@ TranslateResult LibVEX_Translate ( } *host_bytes_used = out_used; - LibVEX_ClearTemporary(False); + vexClearTEMP(); vex_traceflags = 0; - return TransOK; + return VexTransOK; } diff --git a/VEX/priv/main/vex_util.c b/VEX/priv/main/vex_util.c index 9fb32afc0e..ea7e0114dc 100644 --- a/VEX/priv/main/vex_util.c +++ b/VEX/priv/main/vex_util.c @@ -70,19 +70,15 @@ static ULong temporary_bytes_allocd_TOT = 0; static ULong temporary_count_allocs_TOT = 0; /* The current allocation mode. */ -static AllocMode mode = AllocModeTEMPORARY; +static VexAllocMode mode = VexAllocModeTEMP; -/* Exported to library client. */ - -void LibVEX_SetAllocMode ( AllocMode m ) +void vexSetAllocMode ( VexAllocMode m ) { mode = m; } -/* Exported to library client. */ - -AllocMode LibVEX_GetAllocMode ( void ) +VexAllocMode vexGetAllocMode ( void ) { return mode; } @@ -101,7 +97,7 @@ void* LibVEX_Alloc ( Int nbytes ) return malloc(nbytes); } else { nbytes = (nbytes + ALIGN) & ~ALIGN; - if (mode == AllocModeTEMPORARY) { + if (mode == VexAllocModeTEMP) { if (temporary_used + nbytes > N_TEMPORARY_BYTES) vpanic("VEX temporary storage exhausted.\n" "Increase N_TEMPORARY_BYTES and recompile."); @@ -120,26 +116,28 @@ void* LibVEX_Alloc ( Int nbytes ) # undef ALIGN } -/* Exported to library client. */ - -void LibVEX_ClearTemporary ( Bool verb ) +void vexClearTEMP ( void ) { /* vassert(vex_initdone); */ /* causes infinite assert loops */ temporary_bytes_allocd_TOT += (ULong)temporary_bytes_allocd; temporary_count_allocs_TOT += (ULong)temporary_count_allocs; - if (verb) { - vex_printf("vex storage: P %d, T total %lld (%lld), T curr %d (%d)\n", - permanent_used, - (Long)temporary_bytes_allocd_TOT, - (Long)temporary_count_allocs_TOT, - temporary_bytes_allocd, temporary_count_allocs ); - } temporary_used = 0; temporary_bytes_allocd = 0; temporary_count_allocs = 0; } +/* Exported to library client. */ + +void LibVEX_ShowAllocStats ( void ) +{ + vex_printf("vex storage: P %d, T total %lld (%lld), T curr %d (%d)\n", + permanent_used, + (Long)temporary_bytes_allocd_TOT, + (Long)temporary_count_allocs_TOT, + temporary_bytes_allocd, temporary_count_allocs ); +} + /*---------------------------------------------------------*/ /*--- Bombing out ---*/ @@ -523,8 +521,6 @@ UInt vex_sprintf ( Char* buf, const HChar *format, ... ) } - - /*---------------------------------------------------------------*/ /*--- end vex_util.c ---*/ /*---------------------------------------------------------------*/ diff --git a/VEX/priv/main/vex_util.h b/VEX/priv/main/vex_util.h index 021e4e0703..d9e4d85997 100644 --- a/VEX/priv/main/vex_util.h +++ b/VEX/priv/main/vex_util.h @@ -75,6 +75,25 @@ extern UInt vex_sprintf ( Char* buf, const HChar *format, ... ); extern Bool vex_streq ( const Char* s1, const Char* s2 ); +/* Storage management: clear the area, and allocate from it. */ + +/* By default allocation occurs in the temporary area. However, it is + possible to switch to permanent area allocation if that's what you + want. Permanent area allocation is very limited, tho. */ + +typedef + enum { + VexAllocModeTEMP, + VexAllocModePERM + } + VexAllocMode; + +extern void vexSetAllocMode ( VexAllocMode ); +extern VexAllocMode vexGetAllocMode ( void ); + +extern void vexClearTEMP ( void ); + + #endif /* ndef __VEX_UTIL_H */ /*---------------------------------------------------------------*/ diff --git a/VEX/pub/libvex.h b/VEX/pub/libvex.h index a208f94eeb..84960e82ff 100644 --- a/VEX/pub/libvex.h +++ b/VEX/pub/libvex.h @@ -42,10 +42,12 @@ /*---------------------------------------------------------------*/ -/*--- Top-level interface to the library. ---*/ +/*--- This file defines the top-level interface to LibVEX. ---*/ /*---------------------------------------------------------------*/ -/* Describes architectures and subarchitecture variants. */ +/*-------------------------------------------------------*/ +/*--- Architectures and architecture variants ---*/ +/*-------------------------------------------------------*/ typedef enum { @@ -73,6 +75,10 @@ extern const HChar* LibVEX_ppVexArch ( VexArch ); extern const HChar* LibVEX_ppVexSubArch ( VexSubArch ); +/*-------------------------------------------------------*/ +/*--- Control of Vex's optimiser (iropt). ---*/ +/*-------------------------------------------------------*/ + /* Control of Vex's optimiser. */ typedef @@ -106,48 +112,38 @@ typedef /* Write the default settings into *vcon. */ -extern void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon ); - - -/* Returns the Vex SVN version. */ - -extern HChar* LibVEX_Version ( void ); +extern +void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon ); -/* Initialise the translator. */ +/*-------------------------------------------------------*/ +/*--- Version information ---*/ +/*-------------------------------------------------------*/ -extern void LibVEX_Init ( - /* failure exit function */ - __attribute__ ((noreturn)) - void (*failure_exit) ( void ), - /* logging output function */ - void (*log_bytes) ( Char*, Int nbytes ), - /* debug paranoia level */ - Int debuglevel, - /* Are we supporting valgrind checking? */ - Bool valgrind_support, - /* Control ... */ - /*READONLY*/VexControl* vcon -); +/* Returns the Vex SVN version, as a statically allocated string. */ +extern const HChar* LibVEX_Version ( void ); -/* Storage management: clear the area, and allocate from it. */ -/* By default allocation occurs in the temporary area. However, it is - possible to switch to permanent area allocation if that's what you - want. Permanent area allocation is very limited, tho. */ +/*-------------------------------------------------------*/ +/*--- Storage management control ---*/ +/*-------------------------------------------------------*/ -typedef - enum { AllocModeTEMPORARY, AllocModePERMANENT } - AllocMode; +/* Allocate in Vex's temporary allocation area. Be careful with this. + You can only call it inside an instrumentation or optimisation + callback that you have previously specified in a call to + LibVEX_Translate. The storage allocated will only stay alive until + translation of the current basic block is complete. + */ +extern void* LibVEX_Alloc ( Int nbytes ); -extern void LibVEX_SetAllocMode ( AllocMode ); -extern AllocMode LibVEX_GetAllocMode ( void ); +/* Show Vex allocation statistics. */ +extern void LibVEX_ShowAllocStats ( void ); -extern void LibVEX_ClearTemporary ( Bool show_stats ); - -extern void* LibVEX_Alloc ( Int nbytes ); +/*-------------------------------------------------------*/ +/*--- Describing guest state layout ---*/ +/*-------------------------------------------------------*/ /* Describe the guest state enough that the instrumentation functions can work. */ @@ -177,15 +173,57 @@ typedef } VexGuestLayout; +/* A note about guest state layout. + + LibVEX defines the layout for the guest state, in the file + pub/libvex_guest_.h. The struct will have an 8-aligned size. + Each translated bb is assumed to be entered with a specified + register pointing at such a struct. Beyond that is a shadow + state area with the same size as the struct. Beyond that is + a spill area that LibVEX may spill into. It must have size + LibVEX_N_SPILL_BYTES, and this must be a 16-aligned number. + + On entry, the baseblock pointer register must be 8-aligned. +*/ + +#define LibVEX_N_SPILL_BYTES 768 + -/* Translate a basic block. */ +/*-------------------------------------------------------*/ +/*--- Initialisation of the library ---*/ +/*-------------------------------------------------------*/ + +/* Initialise the library. You must call this first. */ + +extern void LibVEX_Init ( + /* failure exit function */ + __attribute__ ((noreturn)) + void (*failure_exit) ( void ), + /* logging output function */ + void (*log_bytes) ( Char*, Int nbytes ), + /* debug paranoia level */ + Int debuglevel, + /* Are we supporting valgrind checking? */ + Bool valgrind_support, + /* Control ... */ + /*READONLY*/VexControl* vcon +); + + +/*-------------------------------------------------------*/ +/*--- Make a translation ---*/ +/*-------------------------------------------------------*/ typedef - enum { TransOK, TransAccessFail, TransOutputFull } - TranslateResult; + enum { + VexTransOK, + VexTransAccessFail, + VexTransOutputFull + } + VexTranslateResult; extern -TranslateResult LibVEX_Translate ( +VexTranslateResult LibVEX_Translate ( /* The instruction sets we are translating from and to. */ VexArch arch_guest, VexSubArch subarch_guest, @@ -213,28 +251,16 @@ TranslateResult LibVEX_Translate ( ); -/* Show accumulated statistics. */ +/*-------------------------------------------------------*/ +/*--- Show accumulated statistics ---*/ +/*-------------------------------------------------------*/ extern void LibVEX_ShowStats ( void ); - -/* A note about baseblock layout. - - LibVEX defines the layout for the guest state, in the file - pub/libvex_guest_.h. The struct will have an 8-aligned size. - Each translated bb is assumed to be entered with a specified - register pointing at such a struct. Beyond that is a shadow - state area with the same size as the struct. Beyond that is - a spill area that LibVEX may spill into. It must have size - LibVEX_N_SPILL_BYTES, and this will be a 16-aligned number. - - On entry, the baseblock pointer register must be 8-aligned. -*/ - -#define LibVEX_N_SPILL_BYTES 768 - - +/*-------------------------------------------------------*/ +/*--- Notes ---*/ +/*-------------------------------------------------------*/ /* Code generation conventions that need to be recorded somewhere. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/VEX/test_main.c b/VEX/test_main.c index 047a25032f..c588551432 100644 --- a/VEX/test_main.c +++ b/VEX/test_main.c @@ -61,7 +61,7 @@ int main ( int argc, char** argv ) Addr32 orig_addr; Int bb_number, n_bbs_done = 0; Int orig_nbytes, trans_used, orig_used; - TranslateResult tres; + VexTranslateResult tres; VexControl vcon; if (argc != 2) { @@ -145,9 +145,9 @@ int main ( int argc, char** argv ) TEST_FLAGS ); - if (tres != TransOK) + if (tres != VexTransOK) printf("\ntres = %d\n", (Int)tres); - assert(tres == TransOK); + assert(tres == VexTransOK); assert(orig_used == orig_nbytes); sum = 0; @@ -158,7 +158,7 @@ int main ( int argc, char** argv ) fclose(f); printf("\n"); - LibVEX_ClearTemporary(True); + LibVEX_ShowAllocStats(); return 0; }