parse.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "binding.h"
#include "db.h"
#include "defines.h"
#include "fsm_var.h"
#include "fst.h"
#include "info.h"
#include "link.h"
#include "parser_misc.h"
#include "race.h"
#include "score.h"
#include "sim.h"
#include "stmt_blk.h"
#include "util.h"

Functions

void reset_lexer (str_link *file_list_head)
int VLparse ()
int parse_readline (FILE *file, char *line, int size)
void parse_design (const char *top, const char *output_db)
 Parses the specified design and generates scoring modules.
void parse_and_score_dumpfile (const char *db, const char *dump_file, int dump_mode)
 Parses VCD dumpfile and scores design.

Variables

str_linkuse_files_head
str_linkmodlist_head
str_linkmodlist_tail
char user_msg [USER_MSG_LENGTH]
isuppl info_suppl
bool flag_check_races
sig_range curr_prange
sig_range curr_urange
bool instance_specified
char * top_module
char * ppfilename
bool debug_mode
char * dumpvars_file

Detailed Description

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
11/27/2001

Function Documentation

void parse_and_score_dumpfile ( const char *  db,
const char *  dump_file,
int  dump_mode 
)

Parses VCD dumpfile and scores design.

Exceptions:
anonymous db_do_timestep Throw vcd_parse bind_perform db_read lxt_parse db_write

Reads in specified CDD database file, reads in specified dumpfile in the specified format, performs re-simulation and writes the scored design back to the specified CDD database file for merging or reporting.

Parameters:
db Name of output database file to generate
dump_file Name of dumpfile to parse for scoring
dump_mode Type of dumpfile being used (see Dumpfile Format for legal values)

References bind_perform(), Catch_anonymous, db_do_timestep(), db_read(), db_write(), DEBUG, debug_mode, DUMP_FMT_FST, DUMP_FMT_LXT, DUMP_FMT_VCD, FALSE, fst_parse(), lxt_parse(), isuppl_u::part, print_output(), PROFILE, PROFILE_END, READ_MODE_NO_MERGE, isuppl_u::scored, sim_dealloc(), sim_initialize(), Throw, TRUE, Try, user_msg, USER_MSG_LENGTH, and vcd_parse().

Referenced by command_score().

00243   { PROFILE(PARSE_AND_SCORE_DUMPFILE);
00244 
00245   assert( dump_file != NULL );
00246 
00247   Try {
00248 
00249 #ifdef DEBUG_MODE
00250     if( debug_mode ) {
00251       unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "========  Reading in database %s  ========\n", db );
00252       assert( rv < USER_MSG_LENGTH );
00253       print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00254     }
00255 #endif
00256 
00257     /* Read in contents of specified database file */
00258     (void)db_read( db, READ_MODE_NO_MERGE );
00259   
00260     /* Bind expressions to signals/functional units */
00261     bind_perform( TRUE, 0 );
00262 
00263     /* Add static values to simulator */
00264     sim_initialize();
00265 
00266 #ifdef DEBUG_MODE
00267     if( debug_mode ) {
00268       unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "========  Reading in VCD dumpfile %s  ========\n", dump_file );
00269       assert( rv < USER_MSG_LENGTH );
00270       print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00271     }
00272 #endif
00273   
00274     /* Perform the parse */
00275     switch( dump_mode ) {
00276       case DUMP_FMT_VCD :  vcd_parse( dump_file );  break;
00277       case DUMP_FMT_LXT :  lxt_parse( dump_file );  break;
00278       case DUMP_FMT_FST :  fst_parse( dump_file );  break;
00279       default           :  assert( (dump_mode == DUMP_FMT_VCD) || (dump_mode == DUMP_FMT_LXT) || (dump_mode == DUMP_FMT_FST) );
00280     }
00281     
00282     /* Flush any pending statement trees that are waiting for delay */
00283     (void)db_do_timestep( 0, TRUE );
00284 
00285 #ifdef DEBUG_MODE
00286     if( debug_mode ) {
00287       unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "========  Writing database %s  ========\n", db );
00288       assert( rv < USER_MSG_LENGTH );
00289       print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00290     }
00291 #endif
00292 
00293     /* Indicate that this CDD contains scored information */
00294     info_suppl.part.scored = 1;
00295 
00296     /* Write contents to database file */
00297     db_write( db, FALSE, FALSE );
00298 
00299   } Catch_anonymous {
00300     sim_dealloc();
00301     Throw 0;
00302   }
00303 
00304   /* Deallocate simulator stuff */
00305   sim_dealloc();
00306 
00307   PROFILE_END;
00308 
00309 }

