arc.h File Reference

Contains functions for handling FSM arc arrays. More...

#include <stdio.h>
#include "defines.h"

Go to the source code of this file.

Functions

fsm_tablearc_create ()
 Allocates and initializes new state transition array.
void arc_add (fsm_table *table, const vector *fr_st, const vector *to_st, int hit, bool exclude)
 Adds new state transition arc entry to specified table.
int arc_find_from_state (const fsm_table *table, const vector *st)
 Finds the specified FROM state in the given FSM table.
int arc_find_to_state (const fsm_table *table, const vector *st)
 Finds the specified TO state in the given FSM table.
int arc_find_arc (const fsm_table *table, unsigned int fr_index, unsigned int to_index)
 Finds the specified state transition in the given FSM table.
int arc_find_arc_by_exclusion_id (const fsm_table *table, int id)
 Finds the specified state transition in the given FSM table by the exclusion ID.
void arc_get_stats (const fsm_table *table, int *state_hits, int *state_total, int *arc_hits, int *arc_total, int *arc_excluded)
 Calculates all state and state transition values for reporting purposes.
void arc_db_write (const fsm_table *table, FILE *file)
 Writes specified arc array to specified CDD file.
void arc_db_read (fsm_table **table, char **line)
 Reads in arc array from CDD database string.
void arc_db_merge (fsm_table *table, char **line)
 Merges contents of arc table from line to specified base array.
void arc_merge (fsm_table *base, const fsm_table *other)
 Merges two FSM arcs, placing the results in the base arc.
void arc_get_states (char ***fr_states, unsigned int *fr_state_size, char ***to_states, unsigned int *to_state_size, const fsm_table *table, bool hit, bool any, unsigned int fr_width, unsigned int to_width)
 Stores arc array state values to specified string array.
void arc_get_transitions (char ***from_states, char ***to_states, int **ids, int **excludes, char ***reasons, int *arc_size, const fsm_table *table, func_unit *funit, bool hit, bool any, unsigned int fr_width, unsigned int to_width)
 Outputs arc array state transition values to specified output stream.
bool arc_are_any_excluded (const fsm_table *table)
 Specifies if any state transitions have been excluded from coverage.
void arc_dealloc (fsm_table *table)
 Deallocates memory for specified arcs array.

Detailed Description

Contains functions for handling FSM arc arrays.

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
8/25/2003

Function Documentation

void arc_add ( fsm_table table,
const vector fr_st,
const vector to_st,
int  hit,
bool  exclude 
)

Adds new state transition arc entry to specified table.

If specified arcs array has not been created yet (value is set to NULL), allocate enough memory in the arc array to hold width number of state transitions. If the specified arcs array has been created but is currently full (arc array max_size and curr_size are equal to each other), add width number of more arc array entries to the current array. After memory has been allocated, create a state transition entry from the fr_st and to_st expressions, setting the hit bits in the entry to 0.

Parameters:
table Pointer to FSM table to add state transition arc array to
fr_st Pointer to vector containing the from state
to_st Pointer to vector containing the to state
hit Specifies if arc entry should be marked as hit
exclude If new arc is created, sets the exclude bit to this value

References asuppl_u::all, arc_find_arc(), arc_find_from_state(), arc_find_to_state(), fsm_table_s::arcs, vsuppl_u::data_type, asuppl_u::excluded, fsm_table_s::fr_states, fsm_table_arc_s::from, asuppl_u::hit, fsuppl_u::known, malloc_safe, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsm_table_s::num_to_states, fsuppl_u::part, asuppl_u::part, vsuppl_u::part, PROFILE, PROFILE_END, realloc_safe, fsm_table_s::suppl, fsm_table_arc_s::suppl, vector_s::suppl, fsm_table_arc_s::to, fsm_table_s::to_states, TRUE, vector_copy(), vector_create(), vector_is_unknown(), VTYPE_VAL, and vector_s::width.

Referenced by arc_db_merge(), arc_merge(), fsm_create_tables(), and fsm_table_set().

