fst.c File Reference

#include "assert.h"
#include "defines.h"
#include "fstapi.c"
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <zlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <time.h>
#include "fastlz.h"
#include <sys/mman.h>
#include "symtable.h"
#include "db.h"
#include "util.h"

Defines

#define FST_ID_NAM_SIZ   (512)

Functions

static void fst_reader_process_hier (void *ctx)
static void fst_callback (void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value)
void fst_parse (const char *fst_file)
 Parses and scores FST-style dumpfile.

Variables

char user_msg [USER_MSG_LENGTH]
symtablevcd_symtab
int vcd_symtab_size
symtable ** timestep_tab
static uint64_t vcd_prevtime = 0
static bool vcd_prevtime_valid = FALSE
static bool vcd_blackout

Define Documentation

#define FST_ID_NAM_SIZ   (512)
Parameters:
fst.c 
Author:
Trevor Williams (phase1geo@gmail.com)
Date:
1/25/2006
Note:
This file is based on the fst2vcd utility that comes with GtkWave-3.3.6

Referenced by fst_reader_process_hier(), and fstReaderProcessHier().


Function Documentation

static void fst_callback ( void *  user_callback_data_pointer,
uint64_t  time,
fstHandle  facidx,
const unsigned char *  value 
) [static]
Exceptions:
anonymous db_do_timestep

References db_do_timestep(), db_set_symbol_char(), db_set_symbol_string(), FALSE, fstVcdID(), PROFILE, PROFILE_END, TRUE, vcd_blackout, vcd_prevtime, and vcd_prevtime_valid.

Referenced by fst_parse().

00234   { PROFILE(FST_CALLBACK);
00235 
00236   /* If this is a new timestamp, perform a simulation */
00237   if( (vcd_prevtime != time) || !vcd_prevtime_valid ) {
00238     if( vcd_prevtime_valid ) {
00239       (void)db_do_timestep( vcd_prevtime, FALSE );
00240     }
00241     vcd_prevtime       = time;
00242     vcd_prevtime_valid = TRUE;
00243   }
00244 
00245   /* Handle dumpon/off information */
00246   if( !value[0] ) {
00247 
00248     if( !vcd_blackout ) {
00249       vcd_blackout = TRUE;
00250     }
00251 
00252   } else {
00253 
00254     if( vcd_blackout ) {
00255       vcd_blackout = FALSE;
00256     }
00257 
00258     if( !value[1] ) {
00259       db_set_symbol_char( fstVcdID( facidx ), value[0] );
00260     } else {
00261       db_set_symbol_string( fstVcdID( facidx ), value );
00262     }
00263 
00264   }
00265 
00266   PROFILE_END;
00267 
00268 }

void fst_parse ( const char *  fst_file  ) 

Parses and scores FST-style dumpfile.

Main FST parsing function. Reads in an FST-style dumpfile, tells Covered about signal information and simulation results.

Parameters:
fst_file Name of FST file to read and score

References Catch_anonymous, db_check_dumpfile_scopes(), db_do_timestep(), FALSE, FATAL, free_safe, fst_callback(), fst_reader_process_hier(), fstReaderClose(), fstReaderIterBlocks(), fstReaderOpen(), fstReaderSetFacProcessMaskAll(), malloc_safe_nolimit, print_output(), PROFILE, PROFILE_END, symtable_create(), symtable_dealloc(), Throw, Try, vcd_prevtime, vcd_prevtime_valid, and vcd_symtab_size.

Referenced by parse_and_score_dumpfile().

00276   { PROFILE(FST_PARSE);
00277 
00278   struct fstReaderContext *xc;
00279 
00280   printf( "fst_file: %s\n", fst_file );
00281 
00282   /* Open LXT file for opening and extract members */
00283   if( (xc = fstReaderOpen( fst_file )) != NULL ) {
00284 
00285     /* Create initial symbol table */
00286     vcd_symtab = symtable_create();
00287 
00288     Try {
00289 
00290       /* Handle the dumpfile definitions */
00291       fst_reader_process_hier( xc );
00292 
00293       /* Check to see that at least one instance was found */
00294       db_check_dumpfile_scopes(); 
00295           
00296       /* Create timestep symbol table array */
00297       if( vcd_symtab_size > 0 ) {
00298         timestep_tab = malloc_safe_nolimit( sizeof( symtable*) * vcd_symtab_size );
00299       }
00300         
00301       /* Not sure what this does but it seems to be a requirement of the FST reader */
00302       fstReaderSetFacProcessMaskAll( xc );
00303 
00304       /* Perform simulation */
00305       fstReaderIterBlocks( xc, fst_callback, NULL, NULL );
00306 
00307       /* Perform last simulation if necessary */
00308       if( vcd_prevtime_valid ) {
00309         (void)db_do_timestep( vcd_prevtime, FALSE );
00310       }
00311 
00312     } Catch_anonymous {
00313       symtable_dealloc( vcd_symtab );
00314       free_safe( timestep_tab, (sizeof( symtable* ) * vcd_symtab_size) );
00315       fstReaderClose( xc );
00316       Throw 0;
00317     }
00318         
00319     /* Deallocate memory */
00320     symtable_dealloc( vcd_symtab );
00321     free_safe( timestep_tab, (sizeof( symtable* ) * vcd_symtab_size) );
00322 
00323     /* Close FST file */
00324     fstReaderClose( xc );
00325 
00326   } else {
00327 
00328     print_output( "Unable to read data from FST dumpfile.  Exiting without scoring.", FATAL, __FILE__, __LINE__ );
00329     Throw 0;
00330 
00331   }
00332 
00333   PROFILE_END;
00334 
00335 }