void parse_design ( const char *  top,
const char *  output_db 
)

Parses the specified design and generates scoring modules.

Exceptions:
anonymous fsm_var_bind race_check_modules Throw bind_perform db_write

Resets the lexer and parses all Verilog files specified in use_files list. After all design files are parsed, their information will be appropriately stored in the associated lists.

Parameters:
top Name of top-level module to score
output_db Name of output directory for generated scored files

References bind_perform(), Catch_anonymous, db_check_for_top_module(), db_close(), db_write(), DEBUG, debug_mode, dumpvars_file, error_count, FALSE, FATAL, FATAL_WRAP, flag_check_races, fsm_var_bind(), fsm_var_cleanup(), instance_specified, NORMAL, parser_dealloc_sig_range(), ppfilename, print_output(), PROFILE, PROFILE_END, race_check_modules(), reset_lexer(), score_generate_top_dumpvars_module(), sim_dealloc(), stmt_blk_remove(), str_link_add(), strdup_safe, Throw, top_module, TRUE, Try, user_msg, USER_MSG_LENGTH, VLparse(), WARNING, and WARNING_WRAP.

Referenced by command_score().

00106   { PROFILE(PARSE_DESIGN);
00107 
00108   Try {
00109 
00110     (void)str_link_add( strdup_safe( top ), &modlist_head, &modlist_tail );
00111 
00112     if( use_files_head != NULL ) {
00113 
00114       int parser_ret;
00115 
00116       /* Initialize lexer with first file */
00117       reset_lexer( use_files_head );
00118 
00119       Try {
00120 
00121         /* Parse the design -- if we catch an exception, remove the temporary ppfilename */
00122         parser_ret = VLparse();
00123 
00124         if( (parser_ret != 0) || (error_count > 0) ) {
00125           print_output( "Error in parsing design", FATAL, __FILE__, __LINE__ );
00126           Throw 0;
00127         }
00128 
00129       } Catch_anonymous {
00130         (void)unlink( ppfilename );
00131         parser_dealloc_sig_range( &curr_urange, FALSE );
00132         parser_dealloc_sig_range( &curr_prange, FALSE );
00133         Throw 0;
00134       }
00135      
00136       /* Deallocate any memory in curr_range variable */
00137       parser_dealloc_sig_range( &curr_urange, FALSE );
00138       parser_dealloc_sig_range( &curr_prange, FALSE );
00139 
00140 #ifdef DEBUG_MODE
00141       if( debug_mode ) {
00142         print_output( "========  Completed design parsing  ========\n", DEBUG, __FILE__, __LINE__ );
00143       }
00144 #endif
00145 
00146       /* Check to make sure that the -t and -i options were specified correctly */
00147       if( db_check_for_top_module() ) {
00148         if( instance_specified ) {
00149           unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Module specified with -t option (%s) is a top-level module.", top_module );
00150           assert( rv < USER_MSG_LENGTH );
00151           print_output( user_msg, FATAL, __FILE__, __LINE__ );
00152           print_output( "The -i option should not have been specified", FATAL_WRAP, __FILE__, __LINE__ );
00153           Throw 0;
00154         }
00155       } else {
00156         if( !instance_specified ) {
00157           unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Module specified with -t option (%s) is not a top-level module.", top_module );
00158           assert( rv < USER_MSG_LENGTH );
00159           print_output( user_msg, FATAL, __FILE__, __LINE__ );
00160           print_output( "The -i option must be specified to provide the hierarchy to the module specified with", FATAL_WRAP, __FILE__, __LINE__ );
00161           print_output( "the -t option.", FATAL_WRAP, __FILE__, __LINE__ );
00162           Throw 0;
00163         }
00164       }
00165 
00166       /* Perform all signal/expression binding */
00167       bind_perform( FALSE, 0 );
00168       fsm_var_bind();
00169   
00170       /* Perform race condition checking */
00171       if( flag_check_races ) {
00172         print_output( "\nChecking for race conditions...", NORMAL, __FILE__, __LINE__ );
00173         race_check_modules();
00174       } else {
00175         print_output( "The -rI option was specified in the command-line, causing Covered to skip race condition", WARNING, __FILE__, __LINE__ );
00176         print_output( "checking; therefore, coverage information may not be accurate if actual race conditions", WARNING_WRAP, __FILE__, __LINE__ );
00177         print_output( "do exist.  Proceed at your own risk!", WARNING_WRAP, __FILE__, __LINE__ );
00178       }
00179 
00180       /* Remove all statement blocks that cannot be considered for coverage */
00181       stmt_blk_remove();
00182 
00183 #ifdef DEBUG_MODE
00184       if( debug_mode ) {
00185         print_output( "========  Completed race condition checking  ========\n", DEBUG, __FILE__, __LINE__ );
00186       }
00187 #endif
00188 
00189     } else {
00190 
00191       print_output( "No Verilog input files specified", FATAL, __FILE__, __LINE__ );
00192       Throw 0;
00193 
00194     }
00195 
00196     /* Output the dumpvars module, if specified. */
00197     if( dumpvars_file != NULL ) {
00198       unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Outputting dumpvars file %s...", dumpvars_file );
00199       assert( rv < USER_MSG_LENGTH );
00200       print_output( user_msg, NORMAL, __FILE__, __LINE__ );
00201       score_generate_top_dumpvars_module( dumpvars_file );
00202     }
00203 
00204     /* Write contents to baseline database file. */
00205     db_write( output_db, TRUE, TRUE );
00206 
00207   } Catch_anonymous {
00208     fsm_var_cleanup();
00209     sim_dealloc();
00210     db_close();
00211     Throw 0;
00212   }
00213 
00214   /* Deallocate simulator stuff */
00215   sim_dealloc();
00216 
00217   /* Close database */
00218   db_close();
00219 
00220 #ifdef DEBUG_MODE
00221   if( debug_mode ) {
00222     unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "========  Design written to database %s successfully  ========\n\n", output_db );
00223     assert( rv < USER_MSG_LENGTH );
00224     print_output( user_msg, DEBUG, __FILE__, __LINE__ );
00225   }
00226 #endif
00227 
00228   PROFILE_END;
00229 
00230 }

