4 struct allocation_blob
{
5 struct allocation_blob
*next
;
6 unsigned int left
, offset
;
10 struct allocator_struct
{
12 struct allocation_blob
*blobs
;
13 unsigned int alignment
;
14 unsigned int chunking
;
17 unsigned long allocations
, total_bytes
, useful_bytes
;
20 struct allocator_stats
{
22 unsigned int allocations
;
23 unsigned long total_bytes
, useful_bytes
;
26 extern void protect_allocations(struct allocator_struct
*desc
);
27 extern void drop_all_allocations(struct allocator_struct
*desc
);
28 extern void *allocate(struct allocator_struct
*desc
, unsigned int size
);
29 extern void free_one_entry(struct allocator_struct
*desc
, void *entry
);
30 extern void show_allocations(struct allocator_struct
*);
31 extern void get_allocator_stats(struct allocator_struct
*, struct allocator_stats
*);
32 extern void show_allocation_stats(void);
34 #define __DECLARE_ALLOCATOR(type, x) \
35 extern type *__alloc_##x(int); \
36 extern void __free_##x(type *); \
37 extern void show_##x##_alloc(void); \
38 extern void get_##x##_stats(struct allocator_stats *); \
39 extern void clear_##x##_alloc(void); \
40 extern void protect_##x##_alloc(void);
41 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
43 #define __DO_ALLOCATOR(type, objsize, objalign, objname, x) \
44 static struct allocator_struct x##_allocator = { \
46 .alignment = objalign, \
47 .chunking = CHUNK }; \
48 type *__alloc_##x(int extra) \
50 return allocate(&x##_allocator, objsize+extra); \
52 void __free_##x(type *entry) \
54 free_one_entry(&x##_allocator, entry); \
56 void show_##x##_alloc(void) \
58 show_allocations(&x##_allocator); \
60 void get_##x##_stats(struct allocator_stats *s) \
62 get_allocator_stats(&x##_allocator, s); \
64 void clear_##x##_alloc(void) \
66 drop_all_allocations(&x##_allocator); \
68 void protect_##x##_alloc(void) \
70 protect_allocations(&x##_allocator); \
73 #define __ALLOCATOR(t, n, x) \
74 __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x)
76 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, n, x)
78 DECLARE_ALLOCATOR(ident
);
79 DECLARE_ALLOCATOR(token
);
80 DECLARE_ALLOCATOR(context
);
81 DECLARE_ALLOCATOR(symbol
);
82 DECLARE_ALLOCATOR(expression
);
83 DECLARE_ALLOCATOR(statement
);
84 DECLARE_ALLOCATOR(string
);
85 DECLARE_ALLOCATOR(scope
);
86 __DECLARE_ALLOCATOR(void, bytes
);
87 DECLARE_ALLOCATOR(basic_block
);
88 DECLARE_ALLOCATOR(entrypoint
);
89 DECLARE_ALLOCATOR(instruction
);
90 DECLARE_ALLOCATOR(multijmp
);
91 DECLARE_ALLOCATOR(pseudo
);
92 DECLARE_ALLOCATOR(attribute
);