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
;
34 struct token
*skip_to(struct token
*, int);
35 struct token
*expect(struct token
*, int, const char *);
36 extern void warn(struct position
, const char *, ...);
37 extern void error(struct position
, const char *, ...);
39 #define __DECLARE_ALLOCATOR(type, x) \
40 extern type *__alloc_##x(int); \
41 extern void show_##x##_alloc(void); \
42 extern void clear_##x##_alloc(void);
43 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
45 DECLARE_ALLOCATOR(ident
);
46 DECLARE_ALLOCATOR(token
);
47 DECLARE_ALLOCATOR(symbol
);
48 DECLARE_ALLOCATOR(expression
);
49 DECLARE_ALLOCATOR(statement
);
50 DECLARE_ALLOCATOR(string
);
51 DECLARE_ALLOCATOR(scope
);
52 __DECLARE_ALLOCATOR(void, bytes
);
53 DECLARE_ALLOCATOR(basic_block
);
54 DECLARE_ALLOCATOR(entrypoint
);
57 #define LIST_NODE_NR (29)
61 struct ptr_list
*prev
;
62 struct ptr_list
*next
;
63 void *list
[LIST_NODE_NR
];
66 #define ITERATE_FIRST 1
67 #define ITERATE_LAST 2
68 void iterate(struct ptr_list
*,void (*callback
)(void *, void *, int), void*);
69 extern void add_ptr_list(struct ptr_list
**, void *);
70 extern void concat_ptr_list(struct ptr_list
*a
, struct ptr_list
**b
);
71 extern void free_ptr_list(struct ptr_list
**);
72 extern int ptr_list_size(struct ptr_list
*);
73 extern char **handle_switch(char *arg
, char **next
);
74 extern void add_pre_buffer(const char *fmt
, ...);
76 extern unsigned int pre_buffer_size
;
77 extern unsigned char pre_buffer
[8192];
78 extern int include_fd
;
80 extern int preprocess_only
;
82 extern void create_builtin_stream(void);
84 #define symbol_list_size(list) ptr_list_size((struct ptr_list *)(list))
85 #define statement_list_size(list) ptr_list_size((struct ptr_list *)(list))
86 #define expression_list_size(list) ptr_list_size((struct ptr_list *)(list))
88 static inline void concat_symbol_list(struct symbol_list
*from
, struct symbol_list
**to
)
90 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
93 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
95 add_ptr_list((struct ptr_list
**)list
, sym
);
98 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
100 add_ptr_list((struct ptr_list
**)list
, stmt
);
103 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
105 add_ptr_list((struct ptr_list
**)list
, expr
);
108 static inline void symbol_iterate(struct symbol_list
*list
, void (*callback
)(struct symbol
*, void *, int), void *data
)
110 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
113 static inline void statement_iterate(struct statement_list
*list
, void (*callback
)(struct statement
*, void *, int), void *data
)
115 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
118 static inline void expression_iterate(struct expression_list
*list
, void (*callback
)(struct expression
*, void *, int), void *data
)
120 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
123 #define PREPARE_PTR_LIST(head, ptr) \
125 struct ptr_list *__head##ptr = (struct ptr_list *) (head); \
126 struct ptr_list *__list##ptr = __head##ptr; \
128 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
131 #define NEXT_PTR_LIST(ptr) \
133 if (++__nr##ptr < __list##ptr->nr) { \
134 ptr = (__typeof__(ptr)) __list##ptr->list[__nr##ptr]; \
136 __list##ptr = __list##ptr->next; \
138 if (__list##ptr != __head##ptr) { \
140 ptr = (__typeof__(ptr)) __list##ptr->list[0]; \
145 #define RESET_PTR_LIST(ptr) do { \
147 __list##ptr = __head##ptr; \
148 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
152 #define FINISH_PTR_LIST(ptr) \
153 (void)(__nr##ptr); /* Sanity-check nesting */ \
156 #define FOR_EACH_PTR(head, ptr) do { \
157 struct ptr_list *__head = (struct ptr_list *) (head); \
158 struct ptr_list *__list = __head; \
159 int __flag = ITERATE_FIRST; \
162 for (__i = 0; __i < __list->nr; __i++) { \
163 if (__i == __list->nr-1 && __list->next == __head) \
164 __flag |= ITERATE_LAST; \
166 ptr = (__typeof__(ptr)) (__list->list[__i]); \
169 #define END_FOR_EACH_PTR } while (0); \
173 } while ((__list = __list->next) != __head); \
177 #define FOR_EACH_PTR_REVERSE(head, ptr) do { \
178 struct ptr_list *__head = (struct ptr_list *) (head); \
179 struct ptr_list *__list = __head; \
180 int __flag = ITERATE_FIRST; \
183 __list = __list->prev; \
185 while (--__i >= 0) { \
186 if (__i == 0 && __list == __head) \
187 __flag |= ITERATE_LAST; \
189 ptr = (__typeof__(ptr)) (__list->list[__i]); \
192 #define END_FOR_EACH_PTR_REVERSE } while (0); \
196 } while (__list != __head); \
200 #define THIS_ADDRESS(x) \
201 ((__typeof__(&(x))) (__list->list + __i))