main.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include "devel_doc.h"
#include "defines.h"
#include "exclude.h"
#include "obfuscate.h"
#include "profiler.h"
#include "report.h"
#include "score.h"
#include "util.h"

Functions

static void usage ()
int main (int argc, const char **argv)

Variables

struct exception_context the_exception_context [1]
char user_msg [USER_MSG_LENGTH]
char * ppfilename
int64 curr_malloc_size
bool test_mode

Detailed Description

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

Function Documentation

int main ( int  argc,
const char **  argv 
)
Parameters:
argc Number of arguments specified in argv parameter list.
argv List of arguments passed to this process from the command-line.
Returns:
Returns EXIT_SUCCESS to indicate a successful return; otherwise, returns EXIT_FAILURE.

Main function for the Covered utility. Parses command-line arguments and calls the appropriate functions.

References Catch_anonymous, command_exclude(), command_merge(), command_rank(), command_report(), command_score(), COVERED_VERSION, curr_malloc_size, FALSE, FATAL, init_exception_context, NORMAL, obfuscate_dealloc(), obfuscate_set_mode(), print_output(), profiler_report(), profiler_set_filename(), profiler_set_mode(), PROFILING_OUTPUT_NAME, set_debug(), set_quiet(), set_terse(), set_testmode(), test_mode, the_exception_context, Throw, TRUE, Try, usage(), user_msg, USER_MSG_LENGTH, and WARNING.

00114                                         {
00115 
00116   int  retval    = EXIT_SUCCESS;  /* Return value of this utility */
00117   int  curr_arg  = 1;             /* Current position in argument list */
00118   bool cmd_found = FALSE;         /* Set to TRUE when command found in arg list */
00119 
00120   /* Initialize the exception context */
00121   init_exception_context( the_exception_context );
00122 
00123   /* Initialize error suppression value */
00124   set_quiet( FALSE );
00125   set_debug( FALSE );
00126   set_terse( FALSE );
00127 #ifdef TESTMODE
00128   set_testmode();
00129 #endif
00130   obfuscate_set_mode( FALSE );
00131   profiler_set_mode( FALSE );
00132 
00133   Try {
00134 
00135     if( argc == 1 ) {
00136 
00137       print_output( "Must specify a command (score, merge, report, rank, -v, or -h)", FATAL, __FILE__, __LINE__ );
00138       retval = -1;
00139 
00140     } else {
00141 
00142       if( strncmp( "-v", argv[1], 2 ) == 0 ) {
00143 
00144         /* Display version of Covered */
00145         print_output( COVERED_VERSION, NORMAL, __FILE__, __LINE__ );
00146 
00147       } else if( strncmp( "-h", argv[1], 2 ) == 0 ) {
00148 
00149         usage();
00150 
00151       } else {
00152 
00153         do {
00154 
00155           if( strncmp( "-Q", argv[curr_arg], 2 ) == 0 ) {
00156   
00157             set_quiet( TRUE );
00158 
00159           } else if( strncmp( "-T", argv[curr_arg], 2 ) == 0 ) {
00160           
00161             set_terse( TRUE );
00162             
00163           } else if( strncmp( "-D", argv[curr_arg], 2 ) == 0 ) {
00164 
00165 #ifdef DEBUG_MODE
00166             set_debug( TRUE );
00167 #else
00168             print_output( "Global command -D can only be used when Covered is configured with the --enable-debug flag when being built", WARNING, __FILE__, __LINE__ );
00169 #endif
00170 
00171           } else if( strncmp( "-P", argv[curr_arg], 2 ) == 0 ) {
00172 
00173 #ifdef PROFILER
00174             profiler_set_mode( TRUE );
00175             curr_arg++;
00176             if( (curr_arg < argc) && (argv[curr_arg][0] != '-') &&
00177                 (strncmp( "score",  argv[curr_arg], 5 ) != 0) &&
00178                 (strncmp( "merge",  argv[curr_arg], 5 ) != 0) &&
00179                 (strncmp( "report", argv[curr_arg], 6 ) != 0)) {
00180               profiler_set_filename( argv[curr_arg] );
00181             } else {
00182               curr_arg--;
00183               profiler_set_filename( PROFILING_OUTPUT_NAME );
00184             }
00185 #else
00186             print_output( "Global command -P can only be used when Covered is configured with the --enable-profiling flag when being built", WARNING, __FILE__, __LINE__ );
00187 #endif
00188 
00189           } else if( strncmp( "-B", argv[curr_arg], 2 ) == 0 ) {
00190 
00191             obfuscate_set_mode( TRUE );
00192 
00193           } else if( strncmp( "score", argv[curr_arg], 5 ) == 0 ) {
00194 
00195             command_score( argc, curr_arg, argv );
00196             cmd_found = TRUE;
00197 
00198           } else if( strncmp( "merge", argv[curr_arg], 5 ) == 0 ) {
00199 
00200             command_merge( argc, curr_arg, argv );
00201             cmd_found = TRUE;
00202 
00203           } else if( strncmp( "report", argv[curr_arg], 6 ) == 0 ) {
00204 
00205             command_report( argc, curr_arg, argv );
00206             cmd_found = TRUE;
00207 
00208           } else if( strncmp( "rank", argv[curr_arg], 4 ) == 0 ) {
00209 
00210             command_rank( argc, curr_arg, argv );
00211             cmd_found = TRUE;
00212 
00213           } else if( strncmp( "exclude", argv[curr_arg], 7 ) == 0 ) {
00214 
00215             command_exclude( argc, curr_arg, argv );
00216             cmd_found = TRUE;
00217 
00218           } else {
00219 
00220             unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Unknown command/global option \"%s\".  Please see \"covered -h\" for usage.", argv[curr_arg] );
00221             assert( rv < USER_MSG_LENGTH );
00222             print_output( user_msg, FATAL, __FILE__, __LINE__ );
00223             Throw 0;
00224 
00225           }
00226 
00227           curr_arg++;
00228 
00229         } while( (curr_arg < argc) && !cmd_found );
00230 
00231         if( !cmd_found ) {
00232  
00233           print_output( "Must specify a command (score, merge, report, rank, exclude, -v, or -h)", FATAL, __FILE__, __LINE__ );
00234           Throw 0;
00235 
00236         }
00237 
00238       }
00239 
00240     }
00241 
00242   } Catch_anonymous {
00243     retval = EXIT_FAILURE;
00244   }
00245 
00246   /* Deallocate obfuscation tree */
00247   obfuscate_dealloc();
00248 
00249   /* Output profiling information, if necessary */
00250   profiler_report();
00251 
00252 #ifdef TESTMODE
00253   /* Make sure that all of our allocate memory has been deallocated */
00254   if( test_mode ) {
00255     printf( "curr_malloc_size: %" FMT64 "d\n", curr_malloc_size );
00256     assert( curr_malloc_size == 0 );
00257   }
00258 #endif
00259 
00260   return( retval );
00261 
00262 }

