00001 #ifndef __UTIL_H__
00002 #define __UTIL_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00026 #include <stdio.h>
00027
00028 #include "defines.h"
00029 #include "profiler.h"
00030
00031
00033 #define malloc_safe(x) malloc_safe1(x,__FILE__,__LINE__,profile_index)
00034
00036 #define malloc_safe_nolimit(x) malloc_safe_nolimit1(x,__FILE__,__LINE__,profile_index)
00037
00039 #define strdup_safe(x) strdup_safe1(x,__FILE__,__LINE__,profile_index)
00040
00042 #define realloc_safe(x,y,z) realloc_safe1(x,(((x)!=NULL)?y:0),z,__FILE__,__LINE__,profile_index)
00043
00045 #define calloc_safe(x,y) calloc_safe1(x,y,__FILE__,__LINE__,profile_index)
00046
00048 #ifdef TESTMODE
00049 #define free_safe(x,y) free_safe2(x,(((x)!=NULL)?y:0),__FILE__, __LINE__,profile_index)
00050 #else
00051 #define free_safe(x,y) free_safe1(x,profile_index)
00052 #endif
00053
00054
00056 void set_quiet( bool value );
00057
00059 void set_terse( bool value );
00060
00062 void set_debug( bool value );
00063
00065 void set_testmode();
00066
00068 void print_output( const char* msg, int type, const char* file, int line );
00069
00071 bool check_option_value( int argc, const char** argv, int option_index );
00072
00074 bool is_variable( const char* token );
00075
00077 bool is_legal_filename( const char* token );
00078
00080 bool is_func_unit( const char* token );
00081
00083 const char* get_basename( const char* str );
00084
00086 char* get_dirname( char* str );
00087
00089 char* get_absolute_path( const char* filename );
00090
00092 char* get_relative_path( const char* abs_path );
00093
00095 bool directory_exists( const char* dir );
00096
00098 void directory_load( const char* dir, const str_link* ext_head, str_link** file_head, str_link** file_tail );
00099
00101 bool file_exists( const char* file );
00102
00104 bool util_readline(
00105 FILE* file,
00106 char** line,
00107 unsigned int* line_size
00108 );
00109
00111 bool get_quoted_string(
00112 FILE* file,
00113 char* line
00114 );
00115
00117 char* substitute_env_vars( const char* value );
00118
00120 void scope_extract_front( const char* scope, char* front, char* rest );
00121
00123 void scope_extract_back( const char* scope, char* back, char* rest );
00124
00126 void scope_extract_scope( const char* scope, const char* front, char* back );
00127
00129 char* scope_gen_printable( const char* str );
00130
00132 bool scope_compare( const char* str1, const char* str2 );
00133
00135 bool scope_local( const char* scope );
00136
00138 str_link* get_next_vfile( str_link* curr, const char* mod );
00139
00141 void* malloc_safe1( size_t size, const char* file, int line, unsigned int profile_index );
00142
00144 void* malloc_safe_nolimit1( size_t size, const char* file, int line, unsigned int profile_index );
00145
00147 void free_safe1( void* ptr, unsigned int profile_index ) ;
00148
00150 void free_safe2( void* ptr, size_t size, const char* file, int line, unsigned int profile_index ) ;
00151
00153 char* strdup_safe1( const char* str, const char* file, int line, unsigned int profile_index );
00154
00156 void* realloc_safe1(
00157 void* ptr,
00158 size_t old_size,
00159 size_t size,
00160 const char* file,
00161 int line,
00162 unsigned int profile_index
00163 );
00164
00166 void* calloc_safe1(
00167 size_t num,
00168 size_t size,
00169 const char* file,
00170 int line,
00171 unsigned int profile_index
00172 );
00173
00175 void gen_char_string(
00176 char* spaces,
00177 char c,
00178 int num_spaces
00179 );
00180
00182 char* remove_underscores(
00183 char* str
00184 );
00185
00186 #ifdef HAVE_SYS_TIME_H
00187
00188 void timer_clear( timer** tm );
00189
00191 void timer_start( timer** tm );
00192
00194 void timer_stop( timer** tm );
00195
00197 char* timer_to_string( timer* tm );
00198 #endif
00199
00201 const char* get_funit_type( int type );
00202
00204 void calc_miss_percent(
00205 int hits,
00206 int total,
00207 int* misses,
00208 float* percent );
00209
00211 void set_timestep( sim_time* st, char* value );
00212
00214 void read_command_file(
00215 const char* cmd_file,
00216 char*** arg_list,
00217 int* arg_num
00218 );
00219
00221 void gen_exclusion_id(
00222 char* excl_id,
00223 char type,
00224 int id
00225 );
00226
00227 #endif
00228