INCLUDES ///.
Description [The buffer constains the AIG in AIGER format. The size gives the number of bytes in the buffer. The buffer is allocated by the user and not deallocated by this procedure.]
106{
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;
115
116
117 if (
strncmp(pContents,
"aig", 3) != 0 || (pContents[3] !=
' ' && pContents[3] !=
'2') )
118 {
119 fprintf( stdout, "Wrong input file format.\n" );
120 return NULL;
121 }
122
123
124 pCur = pContents; while ( *pCur != ' ' ) pCur++; pCur++;
125
126 nTotal = atoi( pCur );
while ( *pCur !=
' ' ) pCur++; pCur++;
127
128 nInputs = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
129
130 nLatches = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
131
132 nOutputs = atoi( pCur ); while ( *pCur != ' ' ) pCur++; pCur++;
133
134 nAnds = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
135 if ( *pCur == ' ' )
136 {
138
139 pCur++;
140 nBad = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
141 nOutputs += nBad;
142 }
143 if ( *pCur == ' ' )
144 {
145
146 pCur++;
147 nConstr = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
148 nOutputs += nConstr;
149 }
150 if ( *pCur == ' ' )
151 {
152
153 pCur++;
154 nJust = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
155 nOutputs += nJust;
156 }
157 if ( *pCur == ' ' )
158 {
159
160 pCur++;
161 nFair = atoi( pCur ); while ( *pCur != ' ' && *pCur != '\n' ) pCur++;
162 nOutputs += nFair;
163 }
164 if ( *pCur != '\n' )
165 {
166 fprintf( stdout, "The parameter line is in a wrong format.\n" );
167 return NULL;
168 }
169 pCur++;
170
171
172 if (
nTotal != nInputs + nLatches + nAnds )
173 {
174 fprintf( stdout, "The number of objects does not match.\n" );
175 return NULL;
176 }
177 if ( nJust || nFair )
178 {
179 fprintf( stdout, "Reading AIGER files with liveness properties are currently not supported.\n" );
180 return NULL;
181 }
182
183 if ( nConstr )
184 {
185 if ( nConstr == 1 )
186 fprintf( stdout, "Warning: The last output is interpreted as a constraint.\n" );
187 else
188 fprintf( stdout, "Warning: The last %d outputs are interpreted as constraints.\n", nConstr );
189 }
190
191
193 pNew->nConstrs = nConstr;
194
195
196 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
197 Vec_PtrPush( vNodes, Aig_ManConst0(pNew) );
198
199
200 for ( i = 0; i < nInputs + nLatches; i++ )
201 {
203 Vec_PtrPush( vNodes, pObj );
204 }
205
206
207
208
209
210
211
212
213 pNew->nRegs = nLatches;
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 pDrivers = pCur;
233 if ( pContents[3] == ' ' )
234 {
235
236 for ( i = 0; i < nLatches + nOutputs; )
237 if ( *pCur++ == '\n' )
238 i++;
239 }
240 else
241 {
243 }
244
245
246
247 for ( i = 0; i < nAnds; i++ )
248 {
249
250 uLit = ((i + 1 + nInputs + nLatches) << 1);
253
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) );
258 }
259
260
261
262 pSymbols = pCur;
263
264
265 vDrivers = Vec_PtrAlloc( nLatches + nOutputs );
266 if ( pContents[3] == ' ' )
267 {
268 pCur = pDrivers;
269 for ( i = 0; i < nLatches; i++ )
270 {
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 );
274 }
275
276 for ( i = 0; i < nOutputs; i++ )
277 {
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 );
281 }
282
283 }
284 else
285 {
286
287 for ( i = 0; i < nLatches; i++ )
288 {
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 );
292 }
293
294 for ( i = 0; i < nOutputs; i++ )
295 {
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 );
299 }
300 Vec_IntFree( vLits );
301 }
302
303
304 for ( i = 0; i < nOutputs; i++ )
306 for ( i = 0; i < nLatches; i++ )
308 Vec_PtrFree( vDrivers );
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386 pCur = pSymbols;
387 if ( pCur + 1 < pContents + nFileSize && *pCur == 'c' )
388 {
389 pCur++;
390 if ( *pCur == 'n' )
391 {
392 pCur++;
393
395 pNew->pName = Abc_UtilStrsav( pCur );
396 }
397 }
398
399
400 Vec_PtrFree( vNodes );
401
402
405
406
407 if ( nBad || nConstr || nJust || nFair )
409
410
412 {
413 printf( "Ioa_ReadAiger: The network check has failed.\n" );
415 return NULL;
416 }
417 return pNew;
418}
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
void Aig_ManInvertConstraints(Aig_Man_t *pAig)
void Aig_ManStop(Aig_Man_t *p)
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
struct Aig_Obj_t_ Aig_Obj_t
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
int Aig_ManCleanup(Aig_Man_t *p)
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
ABC_DLL int Aig_ManCheck(Aig_Man_t *p)
FUNCTION DECLARATIONS ///.
int nTotal
DECLARATIONS ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Vec_Int_t * Ioa_WriteDecodeLiterals(char **ppPos, int nEntries)
ABC_NAMESPACE_IMPL_START unsigned Ioa_ReadAigerDecode(char **ppPos)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.