abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ver.h File Reference
#include <stdio.h>
#include "base/abc/abc.h"

Go to the source code of this file.

Data Structures

struct  Ver_Man_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_HEADER_START
struct Ver_Man_t_ 
Ver_Man_t
 INCLUDES ///. More...
 
typedef struct Ver_Stream_t_ Ver_Stream_t
 

Functions

Abc_Des_tVer_ParseFile (char *pFileName, Abc_Des_t *pGateLib, int fCheck, int fUseMemMan)
 MACRO DEFINITIONS ///. More...
 
void Ver_ParsePrintErrorMessage (Ver_Man_t *p)
 
void * Ver_FormulaParser (char *pFormula, void *pMan, Vec_Ptr_t *vNames, Vec_Ptr_t *vStackFn, Vec_Int_t *vStackOp, char *pErrorMessage)
 FUNCTION DEFINITIONS ///. More...
 
void * Ver_FormulaReduction (char *pFormula, void *pMan, Vec_Ptr_t *vNames, char *pErrorMessage)
 
int Ver_ParseSkipComments (Ver_Man_t *p)
 DECLARATIONS ///. More...
 
char * Ver_ParseGetName (Ver_Man_t *p)
 
Ver_Stream_tVer_StreamAlloc (char *pFileName)
 FUNCTION DEFINITIONS ///. More...
 
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)
 

Typedef Documentation

typedef typedefABC_NAMESPACE_HEADER_START struct Ver_Man_t_ Ver_Man_t

INCLUDES ///.

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

FileName [ver.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Verilog parser.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - August 19, 2006.]

