39#define vsnprintf _vsnprintf
146static unsigned Io_ObjMakeLit(
int Var,
int fCompl ) {
return (
Var << 1) | fCompl; }
147static unsigned Io_ObjAigerNum(
Abc_Obj_t * pObj ) {
return (
unsigned)(ABC_PTRINT_T)pObj->
pCopy; }
148static void Io_ObjSetAigerNum(
Abc_Obj_t * pObj,
unsigned Num ) { pObj->
pCopy = (
Abc_Obj_t *)(ABC_PTRINT_T)Num; }
171 ch = (x & 0x7f) | 0x80;
198 vLits = Vec_IntAlloc( Abc_NtkCoNum(pNtk) );
201 pDriver = Abc_ObjFanin0(pObj);
202 Vec_IntPush( vLits, Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) );
206 pDriver = Abc_ObjFanin0(pObj);
207 Vec_IntPush( vLits, Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) );
226 int Pos = 0, Lit, LitPrev, Diff, i;
227 vBinary = Vec_StrAlloc( 2 * Vec_IntSize(vLits) );
228 LitPrev = Vec_IntEntry( vLits, 0 );
232 Diff = Lit - LitPrev;
233 Diff = (Lit < LitPrev)? -Diff : Diff;
234 Diff = (Diff << 1) | (
int)(Lit < LitPrev);
237 if (
Pos + 10 > vBinary->
nCap )
238 Vec_StrGrow( vBinary, vBinary->
nCap+1 );
274 int i, nNodes, nBufferSize,
Pos, fExtended;
275 unsigned char * pBuffer;
276 unsigned uLit0, uLit1, uLit;
278 fExtended = Abc_NtkConstrNum(pNtk);
280 assert( Abc_NtkIsStrash(pNtk) );
282 if ( !Abc_LatchIsInit0(pObj) )
289 fprintf( stdout,
"Io_WriteAiger(): Cannot write AIGER format with non-0 latch init values. Run \"zero\".\n" );
294 pFile = fopen( pFileName,
"wb" );
297 fprintf( stdout,
"Io_WriteAiger(): Cannot open the output file \"%s\".\n", pFileName );
305 Io_ObjSetAigerNum( pObj, nNodes++ );
307 Io_ObjSetAigerNum( pObj, nNodes++ );
310 fprintf( pFile,
"aig%s %u %u %u %u %u",
312 Abc_NtkPiNum(pNtk) + Abc_NtkLatchNum(pNtk) + Abc_NtkNodeNum(pNtk),
314 Abc_NtkLatchNum(pNtk),
315 fExtended ? 0 : Abc_NtkPoNum(pNtk),
316 Abc_NtkNodeNum(pNtk) );
319 fprintf( pFile,
" %u %u", Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk), Abc_NtkConstrNum(pNtk) );
320 fprintf( pFile,
"\n" );
332 pObj = Abc_ObjFanin0(pLatch);
333 pDriver = Abc_ObjFanin0(pObj);
334 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) );
335 if ( Abc_LatchIsInit0(pLatch) )
336 fprintf( pFile,
"%u\n", uLit );
337 else if ( Abc_LatchIsInit1(pLatch) )
338 fprintf( pFile,
"%u 1\n", uLit );
342 assert( Abc_LatchIsInitNone(pLatch) || Abc_LatchIsInitDc(pLatch) );
343 fprintf( pFile,
"%u %u\n", uLit, Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanout0(pLatch)), 0 ) );
349 pDriver = Abc_ObjFanin0(pObj);
350 fprintf( pFile,
"%u\n", Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) );
357 fwrite( Vec_StrArray(vBinary), 1, Vec_StrSize(vBinary), pFile );
358 Vec_StrFree( vBinary );
359 Vec_IntFree( vLits );
365 nBufferSize = 6 * Abc_NtkNodeNum(pNtk) + 100;
366 pBuffer =
ABC_ALLOC(
unsigned char, nBufferSize );
370 Extra_ProgressBarUpdate( pProgress, i, NULL );
371 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pObj), 0 );
372 uLit0 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin0(pObj)), Abc_ObjFaninC0(pObj) );
373 uLit1 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin1(pObj)), Abc_ObjFaninC1(pObj) );
376 unsigned Temp = uLit0;
383 if (
Pos > nBufferSize - 10 )
385 printf(
"Io_WriteAiger(): AIGER generation has failed because the allocated buffer is too small.\n" );
394 fwrite( pBuffer, 1,
Pos, pFile );
402 fprintf( pFile,
"i%d %s\n", i,
Abc_ObjName(pObj) );
405 fprintf( pFile,
"l%d %s\n", i,
Abc_ObjName(Abc_ObjFanout0(pObj)) );
409 fprintf( pFile,
"o%d %s\n", i,
Abc_ObjName(pObj) );
410 else if ( i < Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk) )
411 fprintf( pFile,
"b%d %s\n", i,
Abc_ObjName(pObj) );
413 fprintf( pFile,
"c%d %s\n", i - (Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk)),
Abc_ObjName(pObj) );
417 fprintf( pFile,
"c\n" );
419 fprintf( pFile,
".model %s\n", pNtk->
pName );
420 fprintf( pFile,
"This file was produced by ABC on %s\n",
Extra_TimeStamp() );
421 fprintf( pFile,
"For information about AIGER format, refer to %s\n",
"http://fmv.jku.at/aiger" );
441 int i, nNodes,
Pos, nBufferSize, fExtended;
442 unsigned char * pBuffer;
443 unsigned uLit0, uLit1, uLit;
445 assert( Abc_NtkIsStrash(pNtk) );
447 pFile =
gzopen( pFileName,
"wb" );
450 fprintf( stdout,
"Io_WriteAigerGz(): Cannot open the output file \"%s\".\n", pFileName );
454 fExtended = Abc_NtkConstrNum(pNtk);
460 Io_ObjSetAigerNum( pObj, nNodes++ );
462 Io_ObjSetAigerNum( pObj, nNodes++ );
465 gzprintf( pFile,
"aig %u %u %u %u %u",
466 Abc_NtkPiNum(pNtk) + Abc_NtkLatchNum(pNtk) + Abc_NtkNodeNum(pNtk),
468 Abc_NtkLatchNum(pNtk),
469 fExtended ? 0 : Abc_NtkPoNum(pNtk),
470 Abc_NtkNodeNum(pNtk) );
473 gzprintf( pFile,
" %u %u", Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk), Abc_NtkConstrNum(pNtk) );
484 pObj = Abc_ObjFanin0(pLatch);
485 pDriver = Abc_ObjFanin0(pObj);
486 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) );
487 if ( Abc_LatchIsInit0(pLatch) )
489 else if ( Abc_LatchIsInit1(pLatch) )
494 assert( Abc_LatchIsInitNone(pLatch) || Abc_LatchIsInitDc(pLatch) );
495 gzprintf( pFile,
"%u %u\n", uLit, Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanout0(pLatch)), 0 ) );
501 pDriver = Abc_ObjFanin0(pObj);
502 gzprintf( pFile,
"%u\n", Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) );
508 nBufferSize = 6 * Abc_NtkNodeNum(pNtk) + 100;
509 pBuffer =
ABC_ALLOC(
unsigned char, nBufferSize );
513 Extra_ProgressBarUpdate( pProgress, i, NULL );
514 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pObj), 0 );
515 uLit0 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin0(pObj)), Abc_ObjFaninC0(pObj) );
516 uLit1 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin1(pObj)), Abc_ObjFaninC1(pObj) );
519 unsigned Temp = uLit0;
526 if (
Pos > nBufferSize - 10 )
528 printf(
"Io_WriteAiger(): AIGER generation has failed because the allocated buffer is too small.\n" );
553 else if ( i < Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk) )
556 gzprintf( pFile,
"c%d %s\n", i - (Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk)),
Abc_ObjName(pObj) );
564 gzprintf( pFile,
"For information about AIGER format, refer to %s\n",
"http://fmv.jku.at/aiger" );
610 fprintf( stdout,
"Ioa_WriteBlif(): I/O error writing to compressed stream.\n" );
618 n = vfprintf( b->
f, fmt, ap);
640 int i, nNodes, nBufferSize, bzError,
Pos, fExtended;
641 unsigned char * pBuffer;
642 unsigned uLit0, uLit1, uLit;
652 fExtended = Abc_NtkConstrNum(pNtk);
655 assert( Abc_NtkIsStrash(pNtk) );
657 if ( !Abc_LatchIsInit0(pObj) )
664 fprintf( stdout,
"Io_WriteAiger(): Cannot write AIGER format with non-0 latch init values. Run \"zero\".\n" );
680 b.
f = fopen( pFileName,
"wb" );
683 fprintf( stdout,
"Io_WriteAiger(): Cannot open the output file \"%s\".\n", pFileName );
689 if ( bzError !=
BZ_OK ) {
691 fprintf( stdout,
"Io_WriteAiger(): Cannot start compressed stream.\n" );
702 Io_ObjSetAigerNum( pObj, nNodes++ );
704 Io_ObjSetAigerNum( pObj, nNodes++ );
709 Abc_NtkPiNum(pNtk) + Abc_NtkLatchNum(pNtk) + Abc_NtkNodeNum(pNtk),
711 Abc_NtkLatchNum(pNtk),
712 fExtended ? 0 : Abc_NtkPoNum(pNtk),
713 Abc_NtkNodeNum(pNtk) );
716 fprintfBz2Aig( &b,
" %u %u", Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk), Abc_NtkConstrNum(pNtk) );
729 pObj = Abc_ObjFanin0(pLatch);
730 pDriver = Abc_ObjFanin0(pObj);
731 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) );
732 if ( Abc_LatchIsInit0(pLatch) )
734 else if ( Abc_LatchIsInit1(pLatch) )
739 assert( Abc_LatchIsInitNone(pLatch) || Abc_LatchIsInitDc(pLatch) );
740 fprintfBz2Aig( &b,
"%u %u\n", uLit, Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanout0(pLatch)), 0 ) );
746 pDriver = Abc_ObjFanin0(pObj);
747 fprintfBz2Aig( &b,
"%u\n", Io_ObjMakeLit( Io_ObjAigerNum(pDriver), Abc_ObjFaninC0(pObj) ^ (Io_ObjAigerNum(pDriver) == 0) ) );
755 fwrite( Vec_StrArray(vBinary), 1, Vec_StrSize(vBinary), b.
f );
758 BZ2_bzWrite( &bzError, b.
b, Vec_StrArray(vBinary), Vec_StrSize(vBinary) );
760 fprintf( stdout,
"Io_WriteAiger(): I/O error writing to compressed stream.\n" );
763 Vec_StrFree( vBinary );
767 Vec_StrFree( vBinary );
768 Vec_IntFree( vLits );
774 nBufferSize = 6 * Abc_NtkNodeNum(pNtk) + 100;
775 pBuffer =
ABC_ALLOC(
unsigned char, nBufferSize );
779 Extra_ProgressBarUpdate( pProgress, i, NULL );
780 uLit = Io_ObjMakeLit( Io_ObjAigerNum(pObj), 0 );
781 uLit0 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin0(pObj)), Abc_ObjFaninC0(pObj) );
782 uLit1 = Io_ObjMakeLit( Io_ObjAigerNum(Abc_ObjFanin1(pObj)), Abc_ObjFaninC1(pObj) );
785 unsigned Temp = uLit0;
792 if (
Pos > nBufferSize - 10 )
794 printf(
"Io_WriteAiger(): AIGER generation has failed because the allocated buffer is too small.\n" );
806 fwrite( pBuffer, 1,
Pos, b.
f );
811 fprintf( stdout,
"Io_WriteAiger(): I/O error writing to compressed stream.\n" );
832 else if ( i < Abc_NtkPoNum(pNtk) - Abc_NtkConstrNum(pNtk) )
845 fprintfBz2Aig( &b,
"For information about AIGER format, refer to %s\n",
"http://fmv.jku.at/aiger" );
852 fprintf( stdout,
"Io_WriteAiger(): I/O error closing compressed stream.\n" );
892 Abc_NtkPiNum(pNtk) == pCex->nPis &&
893 Abc_NtkLatchNum(pNtk) == pCex->nRegs )
897 else if ( pGia != NULL &&
898 Gia_ManPiNum(pGia) == pCex->nPis &&
899 Gia_ManRegNum(pGia) == pCex->
nRegs )
905 printf(
"AIG parameters do not match those of the CEX.\n" );
910 pFile = fopen( pFileName,
"wb" );
911 fprintf( pFile,
"1\n" );
913 for ( k = 0; k < pCex->nRegs; k++ )
914 fprintf( pFile,
"0" );
915 fprintf( pFile,
" " );
917 Aig_ManConst1(pAig)->fMarkA = 1;
918 for ( f = 0; f <= pCex->iFrame; f++ )
920 for ( k = 0; k < pCex->nPis; k++ )
922 fprintf( pFile,
"%d", Abc_InfoHasBit(pCex->pData, b) );
923 Aig_ManCi( pAig, k )->fMarkA = Abc_InfoHasBit(pCex->pData, b++);
925 fprintf( pFile,
" " );
927 pObj->
fMarkA = (Aig_ObjFanin0(pObj)->fMarkA ^ Aig_ObjFaninC0(pObj)) &
928 (Aig_ObjFanin1(pObj)->fMarkA ^ Aig_ObjFaninC1(pObj));
930 pObj->
fMarkA = (Aig_ObjFanin0(pObj)->fMarkA ^ Aig_ObjFaninC0(pObj));
932 fprintf( pFile,
"%d", pObj->
fMarkA );
933 fprintf( pFile,
" " );
935 fprintf( pFile,
"%d", pObj->
fMarkA );
936 fprintf( pFile,
"\n" );
937 if ( f == pCex->iFrame )
940 fprintf( pFile,
"%d", pObj->
fMarkA );
941 fprintf( pFile,
" " );
945 assert( b == pCex->nBits );
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_AigForEachAnd(pNtk, pNode, i)
#define Abc_NtkForEachPo(pNtk, pPo, i)
#define Abc_NtkForEachLatch(pNtk, pObj, i)
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NtkInvertConstraints(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachLatchInput(pNtk, pObj, i)
#define Abc_NtkForEachPi(pNtk, pPi, i)
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManCleanMarkA(Aig_Man_t *p)
void Aig_ManStop(Aig_Man_t *p)
struct Aig_Obj_t_ Aig_Obj_t
#define Aig_ManForEachNode(p, pObj, i)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
#define Aig_ManForEachCo(p, pObj, i)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
BZFILE *BZ_API BZ2_bzWriteOpen(int *bzerror, FILE *f, int blockSize100k, int verbosity, int workFactor)
void BZ_API BZ2_bzWrite(int *bzerror, BZFILE *b, void *buf, int len)
void BZ_API BZ2_bzWriteClose(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Aig_Man_t * Abc_NtkToDar(Abc_Ntk_t *pNtk, int fExors, int fRegisters)
struct Gia_Man_t_ Gia_Man_t
ABC_NAMESPACE_IMPL_START int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(const char *path, const char *mode)
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
Vec_Str_t * Io_WriteEncodeLiterals(Vec_Int_t *vLits)
int Io_WriteAigerEncode(unsigned char *pBuffer, int Pos, unsigned x)
FUNCTION DEFINITIONS ///.
int fprintfBz2Aig(bz2file *b, char *fmt,...)
void Io_WriteAiger(Abc_Ntk_t *pNtk, char *pFileName, int fWriteSymbols, int fCompact, int fUnique)
Vec_Int_t * Io_WriteAigerLiterals(Abc_Ntk_t *pNtk)
void Io_WriteAigerGz(Abc_Ntk_t *pNtk, char *pFileName, int fWriteSymbols)
void Io_WriteAiger_old(Abc_Ntk_t *pNtk, char *pFileName, int fWriteSymbols, int fCompact)
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START void Io_WriteAigerCex(Abc_Cex_t *pCex, Abc_Ntk_t *pNtk, void *pG, char *pFileName)
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
#define Saig_ManForEachLi(p, pObj, i)
#define Saig_ManForEachPo(p, pObj, i)
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)