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