Revision [

Id:
ver.h,v 1.00 2006/08/19 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Definition at line 45 of file ver.h.

typedef struct Ver_Stream_t_ Ver_Stream_t

Definition at line 46 of file ver.h.

Function Documentation

void* Ver_FormulaParser ( char *  pFormula,
void *  pMan,
Vec_Ptr_t vNames,
Vec_Ptr_t vStackFn,
Vec_Int_t vStackOp,
char *  pErrorMessage 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Parser of the formula encountered in assign statements.]

Description []

SideEffects []

SeeAlso []

Definition at line 76 of file verFormula.c.

77 {
78  char * pTemp;
79  Hop_Obj_t * bFunc, * bTemp;
80  int nParans, Flag;
81  int Oper, Oper1, Oper2;
82  int v;
83 
84  // clear the stacks and the names
85  Vec_PtrClear( vNames );
86  Vec_PtrClear( vStackFn );
87  Vec_IntClear( vStackOp );
88 
89  if ( !strcmp(pFormula, "0") || !strcmp(pFormula, "1\'b0") )
90  return Hop_ManConst0((Hop_Man_t *)pMan);
91  if ( !strcmp(pFormula, "1") || !strcmp(pFormula, "1\'b1") )
92  return Hop_ManConst1((Hop_Man_t *)pMan);
93 
94  // make sure that the number of opening and closing parantheses is the same
95  nParans = 0;
96  for ( pTemp = pFormula; *pTemp; pTemp++ )
97  if ( *pTemp == '(' )
98  nParans++;
99  else if ( *pTemp == ')' )
100  nParans--;
101  if ( nParans != 0 )
102  {
103  sprintf( pErrorMessage, "Parse_FormulaParser(): Different number of opening and closing parantheses ()." );
104  return NULL;
105  }
106 
107  // add parantheses
108  pTemp = pFormula + strlen(pFormula) + 2;
109  *pTemp-- = 0; *pTemp = ')';
110  while ( --pTemp != pFormula )
111  *pTemp = *(pTemp - 1);
112  *pTemp = '(';
113 
114  // perform parsing
115  Flag = VER_PARSE_FLAG_START;
116  for ( pTemp = pFormula; *pTemp; pTemp++ )
117  {
118  switch ( *pTemp )
119  {
120  // skip all spaces, tabs, and end-of-lines
121  case ' ':
122  case '\t':
123  case '\r':
124  case '\n':
125  continue;
126 /*
127  // treat Constant 0 as a variable
128  case VER_PARSE_SYM_CONST0:
129  Vec_PtrPush( vStackFn, Hop_ManConst0(pMan) ); // Cudd_Ref( Hop_ManConst0(pMan) );
130  if ( Flag == VER_PARSE_FLAG_VAR )
131  {
132  sprintf( pErrorMessage, "Parse_FormulaParser(): No operation symbol before constant 0." );
133  Flag = VER_PARSE_FLAG_ERROR;
134  break;
135  }
136  Flag = VER_PARSE_FLAG_VAR;
137  break;
138 
139  // the same for Constant 1
140  case VER_PARSE_SYM_CONST1:
141  Vec_PtrPush( vStackFn, Hop_ManConst1(pMan) ); // Cudd_Ref( Hop_ManConst1(pMan) );
142  if ( Flag == VER_PARSE_FLAG_VAR )
143  {
144  sprintf( pErrorMessage, "Parse_FormulaParser(): No operation symbol before constant 1." );
145  Flag = VER_PARSE_FLAG_ERROR;
146  break;
147  }
148  Flag = VER_PARSE_FLAG_VAR;
149  break;
150 */
153  if ( Flag == VER_PARSE_FLAG_VAR )
154  {// if NEGBEF follows a variable, AND is assumed
155  sprintf( pErrorMessage, "Parse_FormulaParser(): Variable before negation." );
156  Flag = VER_PARSE_FLAG_ERROR;
157  break;
158  }
159  Vec_IntPush( vStackOp, VER_PARSE_OPER_NEG );
160  break;
161 
162  case VER_PARSE_SYM_AND:
163  case VER_PARSE_SYM_OR:
164  case VER_PARSE_SYM_XOR:
165  case VER_PARSE_SYM_MUX1:
166  case VER_PARSE_SYM_MUX2:
167  if ( Flag != VER_PARSE_FLAG_VAR )
168  {
169  sprintf( pErrorMessage, "Parse_FormulaParser(): There is no variable before AND, EXOR, or OR." );
170  Flag = VER_PARSE_FLAG_ERROR;
171  break;
172  }
173  if ( *pTemp == VER_PARSE_SYM_AND )
174  Vec_IntPush( vStackOp, VER_PARSE_OPER_AND );
175  else if ( *pTemp == VER_PARSE_SYM_OR )
176  Vec_IntPush( vStackOp, VER_PARSE_OPER_OR );
177  else if ( *pTemp == VER_PARSE_SYM_XOR )
178  Vec_IntPush( vStackOp, VER_PARSE_OPER_XOR );
179  else if ( *pTemp == VER_PARSE_SYM_MUX1 )
180  Vec_IntPush( vStackOp, VER_PARSE_OPER_MUX );
181 // else if ( *pTemp == VER_PARSE_SYM_MUX2 )
182 // Vec_IntPush( vStackOp, VER_PARSE_OPER_MUX );
183  Flag = VER_PARSE_FLAG_OPER;
184  break;
185 
186  case VER_PARSE_SYM_OPEN:
187  if ( Flag == VER_PARSE_FLAG_VAR )
188  {
189  sprintf( pErrorMessage, "Parse_FormulaParser(): Variable before a paranthesis." );
190  Flag = VER_PARSE_FLAG_ERROR;
191  break;
192  }
193  Vec_IntPush( vStackOp, VER_PARSE_OPER_MARK );
194  // after an opening bracket, it feels like starting over again
195  Flag = VER_PARSE_FLAG_START;
196  break;
197 
198  case VER_PARSE_SYM_CLOSE:
199  if ( Vec_IntSize( vStackOp ) )
200  {
201  while ( 1 )
202  {
203  if ( !Vec_IntSize( vStackOp ) )
204  {
205  sprintf( pErrorMessage, "Parse_FormulaParser(): There is no opening paranthesis\n" );
206  Flag = VER_PARSE_FLAG_ERROR;
207  break;
208  }
209  Oper = Vec_IntPop( vStackOp );
210  if ( Oper == VER_PARSE_OPER_MARK )
211  break;
212  // skip the second MUX operation
213 // if ( Oper == VER_PARSE_OPER_MUX2 )
214 // {
215 // Oper = Vec_IntPop( vStackOp );
216 // assert( Oper == VER_PARSE_OPER_MUX1 );
217 // }
218 
219  // perform the given operation
220  if ( Ver_FormulaParserTopOper( (Hop_Man_t *)pMan, vStackFn, Oper ) == NULL )
221  {
222  sprintf( pErrorMessage, "Parse_FormulaParser(): Unknown operation\n" );
223  return NULL;
224  }
225  }
226  }
227  else
228  {
229  sprintf( pErrorMessage, "Parse_FormulaParser(): There is no opening paranthesis\n" );
230  Flag = VER_PARSE_FLAG_ERROR;
231  break;
232  }
233  if ( Flag != VER_PARSE_FLAG_ERROR )
234  Flag = VER_PARSE_FLAG_VAR;
235  break;
236 
237 
238  default:
239  // scan the next name
240  v = Ver_FormulaParserFindVar( pTemp, vNames );
241  if ( *pTemp == '\\' )
242  pTemp++;
243  pTemp += (int)(ABC_PTRUINT_T)Vec_PtrEntry( vNames, 2*v ) - 1;
244 
245  // assume operation AND, if vars follow one another
246  if ( Flag == VER_PARSE_FLAG_VAR )
247  {
248  sprintf( pErrorMessage, "Parse_FormulaParser(): Incorrect state." );
249  return NULL;
250  }
251  bTemp = Hop_IthVar( (Hop_Man_t *)pMan, v );
252  Vec_PtrPush( vStackFn, bTemp ); // Cudd_Ref( bTemp );
253  Flag = VER_PARSE_FLAG_VAR;
254  break;
255  }
256 
257  if ( Flag == VER_PARSE_FLAG_ERROR )
258  break; // error exit
259  else if ( Flag == VER_PARSE_FLAG_START )
260  continue; // go on parsing
261  else if ( Flag == VER_PARSE_FLAG_VAR )
262  while ( 1 )
263  { // check if there are negations in the OpStack
264  if ( !Vec_IntSize(vStackOp) )
265  break;
266  Oper = Vec_IntPop( vStackOp );
267  if ( Oper != VER_PARSE_OPER_NEG )
268  {
269  Vec_IntPush( vStackOp, Oper );
270  break;
271  }
272  else
273  {
274 // Vec_PtrPush( vStackFn, Cudd_Not(Vec_PtrPop(vStackFn)) );
275  Vec_PtrPush( vStackFn, Hop_Not((Hop_Obj_t *)Vec_PtrPop(vStackFn)) );
276  }
277  }
278  else // if ( Flag == VER_PARSE_FLAG_OPER )
279  while ( 1 )
280  { // execute all the operations in the OpStack
281  // with precedence higher or equal than the last one
282  Oper1 = Vec_IntPop( vStackOp ); // the last operation
283  if ( !Vec_IntSize(vStackOp) )
284  { // if it is the only operation, push it back
285  Vec_IntPush( vStackOp, Oper1 );
286  break;
287  }
288  Oper2 = Vec_IntPop( vStackOp ); // the operation before the last one
289  if ( Oper2 >= Oper1 && !(Oper1 == Oper2 && Oper1 == VER_PARSE_OPER_MUX) )
290  { // if Oper2 precedence is higher or equal, execute it
291  if ( Ver_FormulaParserTopOper( (Hop_Man_t *)pMan, vStackFn, Oper2 ) == NULL )
292  {
293  sprintf( pErrorMessage, "Parse_FormulaParser(): Unknown operation\n" );
294  return NULL;
295  }
296  Vec_IntPush( vStackOp, Oper1 ); // push the last operation back
297  }
298  else
299  { // if Oper2 precedence is lower, push them back and done
300  Vec_IntPush( vStackOp, Oper2 );
301  Vec_IntPush( vStackOp, Oper1 );
302  break;
303  }
304  }
305  }
306 
307  if ( Flag != VER_PARSE_FLAG_ERROR )
308  {
309  if ( Vec_PtrSize(vStackFn) )
310  {
311  bFunc = (Hop_Obj_t *)Vec_PtrPop(vStackFn);
312  if ( !Vec_PtrSize(vStackFn) )
313  if ( !Vec_IntSize(vStackOp) )
314  {
315 // Cudd_Deref( bFunc );
316  return bFunc;
317  }
318  else
319  sprintf( pErrorMessage, "Parse_FormulaParser(): Something is left in the operation stack\n" );
320  else
321  sprintf( pErrorMessage, "Parse_FormulaParser(): Something is left in the function stack\n" );
322  }
323  else
324  sprintf( pErrorMessage, "Parse_FormulaParser(): The input string is empty\n" );
325  }
326 // Cudd_Ref( bFunc );
327 // Cudd_RecursiveDeref( dd, bFunc );
328  return NULL;
329 }
#define VER_PARSE_SYM_MUX1
Definition: verFormula.c:40
#define VER_PARSE_OPER_MARK
Definition: verFormula.c:50
#define VER_PARSE_SYM_AND
Definition: verFormula.c:37
#define VER_PARSE_OPER_AND
Definition: verFormula.c:45
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
#define VER_PARSE_FLAG_START
Definition: verFormula.c:53
#define VER_PARSE_OPER_MUX
Definition: verFormula.c:49
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
Definition: hop.h:65
#define VER_PARSE_OPER_NEG
Definition: verFormula.c:44
int strcmp()
#define VER_PARSE_SYM_XOR
Definition: verFormula.c:39
#define VER_PARSE_SYM_OPEN
DECLARATIONS ///.
Definition: verFormula.c:31
#define VER_PARSE_OPER_XOR
Definition: verFormula.c:46
#define VER_PARSE_SYM_NEGBEF1
Definition: verFormula.c:35
#define VER_PARSE_FLAG_ERROR
Definition: verFormula.c:56
#define VER_PARSE_SYM_MUX2
Definition: verFormula.c:41
#define VER_PARSE_FLAG_OPER
Definition: verFormula.c:55
#define VER_PARSE_FLAG_VAR
Definition: verFormula.c:54
static int Vec_IntPop(Vec_Int_t *p)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * sprintf()
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Hop_Obj_t * Ver_FormulaParserTopOper(Hop_Man_t *pMan, Vec_Ptr_t *vStackFn, int Oper)
Definition: verFormula.c:342
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define VER_PARSE_SYM_CLOSE
Definition: verFormula.c:32
static int Ver_FormulaParserFindVar(char *pString, Vec_Ptr_t *vNames)
Definition: verFormula.c:384
#define VER_PARSE_OPER_OR
Definition: verFormula.c:47
#define VER_PARSE_SYM_NEGBEF2
Definition: verFormula.c:36
#define VER_PARSE_SYM_OR
Definition: verFormula.c:38
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int strlen()
static Hop_Obj_t * Hop_ManConst0(Hop_Man_t *p)
Definition: hop.h:131
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
void* Ver_FormulaReduction ( char *  pFormula,
void *  pMan,
Vec_Ptr_t vNames,
char *  pErrorMessage 
)

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

Synopsis [Returns the AIG representation of the reduction formula.]

Description []

SideEffects []

SeeAlso []

Definition at line 435 of file verFormula.c.

436 {
437  Hop_Obj_t * pRes = NULL;
438  int v, fCompl;
439  char Symbol;
440 
441  // get the operation
442  Symbol = *pFormula++;
443  fCompl = ( Symbol == '~' );
444  if ( fCompl )
445  Symbol = *pFormula++;
446  // check the operation
447  if ( Symbol != '&' && Symbol != '|' && Symbol != '^' )
448  {
449  sprintf( pErrorMessage, "Ver_FormulaReduction(): Unknown operation (%c)\n", Symbol );
450  return NULL;
451  }
452  // skip the brace
453  while ( *pFormula++ != '{' );
454  // parse the names
455  Vec_PtrClear( vNames );
456  while ( *pFormula != '}' )
457  {
458  v = Ver_FormulaParserFindVar( pFormula, vNames );
459  pFormula += (int)(ABC_PTRUINT_T)Vec_PtrEntry( vNames, 2*v );
460  while ( *pFormula == ' ' || *pFormula == ',' )
461  pFormula++;
462  }
463  // compute the function
464  if ( Symbol == '&' )
465  pRes = Hop_CreateAnd( (Hop_Man_t *)pMan, Vec_PtrSize(vNames)/2 );
466  else if ( Symbol == '|' )
467  pRes = Hop_CreateOr( (Hop_Man_t *)pMan, Vec_PtrSize(vNames)/2 );
468  else if ( Symbol == '^' )
469  pRes = Hop_CreateExor( (Hop_Man_t *)pMan, Vec_PtrSize(vNames)/2 );
470  return Hop_NotCond( pRes, fCompl );
471 }
Hop_Obj_t * Hop_CreateExor(Hop_Man_t *p, int nVars)
Definition: hopOper.c:362
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: hop.h:65
Hop_Obj_t * Hop_CreateAnd(Hop_Man_t *p, int nVars)
Definition: hopOper.c:320
char * sprintf()
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
Hop_Obj_t * Hop_CreateOr(Hop_Man_t *p, int nVars)
Definition: hopOper.c:341
static int Ver_FormulaParserFindVar(char *pString, Vec_Ptr_t *vNames)
Definition: verFormula.c:384
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Abc_Des_t* Ver_ParseFile ( char *  pFileName,
Abc_Des_t pGateLib,
int  fCheck,
int  fUseMemMan 
)

MACRO DEFINITIONS ///.

ITERATORS ///FUNCTION DECLARATIONS ///

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

Synopsis [File parser.]

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file verCore.c.

166 {
167  Ver_Man_t * p;
168  Abc_Des_t * pDesign;
169  // start the parser
170  p = Ver_ParseStart( pFileName, pGateLib );
171  p->fMapped = glo_fMapped;
172  p->fCheck = fCheck;
173  p->fUseMemMan = fUseMemMan;
174  if ( glo_fMapped )
175  {
176  Hop_ManStop((Hop_Man_t *)p->pDesign->pManFunc);
177  p->pDesign->pManFunc = NULL;
178  }
179  // parse the file
180  Ver_ParseInternal( p );
181  // save the result
182  pDesign = p->pDesign;
183  p->pDesign = NULL;
184  // stop the parser
185  Ver_ParseStop( p );
186  return pDesign;
187 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int glo_fMapped
Definition: verCore.c:80
static void Ver_ParseInternal(Ver_Man_t *p)
Definition: verCore.c:200
static void Ver_ParseStop(Ver_Man_t *p)
Definition: verCore.c:142
void Hop_ManStop(Hop_Man_t *p)
Definition: hopMan.c:84
typedefABC_NAMESPACE_HEADER_START struct Ver_Man_t_ Ver_Man_t
INCLUDES ///.
Definition: ver.h:45
static Ver_Man_t * Ver_ParseStart(char *pFileName, Abc_Des_t *pGateLib)
FUNCTION DEFINITIONS ///.
Definition: verCore.c:104
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
char* Ver_ParseGetName ( Ver_Man_t pMan)

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

Synopsis [Parses a Verilog name that can be being with a slash.]

Description []

SideEffects []

SeeAlso []

Definition at line 91 of file verParse.c.

92 {
93  Ver_Stream_t * p = pMan->pReader;
94  char Symbol;
95  char * pWord;
96  pMan->fNameLast = 0;
97  if ( !Ver_StreamIsOkey(p) )
98  return NULL;
99  if ( !Ver_ParseSkipComments( pMan ) )
100  return NULL;
101  Symbol = Ver_StreamScanChar( p );
102  if ( Symbol == '\\' )
103  {
104  pMan->fNameLast = 1;
105  Ver_StreamPopChar( p );
106  pWord = Ver_StreamGetWord( p, " \r\n" );
107  Ver_StreamSkipChars( p, " \r\n" );
108  if ( Ver_StreamScanChar(p) == '[' )
109  {
110  char This, * pEnd = pWord + strlen( pWord );
111  while ( (This = Ver_StreamPopChar(p)) != ']' )
112  *pEnd++ = This;
113  *pEnd++ = This;
114  *pEnd = 0;
115  }
116  }
117  else
118  pWord = Ver_StreamGetWord( p, " \t\n\r(),;" );
119  if ( Ver_StreamIsOkey(p) && !Ver_ParseSkipComments( pMan ) )
120  return NULL;
121  return pWord;
122 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char Ver_StreamPopChar(Ver_Stream_t *p)
Definition: verStream.c:275
char * Ver_StreamGetWord(Ver_Stream_t *p, char *pCharsToStop)
Definition: verStream.c:397
char Ver_StreamScanChar(Ver_Stream_t *p)
Definition: verStream.c:258
int Ver_StreamIsOkey(Ver_Stream_t *p)
Definition: verStream.c:242
void Ver_StreamSkipChars(Ver_Stream_t *p, char *pCharsToSkip)
Definition: verStream.c:304
ABC_NAMESPACE_IMPL_START int Ver_ParseSkipComments(Ver_Man_t *pMan)
DECLARATIONS ///.
Definition: verParse.c:45
int strlen()
void Ver_ParsePrintErrorMessage ( Ver_Man_t p)

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

Synopsis [Prints the error message including the file name and line number.]

Description []

SideEffects []

SeeAlso []

Definition at line 278 of file verCore.c.

279 {
280  p->fError = 1;
281  if ( p->fTopLevel ) // the line number is not given
282  fprintf( p->Output, "%s: %s\n", p->pFileName, p->sError );
283  else // print the error message with the line number
284  fprintf( p->Output, "%s (line %d): %s\n",
285  p->pFileName, Ver_StreamGetLineNumber(p->pReader), p->sError );
286  // free the data
287  Ver_ParseFreeData( p );
288 }
int Ver_StreamGetLineNumber(Ver_Stream_t *p)
Definition: verStream.c:224
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Ver_ParseFreeData(Ver_Man_t *p)
Definition: verCore.c:258
int Ver_ParseSkipComments ( Ver_Man_t pMan)

DECLARATIONS ///.

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

FileName [verParse.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Verilog parser.]

Synopsis [Performs some Verilog parsing tasks.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - August 19, 2006.]

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Skips the comments of they are present.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file verParse.c.

46 {
47  Ver_Stream_t * p = pMan->pReader;
48  char Symbol;
49  // skip spaces
50  Ver_StreamSkipChars( p, " \t\n\r" );
51  if ( !Ver_StreamIsOkey(pMan->pReader) )
52  return 1;
53  // read the first symbol
54  Symbol = Ver_StreamScanChar( p );
55  if ( Symbol != '/' )
56  return 1;
57  Ver_StreamPopChar( p );
58  // read the second symbol
59  Symbol = Ver_StreamScanChar( p );
60  if ( Symbol == '/' )
61  { // skip till the end of line
62  Ver_StreamSkipToChars( p, "\n" );
63  return Ver_ParseSkipComments( pMan );
64  }
65  if ( Symbol == '*' )
66  { // skip till the next occurrence of */
67  Ver_StreamPopChar( p );
68  do {
69  Ver_StreamSkipToChars( p, "*" );
70  Ver_StreamPopChar( p );
71  } while ( Ver_StreamScanChar( p ) != '/' );
72  Ver_StreamPopChar( p );
73  return Ver_ParseSkipComments( pMan );
74  }
75  sprintf( pMan->sError, "Cannot parse after symbol \"/\"." );
77  return 0;
78 }
void Ver_ParsePrintErrorMessage(Ver_Man_t *p)
Definition: verCore.c:278
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char Ver_StreamPopChar(Ver_Stream_t *p)
Definition: verStream.c:275
char Ver_StreamScanChar(Ver_Stream_t *p)
Definition: verStream.c:258
void Ver_StreamSkipToChars(Ver_Stream_t *p, char *pCharsToStop)
Definition: verStream.c:349
int Ver_StreamIsOkey(Ver_Stream_t *p)
Definition: verStream.c:242
char * sprintf()
void Ver_StreamSkipChars(Ver_Stream_t *p, char *pCharsToSkip)
Definition: verStream.c:304
ABC_NAMESPACE_IMPL_START int Ver_ParseSkipComments(Ver_Man_t *pMan)
DECLARATIONS ///.
Definition: verParse.c:45
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 {
76  Ver_Stream_t * p;
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 );
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;
108  // start the arrays
109  p->nLineCounter = 1; // 1-based line counting
110  return p;
111 }
char * memset()
char * pBufferEnd
Definition: verStream.c:48
static Llb_Mgr_t * p
Definition: llb3Image.c:950
iword nLineCounter
Definition: verStream.c:43
#define SEEK_END
Definition: zconf.h:392
char * pBuffer
Definition: verStream.c:46
iword nBufferSize
Definition: verStream.c:45
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define VER_BUFFER_SIZE
DECLARATIONS ///.
Definition: verStream.c:30
iword nFileSize
Definition: verStream.c:41
char * pBufferCur
Definition: verStream.c:47
FILE * pFile
Definition: verStream.c:40
char * pBufferStop
Definition: verStream.c:49
iword nFileRead
Definition: verStream.c:42
#define VER_MINIMUM(a, b)
Definition: verStream.c:34
char * pFileName
Definition: verStream.c:39
#define VER_OFFSET_SIZE
Definition: verStream.c:31
VOID_HACK rewind()
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 }
char * pBuffer
Definition: verStream.c:46
FILE * pFile
Definition: verStream.c:40
#define ABC_FREE(obj)
Definition: abc_global.h:232
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 }
char * pBufferEnd
Definition: verStream.c:48
char * pBufferCur
Definition: verStream.c:47
iword nFileRead
Definition: verStream.c:42
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 }
char * pFileName
Definition: verStream.c:39
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 }
iword nFileSize
Definition: verStream.c:41
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 }
iword nLineCounter
Definition: verStream.c:43
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 }
char * pBufferEnd
Definition: verStream.c:48
iword nLineCounter
Definition: verStream.c:43
static void Ver_StreamReload(Ver_Stream_t *p)
Definition: verStream.c:124
char pChars[VER_WORD_SIZE+5]
Definition: verStream.c:51
char * pBufferCur
Definition: verStream.c:47
char * pBufferStop
Definition: verStream.c:49
char * pFileName
Definition: verStream.c:39
#define VER_WORD_SIZE
Definition: verStream.c:32
#define assert(ex)
Definition: util_old.h:213
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 }
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 }
char * pBufferEnd
Definition: verStream.c:48
iword nLineCounter
Definition: verStream.c:43
static void Ver_StreamReload(Ver_Stream_t *p)
Definition: verStream.c:124
char * pBufferCur
Definition: verStream.c:47
char * pBufferStop
Definition: verStream.c:49
#define assert(ex)
Definition: util_old.h:213
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 }
char * pBufferCur
Definition: verStream.c:47
#define assert(ex)
Definition: util_old.h:213
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 }
char * pBufferEnd
Definition: verStream.c:48
iword nLineCounter
Definition: verStream.c:43
static void Ver_StreamReload(Ver_Stream_t *p)
Definition: verStream.c:124
char * pBufferCur
Definition: verStream.c:47
char * pBufferStop
Definition: verStream.c:49
char * pFileName
Definition: verStream.c:39
#define assert(ex)
Definition: util_old.h:213
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 }
char * pBufferEnd
Definition: verStream.c:48
iword nLineCounter
Definition: verStream.c:43
static void Ver_StreamReload(Ver_Stream_t *p)
Definition: verStream.c:124
char * pBufferCur
Definition: verStream.c:47
char * pBufferStop
Definition: verStream.c:49
char * pFileName
Definition: verStream.c:39
#define assert(ex)
Definition: util_old.h:213