111 int nTotal, nInputs, nOutputs, nLatches, nAnds, i;
112 int nBad = 0, nConstr = 0, nJust = 0, nFair = 0;
113 char * pDrivers, * pSymbols, * pCur;
114 unsigned uLit0, uLit1, uLit;
117 if (
strncmp(pContents,
"aig", 3) != 0 || (pContents[3] !=
' ' && pContents[3] !=
'2') )
119 fprintf( stdout,
"Wrong input file format.\n" );
124 pCur = pContents;
while ( *pCur !=
' ' ) pCur++; pCur++;
126 nTotal = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
128 nInputs = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
130 nLatches = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
132 nOutputs = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
134 nAnds = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
140 nBad = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
147 nConstr = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
154 nJust = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
161 nFair = atoi( pCur );
while ( *pCur !=
' ' && *pCur !=
'\n' ) pCur++;
166 fprintf( stdout,
"The parameter line is in a wrong format.\n" );
172 if (
nTotal != nInputs + nLatches + nAnds )
174 fprintf( stdout,
"The number of objects does not match.\n" );
177 if ( nJust || nFair )
179 fprintf( stdout,
"Reading AIGER files with liveness properties are currently not supported.\n" );
186 fprintf( stdout,
"Warning: The last output is interpreted as a constraint.\n" );
188 fprintf( stdout,
"Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
193 pNew->nConstrs = nConstr;
196 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
197 Vec_PtrPush( vNodes, Aig_ManConst0(pNew) );
200 for ( i = 0; i < nInputs + nLatches; i++ )
203 Vec_PtrPush( vNodes, pObj );
213 pNew->nRegs = nLatches;
233 if ( pContents[3] ==
' ' )
236 for ( i = 0; i < nLatches + nOutputs; )
237 if ( *pCur++ ==
'\n' )
247 for ( i = 0; i < nAnds; i++ )
250 uLit = ((i + 1 + nInputs + nLatches) << 1);
254 pNode0 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), uLit0 & 1 );
255 pNode1 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit1 >> 1), uLit1 & 1 );
256 assert( Vec_PtrSize(vNodes) == i + 1 + nInputs + nLatches );
257 Vec_PtrPush( vNodes,
Aig_And(pNew, pNode0, pNode1) );
265 vDrivers = Vec_PtrAlloc( nLatches + nOutputs );
266 if ( pContents[3] ==
' ' )
269 for ( i = 0; i < nLatches; i++ )
271 uLit0 = atoi( pCur );
while ( *pCur++ !=
'\n' );
272 pNode0 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
273 Vec_PtrPush( vDrivers, pNode0 );
276 for ( i = 0; i < nOutputs; i++ )
278 uLit0 = atoi( pCur );
while ( *pCur++ !=
'\n' );
279 pNode0 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
280 Vec_PtrPush( vDrivers, pNode0 );
287 for ( i = 0; i < nLatches; i++ )
289 uLit0 = Vec_IntEntry( vLits, i );
290 pNode0 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
291 Vec_PtrPush( vDrivers, pNode0 );
294 for ( i = 0; i < nOutputs; i++ )
296 uLit0 = Vec_IntEntry( vLits, i+nLatches );
297 pNode0 = Aig_NotCond( (
Aig_Obj_t *)Vec_PtrEntry(vNodes, uLit0 >> 1), (uLit0 & 1) );
298 Vec_PtrPush( vDrivers, pNode0 );
300 Vec_IntFree( vLits );
304 for ( i = 0; i < nOutputs; i++ )
306 for ( i = 0; i < nLatches; i++ )
308 Vec_PtrFree( vDrivers );
387 if ( pCur + 1 < pContents + nFileSize && *pCur ==
'c' )
395 pNew->pName = Abc_UtilStrsav( pCur );
400 Vec_PtrFree( vNodes );
407 if ( nBad || nConstr || nJust || nFair )
413 printf(
"Ioa_ReadAiger: The network check has failed.\n" );