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