ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlnNtk.c
Go to the documentation of this file.
1
20
21#include "wln.h"
22
24
25
29
33
45Wln_Ntk_t * Wln_NtkAlloc( char * pName, int nObjsMax )
46{
47 Wln_Ntk_t * p; int i;
48 p = ABC_CALLOC( Wln_Ntk_t, 1 );
49 p->pName = pName ? Extra_FileNameGeneric( pName ) : NULL;
50 Vec_IntGrow( &p->vCis, 111 );
51 Vec_IntGrow( &p->vCos, 111 );
52 Vec_IntGrow( &p->vFfs, 111 );
53 Vec_IntGrow( &p->vTypes, nObjsMax+1 );
54 Vec_StrGrow( &p->vSigns, nObjsMax+1 );
55 Vec_IntGrow( &p->vRanges, nObjsMax+1 );
56 Vec_IntPush( &p->vTypes, -1 );
57 Vec_StrPush( &p->vSigns, -1 );
58 Vec_IntPush( &p->vRanges, -1 );
59 p->vFanins = ABC_CALLOC( Wln_Vec_t, nObjsMax+1 );
60 p->pRanges = Hash_IntManStart( 1000 );
61 for ( i = 0; i < 65; i++ )
62 Hash_Int2ManInsert( p->pRanges, i, i, 0 );
63 for ( i = 1; i < 64; i++ )
64 Hash_Int2ManInsert( p->pRanges, i, 0, 0 );
65 assert( Hash_IntManEntryNum(p->pRanges) == 128 );
66 return p;
67}
69{
70 int i;
71 for ( i = 0; i < Wln_NtkObjNum(p); i++ )
72 if ( Wln_ObjFaninNum(p, i) > 2 )
73 ABC_FREE( p->vFanins[i].pArray[0] );
74 ABC_FREE( p->vFanins );
75
76 if ( p->pRanges ) Hash_IntManStop( p->pRanges );
77 if ( p->pManName ) Abc_NamStop( p->pManName );
78
79 ABC_FREE( p->vCis.pArray );
80 ABC_FREE( p->vCos.pArray );
81 ABC_FREE( p->vFfs.pArray );
82
83 ABC_FREE( p->vTypes.pArray );
84 ABC_FREE( p->vSigns.pArray );
85 ABC_FREE( p->vRanges.pArray );
86 ABC_FREE( p->vNameIds.pArray );
87 ABC_FREE( p->vInstIds.pArray );
88 ABC_FREE( p->vTravIds.pArray );
89 ABC_FREE( p->vCopies.pArray );
90 ABC_FREE( p->vBits.pArray );
91 ABC_FREE( p->vLevels.pArray );
92 ABC_FREE( p->vRefs.pArray );
93 ABC_FREE( p->vFanout.pArray );
94 ABC_FREE( p->vFaninAttrs.pArray );
95 ABC_FREE( p->vFaninLists.pArray );
96
97 ABC_FREE( p->pName );
98 ABC_FREE( p->pSpec );
99 ABC_FREE( p );
100}
102{
103 int Mem = sizeof(Wln_Ntk_t);
104 Mem += 4 * p->vCis.nCap;
105 Mem += 4 * p->vCos.nCap;
106 Mem += 4 * p->vFfs.nCap;
107 Mem += 1 * p->vTypes.nCap;
108 Mem += 4 * p->vRanges.nCap;
109 Mem += 4 * p->vNameIds.nCap;
110 Mem += 4 * p->vInstIds.nCap;
111 Mem += 4 * p->vTravIds.nCap;
112 Mem += 4 * p->vCopies.nCap;
113 Mem += 4 * p->vBits.nCap;
114 Mem += 4 * p->vLevels.nCap;
115 Mem += 4 * p->vRefs.nCap;
116 Mem += 4 * p->vFanout.nCap;
117 Mem += 4 * p->vFaninAttrs.nCap;
118 Mem += 4 * p->vFaninLists.nCap;
119 Mem += 20 * Hash_IntManEntryNum(p->pRanges);
120 Mem += Abc_NamMemUsed(p->pManName);
121 return Mem;
122}
124{
125 int iObj;
126 printf( "Printing %d objects of network \"%s\":\n", Wln_NtkObjNum(p), p->pName );
127 Wln_NtkForEachObj( p, iObj )
128 Wln_ObjPrint( p, iObj );
129 printf( "\n" );
130}
131
132
133
153{
154 int i, iFanin;
155 //printf( "Visiting node %d\n", iObj );
156 // skip the node if it is already visited
157 if ( Wln_ObjIsTravIdPrevious(p, iObj) )
158 return 1;
159 // check if the node is part of the combinational loop
160 if ( Wln_ObjIsTravIdCurrent(p, iObj) )
161 {
162 fprintf( stdout, "Network contains combinational loop!\n" );
163 fprintf( stdout, "Node %16s is encountered twice on the following path:\n", Wln_ObjName(p, iObj) );
164 fprintf( stdout, "Node %16s (ID %6d) of type %5s (type ID %2d) ->\n",
165 Wln_ObjName(p, iObj), iObj, Abc_OperName(Wln_ObjType(p, iObj)), Wln_ObjType(p, iObj) );
166 return 0;
167 }
168 // mark this node as a node on the current path
169 Wln_ObjSetTravIdCurrent( p, iObj );
170 // quit if it is a CI or constant node
171 if ( Wln_ObjIsCi(p, iObj) || Wln_ObjIsFf(p, iObj) || Wln_ObjFaninNum(p, iObj) == 0 )
172 {
173 // mark this node as a visited node
174 Wln_ObjSetTravIdPrevious( p, iObj );
175 return 1;
176 }
177 // traverse the fanin's cone searching for the loop
178 Wln_ObjForEachFanin( p, iObj, iFanin, i )
179 {
180 if ( !Wln_NtkIsAcyclic_rec(p, iFanin) )
181 {
182 // return as soon as the loop is detected
183 fprintf( stdout, "Node %16s (ID %6d) of type %5s (type ID %2d) ->\n",
184 Wln_ObjName(p, iObj), iObj, Abc_OperName(Wln_ObjType(p, iObj)), Wln_ObjType(p, iObj) );
185 return 0;
186 }
187 }
188 // mark this node as a visited node
189 Wln_ObjSetTravIdPrevious( p, iObj );
190 return 1;
191}
193{
194 int fAcyclic, i, iObj, nUnvisited = 0 ;
195 // set the traversal ID for this DFS ordering
196 Wln_NtkIncrementTravId( p );
197 Wln_NtkIncrementTravId( p );
198 // iObj->TravId == pNet->nTravIds means "iObj is on the path"
199 // iObj->TravId == pNet->nTravIds - 1 means "iObj is visited but is not on the path"
200 // iObj->TravId < pNet->nTravIds - 1 means "iObj is not visited"
201 // traverse the network to detect cycles
202 fAcyclic = 1;
203 Wln_NtkForEachCo( p, iObj, i )
204 {
205 // traverse the output logic cone
206 if ( (fAcyclic = Wln_NtkIsAcyclic_rec(p, iObj)) )
207 continue;
208 // stop as soon as the first loop is detected
209 fprintf( stdout, "Primary output %16s (ID %6d)\n", Wln_ObjName(p, iObj), iObj );
210 goto finish;
211 }
212 Wln_NtkForEachFf( p, iObj, i )
213 {
214 // traverse the output logic cone
215 if ( (fAcyclic = Wln_NtkIsAcyclic_rec(p, iObj)) )
216 continue;
217 // stop as soon as the first loop is detected
218 fprintf( stdout, "Flip-flop %16s (ID %6d)\n", Wln_ObjName(p, iObj), iObj );
219 goto finish;
220 }
221 Wln_NtkForEachObj( p, iObj )
222 nUnvisited += !Wln_ObjIsTravIdPrevious(p, iObj) && !Wln_ObjIsCi(p, iObj);
223 if ( nUnvisited )
224 {
225 int nSinks = 0;
227 printf( "The network has %d objects and %d (%6.2f %%) of them are not connected to the outputs.\n",
228 Wln_NtkObjNum(p), nUnvisited, 100.0*nUnvisited/Wln_NtkObjNum(p) );
229 Wln_NtkForEachObj( p, iObj )
230 if ( !Wln_ObjRefs(p, iObj) && !Wln_ObjIsCi(p, iObj) && !Wln_ObjIsCo(p, iObj) && !Wln_ObjIsFf(p, iObj) )
231 nSinks++;
232 if ( nSinks )
233 {
234 int nPrinted = 0;
235 printf( "These unconnected objects feed into %d sink objects without fanout:\n", nSinks );
236 Wln_NtkForEachObj( p, iObj )
237 if ( !Wln_ObjRefs(p, iObj) && !Wln_ObjIsCi(p, iObj) && !Wln_ObjIsCo(p, iObj) && !Wln_ObjIsFf(p, iObj) )
238 {
239 fprintf( stdout, "Node %16s (ID %6d) of type %5s (type ID %2d)\n",
240 Wln_ObjName(p, iObj), iObj, Abc_OperName(Wln_ObjType(p, iObj)), Wln_ObjType(p, iObj) );
241 if ( ++nPrinted == 5 )
242 break;
243 }
244 if ( nPrinted < nSinks )
245 printf( "...\n" );
246 }
247 Wln_NtkForEachObj( p, iObj )
248 if ( !Wln_ObjIsTravIdPrevious(p, iObj) && !Wln_ObjIsCi(p, iObj) )
249 {
250 // traverse the output logic cone
251 if ( (fAcyclic = Wln_NtkIsAcyclic_rec(p, iObj)) )
252 continue;
253 // stop as soon as the first loop is detected
254 fprintf( stdout, "Unconnected object %s\n", Wln_ObjName(p, iObj) );
255 goto finish;
256 }
257 }
258finish:
259 return fAcyclic;
260}
261
274{
275 assert( pNew->pManName == NULL && p->pManName != NULL );
276 pNew->pManName = p->pManName;
277 p->pManName = NULL;
278 assert( !Wln_NtkHasCopy(pNew) && Wln_NtkHasCopy(p) );
279 if ( Wln_NtkHasNameId(p) )
280 {
281 int i;
282 assert( !Wln_NtkHasNameId(pNew) && Wln_NtkHasNameId(p) );
283 Wln_NtkCleanNameId( pNew );
284 Wln_NtkForEachObj( p, i )
285 if ( Wln_ObjCopy(p, i) && i < Vec_IntSize(&p->vNameIds) && Wln_ObjNameId(p, i) )
286 Wln_ObjSetNameId( pNew, Wln_ObjCopy(p, i), Wln_ObjNameId(p, i) );
287 Vec_IntErase( &p->vNameIds );
288 }
289 if ( Wln_NtkHasInstId(p) )
290 {
291 int i;
292 assert( !Wln_NtkHasInstId(pNew) && Wln_NtkHasInstId(p) );
293 Wln_NtkCleanInstId( pNew );
294 Wln_NtkForEachObj( p, i )
295 if ( Wln_ObjCopy(p, i) && i < Vec_IntSize(&p->vInstIds) && Wln_ObjInstId(p, i) )
296 Wln_ObjSetInstId( pNew, Wln_ObjCopy(p, i), Wln_ObjInstId(p, i) );
297 Vec_IntErase( &p->vInstIds );
298 }
299}
300int Wln_ObjDup( Wln_Ntk_t * pNew, Wln_Ntk_t * p, int iObj )
301{
302 int i, iFanin, iObjNew = Wln_ObjClone( pNew, p, iObj );
303 Wln_ObjForEachFanin( p, iObj, iFanin, i )
304 Wln_ObjAddFanin( pNew, iObjNew, Wln_ObjCopy(p, iFanin) );
305 if ( Wln_ObjIsConst(p, iObj) )
306 Wln_ObjSetConst( pNew, iObjNew, Wln_ObjFanin0(p, iObj) );
307 else if ( Wln_ObjIsSlice(p, iObj) || Wln_ObjIsRotate(p, iObj) || Wln_ObjIsTable(p, iObj) )
308 Wln_ObjSetFanin( pNew, iObjNew, 1, Wln_ObjFanin1(p, iObj) );
309 Wln_ObjSetCopy( p, iObj, iObjNew );
310 return iObjNew;
311}
312int Wln_NtkDupDfs_rec( Wln_Ntk_t * pNew, Wln_Ntk_t * p, int iObj )
313{
314 int i, iFanin;
315 if ( iObj == 0 )
316 return 0;
317 if ( Wln_ObjCopy(p, iObj) )
318 return Wln_ObjCopy(p, iObj);
319 //printf( "Visiting node %16s (ID %6d) of type %5s (type ID %2d)\n", Wln_ObjName(p, iObj), iObj, Abc_OperName(Wln_ObjType(p, iObj)), Wln_ObjType(p, iObj) );
320 assert( !Wln_ObjIsFf(p, iObj) );
321 Wln_ObjForEachFanin( p, iObj, iFanin, i )
322 Wln_NtkDupDfs_rec( pNew, p, iFanin );
323 return Wln_ObjDup( pNew, p, iObj );
324}
326{
327 int i, k, iObj, iFanin;
328 Wln_Ntk_t * pNew = Wln_NtkAlloc( p->pName, Wln_NtkObjNum(p) );
329 pNew->fSmtLib = p->fSmtLib;
330 if ( p->pSpec ) pNew->pSpec = Abc_UtilStrsav( p->pSpec );
331 Wln_NtkCleanCopy( p );
332 Wln_NtkForEachCi( p, iObj, i )
333 Wln_ObjDup( pNew, p, iObj );
334 Wln_NtkForEachFf( p, iObj, i )
335 Wln_ObjSetCopy( p, iObj, Wln_ObjClone(pNew, p, iObj) );
336 Wln_NtkForEachCo( p, iObj, i )
337 Wln_NtkDupDfs_rec( pNew, p, iObj );
338 Wln_NtkForEachFf( p, iObj, i )
339 Wln_ObjForEachFanin( p, iObj, iFanin, k )
340 Wln_ObjAddFanin( pNew, Wln_ObjCopy(p, iObj), Wln_NtkDupDfs_rec(pNew, p, iFanin) );
341 if ( Wln_NtkHasNameId(p) )
342 Wln_NtkTransferNames( pNew, p );
343 return pNew;
344}
345
358{
359 int k, iObj, iFanin;
360 Wln_NtkCleanRefs( p );
361 Wln_NtkForEachObj( p, iObj )
362 Wln_ObjForEachFanin( p, iObj, iFanin, k )
363 Wln_ObjRefsInc( p, iFanin );
364}
366{
367 int iObj, nEdges = 0;
368 Wln_NtkForEachObj( p, iObj )
369 nEdges += Wln_ObjFaninNum(p, iObj);
370 return nEdges;
371}
372void Wln_NtkStartFaninMap( Wln_Ntk_t * p, Vec_Int_t * vFaninMap, int nMulti )
373{
374 int iObj, iOffset = Wln_NtkObjNum(p);
375 Vec_IntFill( vFaninMap, iOffset + nMulti * Wln_NtkFaninNum(p), 0 );
376 Wln_NtkForEachObj( p, iObj )
377 {
378 Vec_IntWriteEntry( vFaninMap, iObj, iOffset );
379 iOffset += nMulti * Wln_ObjFaninNum(p, iObj);
380 }
381 assert( iOffset == Vec_IntSize(vFaninMap) );
382}
383void Wln_NtkStartFanoutMap( Wln_Ntk_t * p, Vec_Int_t * vFanoutMap, Vec_Int_t * vFanoutNums, int nMulti )
384{
385 int iObj, iOffset = Wln_NtkObjNum(p);
386 Vec_IntFill( vFanoutMap, iOffset + nMulti * Vec_IntSum(vFanoutNums), 0 );
387 Wln_NtkForEachObj( p, iObj )
388 {
389 Vec_IntWriteEntry( vFanoutMap, iObj, iOffset );
390 iOffset += nMulti * Wln_ObjRefs(p, iObj);
391 }
392 assert( iOffset == Vec_IntSize(vFanoutMap) );
393}
394
407{
408 int k, iObj, iFanin;
409 Vec_Int_t * vRefsCopy = Vec_IntAlloc(0);
411 Wln_NtkStartFanoutMap( p, &p->vFanout, &p->vRefs, 1 );
412 ABC_SWAP( Vec_Int_t, *vRefsCopy, p->vRefs );
413 // add fanouts
414 Wln_NtkCleanRefs( p );
415 Wln_NtkForEachObj( p, iObj )
416 Wln_ObjForEachFanin( p, iObj, iFanin, k )
417 Wln_ObjSetFanout( p, iFanin, Wln_ObjRefsInc(p, iFanin), iObj );
418 // double-check the current number of fanouts added
419 Wln_NtkForEachObj( p, iObj )
420 assert( Wln_ObjRefs(p, iObj) == Vec_IntEntry(vRefsCopy, iObj) );
421 Vec_IntFree( vRefsCopy );
422}
424{
425 Vec_IntErase( &p->vRefs );
426 Vec_IntErase( &p->vFanout );
427}
429{
430 int k, iObj, iFanout;
431 printf( "Printing fanouts of %d objects of network \"%s\":\n", Wln_NtkObjNum(p), p->pName );
433 Wln_NtkForEachObj( p, iObj )
434 {
435 Wln_ObjPrint( p, iObj );
436 printf( " Fanouts : " );
437 Wln_ObjForEachFanoutStatic( p, iObj, iFanout, k )
438 printf( "%5d ", iFanout );
439 printf( "\n" );
440 }
442 printf( "\n" );
443}
444
448
449
451
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
char * Extra_FileNameGeneric(char *FileName)
int fSmtLib
Definition wln.h:60
char * pSpec
Definition wln.h:59
Abc_Nam_t * pManName
Definition wln.h:70
int Abc_NamMemUsed(Abc_Nam_t *p)
Definition utilNam.c:247
void Abc_NamStop(Abc_Nam_t *p)
Definition utilNam.c:112
#define assert(ex)
Definition util_old.h:213
void Wln_NtkStaticFanoutTest(Wln_Ntk_t *p)
Definition wlnNtk.c:428
void Wln_NtkStaticFanoutStop(Wln_Ntk_t *p)
Definition wlnNtk.c:423
int Wln_NtkIsAcyclic(Wln_Ntk_t *p)
Definition wlnNtk.c:192
Wln_Ntk_t * Wln_NtkDupDfs(Wln_Ntk_t *p)
Definition wlnNtk.c:325
void Wln_NtkStartFaninMap(Wln_Ntk_t *p, Vec_Int_t *vFaninMap, int nMulti)
Definition wlnNtk.c:372
void Wln_NtkFree(Wln_Ntk_t *p)
Definition wlnNtk.c:68
void Wln_NtkStartFanoutMap(Wln_Ntk_t *p, Vec_Int_t *vFanoutMap, Vec_Int_t *vFanoutNums, int nMulti)
Definition wlnNtk.c:383
void Wln_NtkTransferNames(Wln_Ntk_t *pNew, Wln_Ntk_t *p)
Definition wlnNtk.c:273
void Wln_NtkCreateRefs(Wln_Ntk_t *p)
Definition wlnNtk.c:357
void Wln_NtkStaticFanoutStart(Wln_Ntk_t *p)
Definition wlnNtk.c:406
int Wln_NtkMemUsage(Wln_Ntk_t *p)
Definition wlnNtk.c:101
ABC_NAMESPACE_IMPL_START Wln_Ntk_t * Wln_NtkAlloc(char *pName, int nObjsMax)
DECLARATIONS ///.
Definition wlnNtk.c:45
int Wln_NtkFaninNum(Wln_Ntk_t *p)
Definition wlnNtk.c:365
int Wln_NtkDupDfs_rec(Wln_Ntk_t *pNew, Wln_Ntk_t *p, int iObj)
Definition wlnNtk.c:312
int Wln_ObjDup(Wln_Ntk_t *pNew, Wln_Ntk_t *p, int iObj)
Definition wlnNtk.c:300
void Wln_NtkPrint(Wln_Ntk_t *p)
Definition wlnNtk.c:123
int Wln_NtkIsAcyclic_rec(Wln_Ntk_t *p, int iObj)
Definition wlnNtk.c:152
#define Wln_NtkForEachFf(p, iFf, i)
Definition wln.h:202
#define Wln_NtkForEachCo(p, iCo, i)
Definition wln.h:200
#define Wln_ObjForEachFanoutStatic(p, iObj, iFanout, i)
Definition wln.h:210
void Wln_ObjPrint(Wln_Ntk_t *p, int iObj)
Definition wlnObj.c:136
typedefABC_NAMESPACE_HEADER_START struct Wln_Vec_t_ Wln_Vec_t
INCLUDES ///.
Definition wln.h:46
#define Wln_ObjForEachFanin(p, iObj, iFanin, i)
Definition wln.h:205
void Wln_ObjAddFanin(Wln_Ntk_t *p, int iObj, int i)
Definition wlnObj.c:75
#define Wln_NtkForEachCi(p, iCi, i)
Definition wln.h:198
char * Wln_ObjName(Wln_Ntk_t *p, int iObj)
DECLARATIONS ///.
Definition wlnObj.c:45
int Wln_ObjClone(Wln_Ntk_t *pNew, Wln_Ntk_t *p, int iObj)
Definition wlnObj.c:125
struct Wln_Ntk_t_ Wln_Ntk_t
Definition wln.h:55
void Wln_ObjSetConst(Wln_Ntk_t *p, int iObj, int NameId)
Definition wlnObj.c:65
#define Wln_NtkForEachObj(p, i)
MACRO DEFINITIONS ///.
Definition wln.h:187