Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

/Users/trevorw/projects/release/covered-0.7.4/src/func_iter.c File Reference


Detailed Description

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
4/2/2007

#include <stdlib.h>
#include <assert.h>
#include "defines.h"
#include "func_iter.h"
#include "func_unit.h"
#include "iter.h"
#include "util.h"

Functions

void func_iter_display (func_iter *fi)
void func_iter_sort (func_iter *fi)
int func_iter_count_scopes (func_unit *funit)
void func_iter_add_stmt_iters (func_iter *fi, func_unit *funit)
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.

statementfunc_iter_get_next_statement (func_iter *fi)
 Provides the next statement iterator in the functional unit statement iterator.

vsignalfunc_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.


Function Documentation

void func_iter_add_sig_links func_iter fi,
func_unit funit
[static]
 

Recursively iterates through the functional units, adding their signal link pointers to the func_iter structure's array.

Parameters:
fi  Pointer to functional unit iterator to populate
funit  Pointer to current functional unit

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 }

void func_iter_add_stmt_iters func_iter fi,
func_unit funit
[static]
 

Recursively iterates through functional units, adding their statement iterators to the func_iter structure's array.

Parameters:
fi  Pointer to functional unit iterator to populate
funit  Pointer to current functional unit

00144   { PROFILE(FUNC_ITER_ADD_STMT_ITERS);
00145 
00146   funit_link* child;   /* Pointer to child functional unit */
00147   func_unit*  parent;  /* Pointer to parent module of this functional unit */
00148   int         i;       /* Loop iterator */
00149 
00150   /* First, shift all current statement iterators down by one */
00151   for( i=(fi->scopes - 2); i>=0; i-- ) {
00152     fi->sis[i+1] = fi->sis[i];
00153   }
00154 
00155   /* Now allocate a new statement iterator at position 0 and point it at the current functional unit statement list */
00156   fi->sis[0] = (stmt_iter*)malloc_safe( sizeof( stmt_iter ) );
00157   stmt_iter_reset( fi->sis[0], funit->stmt_tail );
00158   stmt_iter_find_head( fi->sis[0], FALSE );
00159 
00160   /* Increment the si_num */
00161   (fi->si_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_iters( fi, child->funit );
00174     }
00175     child = child->next;
00176   }
00177 
00178   PROFILE_END;
00179 
00180 }

int func_iter_count_scopes func_unit funit  )  [static]
 

Returns:
Returns the number of statement iterators found in all of the unnamed functional units within a named functional unit.
Parameters:
funit  Pointer to current functional unit being examined

00112   { PROFILE(FUNC_ITER_COUNT_STMT_ITERS);
00113 
00114   int         count = 1;  /* Number of statement iterators within this functional unit */
00115   funit_link* child;      /* Pointer to child functional unit */
00116   func_unit*  parent;     /* Parent module of this functional unit */
00117 
00118   assert( funit != NULL );
00119 
00120   /* Get parent module */
00121   parent = funit_get_curr_module( funit );
00122 
00123   /* Iterate through children functional units, counting all of the unnamed scopes */
00124   child = parent->tf_head;
00125   while( child != NULL ) {
00126     if( funit_is_unnamed( child->funit ) && (child->funit->parent == funit) ) {
00127       count += func_iter_count_scopes( child->funit );
00128     }
00129     child = child->next;
00130   }
00131 
00132   PROFILE_END;
00133 
00134   return( count );
00135 
00136 }

void func_iter_dealloc func_iter fi  ) 
 

Deallocates functional unit iterator.

Deallocates all allocated memory for the given functional unit iterator.

Parameters:
fi  Pointer to functional unit iterator to deallocate

