1 /**CFile****************************************************************
2 
3   FileName    [abcNames.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Network and node package.]
8 
9   Synopsis    [Procedures working with net and node names.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: abcNames.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "abc.h"
22 #include "misc/util/utilNam.h"
23 
24 ABC_NAMESPACE_IMPL_START
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 ///                        DECLARATIONS                              ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////////
32 ///                     FUNCTION DEFINITIONS                         ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37   Synopsis    [Returns the unique name for the object.]
38 
39   Description [If the name previously did not exist, creates a new unique
40   name but does not assign this name to the object. The temporary unique
41   name is stored in a static buffer inside this procedure. It is important
42   that the name is used before the function is called again!]
43 
44   SideEffects []
45 
46   SeeAlso     []
47 
48 ***********************************************************************/
Abc_ObjName(Abc_Obj_t * pObj)49 char * Abc_ObjName( Abc_Obj_t * pObj )
50 {
51     return Nm_ManCreateUniqueName( pObj->pNtk->pManName, pObj->Id );
52 }
53 
54 /**Function*************************************************************
55 
56   Synopsis    [Assigns the given name to the object.]
57 
58   Description [The object should not have a name assigned. The same
59   name may be used for several objects, which they share the same net
60   in the original netlist. (For example, latch output and primary output
61   may have the same name.) This procedure returns the pointer to the
62   internally stored representation of the given name.]
63 
64   SideEffects []
65 
66   SeeAlso     []
67 
68 ***********************************************************************/
Abc_ObjAssignName(Abc_Obj_t * pObj,char * pName,char * pSuffix)69 char * Abc_ObjAssignName( Abc_Obj_t * pObj, char * pName, char * pSuffix )
70 {
71     assert( pName != NULL );
72     return Nm_ManStoreIdName( pObj->pNtk->pManName, pObj->Id, pObj->Type, pName, pSuffix );
73 }
74 
75 /**Function*************************************************************
76 
77   Synopsis    [Appends name to the prefix]
78 
79   Description []
80 
81   SideEffects []
82 
83   SeeAlso     []
84 
85 ***********************************************************************/
Abc_ObjNamePrefix(Abc_Obj_t * pObj,char * pPrefix)86 char * Abc_ObjNamePrefix( Abc_Obj_t * pObj, char * pPrefix )
87 {
88     static char Buffer[2000];
89     sprintf( Buffer, "%s%s", pPrefix, Abc_ObjName(pObj) );
90     return Buffer;
91 }
92 
93 /**Function*************************************************************
94 
95   Synopsis    [Appends suffic to the name.]
96 
97   Description []
98 
99   SideEffects []
100 
101   SeeAlso     []
102 
103 ***********************************************************************/
Abc_ObjNameSuffix(Abc_Obj_t * pObj,char * pSuffix)104 char * Abc_ObjNameSuffix( Abc_Obj_t * pObj, char * pSuffix )
105 {
106     static char Buffer[2000];
107     sprintf( Buffer, "%s%s", Abc_ObjName(pObj), pSuffix );
108     return Buffer;
109 }
110 
111 /**Function*************************************************************
112 
113   Synopsis    [Returns the dummy PI name.]
114 
115   Description []
116 
117   SideEffects []
118 
119   SeeAlso     []
120 
121 ***********************************************************************/
Abc_ObjNameDummy(char * pPrefix,int Num,int nDigits)122 char * Abc_ObjNameDummy( char * pPrefix, int Num, int nDigits )
123 {
124     static char Buffer[2000];
125     sprintf( Buffer, "%s%0*d", pPrefix, nDigits, Num );
126     return Buffer;
127 }
128 
129 /**Function*************************************************************
130 
131   Synopsis    [Tranfers names to the old network.]
132 
133   Description [Assumes that the new nodes are attached using pObj->pCopy.]
134 
135   SideEffects []
136 
137   SeeAlso     []
138 
139 ***********************************************************************/
Abc_NtkTrasferNames(Abc_Ntk_t * pNtk,Abc_Ntk_t * pNtkNew)140 void Abc_NtkTrasferNames( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
141 {
142     Abc_Obj_t * pObj;
143     int i;
144     assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkNew) );
145     assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkNew) );
146     assert( Abc_NtkBoxNum(pNtk) == Abc_NtkBoxNum(pNtkNew) );
147     assert( Nm_ManNumEntries(pNtk->pManName) > 0 );
148     assert( Nm_ManNumEntries(pNtkNew->pManName) == 0 );
149     // copy the CI/CO/box names
150     Abc_NtkForEachCi( pNtk, pObj, i )
151         Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanout0Ntk(pObj)), NULL );
152     Abc_NtkForEachCo( pNtk, pObj, i )
153         Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanin0Ntk(pObj)), NULL );
154     Abc_NtkForEachBox( pNtk, pObj, i )
155         Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
156 }
157 
158 /**Function*************************************************************
159 
160   Synopsis    [Tranfers names to the old network.]
161 
162   Description [Assumes that the new nodes are attached using pObj->pCopy.]
163 
164   SideEffects []
165 
166   SeeAlso     []
167 
168 ***********************************************************************/
Abc_NtkTrasferNamesNoLatches(Abc_Ntk_t * pNtk,Abc_Ntk_t * pNtkNew)169 void Abc_NtkTrasferNamesNoLatches( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
170 {
171     Abc_Obj_t * pObj;
172     int i;
173     assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkNew) );
174     assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkNew) );
175     assert( Nm_ManNumEntries(pNtk->pManName) > 0 );
176     assert( Nm_ManNumEntries(pNtkNew->pManName) == 0 );
177     // copy the CI/CO/box name and skip latches and theirs inputs/outputs
178     Abc_NtkForEachCi( pNtk, pObj, i )
179         if ( Abc_ObjFaninNum(pObj) == 0 || !Abc_ObjIsLatch(Abc_ObjFanin0(pObj)) )
180             Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanout0Ntk(pObj)), NULL );
181     Abc_NtkForEachCo( pNtk, pObj, i )
182         if ( Abc_ObjFanoutNum(pObj) == 0 || !Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
183             Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanin0Ntk(pObj)), NULL );
184     Abc_NtkForEachBox( pNtk, pObj, i )
185         if ( !Abc_ObjIsLatch(pObj) )
186             Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
187 }
188 
189 /**Function*************************************************************
190 
191   Synopsis    [Gets fanin node names.]
192 
193   Description []
194 
195   SideEffects []
196 
197   SeeAlso     []
198 
199 ***********************************************************************/
Abc_NodeGetFaninNames(Abc_Obj_t * pNode)200 Vec_Ptr_t * Abc_NodeGetFaninNames( Abc_Obj_t * pNode )
201 {
202     Vec_Ptr_t * vNodes;
203     Abc_Obj_t * pFanin;
204     int i;
205     vNodes = Vec_PtrAlloc( 100 );
206     Abc_ObjForEachFanin( pNode, pFanin, i )
207         Vec_PtrPush( vNodes, Abc_UtilStrsav(Abc_ObjName(pFanin)) );
208     return vNodes;
209 }
210 
211 /**Function*************************************************************
212 
213   Synopsis    [Gets fanin node names.]
214 
215   Description []
216 
217   SideEffects []
218 
219   SeeAlso     []
220 
221 ***********************************************************************/
Abc_NodeGetFakeNames(int nNames)222 Vec_Ptr_t * Abc_NodeGetFakeNames( int nNames )
223 {
224     Vec_Ptr_t * vNames;
225     char Buffer[5];
226     int i;
227 
228     vNames = Vec_PtrAlloc( nNames );
229     for ( i = 0; i < nNames; i++ )
230     {
231         if ( nNames < 26 )
232         {
233             Buffer[0] = 'a' + i;
234             Buffer[1] = 0;
235         }
236         else
237         {
238             Buffer[0] = 'a' + i%26;
239             Buffer[1] = '0' + i/26;
240             Buffer[2] = 0;
241         }
242         Vec_PtrPush( vNames, Extra_UtilStrsav(Buffer) );
243     }
244     return vNames;
245 }
246 
247 /**Function*************************************************************
248 
249   Synopsis    [Gets fanin node names.]
250 
251   Description []
252 
253   SideEffects []
254 
255   SeeAlso     []
256 
257 ***********************************************************************/
Abc_NodeFreeNames(Vec_Ptr_t * vNames)258 void Abc_NodeFreeNames( Vec_Ptr_t * vNames )
259 {
260     int i;
261     if ( vNames == NULL )
262         return;
263     for ( i = 0; i < vNames->nSize; i++ )
264         ABC_FREE( vNames->pArray[i] );
265     Vec_PtrFree( vNames );
266 }
267 
268 /**Function*************************************************************
269 
270   Synopsis    [Collects the CI or CO names.]
271 
272   Description []
273 
274   SideEffects []
275 
276   SeeAlso     []
277 
278 ***********************************************************************/
Abc_NtkCollectCioNames(Abc_Ntk_t * pNtk,int fCollectCos)279 char ** Abc_NtkCollectCioNames( Abc_Ntk_t * pNtk, int fCollectCos )
280 {
281     Abc_Obj_t * pObj;
282     char ** ppNames;
283     int i;
284     if ( fCollectCos )
285     {
286         ppNames = ABC_ALLOC( char *, Abc_NtkCoNum(pNtk) );
287         Abc_NtkForEachCo( pNtk, pObj, i )
288             ppNames[i] = Abc_ObjName(pObj);
289     }
290     else
291     {
292         ppNames = ABC_ALLOC( char *, Abc_NtkCiNum(pNtk) );
293         Abc_NtkForEachCi( pNtk, pObj, i )
294             ppNames[i] = Abc_ObjName(pObj);
295     }
296     return ppNames;
297 }
298 
299 /**Function*************************************************************
300 
301   Synopsis    [Orders PIs/POs/latches alphabetically.]
302 
303   Description []
304 
305   SideEffects []
306 
307   SeeAlso     []
308 
309 ***********************************************************************/
Abc_NodeCompareNames(Abc_Obj_t ** pp1,Abc_Obj_t ** pp2)310 int Abc_NodeCompareNames( Abc_Obj_t ** pp1, Abc_Obj_t ** pp2 )
311 {
312     int Diff = strcmp( (char *)(*pp1)->pCopy, (char *)(*pp2)->pCopy );
313     if ( Diff < 0 )
314         return -1;
315     if ( Diff > 0 )
316         return 1;
317     Diff = (*pp1)->Id - (*pp2)->Id;
318     if ( Diff < 0 )
319         return -1;
320     if ( Diff > 0 )
321         return 1;
322     return 0;
323 }
Abc_NtkOrderObjsByName(Abc_Ntk_t * pNtk,int fComb)324 void Abc_NtkOrderObjsByName( Abc_Ntk_t * pNtk, int fComb )
325 {
326     Abc_Obj_t * pObj;
327     int i;
328     assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
329     // temporarily store the names in the copy field
330     Abc_NtkForEachPi( pNtk, pObj, i )
331         pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(pObj);
332     Abc_NtkForEachPo( pNtk, pObj, i )
333         pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(pObj);
334     Abc_NtkForEachBox( pNtk, pObj, i )
335         pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(Abc_ObjFanout0(pObj));
336     // order objects alphabetically
337     qsort( (void *)Vec_PtrArray(pNtk->vPis), (size_t)Vec_PtrSize(pNtk->vPis), sizeof(Abc_Obj_t *),
338         (int (*)(const void *, const void *)) Abc_NodeCompareNames );
339     qsort( (void *)Vec_PtrArray(pNtk->vPos), (size_t)Vec_PtrSize(pNtk->vPos), sizeof(Abc_Obj_t *),
340         (int (*)(const void *, const void *)) Abc_NodeCompareNames );
341     // if the comparison if combinational (latches as PIs/POs), order them too
342     if ( fComb )
343         qsort( (void *)Vec_PtrArray(pNtk->vBoxes), (size_t)Vec_PtrSize(pNtk->vBoxes), sizeof(Abc_Obj_t *),
344             (int (*)(const void *, const void *)) Abc_NodeCompareNames );
345     // order CIs/COs first PIs/POs(Asserts) then latches
346     Abc_NtkOrderCisCos( pNtk );
347     // clean the copy fields
348     Abc_NtkForEachPi( pNtk, pObj, i )
349         pObj->pCopy = NULL;
350     Abc_NtkForEachPo( pNtk, pObj, i )
351         pObj->pCopy = NULL;
352     Abc_NtkForEachBox( pNtk, pObj, i )
353         pObj->pCopy = NULL;
354 }
355 
356 /**Function*************************************************************
357 
358   Synopsis    [Creates name manager storing input/output names.]
359 
360   Description []
361 
362   SideEffects []
363 
364   SeeAlso     []
365 
366 ***********************************************************************/
Abc_NtkNameMan(Abc_Ntk_t * p,int fOuts)367 Abc_Nam_t * Abc_NtkNameMan( Abc_Ntk_t * p, int fOuts )
368 {
369     if ( fOuts )
370     {
371         Abc_Obj_t * pObj;  int i;
372         Abc_Nam_t * pStrsCo = Abc_NamStart( Abc_NtkCoNum(p), 24 );
373         Abc_NtkForEachCo( p, pObj, i )
374             Abc_NamStrFindOrAdd( pStrsCo, Abc_ObjName(pObj), NULL );
375         assert( Abc_NamObjNumMax(pStrsCo) == i + 1 );
376         return pStrsCo;
377     }
378     else
379     {
380         Abc_Obj_t * pObj;  int i;
381         Abc_Nam_t * pStrsCi = Abc_NamStart( Abc_NtkCiNum(p), 24 );
382         Abc_NtkForEachCi( p, pObj, i )
383             Abc_NamStrFindOrAdd( pStrsCi, Abc_ObjName(pObj), NULL );
384         assert( Abc_NamObjNumMax(pStrsCi) == i + 1 );
385         return pStrsCi;
386    }
387 }
388 
389 /**Function*************************************************************
390 
391   Synopsis    [Orders PIs/POs/latches alphabetically.]
392 
393   Description []
394 
395   SideEffects []
396 
397   SeeAlso     []
398 
399 ***********************************************************************/
Abc_NodeCompareIndexes(Abc_Obj_t ** pp1,Abc_Obj_t ** pp2)400 int Abc_NodeCompareIndexes( Abc_Obj_t ** pp1, Abc_Obj_t ** pp2 )
401 {
402     int Diff = (*pp1)->iTemp - (*pp2)->iTemp;
403     if ( Diff < 0 )
404         return -1;
405     if ( Diff > 0 )
406         return 1;
407     return 0;
408 }
Abc_NtkTransferOrder(Abc_Ntk_t * pNtkOld,Abc_Ntk_t * pNtkNew)409 void Abc_NtkTransferOrder( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew )
410 {
411     Abc_Obj_t * pObj;  int i;
412     Abc_Nam_t * pStrsCi = Abc_NtkNameMan( pNtkOld, 0 );
413     Abc_Nam_t * pStrsCo = Abc_NtkNameMan( pNtkOld, 1 );
414     assert( Abc_NtkPiNum(pNtkOld) == Abc_NtkPiNum(pNtkNew) );
415     assert( Abc_NtkPoNum(pNtkOld) == Abc_NtkPoNum(pNtkNew) );
416     assert( Abc_NtkLatchNum(pNtkOld) == Abc_NtkLatchNum(pNtkNew) );
417     // transfer to the new network
418     Abc_NtkForEachCi( pNtkNew, pObj, i )
419     {
420         pObj->iTemp = Abc_NamStrFind(pStrsCi, Abc_ObjName(pObj));
421         assert( pObj->iTemp > 0 && pObj->iTemp <= Abc_NtkCiNum(pNtkNew) );
422     }
423     Abc_NtkForEachCo( pNtkNew, pObj, i )
424     {
425         pObj->iTemp = Abc_NamStrFind(pStrsCo, Abc_ObjName(pObj));
426         assert( pObj->iTemp > 0 && pObj->iTemp <= Abc_NtkCoNum(pNtkNew) );
427     }
428     Abc_NamDeref( pStrsCi );
429     Abc_NamDeref( pStrsCo );
430     // order PI/PO
431     qsort( (void *)Vec_PtrArray(pNtkNew->vPis), (size_t)Vec_PtrSize(pNtkNew->vPis), sizeof(Abc_Obj_t *),
432         (int (*)(const void *, const void *)) Abc_NodeCompareIndexes );
433     qsort( (void *)Vec_PtrArray(pNtkNew->vPos), (size_t)Vec_PtrSize(pNtkNew->vPos), sizeof(Abc_Obj_t *),
434         (int (*)(const void *, const void *)) Abc_NodeCompareIndexes );
435     // order CI/CO
436     qsort( (void *)Vec_PtrArray(pNtkNew->vCis), (size_t)Vec_PtrSize(pNtkNew->vCis), sizeof(Abc_Obj_t *),
437         (int (*)(const void *, const void *)) Abc_NodeCompareIndexes );
438     qsort( (void *)Vec_PtrArray(pNtkNew->vCos), (size_t)Vec_PtrSize(pNtkNew->vCos), sizeof(Abc_Obj_t *),
439         (int (*)(const void *, const void *)) Abc_NodeCompareIndexes );
440     // order CIs/COs first PIs/POs(Asserts) then latches
441     //Abc_NtkOrderCisCos( pNtk );
442     // clean the copy fields
443     Abc_NtkForEachCi( pNtkNew, pObj, i )
444         pObj->iTemp = 0;
445     Abc_NtkForEachCo( pNtkNew, pObj, i )
446         pObj->iTemp = 0;
447 }
448 
449 /**Function*************************************************************
450 
451   Synopsis    [Checks that the order and number of CI/CO is the same.]
452 
453   Description []
454 
455   SideEffects []
456 
457   SeeAlso     []
458 
459 ***********************************************************************/
Abc_NodeCompareCiCo(Abc_Ntk_t * pNtkOld,Abc_Ntk_t * pNtkNew)460 int Abc_NodeCompareCiCo( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew )
461 {
462     int i;
463     if ( Abc_NtkPiNum(pNtkOld) != Abc_NtkPiNum(pNtkNew) )
464         return 0;
465     if ( Abc_NtkPoNum(pNtkOld) != Abc_NtkPoNum(pNtkNew) )
466         return 0;
467     if ( Abc_NtkLatchNum(pNtkOld) != Abc_NtkLatchNum(pNtkNew) )
468         return 0;
469     for ( i = 0; i < Abc_NtkCiNum(pNtkOld); i++ )
470         if ( strcmp(Abc_ObjName(Abc_NtkCi(pNtkOld, i)), Abc_ObjName(Abc_NtkCi(pNtkNew, i))) )
471             return 0;
472     for ( i = 0; i < Abc_NtkCoNum(pNtkOld); i++ )
473         if ( strcmp(Abc_ObjName(Abc_NtkCo(pNtkOld, i)), Abc_ObjName(Abc_NtkCo(pNtkNew, i))) )
474             return 0;
475     return 1;
476 }
477 
478 /**Function*************************************************************
479 
480   Synopsis    [Adds dummy names.]
481 
482   Description []
483 
484   SideEffects []
485 
486   SeeAlso     []
487 
488 ***********************************************************************/
Abc_NtkAddDummyPiNames(Abc_Ntk_t * pNtk)489 void Abc_NtkAddDummyPiNames( Abc_Ntk_t * pNtk )
490 {
491     Abc_Obj_t * pObj;
492     int nDigits, i;
493     nDigits = Abc_Base10Log( Abc_NtkPiNum(pNtk) );
494     Abc_NtkForEachPi( pNtk, pObj, i )
495         Abc_ObjAssignName( pObj, Abc_ObjNameDummy("pi", i, nDigits), NULL );
496 }
497 
498 /**Function*************************************************************
499 
500   Synopsis    [Adds dummy names.]
501 
502   Description []
503 
504   SideEffects []
505 
506   SeeAlso     []
507 
508 ***********************************************************************/
Abc_NtkAddDummyPoNames(Abc_Ntk_t * pNtk)509 void Abc_NtkAddDummyPoNames( Abc_Ntk_t * pNtk )
510 {
511     Abc_Obj_t * pObj;
512     int nDigits, i;
513     nDigits = Abc_Base10Log( Abc_NtkPoNum(pNtk) );
514     Abc_NtkForEachPo( pNtk, pObj, i )
515         Abc_ObjAssignName( pObj, Abc_ObjNameDummy("po", i, nDigits), NULL );
516 }
517 
518 /**Function*************************************************************
519 
520   Synopsis    [Adds dummy names.]
521 
522   Description []
523 
524   SideEffects []
525 
526   SeeAlso     []
527 
528 ***********************************************************************/
Abc_NtkAddDummyBoxNames(Abc_Ntk_t * pNtk)529 void Abc_NtkAddDummyBoxNames( Abc_Ntk_t * pNtk )
530 {
531     char * pName, PrefLi[100], PrefLo[100];
532     Abc_Obj_t * pObj;
533     int nDigits, i, k, CountCur, CountMax = 0;
534     // if PIs/POs already have nodes with what looks like latch names
535     // we need to add different prefix for the new latches
536     Abc_NtkForEachPi( pNtk, pObj, i )
537     {
538         CountCur = 0;
539         pName = Abc_ObjName(pObj);
540         for ( k = 0; pName[k]; k++ )
541             if ( pName[k] == 'l' )
542                 CountCur++;
543             else
544                 break;
545         CountMax = Abc_MaxInt( CountMax, CountCur );
546     }
547     Abc_NtkForEachPo( pNtk, pObj, i )
548     {
549         CountCur = 0;
550         pName = Abc_ObjName(pObj);
551         for ( k = 0; pName[k]; k++ )
552             if ( pName[k] == 'l' )
553                 CountCur++;
554             else
555                 break;
556         CountMax = Abc_MaxInt( CountMax, CountCur );
557     }
558 //printf( "CountMax = %d\n", CountMax );
559     assert( CountMax < 100-2 );
560     for ( i = 0; i <= CountMax; i++ )
561         PrefLi[i] = PrefLo[i] = 'l';
562     PrefLi[i] = 'i';
563     PrefLo[i] = 'o';
564     PrefLi[i+1] = 0;
565     PrefLo[i+1] = 0;
566     // create latch names
567     assert( !Abc_NtkIsNetlist(pNtk) );
568     nDigits = Abc_Base10Log( Abc_NtkLatchNum(pNtk) );
569     Abc_NtkForEachLatch( pNtk, pObj, i )
570     {
571         Abc_ObjAssignName( pObj, Abc_ObjNameDummy("l", i, nDigits), NULL );
572         Abc_ObjAssignName( Abc_ObjFanin0(pObj),  Abc_ObjNameDummy(PrefLi, i, nDigits), NULL );
573         Abc_ObjAssignName( Abc_ObjFanout0(pObj), Abc_ObjNameDummy(PrefLo, i, nDigits), NULL );
574     }
575 /*
576     nDigits = Abc_Base10Log( Abc_NtkBlackboxNum(pNtk) );
577     Abc_NtkForEachBlackbox( pNtk, pObj, i )
578     {
579         pName = Abc_ObjAssignName( pObj, Abc_ObjNameDummy("B", i, nDigits), NULL );
580         nDigitsF = Abc_Base10Log( Abc_ObjFaninNum(pObj) );
581         Abc_ObjForEachFanin( pObj, pTerm, k )
582             Abc_ObjAssignName( Abc_ObjFanin0(pObj), pName, Abc_ObjNameDummy("i", k, nDigitsF) );
583         nDigitsF = Abc_Base10Log( Abc_ObjFanoutNum(pObj) );
584         Abc_ObjForEachFanout( pObj, pTerm, k )
585             Abc_ObjAssignName( Abc_ObjFanin0(pObj), pName, Abc_ObjNameDummy("o", k, nDigitsF) );
586     }
587 */
588 }
589 
590 /**Function*************************************************************
591 
592   Synopsis    [Replaces names by short names.]
593 
594   Description []
595 
596   SideEffects []
597 
598   SeeAlso     []
599 
600 ***********************************************************************/
Abc_NtkShortNames(Abc_Ntk_t * pNtk)601 void Abc_NtkShortNames( Abc_Ntk_t * pNtk )
602 {
603     Nm_ManFree( pNtk->pManName );
604     pNtk->pManName = Nm_ManCreate( Abc_NtkCiNum(pNtk) + Abc_NtkCoNum(pNtk) + Abc_NtkBoxNum(pNtk) );
605     Abc_NtkAddDummyPiNames( pNtk );
606     Abc_NtkAddDummyPoNames( pNtk );
607     Abc_NtkAddDummyBoxNames( pNtk );
608 }
609 
610 /**Function*************************************************************
611 
612   Synopsis    [Moves names from the other network.]
613 
614   Description []
615 
616   SideEffects []
617 
618   SeeAlso     []
619 
620 ***********************************************************************/
Abc_NtkRedirectCiCo(Abc_Ntk_t * pNtk)621 void Abc_NtkRedirectCiCo( Abc_Ntk_t * pNtk )
622 {
623     Abc_Obj_t * pObj, * pObjCi, * pFanin;
624     int i, Count = 0;
625     // if CO points to CI with the same name, remove buffer between them
626     Abc_NtkForEachCo( pNtk, pObj, i )
627     {
628         int nCiId = Nm_ManFindIdByNameTwoTypes( pNtk->pManName, Abc_ObjName(pObj), ABC_OBJ_PI, ABC_OBJ_BO );
629         if ( nCiId == -1 )
630             continue;
631         pObjCi = Abc_NtkObj( pNtk, nCiId );
632         assert( !strcmp( Abc_ObjName(pObj), Abc_ObjName(pObjCi) ) );
633         pFanin = Abc_ObjFanin0(pObj);
634         if ( pFanin == pObjCi )
635             continue;
636         assert( Abc_NodeIsBuf(pFanin) );
637         Abc_ObjPatchFanin( pObj, pFanin, pObjCi );
638         if ( Abc_ObjFanoutNum(pFanin) == 0 )
639             Abc_NtkDeleteObj( pFanin );
640         Count++;
641     }
642     if ( Count )
643         printf( "Redirected %d POs from buffers to PIs with the same name.\n", Count );
644 }
Abc_NtkMoveNames(Abc_Ntk_t * pNtk,Abc_Ntk_t * pOld)645 void Abc_NtkMoveNames( Abc_Ntk_t * pNtk, Abc_Ntk_t * pOld )
646 {
647     Abc_Obj_t * pObj; int i;
648     Nm_ManFree( pNtk->pManName );
649     pNtk->pManName = Nm_ManCreate( Abc_NtkCiNum(pNtk) + Abc_NtkCoNum(pNtk) + Abc_NtkBoxNum(pNtk) );
650     Abc_NtkForEachPi( pNtk, pObj, i )
651         Abc_ObjAssignName( pObj, Abc_ObjName(Abc_NtkPi(pOld, i)), NULL );
652     Abc_NtkForEachPo( pNtk, pObj, i )
653         Abc_ObjAssignName( pObj, Abc_ObjName(Abc_NtkPo(pOld, i)), NULL );
654     Abc_NtkForEachLatch( pNtk, pObj, i )
655     {
656         Abc_ObjAssignName( Abc_ObjFanin0(pObj),  Abc_ObjName(Abc_ObjFanin0(Abc_NtkBox(pOld, i))),  NULL );
657         Abc_ObjAssignName( Abc_ObjFanout0(pObj), Abc_ObjName(Abc_ObjFanout0(Abc_NtkBox(pOld, i))), NULL );
658     }
659     Abc_NtkRedirectCiCo( pNtk );
660 }
661 
662 
663 /**Function*************************************************************
664 
665   Synopsis    [Saves name IDs into a file.]
666 
667   Description []
668 
669   SideEffects []
670 
671   SeeAlso     []
672 
673 ***********************************************************************/
Abc_NtkStartNameIds(Abc_Ntk_t * p)674 void Abc_NtkStartNameIds( Abc_Ntk_t * p )
675 {
676     char pFileName[1000];
677     FILE * pFile;
678     Abc_Obj_t * pObj, * pFanin;
679     Vec_Ptr_t * vNodes;
680     int i, Counter = 1;
681     assert( Abc_NtkIsNetlist(p) );
682     assert( p->vNameIds == NULL );
683     assert( strlen(p->pSpec) < 1000 );
684     sprintf( pFileName, "%s_%s_names.txt", Extra_FileNameGenericAppend(p->pSpec,""), Extra_FileNameExtension(p->pSpec) );
685     pFile = fopen( pFileName, "wb" );
686     p->vNameIds = Vec_IntStart( Abc_NtkObjNumMax(p) );
687     // add inputs
688     Abc_NtkForEachCi( p, pObj, i )
689         fprintf( pFile, "%s            \n", Abc_ObjName(Abc_ObjFanout0(pObj)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pObj), 2*Counter++);
690     // add outputs
691     Abc_NtkForEachCo( p, pObj, i )
692     {
693         pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pObj));
694         if ( !Vec_IntEntry(p->vNameIds, Abc_ObjId(pFanin)) )
695             fprintf( pFile, "%s            \n", Abc_ObjName(Abc_ObjFanout0(pFanin)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pFanin), 2*Counter++);
696     }
697     // add nodes in a topo order
698     vNodes = Abc_NtkDfs( p, 1 );
699     Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
700         if ( !Vec_IntEntry(p->vNameIds, Abc_ObjId(pObj)) )
701             fprintf( pFile, "%s            \n", Abc_ObjName(Abc_ObjFanout0(pObj)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pObj), 2*Counter++);
702     Vec_PtrFree( vNodes );
703     fclose( pFile );
704     // transfer driver node names to COs
705     Abc_NtkForEachCo( p, pObj, i )
706     {
707         pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pObj));
708         Vec_IntWriteEntry( p->vNameIds, Abc_ObjId(pObj), Vec_IntEntry(p->vNameIds, Abc_ObjId(pFanin)) );
709         Vec_IntWriteEntry( p->vNameIds, Abc_ObjId(pFanin), 0 );
710     }
711 }
712 
713 /**Function*************************************************************
714 
715   Synopsis    [Remaps the AIG from the old manager into the new manager.]
716 
717   Description []
718 
719   SideEffects []
720 
721   SeeAlso     []
722 
723 ***********************************************************************/
Abc_NtkTransferNameIds(Abc_Ntk_t * p,Abc_Ntk_t * pNew)724 void Abc_NtkTransferNameIds( Abc_Ntk_t * p, Abc_Ntk_t * pNew )
725 {
726     Abc_Obj_t * pObj, * pObjNew;
727     int i;
728     assert( p->vNameIds != NULL );
729     assert( pNew->vNameIds == NULL );
730     pNew->vNameIds = Vec_IntStart( Abc_NtkObjNumMax(pNew) );
731 //    Abc_NtkForEachCi( p, pObj, i )
732 //        printf( "%d ", Vec_IntEntry(p->vNameIds, Abc_ObjId(pObj)) );
733 //    printf( "\n" );
734     Abc_NtkForEachObj( p, pObj, i )
735         if ( pObj->pCopy && i < Vec_IntSize(p->vNameIds) && Vec_IntEntry(p->vNameIds, i) )
736         {
737             pObjNew = Abc_ObjRegular(pObj->pCopy);
738             assert( Abc_ObjNtk(pObjNew) == pNew );
739             if ( Abc_ObjIsCi(pObjNew) && !Abc_ObjIsCi(pObj) ) // do not overwrite CI name by internal node name
740                 continue;
741             Vec_IntWriteEntry( pNew->vNameIds, Abc_ObjId(pObjNew), Vec_IntEntry(p->vNameIds, i) ^ Abc_ObjIsComplement(pObj->pCopy) );
742         }
743 }
744 
745 /**Function*************************************************************
746 
747   Synopsis    [Updates file with name IDs.]
748 
749   Description []
750 
751   SideEffects []
752 
753   SeeAlso     []
754 
755 ***********************************************************************/
Abc_NtkUpdateNameIds(Abc_Ntk_t * p)756 void Abc_NtkUpdateNameIds( Abc_Ntk_t * p )
757 {
758     char pFileName[1000];
759     Vec_Int_t * vStarts;
760     Abc_Obj_t * pObj;
761     FILE * pFile;
762     int i, c, iVar, fCompl, fSeenSpace, Counter = 0;
763     assert( !Abc_NtkIsNetlist(p) );
764     assert( strlen(p->pSpec) < 1000 );
765     assert( p->vNameIds != NULL );
766     sprintf( pFileName, "%s_%s_names.txt", Extra_FileNameGenericAppend(p->pSpec,""), Extra_FileNameExtension(p->pSpec) );
767     pFile = fopen( pFileName, "r+" );
768     // collect info about lines
769     fSeenSpace = 0;
770     vStarts = Vec_IntAlloc( 1000 );
771     Vec_IntPush( vStarts, -1 );
772     while ( (c = fgetc(pFile)) != EOF && ++Counter )
773         if ( c == ' ' && !fSeenSpace )
774             Vec_IntPush(vStarts, Counter), fSeenSpace = 1;
775         else if ( c == '\n' )
776             fSeenSpace = 0;
777     // add info about names
778     Abc_NtkForEachObj( p, pObj, i )
779     {
780         if ( i == 0 || i >= Vec_IntSize(p->vNameIds) || !Vec_IntEntry(p->vNameIds, i) )
781             continue;
782         iVar = Abc_Lit2Var( Vec_IntEntry(p->vNameIds, i) );
783         fCompl = Abc_LitIsCompl( Vec_IntEntry(p->vNameIds, i) );
784         assert( iVar < Vec_IntSize(vStarts) );
785         fseek( pFile, Vec_IntEntry(vStarts, iVar), SEEK_SET );
786         fprintf( pFile, "%s%d", fCompl? "-":"", i );
787     }
788     printf( "Saved %d names into file \"%s\".\n", Vec_IntSize(vStarts)-1, pFileName );
789     fclose( pFile );
790     Vec_IntFree( vStarts );
791     Vec_IntFreeP( &p->vNameIds );
792 //    Abc_NtkForEachObj( p, pObj, i )
793 //        Abc_ObjPrint( stdout, pObj );
794 }
795 
796 ////////////////////////////////////////////////////////////////////////
797 ///                       END OF FILE                                ///
798 ////////////////////////////////////////////////////////////////////////
799 
800 
801 ABC_NAMESPACE_IMPL_END
802 
803