Fix the segfault when initializer has unknown symbol
[smatch.git] / allocate.h
blob33703fe274f6a00ac3ce75340fb5dc3f60f0cbd5
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 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 = { \
36 .name = objname, \
37 .alignment = objalign, \
38 .chunking = CHUNK }; \
39 type *__alloc_##x(int extra) \
40 { \
41 return allocate(&x##_allocator, objsize+extra); \
42 } \
43 void __free_##x(type *entry) \
44 { \
45 return free_one_entry(&x##_allocator, entry); \
46 } \
47 void show_##x##_alloc(void) \
48 { \
49 show_allocations(&x##_allocator); \
50 } \
51 void clear_##x##_alloc(void) \
52 { \
53 drop_all_allocations(&x##_allocator); \
54 } \
55 void protect_##x##_alloc(void) \
56 { \
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(context);
65 DECLARE_ALLOCATOR(symbol);
66 DECLARE_ALLOCATOR(expression);
67 DECLARE_ALLOCATOR(statement);
68 DECLARE_ALLOCATOR(string);
69 DECLARE_ALLOCATOR(scope);
70 __DECLARE_ALLOCATOR(void, bytes);
71 DECLARE_ALLOCATOR(basic_block);
72 DECLARE_ALLOCATOR(entrypoint);
73 DECLARE_ALLOCATOR(instruction);
74 DECLARE_ALLOCATOR(multijmp);
75 DECLARE_ALLOCATOR(phi);
76 DECLARE_ALLOCATOR(pseudo);
78 #endif