00331   { PROFILE(ARC_ADD);
00332 
00333   int from_index;  /* Index of found from_state in states array */
00334   int to_index;    /* Index of found to_state in states array */
00335   int arcs_index;  /* Index of found state transition in arcs array */
00336 
00337   assert( table != NULL );
00338 
00339   if( (hit == 0) || (!vector_is_unknown( fr_st ) && !vector_is_unknown( to_st )) ) {
00340 
00341     /* Search for the from_state vector in the states array */
00342     if( (from_index = arc_find_from_state( table, fr_st )) == -1 ) {
00343       table->fr_states = (vector**)realloc_safe( table->fr_states, (sizeof( vector* ) * table->num_fr_states), (sizeof( vector* ) * (table->num_fr_states + 1)) );
00344       from_index    = table->num_fr_states;
00345       table->fr_states[from_index] = vector_create( fr_st->width, VTYPE_VAL, fr_st->suppl.part.data_type, TRUE );
00346       vector_copy( fr_st, table->fr_states[from_index] );
00347       table->num_fr_states++;
00348     }
00349 
00350     /* Search for the to_state vector in the states array */
00351     if( (to_index = arc_find_to_state( table, to_st )) == -1 ) {
00352       table->to_states = (vector**)realloc_safe( table->to_states, (sizeof( vector* ) * table->num_to_states), (sizeof( vector* ) * (table->num_to_states + 1)) );
00353       to_index      = table->num_to_states;
00354       table->to_states[to_index] = vector_create( to_st->width, VTYPE_VAL, to_st->suppl.part.data_type, TRUE );
00355       vector_copy( to_st, table->to_states[to_index] );
00356       table->num_to_states++;
00357     }
00358 
00359     /* If we need to add a new arc, do so now */
00360     if( (arcs_index = arc_find_arc( table, from_index, to_index )) == -1 ) {
00361 
00362       table->arcs = (fsm_table_arc**)realloc_safe( table->arcs, (sizeof( fsm_table_arc* ) * table->num_arcs), (sizeof( fsm_table_arc* ) * (table->num_arcs + 1)) );
00363       table->arcs[table->num_arcs] = (fsm_table_arc*)malloc_safe( sizeof( fsm_table_arc ) );
00364       table->arcs[table->num_arcs]->suppl.all           = 0;
00365       table->arcs[table->num_arcs]->suppl.part.hit      = hit;
00366       table->arcs[table->num_arcs]->suppl.part.excluded = exclude;
00367       table->arcs[table->num_arcs]->from                = from_index;
00368       table->arcs[table->num_arcs]->to                  = to_index;
00369       table->num_arcs++;
00370 
00371     /* Otherwise, adjust hit and exclude information */
00372     } else {
00373 
00374       table->arcs[arcs_index]->suppl.part.hit      |= hit;
00375       table->arcs[arcs_index]->suppl.part.excluded |= exclude;
00376 
00377     }
00378 
00379     /* If we have set a side with hit equal to 0, we are specifying a known transition. */
00380     if( hit == 0 ) {
00381       table->suppl.part.known = 1;
00382     }
00383 
00384   }
00385 
00386   PROFILE_END;
00387 
00388 }

bool arc_are_any_excluded ( const fsm_table table  ) 

Specifies if any state transitions have been excluded from coverage.

Returns:
Returns TRUE if any state transitions were excluded from coverage; otherwise, returns FALSE.
Parameters:
table Pointer to state transition arc array

References fsm_table_s::arcs, asuppl_u::excluded, asuppl_u::part, PROFILE, PROFILE_END, and fsm_table_arc_s::suppl.

Referenced by fsm_collect().

00848   { PROFILE(ARC_ARE_ANY_EXCLUDED);
00849 
00850   unsigned int i = 0;  /* Loop iterator */
00851 
00852   assert( table != NULL );
00853 
00854   while( (i < table->num_arcs) && (table->arcs[i]->suppl.part.excluded == 0) ) i++;
00855 
00856   PROFILE_END;
00857 
00858   return( i < table->num_arcs );
00859 
00860 }

fsm_table* arc_create (  ) 

Allocates and initializes new state transition array.

Returns:
Returns a pointer to the newly created arc transition structure.

Allocates memory for a new state transition arc array and initializes its contents.

References fsuppl_u::all, fsm_table_s::arcs, fsm_table_s::fr_states, fsm_table_s::id, malloc_safe, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsm_table_s::num_to_states, PROFILE, PROFILE_END, fsm_table_s::suppl, and fsm_table_s::to_states.

Referenced by arc_db_read(), and fsm_create_tables().

