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

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


Detailed Description

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
8/25/2003
What is an arc?
This group of functions handles the allocation, initialization, deallocation, and manipulation of an arc array. An arc array is a specialized, variable sized, compact byte array that contains all of the information necessary for storing state and state transition information for a single FSM within a design. To store this information into as compact a representation as possible, the data is bit-packed into the array.
The first 7 bytes of the array are known as the "arc header". Every arc array is required to have this information. The layout of the header is shown below:
Byte Description
0 Bits [ 7:0] of output state variable width
1 Bits [15:8] of output state variable width
2 Bits [ 7:0] of number of state transition entries currently allocated
3 Bits [15:8] of number of state transition entries currently allocated
4 Bits [ 7:0] of number of state transition entries currently occupied
5 Bits [15:8] of number of state transition entries currently occupied
6 Bits [ 7:0] of arc array supplemental field
Note: The arc array supplemental field contains miscellaneous information about this arc array. Currently, only bit 0 is used to indicate if the user has specified state transitions manually (using the Verilog-2001 inline attribute mechanism) or whether no state transitions are known prior to simulation.
The rest of the bytes in the arc array represent a list of state transition entries. An entry contains enough information to describe a bidirectional state transition with coverage information. The bit-width of an entry is determined by taking bytes 0 & 1 of the header (the output state variable width, multiplying this value by 2, and adding the number of entry supplemental bits for an entry (currently this value is 6). Each entry is byte-aligned in the arc array. The fields that comprise an entry are described below.
Bits Description
0 Set to 1 if the forward bidirectional state transition was hit; otherwise, set to 0.
1 Set to 1 if the reverse bidirectional state transition was hit; otherwise, set to 0.
2 Set to 1 if this entry is bidirectional (reverse is a transition); otherwise, only forward is valid.
3 Set to 1 if the output state of the forward transition is a new state in the arc array.
4 Set to 1 if the input state of the forward transition is a new state in the arc array.
5 Set to 1 if the forward state transition is excluded from coverage.
6 Set to 1 if the reverse state transition is excluded from coverage.
(width + 6):7 Bit value of output state of the forward transition.
((width * 2) + 6):(width + 7) Bit value of input state of the forward transition.
Adding State Transitions
When an state transition occurs during simulation, the arc array is searched to see if an entry already exists that contains the same state transition. If no matching entry is found, a new entry is added to the existing arc array. If the arc array allocated is currently full (current allocated size in header equals the current number of used entries), the array is grown. The number of entries that the array grows is equal to the bit width of the output state variable. When the new state is added, the entry is stored as a "forward" entry. A forward entry is an entry that contains the input state value in the upper bits of the entry and the output state value in the lower bits of the entry. If the state is added prior to simulation, bit 0 (hit forward) of the entry is set to 0; otherwise, it is set to a value of 1, indicating that the forward version of the state transition was hit. If a state transition is found in the array but the order of the input and output values are reversed from the stored entry, the entry is stored into the same entry, setting bit 2 (bidirectional entry bit) to a value of 1. This indicates that the current entry contains a forward entry and a reverse entry (input state value is stored in lower order bits and output state value is stored in upper order bits of the entry). If this type of entry is stored prior to simulation, bit 1 (reverse hit bit) is set to 0; otherwise, the bit is set to a value of 1. The following example shows an arc array as state transitions are added to it during simulation.
HF: Forward direction hit, HR: Reverse direction hit, BD: Entry is bidirectional
Event Entry Action
0 1 2
Add 0->1 0->1,HF=1,HR=0,BD=0 0->1 not found in table, add as forward in entry 0
Add 1->2 0->1,HF=1,HR=0,BD=0 1->2,HF=1,HR=0,BD=0 1->2 not found in table, add as forward in entry 1
Add 1->0 0->1,HF=1,HR=1,BD=1 1->2,HF=1,HR=0,BD=0 1->0 found in entry 0, add as reverse and set bidirectional entry bit
Calculating FSM State Coverage Metrics
To calculate the number of FSM states that are in an arc array, we first need to figure out what state values are unique in the arc array. Since state transitions contain two state values (input and output), we need to compare each state whether it is an input or an output state to every other state value in the arc array. To do this, we start with the input state (in the forward direction -- value in upper bits of entry) in entry 0 and compare it to each and every state in the arc array. If the current state value matches the first entry and the current state value is in the upper bits of the entry, bit 4 is set in the entry's supplemental field to indicate that its state is not unique. If the current state value matches the first entry and the current state value is in the lower bits of the entry, bit 5 is set in the entry's supplemental field to indicate that its state is not unique. If the current value does not match the first state value, nothing happens. After all states have been compared, the right value (if bit 5 in its entry supplemental field is not set) is compared to all of the rest of the state values (if their bit 4 or bit 5 in their supplemental field is not already set) are compared. This continues for all state values. After the state comparing phase has occurred, we can simply walk through the arc array counting all of the states that do not have their corresponding bit 4 or bit 5 set.
Calculating FSM State Transition Coverage Metrics
To calculate state transition coverage for the arc array is simple. Just count the number of entries that have bit 0 set to 1 and bits 1 and 2 set to 1. This will give you the number of state transitions that were hit during simulation.
Outputting an Arc to a File
Writing and reading an arc to and from a file is accomplished by writing each byte in the arc array to the file in hexidecimal format (zero-filling the output) with no spaces between the bytes. Additionally, if a byte contains the hexidecimal value of 0x0, simply output a comma character (this saves one character in the file for each byte that contains a value of 0x0). Keeping the output of an arc array to as small as possible in the file is necessary due to the large memory footprint that just one FSM can take.

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "arc.h"
#include "defines.h"
#include "exclude.h"
#include "expr.h"
#include "profiler.h"
#include "util.h"
#include "vector.h"

Functions

void arc_display (const fsm_table *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.

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_state_hits (const fsm_table *table)
int arc_transition_hits (const fsm_table *table)
int arc_transition_excluded (const fsm_table *table)
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 *base, 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)
 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)
 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.