00335   { PROFILE(FUNC_ITER_DEALLOC);
00336 
00337   int i;  /* Loop iterator */
00338   
00339   if( fi != NULL ) {
00340 
00341     /* Deallocate statement iterators */
00342     if( fi->sis != NULL ) {
00343 
00344       /* Deallocate all statement iterators */
00345       for( i=0; i<fi->scopes; i++ ) {
00346         free_safe( fi->sis[i], sizeof( stmt_iter ) );
00347       }
00348 
00349       /* Deallocate array of statement iterators */
00350       free_safe( fi->sis, (sizeof( stmt_iter* ) * 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.

Parameters:
fi  Pointer to functional unit iterator to display

00037   { PROFILE(FUNC_ITER_DISPLAY);
00038 
00039   int i;  /* Loop iterator */
00040 
00041   printf( "Functional unit iterator (scopes: %u):\n", fi->scopes );
00042 
00043   if( fi->sis != NULL ) {
00044     for( i=0; i<fi->si_num; i++ ) {
00045       if( fi->sis[i] != NULL ) {
00046         printf( "  Line: %u\n", fi->sis[i]->curr->stmt->ppline );
00047       }
00048     }
00049   }
00050 
00051   if( fi->sigs != NULL ) {
00052     for( i=0; i<fi->sig_num; i++ ) {
00053       if( fi->sigs[i] != NULL ) {
00054         printf( "  Name: %s\n", fi->sigs[i]->sig->name );
00055       }
00056     }
00057   }
00058 
00059   PROFILE_END;
00060 
00061 }

vsignal* func_iter_get_next_signal func_iter fi  ) 
 

Provides the next signal in the functional unit signal iterator.

Returns:
Returns pointer to next signal in order (or NULL if there are no more signals in the given functional unit)
Parameters:
fi  Pointer to functional unit iterator to use

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 }

statement* func_iter_get_next_statement func_iter fi  ) 
 

Provides the next statement iterator in the functional unit statement iterator.

Returns:
Returns pointer to next statement in line order (or NULL if there are no more statements in the given functional unit)
Parameters:
fi  Pointer to functional unit iterator to use

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->si_num == 0 ) {
00267 
00268     stmt = NULL;
00269 
00270   } else {
00271 
00272     assert( fi->sis[0]->curr != NULL );
00273 
00274     /* Get the statement at the head of the sorted list */
00275     stmt = fi->sis[0]->curr->stmt;
00276 
00277     /* Go to the next statement in the current statement list */
00278     stmt_iter_get_next_in_order( fi->sis[0] );
00279 
00280     /* Resort */
00281     func_iter_sort( fi );
00282 
00283   }
00284 
00285   PROFILE_END;
00286 
00287   return( stmt );
00288 
00289 }

void func_iter_init func_iter fi,
func_unit funit,
bool  stmts,
bool  sigs
 

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.

Parameters:
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

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->sis     = NULL;
00231   fi->sigs    = NULL;
00232   fi->sig_num = 0;
00233 
00234   /* Add statement iterators */
00235   if( stmts ) {
00236     fi->sis    = (stmt_iter**)malloc_safe( sizeof( stmt_iter* ) * fi->scopes );
00237     fi->si_num = 0;
00238     func_iter_add_stmt_iters( 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 }

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.

Parameters:
fi  Pointer to functional unit iterator to sort

00068   { PROFILE(FUNC_ITER_SORT);
00069 
00070   stmt_iter* tmp;  /* Temporary statement iterator */
00071   int        i;    /* Loop iterator */
00072 
00073   assert( fi != NULL );
00074   assert( fi->si_num > 0 );
00075 
00076   tmp = fi->sis[0];
00077 
00078   /*
00079    If the statement iterator at the top of the list is NULL, shift all valid statement iterators
00080    towards the top and store this statement iterator after them 
00081   */
00082   if( tmp->curr == NULL ) {
00083 
00084     for( i=0; i<(fi->si_num - 1); i++ ) {
00085       fi->sis[i] = fi->sis[i+1];
00086     }
00087     fi->sis[i] = tmp;
00088     (fi->si_num)--;
00089 
00090   /* Otherwise, re-sort them based on line number */
00091   } else {
00092 
00093     i = 0;
00094     while( (i < (fi->si_num - 1)) && (tmp->curr->stmt->ppline > fi->sis[i+1]->curr->stmt->ppline) ) {
00095       fi->sis[i] = fi->sis[i+1];
00096       i++;
00097     }
00098     fi->sis[i] = tmp;
00099 
00100   }
00101 
00102   PROFILE_END;
00103 
00104 }


Generated on Wed Jun 17 22:19:22 2009 for Covered by doxygen 1.3.4