179 Vec_Ptr_t * vNamesIn = NULL, * vNamesOut = NULL, * vNamesRegIn = NULL, * vNamesRegOut = NULL, * vNamesNode = NULL;
180 Vec_Int_t * vLits = NULL, * vPoTypes = NULL;
181 Vec_Int_t * vNodes, * vDrivers, * vInits = NULL;
182 int iObj, iNode0, iNode1, fHieOnly = 0;
183 int nTotal, nInputs, nOutputs, nLatches, nAnds, i;
184 int nBad = 0, nConstr = 0, nJust = 0, nFair = 0;
185 unsigned char * pDrivers, * pSymbols, * pCur;
186 unsigned uLit0, uLit1, uLit;
189 pCur = (
unsigned char *)pContents;
while ( *pCur !=
' ' ) pCur++; pCur++;
191 nTotal = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
193 nInputs = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
195 nLatches = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
197 nOutputs = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
199 nAnds = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
205 nBad = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
212 nConstr = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
219 nJust = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
226 nFair = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
231 fprintf( stdout,
"The parameter line is in a wrong format.\n" );
237 if (
nTotal != nInputs + nLatches + nAnds )
239 fprintf( stdout,
"The number of objects does not match.\n" );
242 if ( nJust || nFair )
244 fprintf( stdout,
"Reading AIGER files with liveness properties is currently not supported.\n" );
251 fprintf( stdout,
"Warning: The last output is interpreted as a constraint.\n" );
253 fprintf( stdout,
"Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
262 vNodes = Vec_IntAlloc( 1 +
nTotal );
263 Vec_IntPush( vNodes, 0 );
266 for ( i = 0; i < nInputs + nLatches; i++ )
268 iObj = Gia_ManAppendCi(pNew);
269 Vec_IntPush( vNodes, iObj );
274 if ( pContents[3] ==
' ' )
277 for ( i = 0; i < nLatches + nOutputs; )
278 if ( *pCur++ ==
'\n' )
287 if ( !fGiaSimple && !fSkipStrash )
289 for ( i = 0; i < nAnds; i++ )
291 uLit = ((i + 1 + nInputs + nLatches) << 1);
292 uLit1 = uLit - Gia_AigerReadUnsigned( &pCur );
293 uLit0 = uLit1 - Gia_AigerReadUnsigned( &pCur );
295 iNode0 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), uLit0 & 1 );
296 iNode1 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit1 >> 1), uLit1 & 1 );
297 assert( Vec_IntSize(vNodes) == i + 1 + nInputs + nLatches );
298 if ( !fGiaSimple && fSkipStrash )
300 if ( iNode0 == iNode1 )
301 Vec_IntPush( vNodes, Gia_ManAppendBuf(pNew, iNode0) );
303 Vec_IntPush( vNodes, Gia_ManAppendAnd(pNew, iNode0, iNode1) );
308 if ( !fGiaSimple && !fSkipStrash )
315 vDrivers = Vec_IntAlloc( nLatches + nOutputs );
316 if ( pContents[3] ==
' ' )
318 vInits = Vec_IntAlloc( nLatches );
320 for ( i = 0; i < nLatches; i++ )
322 uLit0 = atoi( (
char *)pCur );
323 while ( *pCur !=
' ' && *pCur !=
'\n' )
328 Vec_IntPush( vInits, atoi( (
char *)pCur ) );
329 while ( *pCur++ !=
'\n' );
334 Vec_IntPush( vInits, 0 );
336 iNode0 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
337 Vec_IntPush( vDrivers, iNode0 );
340 for ( i = 0; i < nOutputs; i++ )
342 uLit0 = atoi( (
char *)pCur );
while ( *pCur++ !=
'\n' );
343 iNode0 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
344 Vec_IntPush( vDrivers, iNode0 );
351 for ( i = 0; i < nLatches; i++ )
353 uLit0 = Vec_IntEntry( vLits, i );
354 iNode0 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
355 Vec_IntPush( vDrivers, iNode0 );
358 for ( i = 0; i < nOutputs; i++ )
360 uLit0 = Vec_IntEntry( vLits, i+nLatches );
361 iNode0 = Abc_LitNotCond( Vec_IntEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
362 Vec_IntPush( vDrivers, iNode0 );
364 Vec_IntFree( vLits );
368 for ( i = 0; i < nOutputs; i++ )
369 Gia_ManAppendCo( pNew, Vec_IntEntry(vDrivers, nLatches + i) );
370 for ( i = 0; i < nLatches; i++ )
371 Gia_ManAppendCo( pNew, Vec_IntEntry(vDrivers, i) );
372 Vec_IntFree( vDrivers );
379 if ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
385 while ( !fError && pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
388 char * pType = (
char *)pCur;
391 if ( *pCur !=
'i' && *pCur !=
'o' && *pCur !=
'l' && *pCur !=
'n' )
397 iTerm = atoi( (
char *)++pCur );
while ( *pCur++ !=
' ' );
399 while ( *pCur ==
' ' )
402 for ( pName = (
char *)pCur; *pCur && *pCur !=
'\n'; pCur++ );
408 if ( vNamesIn == NULL )
409 vNamesIn = Vec_PtrStart( nInputs );
410 if ( Vec_PtrSize(vNamesIn) <= iTerm )
415 Vec_PtrWriteEntry( vNamesIn, iTerm, Abc_UtilStrsav(pName) );
417 else if ( *pType ==
'o' )
419 if ( vNamesOut == NULL )
420 vNamesOut = Vec_PtrStart( nOutputs );
421 if ( Vec_PtrSize(vNamesOut) <= iTerm )
426 Vec_PtrWriteEntry( vNamesOut, iTerm, Abc_UtilStrsav(pName) );
428 else if ( *pType ==
'l' )
432 sprintf( Buffer,
"%s_in", pName );
433 if ( vNamesRegIn == NULL )
434 vNamesRegIn = Vec_PtrStart( nLatches );
435 if ( vNamesRegOut == NULL )
436 vNamesRegOut = Vec_PtrStart( nLatches );
437 if ( Vec_PtrSize(vNamesRegIn) <= iTerm )
442 Vec_PtrWriteEntry( vNamesRegIn, iTerm, Abc_UtilStrsav(Buffer) );
443 Vec_PtrWriteEntry( vNamesRegOut, iTerm, Abc_UtilStrsav(pName) );
445 else if ( *pType ==
'n' )
447 if ( Vec_IntSize(&pNew->
vHTable) != 0 )
449 printf(
"Structural hashing should be disabled to read internal nodes names.\n" );
453 if ( vNamesNode == NULL )
454 vNamesNode = Vec_PtrStart( Gia_ManObjNum(pNew) );
455 Vec_PtrWriteEntry( vNamesNode, iTerm, Abc_UtilStrsav(pName) );
466 printf(
"Error occurred when reading signal names. Signal names ignored.\n" );
467 if ( vNamesIn ) Vec_PtrFreeFree( vNamesIn ), vNamesIn = NULL;
468 if ( vNamesOut ) Vec_PtrFreeFree( vNamesOut ), vNamesOut = NULL;
469 if ( vNamesRegIn ) Vec_PtrFreeFree( vNamesRegIn ), vNamesRegIn = NULL;
470 if ( vNamesRegOut ) Vec_PtrFreeFree( vNamesRegOut ), vNamesRegOut = NULL;
471 if ( vNamesNode ) Vec_PtrFreeFree( vNamesNode ), vNamesNode = NULL;
477 unsigned char * pCurOld = pCur;
478 pNew->
vUserPiIds = Vec_IntStartFull( nInputs );
479 pNew->
vUserPoIds = Vec_IntStartFull( nOutputs );
480 pNew->
vUserFfIds = Vec_IntStartFull( nLatches );
481 while ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
484 char * pType = (
char *)pCur;
486 if ( *pCur !=
'i' && *pCur !=
'o' && *pCur !=
'l' )
493 iTerm = atoi( (
char *)++pCur );
while ( *pCur++ !=
' ' );
495 while ( *pCur ==
' ' )
501 if ( *pCur++ !=
'@' )
506 if ( *pCur ==
'i' && *pType ==
'i' )
507 Vec_IntWriteEntry( pNew->
vUserPiIds, iTerm, atoi((
char *)pCur+1) );
508 else if ( *pCur ==
'o' && *pType ==
'o' )
509 Vec_IntWriteEntry( pNew->
vUserPoIds, iTerm, atoi((
char *)pCur+1) );
510 else if ( *pCur ==
'l' && *pType ==
'l' )
511 Vec_IntWriteEntry( pNew->
vUserFfIds, iTerm, atoi((
char *)pCur+1) );
514 fprintf( stdout,
"Wrong name format.\n" );
519 while ( *pCur++ !=
'\n' );
524 unsigned char * pName;
525 int Entry, nInvars, nConstr, iTerm;
527 Vec_Int_t * vPoNames = Vec_IntStartFull( nOutputs );
535 pCur = (
unsigned char *)pCurOld;
536 while ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
539 if ( *pCur ==
'i' || *pCur ==
'l' )
542 while ( *pCur++ !=
'\n' );
553 iTerm = atoi( (
char *)++pCur );
while ( *pCur++ !=
' ' );
555 if ( iTerm < 0 || iTerm >= nOutputs )
557 fprintf( stdout,
"The output number (%d) is out of range.\n", iTerm );
561 if ( Vec_IntEntry(vPoNames, iTerm) != ~0 )
563 fprintf( stdout,
"The output number (%d) is listed twice.\n", iTerm );
569 pName = pCur;
while ( *pCur++ !=
'\n' );
572 Vec_IntWriteEntry( vPoNames, iTerm, pName - (
unsigned char *)pContents );
578 nInvars = nConstr = 0;
579 vPoTypes = Vec_IntStart( Gia_ManPoNum(pNew) );
584 if (
strncmp( pContents+Entry,
"constraint:", 11 ) == 0 )
586 Vec_IntWriteEntry( vPoTypes, i, 1 );
589 if (
strncmp( pContents+Entry,
"invariant:", 10 ) == 0 )
591 Vec_IntWriteEntry( vPoTypes, i, 2 );
596 fprintf( stdout,
"Recognized and added %d constraints.\n", nConstr );
598 fprintf( stdout,
"Recognized and skipped %d invariants.\n", nInvars );
599 if ( nConstr == 0 && nInvars == 0 )
600 Vec_IntFreeP( &vPoTypes );
602 Vec_IntFree( vPoNames );
609 if ( pCur + 1 < (
unsigned char *)pContents + nFileSize && *pCur ==
'c' )
613 unsigned char * pCurTemp;
618 while ( pCur < (
unsigned char *)pContents + nFileSize )
624 vStr = Vec_StrStart( Gia_AigerReadInt(pCur) ); pCur += 4;
625 memcpy( Vec_StrArray(vStr), pCur, (
size_t)Vec_StrSize(vStr) );
626 pCur += Vec_StrSize(vStr);
629 if ( fVerbose ) printf(
"Finished reading extension \"a\".\n" );
632 else if ( *pCur ==
'c' )
635 assert( Gia_AigerReadInt(pCur) == 4 ); pCur += 4;
636 pNew->
nConstrs = Gia_AigerReadInt( pCur ); pCur += 4;
637 if ( fVerbose ) printf(
"Finished reading extension \"c\".\n" );
640 else if ( *pCur ==
'd' )
643 assert( Gia_AigerReadInt(pCur) == 4 ); pCur += 4;
644 pNew->
nAnd2Delay = Gia_AigerReadInt(pCur); pCur += 4;
645 if ( fVerbose ) printf(
"Finished reading extension \"d\".\n" );
647 else if ( *pCur ==
'i' )
650 nInputs = Gia_AigerReadInt(pCur)/4; pCur += 4;
651 pNew->
vInArrs = Vec_FltStart( nInputs );
652 memcpy( Vec_FltArray(pNew->
vInArrs), pCur, (
size_t)4*nInputs ); pCur += 4*nInputs;
653 if ( fVerbose ) printf(
"Finished reading extension \"i\".\n" );
655 else if ( *pCur ==
'o' )
658 nOutputs = Gia_AigerReadInt(pCur)/4; pCur += 4;
659 pNew->
vOutReqs = Vec_FltStart( nOutputs );
660 memcpy( Vec_FltArray(pNew->
vOutReqs), pCur, (
size_t)4*nOutputs ); pCur += 4*nOutputs;
661 if ( fVerbose ) printf(
"Finished reading extension \"o\".\n" );
664 else if ( *pCur ==
'e' )
668 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
671 assert( pCur == pCurTemp );
672 if ( fVerbose ) printf(
"Finished reading extension \"e\".\n" );
675 else if ( *pCur ==
'f' )
678 assert( Gia_AigerReadInt(pCur) == 4*Gia_ManRegNum(pNew) ); pCur += 4;
679 pNew->
vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) );
680 memcpy( Vec_IntArray(pNew->
vFlopClasses), pCur, (
size_t)4*Gia_ManRegNum(pNew) ); pCur += 4*Gia_ManRegNum(pNew);
681 if ( fVerbose ) printf(
"Finished reading extension \"f\".\n" );
684 else if ( *pCur ==
'g' )
687 assert( Gia_AigerReadInt(pCur) == 4*Gia_ManObjNum(pNew) ); pCur += 4;
688 pNew->
vGateClasses = Vec_IntStart( Gia_ManObjNum(pNew) );
689 memcpy( Vec_IntArray(pNew->
vGateClasses), pCur, (
size_t)4*Gia_ManObjNum(pNew) ); pCur += 4*Gia_ManObjNum(pNew);
690 if ( fVerbose ) printf(
"Finished reading extension \"g\".\n" );
693 else if ( *pCur ==
'h' )
696 vStr = Vec_StrStart( Gia_AigerReadInt(pCur) ); pCur += 4;
697 memcpy( Vec_StrArray(vStr), pCur, (
size_t)Vec_StrSize(vStr) );
698 pCur += Vec_StrSize(vStr);
702 if ( fVerbose ) printf(
"Finished reading extension \"h\".\n" );
705 else if ( *pCur ==
'k' )
710 nSize = Gia_AigerReadInt(pCur);
711 pCurTemp = pCur + nSize + 4; pCur += 4;
713 assert( pCur == pCurTemp );
714 if ( fVerbose ) printf(
"Finished reading extension \"k\".\n" );
717 else if ( *pCur ==
'm' )
724 nSize = Gia_AigerReadInt(pCur);
725 pCurTemp = pCur + nSize + 4; pCur += 4;
727 assert( pCur == pCurTemp );
728 if ( fVerbose ) printf(
"Finished reading extension \"m\".\n" );
731 else if ( *pCur ==
'n' )
734 if ( (*pCur >=
'a' && *pCur <=
'z') || (*pCur >=
'A' && *pCur <=
'Z') || (*pCur >=
'0' && *pCur <=
'9') )
737 pNew->
pName = Abc_UtilStrsav( (
char *)pCur ); pCur +=
strlen(pNew->
pName) + 1;
741 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
743 pNew->
pName = Abc_UtilStrsav( (
char *)pCur ); pCur +=
strlen(pNew->
pName) + 1;
744 assert( pCur == pCurTemp );
748 else if ( *pCur ==
'p' )
752 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
754 memcpy( pPlacement, pCur, (
size_t)4*Gia_ManObjNum(pNew) ); pCur += 4*Gia_ManObjNum(pNew);
755 assert( pCur == pCurTemp );
757 if ( fVerbose ) printf(
"Finished reading extension \"p\".\n" );
760 else if ( *pCur ==
'r' )
764 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
765 nRegs = Gia_AigerReadInt(pCur); pCur += 4;
768 for ( i = 0; i < nRegs; i++ )
769 Vec_IntPush( pNew->
vRegClasses, Gia_AigerReadInt(pCur) ), pCur += 4;
770 assert( pCur == pCurTemp );
771 if ( fVerbose ) printf(
"Finished reading extension \"r\".\n" );
774 else if ( *pCur ==
's' )
778 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
779 nRegs = Gia_AigerReadInt(pCur); pCur += 4;
781 for ( i = 0; i < nRegs; i++ )
782 Vec_IntPush( pNew->
vRegInits, Gia_AigerReadInt(pCur) ), pCur += 4;
783 assert( pCur == pCurTemp );
784 if ( fVerbose ) printf(
"Finished reading extension \"s\".\n" );
787 else if ( *pCur ==
'b' )
791 nSize = Gia_AigerReadInt(pCur);
792 pCurTemp = pCur + nSize + 4; pCur += 4;
793 pNew->
pCellStr = Abc_UtilStrsav( (
char*)pCur ); pCur +=
strlen((
char*)pCur) + 1;
796 pNew->
vConfigs = Vec_IntAlloc(nSize / 4);
798 for ( i = 0; i < nSize / 4; i++ )
799 Vec_IntPush( pNew->
vConfigs, Gia_AigerReadInt(pCur) ), pCur += 4;
800 assert( pCur == pCurTemp );
801 if ( fVerbose ) printf(
"Finished reading extension \"b\".\n" );
804 else if ( *pCur ==
'q' )
806 int i, nPairs, iRepr, iNode;
807 assert( !Gia_ManHasChoices(pNew) );
810 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
811 nPairs = Gia_AigerReadInt(pCur); pCur += 4;
812 for ( i = 0; i < nPairs; i++ )
814 iRepr = Gia_AigerReadInt(pCur); pCur += 4;
815 iNode = Gia_AigerReadInt(pCur); pCur += 4;
816 pNew->
pSibls[iRepr] = iNode;
819 assert( pCur == pCurTemp );
820 if ( fVerbose ) printf(
"Finished reading extension \"q\".\n" );
823 else if ( *pCur ==
'u' )
825 unsigned char * pSwitching;
827 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
828 pSwitching =
ABC_ALLOC(
unsigned char, Gia_ManObjNum(pNew) );
829 memcpy( pSwitching, pCur, (
size_t)Gia_ManObjNum(pNew) ); pCur += Gia_ManObjNum(pNew);
830 assert( pCur == pCurTemp );
831 if ( fVerbose ) printf(
"Finished reading extension \"s\".\n" );
834 else if ( *pCur ==
't' )
837 vStr = Vec_StrStart( Gia_AigerReadInt(pCur) ); pCur += 4;
838 memcpy( Vec_StrArray(vStr), pCur, (
size_t)Vec_StrSize(vStr) ); pCur += Vec_StrSize(vStr);
841 if ( fVerbose ) printf(
"Finished reading extension \"t\".\n" );
844 else if ( *pCur ==
'v' )
847 pNew->
vObjClasses = Vec_IntStart( Gia_AigerReadInt(pCur)/4 ); pCur += 4;
850 if ( fVerbose ) printf(
"Finished reading extension \"v\".\n" );
853 else if ( *pCur ==
'w' )
858 pCurTemp = pCur + Gia_AigerReadInt(pCur) + 4; pCur += 4;
859 nPairs = Gia_AigerReadInt(pCur); pCur += 4;
860 vPairs = Vec_IntAlloc( 2*nPairs );
861 for ( i = 0; i < 2*nPairs; i++ )
862 Vec_IntPush( vPairs, Gia_AigerReadInt(pCur) ), pCur += 4;
863 assert( pCur == pCurTemp );
867 if ( fVerbose ) printf(
"Finished reading extension \"w\".\n" );
870 printf(
"Cannot read extension \"w\" because AIG is rehashed. Use \"&r -s <file.aig>\".\n" );
871 Vec_IntFree( vPairs );
878 Vec_IntFree( vNodes );
881 if ( nBad || nConstr || nJust || nFair )
889 Vec_IntFreeP( &vPoTypes );
896 Vec_Int_t * vFlopMap, * vGateMap, * vObjMap, * vRegClasses, * vRegInits;
905 if ( (vGateMap || vObjMap) && (Gia_ManObjNum(pNew) < Gia_ManObjNum(pTemp)) )
906 printf(
"Cleanup removed objects after reading. Old gate/object abstraction maps are invalid!\n" );
921 printf(
"Warning: Creating unit-delay box delay tables because box library is not available.\n" );
924 Vec_FltFreeP( &pNew->
vInArrs );
936 if ( vInits && Vec_IntSum(vInits) )
938 char * pInit =
ABC_ALLOC(
char, Vec_IntSize(vInits) + 1 );
941 assert( Vec_IntSize(vInits) == Gia_ManRegNum(pNew) );
944 if ( Vec_IntEntry(vInits, i) == 0 )
946 else if ( Vec_IntEntry(vInits, i) == 1 )
950 assert( Vec_IntEntry(vInits, i) == Abc_Var2Lit(Gia_ObjId(pNew, pObj), 0) );
964 Vec_IntFreeP( &vInits );
965 if ( !fGiaSimple && !fSkipStrash && pNew->
vMapping )
967 Abc_Print( 0,
"Structural hashing enabled while reading AIGER invalidated the mapping. Consider using \"&r -s\".\n" );
970 if ( vNamesIn && Gia_ManPiNum(pNew) != Vec_PtrSize(vNamesIn) )
971 Abc_Print( 0,
"The number of inputs does not match the number of input names.\n" );
972 else if ( vNamesOut && Gia_ManPoNum(pNew) != Vec_PtrSize(vNamesOut) )
973 Abc_Print( 0,
"The number of output does not match the number of output names.\n" );
974 else if ( vNamesRegOut && Gia_ManRegNum(pNew) != Vec_PtrSize(vNamesRegOut) )
975 Abc_Print( 0,
"The number of inputs does not match the number of flop names.\n" );
976 else if ( vNamesIn && vNamesOut )
978 pNew->
vNamesIn = vNamesIn; vNamesIn = NULL;
979 pNew->
vNamesOut = vNamesOut; vNamesOut = NULL;
982 Vec_PtrAppend( pNew->
vNamesIn, vNamesRegOut );
983 Vec_PtrClear( vNamesRegOut );
984 Vec_PtrFree( vNamesRegOut );
989 Vec_PtrAppend( pNew->
vNamesOut, vNamesRegIn );
990 Vec_PtrClear( vNamesRegIn );
991 Vec_PtrFree( vNamesRegIn );
995 if ( vNamesNode && Gia_ManObjNum(pNew) != Vec_PtrSize(vNamesNode) )
996 Abc_Print( 0,
"The size of the node name array does not match the number of objects. Names are not entered.\n" );
997 else if ( vNamesNode )
998 pNew->
vNamesNode = vNamesNode, vNamesNode = NULL;
999 if ( vNamesIn ) Vec_PtrFreeFree( vNamesIn );
1000 if ( vNamesOut ) Vec_PtrFreeFree( vNamesOut );
1001 if ( vNamesRegIn ) Vec_PtrFreeFree( vNamesRegIn );
1002 if ( vNamesRegOut ) Vec_PtrFreeFree( vNamesRegOut );
1227 int i, nBufferSize,
Pos;
1228 unsigned char * pBuffer;
1229 unsigned uLit0, uLit1, uLit;
1232 if ( Gia_ManCoNum(pInit) == 0 )
1234 printf(
"AIG cannot be written because it has no POs.\n" );
1239 pFile = fopen( pFileName,
"wb" );
1240 if ( pFile == NULL )
1242 fprintf( stdout,
"Gia_AigerWrite(): Cannot open the output file \"%s\".\n", pFileName );
1260 fprintf( pFile,
"aig%s %u %u %u %u %u",
1262 Gia_ManCiNum(
p) + Gia_ManAndNum(
p),
1265 Gia_ManConstrNum(
p) ? 0 : Gia_ManPoNum(
p),
1268 if ( Gia_ManConstrNum(
p) )
1269 fprintf( pFile,
" %u %u", Gia_ManPoNum(
p) - Gia_ManConstrNum(
p), Gia_ManConstrNum(
p) );
1270 fprintf( pFile,
"\n" );
1277 fprintf( pFile,
"%u\n", Gia_ObjFaninLit0p(
p, pObj) );
1280 fprintf( pFile,
"%u\n", Gia_ObjFaninLit0p(
p, pObj) );
1286 fwrite( Vec_StrArray(vBinary), 1, Vec_StrSize(vBinary), pFile );
1287 Vec_StrFree( vBinary );
1288 Vec_IntFree( vLits );
1294 nBufferSize = 8 * Gia_ManAndNum(
p) + 100;
1295 pBuffer =
ABC_ALLOC(
unsigned char, nBufferSize );
1298 uLit = Abc_Var2Lit( i, 0 );
1299 uLit0 = Gia_ObjFaninLit0( pObj, i );
1300 uLit1 = Gia_ObjFaninLit1( pObj, i );
1301 assert(
p->fGiaSimple || Gia_ManBufNum(
p) || uLit0 < uLit1 );
1302 Pos = Gia_AigerWriteUnsignedBuffer( pBuffer,
Pos, uLit - uLit1 );
1303 Pos = Gia_AigerWriteUnsignedBuffer( pBuffer,
Pos, uLit1 - uLit0 );
1304 if (
Pos > nBufferSize - 10 )
1306 printf(
"Gia_AigerWrite(): AIGER generation has failed because the allocated buffer is too small.\n" );
1316 fwrite( pBuffer, 1,
Pos, pFile );
1320 if (
p->vNamesIn &&
p->vNamesOut )
1322 assert( Vec_PtrSize(
p->vNamesIn) == Gia_ManCiNum(
p) );
1323 assert( Vec_PtrSize(
p->vNamesOut) == Gia_ManCoNum(
p) );
1326 fprintf( pFile,
"i%d %s\n", i, (
char *)Vec_PtrEntry(
p->vNamesIn, i) );
1329 fprintf( pFile,
"l%d %s\n", i, (
char *)Vec_PtrEntry(
p->vNamesIn, Gia_ManPiNum(
p) + i) );
1332 fprintf( pFile,
"o%d %s\n", i, (
char *)Vec_PtrEntry(
p->vNamesOut, i) );
1334 if (
p->vNamesNode && Vec_PtrSize(
p->vNamesNode) != Gia_ManObjNum(
p) )
1335 Abc_Print( 0,
"The size of the node name array does not match the number of objects. Names are not written.\n" );
1336 else if (
p->vNamesNode )
1339 if ( Vec_PtrEntry(
p->vNamesNode, i) )
1340 fprintf( pFile,
"n%d %s\n", i, (
char *)Vec_PtrEntry(
p->vNamesNode, i) );
1344 if ( fWriteNewLine )
1345 fprintf( pFile,
"c\n" );
1347 fprintf( pFile,
"c" );
1352 fprintf( pFile,
"a" );
1355 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1356 Vec_StrFree( vStrExt );
1357 if ( fVerbose ) printf(
"Finished writing extension \"a\".\n" );
1362 fprintf( pFile,
"c" );
1367 if (
p->nAnd2Delay )
1369 fprintf( pFile,
"d" );
1379 fprintf( pFile,
"i" );
1383 if ( fVerbose ) printf(
"Finished writing extension \"i\".\n" );
1388 fprintf( pFile,
"o" );
1392 if ( fVerbose ) printf(
"Finished writing extension \"o\".\n" );
1396 if (
p->pReprs &&
p->pNexts )
1399 fprintf( pFile,
"e" );
1402 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1403 Vec_StrFree( vStrExt );
1406 if (
p->vFlopClasses )
1408 fprintf( pFile,
"f" );
1410 assert( Vec_IntSize(
p->vFlopClasses) == Gia_ManRegNum(
p) );
1411 fwrite( Vec_IntArray(
p->vFlopClasses), 1, 4*Gia_ManRegNum(
p), pFile );
1414 if (
p->vGateClasses )
1416 fprintf( pFile,
"g" );
1418 assert( Vec_IntSize(
p->vGateClasses) == Gia_ManObjNum(
p) );
1419 fwrite( Vec_IntArray(
p->vGateClasses), 1, 4*Gia_ManObjNum(
p), pFile );
1424 fprintf( pFile,
"h" );
1427 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1428 Vec_StrFree( vStrExt );
1429 if ( fVerbose ) printf(
"Finished writing extension \"h\".\n" );
1435 fprintf( pFile,
"k" );
1438 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1439 Vec_StrFree( vStrExt );
1440 if ( fVerbose ) printf(
"Finished writing extension \"k\".\n" );
1447 fprintf( pFile,
"w" );
1450 for ( i = 0; i < Vec_IntSize(vPairs); i++ )
1452 Vec_IntFree( vPairs );
1455 if ( Gia_ManHasMapping(
p) )
1460 fprintf( pFile,
"m" );
1463 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1464 Vec_StrFree( vStrExt );
1465 if ( fVerbose ) printf(
"Finished writing extension \"m\".\n" );
1468 if ( Gia_ManHasCellMapping(
p) )
1471 fprintf( pFile,
"M" );
1474 fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile );
1475 Vec_StrFree( vStrExt );
1476 if ( fVerbose ) printf(
"Finished writing extension \"M\".\n" );
1480 if (
p->pPlacement )
1482 fprintf( pFile,
"p" );
1484 fwrite(
p->pPlacement, 1, 4*Gia_ManObjNum(
p), pFile );
1487 if (
p->vRegClasses )
1490 fprintf( pFile,
"r" );
1493 for ( i = 0; i < Vec_IntSize(
p->vRegClasses); i++ )
1500 fprintf( pFile,
"s" );
1503 for ( i = 0; i < Vec_IntSize(
p->vRegInits); i++ )
1509 fprintf( pFile,
"b" );
1510 assert(
p->pCellStr != NULL );
1512 fwrite(
p->pCellStr, 1,
strlen(
p->pCellStr) + 1, pFile );
1514 for ( i = 0; i < Vec_IntSize(
p->vConfigs); i++ )
1518 if ( Gia_ManHasChoices(
p) )
1521 fprintf( pFile,
"q" );
1522 for ( i = 0; i < Gia_ManObjNum(
p); i++ )
1523 nPairs += (Gia_ObjSibl(
p, i) > 0);
1526 for ( i = 0; i < Gia_ManObjNum(
p); i++ )
1527 if ( Gia_ObjSibl(
p, i) )
1529 assert( i > Gia_ObjSibl(
p, i) );
1533 if ( fVerbose ) printf(
"Finished writing extension \"q\".\n" );
1536 if (
p->pSwitching )
1538 fprintf( pFile,
"u" );
1540 fwrite(
p->pSwitching, 1, Gia_ManObjNum(
p), pFile );
1554 if (
p->vObjClasses )
1556 fprintf( pFile,
"v" );
1558 assert( Vec_IntSize(
p->vObjClasses) == Gia_ManObjNum(
p) );
1559 fwrite( Vec_IntArray(
p->vObjClasses), 1, 4*Gia_ManObjNum(
p), pFile );
1564 fprintf( pFile,
"n" );
1566 fwrite(
p->pName, 1,
strlen(
p->pName), pFile );
1567 fprintf( pFile,
"%c",
'\0' );
1570 if ( fWriteNewLine )
1571 fprintf( pFile,
"c\n" );
1572 if ( !fSkipComment ) {
1573 fprintf( pFile,
"\nThis file was produced by the GIA package in ABC on %s\n",
Gia_TimeStamp() );
1574 fprintf( pFile,
"For information about AIGER format, refer to %s\n",
"http://fmv.jku.at/aiger" );