ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
verStream.c File Reference
#include "ver.h"
Include dependency graph for verStream.c:

Go to the source code of this file.

Classes

struct  Ver_Stream_t_
 

Macros

#define VER_BUFFER_SIZE   1048576
 DECLARATIONS ///.
 
#define VER_OFFSET_SIZE   65536
 
#define VER_WORD_SIZE   65536
 
#define VER_MINIMUM(a, b)
 

Functions

Ver_Stream_tVer_StreamAlloc (char *pFileName)
 FUNCTION DEFINITIONS ///.
 
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)
 
void Ver_StreamMove (Ver_Stream_t *p)
 

Macro Definition Documentation

◆ VER_BUFFER_SIZE

#define VER_BUFFER_SIZE   1048576

DECLARATIONS ///.

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 [

Id
verStream.c,v 1.00 2006/08/19 00:00:00 alanmi Exp

]

Definition at line 30 of file verStream.c.

◆ VER_MINIMUM

#define VER_MINIMUM ( a,
b )
Value:
(((a) < (b))? (a) : (b))

Definition at line 34 of file verStream.c.

◆ VER_OFFSET_SIZE

#define VER_OFFSET_SIZE   65536

Definition at line 31 of file verStream.c.

◆ VER_WORD_SIZE

#define VER_WORD_SIZE   65536

Definition at line 32 of file verStream.c.

Function Documentation

◆ Ver_StreamAlloc()

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 74 of file verStream.c.

75{
77 FILE * pFile;
78 int nCharsToRead;
79 int RetValue;
80 // check if the file can be opened
81 pFile = fopen( pFileName, "rb" );
82 if ( pFile == NULL )
83 {
84 printf( "Ver_StreamAlloc(): Cannot open input file \"%s\".\n", pFileName );
85 return NULL;
86 }
87 // start the file reader
88 p = ABC_ALLOC( Ver_Stream_t, 1 );
89 memset( p, 0, sizeof(Ver_Stream_t) );
90 p->pFileName = pFileName;
91 p->pFile = pFile;
92 // get the file size, in bytes
93 fseek( pFile, 0, SEEK_END );
94 p->nFileSize = ftell( pFile );
95 rewind( pFile );
96 // allocate the buffer
97 p->pBuffer = ABC_ALLOC( char, VER_BUFFER_SIZE+1 );
98 p->nBufferSize = VER_BUFFER_SIZE;
99 p->pBufferCur = p->pBuffer;
100 // determine how many chars to read
101 nCharsToRead = VER_MINIMUM(p->nFileSize, VER_BUFFER_SIZE);
102 // load the first part into the buffer
103 RetValue = fread( p->pBuffer, nCharsToRead, 1, p->pFile );
104 p->nFileRead = nCharsToRead;
105 // set the ponters to the end and the stopping point
106 p->pBufferEnd = p->pBuffer + nCharsToRead;
107 p->pBufferStop = (p->nFileRead == p->nFileSize)? p->pBufferEnd : p->pBuffer + VER_BUFFER_SIZE - VER_OFFSET_SIZE;
108 // start the arrays
109 p->nLineCounter = 1; // 1-based line counting
110 return p;
111}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
Cube * p
Definition exorList.c:222
char * memset()
VOID_HACK rewind()
#define VER_MINIMUM(a, b)
Definition verStream.c:34
#define VER_OFFSET_SIZE
Definition verStream.c:31
#define VER_BUFFER_SIZE
DECLARATIONS ///.
Definition verStream.c:30
struct Ver_Stream_t_ Ver_Stream_t
Definition ver.h:46
#define SEEK_END
Definition zconf.h:392
Here is the call graph for this function:

◆ Ver_StreamFree()

void Ver_StreamFree ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Stops the file reader.]

Description []

SideEffects []

SeeAlso []

Definition at line 157 of file verStream.c.

158{
159 if ( p->pFile )
160 fclose( p->pFile );
161 ABC_FREE( p->pBuffer );
162 ABC_FREE( p );
163}
#define ABC_FREE(obj)
Definition abc_global.h:267

◆ Ver_StreamGetCurPosition()

int Ver_StreamGetCurPosition ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns the current reading position.]

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file verStream.c.

209{
210 return p->nFileRead - (p->pBufferEnd - p->pBufferCur);
211}

◆ Ver_StreamGetFileName()

char * Ver_StreamGetFileName ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 176 of file verStream.c.

177{
178 return p->pFileName;
179}

◆ Ver_StreamGetFileSize()

int Ver_StreamGetFileSize ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file verStream.c.

193{
194 return p->nFileSize;
195}

◆ Ver_StreamGetLineNumber()

int Ver_StreamGetLineNumber ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns the line number for the given token.]

Description []

SideEffects []

SeeAlso []

Definition at line 224 of file verStream.c.

225{
226 return p->nLineCounter;
227}
Here is the caller graph for this function:

◆ Ver_StreamGetWord()

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 397 of file verStream.c.