00293                         { PROFILE(ARC_CREATE);
00294 
00295   fsm_table* table;  /* Pointer to newly created FSM table */
00296 
00297   /* Allocate memory for the new table here */
00298   table = (fsm_table*)malloc_safe( sizeof( fsm_table ) );
00299 
00300   /* Initialize */
00301   table->suppl.all     = 0;
00302   table->id            = 0;
00303   table->fr_states     = NULL;
00304   table->num_fr_states = 0;
00305   table->to_states     = NULL;
00306   table->num_to_states = 0;
00307   table->arcs          = NULL;
00308   table->num_arcs      = 0;
00309 
00310   PROFILE_END;
00311 
00312   return( table );
00313 
00314 }

void arc_db_merge ( fsm_table base,
char **  line 
)

Merges contents of arc table from line to specified base array.

Exceptions:
anonymous Throw arc_db_read

Merges the specified FSM arc information from the current line into the base FSM arc information.

Parameters:
base Pointer to arc table to merge data into
line Pointer to read in line from CDD file to merge

References arc_add(), arc_db_read(), arc_dealloc(), fsm_table_s::arcs, asuppl_u::excluded, fsm_table_s::fr_states, fsm_table_arc_s::from, asuppl_u::hit, fsm_table_s::num_arcs, asuppl_u::part, PROFILE, PROFILE_END, fsm_table_arc_s::suppl, fsm_table_arc_s::to, and fsm_table_s::to_states.

Referenced by fsm_db_merge().

00668   { PROFILE(ARC_DB_MERGE);
00669 
00670   /*@-mustfreeonly -mustfreefresh@*/
00671 
00672   fsm_table*   table;  /* Currently read FSM table */
00673   unsigned int i;      /* Loop iterator */
00674 
00675   /* Read in the table */
00676   arc_db_read( &table, line );
00677 
00678   /* Merge state transitions */
00679   for( i=0; i<table->num_arcs; i++ ) {
00680     arc_add( base, table->fr_states[table->arcs[i]->from], table->to_states[table->arcs[i]->to], table->arcs[i]->suppl.part.hit, table->arcs[i]->suppl.part.excluded );
00681   }
00682 
00683   /* Deallocate the merged table */
00684   arc_dealloc( table );
00685 
00686   PROFILE_END;
00687 
00688   /*@=mustfreeonly =mustfreefresh@*/
00689 
00690 }

void arc_db_read ( fsm_table **  table,
char **  line 
)

Reads in arc array from CDD database string.

Exceptions:
anonymous Throw

Reads in specified state transition arc table, allocating the appropriate space to hold the table. Returns TRUE if the specified line contained an appropriately written arc transition table; otherwise, returns FALSE.

Parameters:
table Pointer to state transition arc array
line String containing current CDD line of arc information

References arc_create(), arc_dealloc(), Catch_anonymous, curr_arc_id, FATAL, malloc_safe, print_output(), PROFILE, PROFILE_END, Throw, Try, and vector_db_read().

Referenced by arc_db_merge(), and fsm_db_read().

