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 protect_allocations(struct allocator_struct
*desc
);
21 extern void drop_all_allocations(struct allocator_struct
*desc
);
22 extern void *allocate(struct allocator_struct
*desc
, unsigned int size
);
23 extern void free_one_entry(struct allocator_struct
*desc
, void *entry
);
24 extern void show_allocations(struct allocator_struct
*);
26 #define __DECLARE_ALLOCATOR(type, x) \
27 extern type *__alloc_##x(int); \
28 extern void __free_##x(type *); \
29 extern void show_##x##_alloc(void); \
30 extern void clear_##x##_alloc(void); \
31 extern void protect_##x##_alloc(void);
32 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
34 #define __ALLOCATOR(type, objsize, objalign, objname, x) \
35 static struct allocator_struct x##_allocator = { \
37 .alignment = objalign, \
38 .chunking = CHUNK }; \
39 type *__alloc_##x(int extra) \
41 return allocate(&x##_allocator, objsize+extra); \
43 void __free_##x(type *entry) \
45 return free_one_entry(&x##_allocator, entry); \
47 void show_##x##_alloc(void) \
49 show_allocations(&x##_allocator); \
51 void clear_##x##_alloc(void) \
53 drop_all_allocations(&x##_allocator); \
55 void protect_##x##_alloc(void) \
57 protect_allocations(&x##_allocator); \
60 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, sizeof(struct x), __alignof__(struct x), n, x)
62 DECLARE_ALLOCATOR(ident
);
63 DECLARE_ALLOCATOR(token
);
64 DECLARE_ALLOCATOR(symbol
);
65 DECLARE_ALLOCATOR(expression
);
66 DECLARE_ALLOCATOR(statement
);
67 DECLARE_ALLOCATOR(string
);
68 DECLARE_ALLOCATOR(scope
);
69 __DECLARE_ALLOCATOR(void, bytes
);
70 DECLARE_ALLOCATOR(basic_block
);
71 DECLARE_ALLOCATOR(entrypoint
);
72 DECLARE_ALLOCATOR(instruction
);
73 DECLARE_ALLOCATOR(multijmp
);
74 DECLARE_ALLOCATOR(phi
);
75 DECLARE_ALLOCATOR(pseudo
);