ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
nmApi.c
Go to the documentation of this file.
1
20
21#include "nmInt.h"
22
24
25
29
33
45Nm_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
77{
78 Extra_MmFlexStop( p->pMem );
79 ABC_FREE( p->pBinsI2N );
80 ABC_FREE( p->pBinsN2I );
81 ABC_FREE( p );
82}
83
96{
97 return p->nEntries;
98}
99
112char * 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 ID %d already exists.\n", ObjId );
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
149void 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(): Entry with ID %d is not in the table.\n", ObjId );
156 return;
157 }
158 // remove entry from the table
159 Nm_ManTableDelete( p, ObjId );
160}
161
162
175char * 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
199char * 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
219int 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
239int 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
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
275
276
278
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#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
void Extra_MmFlexStop(Extra_MmFlex_t *p)
Extra_MmFlex_t * Extra_MmFlexStart()
char * Extra_MmFlexEntryFetch(Extra_MmFlex_t *p, int nBytes)
Vec_Int_t * Nm_ManReturnNameIds(Nm_Man_t *p)
Definition nmApi.c:261
int Nm_ManNumEntries(Nm_Man_t *p)
Definition nmApi.c:95
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition nmApi.c:199
void Nm_ManFree(Nm_Man_t *p)
Definition nmApi.c:76
int Nm_ManFindIdByNameTwoTypes(Nm_Man_t *p, char *pName, int Type1, int Type2)
Definition nmApi.c:239
void Nm_ManDeleteIdName(Nm_Man_t *p, int ObjId)
Definition nmApi.c:149
char * Nm_ManCreateUniqueName(Nm_Man_t *p, int ObjId)
Definition nmApi.c:175
int Nm_ManFindIdByName(Nm_Man_t *p, char *pName, int Type)
Definition nmApi.c:219
ABC_NAMESPACE_IMPL_START Nm_Man_t * Nm_ManCreate(int nSize)
DECLARATIONS ///.
Definition nmApi.c:45
char * Nm_ManStoreIdName(Nm_Man_t *p, int ObjId, int Type, char *pName, char *pSuffix)
Definition nmApi.c:112
Nm_Entry_t * Nm_ManTableLookupName(Nm_Man_t *p, char *pName, int Type)
Definition nmTable.c:191
int Nm_ManTableAdd(Nm_Man_t *p, Nm_Entry_t *pEntry)
MACRO DEFINITIONS ///.
Definition nmTable.c:71
int Nm_ManTableDelete(Nm_Man_t *p, int ObjId)
Definition nmTable.c:112
Nm_Entry_t * Nm_ManTableLookupId(Nm_Man_t *p, int ObjId)
Definition nmTable.c:171
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition nmInt.h:46
typedefABC_NAMESPACE_HEADER_START struct Nm_Man_t_ Nm_Man_t
INCLUDES ///.
Definition nm.h:63
#define assert(ex)
Definition util_old.h:213
char * memset()
int strlen()
char * sprintf()