ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
extraUtilReader.c File Reference
#include <stdio.h>
#include "extra.h"
#include "misc/vec/vec.h"
Include dependency graph for extraUtilReader.c:

Go to the source code of this file.

Classes

struct  Extra_FileReader_t_
 

Macros

#define EXTRA_BUFFER_SIZE   4*1048576
 DECLARATIONS ///.
 
#define EXTRA_OFFSET_SIZE   4096
 
#define EXTRA_MINIMUM(a, b)
 

Enumerations

enum  Extra_CharType_t { EXTRA_CHAR_COMMENT , EXTRA_CHAR_NORMAL , EXTRA_CHAR_STOP , EXTRA_CHAR_CLEAN }
 

Functions

Extra_FileReader_tExtra_FileReaderAlloc (char *pFileName, char *pCharsComment, char *pCharsStop, char *pCharsClean)
 FUNCTION DEFINITIONS ///.
 
void Extra_FileReaderFree (Extra_FileReader_t *p)
 
char * Extra_FileReaderGetFileName (Extra_FileReader_t *p)
 
int Extra_FileReaderGetFileSize (Extra_FileReader_t *p)
 
int Extra_FileReaderGetCurPosition (Extra_FileReader_t *p)
 
int Extra_FileReaderGetLineNumber (Extra_FileReader_t *p, int iToken)
 
void * Extra_FileReaderGetTokens (Extra_FileReader_t *p)
 

Macro Definition Documentation

◆ EXTRA_BUFFER_SIZE

#define EXTRA_BUFFER_SIZE   4*1048576

DECLARATIONS ///.

CFile****************************************************************

