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

/Users/trevorw/projects/release/covered-0.7.4/src/fsm_arg.h File Reference


Detailed Description

Contains functions for handling FSM arguments from the command-line.

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
10/02/2003

#include "defines.h"

Go to the source code of this file.

Defines

#define __FSM_ARG_H__

Functions

void fsm_arg_parse (const char *arg)
 Parses specified -F argument for FSM information.

void fsm_arg_parse_attr (attr_param *ap, const func_unit *funit, bool exclude)
 Parses specified attribute argument for FSM information.


Define Documentation

#define __FSM_ARG_H__
 


Function Documentation

void fsm_arg_parse const char *  arg  ) 
 

Parses specified -F argument for FSM information.

Exceptions:
anonymous Throw
Parses specified argument string for FSM information. If the FSM information is considered legal, returns TRUE; otherwise, returns FALSE.
Parameters:
arg  Command-line argument following -F specifier

00247   { PROFILE(FSM_ARG_PARSE);
00248 
00249   char*       tmp = strdup_safe( arg );  /* Temporary copy of given argument */
00250   char*       ptr = tmp;                 /* Pointer to current character in arg */
00251   expression* in_state;                  /* Pointer to input state expression */
00252   expression* out_state;                 /* Pointer to output state expression */
00253 
00254   Try {
00255 
00256     while( (*ptr != '\0') && (*ptr != '=') ) {
00257       ptr++;
00258     }
00259 
00260     if( *ptr == '\0' ) {
00261 
00262       print_output( "Option -F must specify a module/task/function/named block and one or two variables.  See \"covered score -h\" for more information.",
00263                     FATAL, __FILE__, __LINE__ );
00264       Throw 0;
00265 
00266     } else {
00267 
00268       *ptr = '\0';
00269       ptr++;
00270 
00271       if( (in_state = fsm_arg_parse_state( &ptr, tmp )) != NULL ) {
00272 
00273         if( *ptr == ',' ) {
00274 
00275           ptr++;
00276 
00277           if( (out_state = fsm_arg_parse_state( &ptr, tmp )) != NULL ) {
00278             (void)fsm_var_add( arg, in_state, out_state, NULL, FALSE );
00279           } else {
00280             print_output( "Illegal FSM command-line output state", FATAL, __FILE__, __LINE__ );
00281             Throw 0;
00282           }
00283 
00284         } else {
00285 
00286           /* Copy the current expression */
00287           (void)fsm_var_add( arg, in_state, in_state, NULL, FALSE );
00288 
00289         }
00290 
00291       } else {
00292   
00293         print_output( "Illegal FSM command-line input state", FATAL, __FILE__, __LINE__ );
00294         Throw 0;
00295  
00296       }
00297 
00298     }
00299 
00300   } Catch_anonymous {
00301     free_safe( tmp, (strlen( arg ) + 1) );
00302     Throw 0;
00303   }
00304 
00305   /* Deallocate temporary memory */
00306   free_safe( tmp, (strlen( arg ) + 1) );
00307 
00308   PROFILE_END;
00309 
00310 }

void fsm_arg_parse_attr attr_param ap,
const func_unit funit,
bool  exclude
 

Parses specified attribute argument for FSM information.

Exceptions:
anonymous Throw Throw Throw Throw Throw Throw Throw Throw fsm_arg_parse_trans
Parses the specified attribute parameter for validity and updates FSM structure accordingly.
Parameters:
ap  Pointer to attribute parameter list
funit  Pointer to functional unit containing this attribute
exclude  If TRUE, sets the exclude bits in the FSM