00565   { PROFILE(ARC_DB_READ);
00566 
00567   /* Allocate table */
00568   *table = arc_create();
00569 
00570   Try {
00571 
00572     unsigned int num_fr_states;
00573     unsigned int num_to_states;
00574     int          chars_read;
00575 
00576     /*@-formatcode@*/
00577     if( sscanf( *line, "%hhx %u %u%n", &((*table)->suppl.all), &num_fr_states, &num_to_states, &chars_read ) == 3 ) {
00578     /*@=formatcode@*/
00579 
00580       unsigned int i;
00581       unsigned int num_arcs;
00582 
00583       *line += chars_read;
00584 
00585       /* Set exclusion ID */
00586       (*table)->id = curr_arc_id;
00587 
00588       /* Allocate and initialize fr_states array */
00589       (*table)->fr_states     = (vector**)malloc_safe( sizeof( vector* ) * num_fr_states );
00590       (*table)->num_fr_states = num_fr_states;
00591       for( i=0; i<num_fr_states; i++ ) {
00592         (*table)->fr_states[i] = NULL;
00593       }
00594 
00595       /* Read in from vectors */
00596       for( i=0; i<num_fr_states; i++ ) {
00597         vector_db_read( &((*table)->fr_states[i]), line );
00598       }
00599 
00600       /* Allocate and initialize to_states array */
00601       (*table)->to_states     = (vector**)malloc_safe( sizeof( vector* ) * num_to_states );
00602       (*table)->num_to_states = num_to_states;
00603       for( i=0; i<num_to_states; i++ ) {
00604         (*table)->to_states[i] = NULL;
00605       }
00606 
00607       /* Read in vectors */
00608       for( i=0; i<num_to_states; i++ ) {
00609         vector_db_read( &((*table)->to_states[i]), line );
00610       }
00611 
00612       if( sscanf( *line, "%u%n", &num_arcs, &chars_read ) == 1 ) {
00613 
00614         *line += chars_read;
00615 
00616         /* Allocate arcs array */
00617         (*table)->arcs     = (fsm_table_arc**)malloc_safe( sizeof( fsm_table_arc* ) * num_arcs );
00618         (*table)->num_arcs = num_arcs;
00619         for( i=0; i<num_arcs; i++ ) {
00620           (*table)->arcs[i] = NULL;
00621         }
00622 
00623         for( i=0; i<num_arcs; i++ ) {
00624 
00625           /* Allocate fsm_table_arc */
00626           (*table)->arcs[i] = (fsm_table_arc*)malloc_safe( sizeof( fsm_table_arc ) );
00627 
00628           /*@-formatcode@*/
00629           if( sscanf( *line, "%u %u %hhx%n", &((*table)->arcs[i]->from), &((*table)->arcs[i]->to), &((*table)->arcs[i]->suppl.all), &chars_read ) != 3 ) {
00630           /*@=formatcode@*/
00631             print_output( "Unable to parse FSM table information from database.  Unable to read.", FATAL, __FILE__, __LINE__ );
00632             Throw 0;
00633           } else {
00634             *line += chars_read;
00635             curr_arc_id++;
00636           }
00637 
00638         }
00639 
00640       } else {
00641         print_output( "Unable to parse FSM table information from database.  Unable to read.", FATAL, __FILE__, __LINE__ );
00642         Throw 0;
00643       }
00644 
00645     } else {
00646       print_output( "Unable to parse FSM table information from database.  Unable to read.", FATAL, __FILE__, __LINE__ );
00647       Throw 0;
00648     }
00649 
00650   } Catch_anonymous {
00651     arc_dealloc( *table );
00652     *table = NULL;
00653     Throw 0;
00654   }
00655 
00656   PROFILE_END;
00657 
00658 }

void arc_db_write ( const fsm_table table,
FILE *  file 
)

Writes specified arc array to specified CDD file.

Writes the specified arcs array to the specified CDD output file. An arc array is output in a special format that is described in the above documentation for this file.

Parameters:
table Pointer to state transition arc array to write
file Pointer to CDD file to write

References asuppl_u::all, fsuppl_u::all, fsm_table_s::arcs, FALSE, fsm_table_s::fr_states, fsm_table_arc_s::from, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsm_table_s::num_to_states, PROFILE, PROFILE_END, fsm_table_arc_s::suppl, fsm_table_s::suppl, fsm_table_arc_s::to, fsm_table_s::to_states, TRUE, and vector_db_write().

Referenced by fsm_db_write().

00523   { PROFILE(ARC_DB_WRITE);
00524 
00525   unsigned int  i;   /* Loop iterator */
00526 
00527   assert( table != NULL );
00528 
00529   /*@-formatcode@*/
00530   fprintf( file, " %hhx %u %u ", table->suppl.all, table->num_fr_states, table->num_to_states );
00531   /*@=formatcode@*/
00532 
00533   /* Output state information */
00534   for( i=0; i<table->num_fr_states; i++ ) {
00535     vector_db_write( table->fr_states[i], file, TRUE, FALSE );
00536     fprintf( file, "  " );
00537   }
00538   for( i=0; i<table->num_to_states; i++ ) {
00539     vector_db_write( table->to_states[i], file, TRUE, FALSE );
00540     fprintf( file, "  " );
00541   }
00542 
00543   /* Output arc information */
00544   fprintf( file, " %u", table->num_arcs );
00545   for( i=0; i<table->num_arcs; i++ ) {
00546     /*@-formatcode@*/
00547     fprintf( file, "  %u %u %hhx", table->arcs[i]->from, table->arcs[i]->to, table->arcs[i]->suppl.all );
00548     /*@=formatcode@*/
00549   }
00550 
00551   PROFILE_END;
00552 
00553 }

