Contains functions for handling FSM variable structure. More...
#include "defines.h"
Go to the source code of this file.
Functions | |
fsm_var * | fsm_var_add (const char *funit_name, int line, expression *in_state, expression *out_state, char *name, bool exclude) |
Allocates, initializes and adds FSM variable to global list. | |
void | fsm_var_bind_add (char *sig_name, expression *expr, char *funit_name) |
Adds specified signal and expression to binding list. | |
void | fsm_var_stmt_add (statement *stmt, char *funit_name) |
Add specified functional unit and statement to binding list. | |
void | fsm_var_bind () |
Performs FSM signal/expression binding process. | |
void | fsm_var_cleanup () |
Cleans up the global lists used in this file. |
Contains functions for handling FSM variable structure.
fsm_var* fsm_var_add | ( | const char * | funit_name, | |
int | line, | |||
expression * | in_state, | |||
expression * | out_state, | |||
char * | name, | |||
bool | exclude | |||
) |
Allocates, initializes and adds FSM variable to global list.
Adds the specified Verilog hierarchical scope to a list of FSM scopes to find during the parsing phase.
funit_name | String containing functional unit containing FSM state variable | |
line | First line of FSM variable | |
in_state | Pointer to expression containing input state | |
out_state | Pointer to expression containing output state | |
name | Name of this FSM (only valid for attributes | |
exclude | If TRUE, excludes the FSM from coverage consideration |
References curr_db, fsm_var_s::exclude, fsm_create(), func_unit_s::fsm_head, fsm_link_add(), func_unit_s::fsm_tail, funit_link_s::funit, fsm_var_s::funit, funit_head, funit_link_find(), FUNIT_MODULE, fsm_var_s::iexp, fsm_var_s::ivar, fsm_var_s::line, malloc_safe, fsm_s::name, fsm_var_s::name, fsm_var_s::next, fsm_var_s::ovar, PROFILE, strdup_safe, expression_s::table, and fsm_var_s::table.
Referenced by fsm_arg_parse(), and fsm_arg_parse_attr().
00109 { PROFILE(FSM_VAR_ADD); 00110 00111 fsm_var* new_var = NULL; /* Pointer to newly created FSM variable */ 00112 funit_link* funitl; /* Pointer to functional unit link found */ 00113 fsm* table; /* Pointer to newly create FSM */ 00114 00115 /* If we have not parsed design, add new FSM variable to list */ 00116 if( db_list[curr_db]->funit_head == NULL ) { 00117 00118 new_var = (fsm_var*)malloc_safe( sizeof( fsm_var ) ); 00119 new_var->funit = strdup_safe( funit_name ); 00120 new_var->name = NULL; 00121 new_var->ivar = in_state; 00122 new_var->ovar = out_state; 00123 new_var->iexp = NULL; 00124 new_var->table = NULL; 00125 new_var->exclude = exclude; 00126 new_var->line = line; 00127 new_var->next = NULL; 00128 00129 if( fsm_var_head == NULL ) { 00130 fsm_var_head = fsm_var_tail = new_var; 00131 } else { 00132 fsm_var_tail->next = new_var; 00133 fsm_var_tail = new_var; 00134 } 00135 00136 } else { 00137 00138 if( (funitl = funit_link_find( funit_name, FUNIT_MODULE, db_list[curr_db]->funit_head )) != NULL ) { 00139 table = fsm_create( in_state, out_state, line, exclude ); 00140 if( name != NULL ) { 00141 table->name = strdup_safe( name ); 00142 } 00143 in_state->table = table; 00144 out_state->table = table; 00145 fsm_link_add( table, &(funitl->funit->fsm_head), &(funitl->funit->fsm_tail) ); 00146 } else { 00147 assert( funitl != NULL ); 00148 } 00149 00150 } 00151 00152 return( new_var ); 00153 00154 }
void fsm_var_bind | ( | ) |
Performs FSM signal/expression binding process.
anonymous | fsm_var_bind_expr Throw |
After Verilog parsing has completed, this function should be called to bind all signals to their associated FSM state expressions and functional units. For each entry in the FSM binding list the signal name is looked in the functional unit specified in the binding entry. If the signal is found, the associated expression pointer is added to the signal's expression list and the expression's signal pointer is set to point at the found signal structure. If the signal was not found, an error message is reported to the user, specifying the signal did not exist in the design.
After the signals and expressions have been bound, the FSM statement binding list is iterated through binding all statements containing FSM state expressions to the functional unit that it is a part of. If the statement contains an FSM state expression that is an output state expression, create the FSM structure for this FSM and add it to the design.
References Catch_anonymous, fv_bind_s::expr, free_safe, fsm_var_bind_expr(), fsm_var_bind_stmt(), fv_bind_s::funit_name, fv_bind_s::next, PROFILE, PROFILE_END, fv_bind_s::sig_name, fv_bind_s::stmt, Throw, and Try.
Referenced by parse_design().
00394 { PROFILE(FSM_VAR_BIND); 00395 00396 fv_bind* curr = NULL; /* Pointer to current FSM variable */ 00397 fv_bind* tmp; /* Temporary pointer to FSM bind structure */ 00398 00399 Try { 00400 00401 curr = fsm_var_bind_head; 00402 while( curr != NULL ) { 00403 00404 /* Perform binding */ 00405 fsm_var_bind_expr( curr->sig_name, curr->expr, curr->funit_name ); 00406 00407 tmp = curr->next; 00408 00409 /* Deallocate memory for this bind structure */ 00410 free_safe( curr->sig_name, (strlen( curr->sig_name ) + 1) ); 00411 free_safe( curr->funit_name, (strlen( curr->funit_name ) + 1) ); 00412 free_safe( curr, sizeof( fv_bind ) ); 00413 00414 curr = tmp; 00415 00416 } 00417 00418 } Catch_anonymous { 00419 while( curr != NULL ) { 00420 tmp = curr->next; 00421 free_safe( curr->sig_name, (strlen( curr->sig_name ) + 1) ); 00422 free_safe( curr->funit_name, (strlen( curr->funit_name ) + 1) ); 00423 free_safe( curr, sizeof( fv_bind ) ); 00424 curr = tmp; 00425 } 00426 curr = fsm_var_stmt_head; 00427 while( curr != NULL ) { 00428 tmp = curr->next; 00429 free_safe( curr->funit_name, (strlen( curr->funit_name ) + 1) ); 00430 free_safe( curr, sizeof( fv_bind ) ); 00431 curr = tmp; 00432 } 00433 Throw 0; 00434 } 00435 00436 curr = fsm_var_stmt_head; 00437 while( curr != NULL ) { 00438 00439 /* Bind statement to functional unit */ 00440 (void)fsm_var_bind_stmt( curr->stmt, curr->funit_name ); 00441 00442 tmp = curr->next; 00443 00444 /* Deallocate memory for this bind structure */ 00445 free_safe( curr->funit_name, (strlen( curr->funit_name ) + 1) ); 00446 free_safe( curr, sizeof( fv_bind ) ); 00447 00448 curr = tmp; 00449 00450 } 00451 00452 PROFILE_END; 00453 00454 }
void fsm_var_bind_add | ( | char * | sig_name, | |
expression * | expr, | |||
char * | funit_name | |||
) |
Adds specified signal and expression to binding list.
anonymous | fsm_var_bind_expr |
Creates a new FSM binding structure and initializes it with the specified information. The FSM binding structure is then added to the global list of FSM binding structures to be bound after parsing is complete.
sig_name | Name of signal to bind | |
expr | Pointer to expression to bind | |
funit_name | Name of functional unit that will contain the expression and signal being bound |
References curr_db, fv_bind_s::expr, fsm_var_bind_expr(), funit_head, fv_bind_s::funit_name, malloc_safe, fv_bind_s::next, PROFILE, PROFILE_END, fv_bind_s::sig_name, and strdup_safe.
Referenced by fsm_arg_parse_state().
00319 { PROFILE(FSM_VAR_BIND_ADD); 00320 00321 fv_bind* fvb; /* Pointer to new FSM variable binding structure */ 00322 00323 /* If the functional unit list does not exist yet, we need to bind this later; otherwise, bind now */ 00324 if( db_list[curr_db]->funit_head == NULL ) { 00325 00326 /* Allocate and initialize FSM variable bind structure */ 00327 fvb = (fv_bind*)malloc_safe( sizeof( fv_bind ) ); 00328 fvb->sig_name = strdup_safe( sig_name ); 00329 fvb->expr = expr; 00330 fvb->funit_name = strdup_safe( funit_name ); 00331 fvb->next = NULL; 00332 00333 /* Add new structure to the global list */ 00334 if( fsm_var_bind_head == NULL ) { 00335 fsm_var_bind_head = fsm_var_bind_tail = fvb; 00336 } else { 00337 fsm_var_bind_tail->next = fvb; 00338 fsm_var_bind_tail = fvb; 00339 } 00340 00341 } else { 00342 00343 fsm_var_bind_expr( sig_name, expr, funit_name ); 00344 00345 } 00346 00347 PROFILE_END; 00348 00349 }
void fsm_var_cleanup | ( | ) |
Cleans up the global lists used in this file.
Iterates through the various global lists in this file, deallocating all memory. This function is called when an error has occurred during the parsing stage.
References statement_s::exp, fv_bind_s::expr, expression_dealloc(), FALSE, free_safe, fsm_var_s::funit, fv_bind_s::funit_name, fsm_var_s::ivar, fv_bind_s::next, fsm_var_s::next, fsm_var_s::ovar, PROFILE, PROFILE_END, fv_bind_s::sig_name, statement_dealloc(), and fv_bind_s::stmt.
Referenced by command_score(), and parse_design().
00522 { PROFILE(FSM_VAR_CLEANUP); 00523 00524 fsm_var* curr_fv; /* Pointer to the current fsm_var structure */ 00525 fsm_var* tmp_fv; /* Temporary pointer */ 00526 fv_bind* curr_fvb; /* Pointer to the current fv_bind structure */ 00527 fv_bind* tmp_fvb; /* Temporary pointer */ 00528 00529 /* Deallocate fsm_var list */ 00530 curr_fv = fsm_var_head; 00531 while( curr_fv != NULL ) { 00532 tmp_fv = curr_fv; 00533 curr_fv = curr_fv->next; 00534 00535 free_safe( tmp_fv->funit, (strlen( curr_fv->funit ) + 1) ); 00536 expression_dealloc( tmp_fv->ivar, FALSE ); 00537 expression_dealloc( tmp_fv->ovar, FALSE ); 00538 free_safe( tmp_fv, sizeof( fsm_var ) ); 00539 } 00540 fsm_var_head = fsm_var_tail = NULL; 00541 00542 /* Deallocate fsm_var_bind list */ 00543 curr_fvb = fsm_var_bind_head; 00544 while( curr_fvb != NULL ) { 00545 tmp_fvb = curr_fvb; 00546 curr_fvb = curr_fvb->next; 00547 00548 free_safe( tmp_fvb->sig_name, (strlen( tmp_fvb->sig_name ) + 1) ); 00549 free_safe( tmp_fvb->funit_name, (strlen( tmp_fvb->funit_name ) + 1) ); 00550 expression_dealloc( tmp_fvb->expr, FALSE ); 00551 free_safe( tmp_fvb, sizeof( fv_bind ) ); 00552 } 00553 fsm_var_bind_head = fsm_var_bind_tail = NULL; 00554 00555 /* Deallocate fsm_var_stmt list */ 00556 curr_fvb = fsm_var_stmt_head; 00557 while( curr_fvb != NULL ) { 00558 tmp_fvb = curr_fvb; 00559 curr_fvb = curr_fvb->next; 00560 00561 free_safe( tmp_fvb->funit_name, (strlen( tmp_fvb->funit_name ) + 1) ); 00562 expression_dealloc( tmp_fvb->stmt->exp, FALSE ); 00563 statement_dealloc( tmp_fvb->stmt ); 00564 free_safe( tmp_fvb, sizeof( fv_bind ) ); 00565 } 00566 fsm_var_stmt_head = fsm_var_stmt_tail = NULL; 00567 00568 PROFILE_END; 00569 00570 }
void fsm_var_stmt_add | ( | statement * | stmt, | |
char * | funit_name | |||
) |
Add specified functional unit and statement to binding list.
Allocates and initializes an FSM variable binding entry and adds it to the fsm_var_stmt list for later processing.
stmt | Pointer to statement containing FSM state expression | |
funit_name | Name of functional unit that will contain stmt |
References fv_bind_s::funit_name, malloc_safe, fv_bind_s::next, PROFILE, PROFILE_END, fv_bind_s::stmt, and strdup_safe.
Referenced by fsm_arg_parse_state().
00358 { PROFILE(FSM_VAR_STMT_ADD); 00359 00360 fv_bind* fvb; /* Pointer to new FSM variable binding structure */ 00361 00362 fvb = (fv_bind*)malloc_safe( sizeof( fv_bind ) ); 00363 fvb->stmt = stmt; 00364 fvb->funit_name = strdup_safe( funit_name ); 00365 fvb->next = NULL; 00366 00367 /* Add new structure to the head of the global list */ 00368 if( fsm_var_stmt_head == NULL ) { 00369 fsm_var_stmt_head = fsm_var_stmt_tail = fvb; 00370 } else { 00371 fvb->next = fsm_var_stmt_head; 00372 fsm_var_stmt_head = fvb; 00373 } 00374 00375 PROFILE_END; 00376 00377 }