signed: unsigned variables are allowed to do math with negatives
[smatch.git] / allocate.h
blob9f1dc8cc44252b49ab5c6bf6e0dc77781fa178f8
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 __DO_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 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(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);
81 #endif