Add "stream_name()" helper function, and use it.
[smatch.git] / allocate.h
blobe75323c4dfc50be28b5d3e8e5bfd1e96667d325a
1 #ifndef ALLOCATE_H
2 #define ALLOCATE_H
4 struct allocation_blob {
5 struct allocation_blob *next;
6 unsigned int left, offset;
7 unsigned char data[];
8 };
10 struct allocator_struct {
11 const char *name;
12 struct allocation_blob *blobs;
13 unsigned int alignment;
14 unsigned int chunking;
15 void *freelist;
16 /* statistics */
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 = { \
34 .name = objname, \
35 .alignment = objalign, \
36 .chunking = CHUNK }; \
37 type *__alloc_##x(int extra) \
38 { \
39 return allocate(&x##_allocator, objsize+extra); \
40 } \
41 void __free_##x(type *entry) \
42 { \
43 return free_one_entry(&x##_allocator, entry); \
44 } \
45 void show_##x##_alloc(void) \
46 { \
47 show_allocations(&x##_allocator); \
48 } \
49 void clear_##x##_alloc(void) \
50 { \
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);
71 #endif