1 /**CFile****************************************************************
2 
3   FileName    [vecAtt.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Resizable arrays.]
8 
9   Synopsis    [Array of user-specified attiributes.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: vecAtt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__vec__vecAtt_h
22 #define ABC__misc__vec__vecAtt_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 ///                          INCLUDES                                ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 #include <stdio.h>
30 
31 ABC_NAMESPACE_HEADER_START
32 
33 
34 ////////////////////////////////////////////////////////////////////////
35 ///                         PARAMETERS                               ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 // various attributes
39 typedef enum {
40     VEC_ATTR_NONE = 0,     // 0
41     VEC_ATTR_COPY,         // 1
42     VEC_ATTR_LOCAL_AIG,    // 2
43     VEC_ATTR_LOCAL_SOP,    // 3
44     VEC_ATTR_LOCAL_BDD,    // 4
45     VEC_ATTR_GLOBAL_AIG,   // 5
46     VEC_ATTR_GLOBAL_SOP,   // 6
47     VEC_ATTR_GLOBAL_BDD,   // 7
48     VEC_ATTR_LEVEL,        // 8
49     VEC_ATTR_LEVEL_REV,    // 9
50     VEC_ATTR_RETIME_LAG,   // 10
51     VEC_ATTR_FRAIG,        // 11
52     VEC_ATTR_MVVAR,        // 12
53     VEC_ATTR_DATA1,        // 13
54     VEC_ATTR_DATA2,        // 14
55     VEC_ATTR_TOTAL_NUM     // 15
56 } Vec_AttrType_t;
57 
58 ////////////////////////////////////////////////////////////////////////
59 ///                         BASIC TYPES                              ///
60 ////////////////////////////////////////////////////////////////////////
61 
62 typedef struct Vec_Att_t_  Vec_Att_t;
63 struct 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 
77 ////////////////////////////////////////////////////////////////////////
78 ///                      MACRO DEFINITIONS                           ///
79 ////////////////////////////////////////////////////////////////////////
80 
81 ////////////////////////////////////////////////////////////////////////
82 ///                     FUNCTION DEFINITIONS                         ///
83 ////////////////////////////////////////////////////////////////////////
84 
85 /**Function*************************************************************
86 
87   Synopsis    [Allocates a vector with the given capacity.]
88 
89   Description []
90 
91   SideEffects []
92 
93   SeeAlso     []
94 
95 ***********************************************************************/
Vec_AttAlloc(int nSize,void * pMan,void (* pFuncFreeMan)(void *),void * (* pFuncStartObj)(void *),void (* pFuncFreeObj)(void *,void *))96 static 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 
115 /**Function*************************************************************
116 
117   Synopsis    [Frees the vector.]
118 
119   Description []
120 
121   SideEffects []
122 
123   SeeAlso     []
124 
125 ***********************************************************************/
Vec_AttFree(Vec_Att_t * p,int fFreeMan)126 static 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 
148 /**Function*************************************************************
149 
150   Synopsis    [Clears the vector.]
151 
152   Description []
153 
154   SideEffects []
155 
156   SeeAlso     []
157 
158 ***********************************************************************/
Vec_AttClear(Vec_Att_t * p)159 static 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 
173 /**Function*************************************************************
174 
175   Synopsis    [Deletes one entry from the attribute manager.]
176 
177   Description []
178 
179   SideEffects []
180 
181   SeeAlso     []
182 
183 ***********************************************************************/
Vec_AttFreeEntry(Vec_Att_t * p,int i)184 static 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 
196 /**Function*************************************************************
197 
198   Synopsis    [Resizes the vector to the given capacity.]
199 
200   Description []
201 
202   SideEffects []
203 
204   SeeAlso     []
205 
206 ***********************************************************************/
Vec_AttGrow(Vec_Att_t * p,int nCapMin)207 static 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 
216 /**Function*************************************************************
217 
218   Synopsis    [Writes the entry into its place.]
219 
220   Description [Only works if the manager is not defined.]
221 
222   SideEffects []
223 
224   SeeAlso     []
225 
226 ***********************************************************************/
Vec_AttWriteEntry(Vec_Att_t * p,int i,void * pEntry)227 static 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 
236 /**Function*************************************************************
237 
238   Synopsis    [Returns the entry.]
239 
240   Description []
241 
242   SideEffects []
243 
244   SeeAlso     []
245 
246 ***********************************************************************/
Vec_AttEntry(Vec_Att_t * p,int i)247 static 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 
257 /**Function*************************************************************
258 
259   Synopsis    [Returns the entry.]
260 
261   Description []
262 
263   SideEffects []
264 
265   SeeAlso     []
266 
267 ***********************************************************************/
Vec_AttMan(Vec_Att_t * p)268 static inline void * Vec_AttMan( Vec_Att_t * p )
269 {
270     return p->pMan;
271 }
272 
273 /**Function*************************************************************
274 
275   Synopsis    [Returns the array of attributes.]
276 
277   Description []
278 
279   SideEffects []
280 
281   SeeAlso     []
282 
283 ***********************************************************************/
Vec_AttArray(Vec_Att_t * p)284 static inline void ** Vec_AttArray( Vec_Att_t * p )
285 {
286     return p->pArrayPtr;
287 }
288 
289 
290 
291 ABC_NAMESPACE_HEADER_END
292 
293 #endif
294 
295 ////////////////////////////////////////////////////////////////////////
296 ///                       END OF FILE                                ///
297 ////////////////////////////////////////////////////////////////////////
298 
299