28 #define XAIG_VERBOSE 0
52 for ( pName = pFileName; *pName; pName++ )
60 if ( (pDot =
strrchr( pRes,
'.' )) )
68 pFile = fopen( pFileName,
"r" );
71 printf(
"Gia_FileSize(): The file is unavailable (absent or open).\n" );
75 nFileSize = ftell( pFile );
81 unsigned char Buffer[5];
83 fwrite( Buffer, 1, 4, pFile );
112 int Lit, LitPrev, Diff, i;
116 for ( i = 1; i < nEntries; i++ )
122 Diff = (Diff & 1)? -(Diff >> 1) : Diff >> 1;
123 Lit = Diff + LitPrev;
132 int Pos = 0, Lit, LitPrev, Diff, i;
138 Diff = Lit - LitPrev;
139 Diff = (Lit < LitPrev)? -Diff : Diff;
140 Diff = (Diff << 1) | (
int)(Lit < LitPrev);
143 if ( Pos + 10 > vBinary->
nCap )
179 Vec_Int_t * vLits = NULL, * vPoTypes = NULL;
180 Vec_Int_t * vNodes, * vDrivers, * vInits = NULL;
181 int iObj, iNode0, iNode1, fHieOnly = 0;
182 int nTotal, nInputs, nOutputs, nLatches, nAnds, i;
183 int nBad = 0, nConstr = 0, nJust = 0, nFair = 0;
184 unsigned char * pDrivers, * pSymbols, * pCur;
185 unsigned uLit0, uLit1, uLit;
188 pCur = (
unsigned char *)pContents;
while ( *pCur !=
' ' ) pCur++; pCur++;
190 nTotal = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
192 nInputs = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
194 nLatches = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
196 nOutputs = atoi( (
const char *)pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
198 nAnds = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
204 nBad = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
211 nConstr = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
218 nJust = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
225 nFair = atoi( (
const char *)pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
230 fprintf( stdout,
"The parameter line is in a wrong format.\n" );
236 if ( nTotal != nInputs + nLatches + nAnds )
238 fprintf( stdout,
"The number of objects does not match.\n" );
241 if ( nJust || nFair )
243 fprintf( stdout,
"Reading AIGER files with liveness properties is currently not supported.\n" );
250 fprintf( stdout,
"Warning: The last output is interpreted as a constraint.\n" );
252 fprintf( stdout,
"Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
256 pNew =
Gia_ManStart( nTotal + nLatches + nOutputs + 1 );
264 for ( i = 0; i < nInputs + nLatches; i++ )
272 if ( pContents[3] ==
' ' )
275 for ( i = 0; i < nLatches + nOutputs; )
276 if ( *pCur++ ==
'\n' )
287 for ( i = 0; i < nAnds; i++ )
289 uLit = ((i + 1 + nInputs + nLatches) << 1);
298 if ( iNode0 == iNode1 )
314 if ( pContents[3] ==
' ' )
318 for ( i = 0; i < nLatches; i++ )
320 uLit0 = atoi( (
char *)pCur );
321 while ( *pCur !=
' ' && *pCur !=
'\n' )
327 while ( *pCur++ !=
'\n' );
338 for ( i = 0; i < nOutputs; i++ )
340 uLit0 = atoi( (
char *)pCur );
while ( *pCur++ !=
'\n' );
349 for ( i = 0; i < nLatches; i++ )
356 for ( i = 0; i < nOutputs; i++ )
366 for ( i = 0; i < nOutputs; i++ )
368 for ( i = 0; i < nLatches; i++ )
377 if ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
380 unsigned char * pCurOld = pCur;
384 while ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
387 char * pType = (
char *)pCur;
389 if ( *pCur !=
'i' && *pCur !=
'o' && *pCur !=
'l' )
396 iTerm = atoi( (
char *)++pCur );
while ( *pCur++ !=
' ' );
398 while ( *pCur ==
' ' )
404 if ( *pCur++ !=
'@' )
409 if ( *pCur ==
'i' && *pType ==
'i' )
411 else if ( *pCur ==
'o' && *pType ==
'o' )
413 else if ( *pCur ==
'l' && *pType ==
'l' )
417 fprintf( stdout,
"Wrong name format.\n" );
422 while ( *pCur++ !=
'\n' );
427 unsigned char * pName;
428 int Entry, nInvars, nConstr, iTerm;
438 pCur = (
unsigned char *)pCurOld;
439 while ( pCur < (
unsigned char *)pContents + nFileSize && *pCur !=
'c' )
442 if ( *pCur ==
'i' || *pCur ==
'l' )
445 while ( *pCur++ !=
'\n' );
456 iTerm = atoi( (
char *)++pCur );
while ( *pCur++ !=
' ' );
458 if ( iTerm < 0 || iTerm >= nOutputs )
460 fprintf( stdout,
"The output number (%d) is out of range.\n", iTerm );
466 fprintf( stdout,
"The output number (%d) is listed twice.\n", iTerm );
472 pName = pCur;
while ( *pCur++ !=
'\n' );
481 nInvars = nConstr = 0;
487 if (
strncmp( pContents+Entry,
"constraint:", 11 ) == 0 )
492 if (
strncmp( pContents+Entry,
"invariant:", 10 ) == 0 )
499 fprintf( stdout,
"Recognized and added %d constraints.\n", nConstr );
501 fprintf( stdout,
"Recognized and skipped %d invariants.\n", nInvars );
502 if ( nConstr == 0 && nInvars == 0 )
511 if ( pCur + 1 < (
unsigned char *)pContents + nFileSize && *pCur ==
'c' )
515 unsigned char * pCurTemp;
520 while ( pCur < (
unsigned char *)pContents + nFileSize )
531 if ( fVerbose ) printf(
"Finished reading extension \"a\".\n" );
534 else if ( *pCur ==
'c' )
539 if ( fVerbose ) printf(
"Finished reading extension \"c\".\n" );
542 else if ( *pCur ==
'd' )
547 if ( fVerbose ) printf(
"Finished reading extension \"d\".\n" );
549 else if ( *pCur ==
'i' )
555 if ( fVerbose ) printf(
"Finished reading extension \"i\".\n" );
557 else if ( *pCur ==
'o' )
563 if ( fVerbose ) printf(
"Finished reading extension \"o\".\n" );
566 else if ( *pCur ==
'e' )
573 assert( pCur == pCurTemp );
574 if ( fVerbose ) printf(
"Finished reading extension \"e\".\n" );
577 else if ( *pCur ==
'f' )
583 if ( fVerbose ) printf(
"Finished reading extension \"f\".\n" );
586 else if ( *pCur ==
'g' )
592 if ( fVerbose ) printf(
"Finished reading extension \"g\".\n" );
595 else if ( *pCur ==
'h' )
604 if ( fVerbose ) printf(
"Finished reading extension \"h\".\n" );
607 else if ( *pCur ==
'k' )
613 pCurTemp = pCur + nSize + 4; pCur += 4;
615 assert( pCur == pCurTemp );
616 if ( fVerbose ) printf(
"Finished reading extension \"k\".\n" );
619 else if ( *pCur ==
'm' )
627 pCurTemp = pCur + nSize + 4; pCur += 4;
629 assert( pCur == pCurTemp );
630 if ( fVerbose ) printf(
"Finished reading extension \"m\".\n" );
633 else if ( *pCur ==
'n' )
636 if ( (*pCur >=
'a' && *pCur <=
'z') || (*pCur >=
'A' && *pCur <=
'Z') || (*pCur >=
'0' && *pCur <=
'9') )
645 assert( pCur == pCurTemp );
649 else if ( *pCur ==
'p' )
656 assert( pCur == pCurTemp );
658 if ( fVerbose ) printf(
"Finished reading extension \"p\".\n" );
661 else if ( *pCur ==
'r' )
667 for ( i = 0; i < nRegs; i++ )
669 if ( fVerbose ) printf(
"Finished reading extension \"r\".\n" );
672 else if ( *pCur ==
'q' )
674 int i, nPairs, iRepr, iNode;
680 for ( i = 0; i < nPairs; i++ )
684 pNew->
pSibls[iRepr] = iNode;
687 assert( pCur == pCurTemp );
688 if ( fVerbose ) printf(
"Finished reading extension \"q\".\n" );
691 else if ( *pCur ==
'u' )
693 unsigned char * pSwitching;
698 assert( pCur == pCurTemp );
699 if ( fVerbose ) printf(
"Finished reading extension \"s\".\n" );
702 else if ( *pCur ==
't' )
709 if ( fVerbose ) printf(
"Finished reading extension \"t\".\n" );
712 else if ( *pCur ==
'v' )
718 if ( fVerbose ) printf(
"Finished reading extension \"v\".\n" );
728 if ( nBad || nConstr || nJust || nFair )
742 Vec_Int_t * vFlopMap, * vGateMap, * vObjMap;
749 printf(
"Cleanup removed objects after reading. Old gate/object abstraction maps are invalid!\n" );
761 printf(
"Warning: Creating unit-delay box delay tables because box library is not available.\n" );
802 if ( !fSkipStrash && pNew->
vMapping )
804 Abc_Print( 0,
"Structural hashing enabled while reading AIGER invalidated the mapping. Consider using \"&r -s\".\n" );
825 char * pName, * pContents;
832 pFile = fopen( pFileName,
"rb" );
833 pContents =
ABC_ALLOC(
char, nFileSize );
834 RetValue = fread( pContents, nFileSize, 1, pFile );
870 int nNodes = 0, i, uLit, uLit0, uLit1;
874 pObj->
Value = nNodes++;
876 pObj->
Value = nNodes++;
944 int nNodes = 0, i, uLit, uLit0, uLit1;
950 pObj->
Value = nNodes++;
955 pObj->
Value = nNodes++;
1000 if ( uLit0 > uLit1 )
1031 int i, nBufferSize,
Pos;
1032 unsigned char * pBuffer;
1033 unsigned uLit0, uLit1, uLit;
1038 printf(
"AIG cannot be written because it has no POs.\n" );
1043 pFile = fopen( pFileName,
"wb" );
1044 if ( pFile == NULL )
1046 fprintf( stdout,
"Gia_AigerWrite(): Cannot open the output file \"%s\".\n", pFileName );
1066 fprintf( pFile,
"aig%s %u %u %u %u %u",
1076 fprintf( pFile,
"\n" );
1101 pBuffer =
ABC_ALLOC(
unsigned char, nBufferSize );
1110 if ( Pos > nBufferSize - 10 )
1112 printf(
"Gia_AigerWrite(): AIGER generation has failed because the allocated buffer is too small.\n" );
1119 assert( Pos < nBufferSize );
1122 fwrite( pBuffer, 1, Pos, pFile );
1143 fprintf( pFile,
"c" );
1148 fprintf( pFile,
"a" );
1153 if ( fVerbose ) printf(
"Finished writing extension \"a\".\n" );
1158 fprintf( pFile,
"c" );
1165 fprintf( pFile,
"d" );
1175 fprintf( pFile,
"i" );
1179 if ( fVerbose ) printf(
"Finished writing extension \"i\".\n" );
1184 fprintf( pFile,
"o" );
1188 if ( fVerbose ) printf(
"Finished writing extension \"o\".\n" );
1195 fprintf( pFile,
"e" );
1204 fprintf( pFile,
"f" );
1212 fprintf( pFile,
"g" );
1220 fprintf( pFile,
"h" );
1225 if ( fVerbose ) printf(
"Finished writing extension \"h\".\n" );
1231 fprintf( pFile,
"k" );
1236 if ( fVerbose ) printf(
"Finished writing extension \"k\".\n" );
1244 fprintf( pFile,
"m" );
1249 if ( fVerbose ) printf(
"Finished writing extension \"m\".\n" );
1254 fprintf( pFile,
"p" );
1262 fprintf( pFile,
"r" );
1271 fprintf( pFile,
"q" );
1283 if ( fVerbose ) printf(
"Finished writing extension \"q\".\n" );
1288 fprintf( pFile,
"u" );
1306 fprintf( pFile,
"v" );
1314 fprintf( pFile,
"n" );
1317 fprintf( pFile,
"%c",
'\0' );
1320 fprintf( pFile,
"\nThis file was produced by the GIA package in ABC on %s\n",
Gia_TimeStamp() );
1321 fprintf( pFile,
"For information about AIGER format, refer to %s\n",
"http://fmv.jku.at/aiger" );
1346 sprintf( Buffer,
"%s%0*d.aig", pFilePrefix, nFileNumDigits, iFileNum );
1367 printf(
"Gia_AigerWriteSimple(): AIG cannot be written because it has no POs.\n" );
1371 pFile = fopen( pFileName,
"wb" );
1372 if ( pFile == NULL )
1374 fprintf( stdout,
"Gia_AigerWriteSimple(): Cannot open the output file \"%s\".\n", pFileName );
void Gia_AigerWriteSimple(Gia_Man_t *pInit, char *pFileName)
static int * Vec_IntArray(Vec_Int_t *p)
static int Gia_ManAppendAnd(Gia_Man_t *p, int iLit0, int iLit1)
static int Gia_ObjFaninLit0(Gia_Obj_t *pObj, int ObjId)
void Gia_ManInvertConstraints(Gia_Man_t *pAig)
Vec_Str_t * Tim_ManSave(Tim_Man_t *p, int fHieOnly)
FUNCTION DEFINITIONS ///.
void Gia_ManStop(Gia_Man_t *p)
static void Gia_AigerWriteInt(unsigned char *pPos, int Value)
static int Gia_ManPoNum(Gia_Man_t *p)
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
static char * Vec_StrArray(Vec_Str_t *p)
static int Gia_ObjFaninLit0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Vec_Str_t * Gia_AigerWriteMappingDoc(Gia_Man_t *p)
static int Gia_ManConstrNum(Gia_Man_t *p)
static void Vec_StrPrintNum(Vec_Str_t *p, int Num)
static int Gia_ManAppendCi(Gia_Man_t *p)
void Gia_FileFixName(char *pFileName)
DECLARATIONS ///.
static int Abc_Var2Lit(int Var, int fCompl)
static int Gia_ObjValue(Gia_Obj_t *pObj)
#define ABC_ALLOC(type, num)
int Gia_FileSize(char *pFileName)
FUNCTION DECLARATIONS ///.
static float * Vec_FltArray(Vec_Flt_t *p)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
ABC_NAMESPACE_IMPL_START Gia_Rpr_t * Gia_AigerReadEquivClasses(unsigned char **ppPos, int nSize)
DECLARATIONS ///.
static Vec_Str_t * Vec_StrAlloc(int nCap)
static void Gia_AigerWriteUnsigned(Vec_Str_t *vStr, unsigned x)
int * Gia_AigerReadMapping(unsigned char **ppPos, int nSize)
Vec_Int_t * Gia_AigerReadLiterals(unsigned char **ppPos, int nEntries)
static int Vec_PtrSize(Vec_Ptr_t *p)
static Vec_Int_t * Vec_IntStartFull(int nSize)
static void Vec_FltFreeP(Vec_Flt_t **p)
static int Abc_LitNotCond(int Lit, int c)
Gia_Man_t * Gia_ManDupZeroUndc(Gia_Man_t *p, char *pInit, int fVerbose)
int Gia_ManHasDangling(Gia_Man_t *p)
static int Gia_ManHasChoices(Gia_Man_t *p)
void Tim_ManCreate(Tim_Man_t *p, void *pLib, Vec_Flt_t *vInArrs, Vec_Flt_t *vOutReqs)
int Tim_ManPiNum(Tim_Man_t *p)
static Vec_Flt_t * Vec_FltStart(int nSize)
#define Gia_ManForEachCi(p, pObj, i)
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
static int Gia_ManAndNum(Gia_Man_t *p)
static int Gia_ObjSibl(Gia_Man_t *p, int Id)
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
static Vec_Int_t * Vec_IntStart(int nSize)
Vec_Str_t * Gia_AigerWriteMappingSimple(Gia_Man_t *p)
Vec_Int_t * Gia_AigerCollectLiterals(Gia_Man_t *p)
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
static int Gia_AigerReadInt(unsigned char *pPos)
static int Gia_ObjFaninLit1(Gia_Obj_t *pObj, int ObjId)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
void Gia_DumpAiger(Gia_Man_t *p, char *pFilePrefix, int iFileNum, int nFileNumDigits)
static void Vec_StrFree(Vec_Str_t *p)
Gia_Man_t * Gia_ManDupNormalize(Gia_Man_t *p)
static int Gia_ManAppendBuf(Gia_Man_t *p, int iLit)
static int Vec_IntEntry(Vec_Int_t *p, int i)
#define ABC_NAMESPACE_IMPL_END
Vec_Str_t * Gia_AigerWriteMapping(Gia_Man_t *p)
unsigned char * pSwitching
ABC_DLL void * Abc_FrameReadLibBox()
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
#define Gia_ManForEachAnd(p, pObj, i)
static Vec_Str_t * Vec_StrStart(int nSize)
Vec_Str_t * Gia_WriteEquivClasses(Gia_Man_t *p)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
void Gia_ManTransferTiming(Gia_Man_t *p, Gia_Man_t *pGia)
static int Gia_ManCandNum(Gia_Man_t *p)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
static void Vec_IntFreeP(Vec_Int_t **p)
#define Gia_ManForEachPi(p, pObj, i)
static void Abc_Print(int level, const char *format,...)
int * Gia_ManDeriveNexts(Gia_Man_t *p)
Vec_Int_t * Gia_AigerReadMappingDoc(unsigned char **ppPos, int nObjs)
Gia_Man_t * Gia_AigerRead(char *pFileName, int fSkipStrash, int fCheck)
float * Tim_ManGetReqTimes(Tim_Man_t *p)
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
#define ABC_NAMESPACE_IMPL_START
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
static int Vec_StrSize(Vec_Str_t *p)
static int Gia_ManCiNum(Gia_Man_t *p)
static int Vec_IntSize(Vec_Int_t *p)
char * Gia_FileNameGeneric(char *FileName)
static int Vec_IntSum(Vec_Int_t *p)
static int Gia_ManHasMapping(Gia_Man_t *p)
void Gia_FileWriteBufferSize(FILE *pFile, int nSize)
int Gia_ManIsNormalized(Gia_Man_t *p)
static int Gia_ManBufNum(Gia_Man_t *p)
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
void Gia_AigerWrite(Gia_Man_t *pInit, char *pFileName, int fWriteSymbols, int fCompact)
#define ABC_CALLOC(type, num)
void Gia_ManTransferPacking(Gia_Man_t *p, Gia_Man_t *pGia)
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
#define Gia_ManForEachRo(p, pObj, i)
void Gia_ManTransferMapping(Gia_Man_t *p, Gia_Man_t *pGia)
int * Gia_AigerReadMappingSimple(unsigned char **ppPos, int nSize)
Vec_Str_t * Gia_AigerWriteIntoMemoryStr(Gia_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
static unsigned Gia_AigerReadUnsigned(unsigned char **ppPos)
static void Vec_StrPrintStr(Vec_Str_t *p, const char *pStr)
#define Gia_ManForEachRi(p, pObj, i)
void Gia_ManHashAlloc(Gia_Man_t *p)
static int Gia_AigerWriteUnsignedBuffer(unsigned char *pBuffer, int Pos, unsigned x)
Vec_Str_t * Gia_WritePacking(Vec_Int_t *vPacking)
Gia_Man_t * Gia_AigerReadFromMemory(char *pContents, int nFileSize, int fSkipStrash, int fCheck)
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
float * Tim_ManGetArrTimes(Tim_Man_t *p)
Tim_Man_t * Tim_ManLoad(Vec_Str_t *p, int fHieOnly)
static void Vec_IntFree(Vec_Int_t *p)
static int Gia_ManPiNum(Gia_Man_t *p)
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
char * Abc_UtilStrsav(char *s)
#define Gia_ManForEachPo(p, pObj, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Gia_Man_t * Gia_ManDupWithConstraints(Gia_Man_t *p, Vec_Int_t *vPoTypes)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
int Tim_ManPoNum(Tim_Man_t *p)
Vec_Int_t * Gia_AigerReadPacking(unsigned char **ppPos, int nSize)
Vec_Str_t * Gia_AigerWriteLiterals(Vec_Int_t *vLits)
static int Gia_ManObjNum(Gia_Man_t *p)
int nTotal
DECLARATIONS ///.
Vec_Str_t * Gia_AigerWriteIntoMemoryStrPart(Gia_Man_t *p, Vec_Int_t *vCis, Vec_Int_t *vAnds, Vec_Int_t *vCos, int nRegs)
void Gia_ManHashStop(Gia_Man_t *p)
static int Gia_ManCoNum(Gia_Man_t *p)
static int Gia_ManRegNum(Gia_Man_t *p)