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;
251 pContents = Ioa_ReadLoadFileBz2Aig( pFileName, &nFileSize );
253 pContents = Ioa_ReadLoadFileGzAig( pFileName, &nFileSize );
258 pFile = fopen( pFileName,
"rb" );
259 pContents =
ABC_ALLOC(
char, nFileSize );
260 RetValue = fread( pContents, nFileSize, 1, pFile );
266 if (
strncmp(pContents,
"aig", 3) != 0 || (pContents[3] !=
' ' && pContents[3] !=
'2') )
268 fprintf( stdout,
"Wrong input file format.\n" );
274 pCur = pContents;
while ( *pCur !=
' ' ) pCur++; pCur++;
276 nTotal = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
278 nInputs = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
280 nLatches = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
282 nOutputs = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
284 nAnds = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
290 nBad = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
297 nConstr = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
304 nJust = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
311 nFair = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
316 fprintf( stdout,
"The parameter line is in a wrong format.\n" );
323 if (
nTotal != nInputs + nLatches + nAnds )
325 fprintf( stdout,
"The number of objects does not match.\n" );
329 if ( nJust || nFair )
331 fprintf( stdout,
"Reading AIGER files with liveness properties is currently not supported.\n" );
339 fprintf( stdout,
"Warning: The last output is interpreted as a constraint.\n" );
341 fprintf( stdout,
"Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
353 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
357 for ( i = 0; i < nInputs; i++ )
359 pObj = Abc_NtkCreatePi(pNtkNew);
360 Vec_PtrPush( vNodes, pObj );
363 for ( i = 0; i < nOutputs; i++ )
365 pObj = Abc_NtkCreatePo(pNtkNew);
368 nDigits = Abc_Base10Log( nLatches );
369 for ( i = 0; i < nLatches; i++ )
371 pObj = Abc_NtkCreateLatch(pNtkNew);
372 Abc_LatchSetInit0( pObj );
373 pNode0 = Abc_NtkCreateBi(pNtkNew);
374 pNode1 = Abc_NtkCreateBo(pNtkNew);
377 Vec_PtrPush( vNodes, pNode1 );
384 if ( pContents[3] ==
' ' )
389 for ( i = 0; i < nLatches + nOutputs; )
390 if ( *pCur++ ==
'\n' )
400 for ( i = 0; i < nAnds; i++ )
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 );
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 );
419 if ( pContents[3] ==
' ' )
423 uLit0 = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
430 Abc_LatchSetInit0( Abc_NtkBox(pNtkNew, i) );
431 else if ( Init == 1 )
432 Abc_LatchSetInit1( Abc_NtkBox(pNtkNew, i) );
435 assert( Init == Abc_Var2Lit(1+Abc_NtkPiNum(pNtkNew)+i, 0) );
437 Abc_LatchSetInitDc( Abc_NtkBox(pNtkNew, i) );
439 while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
443 fprintf( stdout,
"The initial value of latch number %d is not recognized.\n", i );
448 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
454 uLit0 = atoi( pCur );
while ( *pCur++ !=
'\n' );
455 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
464 uLit0 = Vec_IntEntry( vLits, i );
465 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
471 uLit0 = Vec_IntEntry( vLits, i+Abc_NtkLatchNum(pNtkNew) );
472 pNode0 = Abc_ObjNotCond( (
Abc_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
475 Vec_IntFree( vLits );
480 if ( pCur < pContents + nFileSize && *pCur !=
'c' )
484 while ( pCur < pContents + nFileSize && *pCur !=
'c' )
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' )
497 while ( *pCur++ !=
'\n' );
506 iTerm = atoi( ++pCur );
while ( *pCur++ !=
' ' );
508 if ( iTerm >= Vec_PtrSize(vTerms) )
510 fprintf( stdout,
"The number of terminal is out of bound.\n" );
513 pObj = (
Abc_Obj_t *)Vec_PtrEntry( vTerms, iTerm );
515 pObj = Abc_ObjFanout0(pObj);
517 pName = pCur;
while ( *pCur++ !=
'\n' );
533 if ( pObj->
pCopy )
continue;
539 if ( pObj->
pCopy )
continue;
547 if ( pObj->
pCopy )
continue;
554 printf(
"Io_ReadAiger(): The names of internal nodes are not supported. Ignoring %d node names.\n", fNodeNames );
564 if ( pCur + 1 < pContents + nFileSize && *pCur ==
'c' )
581 Vec_PtrFree( vNodes );
587 if ( nBad || nConstr || nJust || nFair )
593 printf(
"Io_ReadAiger: The network check has failed.\n" );