abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nmApi.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [nmApi.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Name manager.]
8 
9  Synopsis [APIs of the name manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: nmApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "nmInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Allocates the name manager.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 Nm_Man_t * Nm_ManCreate( int nSize )
46 {
47  Nm_Man_t * p;
48  // allocate the table
49  p = ABC_ALLOC( Nm_Man_t, 1 );
50  memset( p, 0, sizeof(Nm_Man_t) );
51  // set the parameters
52  p->nSizeFactor = 2; // determined the limit on the grow of data before the table resizes
53  p->nGrowthFactor = 3; // determined how much the table grows after resizing
54  // allocate and clean the bins
55  p->nBins = Abc_PrimeCudd(nSize);
56  p->pBinsI2N = ABC_ALLOC( Nm_Entry_t *, p->nBins );
57  p->pBinsN2I = ABC_ALLOC( Nm_Entry_t *, p->nBins );
58  memset( p->pBinsI2N, 0, sizeof(Nm_Entry_t *) * p->nBins );
59  memset( p->pBinsN2I, 0, sizeof(Nm_Entry_t *) * p->nBins );
60  // start the memory manager
61  p->pMem = Extra_MmFlexStart();
62  return p;
63 }
64 
65 /**Function*************************************************************
66 
67  Synopsis [Deallocates the name manager.]
68 
69  Description []
70 
71  SideEffects []
72 
73  SeeAlso []
74 
75 ***********************************************************************/
77 {
78  Extra_MmFlexStop( p->pMem );
79  ABC_FREE( p->pBinsI2N );
80  ABC_FREE( p->pBinsN2I );
81  ABC_FREE( p );
82 }
83 
84 /**Function*************************************************************
85 
86  Synopsis [Returns the number of objects with names.]
87 
88  Description []
89 
90  SideEffects []
91 
92  SeeAlso []
93 
94 ***********************************************************************/
96 {
97  return p->nEntries;
98 }
99 
100 /**Function*************************************************************
101 
102  Synopsis [Creates a new entry in the name manager.]
103 
104  Description [Returns 1 if the entry with the given object ID
105  already exists in the name manager.]
106 
107  SideEffects []
108 
109  SeeAlso []
110 
111 ***********************************************************************/
112 char * Nm_ManStoreIdName( Nm_Man_t * p, int ObjId, int Type, char * pName, char * pSuffix )
113 {
114  Nm_Entry_t * pEntry;
115  int RetValue, nEntrySize;
116  // check if the object with this ID is already stored
117  if ( (pEntry = Nm_ManTableLookupId(p, ObjId)) )
118  {
119  printf( "Nm_ManStoreIdName(): Entry with the same ID already exists.\n" );
120  return NULL;
121  }
122  // create a new entry
123  nEntrySize = sizeof(Nm_Entry_t) + strlen(pName) + (pSuffix?strlen(pSuffix):0) + 1;
124 // nEntrySize = (nEntrySize / 4 + ((nEntrySize % 4) > 0)) * 4;
125  nEntrySize = (nEntrySize / sizeof(char*) + ((nEntrySize % sizeof(char*)) > 0)) * sizeof(char*); // added by Saurabh on Sep 3, 2009
126  pEntry = (Nm_Entry_t *)Extra_MmFlexEntryFetch( p->pMem, nEntrySize );
127  pEntry->pNextI2N = pEntry->pNextN2I = pEntry->pNameSake = NULL;
128  pEntry->ObjId = ObjId;
129  pEntry->Type = Type;
130  sprintf( pEntry->Name, "%s%s", pName, pSuffix? pSuffix : "" );
131  // add the entry to the hash table
132  RetValue = Nm_ManTableAdd( p, pEntry );
133  assert( RetValue == 1 );
134  return pEntry->Name;
135 }
136 
137 /**Function*************************************************************
138 
139  Synopsis [Creates a new entry in the name manager.]
140 
141  Description [Returns 1 if the entry with the given object ID
142  already exists in the name manager.]
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
149 void Nm_ManDeleteIdName( Nm_Man_t * p, int ObjId )
150 {
151  Nm_Entry_t * pEntry;
152  pEntry = Nm_ManTableLookupId(p, ObjId);
153  if ( pEntry == NULL )
154  {
155  printf( "Nm_ManDeleteIdName(): This entry is not in the table.\n" );
156  return;
157  }
158  // remove entry from the table
159  Nm_ManTableDelete( p, ObjId );
160 }
161 
162 
163 /**Function*************************************************************
164 
165  Synopsis [Finds a unique name for the node.]
166 
167  Description [If the name exists, tries appending numbers to it until
168  it becomes unique. The name is not added to the table.]
169 
170  SideEffects []
171 
172  SeeAlso []
173 
174 ***********************************************************************/
175 char * Nm_ManCreateUniqueName( Nm_Man_t * p, int ObjId )
176 {
177  static char NameStr[1000];
178  Nm_Entry_t * pEntry;
179  int i;
180  if ( (pEntry = Nm_ManTableLookupId(p, ObjId)) )
181  return pEntry->Name;
182  sprintf( NameStr, "n%d", ObjId );
183  for ( i = 1; Nm_ManTableLookupName(p, NameStr, -1); i++ )
184  sprintf( NameStr, "n%d_%d", ObjId, i );
185  return NameStr;
186 }
187 
188 /**Function*************************************************************
189 
190  Synopsis [Returns name of the object if the ID is known.]
191 
192  Description []
193 
194  SideEffects []
195 
196  SeeAlso []
197 
198 ***********************************************************************/
199 char * Nm_ManFindNameById( Nm_Man_t * p, int ObjId )
200 {
201  Nm_Entry_t * pEntry;
202  if ( (pEntry = Nm_ManTableLookupId(p, ObjId)) )
203  return pEntry->Name;
204  return NULL;
205 }
206 
207 /**Function*************************************************************
208 
209  Synopsis [Returns ID of the object if its name is known.]
210 
211  Description [This procedure may return two IDs because POs and latches
212  may have the same name (the only allowed case of name duplication).]
213 
214  SideEffects []
215 
216  SeeAlso []
217 
218 ***********************************************************************/
219 int Nm_ManFindIdByName( Nm_Man_t * p, char * pName, int Type )
220 {
221  Nm_Entry_t * pEntry;
222  if ( (pEntry = Nm_ManTableLookupName(p, pName, Type)) )
223  return pEntry->ObjId;
224  return -1;
225 }
226 
227 /**Function*************************************************************
228 
229  Synopsis [Returns ID of the object if its name is known.]
230 
231  Description [This procedure may return two IDs because POs and latches
232  may have the same name (the only allowed case of name duplication).]
233 
234  SideEffects []
235 
236  SeeAlso []
237 
238 ***********************************************************************/
239 int Nm_ManFindIdByNameTwoTypes( Nm_Man_t * p, char * pName, int Type1, int Type2 )
240 {
241  int iNodeId;
242  iNodeId = Nm_ManFindIdByName( p, pName, Type1 );
243  if ( iNodeId == -1 )
244  iNodeId = Nm_ManFindIdByName( p, pName, Type2 );
245  if ( iNodeId == -1 )
246  return -1;
247  return iNodeId;
248 }
249 
250 /**Function*************************************************************
251 
252  Synopsis [Return the IDs of objects with names.]
253 
254  Description []
255 
256  SideEffects []
257 
258  SeeAlso []
259 
260 ***********************************************************************/
262 {
263  Vec_Int_t * vNameIds;
264  int i;
265  vNameIds = Vec_IntAlloc( p->nEntries );
266  for ( i = 0; i < p->nBins; i++ )
267  if ( p->pBinsI2N[i] )
268  Vec_IntPush( vNameIds, p->pBinsI2N[i]->ObjId );
269  return vNameIds;
270 }
271 
272 ////////////////////////////////////////////////////////////////////////
273 /// END OF FILE ///
274 ////////////////////////////////////////////////////////////////////////
275 
276 
278 
char * Extra_MmFlexEntryFetch(Extra_MmFlex_t *p, int nBytes)
int Nm_ManTableDelete(Nm_Man_t *p, int ObjId)
Definition: nmTable.c:112
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
int Nm_ManFindIdByName(Nm_Man_t *p, char *pName, int Type)
Definition: nmApi.c:219
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Int_t * Nm_ManReturnNameIds(Nm_Man_t *p)
Definition: nmApi.c:261
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Extra_MmFlex_t * Extra_MmFlexStart()
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition: nmInt.h:46
ABC_NAMESPACE_IMPL_START Nm_Man_t * Nm_ManCreate(int nSize)
DECLARATIONS ///.
Definition: nmApi.c:45
int Nm_ManFindIdByNameTwoTypes(Nm_Man_t *p, char *pName, int Type1, int Type2)
Definition: nmApi.c:239
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Nm_ManFree(Nm_Man_t *p)
Definition: nmApi.c:76
Nm_Entry_t * Nm_ManTableLookupId(Nm_Man_t *p, int ObjId)
Definition: nmTable.c:171
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
typedefABC_NAMESPACE_HEADER_START struct Nm_Man_t_ Nm_Man_t
INCLUDES ///.
Definition: nm.h:63
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * sprintf()
char * Nm_ManCreateUniqueName(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:175
int Nm_ManNumEntries(Nm_Man_t *p)
Definition: nmApi.c:95
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Nm_Entry_t * Nm_ManTableLookupName(Nm_Man_t *p, char *pName, int Type)
Definition: nmTable.c:191
void Nm_ManDeleteIdName(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:149
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Nm_ManTableAdd(Nm_Man_t *p, Nm_Entry_t *pEntry)
MACRO DEFINITIONS ///.
Definition: nmTable.c:71
#define assert(ex)
Definition: util_old.h:213
char * Nm_ManStoreIdName(Nm_Man_t *p, int ObjId, int Type, char *pName, char *pSuffix)
Definition: nmApi.c:112
int strlen()
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
void Extra_MmFlexStop(Extra_MmFlex_t *p)