FileName [extraUtilReader.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [File reading utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
extraUtilReader.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 35 of file extraUtilReader.c.

◆ EXTRA_MINIMUM

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

Definition at line 38 of file extraUtilReader.c.

◆ EXTRA_OFFSET_SIZE

#define EXTRA_OFFSET_SIZE   4096

Definition at line 36 of file extraUtilReader.c.

Enumeration Type Documentation

◆ Extra_CharType_t

Enumerator
EXTRA_CHAR_COMMENT 
EXTRA_CHAR_NORMAL 
EXTRA_CHAR_STOP 
EXTRA_CHAR_CLEAN 

Definition at line 64 of file extraUtilReader.c.

64 {
65 EXTRA_CHAR_COMMENT, // a character that begins the comment
66 EXTRA_CHAR_NORMAL, // a regular character
67 EXTRA_CHAR_STOP, // a character that delimits a series of tokens
68 EXTRA_CHAR_CLEAN // a character that should be cleaned
Extra_CharType_t
@ EXTRA_CHAR_STOP
@ EXTRA_CHAR_CLEAN
@ EXTRA_CHAR_COMMENT
@ EXTRA_CHAR_NORMAL

Function Documentation

◆ Extra_FileReaderAlloc()

Extra_FileReader_t * Extra_FileReaderAlloc ( char * pFileName,
char * pCharsComment,
char * pCharsStop,
char * pCharsClean )

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the file reader.]

Description []

SideEffects []

SeeAlso []

Definition at line 90 of file extraUtilReader.c.

92{
94 FILE * pFile;
95 char * pChar;
96 int nCharsToRead;
97 int RetValue;
98 // check if the file can be opened
99 pFile = fopen( pFileName, "rb" );
100 if ( pFile == NULL )
101 {
102 printf( "Extra_FileReaderAlloc(): Cannot open input file \"%s\".\n", pFileName );
103 return NULL;
104 }
105 // start the file reader
107 memset( p, 0, sizeof(Extra_FileReader_t) );
108 p->pFileName = pFileName;
109 p->pFile = pFile;
110 // set the character map
111 memset( p->pCharMap, EXTRA_CHAR_NORMAL, 256 );
112 for ( pChar = pCharsComment; *pChar; pChar++ )
113 p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_COMMENT;
114 for ( pChar = pCharsStop; *pChar; pChar++ )
115 p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_STOP;
116 for ( pChar = pCharsClean; *pChar; pChar++ )
117 p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_CLEAN;
118 // get the file size, in bytes
119 fseek( pFile, 0, SEEK_END );
120 p->nFileSize = ftell( pFile );
121 rewind( pFile );
122 // allocate the buffer
123 p->pBuffer = ABC_ALLOC( char, EXTRA_BUFFER_SIZE+1 );
124 p->nBufferSize = EXTRA_BUFFER_SIZE;
125 p->pBufferCur = p->pBuffer;
126 // determine how many chars to read
127 nCharsToRead = EXTRA_MINIMUM(p->nFileSize, EXTRA_BUFFER_SIZE);
128 // load the first part into the buffer
129 RetValue = fread( p->pBuffer, nCharsToRead, 1, p->pFile );
130 p->nFileRead = nCharsToRead;
131 // set the ponters to the end and the stopping point
132 p->pBufferEnd = p->pBuffer + nCharsToRead;
133 p->pBufferStop = (p->nFileRead == p->nFileSize)? p->pBufferEnd : p->pBuffer + EXTRA_BUFFER_SIZE - EXTRA_OFFSET_SIZE;
134 // start the arrays
135 p->vTokens = Vec_PtrAlloc( 100 );
136 p->vLines = Vec_IntAlloc( 100 );
137 p->nLineCounter = 1; // 1-based line counting
138 return p;
139}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
Cube * p
Definition exorList.c:222
#define EXTRA_OFFSET_SIZE
#define EXTRA_MINIMUM(a, b)
#define EXTRA_BUFFER_SIZE
DECLARATIONS ///.
struct Extra_FileReader_t_ Extra_FileReader_t
Definition extra.h:135
char * memset()
VOID_HACK rewind()
#define SEEK_END
Definition zconf.h:392
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileReaderFree()

void Extra_FileReaderFree ( Extra_FileReader_t * p)

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

Synopsis [Stops the file reader.]

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file extraUtilReader.c.

153{
154 if ( p->pFile )
155 fclose( p->pFile );
156 ABC_FREE( p->pBuffer );
157 Vec_PtrFree( p->vTokens );
158 Vec_IntFree( p->vLines );
159 ABC_FREE( p );
160}
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Extra_FileReaderGetCurPosition()

int Extra_FileReaderGetCurPosition ( Extra_FileReader_t * p)

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

Synopsis [Returns the current reading position.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file extraUtilReader.c.

206{
207 return p->nFileRead - (p->pBufferEnd - p->pBufferCur);
208}

◆ Extra_FileReaderGetFileName()

char * Extra_FileReaderGetFileName ( Extra_FileReader_t * p)

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

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 173 of file extraUtilReader.c.

174{
175 return p->pFileName;
176}

◆ Extra_FileReaderGetFileSize()

int Extra_FileReaderGetFileSize ( Extra_FileReader_t * p)

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

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 189 of file extraUtilReader.c.

190{
191 return p->nFileSize;
192}

◆ Extra_FileReaderGetLineNumber()

int Extra_FileReaderGetLineNumber ( Extra_FileReader_t * p,
int iToken )

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 221 of file extraUtilReader.c.

222{
223 assert( iToken >= 0 && iToken < p->vTokens->nSize );
224 return p->vLines->pArray[iToken];
225}
#define assert(ex)
Definition util_old.h:213

◆ Extra_FileReaderGetTokens()

void * Extra_FileReaderGetTokens ( Extra_FileReader_t * p)

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

Synopsis [Returns the next set of tokens.]

Description []

SideEffects []

SeeAlso []

Definition at line 239 of file extraUtilReader.c.

240{
241 Vec_Ptr_t * vTokens;
242 while ( (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens_int( p )) )
243 if ( vTokens->nSize > 0 )
244 break;
245 return vTokens;
246}
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42