Variables

int curr_arc_id = 1


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

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

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

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

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.

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

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

00667   { PROFILE(ARC_DB_MERGE);
00668 
00669   /*@-mustfreeonly -mustfreefresh@*/
00670 
00671   fsm_table*   table;  /* Currently read FSM table */
00672   unsigned int i;      /* Loop iterator */
00673 
00674   /* Read in the table */
00675   arc_db_read( &table, line );
00676 
00677   /* Merge state transitions */
00678   for( i=0; i<table->num_arcs; i++ ) {
00679     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 );
00680   }
00681 
00682   /* Deallocate the merged table */
00683   arc_dealloc( table );
00684 
00685   PROFILE_END;
00686 
00687   /*@=mustfreeonly =mustfreefresh@*/
00688 
00689 }

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

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

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

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

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

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

void arc_display const fsm_table table  )  [static]
 

Displays the given state transition arcs in a human-readable format.

Parameters:
table  Pointer to state transition arc array to display

00151   {
00152 
00153   unsigned int i;  /* Loop iterator */
00154 
00155   assert( table != NULL );
00156 
00157   for( i=0; i<table->num_arcs; i++ ) {
00158 
00159     char* lvec = vector_to_string( table->fr_states[table->arcs[i]->from], HEXIDECIMAL, TRUE );
00160     char* rvec = vector_to_string( table->to_states[table->arcs[i]->to],   HEXIDECIMAL, TRUE );
00161 
00162     printf( "       entry %u: ", i );
00163 
00164     /* Output the state transition */
00165     printf( "%s", lvec );
00166     printf( " --> " );
00167     printf( "%s", rvec );
00168 
00169     /* Now output the relevant supplemental information */
00170     printf( "  (%s %s)\n",
00171             ((table->arcs[i]->suppl.part.excluded == 1) ? "E" : "  "),
00172             ((table->arcs[i]->suppl.part.hit      == 1) ? "H" : "  ") );
00173 
00174     
00175     /* Deallocate strings */
00176     free_safe( lvec, (strlen( lvec ) + 1) );
00177     free_safe( rvec, (strlen( rvec ) + 1) );
00178 
00179   }
00180 
00181 }

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

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

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

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

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

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

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

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

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
 

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

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

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

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

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
 

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

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

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.

