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 int allocations
, total_bytes
, useful_bytes
;
20 extern void drop_all_allocations(struct allocator_struct
*desc
);
21 extern void *allocate(struct allocator_struct
*desc
, unsigned int size
);
22 extern void free_one_entry(struct allocator_struct
*desc
, void *entry
);
23 extern void show_allocations(struct allocator_struct
*);
25 #define __DECLARE_ALLOCATOR(type, x) \
26 extern type *__alloc_##x(int); \
27 extern void __free_##x(type *); \
28 extern void show_##x##_alloc(void); \
29 extern void clear_##x##_alloc(void);
30 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
32 #define __ALLOCATOR(type, objsize, objalign, objname, x) \
33 struct allocator_struct x##_allocator = { \
35 .alignment = objalign, \
36 .chunking = CHUNK }; \
37 type *__alloc_##x(int extra) \
39 return allocate(&x##_allocator, objsize+extra); \
41 void __free_##x(type *entry) \
43 return free_one_entry(&x##_allocator, entry); \
45 void show_##x##_alloc(void) \
47 show_allocations(&x##_allocator); \
49 void clear_##x##_alloc(void) \
51 drop_all_allocations(&x##_allocator); \
54 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, sizeof(struct x), __alignof__(struct x), n, x)
56 DECLARE_ALLOCATOR(ident
);
57 DECLARE_ALLOCATOR(token
);
58 DECLARE_ALLOCATOR(symbol
);
59 DECLARE_ALLOCATOR(expression
);
60 DECLARE_ALLOCATOR(statement
);
61 DECLARE_ALLOCATOR(string
);
62 DECLARE_ALLOCATOR(scope
);
63 __DECLARE_ALLOCATOR(void, bytes
);
64 DECLARE_ALLOCATOR(basic_block
);
65 DECLARE_ALLOCATOR(entrypoint
);
66 DECLARE_ALLOCATOR(instruction
);
67 DECLARE_ALLOCATOR(multijmp
);
68 DECLARE_ALLOCATOR(phi
);
69 DECLARE_ALLOCATOR(pseudo
);