abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcLib.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcLib.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Functions to manipulate verilog libraries.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcLib.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "abc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Create the library.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 Abc_Des_t * Abc_DesCreate( char * pName )
46 {
47  Abc_Des_t * p;
48  p = ABC_ALLOC( Abc_Des_t, 1 );
49  memset( p, 0, sizeof(Abc_Des_t) );
50  p->pName = Abc_UtilStrsav( pName );
52  p->vTops = Vec_PtrAlloc( 100 );
53  p->vModules = Vec_PtrAlloc( 100 );
54  p->pManFunc = Hop_ManStart();
55  p->pLibrary = NULL;
56  return p;
57 }
58 
59 /**Function*************************************************************
60 
61  Synopsis [Removes all pointers to the manager.]
62 
63  Description []
64 
65  SideEffects []
66 
67  SeeAlso []
68 
69 ***********************************************************************/
70 void Abc_DesCleanManPointer( Abc_Des_t * p, void * pMan )
71 {
72  Abc_Ntk_t * pTemp;
73  int i;
74  if ( p == NULL )
75  return;
76  if ( p->pManFunc == pMan )
77  p->pManFunc = NULL;
78  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pTemp, i )
79  if ( pTemp->pManFunc == pMan )
80  pTemp->pManFunc = NULL;
81 }
82 
83 /**Function*************************************************************
84 
85  Synopsis [Frees the library.]
86 
87  Description []
88 
89  SideEffects []
90 
91  SeeAlso []
92 
93 ***********************************************************************/
94 void Abc_DesFree( Abc_Des_t * p, Abc_Ntk_t * pNtkSave )
95 {
96  Abc_Ntk_t * pNtk;
97  int i;
98  if ( p->pName )
99  ABC_FREE( p->pName );
100  if ( p->pManFunc )
101  Hop_ManStop( (Hop_Man_t *)p->pManFunc );
102  if ( p->tModules )
103  st__free_table( p->tModules );
104  if ( p->vModules )
105  {
106  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtk, i )
107  {
108  if ( pNtk == pNtkSave )
109  continue;
110  pNtk->pDesign = NULL;
111  if ( (pNtkSave && pNtk->pManFunc == pNtkSave->pManFunc) || (pNtk->pManFunc == p->pManFunc) )
112  pNtk->pManFunc = NULL;
113  Abc_NtkDelete( pNtk );
114  }
115  Vec_PtrFree( p->vModules );
116  }
117  if ( p->vTops )
118  Vec_PtrFree( p->vTops );
119  ABC_FREE( p );
120 }
121 
122 /**Function*************************************************************
123 
124  Synopsis [Duplicated the library.]
125 
126  Description []
127 
128  SideEffects []
129 
130  SeeAlso []
131 
132 ***********************************************************************/
134 {
135  Abc_Des_t * pNew;
136  Abc_Ntk_t * pTemp;
137  Abc_Obj_t * pObj;
138  int i, k;
139  pNew = Abc_DesCreate( p->pName );
140  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pTemp, i )
141  Abc_DesAddModel( pNew, Abc_NtkDup(pTemp) );
142  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vTops, pTemp, i )
143  Vec_PtrPush( pNew->vTops, pTemp->pCopy );
144  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pTemp, i )
145  pTemp->pCopy->pAltView = pTemp->pAltView ? pTemp->pAltView->pCopy : NULL;
146  // update box models
147  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pTemp, i )
148  Abc_NtkForEachBox( pTemp, pObj, k )
149  if ( Abc_ObjIsWhitebox(pObj) || Abc_ObjIsBlackbox(pObj) )
150  pObj->pCopy->pData = Abc_ObjModel(pObj)->pCopy;
151  return pNew;
152 }
153 
154 /**Function*************************************************************
155 
156  Synopsis [Frees the library.]
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
166 {
167  Abc_Des_t * pNew;
168  Abc_Ntk_t * pNtkTemp;
169  int i;
170  assert( Vec_PtrSize(p->vTops) > 0 );
171  assert( Vec_PtrSize(p->vModules) > 1 );
172  pNew = Abc_DesCreate( p->pName );
173 // pNew->pManFunc = pNtkSave->pManFunc;
174  Vec_PtrPush( pNew->vTops, pNtkSave );
175  Vec_PtrPush( pNew->vModules, pNtkSave );
176  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtkTemp, i )
177  if ( Abc_NtkHasBlackbox( pNtkTemp ) )
178  Vec_PtrPush( pNew->vModules, Abc_NtkDup(pNtkTemp) );
179  return pNew;
180 }
181 
182 
183 /**Function*************************************************************
184 
185  Synopsis [Prints the library.]
186 
187  Description []
188 
189  SideEffects []
190 
191  SeeAlso []
192 
193 ***********************************************************************/
195 {
196  Abc_Ntk_t * pNtk;
197  Abc_Obj_t * pObj;
198  int i, k;
199  printf( "Models of design %s:\n", p->pName );
200  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtk, i )
201  {
202  printf( "%2d : %20s ", i+1, pNtk->pName );
203  printf( "nd = %6d lat = %6d whitebox = %3d blackbox = %3d\n",
204  Abc_NtkNodeNum(pNtk), Abc_NtkLatchNum(pNtk),
205  Abc_NtkWhiteboxNum(pNtk), Abc_NtkBlackboxNum(pNtk) );
206  if ( Abc_NtkBlackboxNum(pNtk) == 0 )
207  continue;
208  Abc_NtkForEachWhitebox( pNtk, pObj, k )
209  printf( " %20s (whitebox)\n", Abc_NtkName((Abc_Ntk_t *)pObj->pData) );
210  Abc_NtkForEachBlackbox( pNtk, pObj, k )
211  printf( " %20s (blackbox)\n", Abc_NtkName((Abc_Ntk_t *)pObj->pData) );
212  }
213 }
214 
215 /**Function*************************************************************
216 
217  Synopsis [Create the library.]
218 
219  Description []
220 
221  SideEffects []
222 
223  SeeAlso []
224 
225 ***********************************************************************/
227 {
228  if ( st__is_member( p->tModules, (char *)pNtk->pName ) )
229  return 0;
230  st__insert( p->tModules, (char *)pNtk->pName, (char *)pNtk );
231  assert( pNtk->Id == 0 );
232  pNtk->Id = Vec_PtrSize(p->vModules);
233  Vec_PtrPush( p->vModules, pNtk );
234  pNtk->pDesign = p;
235  return 1;
236 }
237 
238 /**Function*************************************************************
239 
240  Synopsis [Create the library.]
241 
242  Description []
243 
244  SideEffects []
245 
246  SeeAlso []
247 
248 ***********************************************************************/
250 {
251  Abc_Ntk_t * pNtk;
252  if ( ! st__is_member( p->tModules, (char *)pName ) )
253  return NULL;
254  st__lookup( p->tModules, (char *)pName, (char **)&pNtk );
255  return pNtk;
256 }
257 
258 /**Function*************************************************************
259 
260  Synopsis [Frees the library.]
261 
262  Description []
263 
264  SideEffects []
265 
266  SeeAlso []
267 
268 ***********************************************************************/
270 {
271  Abc_Ntk_t * pNtk;
272  if ( Vec_PtrSize(p->vModules) > 1 )
273  {
274  printf( "The design includes more than one module and is currently not used.\n" );
275  return NULL;
276  }
277  pNtk = (Abc_Ntk_t *)Vec_PtrEntry( p->vModules, 0 ); Vec_PtrClear( p->vModules );
278  pNtk->pManFunc = p->pManFunc; p->pManFunc = NULL;
279  return pNtk;
280 }
281 
282 /**Function*************************************************************
283 
284  Synopsis [Detects the top-level models.]
285 
286  Description []
287 
288  SideEffects []
289 
290  SeeAlso []
291 
292 ***********************************************************************/
294 {
295  Abc_Ntk_t * pNtk, * pNtkBox;
296  Abc_Obj_t * pObj;
297  int i, k;
298  assert( Vec_PtrSize( p->vModules ) > 0 );
299  // clear the models
300  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtk, i )
301  pNtk->fHieVisited = 0;
302  // mark all the models reachable from other models
303  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtk, i )
304  {
305  Abc_NtkForEachBox( pNtk, pObj, k )
306  {
307  if ( Abc_ObjIsLatch(pObj) )
308  continue;
309  if ( pObj->pData == NULL )
310  continue;
311  pNtkBox = (Abc_Ntk_t *)pObj->pData;
312  pNtkBox->fHieVisited = 1;
313  }
314  }
315  // collect the models that are not marked
316  Vec_PtrClear( p->vTops );
317  Vec_PtrForEachEntry( Abc_Ntk_t *, p->vModules, pNtk, i )
318  {
319  if ( pNtk->fHieVisited == 0 )
320  Vec_PtrPush( p->vTops, pNtk );
321  else
322  pNtk->fHieVisited = 0;
323  }
324  return Vec_PtrSize( p->vTops );
325 }
326 
327 
328 /**Function*************************************************************
329 
330  Synopsis [Derive the AIG of the logic in the netlist.]
331 
332  Description []
333 
334  SideEffects []
335 
336  SeeAlso []
337 
338 ***********************************************************************/
340 {
341  Abc_Obj_t * pFanin;
342  int i;
343  assert( !Abc_ObjIsNet(pObj) );
344  if ( pObj->pCopy )
345  return;
346  // call for the fanins
347  Abc_ObjForEachFanin( pObj, pFanin, i )
349  // compute for the node
350  pObj->pCopy = Abc_NodeStrash( pNtkAig, pObj, 0 );
351  // set for the fanout net
352  Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
353 }
354 
355 /**Function*************************************************************
356 
357  Synopsis [Derive the AIG of the logic in the netlist.]
358 
359  Description []
360 
361  SideEffects []
362 
363  SeeAlso []
364 
365 ***********************************************************************/
367 {
368  Abc_Ntk_t * pNtkGate;
369  Abc_Obj_t * pObj;
370  unsigned * pPolarity;
371  int i, fCompl;
372  assert( Abc_ObjIsBox(pBox) );
373  pNtkGate = (Abc_Ntk_t *)pBox->pData;
374  pPolarity = (unsigned *)pBox->pNext;
375  assert( Abc_NtkIsNetlist(pNtkGate) );
376  assert( Abc_NtkLatchNum(pNtkGate) == 0 );
377  Abc_NtkCleanCopy( pNtkGate );
378  // set the PI values
379  Abc_NtkForEachPi( pNtkGate, pObj, i )
380  {
381  fCompl = (pPolarity && Abc_InfoHasBit(pPolarity, i));
382  pObj->pCopy = Abc_ObjNotCond( Abc_ObjFanin(pBox,i)->pCopy, fCompl );
383  Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
384  }
385  // build recursively and set the PO values
386  Abc_NtkForEachPo( pNtkGate, pObj, i )
387  {
389  Abc_ObjFanout(pBox,i)->pCopy = Abc_ObjFanin0(pObj)->pCopy;
390  }
391 //printf( "processing %d\n", pBox->Id );
392 }
393 
394 ////////////////////////////////////////////////////////////////////////
395 /// END OF FILE ///
396 ////////////////////////////////////////////////////////////////////////
397 
398 
400 
char * memset()
void st__free_table(st__table *table)
Definition: st.c:81
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
static int Abc_NtkIsNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:249
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
#define Abc_NtkForEachWhitebox(pNtk, pObj, i)
Definition: abc.h:506
static Abc_Obj_t * Abc_ObjFanin0Ntk(Abc_Obj_t *pObj)
Definition: abc.h:375
st__table * tModules
Definition: abc.h:224
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Abc_ObjIsWhitebox(Abc_Obj_t *pObj)
Definition: abc.h:358
char * pName
Definition: abc.h:220
#define st__is_member(table, key)
Definition: st.h:70
int Id
Definition: abc.h:184
static int Abc_NtkWhiteboxNum(Abc_Ntk_t *pNtk)
Definition: abc.h:295
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
void Hop_ManStop(Hop_Man_t *p)
Definition: hopMan.c:84
static Abc_Ntk_t * Abc_ObjModel(Abc_Obj_t *pObj)
Definition: abc.h:335
int strcmp()
void * pManFunc
Definition: abc.h:221
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
int st__strhash(const char *string, int modulus)
Definition: st.c:449
void * pManFunc
Definition: abc.h:191
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
void Abc_DesCleanManPointer(Abc_Des_t *p, void *pMan)
Definition: abcLib.c:70
Abc_Des_t * pLibrary
Definition: abc.h:225
Abc_Obj_t * pCopy
Definition: abc.h:148
void Abc_NodeStrashUsingNetwork(Abc_Ntk_t *pNtkAig, Abc_Obj_t *pBox)
Definition: abcLib.c:366
static int Abc_NtkHasBlackbox(Abc_Ntk_t *pNtk)
Definition: abc.h:258
ABC_DLL Abc_Obj_t * Abc_NodeStrash(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pNode, int fRecord)
Definition: abcStrash.c:468
#define Abc_NtkForEachBlackbox(pNtk, pObj, i)
Definition: abc.h:509
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Abc_Des_t * Abc_DesDupBlackboxes(Abc_Des_t *p, Abc_Ntk_t *pNtkSave)
Definition: abcLib.c:165
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition: hopMan.c:45
Abc_Ntk_t * pAltView
Definition: abc.h:181
int Abc_DesAddModel(Abc_Des_t *p, Abc_Ntk_t *pNtk)
Definition: abcLib.c:226
Vec_Ptr_t * vTops
Definition: abc.h:222
Abc_Des_t * Abc_DesDup(Abc_Des_t *p)
Definition: abcLib.c:133
Abc_Ntk_t * Abc_DesDeriveRoot(Abc_Des_t *p)
Definition: abcLib.c:269
#define Abc_NtkForEachBox(pNtk, pObj, i)
Definition: abc.h:495
void Abc_NodeStrashUsingNetwork_rec(Abc_Ntk_t *pNtkAig, Abc_Obj_t *pObj)
Definition: abcLib.c:339
void Abc_DesPrint(Abc_Des_t *p)
Definition: abcLib.c:194
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
Abc_Ntk_t * pCopy
Definition: abc.h:204
static char * Abc_NtkName(Abc_Ntk_t *pNtk)
Definition: abc.h:270
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Abc_ObjIsNet(Abc_Obj_t *pObj)
Definition: abc.h:354
Abc_Obj_t * pNext
Definition: abc.h:131
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
void Abc_DesFree(Abc_Des_t *p, Abc_Ntk_t *pNtkSave)
Definition: abcLib.c:94
Vec_Ptr_t * vModules
Definition: abc.h:223
static Abc_Obj_t * Abc_ObjNotCond(Abc_Obj_t *p, int c)
Definition: abc.h:325
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static int Abc_ObjIsBox(Abc_Obj_t *pObj)
Definition: abc.h:357
int Abc_DesFindTopLevelModels(Abc_Des_t *p)
Definition: abcLib.c:293
void * pData
Definition: abc.h:145
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static int Abc_NtkBlackboxNum(Abc_Ntk_t *pNtk)
Definition: abc.h:296
static Abc_Obj_t * Abc_ObjFanout(Abc_Obj_t *pObj, int i)
Definition: abc.h:370
static Abc_Obj_t * Abc_ObjFanin(Abc_Obj_t *pObj, int i)
Definition: abc.h:372
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Abc_Ntk_t * Abc_DesFindModelByName(Abc_Des_t *p, char *pName)
Definition: abcLib.c:249
Abc_Des_t * pDesign
Definition: abc.h:180
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
char * pName
Definition: abc.h:158
int fHieVisited
Definition: abc.h:182
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static int Abc_ObjIsBlackbox(Abc_Obj_t *pObj)
Definition: abc.h:359
ABC_NAMESPACE_IMPL_START Abc_Des_t * Abc_DesCreate(char *pName)
DECLARATIONS ///.
Definition: abcLib.c:45