#include <stdlib.h>
#include <assert.h>
#include "defines.h"
#include "func_iter.h"
#include "func_unit.h"
#include "util.h"
Functions | |
void | func_iter_display (func_iter *fi) |
static void | func_iter_sort (func_iter *fi) |
static int | func_iter_count_scopes (func_unit *funit) |
static void | func_iter_add_stmt_links (func_iter *fi, func_unit *funit) |
static void | func_iter_add_sig_links (func_iter *fi, func_unit *funit) |
void | func_iter_init (func_iter *fi, func_unit *funit, bool stmts, bool sigs) |
Initializes the values in the given structure. | |
statement * | func_iter_get_next_statement (func_iter *fi) |
Provides the next statement iterator in the functional unit statement iterator. | |
vsignal * | func_iter_get_next_signal (func_iter *fi) |
Provides the next signal in the functional unit signal iterator. | |
void | func_iter_dealloc (func_iter *fi) |
Deallocates functional unit iterator. |
Recursively iterates through the functional units, adding their signal link pointers to the func_iter structure's array.
fi | Pointer to functional unit iterator to populate | |
funit | Pointer to current functional unit |
References funit_link_s::funit, funit_get_curr_module(), funit_is_unnamed(), funit_link_s::next, func_unit_s::parent, PROFILE, PROFILE_END, func_unit_s::sig_head, func_iter_s::sig_num, func_iter_s::sigs, and func_unit_s::tf_head.
Referenced by func_iter_init().
00188 { PROFILE(FUNC_ITER_ADD_SIG_LINKS); 00189 00190 funit_link* child; /* Pointer to child functional unit */ 00191 func_unit* parent; /* Pointer to parent module of this functional unit */ 00192 00193 /* Add the pointer */ 00194 fi->sigs[fi->sig_num] = funit->sig_head; 00195 fi->sig_num++; 00196 00197 /* Get the parent module */ 00198 parent = funit_get_curr_module( funit ); 00199 00200 /* Now traverse down all of the child functional units doing the same */ 00201 child = parent->tf_head; 00202 while( child != NULL ) { 00203 if( funit_is_unnamed( child->funit ) && (child->funit->parent == funit) ) { 00204 func_iter_add_sig_links( fi, child->funit ); 00205 } 00206 child = child->next; 00207 } 00208 00209 PROFILE_END; 00210 00211 }
Recursively iterates through functional units, adding their statement links to the func_iter structure's array.
fi | Pointer to functional unit iterator to populate | |
funit | Pointer to current functional unit |
References func_iter_sort(), funit_link_s::funit, funit_get_curr_module(), funit_is_unnamed(), funit_link_s::next, func_unit_s::parent, PROFILE, PROFILE_END, func_iter_s::scopes, func_iter_s::sl_num, func_iter_s::sls, func_unit_s::stmt_head, and func_unit_s::tf_head.
Referenced by func_iter_init().
00146 { PROFILE(FUNC_ITER_ADD_STMT_LINKS); 00147 00148 funit_link* child; /* Pointer to child functional unit */ 00149 func_unit* parent; /* Pointer to parent module of this functional unit */ 00150 int i; /* Loop iterator */ 00151 00152 /* First, shift all current statement iterators down by one */ 00153 for( i=(fi->scopes - 2); i>=0; i-- ) { 00154 fi->sls[i+1] = fi->sls[i]; 00155 } 00156 00157 /* Set the sls pointer to the head of the functional unit statement list */ 00158 fi->sls[0] = funit->stmt_head; 00159 00160 /* Increment the si_num */ 00161 (fi->sl_num)++; 00162 00163 /* Now sort the new statement iterator */ 00164 func_iter_sort( fi ); 00165 00166 /* Get the parent module */ 00167 parent = funit_get_curr_module( funit ); 00168 00169 /* Now traverse down all of the child functional units doing the same */ 00170 child = parent->tf_head; 00171 while( child != NULL ) { 00172 if( funit_is_unnamed( child->funit ) && (child->funit->parent == funit) ) { 00173 func_iter_add_stmt_links( fi, child->funit ); 00174 } 00175 child = child->next; 00176 } 00177 00178 PROFILE_END; 00179 00180 }
static int func_iter_count_scopes | ( | func_unit * | funit | ) | [static] |
funit | Pointer to current functional unit being examined |
References funit_link_s::funit, funit_get_curr_module(), funit_is_unnamed(), funit_link_s::next, func_unit_s::parent, PROFILE, PROFILE_END, and func_unit_s::tf_head.
Referenced by func_iter_init().
00114 { PROFILE(FUNC_ITER_COUNT_STMT_ITERS); 00115 00116 int count = 1; /* Number of statement iterators within this functional unit */ 00117 funit_link* child; /* Pointer to child functional unit */ 00118 func_unit* parent; /* Parent module of this functional unit */ 00119 00120 assert( funit != NULL ); 00121 00122 /* Get parent module */ 00123 parent = funit_get_curr_module( funit ); 00124 00125 /* Iterate through children functional units, counting all of the unnamed scopes */ 00126 child = parent->tf_head; 00127 while( child != NULL ) { 00128 if( funit_is_unnamed( child->funit ) && (child->funit->parent == funit) ) { 00129 count += func_iter_count_scopes( child->funit ); 00130 } 00131 child = child->next; 00132 } 00133 00134 PROFILE_END; 00135 00136 return( count ); 00137 00138 }
void func_iter_dealloc | ( | func_iter * | fi | ) |
Deallocates functional unit iterator.
Deallocates all allocated memory for the given functional unit iterator.
fi | Pointer to functional unit iterator to deallocate |
References free_safe, PROFILE, PROFILE_END, func_iter_s::scopes, func_iter_s::sigs, and func_iter_s::sls.
Referenced by combination_collect(), combination_display_verbose(), combination_get_stats(), exclude_is_assert_excluded(), exclude_is_comb_excluded(), exclude_is_line_excluded(), exclude_is_toggle_excluded(), exclude_set_assert_exclude(), exclude_set_comb_exclude(), exclude_set_line_exclude(), exclude_set_toggle_exclude(), line_collect(), line_display_verbose(), line_get_stats(), memory_collect(), memory_display_verbose(), memory_get_coverage(), memory_get_stats(), ovl_collect(), ovl_display_verbose(), ovl_get_coverage(), ovl_get_funit_stats(), rank_gather_comp_cdd_cov(), toggle_collect(), toggle_display_verbose(), toggle_get_coverage(), and toggle_get_stats().
00335 { PROFILE(FUNC_ITER_DEALLOC); 00336 00337 int i; /* Loop iterator */ 00338 00339 if( fi != NULL ) { 00340 00341 /* Deallocate statement iterators */ 00342 if( fi->sls != NULL ) { 00343 00344 /* Deallocate all statement iterators */ 00345 for( i=0; i<fi->scopes; i++ ) { 00346 free_safe( fi->sls[i], sizeof( stmt_link ) ); 00347 } 00348 00349 /* Deallocate array of statement iterators */ 00350 free_safe( fi->sls, (sizeof( stmt_link* ) * fi->scopes) ); 00351 00352 } 00353 00354 /* Deallocate signal array */ 00355 if( fi->sigs != NULL ) { 00356 00357 /* Deallocate array of signals */ 00358 free_safe( fi->sigs, (sizeof( sig_link* ) * fi->scopes) ); 00359 00360 } 00361 00362 } 00363 00364 PROFILE_END; 00365 00366 }
void func_iter_display | ( | func_iter * | fi | ) |
Displays the given function iterator to standard output.
fi | Pointer to functional unit iterator to display |
References vsignal_s::name, statement_s::ppline, PROFILE, PROFILE_END, func_iter_s::scopes, sig_link_s::sig, func_iter_s::sig_num, func_iter_s::sigs, func_iter_s::sl_num, func_iter_s::sls, and stmt_link_s::stmt.
00036 { PROFILE(FUNC_ITER_DISPLAY); 00037 00038 int i; /* Loop iterator */ 00039 00040 printf( "Functional unit iterator (scopes: %u):\n", fi->scopes ); 00041 00042 if( fi->sls != NULL ) { 00043 for( i=0; i<fi->sl_num; i++ ) { 00044 if( fi->sls[i] != NULL ) { 00045 printf( " Line: %u\n", fi->sls[i]->stmt->ppline ); 00046 } 00047 } 00048 } 00049 00050 if( fi->sigs != NULL ) { 00051 for( i=0; i<fi->sig_num; i++ ) { 00052 if( fi->sigs[i] != NULL ) { 00053 printf( " Name: %s\n", fi->sigs[i]->sig->name ); 00054 } 00055 } 00056 } 00057 00058 PROFILE_END; 00059 00060 }
Provides the next signal in the functional unit signal iterator.
fi | Pointer to functional unit iterator to use |
References func_iter_s::curr_sigl, sig_link_s::next, PROFILE, PROFILE_END, func_iter_s::scopes, sig_link_s::sig, func_iter_s::sig_num, and func_iter_s::sigs.
Referenced by exclude_is_toggle_excluded(), exclude_set_toggle_exclude(), memory_collect(), memory_display_verbose(), memory_get_coverage(), memory_get_stats(), toggle_collect(), toggle_display_verbose(), toggle_get_coverage(), and toggle_get_stats().
00297 { PROFILE(FUNC_ITER_GET_NEXT_SIGNAL); 00298 00299 vsignal* sig; 00300 00301 assert( fi != NULL ); 00302 00303 if( fi->curr_sigl != NULL ) { 00304 00305 sig = fi->curr_sigl->sig; 00306 fi->curr_sigl = fi->curr_sigl->next; 00307 00308 } else { 00309 00310 do { 00311 fi->sig_num++; 00312 } while( (fi->sig_num < fi->scopes) && (fi->sigs[fi->sig_num] == NULL) ); 00313 00314 if( fi->sig_num < fi->scopes ) { 00315 sig = fi->sigs[fi->sig_num]->sig; 00316 fi->curr_sigl = fi->sigs[fi->sig_num]->next; 00317 } else { 00318 sig = NULL; 00319 fi->curr_sigl = NULL; 00320 } 00321 00322 } 00323 00324 PROFILE_END; 00325 00326 return( sig ); 00327 00328 }
Provides the next statement iterator in the functional unit statement iterator.
fi | Pointer to functional unit iterator to use |
References func_iter_sort(), stmt_link_s::next, PROFILE, PROFILE_END, func_iter_s::sl_num, func_iter_s::sls, and stmt_link_s::stmt.
Referenced by combination_collect(), combination_display_verbose(), combination_get_stats(), exclude_is_assert_excluded(), exclude_is_comb_excluded(), exclude_is_line_excluded(), exclude_set_assert_exclude(), exclude_set_comb_exclude(), exclude_set_line_exclude(), line_collect(), line_display_verbose(), line_get_stats(), ovl_collect(), ovl_display_verbose(), ovl_get_coverage(), ovl_get_funit_stats(), and rank_gather_comp_cdd_cov().
00260 { PROFILE(FUNC_ITER_GET_NEXT_STATEMENT); 00261 00262 statement* stmt; /* Pointer to next statement in line order */ 00263 00264 assert( fi != NULL ); 00265 00266 if( fi->sl_num == 0 ) { 00267 00268 stmt = NULL; 00269 00270 } else { 00271 00272 assert( fi->sls[0] != NULL ); 00273 00274 /* Get the statement at the head of the sorted list */ 00275 stmt = fi->sls[0]->stmt; 00276 00277 /* Go to the next statement in the current statement list */ 00278 fi->sls[0] = fi->sls[0]->next; 00279 00280 /* Resort */ 00281 func_iter_sort( fi ); 00282 00283 } 00284 00285 PROFILE_END; 00286 00287 return( stmt ); 00288 00289 }
Initializes the values in the given structure.
Initializes the contents of the functional unit iterator structure. This should be called before the functional unit iterator structure is populated with either statement iterator or signal information.
fi | Pointer to functional unit iterator to initializes | |
funit | Pointer to main functional unit to create iterator for (must be named) | |
stmts | Set to TRUE if we want statements to be included in the iterator | |
sigs | Set to TRUE if we want signals to be included in the iterator |
References func_iter_s::curr_sigl, func_iter_add_sig_links(), func_iter_add_stmt_links(), func_iter_count_scopes(), malloc_safe, PROFILE, PROFILE_END, func_iter_s::scopes, func_iter_s::sig_num, func_iter_s::sigs, func_iter_s::sl_num, and func_iter_s::sls.
Referenced by combination_collect(), combination_display_verbose(), combination_get_stats(), exclude_is_assert_excluded(), exclude_is_comb_excluded(), exclude_is_line_excluded(), exclude_is_toggle_excluded(), exclude_set_assert_exclude(), exclude_set_comb_exclude(), exclude_set_line_exclude(), exclude_set_toggle_exclude(), line_collect(), line_display_verbose(), line_get_stats(), memory_collect(), memory_display_verbose(), memory_get_coverage(), memory_get_stats(), ovl_collect(), ovl_display_verbose(), ovl_get_coverage(), ovl_get_funit_stats(), rank_gather_comp_cdd_cov(), toggle_collect(), toggle_display_verbose(), toggle_get_coverage(), and toggle_get_stats().
00223 { PROFILE(FUNC_ITER_INIT); 00224 00225 assert( fi != NULL ); 00226 assert( funit != NULL ); 00227 00228 /* Count the number of scopes that are within the functional unit iterator */ 00229 fi->scopes = func_iter_count_scopes( funit ); 00230 fi->sls = NULL; 00231 fi->sigs = NULL; 00232 fi->sig_num = 0; 00233 00234 /* Add statement iterators */ 00235 if( stmts ) { 00236 fi->sls = (stmt_link**)malloc_safe( sizeof( stmt_link* ) * fi->scopes ); 00237 fi->sl_num = 0; 00238 func_iter_add_stmt_links( fi, funit ); 00239 } 00240 00241 /* Add signal lists */ 00242 if( sigs ) { 00243 fi->sigs = (sig_link**)malloc_safe( sizeof( sig_link* ) * fi->scopes ); 00244 fi->sig_num = 0; 00245 func_iter_add_sig_links( fi, funit ); 00246 fi->sig_num = 0; 00247 fi->curr_sigl = fi->sigs[0]; 00248 } 00249 00250 PROFILE_END; 00251 00252 }
static void func_iter_sort | ( | func_iter * | fi | ) | [static] |
Performs a bubble sort of the first element such that the first line is in location 0 of the sis array.
fi | Pointer to functional unit iterator to sort |
References expression_s::col, statement_s::exp, expression_s::part, statement_s::ppline, PROFILE, PROFILE_END, func_iter_s::sl_num, func_iter_s::sls, and stmt_link_s::stmt.
Referenced by func_iter_add_stmt_links(), and func_iter_get_next_statement().
00067 { PROFILE(FUNC_ITER_SORT); 00068 00069 stmt_link* tmp; /* Temporary statement iterator */ 00070 int i; /* Loop iterator */ 00071 00072 assert( fi != NULL ); 00073 assert( fi->sl_num > 0 ); 00074 00075 tmp = fi->sls[0]; 00076 00077 /* 00078 If the statement iterator at the top of the list is NULL, shift all valid statement iterators 00079 towards the top and store this statement iterator after them 00080 */ 00081 if( tmp == NULL ) { 00082 00083 for( i=0; i<(fi->sl_num - 1); i++ ) { 00084 fi->sls[i] = fi->sls[i+1]; 00085 } 00086 fi->sls[i] = tmp; 00087 (fi->sl_num)--; 00088 00089 /* Otherwise, re-sort them based on line number */ 00090 } else { 00091 00092 i = 0; 00093 while( (i < (fi->sl_num - 1)) && 00094 ((tmp->stmt->ppline > fi->sls[i+1]->stmt->ppline) || 00095 ((tmp->stmt->ppline == fi->sls[i+1]->stmt->ppline) && 00096 (tmp->stmt->exp->col.part.last > fi->sls[i+1]->stmt->exp->col.part.last))) ) { 00097 fi->sls[i] = fi->sls[i+1]; 00098 i++; 00099 } 00100 fi->sls[i] = tmp; 00101 00102 } 00103 00104 PROFILE_END; 00105 00106 }