void arc_dealloc ( fsm_table table  ) 

Deallocates memory for specified arcs array.

Deallocates all allocated memory for the specified state transition arc array.

Parameters:
table Pointer to state transition arc array

References fsm_table_s::arcs, fsm_table_s::fr_states, free_safe, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsm_table_s::num_to_states, PROFILE, PROFILE_END, fsm_table_s::to_states, and vector_dealloc().

Referenced by arc_db_merge(), arc_db_read(), fsm_db_write(), and fsm_dealloc().

00868   { PROFILE(ARC_DEALLOC);
00869 
00870   if( table != NULL ) {
00871 
00872     unsigned int i;
00873 
00874     /* Deallocate fr_states */
00875     for( i=0; i<table->num_fr_states; i++ ) {
00876       vector_dealloc( table->fr_states[i] );
00877     }
00878     free_safe( table->fr_states, (sizeof( vector* ) * table->num_fr_states) );
00879 
00880     /* Deallocate to_states */
00881     for( i=0; i<table->num_to_states; i++ ) {
00882       vector_dealloc( table->to_states[i] );
00883     }
00884     free_safe( table->to_states, (sizeof( vector* ) * table->num_to_states) );
00885 
00886     /* Deallocate arcs */
00887     for( i=0; i<table->num_arcs; i++ ) {
00888       free_safe( table->arcs[i], sizeof( fsm_table_arc ) );
00889     }
00890     free_safe( table->arcs, (sizeof( fsm_table_arc* ) * table->num_arcs) );
00891 
00892     /* Now deallocate ourself */
00893     free_safe( table, sizeof( fsm_table ) );
00894 
00895   }
00896 
00897   PROFILE_END;
00898 
00899 }

int arc_find_arc ( const fsm_table table,
unsigned int  fr_index,
unsigned int  to_index 
)

Finds the specified state transition in the given FSM table.

Returns:
Returns the index of the found arc in the arcs array if it is found; otherwise, returns -1.

Searches for the arc in the arcs array of the given FSM table specified by the given state indices.

Parameters:
table Pointer to FSM table to search in
fr_index Index of from state to find
to_index Index of to state to find

References fsm_table_s::arcs, fsm_table_arc_s::from, PROFILE, PROFILE_END, and fsm_table_arc_s::to.

Referenced by arc_add(), exclude_is_fsm_excluded(), and exclude_set_fsm_exclude().

00249   { PROFILE(ARC_FIND_ARC);
00250 
00251   int          index = -1;
00252   unsigned int i     = 0;
00253 
00254   while( (i < table->num_arcs) && (index == -1) ) {
00255     if( (table->arcs[i]->from == fr_index) && (table->arcs[i]->to == to_index) ) {
00256       index = i;
00257     }
00258     i++;
00259   }
00260 
00261   PROFILE_END;
00262 
00263   return( index );
00264 
00265 }

int arc_find_arc_by_exclusion_id ( const fsm_table table,
int  id 
)

Finds the specified state transition in the given FSM table by the exclusion ID.

Returns:
Returns the index of the found arc in the arcs array if it is found; otherwise, returns -1.
Parameters:
table Pointer to FSM table structure to search
id Exclusion ID to search for

References fsm_table_s::id, fsm_table_s::num_arcs, PROFILE, and PROFILE_END.

Referenced by instance_find_fsm_arc_index_by_exclusion_id().

00273   { PROFILE(ARC_FIND_ARC_BY_EXCLUSION_ID);
00274 
00275   int index = -1;
00276 
00277   if( (table->id <= id) && ((table->id + table->num_arcs) > id) ) {
00278     index = id - table->id;
00279   }
00280 
00281   PROFILE_END;
00282 
00283   return( index );
00284 
00285 }

int arc_find_from_state ( const fsm_table table,
const vector st 
)

Finds the specified FROM state in the given FSM table.

Returns:
Returns the index of the found from_state in the fr_states array if one is found; otherwise, returns -1 to indicate that a match could not be found.

Searches the list of FROM states for a match to the given vector value.

Parameters:
table Pointer to FSM table to search in
st State to search for

