#include "ver.h"
Go to the source code of this file.
Data Structures | |
struct | Ver_Stream_t_ |
Defines | |
#define | VER_BUFFER_SIZE 1048576 |
#define | VER_OFFSET_SIZE 65536 |
#define | VER_WORD_SIZE 65536 |
#define | VER_MINIMUM(a, b) (((a) < (b))? (a) : (b)) |
Functions | |
static void | Ver_StreamReload (Ver_Stream_t *p) |
Ver_Stream_t * | Ver_StreamAlloc (char *pFileName) |
void | Ver_StreamFree (Ver_Stream_t *p) |
char * | Ver_StreamGetFileName (Ver_Stream_t *p) |
int | Ver_StreamGetFileSize (Ver_Stream_t *p) |
int | Ver_StreamGetCurPosition (Ver_Stream_t *p) |
int | Ver_StreamGetLineNumber (Ver_Stream_t *p) |
int | Ver_StreamIsOkey (Ver_Stream_t *p) |
char | Ver_StreamScanChar (Ver_Stream_t *p) |
char | Ver_StreamPopChar (Ver_Stream_t *p) |
void | Ver_StreamSkipChars (Ver_Stream_t *p, char *pCharsToSkip) |
void | Ver_StreamSkipToChars (Ver_Stream_t *p, char *pCharsToStop) |
char * | Ver_StreamGetWord (Ver_Stream_t *p, char *pCharsToStop) |
#define VER_BUFFER_SIZE 1048576 |
CFile****************************************************************
FileName [verStream.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Input file stream, which knows nothing about Verilog.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 19, 2006.]
Revision [
] DECLARATIONS ///
Definition at line 27 of file verStream.c.
#define VER_MINIMUM | ( | a, | |||
b | ) | (((a) < (b))? (a) : (b)) |
Definition at line 31 of file verStream.c.
#define VER_OFFSET_SIZE 65536 |
Definition at line 28 of file verStream.c.
#define VER_WORD_SIZE 65536 |
Definition at line 29 of file verStream.c.
Ver_Stream_t* Ver_StreamAlloc | ( | char * | pFileName | ) |
FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Starts the file reader for the given file.]
Description []
SideEffects []
SeeAlso []
Definition at line 71 of file verStream.c.
00072 { 00073 Ver_Stream_t * p; 00074 FILE * pFile; 00075 int nCharsToRead; 00076 // check if the file can be opened 00077 pFile = fopen( pFileName, "rb" ); 00078 if ( pFile == NULL ) 00079 { 00080 printf( "Ver_StreamAlloc(): Cannot open input file \"%s\".\n", pFileName ); 00081 return NULL; 00082 } 00083 // start the file reader 00084 p = ALLOC( Ver_Stream_t, 1 ); 00085 memset( p, 0, sizeof(Ver_Stream_t) ); 00086 p->pFileName = pFileName; 00087 p->pFile = pFile; 00088 // get the file size, in bytes 00089 fseek( pFile, 0, SEEK_END ); 00090 p->nFileSize = ftell( pFile ); 00091 rewind( pFile ); 00092 // allocate the buffer 00093 p->pBuffer = ALLOC( char, VER_BUFFER_SIZE+1 ); 00094 p->nBufferSize = VER_BUFFER_SIZE; 00095 p->pBufferCur = p->pBuffer; 00096 // determine how many chars to read 00097 nCharsToRead = VER_MINIMUM(p->nFileSize, VER_BUFFER_SIZE); 00098 // load the first part into the buffer 00099 fread( p->pBuffer, nCharsToRead, 1, p->pFile ); 00100 p->nFileRead = nCharsToRead; 00101 // set the ponters to the end and the stopping point 00102 p->pBufferEnd = p->pBuffer + nCharsToRead; 00103 p->pBufferStop = (p->nFileRead == p->nFileSize)? p->pBufferEnd : p->pBuffer + VER_BUFFER_SIZE - VER_OFFSET_SIZE; 00104 // start the arrays 00105 p->nLineCounter = 1; // 1-based line counting 00106 return p; 00107 }
void Ver_StreamFree | ( | Ver_Stream_t * | p | ) |
int Ver_StreamGetCurPosition | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns the current reading position.]
Description []
SideEffects []
SeeAlso []
Definition at line 203 of file verStream.c.
00204 { 00205 return p->nFileRead - (p->pBufferEnd - p->pBufferCur); 00206 }
char* Ver_StreamGetFileName | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns the file size.]
Description []
SideEffects []
SeeAlso []
Definition at line 171 of file verStream.c.
00172 { 00173 return p->pFileName; 00174 }
int Ver_StreamGetFileSize | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns the file size.]
Description []
SideEffects []
SeeAlso []
Definition at line 187 of file verStream.c.
00188 { 00189 return p->nFileSize; 00190 }
int Ver_StreamGetLineNumber | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns the line number for the given token.]
Description []
SideEffects []
SeeAlso []
Definition at line 219 of file verStream.c.
00220 { 00221 return p->nLineCounter; 00222 }
char* Ver_StreamGetWord | ( | Ver_Stream_t * | p, | |
char * | pCharsToStop | |||
) |
Function*************************************************************
Synopsis [Returns current word delimited by the set of symbols.]
Description [Modifies the stream by inserting 0 at the first encounter of one of the symbols in the list.]
SideEffects []
SeeAlso []
Definition at line 392 of file verStream.c.
00393 { 00394 char * pChar, * pTemp; 00395 if ( p->fStop ) 00396 return NULL; 00397 assert( pCharsToStop != NULL ); 00398 // check if the new data should to be loaded 00399 if ( p->pBufferCur > p->pBufferStop ) 00400 Ver_StreamReload( p ); 00401 // skip the symbols 00402 p->nChars = 0; 00403 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ ) 00404 { 00405 // skip symbols as long as they are NOT in the list 00406 for ( pTemp = pCharsToStop; *pTemp; pTemp++ ) 00407 if ( *pChar == *pTemp ) 00408 break; 00409 if ( *pTemp == 0 ) // pChar is not found in the list 00410 { 00411 p->pChars[p->nChars++] = *pChar; 00412 if ( p->nChars == VER_WORD_SIZE ) 00413 { 00414 printf( "Ver_StreamGetWord(): The buffer size is exceeded.\n" ); 00415 return NULL; 00416 } 00417 // count the lines 00418 if ( *pChar == '\n' ) 00419 p->nLineCounter++; 00420 continue; 00421 } 00422 // the symbol is found - move the position, set the word end, return the word 00423 p->pBufferCur = pChar; 00424 p->pChars[p->nChars] = 0; 00425 return p->pChars; 00426 } 00427 // the file is finished or the last part continued 00428 // through VER_OFFSET_SIZE chars till the end of the buffer 00429 if ( p->pBufferStop == p->pBufferEnd ) // end of file 00430 { 00431 p->fStop = 1; 00432 p->pChars[p->nChars] = 0; 00433 return p->pChars; 00434 } 00435 printf( "Ver_StreamGetWord() failed to parse the file \"%s\".\n", p->pFileName ); 00436 return NULL; 00437 }
int Ver_StreamIsOkey | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns current symbol.]
Description []
SideEffects []
SeeAlso []
Definition at line 237 of file verStream.c.
00238 { 00239 return !p->fStop; 00240 }
char Ver_StreamPopChar | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns current symbol and moves to the next.]
Description []
SideEffects []
SeeAlso []
Definition at line 270 of file verStream.c.
00271 { 00272 assert( !p->fStop ); 00273 // check if the new data should to be loaded 00274 if ( p->pBufferCur > p->pBufferStop ) 00275 Ver_StreamReload( p ); 00276 // check if there are symbols left 00277 if ( p->pBufferCur == p->pBufferEnd ) // end of file 00278 { 00279 p->fStop = 1; 00280 return -1; 00281 } 00282 // count the lines 00283 if ( *p->pBufferCur == '\n' ) 00284 p->nLineCounter++; 00285 return *p->pBufferCur++; 00286 }
void Ver_StreamReload | ( | Ver_Stream_t * | p | ) | [static] |
Function*************************************************************
Synopsis [Loads new data into the file reader.]
Description []
SideEffects []
SeeAlso []
Definition at line 120 of file verStream.c.
00121 { 00122 int nCharsUsed, nCharsToRead; 00123 assert( !p->fStop ); 00124 assert( p->pBufferCur > p->pBufferStop ); 00125 assert( p->pBufferCur < p->pBufferEnd ); 00126 // figure out how many chars are still not processed 00127 nCharsUsed = p->pBufferEnd - p->pBufferCur; 00128 // move the remaining data to the beginning of the buffer 00129 memmove( p->pBuffer, p->pBufferCur, nCharsUsed ); 00130 p->pBufferCur = p->pBuffer; 00131 // determine how many chars we will read 00132 nCharsToRead = VER_MINIMUM( p->nBufferSize - nCharsUsed, p->nFileSize - p->nFileRead ); 00133 // read the chars 00134 fread( p->pBuffer + nCharsUsed, nCharsToRead, 1, p->pFile ); 00135 p->nFileRead += nCharsToRead; 00136 // set the ponters to the end and the stopping point 00137 p->pBufferEnd = p->pBuffer + nCharsUsed + nCharsToRead; 00138 p->pBufferStop = (p->nFileRead == p->nFileSize)? p->pBufferEnd : p->pBuffer + VER_BUFFER_SIZE - VER_OFFSET_SIZE; 00139 }
char Ver_StreamScanChar | ( | Ver_Stream_t * | p | ) |
Function*************************************************************
Synopsis [Returns current symbol.]
Description []
SideEffects []
SeeAlso []
Definition at line 253 of file verStream.c.
00254 { 00255 assert( !p->fStop ); 00256 return *p->pBufferCur; 00257 }
void Ver_StreamSkipChars | ( | Ver_Stream_t * | p, | |
char * | pCharsToSkip | |||
) |
Function*************************************************************
Synopsis [Skips the current symbol and all symbols from the list.]
Description []
SideEffects []
SeeAlso []
Definition at line 299 of file verStream.c.
00300 { 00301 char * pChar, * pTemp; 00302 assert( !p->fStop ); 00303 assert( pCharsToSkip != NULL ); 00304 // check if the new data should to be loaded 00305 if ( p->pBufferCur > p->pBufferStop ) 00306 Ver_StreamReload( p ); 00307 // skip the symbols 00308 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ ) 00309 { 00310 // skip symbols as long as they are in the list 00311 for ( pTemp = pCharsToSkip; *pTemp; pTemp++ ) 00312 if ( *pChar == *pTemp ) 00313 break; 00314 if ( *pTemp == 0 ) // pChar is not found in the list 00315 { 00316 p->pBufferCur = pChar; 00317 return; 00318 } 00319 // count the lines 00320 if ( *pChar == '\n' ) 00321 p->nLineCounter++; 00322 } 00323 // the file is finished or the last part continued 00324 // through VER_OFFSET_SIZE chars till the end of the buffer 00325 if ( p->pBufferStop == p->pBufferEnd ) // end of file 00326 { 00327 p->fStop = 1; 00328 return; 00329 } 00330 printf( "Ver_StreamSkipSymbol() failed to parse the file \"%s\".\n", p->pFileName ); 00331 }
void Ver_StreamSkipToChars | ( | Ver_Stream_t * | p, | |
char * | pCharsToStop | |||
) |
Function*************************************************************
Synopsis [Skips all symbols until encountering one from the list.]
Description []
SideEffects []
SeeAlso []
Definition at line 344 of file verStream.c.
00345 { 00346 char * pChar, * pTemp; 00347 assert( !p->fStop ); 00348 assert( pCharsToStop != NULL ); 00349 // check if the new data should to be loaded 00350 if ( p->pBufferCur > p->pBufferStop ) 00351 Ver_StreamReload( p ); 00352 // skip the symbols 00353 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ ) 00354 { 00355 // skip symbols as long as they are NOT in the list 00356 for ( pTemp = pCharsToStop; *pTemp; pTemp++ ) 00357 if ( *pChar == *pTemp ) 00358 break; 00359 if ( *pTemp == 0 ) // pChar is not found in the list 00360 { 00361 // count the lines 00362 if ( *pChar == '\n' ) 00363 p->nLineCounter++; 00364 continue; 00365 } 00366 // the symbol is found - move position and return 00367 p->pBufferCur = pChar; 00368 return; 00369 } 00370 // the file is finished or the last part continued 00371 // through VER_OFFSET_SIZE chars till the end of the buffer 00372 if ( p->pBufferStop == p->pBufferEnd ) // end of file 00373 { 00374 p->fStop = 1; 00375 return; 00376 } 00377 printf( "Ver_StreamSkipToSymbol() failed to parse the file \"%s\".\n", p->pFileName ); 00378 }