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_output_suppression( bool value );
00057
00059 void set_debug( bool value );
00060
00062 void set_testmode();
00063
00065 void print_output( const char* msg, int type, const char* file, int line );
00066
00068 bool check_option_value( int argc, const char** argv, int option_index );
00069
00071 bool is_variable( const char* token );
00072
00074 bool is_legal_filename( const char* token );
00075
00077 bool is_func_unit( const char* token );
00078
00080 const char* get_basename( const char* str );
00081
00083 char* get_dirname( char* str );
00084
00086 char* get_absolute_path( const char* filename );
00087
00089 char* get_relative_path( const char* abs_path );
00090
00092 bool directory_exists( const char* dir );
00093
00095 void directory_load( const char* dir, const str_link* ext_head, str_link** file_head, str_link** file_tail );
00096
00098 bool file_exists( const char* file );
00099
00101 bool util_readline(
00102 FILE* file,
00103 char** line,
00104 unsigned int* line_size
00105 );
00106
00108 bool get_quoted_string(
00109 FILE* file,
00110 char* line
00111 );
00112
00114 char* substitute_env_vars( const char* value );
00115
00117 void scope_extract_front( const char* scope, char* front, char* rest );
00118
00120 void scope_extract_back( const char* scope, char* back, char* rest );
00121
00123 void scope_extract_scope( const char* scope, const char* front, char* back );
00124
00126 char* scope_gen_printable( const char* str );
00127
00129 bool scope_compare( const char* str1, const char* str2 );
00130
00132 bool scope_local( const char* scope );
00133
00135 str_link* get_next_vfile( str_link* curr, const char* mod );
00136
00138 void* malloc_safe1( size_t size, const char* file, int line, unsigned int profile_index );
00139
00141 void* malloc_safe_nolimit1( size_t size, const char* file, int line, unsigned int profile_index );
00142
00144 void free_safe1( void* ptr, unsigned int profile_index ) ;
00145
00147 void free_safe2( void* ptr, size_t size, const char* file, int line, unsigned int profile_index ) ;
00148
00150 char* strdup_safe1( const char* str, const char* file, int line, unsigned int profile_index );
00151
00153 void* realloc_safe1(
00154 void* ptr,
00155 size_t old_size,
00156 size_t size,
00157 const char* file,
00158 int line,
00159 unsigned int profile_index
00160 );
00161
00163 void* calloc_safe1(
00164 size_t num,
00165 size_t size,
00166 const char* file,
00167 int line,
00168 unsigned int profile_index
00169 );
00170
00172 void gen_char_string(
00173 char* spaces,
00174 char c,
00175 int num_spaces
00176 );
00177
00179 char* remove_underscores(
00180 char* str
00181 );
00182
00183 #ifdef HAVE_SYS_TIME_H
00184
00185 void timer_clear( timer** tm );
00186
00188 void timer_start( timer** tm );
00189
00191 void timer_stop( timer** tm );
00192
00194 char* timer_to_string( timer* tm );
00195 #endif
00196
00198 const char* get_funit_type( int type );
00199
00201 void calc_miss_percent(
00202 int hits,
00203 int total,
00204 int* misses,
00205 float* percent );
00206
00208 void set_timestep( sim_time* st, char* value );
00209
00211 void read_command_file(
00212 const char* cmd_file,
00213 char*** arg_list,
00214 int* arg_num
00215 );
00216
00218 void gen_exclusion_id(
00219 char* excl_id,
00220 char type,
00221 int id
00222 );
00223
00224 #endif
00225