References fsm_table_s::fr_states, PROFILE, PROFILE_END, and vector_ceq_ulong().

Referenced by arc_add(), exclude_is_fsm_excluded(), and exclude_set_fsm_exclude().

00194   { PROFILE(ARC_FIND_FROM_STATE);
00195 
00196   int          index = -1;  /* Return value for this function */
00197   unsigned int i     = 0;   /* Loop iterator */
00198 
00199   assert( table != NULL );
00200 
00201   while( (i < table->num_fr_states) && !vector_ceq_ulong( st, table->fr_states[i] ) ) i++;
00202   if( i < table->num_fr_states ) {
00203     index = i;
00204   }
00205 
00206   PROFILE_END;
00207 
00208   return( index );
00209 
00210 }

int arc_find_to_state ( const fsm_table table,
const vector st 
)

Finds the specified TO state in the given FSM table.

Returns:
Returns the index of the found to_state in the to_states array if one is found; otherwise, returns -1 to indicate that a match could not be found. that no match occurred.

Searches the list of TO states for a match to the given vector value.

Parameters:
table Pointer to FSM table to search in
st State to search for

References PROFILE, PROFILE_END, fsm_table_s::to_states, and vector_ceq_ulong().

Referenced by arc_add(), exclude_is_fsm_excluded(), and exclude_set_fsm_exclude().

00222   { PROFILE(ARC_FIND_TO_STATE);
00223 
00224   int          index = -1;  /* Return value for this function */
00225   unsigned int i     = 0;   /* Loop iterator */
00226 
00227   assert( table != NULL );
00228 
00229   while( (i < table->num_to_states) && !vector_ceq_ulong( st, table->to_states[i] ) ) i++;
00230   if( i < table->num_to_states ) {
00231     index = i;
00232   }
00233 
00234   PROFILE_END;
00235 
00236   return( index );
00237 
00238 }

void arc_get_states ( char ***  fr_states,
unsigned int *  fr_state_size,
char ***  to_states,
unsigned int *  to_state_size,
const fsm_table table,
bool  hit,
bool  any,
unsigned int  fr_width,
unsigned int  to_width 
)

Stores arc array state values to specified string array.

Traverses entire arc array, storing all states that were hit during simulation (if hit parameter is true or the any parameter is true) or missed during simulation (if hit parameter is false or the any parameter is true).

Parameters:
fr_states Pointer to string array containing stringified state information
fr_state_size Pointer to number of elements stored in states array
to_states Pointer to string array containing stringified state information
to_state_size Pointer to number of elements stored in states array
table Pointer to FSM table
hit Specifies if hit or missed transitions should be gathered
any Specifies if we should gather any transition or only the type specified by hit
fr_width Width of "from" FSM state to output
to_width Width of "to" FSM state to output

References fsm_table_s::arcs, fsm_table_s::fr_states, fsm_table_arc_s::from, HEXIDECIMAL, asuppl_u::hit, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsm_table_s::num_to_states, asuppl_u::part, PROFILE, PROFILE_END, realloc_safe, fsm_table_arc_s::suppl, fsm_table_arc_s::to, fsm_table_s::to_states, TRUE, and vector_to_string().

Referenced by fsm_display_state_verbose(), and fsm_get_coverage().

00727   { PROFILE(ARC_GET_STATES);
00728 
00729   unsigned int i, j;  /* Loop iterator */
00730 
00731   /*@-nullstate@*/
00732 
00733   assert( fr_states != NULL );
00734   assert( fr_state_size != NULL );
00735   assert( to_states != NULL );
00736   assert( to_state_size != NULL );
00737 
00738   /* Initialize states array pointers and sizes */
00739   *fr_states     = NULL;
00740   *fr_state_size = 0;
00741   *to_states     = NULL;
00742   *to_state_size = 0;
00743 
00744   /* Iterate through the fr_states array, gathering all matching states */
00745   for( i=0; i<table->num_fr_states; i++ ) {
00746     bool state_hit = any;
00747     for( j=0; j<table->num_arcs; j++ ) {
00748       if( table->arcs[j]->from == i ) {
00749         state_hit = state_hit || (table->arcs[j]->suppl.part.hit == 1);
00750       }
00751     }
00752     if( state_hit == hit ) {
00753       *fr_states                     = (char**)realloc_safe( *fr_states, (sizeof( char* ) * (*fr_state_size)), (sizeof( char* ) * ((*fr_state_size) + 1)) );
00754       (*fr_states)[(*fr_state_size)] = vector_to_string( table->fr_states[i], HEXIDECIMAL, TRUE, fr_width );
00755       (*fr_state_size)++;
00756     }
00757   }
00758 
00759   /* Iterate through the to_states array, gathering all matching states */
00760   for( i=0; i<table->num_to_states; i++ ) {
00761     bool state_hit = any;
00762     for( j=0; j<table->num_arcs; j++ ) { 
00763       if( table->arcs[j]->to == i ) {
00764         state_hit = state_hit || (table->arcs[j]->suppl.part.hit == 1);
00765       }
00766     }
00767     if( state_hit == hit ) {
00768       *to_states                     = (char**)realloc_safe( *to_states, (sizeof( char* ) * (*to_state_size)), (sizeof( char* ) * ((*to_state_size) + 1)) );
00769       (*to_states)[(*to_state_size)] = vector_to_string( table->to_states[i], HEXIDECIMAL, TRUE, to_width );
00770       (*to_state_size)++;
00771     }
00772   }
00773 
00774   PROFILE_END;
00775 
00776 }

void arc_get_stats ( const fsm_table table,
int *  state_hits,
int *  state_total,
int *  arc_hits,
int *  arc_total,
int *  arc_excluded 
)

Calculates all state and state transition values for reporting purposes.

Calculates values for all specified totals from given state transition arc array. If the state and state transition totals are not known (i.e., user specified state variables without specifying legal states and state transitions and/or the user specified state variables and state table was not able to be automatically extracted), return a value of -1 for total values to indicate to the calling function that a different report output is required.

Parameters:
table Pointer to FSM table
state_hits Pointer to total number of states hit during simulation
state_total Pointer to total number of states in table
arc_hits Pointer to total number of state transitions hit during simulation
arc_total Pointer to total number of state transitions in table
arc_excluded Pointer to total number of excluded arcs

References arc_state_hits(), arc_transition_excluded(), arc_transition_hits(), fsuppl_u::known, fsm_table_s::num_arcs, fsm_table_s::num_fr_states, fsuppl_u::part, PROFILE, PROFILE_END, and fsm_table_s::suppl.

Referenced by fsm_collect(), and fsm_get_stats().

00495   { PROFILE(ARC_GET_STATS);
00496 
00497   /* First get hits */
00498   *state_hits   += arc_state_hits( table );
00499   *arc_hits     += arc_transition_hits( table );
00500   *arc_excluded += arc_transition_excluded( table );
00501   
00502   /* If the state transitions are known, calculate them; otherwise, return -1 for totals */
00503   if( table->suppl.part.known == 0 ) {
00504     *state_total = -1;
00505     *arc_total   = -1;
00506   } else {
00507     *state_total += table->num_fr_states;
00508     *arc_total   += table->num_arcs;
00509   }
00510 
00511   PROFILE_END;
00512 
00513 }

void arc_get_transitions ( char ***  from_states,
char ***  to_states,
int **  ids,
int **  excludes,
char ***  reasons,
int *  arc_size,
const fsm_table table,
func_unit funit,
bool  hit,
bool  any,
unsigned int  fr_width,
unsigned int  to_width 
)

Outputs arc array state transition values to specified output stream.

Traverses entire arc array, storing all state transitions that were hit during simulation (if hit parameter is true or the any parameter is true) or missed during simulation (if hit parameter is false or the any parameter is true).

Parameters:
from_states Pointer to string array containing from_state values
to_states Pointer to string array containing to_state values
ids List of arc IDs
excludes Pointer to integer array containing exclude values
reasons Pointer to string array containing exclude reasons
arc_size Number of elements in both the from_states and to_states arrays
table Pointer to FSM table
funit Pointer to functional unit containing this FSM
hit Specifies if hit or missed transitions should be gathered
any Specifies if all arc transitions or just the ones that meet the hit criteria should be gathered
fr_width Width of "from" vector to output
to_width Width of "to" vector to output