int parse_readline ( FILE *  file,
char *  line,
int  size 
)
Returns:
Returns the number of characters read from this line.

Reads from specified file, one character at a time, until either a newline or EOF is encountered. Returns the read line and the number of characters stored in the line. No newline character is added to the line.

Parameters:
file Pointer to file to read
line Read line from specified file
size Maximum number of characters that can be stored in line

References FATAL, print_output(), PROFILE, PROFILE_END, user_msg, and USER_MSG_LENGTH.

00072   { PROFILE(PARSE_READLINE);
00073 
00074   int i = 0;  /* Loop iterator */
00075 
00076   while( (i < (size - 1)) && !feof( file ) && ((line[i] = fgetc( file )) != '\n') ) {
00077     i++;
00078   }
00079 
00080   if( !feof( file ) ) {
00081     line[i] = '\0';
00082   }
00083 
00084   if( i == size ) {
00085     unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Line too long.  Must be less than %d characters.", size );
00086     assert( rv < USER_MSG_LENGTH );
00087     print_output( user_msg, FATAL, __FILE__, __LINE__ );
00088   }
00089 
00090   PROFILE_END;
00091 
00092   return( !feof( file ) );
00093 
00094 }

void reset_lexer ( str_link file_list_head  ) 

Referenced by parse_design().

int VLparse (  ) 

Referenced by parse_design().


Variable Documentation

If set to TRUE, causes debug information to be spewed to screen.

Name of dumpvars output file to write contents to

Referenced by command_score(), parse_design(), and score_parse_args().

Specifies if race condition checking should occur

Referenced by parse_design(), and score_parse_args().

Informational line for the CDD file.

Specifies if -i option was specified

Pointer to head of list of module names that need to be parsed yet. These names are added in the db_add_instance function and removed in the db_end_module function.

Pointer to tail of list of module names that need to be parsed yet. These names are added in the db_add_instance function and removed in the db_end_module function.

char* ppfilename

Name of preprocessor filename to use

char* top_module

Name of top-level module to score

Pointer to head element of used files list

char user_msg[USER_MSG_LENGTH]

Holds some output that will be displayed via the print_output command. This is created globally so that memory does not need to be reallocated for each function that wishes to use it.

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