static void fst_reader_process_hier ( void *  ctx  )  [static]

Handles the definitions portion of the dumpfile.

Parameters:
ctx Pointer to the current context

References db_assign_symbol(), db_set_vcd_scope(), db_vcd_upscope(), fstReaderContext::fh, FST_ID_NAM_SIZ, FST_ST_VCD_SCOPE, FST_ST_VCD_UPSCOPE, FST_VT_VCD_ARRAY, FST_VT_VCD_EVENT, FST_VT_VCD_INTEGER, FST_VT_VCD_PARAMETER, FST_VT_VCD_PORT, FST_VT_VCD_REAL, FST_VT_VCD_REAL_PARAMETER, FST_VT_VCD_REALTIME, FST_VT_VCD_REG, FST_VT_VCD_SUPPLY0, FST_VT_VCD_SUPPLY1, FST_VT_VCD_TIME, FST_VT_VCD_TRI, FST_VT_VCD_TRI0, FST_VT_VCD_TRI1, FST_VT_VCD_TRIAND, FST_VT_VCD_TRIOR, FST_VT_VCD_TRIREG, FST_VT_VCD_WAND, FST_VT_VCD_WIRE, FST_VT_VCD_WOR, fstReaderRecreateHierFile(), fstReaderVarint32(), fstVcdID(), fstReaderContext::longest_signal_value_len, fstReaderContext::maxhandle, fstReaderContext::num_alias, fstReaderContext::process_mask, PROFILE, PROFILE_END, fstReaderContext::signal_lens, fstReaderContext::signal_typs, fstReaderContext::temp_signal_value_buf, and fstReaderContext::var_count.

Referenced by fst_parse().

