param_limit: update a comment
[smatch.git] / allocate.h
blobd78677c88ddc972f5b6d16ad757045b626d26215
1 #ifndef ALLOCATE_H
2 #define ALLOCATE_H
4 #include "compat.h"
6 struct allocation_blob {
7 struct allocation_blob *next;
8 unsigned int left, offset;
9 unsigned char data[];
12 struct allocator_struct {
13 const char *name;
14 struct allocation_blob *blobs;
15 unsigned int alignment;
16 unsigned int chunking;
17 void *freelist;
18 /* statistics */
19 unsigned long allocations, total_bytes, useful_bytes;
22 struct allocator_stats {
23 const char *name;
24 unsigned int allocations;
25 unsigned long total_bytes, useful_bytes;
28 extern void protect_allocations(struct allocator_struct *desc);
29 extern void drop_all_allocations(struct allocator_struct *desc);
30 extern void *allocate(struct allocator_struct *desc, unsigned int size);
31 extern void free_one_entry(struct allocator_struct *desc, void *entry);
32 extern void show_allocations(struct allocator_struct *);
33 extern void get_allocator_stats(struct allocator_struct *, struct allocator_stats *);
34 extern void show_allocation_stats(void);
36 #define __DECLARE_ALLOCATOR(type, x) \
37 extern type *__alloc_##x(int); \
38 extern void __free_##x(type *); \
39 extern void show_##x##_alloc(void); \
40 extern void get_##x##_stats(struct allocator_stats *); \
41 extern void clear_##x##_alloc(void); \
42 extern void protect_##x##_alloc(void);
43 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
45 #define __DO_ALLOCATOR(type, objsize, objalign, objname, x) \
46 static struct allocator_struct x##_allocator = { \
47 .name = objname, \
48 .alignment = objalign, \
49 .chunking = CHUNK }; \
50 type *__alloc_##x(int extra) \
51 { \
52 return allocate(&x##_allocator, objsize+extra); \
53 } \
54 void __free_##x(type *entry) \
55 { \
56 free_one_entry(&x##_allocator, entry); \
57 } \
58 void show_##x##_alloc(void) \
59 { \
60 show_allocations(&x##_allocator); \
61 } \
62 void get_##x##_stats(struct allocator_stats *s) \
63 { \
64 get_allocator_stats(&x##_allocator, s); \
65 } \
66 void clear_##x##_alloc(void) \
67 { \
68 drop_all_allocations(&x##_allocator); \
69 } \
70 void protect_##x##_alloc(void) \
71 { \
72 protect_allocations(&x##_allocator); \
75 #define __ALLOCATOR(t, n, x) \
76 __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x)
78 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, n, x)
80 DECLARE_ALLOCATOR(ident);
81 DECLARE_ALLOCATOR(token);
82 DECLARE_ALLOCATOR(context);
83 DECLARE_ALLOCATOR(symbol);
84 DECLARE_ALLOCATOR(asm_operand);
85 DECLARE_ALLOCATOR(expression);
86 DECLARE_ALLOCATOR(statement);
87 DECLARE_ALLOCATOR(string);
88 DECLARE_ALLOCATOR(scope);
89 __DECLARE_ALLOCATOR(void, bytes);
90 DECLARE_ALLOCATOR(basic_block);
91 DECLARE_ALLOCATOR(entrypoint);
92 DECLARE_ALLOCATOR(instruction);
93 DECLARE_ALLOCATOR(multijmp);
94 DECLARE_ALLOCATOR(pseudo);
95 DECLARE_ALLOCATOR(attribute);
97 #endif