[PATCH] fix sparse warnings
[smatch.git] / allocate.h
blobab6bd0a76c05a025c494e98c7c39b0be91ad814f
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(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);
77 #endif