00001
00021 #ifndef __Vec_Att_H__
00022 #define __Vec_Att_H__
00023
00027
00028 #include <stdio.h>
00029
00033
00034
00035 typedef enum {
00036 VEC_ATTR_NONE = 0,
00037 VEC_ATTR_COPY,
00038 VEC_ATTR_LOCAL_AIG,
00039 VEC_ATTR_LOCAL_SOP,
00040 VEC_ATTR_LOCAL_BDD,
00041 VEC_ATTR_GLOBAL_AIG,
00042 VEC_ATTR_GLOBAL_SOP,
00043 VEC_ATTR_GLOBAL_BDD,
00044 VEC_ATTR_LEVEL,
00045 VEC_ATTR_LEVEL_REV,
00046 VEC_ATTR_RETIME_LAG,
00047 VEC_ATTR_FRAIG,
00048 VEC_ATTR_MVVAR,
00049 VEC_ATTR_DATA1,
00050 VEC_ATTR_DATA2,
00051 VEC_ATTR_TOTAL_NUM
00052 } Vec_AttrType_t;
00053
00057
00058 typedef struct Vec_Att_t_ Vec_Att_t;
00059 struct Vec_Att_t_
00060 {
00061
00062 int nCap;
00063 int * pArrayInt;
00064 void ** pArrayPtr;
00065
00066 void * pMan;
00067 void (*pFuncFreeMan) (void *);
00068 void*(*pFuncStartObj)(void *);
00069 void (*pFuncFreeObj) (void *, void *);
00070 };
00071
00075
00079
00091 static inline Vec_Att_t * Vec_AttAlloc(
00092 int fInteger, int nSize, void * pMan,
00093 void (*pFuncFreeMan) (void *),
00094 void*(*pFuncStartObj)(void *),
00095 void (*pFuncFreeObj) (void *, void *) )
00096 {
00097 Vec_Att_t * p;
00098 p = ALLOC( Vec_Att_t, 1 );
00099 memset( p, 0, sizeof(Vec_Att_t) );
00100 p->pMan = pMan;
00101 p->pFuncFreeMan = pFuncFreeMan;
00102 p->pFuncStartObj = pFuncStartObj;
00103 p->pFuncFreeObj = pFuncFreeObj;
00104 p->nCap = nSize? nSize : 16;
00105 if ( fInteger )
00106 {
00107 p->pArrayInt = ALLOC( int, p->nCap );
00108 memset( p->pArrayInt, 0xff, sizeof(int) * p->nCap );
00109 }
00110 else
00111 {
00112 p->pArrayPtr = ALLOC( void *, p->nCap );
00113 memset( p->pArrayPtr, 0, sizeof(void *) * p->nCap );
00114 }
00115 return p;
00116 }
00117
00129 static inline void * Vec_AttFree( Vec_Att_t * p, int fFreeMan )
00130 {
00131 void * pMan;
00132 if ( p == NULL )
00133 return NULL;
00134
00135 if ( p->pFuncFreeObj )
00136 {
00137 int i;
00138 if ( p->pArrayInt )
00139 {
00140 for ( i = 0; i < p->nCap; i++ )
00141 if ( p->pArrayInt[i] )
00142 p->pFuncFreeObj( p->pMan, (void *)p->pArrayInt[i] );
00143 }
00144 else
00145 {
00146 for ( i = 0; i < p->nCap; i++ )
00147 if ( p->pArrayPtr[i] )
00148 p->pFuncFreeObj( p->pMan, p->pArrayPtr[i] );
00149 }
00150 }
00151
00152 pMan = fFreeMan? NULL : p->pMan;
00153 if ( p->pMan && fFreeMan )
00154 p->pFuncFreeMan( p->pMan );
00155 FREE( p->pArrayInt );
00156 FREE( p->pArrayPtr );
00157 FREE( p );
00158 return pMan;
00159 }
00160
00172 static inline void Vec_AttClear( Vec_Att_t * p )
00173 {
00174
00175 if ( p->pFuncFreeObj )
00176 {
00177 int i;
00178 if ( p->pArrayInt )
00179 {
00180 if ( p->pFuncFreeObj )
00181 for ( i = 0; i < p->nCap; i++ )
00182 if ( p->pArrayInt[i] )
00183 p->pFuncFreeObj( p->pMan, (void *)p->pArrayInt[i] );
00184 }
00185 else
00186 {
00187 if ( p->pFuncFreeObj )
00188 for ( i = 0; i < p->nCap; i++ )
00189 if ( p->pArrayPtr[i] )
00190 p->pFuncFreeObj( p->pMan, p->pArrayPtr[i] );
00191 }
00192 }
00193 if ( p->pArrayInt )
00194 memset( p->pArrayInt, 0xff, sizeof(int) * p->nCap );
00195 else
00196 memset( p->pArrayPtr, 0, sizeof(void *) * p->nCap );
00197
00198 }
00199
00211 static inline void Vec_AttFreeEntry( Vec_Att_t * p, int i )
00212 {
00213 if ( i >= p->nCap )
00214 return;
00215 if ( p->pMan )
00216 {
00217 if ( p->pArrayInt[i] && p->pFuncFreeObj )
00218 p->pFuncFreeObj( p->pMan, (void *)p->pArrayInt[i] );
00219 if ( p->pArrayPtr[i] && p->pFuncFreeObj )
00220 p->pFuncFreeObj( p->pMan, (void *)p->pArrayPtr[i] );
00221 }
00222 if ( p->pArrayInt )
00223 p->pArrayInt[i] = ~(unsigned)0;
00224 else
00225 p->pArrayPtr[i] = NULL;
00226 }
00227
00239 static inline void Vec_AttGrow( Vec_Att_t * p, int nCapMin )
00240 {
00241 if ( p->nCap >= nCapMin )
00242 return;
00243 if ( p->pArrayInt )
00244 {
00245 p->pArrayInt = REALLOC( int, p->pArrayInt, nCapMin );
00246 memset( p->pArrayInt + p->nCap, 0xff, sizeof(int) * (nCapMin - p->nCap) );
00247 }
00248 else
00249 {
00250 p->pArrayPtr = REALLOC( void *, p->pArrayPtr, nCapMin );
00251 memset( p->pArrayPtr + p->nCap, 0, sizeof(void *) * (nCapMin - p->nCap) );
00252 }
00253 p->nCap = nCapMin;
00254 }
00255
00267 static inline void Vec_AttWriteEntry( Vec_Att_t * p, int i, void * pEntry )
00268 {
00269 assert( p->pArrayPtr );
00270 assert( p->pFuncStartObj == NULL );
00271 if ( i >= p->nCap )
00272 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
00273 p->pArrayPtr[i] = pEntry;
00274 }
00275
00287 static inline void Vec_AttWriteEntryInt( Vec_Att_t * p, int i, int Entry )
00288 {
00289 assert( p->pArrayInt );
00290 assert( p->pFuncStartObj == NULL );
00291 if ( i >= p->nCap )
00292 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
00293 p->pArrayInt[i] = Entry;
00294 }
00295
00307 static inline void * Vec_AttEntry( Vec_Att_t * p, int i )
00308 {
00309 assert( p->pArrayPtr );
00310 if ( i >= p->nCap )
00311 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
00312 if ( p->pArrayPtr[i] == NULL && p->pFuncStartObj )
00313 p->pArrayPtr[i] = p->pFuncStartObj( p->pMan );
00314 return p->pArrayPtr[i];
00315 }
00316
00328 static inline int Vec_AttEntryInt( Vec_Att_t * p, int i )
00329 {
00330 assert( p->pArrayInt );
00331 assert( p->pMan == NULL );
00332 if ( i >= p->nCap )
00333 Vec_AttGrow( p, (2 * p->nCap > i)? 2 * p->nCap : i + 10 );
00334 return p->pArrayInt[i];
00335 }
00336
00348 static inline void * Vec_AttMan( Vec_Att_t * p )
00349 {
00350 return p->pMan;
00351 }
00352
00364 static inline void ** Vec_AttArray( Vec_Att_t * p )
00365 {
00366 return p->pArrayPtr;
00367 }
00368
00380 static inline int * Vec_AttArrayInt( Vec_Att_t * p )
00381 {
00382 return p->pArrayInt;
00383 }
00384
00385 #endif
00386
00387
00391