ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
attr.h
Go to the documentation of this file.
1
20
21#ifndef ABC__aig__ivy__attr_h
22#define ABC__aig__ivy__attr_h
23
24
28
29#include "misc/extra/extra.h"
30
34
35
36
38
39
43
46{
47 // attribute info
48 int nAttrSize; // the size of each attribute in bytes
49 Extra_MmFixed_t * pManMem; // memory manager for attributes
50 int nAttrs; // the number of attributes allocated
51 void ** pAttrs; // the array of attributes
52 int fUseInt; // uses integer attributes
53 // attribute specific info
54 void * pManAttr; // the manager for this attribute
55 void (*pFuncFreeMan) (void *); // the procedure to call to free attribute-specific manager
56 void (*pFuncFreeObj) (void *, void *); // the procedure to call to free attribute-specific data
57};
58
59// at any time, an attribute of the given ID can be
60// - not available (p->nAttrs < Id)
61// - available but not allocated (p->nAttrs >= Id && p->pAttrs[Id] == NULL)
62// - available and allocated (p->nAttrs >= Id && p->pAttrs[Id] != NULL)
63
67
71
83static inline Attr_Man_t * Attr_ManAlloc( int nAttrSize, int fManMem )
84{
85 Attr_Man_t * p;
86 p = ALLOC( Attr_Man_t, 1 );
87 memset( p, 0, sizeof(Attr_Man_t) );
88 p->nAttrSize = nAttrSize;
89 if ( fManMem )
90 p->pManMem = Extra_MmFixedStart( nAttrSize );
91 return p;
92}
93
105static inline Attr_Man_t * Attr_ManStartInt( int nAttrs )
106{
107 Attr_Man_t * p;
108 p = Attr_ManAlloc( sizeof(int), 0 );
109 p->nAttrs = nAttrs;
110 p->pAttrs = (void **)ALLOC( int, nAttrs );
111 memset( (int *)p->pAttrs, 0, sizeof(int) * nAttrs );
112 p->fUseInt = 1;
113 return p;
114}
115
127static inline Attr_Man_t * Attr_ManStartPtr( int nAttrs )
128{
129 Attr_Man_t * p;
130 p = Attr_ManAlloc( sizeof(void *), 0 );
131 p->nAttrs = nAttrs;
132 p->pAttrs = ALLOC( void *, nAttrs );
133 memset( p->pAttrs, 0, sizeof(void *) * nAttrs );
134 return p;
135}
136
148static inline Attr_Man_t * Attr_ManStartPtrMem( int nAttrs, int nAttrSize )
149{
150 Attr_Man_t * p;
151 int i;
152 p = Attr_ManAlloc( nAttrSize, 1 );
153 p->nAttrs = nAttrs;
154 p->pAttrs = ALLOC( void *, nAttrs );
155 for ( i = 0; i < p->nAttrs; i++ )
156 {
157 p->pAttrs[i] = Extra_MmFixedEntryFetch( p->pManMem );
158 memset( p->pAttrs[i], 0, nAttrSize );
159 }
160 return p;
161}
162
174static inline void Attr_ManStop( Attr_Man_t * p )
175{
176 // free the attributes of objects
177 if ( p->pFuncFreeObj )
178 {
179 int i;
180 if ( p->fUseInt )
181 {
182 for ( i = 0; i < p->nAttrs; i++ )
183 if ( ((int *)p->pAttrs)[i] )
184 p->pFuncFreeObj( p->pManAttr, (void *)((int *)p->pAttrs)[i] );
185 }
186 else
187 {
188 for ( i = 0; i < p->nAttrs; i++ )
189 if ( p->pAttrs[i] )
190 p->pFuncFreeObj( p->pManAttr, p->pAttrs[i] );
191 }
192 }
193 // free the attribute manager
194 if ( p->pManAttr && p->pFuncFreeMan )
195 p->pFuncFreeMan( p->pManAttr );
196 // free the memory manager
197 if ( p->pManMem )
198 Extra_MmFixedStop( p->pManMem);
199 // free the attribute manager
200 FREE( p->pAttrs );
201 free( p );
202}
203
215static inline int Attr_ManReadAttrInt( Attr_Man_t * p, int Id )
216{
217 assert( p->fUseInt );
218 if ( Id >= p->nAttrs )
219 return 0;
220 return ((int *)p->pAttrs)[Id];
221}
222
234static inline void * Attr_ManReadAttrPtr( Attr_Man_t * p, int Id )
235{
236 assert( !p->fUseInt );
237 if ( Id >= p->nAttrs )
238 return NULL;
239 return p->pAttrs[Id];
240}
241
253static inline void Attr_ManWriteAttrInt( Attr_Man_t * p, int Id, int Attr )
254{
255 assert( p->fUseInt );
256 ((int *)p->pAttrs)[Id] = Attr;
257}
258
270static inline void Attr_ManWriteAttrPtr( Attr_Man_t * p, int Id, void * pAttr )
271{
272 assert( !p->fUseInt );
273 assert( p->pManMem == NULL );
274 p->pAttrs[Id] = pAttr;
275}
276
288static inline int * Attr_ManFetchSpotInt( Attr_Man_t * p, int Id )
289{
290 assert( p->fUseInt );
291 if ( Id >= p->nAttrs )
292 {
293 // save the old size
294 int i, nAttrsOld = p->nAttrs;
295 // get the new size
296 p->nAttrs = p->nAttrs? 2*p->nAttrs : 1024;
297 p->pAttrs = realloc( p->pAttrs, sizeof(int) * p->nAttrs );
298 // fill in the empty spots
299 for ( i = nAttrsOld; i < p->nAttrs; i++ )
300 ((int *)p->pAttrs)[Id] = 0;
301 }
302 return ((int *)p->pAttrs) + Id;
303}
304
316static inline void ** Attr_ManFetchSpotPtr( Attr_Man_t * p, int Id )
317{
318 assert( !p->fUseInt );
319 if ( Id >= p->nAttrs )
320 {
321 // save the old size
322 int i, nAttrsOld = p->nAttrs;
323 // get the new size
324 p->nAttrs = p->nAttrs? 2*p->nAttrs : 1024;
325 p->pAttrs = realloc( p->pAttrs, sizeof(void *) * p->nAttrs );
326 // fill in the empty spots
327 for ( i = nAttrsOld; i < p->nAttrs; i++ )
328 p->pAttrs[Id] = NULL;
329 }
330 // if memory manager is available but entry is not created, create it
331 if ( p->pManMem && p->pAttrs[Id] != NULL )
332 {
333 p->pAttrs[Id] = Extra_MmFixedEntryFetch( p->pManMem );
334 memset( p->pAttrs[Id], 0, p->nAttrSize );
335 }
336 return p->pAttrs + Id;
337}
338
339
351static inline int Attr_ManFetchAttrInt( Attr_Man_t * p, int Id )
352{
353 return *Attr_ManFetchSpotInt( p, Id );
354}
355
367static inline void * Attr_ManFetchAttrPtr( Attr_Man_t * p, int Id )
368{
369 return *Attr_ManFetchSpotPtr( p, Id );
370}
371
383static inline void Attr_ManSetAttrInt( Attr_Man_t * p, int Id, int Attr )
384{
385 *Attr_ManFetchSpotInt( p, Id ) = Attr;
386}
387
399static inline void Attr_ManSetAttrPtr( Attr_Man_t * p, int Id, void * pAttr )
400{
401 assert( p->pManMem == NULL );
402 *Attr_ManFetchSpotPtr( p, Id ) = pAttr;
403}
404
405
406
407
408
410
411
412
413#endif
414
418
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_HEADER_START struct Attr_ManStruct_t_ Attr_Man_t
INCLUDES ///.
Definition attr.h:44
#define ALLOC(type, num)
Definition avl.h:27
#define FREE(obj)
Definition avl.h:31
Cube * p
Definition exorList.c:222
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
void Extra_MmFixedStop(Extra_MmFixed_t *p)
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
struct Extra_MmFixed_t_ Extra_MmFixed_t
Definition extra.h:147
void ** pAttrs
Definition attr.h:51
void(* pFuncFreeObj)(void *, void *)
Definition attr.h:56
Extra_MmFixed_t * pManMem
Definition attr.h:49
void * pManAttr
Definition attr.h:54
void(* pFuncFreeMan)(void *)
Definition attr.h:55
#define assert(ex)
Definition util_old.h:213
char * memset()
VOID_HACK free()
char * realloc()