398{
399 char * pChar, * pTemp;
400 if ( p->fStop )
401 return NULL;
402 assert( pCharsToStop != NULL );
403 // check if the new data should to be loaded
404 if ( p->pBufferCur > p->pBufferStop )
405 Ver_StreamReload( p );
406 // skip the symbols
407 p->nChars = 0;
408 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ )
409 {
410 // skip symbols as long as they are NOT in the list
411 for ( pTemp = pCharsToStop; *pTemp; pTemp++ )
412 if ( *pChar == *pTemp )
413 break;
414 if ( *pTemp == 0 ) // pChar is not found in the list
415 {
416 p->pChars[p->nChars++] = *pChar;
417 if ( p->nChars == VER_WORD_SIZE )
418 {
419 printf( "Ver_StreamGetWord(): The buffer size is exceeded.\n" );
420 return NULL;
421 }
422 // count the lines
423 if ( *pChar == '\n' )
424 p->nLineCounter++;
425 continue;
426 }
427 // the symbol is found - move the position, set the word end, return the word
428 p->pBufferCur = pChar;
429 p->pChars[p->nChars] = 0;
430 return p->pChars;
431 }
432 // the file is finished or the last part continued
433 // through VER_OFFSET_SIZE chars till the end of the buffer
434 if ( p->pBufferStop == p->pBufferEnd ) // end of file
435 {
436 p->fStop = 1;
437 p->pChars[p->nChars] = 0;
438 return p->pChars;
439 }
440 printf( "Ver_StreamGetWord() failed to parse the file \"%s\".\n", p->pFileName );
441 return NULL;
442}
#define assert(ex)
Definition util_old.h:213
#define VER_WORD_SIZE
Definition verStream.c:32
Here is the caller graph for this function:

◆ Ver_StreamIsOkey()

int Ver_StreamIsOkey ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns current symbol.]

Description []

SideEffects []

SeeAlso []

Definition at line 242 of file verStream.c.

243{
244 return !p->fStop;
245}
Here is the caller graph for this function:

◆ Ver_StreamMove()

void Ver_StreamMove ( Ver_Stream_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 455 of file verStream.c.

456{
457 if ( !strncmp(p->pBufferCur+1, "z_g_", 4) || !strncmp(p->pBufferCur+1, "co_g", 3) )
458 while ( p->pBufferCur[0] != '(' )
459 p->pBufferCur++;
460}
int strncmp()
Here is the call graph for this function:

◆ Ver_StreamPopChar()

char Ver_StreamPopChar ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns current symbol and moves to the next.]

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file verStream.c.

276{
277 assert( !p->fStop );
278 // check if the new data should to be loaded
279 if ( p->pBufferCur > p->pBufferStop )
280 Ver_StreamReload( p );
281 // check if there are symbols left
282 if ( p->pBufferCur == p->pBufferEnd ) // end of file
283 {
284 p->fStop = 1;
285 return -1;
286 }
287 // count the lines
288 if ( *p->pBufferCur == '\n' )
289 p->nLineCounter++;
290 return *p->pBufferCur++;
291}
Here is the caller graph for this function:

◆ Ver_StreamScanChar()

char Ver_StreamScanChar ( Ver_Stream_t * p)

Function*************************************************************

Synopsis [Returns current symbol.]

Description []

SideEffects []

SeeAlso []

Definition at line 258 of file verStream.c.

259{
260 assert( !p->fStop );
261 return *p->pBufferCur;
262}
Here is the caller graph for this function:

◆ Ver_StreamSkipChars()

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 304 of file verStream.c.

305{
306 char * pChar, * pTemp;
307 assert( !p->fStop );
308 assert( pCharsToSkip != NULL );
309 // check if the new data should to be loaded
310 if ( p->pBufferCur > p->pBufferStop )
311 Ver_StreamReload( p );
312 // skip the symbols
313 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ )
314 {
315 // skip symbols as long as they are in the list
316 for ( pTemp = pCharsToSkip; *pTemp; pTemp++ )
317 if ( *pChar == *pTemp )
318 break;
319 if ( *pTemp == 0 ) // pChar is not found in the list
320 {
321 p->pBufferCur = pChar;
322 return;
323 }
324 // count the lines
325 if ( *pChar == '\n' )
326 p->nLineCounter++;
327 }
328 // the file is finished or the last part continued
329 // through VER_OFFSET_SIZE chars till the end of the buffer
330 if ( p->pBufferStop == p->pBufferEnd ) // end of file
331 {
332 p->fStop = 1;
333 return;
334 }
335 printf( "Ver_StreamSkipSymbol() failed to parse the file \"%s\".\n", p->pFileName );
336}
Here is the caller graph for this function:

◆ Ver_StreamSkipToChars()

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 349 of file verStream.c.

350{
351 char * pChar, * pTemp;
352 assert( !p->fStop );
353 assert( pCharsToStop != NULL );
354 // check if the new data should to be loaded
355 if ( p->pBufferCur > p->pBufferStop )
356 Ver_StreamReload( p );
357 // skip the symbols
358 for ( pChar = p->pBufferCur; pChar < p->pBufferEnd; pChar++ )
359 {
360 // skip symbols as long as they are NOT in the list
361 for ( pTemp = pCharsToStop; *pTemp; pTemp++ )
362 if ( *pChar == *pTemp )
363 break;
364 if ( *pTemp == 0 ) // pChar is not found in the list
365 {
366 // count the lines
367 if ( *pChar == '\n' )
368 p->nLineCounter++;
369 continue;
370 }
371 // the symbol is found - move position and return
372 p->pBufferCur = pChar;
373 return;
374 }
375 // the file is finished or the last part continued
376 // through VER_OFFSET_SIZE chars till the end of the buffer
377 if ( p->pBufferStop == p->pBufferEnd ) // end of file
378 {
379 p->fStop = 1;
380 return;
381 }
382 printf( "Ver_StreamSkipToSymbol() failed to parse the file \"%s\".\n", p->pFileName );
383}
Here is the caller graph for this function: