4 * Basic helper routine descriptions for 'sparse'.
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
12 extern unsigned int hexval(unsigned int c
);
28 struct statement_list
;
30 struct expression_list
;
35 struct token
*skip_to(struct token
*, int);
36 struct token
*expect(struct token
*, int, const char *);
37 extern void warn(struct position
, const char *, ...);
38 extern void error(struct position
, const char *, ...);
40 #define __DECLARE_ALLOCATOR(type, x) \
41 extern type *__alloc_##x(int); \
42 extern void show_##x##_alloc(void); \
43 extern void clear_##x##_alloc(void);
44 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
46 DECLARE_ALLOCATOR(ident
);
47 DECLARE_ALLOCATOR(token
);
48 DECLARE_ALLOCATOR(symbol
);
49 DECLARE_ALLOCATOR(expression
);
50 DECLARE_ALLOCATOR(statement
);
51 DECLARE_ALLOCATOR(string
);
52 DECLARE_ALLOCATOR(scope
);
53 __DECLARE_ALLOCATOR(void, bytes
);
54 DECLARE_ALLOCATOR(basic_block
);
55 DECLARE_ALLOCATOR(entrypoint
);
56 DECLARE_ALLOCATOR(instruction
);
59 #define LIST_NODE_NR (29)
63 struct ptr_list
*prev
;
64 struct ptr_list
*next
;
65 void *list
[LIST_NODE_NR
];
68 #define ITERATE_FIRST 1
69 #define ITERATE_LAST 2
71 #define ptr_list_empty(x) ((x) == NULL)
73 void iterate(struct ptr_list
*,void (*callback
)(void *, void *, int), void*);
74 extern void add_ptr_list(struct ptr_list
**, void *);
75 extern void concat_ptr_list(struct ptr_list
*a
, struct ptr_list
**b
);
76 extern void free_ptr_list(struct ptr_list
**);
77 extern int ptr_list_size(struct ptr_list
*);
78 extern char **handle_switch(char *arg
, char **next
);
79 extern void add_pre_buffer(const char *fmt
, ...);
81 extern unsigned int pre_buffer_size
;
82 extern unsigned char pre_buffer
[8192];
83 extern int include_fd
;
85 extern int preprocess_only
;
87 extern void create_builtin_stream(void);
89 #define symbol_list_size(list) ptr_list_size((struct ptr_list *)(list))
90 #define statement_list_size(list) ptr_list_size((struct ptr_list *)(list))
91 #define expression_list_size(list) ptr_list_size((struct ptr_list *)(list))
93 static inline void concat_symbol_list(struct symbol_list
*from
, struct symbol_list
**to
)
95 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
98 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
100 add_ptr_list((struct ptr_list
**)list
, sym
);
103 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
105 add_ptr_list((struct ptr_list
**)list
, stmt
);
108 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
110 add_ptr_list((struct ptr_list
**)list
, expr
);
113 static inline void symbol_iterate(struct symbol_list
*list
, void (*callback
)(struct symbol
*, void *, int), void *data
)
115 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
118 static inline void statement_iterate(struct statement_list
*list
, void (*callback
)(struct statement
*, void *, int), void *data
)
120 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
123 static inline void expression_iterate(struct expression_list
*list
, void (*callback
)(struct expression
*, void *, int), void *data
)
125 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
128 #define PREPARE_PTR_LIST(head, ptr) \
130 struct ptr_list *__head##ptr = (struct ptr_list *) (head); \
131 struct ptr_list *__list##ptr = __head##ptr; \
133 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
136 #define NEXT_PTR_LIST(ptr) \
138 if (++__nr##ptr < __list##ptr->nr) { \
139 ptr = (__typeof__(ptr)) __list##ptr->list[__nr##ptr]; \
141 __list##ptr = __list##ptr->next; \
143 if (__list##ptr != __head##ptr) { \
145 ptr = (__typeof__(ptr)) __list##ptr->list[0]; \
150 #define RESET_PTR_LIST(ptr) do { \
152 __list##ptr = __head##ptr; \
153 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
157 #define FINISH_PTR_LIST(ptr) \
158 (void)(__nr##ptr); /* Sanity-check nesting */ \
161 #define FOR_EACH_PTR(head, ptr) do { \
162 struct ptr_list *__head = (struct ptr_list *) (head); \
163 struct ptr_list *__list = __head; \
164 int __flag = ITERATE_FIRST; \
167 for (__i = 0; __i < __list->nr; __i++) { \
168 if (__i == __list->nr-1 && __list->next == __head) \
169 __flag |= ITERATE_LAST; \
171 ptr = (__typeof__(ptr)) (__list->list[__i]); \
174 #define END_FOR_EACH_PTR } while (0); \
178 } while ((__list = __list->next) != __head); \
182 #define FOR_EACH_PTR_REVERSE(head, ptr) do { \
183 struct ptr_list *__head = (struct ptr_list *) (head); \
184 struct ptr_list *__list = __head; \
185 int __flag = ITERATE_FIRST; \
188 __list = __list->prev; \
190 while (--__i >= 0) { \
191 if (__i == 0 && __list == __head) \
192 __flag |= ITERATE_LAST; \
194 ptr = (__typeof__(ptr)) (__list->list[__i]); \
197 #define END_FOR_EACH_PTR_REVERSE } while (0); \
201 } while (__list != __head); \
205 #define THIS_ADDRESS(x) \
206 ((__typeof__(&(x))) (__list->list + __i))