abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
attr.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [attr.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network attributes.]
8 
9  Synopsis [External declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: attr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__aig__ivy__attr_h
22 #define ABC__aig__ivy__attr_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// INCLUDES ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 #include "misc/extra/extra.h"
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// PARAMETERS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 
36 
38 
39 
40 ////////////////////////////////////////////////////////////////////////
41 /// BASIC TYPES ///
42 ////////////////////////////////////////////////////////////////////////
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 
64 ////////////////////////////////////////////////////////////////////////
65 /// MACRO DEFINITIONS ///
66 ////////////////////////////////////////////////////////////////////////
67 
68 ////////////////////////////////////////////////////////////////////////
69 /// FUNCTION DECLARATIONS ///
70 ////////////////////////////////////////////////////////////////////////
71 
72 /**Function*************************************************************
73 
74  Synopsis [Allocates the attribute manager.]
75 
76  Description [The manager is simple if it does not need memory manager.]
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
83 static 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 
94 /**Function*************************************************************
95 
96  Synopsis [Start the attribute manager for integers.]
97 
98  Description []
99 
100  SideEffects []
101 
102  SeeAlso []
103 
104 ***********************************************************************/
105 static 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 
116 /**Function*************************************************************
117 
118  Synopsis [Start the attribute manager for pointers.]
119 
120  Description []
121 
122  SideEffects []
123 
124  SeeAlso []
125 
126 ***********************************************************************/
127 static 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 
137 /**Function*************************************************************
138 
139  Synopsis [Start the attribute manager for the fixed entry size.]
140 
141  Description []
142 
143  SideEffects []
144 
145  SeeAlso []
146 
147 ***********************************************************************/
148 static 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 
163 /**Function*************************************************************
164 
165  Synopsis [Stop the attribute manager.]
166 
167  Description []
168 
169  SideEffects []
170 
171  SeeAlso []
172 
173 ***********************************************************************/
174 static 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 
204 /**Function*************************************************************
205 
206  Synopsis [Reads the attribute of the given object.]
207 
208  Description []
209 
210  SideEffects []
211 
212  SeeAlso []
213 
214 ***********************************************************************/
215 static 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 
223 /**Function*************************************************************
224 
225  Synopsis [Reads the attribute of the given object.]
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
234 static 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 
242 /**Function*************************************************************
243 
244  Synopsis [Writes the attribute of the given object.]
245 
246  Description []
247 
248  SideEffects []
249 
250  SeeAlso []
251 
252 ***********************************************************************/
253 static 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 
259 /**Function*************************************************************
260 
261  Synopsis [Writes the attribute of the given object.]
262 
263  Description []
264 
265  SideEffects []
266 
267  SeeAlso []
268 
269 ***********************************************************************/
270 static 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 
277 /**Function*************************************************************
278 
279  Synopsis [Returns or creates the pointer to the attribute of the given object.]
280 
281  Description []
282 
283  SideEffects []
284 
285  SeeAlso []
286 
287 ***********************************************************************/
288 static 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 
305 /**Function*************************************************************
306 
307  Synopsis [Returns or creates the pointer to the attribute of the given object.]
308 
309  Description []
310 
311  SideEffects []
312 
313  SeeAlso []
314 
315 ***********************************************************************/
316 static 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 
340 /**Function*************************************************************
341 
342  Synopsis [Returns or creates the attribute of the given object.]
343 
344  Description []
345 
346  SideEffects []
347 
348  SeeAlso []
349 
350 ***********************************************************************/
351 static inline int Attr_ManFetchAttrInt( Attr_Man_t * p, int Id )
352 {
353  return *Attr_ManFetchSpotInt( p, Id );
354 }
355 
356 /**Function*************************************************************
357 
358  Synopsis [Returns or creates the attribute of the given object.]
359 
360  Description []
361 
362  SideEffects []
363 
364  SeeAlso []
365 
366 ***********************************************************************/
367 static inline void * Attr_ManFetchAttrPtr( Attr_Man_t * p, int Id )
368 {
369  return *Attr_ManFetchSpotPtr( p, Id );
370 }
371 
372 /**Function*************************************************************
373 
374  Synopsis [Sets the attribute of the given object.]
375 
376  Description []
377 
378  SideEffects []
379 
380  SeeAlso []
381 
382 ***********************************************************************/
383 static inline void Attr_ManSetAttrInt( Attr_Man_t * p, int Id, int Attr )
384 {
385  *Attr_ManFetchSpotInt( p, Id ) = Attr;
386 }
387 
388 /**Function*************************************************************
389 
390  Synopsis [Sets the attribute of the given object.]
391 
392  Description []
393 
394  SideEffects []
395 
396  SeeAlso []
397 
398 ***********************************************************************/
399 static 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 
415 ////////////////////////////////////////////////////////////////////////
416 /// END OF FILE ///
417 ////////////////////////////////////////////////////////////////////////
418 
char * memset()
VOID_HACK free()
static void Attr_ManWriteAttrPtr(Attr_Man_t *p, int Id, void *pAttr)
Definition: attr.h:270
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Attr_ManSetAttrPtr(Attr_Man_t *p, int Id, void *pAttr)
Definition: attr.h:399
static Attr_Man_t * Attr_ManStartPtrMem(int nAttrs, int nAttrSize)
Definition: attr.h:148
void Extra_MmFixedStop(Extra_MmFixed_t *p)
void ** pAttrs
Definition: attr.h:51
static void * Attr_ManFetchAttrPtr(Attr_Man_t *p, int Id)
Definition: attr.h:367
int nAttrSize
Definition: attr.h:48
static Attr_Man_t * Attr_ManAlloc(int nAttrSize, int fManMem)
MACRO DEFINITIONS ///.
Definition: attr.h:83
static void ** Attr_ManFetchSpotPtr(Attr_Man_t *p, int Id)
Definition: attr.h:316
char * realloc()
typedefABC_NAMESPACE_HEADER_START struct Attr_ManStruct_t_ Attr_Man_t
INCLUDES ///.
Definition: attr.h:44
static int Attr_ManReadAttrInt(Attr_Man_t *p, int Id)
Definition: attr.h:215
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
static void Attr_ManStop(Attr_Man_t *p)
Definition: attr.h:174
static Attr_Man_t * Attr_ManStartInt(int nAttrs)
Definition: attr.h:105
static void Attr_ManSetAttrInt(Attr_Man_t *p, int Id, int Attr)
Definition: attr.h:383
#define ALLOC(type, num)
Definition: avl.h:27
void(* pFuncFreeMan)(void *)
Definition: attr.h:55
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
static void Attr_ManWriteAttrInt(Attr_Man_t *p, int Id, int Attr)
Definition: attr.h:253
#define FREE(obj)
Definition: avl.h:31
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
void(* pFuncFreeObj)(void *, void *)
Definition: attr.h:56
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static int * Attr_ManFetchSpotInt(Attr_Man_t *p, int Id)
Definition: attr.h:288
void * pManAttr
Definition: attr.h:54
static int Attr_ManFetchAttrInt(Attr_Man_t *p, int Id)
Definition: attr.h:351
#define assert(ex)
Definition: util_old.h:213
static void * Attr_ManReadAttrPtr(Attr_Man_t *p, int Id)
Definition: attr.h:234
Extra_MmFixed_t * pManMem
Definition: attr.h:49
static Attr_Man_t * Attr_ManStartPtr(int nAttrs)
Definition: attr.h:127