00059   { PROFILE(FST_READER_PROCESS_HIER);
00060 
00061   struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
00062   char str[FST_ID_NAM_SIZ+1];
00063   char str2[FST_ID_NAM_SIZ+1];
00064   char *pnt;
00065   int ch, scopetype;
00066   int vartype, vardir;
00067   uint32_t len, alias;
00068   uint32_t msb, lsb;
00069   uint32_t maxvalpos=0;
00070   int num_signal_dyn = 65536;
00071 
00072   if( !xc ) {
00073     return;
00074   }
00075 
00076   xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
00077 
00078   if( !xc->fh ) {
00079     fstReaderRecreateHierFile( xc );
00080   }
00081 
00082   xc->maxhandle = 0;
00083   xc->num_alias = 0;
00084 
00085   if( xc->signal_lens ) free(xc->signal_lens);
00086   xc->signal_lens = malloc(num_signal_dyn*sizeof(uint32_t));
00087 
00088   if( xc->signal_typs ) free(xc->signal_typs);
00089   xc->signal_typs = malloc(num_signal_dyn*sizeof(unsigned char));
00090 
00091   fseeko( xc->fh, 0, SEEK_SET );
00092 
00093   while( !feof( xc->fh ) ) {
00094 
00095     int tag = fgetc(xc->fh);
00096 
00097     switch( tag ) {
00098 
00099       case FST_ST_VCD_SCOPE:
00100         scopetype = fgetc(xc->fh);
00101         pnt = str;
00102         while( (ch = fgetc( xc->fh )) ) {
00103           *(pnt++) = ch;
00104         } /* scopename */
00105         *pnt = 0;
00106         while( fgetc( xc->fh ) ) { }; /* scopecomp */
00107         db_set_vcd_scope( str );
00108         break;
00109 
00110       case FST_ST_VCD_UPSCOPE:
00111         db_vcd_upscope();
00112         break;
00113 
00114       case FST_VT_VCD_EVENT:
00115       case FST_VT_VCD_INTEGER:
00116       case FST_VT_VCD_PARAMETER:
00117       case FST_VT_VCD_REAL:
00118       case FST_VT_VCD_REAL_PARAMETER:
00119       case FST_VT_VCD_REG:
00120       case FST_VT_VCD_SUPPLY0:
00121       case FST_VT_VCD_SUPPLY1:
00122       case FST_VT_VCD_TIME:
00123       case FST_VT_VCD_TRI:
00124       case FST_VT_VCD_TRIAND:
00125       case FST_VT_VCD_TRIOR:
00126       case FST_VT_VCD_TRIREG:
00127       case FST_VT_VCD_TRI0:
00128       case FST_VT_VCD_TRI1:
00129       case FST_VT_VCD_WAND:
00130       case FST_VT_VCD_WIRE:
00131       case FST_VT_VCD_WOR:
00132       case FST_VT_VCD_PORT:
00133       case FST_VT_VCD_ARRAY:
00134       case FST_VT_VCD_REALTIME:
00135         vartype = tag;
00136         vardir  = fgetc( xc->fh ); /* unused in VCD reader */
00137         pnt     = str;
00138         while( (ch = fgetc( xc->fh )) ) {
00139           *(pnt++) = ch;
00140         } /* varname */
00141         *pnt  = 0;
00142         len   = fstReaderVarint32(xc->fh);
00143         alias = fstReaderVarint32(xc->fh);
00144         msb   = len - 1;
00145         lsb   = 0;
00146 
00147         if( !alias ) {
00148           if( xc->maxhandle == num_signal_dyn ) {
00149             num_signal_dyn *= 2;
00150             xc->signal_lens = realloc( xc->signal_lens, num_signal_dyn*sizeof(uint32_t) );
00151             xc->signal_typs = realloc( xc->signal_typs, num_signal_dyn*sizeof(unsigned char) );
00152           }
00153           xc->signal_lens[xc->maxhandle] = len;
00154           xc->signal_typs[xc->maxhandle] = vartype;
00155 
00156           maxvalpos+=len;
00157           if( len > xc->longest_signal_value_len ) {
00158             xc->longest_signal_value_len = len;
00159           }
00160 
00161           if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME)) {
00162             len = 64;
00163             msb = 63;
00164             lsb = 0;
00165             xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
00166           } else {
00167             if( sscanf( str, "%s \[%d:%d]", str2, &msb, &lsb ) != 3 ) {
00168               if( sscanf( str, "%s \[%d]", str2, &lsb ) == 2 ) {
00169                 msb = lsb;
00170                 strcpy( str, str2 );
00171               }
00172             } else {
00173               strcpy( str, str2 );
00174             }
00175           }
00176           {
00177             uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
00178             db_assign_symbol( str, fstVcdID( xc->maxhandle + 1 ), msb, lsb );
00179           }
00180           xc->maxhandle++;
00181         } else {
00182           if((vartype == FST_VT_VCD_REAL) || (vartype == FST_VT_VCD_REAL_PARAMETER) || (vartype == FST_VT_VCD_REALTIME)) {
00183             len = 64;
00184             msb = 63;
00185             lsb = 0;
00186             xc->signal_typs[xc->maxhandle] = FST_VT_VCD_REAL;
00187           } else {
00188             if( sscanf( str, "%s \[%d:%d]", str2, &msb, &lsb ) != 3 ) {
00189               if( sscanf( str, "%s \[%d]", str2, &lsb ) == 2 ) {
00190                 msb = lsb;
00191                 strcpy( str, str2 );
00192               }
00193             } else {
00194               strcpy( str, str2 );
00195             }
00196           }
00197           {
00198             uint32_t modlen = (vartype != FST_VT_VCD_PORT) ? len : ((len - 2) / 3);
00199             db_assign_symbol( str, fstVcdID( alias ), msb, lsb );
00200           }
00201           xc->num_alias++;
00202         }
00203         break;
00204 
00205       default:
00206         break;
00207     }
00208 
00209   }
00210 
00211   xc->signal_lens = realloc( xc->signal_lens, xc->maxhandle*sizeof(uint32_t) );
00212   xc->signal_typs = realloc( xc->signal_typs, xc->maxhandle*sizeof(unsigned char) );
00213 
00214   if( xc->process_mask ) { free( xc->process_mask ); }
00215   xc->process_mask = calloc( 1, (xc->maxhandle+7)/8 );
00216 
00217   if( xc->temp_signal_value_buf ) free( xc->temp_signal_value_buf );
00218   xc->temp_signal_value_buf = malloc( xc->longest_signal_value_len + 1 );
00219 
00220   xc->var_count = xc->maxhandle + xc->num_alias;
00221 
00222   PROFILE_END;
00223 
00224 }


Variable Documentation

Pointer to the current timestep table array. Please see the file description for how this structure is used.

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.

bool vcd_blackout [static]

Specifies when we are handling dumping

Referenced by fst_callback().

uint64_t vcd_prevtime = 0 [static]

Specifies the last timestamp simulated

Referenced by fst_callback(), and fst_parse().

bool vcd_prevtime_valid = FALSE [static]

Specifies the vcd_prevtime value has been assigned by the simulator

Referenced by fst_callback(), and fst_parse().

Pointer to the VCD symbol table. Please see the file description for how this structure is used.

Maintains current number of nodes in the VCD symbol table. This value is used to create the appropriately sized timestep_tab array.

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