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 __DO_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(t, n, x) \
61 __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x)
63 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, n, x)
65 DECLARE_ALLOCATOR(ident
);
66 DECLARE_ALLOCATOR(token
);
67 DECLARE_ALLOCATOR(context
);
68 DECLARE_ALLOCATOR(symbol
);
69 DECLARE_ALLOCATOR(expression
);
70 DECLARE_ALLOCATOR(statement
);
71 DECLARE_ALLOCATOR(string
);
72 DECLARE_ALLOCATOR(scope
);
73 __DECLARE_ALLOCATOR(void, bytes
);
74 DECLARE_ALLOCATOR(basic_block
);
75 DECLARE_ALLOCATOR(entrypoint
);
76 DECLARE_ALLOCATOR(instruction
);
77 DECLARE_ALLOCATOR(multijmp
);
78 DECLARE_ALLOCATOR(phi
);
79 DECLARE_ALLOCATOR(pseudo
);