static void usage (  )  [static]

Displays usage information about this utility.

Referenced by main().

00061                     {
00062 
00063   printf( "\n" );
00064 #ifdef DEBUG_MODE
00065 #ifdef PROFILER
00066   printf( "Usage:  covered (-h | -v | (-D | -T | -Q) (-P [<file>]) (-B) <command> <command_options>))\n" );
00067 #else
00068   printf( "Usage:  covered (-h | -v | (-D | -T | -Q) (-B) <command> <command_options>))\n" );
00069 #endif
00070 #else
00071 #ifdef PROFILER
00072   printf( "Usage:  covered (-h | -v | (-T | -Q) (-P [<file>]) (-B) <command> <command_options>))\n" );
00073 #else
00074   printf( "Usage:  covered (-h | -v | (-T | -Q) (-B) <command> <command_options>))\n" );
00075 #endif
00076 #endif
00077   printf( "\n" );
00078   printf( "   Options:\n" );
00079 #ifdef DEBUG_MODE
00080   printf( "      -D                      Debug.  Display information helpful for debugging tool problems\n" );
00081 #endif
00082 #ifdef PROFILER
00083   printf( "      -P [<file>]             Profile.  Generate profiling information file from command.  Default output file is covered.prof\n" );
00084 #endif
00085   printf( "      -T                      Terse mode.  Causes all output except for header information and warnings to be suppressed\n" );
00086   printf( "      -Q                      Quiet mode.  Causes all output to be suppressed\n" );
00087   printf( "      -B                      Obfuscate.  Obfuscates design-sensitive names in all user-readable output\n" );
00088   printf( "      -v                      Version.  Display current Covered version\n" );
00089   printf( "      -h                      Help.  Display this usage information\n" );
00090   printf( "\n" );
00091   printf( "   Commands:\n" );
00092   printf( "      score                   Parses Verilog files and VCD dumpfiles to create database file used\n" );
00093   printf( "                                for merging and reporting.\n" );
00094   printf( "      merge                   Merges two database files into one.\n" );
00095   printf( "      report                  Generates human-readable coverage reports from database file.\n" );
00096   printf( "      rank                    Generates ranked list of CDD files to run for optimal coverage in a regression run.\n" );
00097   printf( "      exclude                 Excludes coverage points from a given CDD and saves the modified CDD for further commands.\n" );
00098   printf( "\n" );
00099   printf( "   For individual help information for each of the above commands, enter:\n" );
00100   printf( "      covered <command> -h\n" );
00101   printf( "\n" );
00102 
00103 }


Variable Documentation

Contains the total number of bytes malloc'ed during the simulation run. This information is output to the user after simulation as a performance indicator.

Referenced by calloc_safe1(), free_safe2(), main(), malloc_safe1(), malloc_safe_nolimit1(), realloc_safe1(), and strdup_safe1().

char* ppfilename

Name of preprocessor filename to use

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

If set to TRUE, outputs memory information to standard output for processing.

Referenced by calloc_safe1(), free_safe2(), main(), malloc_safe1(), malloc_safe_nolimit1(), realloc_safe1(), set_testmode(), and strdup_safe1().

Exception context structure used by cexcept.h for throwing and catching exceptions.

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:39 2010 for Covered by  doxygen 1.6.3