ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
vecAtt.h
Go to the documentation of this file.
1
20
21#ifndef ABC__misc__vec__vecAtt_h
22#define ABC__misc__vec__vecAtt_h
23
24
28
29#include <stdio.h>
30
32
33
37
38// various attributes
57
61
62typedef struct Vec_Att_t_ Vec_Att_t;
64{
65 // storage for attributes
66 int nCap; // the size of array allocated
67 // Removed pArrayInt as it's not 64-bit safe, it generates compiler
68 // warnings, and it's unused.
69 void ** pArrayPtr; // the pointer attribute array
70 // attribute specific info
71 void * pMan; // the manager for this attribute
72 void (*pFuncFreeMan) (void *); // the procedure to free the manager
73 void*(*pFuncStartObj)(void *); // the procedure to start one attribute
74 void (*pFuncFreeObj) (void *, void *); // the procedure to free one attribute
75};
76
80
84
96static inline Vec_Att_t * Vec_AttAlloc(
97 int nSize, void * pMan,
98 void (*pFuncFreeMan) (void *),
99 void*(*pFuncStartObj)(void *),
100 void (*pFuncFreeObj) (void *, void *) )
101{
102 Vec_Att_t * p;
103 p = ABC_ALLOC( Vec_Att_t, 1 );
104 memset( p, 0, sizeof(Vec_Att_t) );
105 p->pMan = pMan;
106 p->pFuncFreeMan = pFuncFreeMan;
107 p->pFuncStartObj = pFuncStartObj;
108 p->pFuncFreeObj = pFuncFreeObj;
109 p->nCap = nSize? nSize : 16;
110 p->pArrayPtr = ABC_ALLOC( void *, p->nCap );
111 memset( p->pArrayPtr, 0, sizeof(void *) * (size_t)p->nCap );
112 return p;
113}
114
126static inline void * Vec_AttFree( Vec_Att_t * p, int fFreeMan )
127{
128 void * pMan;
129 if ( p == NULL )
130 return NULL;
131 // free the attributes of objects
132 if ( p->pFuncFreeObj )
133 {
134 int i;
135 for ( i = 0; i < p->nCap; i++ )
136 if ( p->pArrayPtr[i] )
137 p->pFuncFreeObj( p->pMan, p->pArrayPtr[i] );
138 }
139 // free the memory manager
140 pMan = fFreeMan? NULL : p->pMan;
141 if ( p->pMan && fFreeMan )
142 p->pFuncFreeMan( p->pMan );
143 ABC_FREE( p->pArrayPtr );
144 ABC_FREE( p );
145 return pMan;
146}
147
159static inline void Vec_AttClear( Vec_Att_t * p )
160{
161 // free the attributes of objects
162 if ( p->pFuncFreeObj )
163 {
164 int i;
165 if ( p->pFuncFreeObj )
166 for ( i = 0; i < p->nCap; i++ )
167 if ( p->pArrayPtr[i] )
168 p->pFuncFreeObj( p->pMan, p->pArrayPtr[i] );
169 }
170 memset( p->pArrayPtr, 0, sizeof(void *) * (size_t)p->nCap );
171}
172
184static inline void Vec_AttFreeEntry( Vec_Att_t * p, int i )
185{
186 if ( i >= p->nCap )
187 return;
188 if ( p->pMan )
189 {
190 if ( p->pArrayPtr[i] && p->pFuncFreeObj )
191 p->pFuncFreeObj( p->pMan, (void *)p->pArrayPtr[i] );
192 }
193 p->pArrayPtr[i] = NULL;
194}
195
207static inline void Vec_AttGrow( Vec_Att_t * p, int nCapMin )
208{
209 if ( p->nCap >= nCapMin )
210 return;
211 p->pArrayPtr = ABC_REALLOC( void *, p->pArrayPtr, nCapMin );
212 memset( p->pArrayPtr + p->nCap, 0, sizeof(void *) * (size_t)(nCapMin - p->nCap) );
213 p->nCap = nCapMin;
214}
215
227static inline void Vec_AttWriteEntry( Vec_Att_t * p, int i, void * pEntry )
228{
229 assert( p->pArrayPtr );
230 assert( p->pFuncStartObj == NULL );
231 if ( i >= p->nCap )
232 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
233 p->pArrayPtr[i] = pEntry;
234}
235
247static inline void * Vec_AttEntry( Vec_Att_t * p, int i )
248{
249 assert( p->pArrayPtr );
250 if ( i >= p->nCap )
251 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
252 if ( p->pArrayPtr[i] == NULL && p->pFuncStartObj )
253 p->pArrayPtr[i] = p->pFuncStartObj( p->pMan );
254 return p->pArrayPtr[i];
255}
256
268static inline void * Vec_AttMan( Vec_Att_t * p )
269{
270 return p->pMan;
271}
272
284static inline void ** Vec_AttArray( Vec_Att_t * p )
285{
286 return p->pArrayPtr;
287}
288
289
290
292
293#endif
294
298
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Cube * p
Definition exorList.c:222
int nCap
Definition vecAtt.h:66
void ** pArrayPtr
Definition vecAtt.h:69
void(* pFuncFreeMan)(void *)
Definition vecAtt.h:72
void(* pFuncFreeObj)(void *, void *)
Definition vecAtt.h:74
void * pMan
Definition vecAtt.h:71
#define assert(ex)
Definition util_old.h:213
char * memset()
Vec_AttrType_t
INCLUDES ///.
Definition vecAtt.h:39
@ VEC_ATTR_MVVAR
Definition vecAtt.h:52
@ VEC_ATTR_LOCAL_SOP
Definition vecAtt.h:43
@ VEC_ATTR_RETIME_LAG
Definition vecAtt.h:50
@ VEC_ATTR_GLOBAL_BDD
Definition vecAtt.h:47
@ VEC_ATTR_COPY
Definition vecAtt.h:41
@ VEC_ATTR_GLOBAL_AIG
Definition vecAtt.h:45
@ VEC_ATTR_GLOBAL_SOP
Definition vecAtt.h:46
@ VEC_ATTR_LEVEL
Definition vecAtt.h:48
@ VEC_ATTR_LEVEL_REV
Definition vecAtt.h:49
@ VEC_ATTR_LOCAL_BDD
Definition vecAtt.h:44
@ VEC_ATTR_NONE
Definition vecAtt.h:40
@ VEC_ATTR_DATA1
Definition vecAtt.h:53
@ VEC_ATTR_DATA2
Definition vecAtt.h:54
@ VEC_ATTR_FRAIG
Definition vecAtt.h:51
@ VEC_ATTR_LOCAL_AIG
Definition vecAtt.h:42
@ VEC_ATTR_TOTAL_NUM
Definition vecAtt.h:55
struct Vec_Att_t_ Vec_Att_t
BASIC TYPES ///.
Definition vecAtt.h:62