00596   { PROFILE(FSM_ARG_PARSE_ATTR);
00597 
00598   attr_param* curr;               /* Pointer to current attribute parameter in list */
00599   fsm_link*   fsml      = NULL;   /* Pointer to found FSM structure */
00600   int         index     = 1;      /* Current index number in list */
00601   bool        ignore    = FALSE;  /* Set to TRUE if we should ignore this attribute */
00602   expression* in_state  = NULL;   /* Pointer to input state */
00603   expression* out_state = NULL;   /* Pointer to output state */
00604   char*       str;                /* Temporary holder for string value */
00605   char*       tmp;                /* Temporary holder for string value */
00606 
00607   curr = ap;
00608   while( (curr != NULL) && !ignore ) {
00609 
00610     /* This name is the name of the FSM structure to update */
00611     if( index == 1 ) {
00612       if( curr->expr != NULL ) {
00613         ignore = TRUE;
00614       } else {
00615         fsml = fsm_link_find( curr->name, funit->fsm_head );
00616       }
00617     } else if( (index == 2) && (strcmp( curr->name, "is" ) == 0) && (curr->expr != NULL) ) {
00618       if( fsml == NULL ) {
00619         int slen;
00620         tmp = str = vector_to_string( curr->expr->value, ESUPPL_STATIC_BASE( curr->expr->suppl ), FALSE );
00621         slen = strlen( tmp );
00622         Try {
00623           if( (in_state = fsm_arg_parse_state( &str, funit->name )) == NULL ) {
00624             unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Illegal input state expression (%s), file: %s", str, obf_file( funit->filename ) );
00625             assert( rv < USER_MSG_LENGTH );
00626             print_output( user_msg, FATAL, __FILE__, __LINE__ );
00627             Throw 0;
00628           }
00629         } Catch_anonymous {
00630           free_safe( tmp, (slen + 1) );
00631           Throw 0;
00632         }
00633         free_safe( tmp, (slen + 1) );
00634       } else {
00635         unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Input state specified after output state for this FSM has already been specified, file: %s",
00636                                     obf_file( funit->filename ) );
00637         assert( rv < USER_MSG_LENGTH );
00638         print_output( user_msg, FATAL, __FILE__, __LINE__ );
00639         Throw 0;
00640       }
00641     } else if( (index == 2) && (strcmp( curr->name, "os" ) == 0) && (curr->expr != NULL) ) {
00642       if( fsml == NULL ) {
00643         int slen;
00644         tmp = str = vector_to_string( curr->expr->value, ESUPPL_STATIC_BASE( curr->expr->suppl ), FALSE );
00645         slen = strlen( tmp );
00646         Try {
00647           if( (out_state = fsm_arg_parse_state( &str, funit->name )) == NULL ) {
00648             unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Illegal output state expression (%s), file: %s", str, obf_file( funit->filename ) );
00649             assert( rv < USER_MSG_LENGTH );
00650             print_output( user_msg, FATAL, __FILE__, __LINE__ );
00651             Throw 0;
00652           } else {
00653             (void)fsm_var_add( funit->name, out_state, out_state, curr->name, exclude );
00654             fsml = fsm_link_find( curr->name, funit->fsm_head );
00655           }
00656         } Catch_anonymous {
00657           free_safe( tmp, (slen + 1) );
00658           Throw 0;
00659         }
00660         free_safe( tmp, (slen + 1) );
00661       } else {
00662         unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Output state specified after output state for this FSM has already been specified, file: %s",
00663                                     obf_file( funit->filename ) );
00664         assert( rv < USER_MSG_LENGTH );
00665         print_output( user_msg, FATAL, __FILE__, __LINE__ );
00666         Throw 0;
00667       }
00668     } else if( (index == 3) && (strcmp( curr->name, "os" ) == 0) && (out_state == NULL) &&
00669                (in_state != NULL) && (curr->expr != NULL) ) {
00670       if( fsml == NULL ) {
00671         int slen;
00672         tmp = str = vector_to_string( curr->expr->value, ESUPPL_STATIC_BASE( curr->expr->suppl ), FALSE );
00673         slen = strlen( tmp );
00674         Try {
00675           if( (out_state = fsm_arg_parse_state( &str, funit->name )) == NULL ) {
00676             unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Illegal output state expression (%s), file: %s", str, obf_file( funit->filename ) );
00677             assert( rv < USER_MSG_LENGTH );
00678             print_output( user_msg, FATAL, __FILE__, __LINE__ );
00679             Throw 0;
00680           } else {
00681             (void)fsm_var_add( funit->name, in_state, out_state, curr->name, exclude );
00682             fsml = fsm_link_find( curr->name, funit->fsm_head );
00683           }
00684         } Catch_anonymous {
00685           free_safe( tmp, (slen + 1) );
00686           Throw 0;
00687         }
00688         free_safe( tmp, (slen + 1) );
00689       } else {
00690         unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Output state specified after output state for this FSM has already been specified, file: %s",
00691                                     obf_file( funit->filename ) );
00692         assert( rv < USER_MSG_LENGTH );
00693         print_output( user_msg, FATAL, __FILE__, __LINE__ );
00694         Throw 0;
00695       }
00696     } else if( (index > 1) && (strcmp( curr->name, "trans" ) == 0) && (curr->expr != NULL) ) {
00697       if( fsml == NULL ) {
00698         unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Attribute FSM name (%s) has not been previously created, file: %s",
00699                                     obf_sig( curr->name ), obf_file( funit->filename ) );
00700         assert( rv < USER_MSG_LENGTH );
00701         print_output( user_msg, FATAL, __FILE__, __LINE__ );
00702         Throw 0;
00703       } else {
00704         fsm_arg_parse_trans( curr->expr, fsml->table, funit );
00705       }
00706     } else {
00707       unsigned int rv;
00708       tmp = vector_to_string( curr->expr->value, ESUPPL_STATIC_BASE( curr->expr->suppl ), FALSE );
00709       rv = snprintf( user_msg, USER_MSG_LENGTH, "Invalid covered_fsm attribute parameter (%s=%s), file: %s",
00710                      curr->name, tmp, obf_file( funit->filename ) );
00711       assert( rv < USER_MSG_LENGTH );
00712       print_output( user_msg, FATAL, __FILE__, __LINE__ );
00713       free_safe( tmp, (strlen( tmp ) + 1) );
00714       Throw 0;
00715     }
00716 
00717     /* We need to work backwards in attribute parameter lists */
00718     curr = curr->prev;
00719     index++;
00720     
00721   }
00722 
00723   PROFILE_END;
00724 
00725 }


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