References fsm_table_s::arcs, exclude_find_exclude_reason(), asuppl_u::excluded, fsm_table_s::fr_states, fsm_table_arc_s::from, HEXIDECIMAL, asuppl_u::hit, fsm_table_s::id, fsm_table_s::num_arcs, asuppl_u::part, PROFILE, PROFILE_END, realloc_safe, exclude_reason_s::reason, strdup_safe, fsm_table_arc_s::suppl, fsm_table_arc_s::to, fsm_table_s::to_states, TRUE, and vector_to_string().

Referenced by fsm_display_arc_verbose(), and fsm_get_coverage().

00796   { PROFILE(ARC_GET_TRANSITIONS);
00797 
00798   unsigned int i;  /* Loop iterator */
00799 
00800   assert( table != NULL );
00801 
00802   /* Initialize state arrays and arc_size */
00803   *from_states = NULL;
00804   *to_states   = NULL;
00805   *ids         = NULL;
00806   *excludes    = NULL;
00807   *reasons     = NULL;
00808   *arc_size    = 0;
00809 
00810   /* Iterate through arc transitions */
00811   for( i=0; i<table->num_arcs; i++ ) {
00812 
00813     if( (table->arcs[i]->suppl.part.hit == hit) || any ) {
00814       exclude_reason* er;
00815 
00816       *from_states                = (char**)realloc_safe( *from_states, (sizeof( char* ) * (*arc_size)), (sizeof( char* ) * (*arc_size + 1)) );
00817       *to_states                  = (char**)realloc_safe( *to_states,   (sizeof( char* ) * (*arc_size)), (sizeof( char* ) * (*arc_size + 1)) );
00818       *ids                        = (int*)realloc_safe( *ids, (sizeof( int ) * (*arc_size)), (sizeof( int ) * (*arc_size + 1)) );
00819       *excludes                   = (int*)realloc_safe( *excludes, (sizeof( int ) * (*arc_size)), (sizeof( int ) * (*arc_size + 1)) );
00820       *reasons                    = (char**)realloc_safe( *reasons, (sizeof( char* ) * (*arc_size)), (sizeof( char* ) * (*arc_size + 1)) );
00821       (*from_states)[(*arc_size)] = vector_to_string( table->fr_states[table->arcs[i]->from], HEXIDECIMAL, TRUE, fr_width );
00822       (*to_states)[(*arc_size)]   = vector_to_string( table->to_states[table->arcs[i]->to],   HEXIDECIMAL, TRUE, to_width );
00823       (*ids)[(*arc_size)]         = table->id + i;
00824       (*excludes)[(*arc_size)]    = table->arcs[i]->suppl.part.excluded;
00825 
00826       /* If the assertion is currently excluded, check to see if there's a reason associated with it */
00827       if( (table->arcs[i]->suppl.part.excluded == 1) && ((er = exclude_find_exclude_reason( 'F', (table->id + i), funit )) != NULL) ) {
00828         (*reasons)[(*arc_size)] = strdup_safe( er->reason );
00829       } else {
00830         (*reasons)[(*arc_size)] = NULL;
00831       }
00832 
00833       (*arc_size)++;
00834     }
00835 
00836   }
00837 
00838   PROFILE_END;
00839 
00840 }

void arc_merge ( fsm_table base,
const fsm_table other 
)

Merges two FSM arcs, placing the results in the base arc.

Merges two FSM arcs into one, placing the result back into the base FSM arc. This function is used to calculate module coverage for the GUI.

References arc_add(), fsm_table_s::arcs, asuppl_u::excluded, fsm_table_s::fr_states, fsm_table_arc_s::from, asuppl_u::hit, fsm_table_s::num_arcs, asuppl_u::part, PROFILE, PROFILE_END, fsm_table_arc_s::suppl, fsm_table_arc_s::to, and fsm_table_s::to_states.

Referenced by fsm_merge().

00699   { PROFILE(ARC_MERGE);
00700 
00701   unsigned int i;  /* Loop iterator */
00702 
00703   /* Merge state transitions */
00704   for( i=0; i<other->num_arcs; i++ ) {
00705     arc_add( base, other->fr_states[other->arcs[i]->from], other->to_states[other->arcs[i]->to], other->arcs[i]->suppl.part.hit, other->arcs[i]->suppl.part.excluded );
00706   }
00707 
00708   PROFILE_END;
00709 
00710 }

Generated on Sun Nov 21 00:55:36 2010 for Covered by  doxygen 1.6.3