abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wlcReadVer.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [wlcReadVer.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Verilog parser.]
8 
9  Synopsis [Parses several flavors of word-level Verilog.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - August 22, 2014.]
16 
17  Revision [$Id: wlcReadVer.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "wlc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // Word-level Verilog file parser
31 #define WLV_PRS_MAX_LINE 1000
32 
33 typedef struct Wlc_Prs_t_ Wlc_Prs_t;
34 struct Wlc_Prs_t_
35 {
36  int nFileSize;
37  char * pFileName;
38  char * pBuffer;
45  int nConsts;
47 };
48 
49 static inline int Wlc_PrsOffset( Wlc_Prs_t * p, char * pStr ) { return pStr - p->pBuffer; }
50 static inline char * Wlc_PrsStr( Wlc_Prs_t * p, int iOffset ) { return p->pBuffer + iOffset; }
51 static inline int Wlc_PrsStrCmp( char * pStr, char * pWhat ) { return !strncmp( pStr, pWhat, strlen(pWhat)); }
52 
53 #define Wlc_PrsForEachLine( p, pLine, i ) \
54  for ( i = 0; (i < Vec_IntSize((p)->vStarts)) && ((pLine) = Wlc_PrsStr(p, Vec_IntEntry((p)->vStarts, i))); i++ )
55 #define Wlc_PrsForEachLineStart( p, pLine, i, Start ) \
56  for ( i = Start; (i < Vec_IntSize((p)->vStarts)) && ((pLine) = Wlc_PrsStr(p, Vec_IntEntry((p)->vStarts, i))); i++ )
57 
58 
59 ////////////////////////////////////////////////////////////////////////
60 /// FUNCTION DEFINITIONS ///
61 ////////////////////////////////////////////////////////////////////////
62 
63 
64 /**Function*************************************************************
65 
66  Synopsis []
67 
68  Description []
69 
70  SideEffects []
71 
72  SeeAlso []
73 
74 ***********************************************************************/
75 Wlc_Prs_t * Wlc_PrsStart( char * pFileName )
76 {
77  Wlc_Prs_t * p;
78  if ( !Extra_FileCheck( pFileName ) )
79  return NULL;
80  p = ABC_CALLOC( Wlc_Prs_t, 1 );
81  p->pFileName = pFileName;
82  p->pBuffer = Extra_FileReadContents( pFileName );
83  p->nFileSize = strlen(p->pBuffer); assert( p->nFileSize > 0 );
84  p->vLines = Vec_IntAlloc( p->nFileSize / 50 );
85  p->vStarts = Vec_IntAlloc( p->nFileSize / 50 );
86  p->vFanins = Vec_IntAlloc( 100 );
87  p->vTables = Vec_PtrAlloc( 1000 );
88  p->pMemTable = Mem_FlexStart();
89  return p;
90 }
92 {
93  if ( p->pNtk )
94  Wlc_NtkFree( p->pNtk );
95  if ( p->pMemTable )
96  Mem_FlexStop( p->pMemTable, 0 );
97  Vec_PtrFreeP( &p->vTables );
98  Vec_IntFree( p->vLines );
99  Vec_IntFree( p->vStarts );
100  Vec_IntFree( p->vFanins );
101  ABC_FREE( p->pBuffer );
102  ABC_FREE( p );
103 }
104 
105 /**Function*************************************************************
106 
107  Synopsis [Prints the error message including the file name and line number.]
108 
109  Description []
110 
111  SideEffects []
112 
113  SeeAlso []
114 
115 ***********************************************************************/
116 int Wlc_PrsWriteErrorMessage( Wlc_Prs_t * p, char * pCur, const char * format, ... )
117 {
118  char * pMessage;
119  // derive message
120  va_list args;
121  va_start( args, format );
122  pMessage = vnsprintf( format, args );
123  va_end( args );
124  // print messsage
125  assert( strlen(pMessage) < WLV_PRS_MAX_LINE - 100 );
126  assert( p->sError[0] == 0 );
127  if ( pCur == NULL ) // the line number is not given
128  sprintf( p->sError, "%s: %s\n", p->pFileName, pMessage );
129  else // print the error message with the line number
130  {
131  int Entry, iLine = 0;
132  Vec_IntForEachEntry( p->vLines, Entry, iLine )
133  if ( Entry > pCur - p->pBuffer )
134  break;
135  sprintf( p->sError, "%s (line %d): %s\n", p->pFileName, iLine+1, pMessage );
136  }
137  ABC_FREE( pMessage );
138  return 0;
139 }
141 {
142  if ( p->sError[0] == 0 )
143  return;
144  fprintf( stdout, "%s", p->sError );
145 }
146 
147 /**Function*************************************************************
148 
149  Synopsis []
150 
151  Description []
152 
153  SideEffects []
154 
155  SeeAlso []
156 
157 ***********************************************************************/
158 static inline int Wlc_PrsIsDigit( char * pStr )
159 {
160  return (pStr[0] >= '0' && pStr[0] <= '9');
161 }
162 static inline int Wlc_PrsIsChar( char * pStr )
163 {
164  return (pStr[0] >= 'a' && pStr[0] <= 'z') ||
165  (pStr[0] >= 'A' && pStr[0] <= 'Z') ||
166  (pStr[0] >= '0' && pStr[0] <= '9') ||
167  pStr[0] == '_' || pStr[0] == '$' || pStr[0] == '\\';
168 }
169 static inline char * Wlc_PrsSkipSpaces( char * pStr )
170 {
171  while ( *pStr && *pStr == ' ' )
172  pStr++;
173  return pStr;
174 }
175 static inline char * Wlc_PrsFindSymbol( char * pStr, char Symb )
176 {
177  int fNotName = 1;
178  for ( ; *pStr; pStr++ )
179  {
180  if ( fNotName && *pStr == Symb )
181  return pStr;
182  if ( pStr[0] == '\\' )
183  fNotName = 0;
184  else if ( !fNotName && *pStr == ' ' )
185  fNotName = 1;
186  }
187  return NULL;
188 }
189 static inline char * Wlc_PrsFindSymbolTwo( char * pStr, char Symb, char Symb2 )
190 {
191  for ( ; pStr[1]; pStr++ )
192  if ( pStr[0] == Symb && pStr[1] == Symb2 )
193  return pStr;
194  return NULL;
195 }
196 static inline char * Wlc_PrsFindClosingParanthesis( char * pStr, char Open, char Close )
197 {
198  int Counter = 0;
199  int fNotName = 1;
200  assert( *pStr == Open );
201  for ( ; *pStr; pStr++ )
202  {
203  if ( fNotName )
204  {
205  if ( *pStr == Open )
206  Counter++;
207  if ( *pStr == Close )
208  Counter--;
209  if ( Counter == 0 )
210  return pStr;
211  }
212  if ( *pStr == '\\' )
213  fNotName = 0;
214  else if ( !fNotName && *pStr == ' ' )
215  fNotName = 1;
216  }
217  return NULL;
218 }
220 {
221  int fSpecifyFound = 0;
222  char * pCur, * pNext, * pEnd = p->pBuffer + p->nFileSize;
223  for ( pCur = p->pBuffer; pCur < pEnd; pCur++ )
224  {
225  // regular comment (//)
226  if ( *pCur == '/' && pCur[1] == '/' )
227  {
228  if ( pCur + 5 < pEnd && pCur[2] == 'a' && pCur[3] == 'b' && pCur[4] == 'c' && pCur[5] == '2' )
229  pCur[0] = pCur[1] = pCur[2] = pCur[3] = pCur[4] = pCur[5] = ' ';
230  else
231  {
232  pNext = Wlc_PrsFindSymbol( pCur, '\n' );
233  if ( pNext == NULL )
234  return Wlc_PrsWriteErrorMessage( p, pCur, "Cannot find end-of-line after symbols \"//\"." );
235  for ( ; pCur < pNext; pCur++ )
236  *pCur = ' ';
237  }
238  }
239  // skip preprocessor directive (`timescale, `celldefine, etc)
240  else if ( *pCur == '`' )
241  {
242  pNext = Wlc_PrsFindSymbol( pCur, '\n' );
243  if ( pNext == NULL )
244  return Wlc_PrsWriteErrorMessage( p, pCur, "Cannot find end-of-line after symbols \"`\"." );
245  for ( ; pCur < pNext; pCur++ )
246  *pCur = ' ';
247  }
248  // regular comment (/* ... */)
249  else if ( *pCur == '/' && pCur[1] == '*' )
250  {
251  pNext = Wlc_PrsFindSymbolTwo( pCur, '*', '/' );
252  if ( pNext == NULL )
253  return Wlc_PrsWriteErrorMessage( p, pCur, "Cannot find symbols \"*/\" after symbols \"/*\"." );
254  // overwrite comment
255  for ( ; pCur < pNext + 2; pCur++ )
256  *pCur = ' ';
257  }
258  // 'specify' treated as comments
259  else if ( *pCur == 's' && pCur[1] == 'p' && pCur[2] == 'e' && !strncmp(pCur, "specify", 7) )
260  {
261  for ( pNext = pCur; pNext < pEnd - 10; pNext++ )
262  if ( *pNext == 'e' && pNext[1] == 'n' && pNext[2] == 'd' && !strncmp(pNext, "endspecify", 10) )
263  {
264  // overwrite comment
265  for ( ; pCur < pNext + 10; pCur++ )
266  *pCur = ' ';
267  if ( fSpecifyFound == 0 )
268  Abc_Print( 0, "Ignoring specify/endspecify directives.\n" );
269  fSpecifyFound = 1;
270  break;
271  }
272  }
273  // insert semicolons
274  else if ( *pCur == 'e' && pCur[1] == 'n' && pCur[2] == 'd' && !strncmp(pCur, "endmodule", 9) )
275  pCur[strlen("endmodule")] = ';';
276  // overwrite end-of-lines with spaces (less checking to do later on)
277  if ( *pCur == '\n' || *pCur == '\r' || *pCur == '\t' )
278  *pCur = ' ';
279  }
280  return 1;
281 }
283 {
284  int fPrettyPrint = 0;
285  int fNotName = 1;
286  char * pTemp, * pPrev, * pThis;
287  // collect info about lines
288  assert( Vec_IntSize(p->vLines) == 0 );
289  for ( pTemp = p->pBuffer; *pTemp; pTemp++ )
290  if ( *pTemp == '\n' )
291  Vec_IntPush( p->vLines, pTemp - p->pBuffer );
292  // delete comments and insert breaks
293  if ( !Wlc_PrsRemoveComments( p ) )
294  return 0;
295  // collect info about breaks
296  assert( Vec_IntSize(p->vStarts) == 0 );
297  for ( pPrev = pThis = p->pBuffer; *pThis; pThis++ )
298  {
299  if ( fNotName && *pThis == ';' )
300  {
301  *pThis = 0;
303  pPrev = pThis + 1;
304  }
305  if ( *pThis == '\\' )
306  fNotName = 0;
307  else if ( !fNotName && *pThis == ' ' )
308  fNotName = 1;
309  }
310 
311  if ( fPrettyPrint )
312  {
313  int i, k;
314  // print the line types
315  Wlc_PrsForEachLine( p, pTemp, i )
316  {
317  if ( Wlc_PrsStrCmp( pTemp, "module" ) )
318  printf( "\n" );
319  if ( !Wlc_PrsStrCmp( pTemp, "module" ) && !Wlc_PrsStrCmp( pTemp, "endmodule" ) )
320  printf( " " );
321  printf( "%c", pTemp[0] );
322  for ( k = 1; pTemp[k]; k++ )
323  if ( pTemp[k] != ' ' || pTemp[k-1] != ' ' )
324  printf( "%c", pTemp[k] );
325  printf( ";\n" );
326  }
327 /*
328  // print the line types
329  Wlc_PrsForEachLine( p, pTemp, i )
330  {
331  int k;
332  if ( !Wlc_PrsStrCmp( pTemp, "module" ) )
333  continue;
334  printf( "%3d : ", i );
335  for ( k = 0; k < 40; k++ )
336  printf( "%c", pTemp[k] ? pTemp[k] : ' ' );
337  printf( "\n" );
338  }
339 */
340  }
341  return 1;
342 }
343 
344 /**Function*************************************************************
345 
346  Synopsis [Modified version of strtok().]
347 
348  Description []
349 
350  SideEffects []
351 
352  SeeAlso []
353 
354 ***********************************************************************/
355 char * Wlc_PrsStrtok( char * s, const char * delim )
356 {
357  const char *spanp;
358  int c, sc;
359  char *tok;
360  static char *last;
361  if (s == NULL && (s = last) == NULL)
362  return NULL;
363  // skip leading delimiters
364 cont:
365  c = *s++;
366  for (spanp = delim; (sc = *spanp++) != 0;)
367  if (c == sc)
368  goto cont;
369  if (c == 0) // no non-delimiter characters
370  return (last = NULL);
371 // tok = s - 1;
372  if ( c != '\\' )
373  tok = s - 1;
374  else
375  tok = s - 1;
376  // go back to the first non-delimiter character
377  s--;
378  // find the token
379  for (;;)
380  {
381  c = *s++;
382  if ( c == '\\' ) // skip blind characters
383  {
384  while ( c != ' ' )
385  c = *s++;
386  c = *s++;
387  }
388  spanp = delim;
389  do {
390  if ((sc = *spanp++) == c)
391  {
392  if (c == 0)
393  s = NULL;
394  else
395  s[-1] = 0;
396  last = s;
397  return (tok);
398  }
399  } while (sc != 0);
400  }
401  // not reached
402  return NULL;
403 }
404 
405 /**Function*************************************************************
406 
407  Synopsis []
408 
409  Description []
410 
411  SideEffects []
412 
413  SeeAlso []
414 
415 ***********************************************************************/
416 static inline char * Wlc_PrsFindRange( char * pStr, int * End, int * Beg )
417 {
418  *End = *Beg = 0;
419  pStr = Wlc_PrsSkipSpaces( pStr );
420  if ( pStr[0] != '[' )
421  return pStr;
422  pStr = Wlc_PrsSkipSpaces( pStr+1 );
423  if ( !Wlc_PrsIsDigit(pStr) )
424  return NULL;
425  *End = *Beg = atoi( pStr );
426  if ( Wlc_PrsFindSymbol( pStr, ':' ) == NULL )
427  {
428  pStr = Wlc_PrsFindSymbol( pStr, ']' );
429  if ( pStr == NULL )
430  return NULL;
431  }
432  else
433  {
434  pStr = Wlc_PrsFindSymbol( pStr, ':' );
435  pStr = Wlc_PrsSkipSpaces( pStr+1 );
436  if ( !Wlc_PrsIsDigit(pStr) )
437  return NULL;
438  *Beg = atoi( pStr );
439  pStr = Wlc_PrsFindSymbol( pStr, ']' );
440  if ( pStr == NULL )
441  return NULL;
442  }
443  assert( *End >= *Beg );
444  return pStr + 1;
445 }
446 static inline char * Wlc_PrsFindWord( char * pStr, char * pWord, int * fFound )
447 {
448  *fFound = 0;
449  pStr = Wlc_PrsSkipSpaces( pStr );
450  if ( !Wlc_PrsStrCmp(pStr, pWord) )
451  return pStr;
452  *fFound = 1;
453  return pStr + strlen(pWord);
454 }
455 static inline char * Wlc_PrsFindName( char * pStr, char ** ppPlace )
456 {
457  static char Buffer[WLV_PRS_MAX_LINE];
458  char * pThis = *ppPlace = Buffer;
459  int fNotName = 1;
460  pStr = Wlc_PrsSkipSpaces( pStr );
461  if ( !Wlc_PrsIsChar(pStr) )
462  return NULL;
463 // while ( Wlc_PrsIsChar(pStr) )
464 // *pThis++ = *pStr++;
465  while ( *pStr )
466  {
467  if ( fNotName && !Wlc_PrsIsChar(pStr) )
468  break;
469  if ( *pStr == '\\' )
470  fNotName = 0;
471  else if ( !fNotName && *pStr == ' ' )
472  fNotName = 1;
473  *pThis++ = *pStr++;
474  }
475  *pThis = 0;
476  return pStr;
477 }
478 static inline char * Wlc_PrsReadConstant( Wlc_Prs_t * p, char * pStr, Vec_Int_t * vFanins, int * pRange, int * pSigned )
479 {
480  int i, nDigits, nBits = atoi( pStr );
481  *pRange = -1;
482  *pSigned = 0;
483  pStr = Wlc_PrsSkipSpaces( pStr );
484  if ( Wlc_PrsFindSymbol( pStr, '\'' ) == NULL )
485  {
486  // handle decimal number
487  int Number = atoi( pStr );
488  *pRange = Abc_Base2Log( Number+1 );
489  assert( *pRange < 32 );
490  while ( Wlc_PrsIsDigit(pStr) )
491  pStr++;
492  Vec_IntFill( vFanins, 1, Number );
493  return pStr;
494  }
495  pStr = Wlc_PrsFindSymbol( pStr, '\'' );
496  if ( pStr[1] == 's' )
497  {
498  *pSigned = 1;
499  pStr++;
500  }
501  if ( pStr[1] == 'b' )
502  {
503  Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
504  for ( i = 0; i < nBits; i++ )
505  if ( pStr[2+i] == '1' )
506  Abc_InfoSetBit( (unsigned *)Vec_IntArray(vFanins), i );
507  else if ( pStr[2+i] != '0' )
508  return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Wrong digit in binary constant \"%c\".", pStr[2+i] );
509  *pRange = nBits;
510  pStr += 2 + nBits;
511  return pStr;
512  }
513  if ( pStr[1] != 'h' )
514  return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Expecting hexadecimal constant and not \"%c\".", pStr[1] );
515  Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
516  nDigits = Abc_TtReadHexNumber( (word *)Vec_IntArray(vFanins), pStr+2 );
517  if ( nDigits != (nBits + 3)/4 )
518  {
519 // return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "The length of a constant does not match." );
520 // printf( "Warning: The length of a constant (%d hex digits) does not match the number of bits (%d).\n", nDigits, nBits );
521  }
522  *pRange = nBits;
523  pStr += 2;
524  while ( Wlc_PrsIsChar(pStr) )
525  pStr++;
526  return pStr;
527 }
528 static inline char * Wlc_PrsReadName( Wlc_Prs_t * p, char * pStr, Vec_Int_t * vFanins )
529 {
530  int NameId, fFound, iObj;
531  pStr = Wlc_PrsSkipSpaces( pStr );
532  if ( Wlc_PrsIsDigit(pStr) )
533  {
534  char Buffer[100];
535  int Range, Signed;
536  Vec_Int_t * vFanins = Vec_IntAlloc(0);
537  pStr = Wlc_PrsReadConstant( p, pStr, vFanins, &Range, &Signed );
538  if ( pStr == NULL )
539  {
540  Vec_IntFree( vFanins );
541  return 0;
542  }
543  // create new node
544  iObj = Wlc_ObjAlloc( p->pNtk, WLC_OBJ_CONST, Signed, Range-1, 0 );
545  Wlc_ObjAddFanins( p->pNtk, Wlc_NtkObj(p->pNtk, iObj), vFanins );
546  Vec_IntFree( vFanins );
547  // add node's name
548  sprintf( Buffer, "_c%d_", p->nConsts++ );
549  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, Buffer, &fFound );
550  if ( fFound )
551  return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Name %s is already used.", Buffer );
552  assert( iObj == NameId );
553  }
554  else
555  {
556  char * pName;
557  pStr = Wlc_PrsFindName( pStr, &pName );
558  if ( pStr == NULL )
559  return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name in assign-statement." );
560  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
561  if ( !fFound )
562  return (char *)(ABC_PTRINT_T)Wlc_PrsWriteErrorMessage( p, pStr, "Name %s is used but not declared.", pName );
563  }
564  Vec_IntPush( vFanins, NameId );
565  return Wlc_PrsSkipSpaces( pStr );
566 }
567 static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * vFanins )
568 {
569  char * pName;
570  int Type = WLC_OBJ_NONE;
571  int fRotating = 0;
572  Vec_IntClear( vFanins );
573  pStr = Wlc_PrsSkipSpaces( pStr );
574  if ( pStr[0] != '=' )
575  return 0;
576  pStr = Wlc_PrsSkipSpaces( pStr+1 );
577  if ( pStr[0] == '(' )
578  {
579  // consider rotating shifter
580  if ( Wlc_PrsFindSymbolTwo(pStr, '>', '>') && Wlc_PrsFindSymbolTwo(pStr, '<', '<') )
581  {
582  // THIS IS A HACK TO DETECT rotating shifters
583  char * pClose = Wlc_PrsFindClosingParanthesis( pStr, '(', ')' );
584  if ( pClose == NULL )
585  return Wlc_PrsWriteErrorMessage( p, pStr, "Expecting closing paranthesis." );
586  *pStr = ' '; *pClose = 0;
587  pStr = Wlc_PrsSkipSpaces( pStr );
588  fRotating = 1;
589  }
590  else
591  {
592  char * pClose = Wlc_PrsFindClosingParanthesis( pStr, '(', ')' );
593  if ( pClose == NULL )
594  return Wlc_PrsWriteErrorMessage( p, pStr, "Expecting closing paranthesis." );
595  *pStr = *pClose = ' ';
596  pStr = Wlc_PrsSkipSpaces( pStr );
597  }
598  }
599  if ( Wlc_PrsIsDigit(pStr) )
600  {
601  int Range, Signed;
602  pStr = Wlc_PrsReadConstant( p, pStr, vFanins, &Range, &Signed );
603  if ( pStr == NULL )
604  return 0;
605  Type = WLC_OBJ_CONST;
606  }
607  else if ( pStr[0] == '!' || pStr[0] == '~' )
608  {
609  if ( pStr[0] == '!' )
610  Type = WLC_OBJ_LOGIC_NOT;
611  else if ( pStr[0] == '~' )
612  Type = WLC_OBJ_BIT_NOT;
613  else assert( 0 );
614  // skip parantheses
615  pStr = Wlc_PrsSkipSpaces( pStr+1 );
616  if ( pStr[0] == '(' )
617  {
618  char * pClose = Wlc_PrsFindClosingParanthesis( pStr, '(', ')' );
619  if ( pClose == NULL )
620  return Wlc_PrsWriteErrorMessage( p, pStr, "Expecting closing paranthesis." );
621  *pStr = *pClose = ' ';
622  }
623  if ( !(pStr = Wlc_PrsReadName(p, pStr, vFanins)) )
624  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after !." );
625  }
626  else if ( pStr[0] == '&' || pStr[0] == '|' || pStr[0] == '^' || pStr[0] == '-' )
627  {
628  if ( pStr[0] == '&' )
629  Type = WLC_OBJ_REDUCT_AND;
630  else if ( pStr[0] == '|' )
631  Type = WLC_OBJ_REDUCT_OR;
632  else if ( pStr[0] == '^' )
633  Type = WLC_OBJ_REDUCT_XOR;
634  else if ( pStr[0] == '-' )
635  Type = WLC_OBJ_ARI_MINUS;
636  else assert( 0 );
637  if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
638  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name after a unary operator." );
639  }
640  else if ( pStr[0] == '{' )
641  {
642  // THIS IS A HACK TO DETECT zero padding AND sign extension
643  if ( Wlc_PrsFindSymbol(pStr+1, '{') )
644  {
645  if ( Wlc_PrsFindSymbol(pStr+1, '\'') )
646  Type = WLC_OBJ_BIT_ZEROPAD;
647  else
648  Type = WLC_OBJ_BIT_SIGNEXT;
649  pStr = Wlc_PrsFindSymbol(pStr+1, ',');
650  if ( pStr == NULL )
651  return Wlc_PrsWriteErrorMessage( p, pStr, "Expecting one comma in this line." );
652  if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
653  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name in sign-extension." );
654  pStr = Wlc_PrsSkipSpaces( pStr );
655  if ( pStr[0] != '}' )
656  return Wlc_PrsWriteErrorMessage( p, pStr, "There is no closing brace (})." );
657  }
658  else // concatenation
659  {
660  while ( 1 )
661  {
662  pStr = Wlc_PrsSkipSpaces( pStr+1 );
663  if ( !(pStr = Wlc_PrsReadName(p, pStr, vFanins)) )
664  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name in concatenation." );
665  if ( pStr[0] == '}' )
666  break;
667  if ( pStr[0] != ',' )
668  return Wlc_PrsWriteErrorMessage( p, pStr, "Expected comma (,) in this place." );
669  }
670  Type = WLC_OBJ_BIT_CONCAT;
671  }
672  assert( pStr[0] == '}' );
673  pStr++;
674  }
675  else
676  {
677  if ( !(pStr = Wlc_PrsReadName(p, pStr, vFanins)) )
678  return 0;
679  // get the next symbol
680  if ( pStr[0] == 0 )
681  Type = WLC_OBJ_BUF;
682  else if ( pStr[0] == '?' )
683  {
684  if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
685  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name in MUX." );
686  if ( pStr[0] != ':' )
687  return Wlc_PrsWriteErrorMessage( p, pStr, "MUX lacks the colon symbol (:)." );
688  if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
689  return Wlc_PrsWriteErrorMessage( p, pStr, "Cannot read name in MUX." );
690  assert( Vec_IntSize(vFanins) == 3 );
691  ABC_SWAP( int, Vec_IntArray(vFanins)[1], Vec_IntArray(vFanins)[2] );
692  Type = WLC_OBJ_MUX;
693  }
694  else if ( pStr[0] == '[' )
695  {
696  int End, Beg;
697  pStr = Wlc_PrsFindRange( pStr, &End, &Beg );
698  Vec_IntPush( vFanins, (End << 16) | Beg );
699  Type = WLC_OBJ_BIT_SELECT;
700  }
701  else
702  {
703  if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] != '>' ) pStr += 2, Type = fRotating ? WLC_OBJ_ROTATE_R : WLC_OBJ_SHIFT_R;
704  else if ( pStr[0] == '>' && pStr[1] == '>' && pStr[2] == '>' ) pStr += 3, Type = WLC_OBJ_SHIFT_RA;
705  else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] != '<' ) pStr += 2, Type = fRotating ? WLC_OBJ_ROTATE_L : WLC_OBJ_SHIFT_L;
706  else if ( pStr[0] == '<' && pStr[1] == '<' && pStr[2] == '<' ) pStr += 3, Type = WLC_OBJ_SHIFT_LA;
707  else if ( pStr[0] == '&' && pStr[1] != '&' ) pStr += 1, Type = WLC_OBJ_BIT_AND;
708  else if ( pStr[0] == '|' && pStr[1] != '|' ) pStr += 1, Type = WLC_OBJ_BIT_OR;
709  else if ( pStr[0] == '^' && pStr[1] != '^' ) pStr += 1, Type = WLC_OBJ_BIT_XOR;
710  else if ( pStr[0] == '&' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_LOGIC_AND;
711  else if ( pStr[0] == '|' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_LOGIC_OR;
712  else if ( pStr[0] == '=' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_EQU;
713  else if ( pStr[0] == '!' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_NOTEQU;
714  else if ( pStr[0] == '<' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_LESS;
715  else if ( pStr[0] == '>' && pStr[1] != '=' ) pStr += 1, Type = WLC_OBJ_COMP_MORE;
716  else if ( pStr[0] == '<' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_LESSEQU;
717  else if ( pStr[0] == '>' && pStr[1] == '=' ) pStr += 2, Type = WLC_OBJ_COMP_MOREEQU;
718  else if ( pStr[0] == '+' ) pStr += 1, Type = WLC_OBJ_ARI_ADD;
719  else if ( pStr[0] == '-' ) pStr += 1, Type = WLC_OBJ_ARI_SUB;
720  else if ( pStr[0] == '*' && pStr[1] != '*' ) pStr += 1, Type = WLC_OBJ_ARI_MULTI;
721  else if ( pStr[0] == '/' ) pStr += 1, Type = WLC_OBJ_ARI_DIVIDE;
722  else if ( pStr[0] == '%' ) pStr += 1, Type = WLC_OBJ_ARI_MODULUS;
723  else if ( pStr[0] == '*' && pStr[1] == '*' ) pStr += 2, Type = WLC_OBJ_ARI_POWER;
724  else return Wlc_PrsWriteErrorMessage( p, pStr, "Unsupported operation (%c).", pStr[0] );
725  if ( !(pStr = Wlc_PrsReadName(p, pStr+1, vFanins)) )
726  return 0;
727  }
728  }
729  // make sure there is nothing left there
730  if ( pStr )
731  {
732  pStr = Wlc_PrsFindName( pStr, &pName );
733  if ( pStr != NULL )
734  return Wlc_PrsWriteErrorMessage( p, pStr, "Name %s is left at the end of the line.", pName );
735  }
736  return Type;
737 }
738 int Wlc_PrsReadDeclaration( Wlc_Prs_t * p, char * pStart )
739 {
740  int fFound = 0, Type = WLC_OBJ_NONE, iObj;
741  int Signed = 0, Beg = 0, End = 0, NameId, fIsPo = 0;
742  if ( Wlc_PrsStrCmp( pStart, "input" ) )
743  pStart += strlen("input"), Type = WLC_OBJ_PI;
744  else if ( Wlc_PrsStrCmp( pStart, "output" ) )
745  pStart += strlen("output"), fIsPo = 1;
746  pStart = Wlc_PrsSkipSpaces( pStart );
747  if ( Wlc_PrsStrCmp( pStart, "wire" ) )
748  pStart += strlen("wire");
749  else if ( Wlc_PrsStrCmp( pStart, "reg" ) )
750  pStart += strlen("reg");
751  // read 'signed'
752  pStart = Wlc_PrsFindWord( pStart, "signed", &Signed );
753  // read range
754  pStart = Wlc_PrsFindRange( pStart, &End, &Beg );
755  if ( pStart == NULL )
756  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read range." );
757  while ( 1 )
758  {
759  char * pName;
760  // read name
761  pStart = Wlc_PrsFindName( pStart, &pName );
762  if ( pStart == NULL )
763  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name in declaration." );
764  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
765  if ( fFound )
766  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is declared more than once.", pName );
767  iObj = Wlc_ObjAlloc( p->pNtk, Type, Signed, End, Beg );
768  if ( fIsPo ) Wlc_ObjSetCo( p->pNtk, Wlc_NtkObj(p->pNtk, iObj), 0 );
769  assert( iObj == NameId );
770  // check next definition
771  pStart = Wlc_PrsSkipSpaces( pStart );
772  if ( pStart[0] == ',' )
773  {
774  pStart++;
775  continue;
776  }
777  // check definition
778  Type = Wlc_PrsFindDefinition( p, pStart, p->vFanins );
779  if ( Type )
780  {
781  Wlc_Obj_t * pObj = Wlc_NtkObj( p->pNtk, iObj );
782  Wlc_ObjUpdateType( p->pNtk, pObj, Type );
783  Wlc_ObjAddFanins( p->pNtk, pObj, p->vFanins );
784  }
785  break;
786  }
787  return 1;
788 }
790 {
791  Wlc_Obj_t * pObj;
792  char * pStart, * pName;
793  int i;
794  // go through the directives
795  Wlc_PrsForEachLine( p, pStart, i )
796  {
797 startword:
798  if ( Wlc_PrsStrCmp( pStart, "module" ) )
799  {
800  // get module name
801  pName = Wlc_PrsStrtok( pStart + strlen("module"), " \r\n\t(,)" );
802  if ( pName == NULL )
803  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read model name." );
804  // THIS IS A HACK to skip definitions of modules beginning with "CPL_"
805  if ( Wlc_PrsStrCmp( pName, "CPL_" ) )
806  {
807  while ( ++i < Vec_IntSize(p->vStarts) )
808  {
809  pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, i));
810  pStart = strstr( pStart, "endmodule" );
811  if ( pStart != NULL )
812  break;
813  }
814  continue;
815  }
816  if ( Wlc_PrsStrCmp( pName, "table" ) )
817  {
818  // THIS IS A HACK to detect table module descriptions
819  int Width1 = -1, Width2 = -1;
820  int v, b, Value, nBits, nInts;
821  unsigned * pTable;
822  Vec_Int_t * vValues = Vec_IntAlloc( 256 );
823  Wlc_PrsForEachLineStart( p, pStart, i, i+1 )
824  {
825  if ( Wlc_PrsStrCmp( pStart, "endcase" ) )
826  break;
827  pStart = Wlc_PrsFindSymbol( pStart, '\'' );
828  if ( pStart == NULL )
829  continue;
830  Width1 = atoi(pStart-1);
831  pStart = Wlc_PrsFindSymbol( pStart+2, '\'' );
832  if ( pStart == NULL )
833  continue;
834  Width2 = atoi(pStart-1);
835  Value = 0;
836  Abc_TtReadHexNumber( (word *)&Value, pStart+2 );
837  Vec_IntPush( vValues, Value );
838  }
839  //Vec_IntPrint( vValues );
840  nBits = Abc_Base2Log( Vec_IntSize(vValues) );
841  if ( Vec_IntSize(vValues) != (1 << nBits) )
842  {
843  Vec_IntFree( vValues );
844  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read module \"%s\".", pName );
845  }
846  assert( Width1 == nBits );
847  // create bitmap
848  nInts = Abc_BitWordNum( Width2 * Vec_IntSize(vValues) );
849  pTable = (unsigned *)Mem_FlexEntryFetch( p->pMemTable, nInts * sizeof(unsigned) );
850  memset( pTable, 0, nInts * sizeof(unsigned) );
851  Vec_IntForEachEntry( vValues, Value, v )
852  for ( b = 0; b < Width2; b++ )
853  if ( (Value >> b) & 1 )
854  Abc_InfoSetBit( pTable, v * Width2 + b );
855  Vec_PtrPush( p->vTables, pTable );
856  Vec_IntFree( vValues );
857  continue;
858  }
859  if ( p->pNtk != NULL )
860  return Wlc_PrsWriteErrorMessage( p, pStart, "Network is already defined." );
861  p->pNtk = Wlc_NtkAlloc( pName, Vec_IntSize(p->vStarts) );
862  p->pNtk->pManName = Abc_NamStart( Vec_IntSize(p->vStarts), 20 );
863  p->pNtk->pMemTable = p->pMemTable; p->pMemTable = NULL;
864  p->pNtk->vTables = p->vTables; p->vTables = NULL;
865  // read the argument definitions
866  while ( (pName = Wlc_PrsStrtok( NULL, "(,)" )) )
867  {
868  pName = Wlc_PrsSkipSpaces( pName );
869  if ( Wlc_PrsStrCmp( pName, "input" ) || Wlc_PrsStrCmp( pName, "output" ) || Wlc_PrsStrCmp( pName, "wire" ) )
870  {
871  if ( !Wlc_PrsReadDeclaration( p, pName ) )
872  return 0;
873  }
874  }
875  }
876  else if ( Wlc_PrsStrCmp( pStart, "endmodule" ) )
877  {
879  Vec_IntAppend( &p->pNtk->vNameIds, vTemp );
880  Vec_IntFree( vTemp );
881  // move FO/FI to be part of CI/CO
882  assert( (Vec_IntSize(&p->pNtk->vFfs) & 1) == 0 );
883  Wlc_NtkForEachFf( p->pNtk, pObj, i )
884  if ( i & 1 )
885  Wlc_ObjSetCo( p->pNtk, pObj, 1 );
886  else
887  Wlc_ObjSetCi( p->pNtk, pObj );
888  Vec_IntClear( &p->pNtk->vFfs );
889  break;
890  }
891  // these are read as part of the interface
892  else if ( Wlc_PrsStrCmp( pStart, "input" ) || Wlc_PrsStrCmp( pStart, "output" ) || Wlc_PrsStrCmp( pStart, "wire" ) || Wlc_PrsStrCmp( pStart, "reg" ) )
893  {
894  if ( !Wlc_PrsReadDeclaration( p, pStart ) )
895  return 0;
896  }
897  else if ( Wlc_PrsStrCmp( pStart, "assign" ) )
898  {
899  int Type, NameId, fFound;
900  pStart += strlen("assign");
901  // read name
902  pStart = Wlc_PrsFindName( pStart, &pName );
903  if ( pStart == NULL )
904  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name after assign." );
905  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
906  if ( !fFound )
907  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
908  // read definition
909  Type = Wlc_PrsFindDefinition( p, pStart, p->vFanins );
910  if ( Type )
911  {
912  pObj = Wlc_NtkObj( p->pNtk, NameId );
913  Wlc_ObjUpdateType( p->pNtk, pObj, Type );
914  Wlc_ObjAddFanins( p->pNtk, pObj, p->vFanins );
915  }
916  else
917  return 0;
918  }
919  else if ( Wlc_PrsStrCmp( pStart, "table" ) )
920  {
921  // THIS IS A HACK to detect tables
922  int NameId, fFound, iTable = atoi( pStart + strlen("table") );
923  // find opening
924  pStart = Wlc_PrsFindSymbol( pStart, '(' );
925  if ( pStart == NULL )
926  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read table." );
927  // read input
928  pStart = Wlc_PrsFindName( pStart+1, &pName );
929  if ( pStart == NULL )
930  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name after assign." );
931  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
932  if ( !fFound )
933  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
934  // save inputs
935  Vec_IntClear( p->vFanins );
936  Vec_IntPush( p->vFanins, NameId );
937  Vec_IntPush( p->vFanins, iTable );
938  // find comma
939  pStart = Wlc_PrsFindSymbol( pStart, ',' );
940  if ( pStart == NULL )
941  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read table." );
942  // read output
943  pStart = Wlc_PrsFindName( pStart+1, &pName );
944  if ( pStart == NULL )
945  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name after assign." );
946  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
947  if ( !fFound )
948  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
949  pObj = Wlc_NtkObj( p->pNtk, NameId );
950  Wlc_ObjUpdateType( p->pNtk, pObj, WLC_OBJ_TABLE );
951  Wlc_ObjAddFanins( p->pNtk, pObj, p->vFanins );
952  }
953  else if ( Wlc_PrsStrCmp( pStart, "always" ) )
954  {
955  // THIS IS A HACK to detect always statement representing combinational MUX
956  int NameId, NameIdOut = -1, fFound;
957  // find control
958  pStart = Wlc_PrsFindWord( pStart, "case", &fFound );
959  if ( pStart == NULL )
960  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read case statement." );
961  // read the name
962  pStart = Wlc_PrsFindSymbol( pStart, '(' );
963  if ( pStart == NULL )
964  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read table." );
965  pStart = Wlc_PrsFindSymbol( pStart+1, '(' );
966  if ( pStart == NULL )
967  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read table." );
968  pStart = Wlc_PrsFindName( pStart+1, &pName );
969  if ( pStart == NULL )
970  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name after case." );
971  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
972  if ( !fFound )
973  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
974  Vec_IntClear( p->vFanins );
975  Vec_IntPush( p->vFanins, NameId );
976  // read data inputs
977  while ( 1 )
978  {
979  // find opening
980  pStart = Wlc_PrsFindSymbol( pStart, ':' );
981  if ( pStart == NULL )
982  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot find colon in the case statement." );
983  // find output name
984  pStart = Wlc_PrsFindName( pStart+1, &pName );
985  if ( pStart == NULL )
986  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name after case." );
987  NameIdOut = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
988  if ( !fFound )
989  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
990  // find equality
991  pStart = Wlc_PrsFindSymbol( pStart, '=' );
992  if ( pStart == NULL )
993  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot find equality in the case statement." );
994  // find input name
995  pStart = Wlc_PrsSkipSpaces( pStart+1 );
996  pStart = Wlc_PrsReadName( p, pStart, p->vFanins );
997  if ( pStart == NULL )
998  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name inside case statement." );
999  // get next line and check its opening character
1000  pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i));
1001  pStart = Wlc_PrsSkipSpaces( pStart );
1002  if ( Wlc_PrsIsDigit(pStart) )
1003  continue;
1004  if ( Wlc_PrsStrCmp( pStart, "default" ) )
1005  {
1006  printf( "Ignoring default in Line %d.\n", i );
1007  pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i));
1008  }
1009  // find closing
1010  pStart = Wlc_PrsFindWord( pStart, "endcase", &fFound );
1011  if ( pStart == NULL )
1012  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read case statement." );
1013  // find closing
1014  pStart = Wlc_PrsFindWord( pStart, "end", &fFound );
1015  if ( pStart == NULL )
1016  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read case statement." );
1017  pStart = Wlc_PrsSkipSpaces( pStart );
1018  break;
1019  }
1020  // check range of the control
1021  pObj = Wlc_NtkObj( p->pNtk, Vec_IntEntry(p->vFanins, 0) );
1022  if ( (1 << Wlc_ObjRange(pObj)) != Vec_IntSize(p->vFanins) - 1 )
1023  return Wlc_PrsWriteErrorMessage( p, pStart, "The number of values in the case statement is wrong.", pName );
1024  pObj = Wlc_NtkObj( p->pNtk, NameIdOut );
1025  Wlc_ObjUpdateType( p->pNtk, pObj, WLC_OBJ_MUX );
1026  Wlc_ObjAddFanins( p->pNtk, pObj, p->vFanins );
1027  goto startword;
1028  }
1029  else if ( Wlc_PrsStrCmp( pStart, "CPL_FF" ) )
1030  {
1031  int NameId = -1, NameIdOut = -1, fFound, nBits = 1, fFlopOut;
1032  pStart += strlen("CPL_FF");
1033  if ( pStart[0] == '#' )
1034  nBits = atoi(pStart+1);
1035  // read names
1036  while ( 1 )
1037  {
1038  pStart = Wlc_PrsFindSymbol( pStart, '.' );
1039  if ( pStart == NULL )
1040  break;
1041  pStart = Wlc_PrsSkipSpaces( pStart+1 );
1042  if ( pStart[0] != 'd' && (pStart[0] != 'q' || pStart[1] == 'b') )
1043  continue;
1044  fFlopOut = (pStart[0] == 'd');
1045  pStart = Wlc_PrsFindSymbol( pStart, '(' );
1046  if ( pStart == NULL )
1047  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read opening paranthesis in the flop description." );
1048  pStart = Wlc_PrsFindName( pStart+1, &pName );
1049  if ( pStart == NULL )
1050  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read name inside flop description." );
1051  if ( fFlopOut )
1052  NameIdOut = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
1053  else
1054  NameId = Abc_NamStrFindOrAdd( p->pNtk->pManName, pName, &fFound );
1055  if ( !fFound )
1056  return Wlc_PrsWriteErrorMessage( p, pStart, "Name %s is not declared.", pName );
1057  }
1058  if ( NameId == -1 || NameIdOut == -1 )
1059  return Wlc_PrsWriteErrorMessage( p, pStart, "Name of flop input or flop output is missing." );
1060  // create flop output
1061  pObj = Wlc_NtkObj( p->pNtk, NameId );
1062  Wlc_ObjUpdateType( p->pNtk, pObj, WLC_OBJ_FO );
1063  Vec_IntPush( &p->pNtk->vFfs, NameId );
1064  if ( nBits != Wlc_ObjRange(pObj) )
1065  printf( "Warning! Flop input has bit-width (%d) that differs from the declaration (%d)\n", nBits, Wlc_ObjRange(pObj) );
1066  // create flop input
1067  pObj = Wlc_NtkObj( p->pNtk, NameIdOut );
1068  Vec_IntPush( &p->pNtk->vFfs, NameIdOut );
1069  if ( nBits != Wlc_ObjRange(pObj) )
1070  printf( "Warning! Flop output has bit-width (%d) that differs from the declaration (%d)\n", nBits, Wlc_ObjRange(pObj) );
1071  }
1072  else if ( pStart[0] != '`' )
1073  {
1074  pStart = Wlc_PrsFindName( pStart, &pName );
1075  return Wlc_PrsWriteErrorMessage( p, pStart, "Cannot read line beginning with %s.", pName );
1076  }
1077  }
1078  return 1;
1079 }
1080 Wlc_Ntk_t * Wlc_ReadVer( char * pFileName )
1081 {
1082  Wlc_Prs_t * p;
1083  Wlc_Ntk_t * pNtk = NULL;
1084  // start the parser
1085  p = Wlc_PrsStart( pFileName );
1086  if ( p == NULL )
1087  return NULL;
1088  // detect lines
1089  if ( !Wlc_PrsPrepare( p ) )
1090  goto finish;
1091  // parse models
1092  if ( !Wlc_PrsDerive( p ) )
1093  goto finish;
1094  // derive topological order
1095  pNtk = Wlc_NtkDupDfs( p->pNtk );
1096  Wlc_NtkTransferNames( pNtk, p->pNtk );
1097 finish:
1099  Wlc_PrsStop( p );
1100  return pNtk;
1101 }
1102 
1103 /**Function*************************************************************
1104 
1105  Synopsis []
1106 
1107  Description []
1108 
1109  SideEffects []
1110 
1111  SeeAlso []
1112 
1113 ***********************************************************************/
1114 void Io_ReadWordTest( char * pFileName )
1115 {
1116  Gia_Man_t * pNew;
1117  Wlc_Ntk_t * pNtk = Wlc_ReadVer( pFileName );
1118  if ( pNtk == NULL )
1119  return;
1120  Wlc_WriteVer( pNtk, "test.v" );
1121 
1122  pNew = Wlc_NtkBitBlast( pNtk, NULL );
1123  Gia_AigerWrite( pNew, "test.aig", 0, 0 );
1124  Gia_ManStop( pNew );
1125 
1126  Wlc_NtkFree( pNtk );
1127 }
1128 
1129 ////////////////////////////////////////////////////////////////////////
1130 /// END OF FILE ///
1131 ////////////////////////////////////////////////////////////////////////
1132 
1133 
1135 
char * memset()
#define Wlc_PrsForEachLineStart(p, pLine, i, Start)
Definition: wlcReadVer.c:55
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Abc_TtReadHexNumber(word *pTruth, char *pString)
Definition: utilTruth.h:878
static int Wlc_PrsIsDigit(char *pStr)
Definition: wlcReadVer.c:158
Mem_Flex_t * pMemTable
Definition: wlc.h:130
int Wlc_PrsRemoveComments(Wlc_Prs_t *p)
Definition: wlcReadVer.c:219
char sError[WLV_PRS_MAX_LINE]
Definition: wlcReadVer.c:46
Wlc_Ntk_t * Wlc_NtkAlloc(char *pName, int nObjsAlloc)
FUNCTION DEFINITIONS ///.
Definition: wlcNtk.c:94
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static char * Wlc_PrsReadConstant(Wlc_Prs_t *p, char *pStr, Vec_Int_t *vFanins, int *pRange, int *pSigned)
Definition: wlcReadVer.c:478
Vec_Int_t * vLines
Definition: wlcReadVer.c:39
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static char * Wlc_PrsSkipSpaces(char *pStr)
Definition: wlcReadVer.c:169
static char * Wlc_PrsFindClosingParanthesis(char *pStr, char Open, char Close)
Definition: wlcReadVer.c:196
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Wlc_PrsForEachLine(p, pLine, i)
Definition: wlcReadVer.c:53
Vec_Ptr_t * vTables
Definition: wlc.h:131
Vec_Int_t * vFanins
Definition: wlcReadVer.c:41
static Wlc_Obj_t * Wlc_NtkObj(Wlc_Ntk_t *p, int Id)
Definition: wlc.h:149
void Wlc_PrsStop(Wlc_Prs_t *p)
Definition: wlcReadVer.c:91
Wlc_Ntk_t * pNtk
Definition: wlcReadVer.c:42
Vec_Int_t * vStarts
Definition: wlcReadVer.c:40
void Wlc_NtkTransferNames(Wlc_Ntk_t *pNew, Wlc_Ntk_t *p)
Definition: wlcNtk.c:475
int Wlc_PrsPrepare(Wlc_Prs_t *p)
Definition: wlcReadVer.c:282
static char * Wlc_PrsFindSymbol(char *pStr, char Symb)
Definition: wlcReadVer.c:175
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Wlc_PrsFindDefinition(Wlc_Prs_t *p, char *pStr, Vec_Int_t *vFanins)
Definition: wlcReadVer.c:567
int Wlc_PrsWriteErrorMessage(Wlc_Prs_t *p, char *pCur, const char *format,...)
Definition: wlcReadVer.c:116
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition: utilNam.c:392
void Wlc_WriteVer(Wlc_Ntk_t *p, char *pFileName)
Definition: wlcWriteVer.c:354
static int Wlc_ObjRange(Wlc_Obj_t *p)
Definition: wlc.h:175
static Vec_Int_t * Vec_IntStartNatural(int nSize)
Definition: bblif.c:192
static int Wlc_PrsStrCmp(char *pStr, char *pWhat)
Definition: wlcReadVer.c:51
void Wlc_ObjUpdateType(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int Type)
Definition: wlcNtk.c:175
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Definition: utilNam.c:78
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
Definition: mem.c:372
int Wlc_ObjAlloc(Wlc_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition: wlcNtk.c:141
int Wlc_PrsReadDeclaration(Wlc_Prs_t *p, char *pStart)
Definition: wlcReadVer.c:738
static char * Wlc_PrsFindSymbolTwo(char *pStr, char Symb, char Symb2)
Definition: wlcReadVer.c:189
Mem_Flex_t * Mem_FlexStart()
Definition: mem.c:311
int Wlc_PrsDerive(Wlc_Prs_t *p)
Definition: wlcReadVer.c:789
#define Wlc_NtkForEachFf(p, pFf, i)
Definition: wlc.h:218
void Wlc_ObjSetCi(Wlc_Ntk_t *p, Wlc_Obj_t *pObj)
Definition: wlcNtk.c:110
static char * Wlc_PrsReadName(Wlc_Prs_t *p, char *pStr, Vec_Int_t *vFanins)
Definition: wlcReadVer.c:528
void Wlc_PrsPrintErrorMessage(Wlc_Prs_t *p)
Definition: wlcReadVer.c:140
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
char * strstr()
char * vnsprintf(const char *format, va_list args)
Definition: utilFile.c:168
char * Wlc_PrsStrtok(char *s, const char *delim)
Definition: wlcReadVer.c:355
static char * Wlc_PrsStr(Wlc_Prs_t *p, int iOffset)
Definition: wlcReadVer.c:50
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
char * pFileName
Definition: wlcReadVer.c:37
void Wlc_NtkFree(Wlc_Ntk_t *p)
Definition: wlcNtk.c:195
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
char * sprintf()
static int Counter
static int Wlc_PrsOffset(Wlc_Prs_t *p, char *pStr)
Definition: wlcReadVer.c:49
Vec_Ptr_t * vTables
Definition: wlcReadVer.c:44
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
void Gia_AigerWrite(Gia_Man_t *p, char *pFileName, int fWriteSymbols, int fCompact)
Definition: giaAiger.c:1024
static char * Wlc_PrsFindName(char *pStr, char **ppPlace)
Definition: wlcReadVer.c:455
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
Definition: mem.c:343
Wlc_Prs_t * Wlc_PrsStart(char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: wlcReadVer.c:75
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Definition: wlc.h:47
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
Definition: wlc.h:45
#define WLV_PRS_MAX_LINE
DECLARATIONS ///.
Definition: wlcReadVer.c:31
Wlc_Ntk_t * Wlc_NtkDupDfs(Wlc_Ntk_t *p)
Definition: wlcNtk.c:457
static char * Wlc_PrsFindWord(char *pStr, char *pWord, int *fFound)
Definition: wlcReadVer.c:446
Gia_Man_t * Wlc_NtkBitBlast(Wlc_Ntk_t *p, Vec_Int_t *vBoxIds)
Definition: wlcBlast.c:405
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int Extra_FileCheck(char *pFileName)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Wlc_Ntk_t * Wlc_ReadVer(char *pFileName)
Definition: wlcReadVer.c:1080
void Io_ReadWordTest(char *pFileName)
Definition: wlcReadVer.c:1114
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
void Wlc_ObjAddFanins(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Vec_Int_t *vFanins)
Definition: wlcNtk.c:182
Mem_Flex_t * pMemTable
Definition: wlcReadVer.c:43
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Wlc_PrsIsChar(char *pStr)
Definition: wlcReadVer.c:162
int nConsts
Definition: wlcReadVer.c:45
int strncmp()
static void Vec_PtrFreeP(Vec_Ptr_t **p)
Definition: vecPtr.h:240
static int Wlc_NtkObjNumMax(Wlc_Ntk_t *p)
Definition: wlc.h:142
int nFileSize
Definition: wlcReadVer.c:36
Vec_Int_t vNameIds
Definition: wlc.h:134
void Wlc_ObjSetCo(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int fFlopInput)
Definition: wlcNtk.c:130
static int Abc_BitWordNum(int nBits)
Definition: abc_global.h:255
#define assert(ex)
Definition: util_old.h:213
static char * Wlc_PrsFindRange(char *pStr, int *End, int *Beg)
Definition: wlcReadVer.c:416
int strlen()
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Vec_Int_t vFfs
Definition: wlc.h:122
Abc_Nam_t * pManName
Definition: wlc.h:133
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
char * pBuffer
Definition: wlcReadVer.c:38
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
char * Extra_FileReadContents(char *pFileName)