00698   { PROFILE(ARC_MERGE);
00699 
00700   unsigned int i;  /* Loop iterator */
00701 
00702   /* Merge state transitions */
00703   for( i=0; i<other->num_arcs; i++ ) {
00704     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 );
00705   }
00706 
00707   PROFILE_END;
00708 
00709 }

int arc_state_hits const fsm_table table  )  [static]
 

Returns:
Returns number of unique states hit during simulation.
Traverses through specified state transition table, figuring out what states in the table are unique. This is done by traversing through the entire arc array, comparing states that have their ARC_NOT_UNIQUE_x bits set to a value 0. If both states contain the same value, the second state has its ARC_NOT_UNIQUE_x set to indicate that this state is not unique to the table.
Parameters:
table  Pointer to state transition arc array

00401   { PROFILE(ARC_STATE_HITS);
00402 
00403   int          hit = 0;     /* Number of states hit */
00404   unsigned int i;           /* Loop iterators */
00405   int*         state_hits;  /* Contains state hit information */
00406 
00407   assert( table != NULL );
00408 
00409   /* First, create and intialize a state table to hold hit counts */
00410   state_hits = (int*)malloc_safe( sizeof( int ) * table->num_fr_states );
00411   for( i=0; i<table->num_fr_states; i++ ) {
00412     state_hits[i] = 0;
00413   }
00414   
00415   /* Iterate through arc transition array and count unique hits */
00416   for( i=0; i<table->num_arcs; i++ ) {
00417     if( (table->arcs[i]->suppl.part.hit || table->arcs[i]->suppl.part.excluded) ) {
00418       hit += (state_hits[table->arcs[i]->from]++ == 0) ? 1 : 0; 
00419     }
00420   }
00421 
00422   /* Deallocate state_hits */
00423   free_safe( state_hits, (sizeof( int ) * table->num_fr_states) );
00424 
00425   PROFILE_END;
00426 
00427   return( hit );
00428 
00429 }

int arc_transition_excluded const fsm_table table  )  [static]
 

Returns:
Returns the number of state transitions that are excluded from coverage.
Parameters:
table  Pointer to state transition arc array

00462   { PROFILE(ARC_TRANSITION_EXCLUDED);
00463 
00464   int          excluded = 0;  /* Number of arcs excluded */
00465   unsigned int i;             /* Loop iterator */
00466 
00467   assert( table != NULL );
00468 
00469   for( i=0; i<table->num_arcs; i++ ) {
00470     excluded += table->arcs[i]->suppl.part.excluded;
00471   }
00472 
00473   PROFILE_END;
00474 
00475   return( excluded );
00476 
00477 }

int arc_transition_hits const fsm_table table  )  [static]
 

Returns:
Returns the number of hit state transitions in the specified arc array.
Iterates through arc array, accumulating the number of state transitions that were hit in simulation.
Parameters:
table  Pointer to state transition arc array

00440   { PROFILE(ARC_TRANSITION_HITS);
00441 
00442   int          hit = 0;  /* Number of arcs hit */
00443   unsigned int i;        /* Loop iterator */
00444 
00445   assert( table != NULL );
00446 
00447   for( i=0; i<table->num_arcs; i++ ) {
00448     hit += table->arcs[i]->suppl.part.hit | table->arcs[i]->suppl.part.excluded;
00449   }
00450 
00451   PROFILE_END;
00452 
00453   return( hit );
00454 
00455 }


Variable Documentation

int curr_arc_id = 1
 

Unique identifier for each arc in the design (used for exclusion purposes). This value is assigned to an arc when it is read from the CDD file.


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