FUNCTION DECLARATIONS ///.
235{
237 FILE * pFile;
242 int nTotal, nInputs, nOutputs, nLatches, nAnds;
243 int nBad = 0, nConstr = 0, nJust = 0, nFair = 0;
244 int nFileSize = -1, iTerm, nDigits, i;
245 char * pContents, * pDrivers = NULL, * pSymbols, * pCur, * pName, * pType;
246 unsigned uLit0, uLit1, uLit;
247 int RetValue;
248
249
251 pContents = Ioa_ReadLoadFileBz2Aig( pFileName, &nFileSize );
253 pContents = Ioa_ReadLoadFileGzAig( pFileName, &nFileSize );
254 else
255 {
256
258 pFile = fopen( pFileName, "rb" );
259 pContents =
ABC_ALLOC(
char, nFileSize );
260 RetValue = fread( pContents, nFileSize, 1, pFile );
261 fclose( pFile );
262 }
263
264
265
266 if (
strncmp(pContents,
"aig", 3) != 0 || (pContents[3] !=
' ' && pContents[3] !=
'2') )
267 {
268 fprintf( stdout, "Wrong input file format.\n" );
270 return NULL;
271 }
272
273
274 pCur = pContents; while ( *pCur != ' ' ) pCur++; pCur++;
275
276 nTotal = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
277
278 nInputs = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
279
280 nLatches = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
281
282 nOutputs = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
283
284 nAnds = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
285 if ( *pCur == ' ' )
286 {
287
288
289 pCur++;
290 nBad = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
291 nOutputs += nBad;
292 }
293 if ( *pCur == ' ' )
294 {
295
296 pCur++;
297 nConstr = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
298 nOutputs += nConstr;
299 }
300 if ( *pCur == ' ' )
301 {
302
303 pCur++;
304 nJust = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
305 nOutputs += nJust;
306 }
307 if ( *pCur == ' ' )
308 {
309
310 pCur++;
311 nFair = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
312 nOutputs += nFair;
313 }
314 if ( *pCur != '\n' )
315 {
316 fprintf( stdout, "The parameter line is in a wrong format.\n" );
318 return NULL;
319 }
320 pCur++;
321
322
323 if (
nTotal != nInputs + nLatches + nAnds )
324 {
325 fprintf( stdout, "The number of objects does not match.\n" );
327 return NULL;
328 }
329 if ( nJust || nFair )
330 {
331 fprintf( stdout, "Reading AIGER files with liveness properties is currently not supported.\n" );
333 return NULL;
334 }
335
336 if ( nConstr )
337 {
338 if ( nConstr == 1 )
339 fprintf( stdout, "Warning: The last output is interpreted as a constraint.\n" );
340 else
341 fprintf( stdout, "Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
342 }
343
344
351
352
353 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
355
356
357 for ( i = 0; i < nInputs; i++ )
358 {
359 pObj = Abc_NtkCreatePi(pNtkNew);
360 Vec_PtrPush( vNodes, pObj );
361 }
362
363 for ( i = 0; i < nOutputs; i++ )
364 {
365 pObj = Abc_NtkCreatePo(pNtkNew);
366 }
367
368 nDigits = Abc_Base10Log( nLatches );
369 for ( i = 0; i < nLatches; i++ )
370 {
371 pObj = Abc_NtkCreateLatch(pNtkNew);
372 Abc_LatchSetInit0( pObj );
373 pNode0 = Abc_NtkCreateBi(pNtkNew);
374 pNode1 = Abc_NtkCreateBo(pNtkNew);
377 Vec_PtrPush( vNodes, pNode1 );
378
379
380
381 }
382
383
384 if ( pContents[3] == ' ' )
385 {
386
387 pDrivers = pCur;
388
389 for ( i = 0; i < nLatches + nOutputs; )
390 if ( *pCur++ == '\n' )
391 i++;
392 }
393 else
394 {
396 }
397
398
400 for ( i = 0; i < nAnds; i++ )
401 {
402 Extra_ProgressBarUpdate( pProgress, i, NULL );
403 uLit = ((i + 1 + nInputs + nLatches) << 1);
404 uLit1 = uLit - Io_ReadAigerDecode( &pCur );
405 uLit0 = uLit1 - Io_ReadAigerDecode( &pCur );
406
407 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), uLit0 & 1 );
408 pNode1 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit1 >> 1), uLit1 & 1 );
409 assert( Vec_PtrSize(vNodes) == i + 1 + nInputs + nLatches );
411 }
413
414
415 pSymbols = pCur;
416
417
418 pCur = pDrivers;
419 if ( pContents[3] == ' ' )
420 {
422 {
423 uLit0 = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
424 if ( *pCur == ' ' )
425 {
426 int Init;
427 pCur++;
428 Init = atoi( pCur );
429 if ( Init == 0 )
430 Abc_LatchSetInit0( Abc_NtkBox(pNtkNew, i) );
431 else if ( Init == 1 )
432 Abc_LatchSetInit1( Abc_NtkBox(pNtkNew, i) );
433 else
434 {
435 assert( Init == Abc_Var2Lit(1+Abc_NtkPiNum(pNtkNew)+i, 0) );
436
437 Abc_LatchSetInitDc( Abc_NtkBox(pNtkNew, i) );
438 }
439 while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
440 }
441 if ( *pCur != '\n' )
442 {
443 fprintf( stdout, "The initial value of latch number %d is not recognized.\n", i );
444 return NULL;
445 }
446 pCur++;
447
448 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
450 }
451
453 {
454 uLit0 = atoi( pCur ); while ( *pCur++ != '\n' );
455 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
457 }
458 }
459 else
460 {
461
463 {
464 uLit0 = Vec_IntEntry( vLits, i );
465 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
467 }
468
470 {
471 uLit0 = Vec_IntEntry( vLits, i+Abc_NtkLatchNum(pNtkNew) );
472 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
474 }
475 Vec_IntFree( vLits );
476 }
477
478
479 pCur = pSymbols;
480 if ( pCur < pContents + nFileSize && *pCur != 'c' )
481 {
482 int Counter = 0;
483 int fNodeNames = 0;
484 while ( pCur < pContents + nFileSize && *pCur != 'c' )
485 {
486
487 pType = pCur;
488 if ( *pCur == 'i' )
489 vTerms = pNtkNew->
vPis;
490 else if ( *pCur == 'l' )
492 else if ( *pCur == 'o' || *pCur == 'b' || *pCur == 'c' || *pCur == 'j' || *pCur == 'f' )
493 vTerms = pNtkNew->
vPos;
494 else if ( *pCur == 'n' )
495 {
496 fNodeNames++;
497 while ( *pCur++ != '\n' );
498 continue;
499 }
500 else
501 {
502
503 return NULL;
504 }
505
506 iTerm = atoi( ++pCur ); while ( *pCur++ != ' ' );
507
508 if ( iTerm >= Vec_PtrSize(vTerms) )
509 {
510 fprintf( stdout, "The number of terminal is out of bound.\n" );
511 return NULL;
512 }
513 pObj = (
Abc_Obj_t *)Vec_PtrEntry( vTerms, iTerm );
514 if ( *pType == 'l' )
515 pObj = Abc_ObjFanout0(pObj);
516
517 pName = pCur; while ( *pCur++ != '\n' );
518
519 *(pCur-1) = 0;
521 if ( *pType == 'l' )
522 {
525 }
526
528 }
529
530
532 {
533 if ( pObj->
pCopy )
continue;
535 Counter++;
536 }
538 {
539 if ( pObj->
pCopy )
continue;
543 Counter++;
544 }
546 {
547 if ( pObj->
pCopy )
continue;
549 Counter++;
550 }
551
552
553 if ( fNodeNames )
554 printf( "Io_ReadAiger(): The names of internal nodes are not supported. Ignoring %d node names.\n", fNodeNames );
555 }
556 else
557 {
558
560 }
561
562
563 pCur = pSymbols;
564 if ( pCur + 1 < pContents + nFileSize && *pCur == 'c' )
565 {
566 pCur++;
567 if ( *pCur == 'n' )
568 {
569 pCur++;
570
572 {
575 }
576 }
577 }
578
579
581 Vec_PtrFree( vNodes );
582
583
585
586
587 if ( nBad || nConstr || nJust || nFair )
589
590
592 {
593 printf( "Io_ReadAiger: The network check has failed.\n" );
595 return NULL;
596 }
597 return pNtkNew;
598}
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
#define Abc_NtkForEachPo(pNtk, pPo, i)
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
struct Abc_Aig_t_ Abc_Aig_t
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
#define Abc_NtkForEachLatchOutput(pNtk, pObj, i)
ABC_DLL void Abc_NtkInvertConstraints(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_NtkForEachLatchInput(pNtk, pObj, i)
#define Abc_NtkForEachPi(pNtk, pPi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkShortNames(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define ABC_ALLOC(type, num)
int nTotal
DECLARATIONS ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Vec_Int_t * Io_WriteDecodeLiterals(char **ppPos, int nEntries)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.