7 * Basic helper routine descriptions for 'sparse'.
9 * Copyright (C) 2003 Transmeta Corp.
13 * Licensed under the Open Software License version 1.1
18 extern unsigned int hexval(unsigned int c
);
35 struct statement_list
;
37 struct expression_list
;
39 struct basic_block_list
;
42 struct instruction_list
;
49 typedef struct pseudo
*pseudo_t
;
51 struct token
*skip_to(struct token
*, int);
52 struct token
*expect(struct token
*, int, const char *);
54 #define FORMAT_ATTR __attribute__ ((__format__ (__printf__, 2, 3)))
58 extern void info(struct position
, const char *, ...) FORMAT_ATTR
;
59 extern void warning(struct position
, const char *, ...) FORMAT_ATTR
;
60 extern void error(struct position
, const char *, ...) FORMAT_ATTR
;
61 extern void error_die(struct position
, const char *, ...) FORMAT_ATTR
;
64 #define __DECLARE_ALLOCATOR(type, x) \
65 extern type *__alloc_##x(int); \
66 extern void __free_##x(type *); \
67 extern void show_##x##_alloc(void); \
68 extern void clear_##x##_alloc(void);
69 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
71 DECLARE_ALLOCATOR(ident
);
72 DECLARE_ALLOCATOR(token
);
73 DECLARE_ALLOCATOR(symbol
);
74 DECLARE_ALLOCATOR(expression
);
75 DECLARE_ALLOCATOR(statement
);
76 DECLARE_ALLOCATOR(string
);
77 DECLARE_ALLOCATOR(scope
);
78 __DECLARE_ALLOCATOR(void, bytes
);
79 DECLARE_ALLOCATOR(basic_block
);
80 DECLARE_ALLOCATOR(entrypoint
);
81 DECLARE_ALLOCATOR(instruction
);
82 DECLARE_ALLOCATOR(multijmp
);
83 DECLARE_ALLOCATOR(phi
);
84 DECLARE_ALLOCATOR(pseudo
);
87 #define LIST_NODE_NR (29)
91 struct ptr_list
*prev
;
92 struct ptr_list
*next
;
93 void *list
[LIST_NODE_NR
];
96 #define ptr_list_empty(x) ((x) == NULL)
98 void * delete_ptr_list_last(struct ptr_list
**head
);
99 int replace_ptr_list(struct ptr_list
*head
, void *old_ptr
, void *new_ptr
);
100 extern void sort_list(struct ptr_list
**, int (*)(const void *, const void *));
102 extern void **add_ptr_list(struct ptr_list
**, void *);
103 extern void concat_ptr_list(struct ptr_list
*a
, struct ptr_list
**b
);
104 extern void free_ptr_list(struct ptr_list
**);
105 extern int ptr_list_size(struct ptr_list
*);
106 extern char **handle_switch(char *arg
, char **next
);
107 extern void add_pre_buffer(const char *fmt
, ...);
108 int linearize_ptr_list(struct ptr_list
*, void **, int);
110 extern unsigned int pre_buffer_size
;
111 extern unsigned char pre_buffer
[8192];
112 extern int include_fd
;
113 extern char *include
;
114 extern int preprocess_only
;
115 extern int Wdefault_bitfield_sign
;
116 extern int Wundefined_preprocessor
;
117 extern int Wbitwise
, Wtypesign
, Wcontext
;
119 extern void declare_builtin_functions(void);
120 extern void create_builtin_stream(void);
122 static inline int symbol_list_size(struct symbol_list
* list
)
124 return ptr_list_size((struct ptr_list
*)(list
));
127 static inline int statement_list_size(struct statement_list
* list
)
129 return ptr_list_size((struct ptr_list
*)(list
));
132 static inline int expression_list_size(struct expression_list
* list
)
134 return ptr_list_size((struct ptr_list
*)(list
));
137 static inline int instruction_list_size(struct instruction_list
* list
)
139 return ptr_list_size((struct ptr_list
*)(list
));
142 static inline int phi_list_size(struct phi_list
* list
)
144 return ptr_list_size((struct ptr_list
*)(list
));
147 static inline int bb_list_size(struct basic_block_list
* list
)
149 return ptr_list_size((struct ptr_list
*)(list
));
152 static inline void free_instruction_list(struct instruction_list
**head
)
154 free_ptr_list((struct ptr_list
**)head
);
157 static inline struct instruction
* delete_last_instruction(struct instruction_list
**head
)
159 return delete_ptr_list_last((struct ptr_list
**)head
);
162 static inline struct basic_block
* delete_last_basic_block(struct basic_block_list
**head
)
164 return delete_ptr_list_last((struct ptr_list
**)head
);
167 static inline void *first_ptr_list(struct ptr_list
*list
)
171 return list
->list
[0];
174 static inline void *last_ptr_list(struct ptr_list
*list
)
180 return list
->list
[list
->nr
-1];
183 static inline struct basic_block
*first_basic_block(struct basic_block_list
*head
)
185 return first_ptr_list((struct ptr_list
*)head
);
187 static inline struct instruction
*last_instruction(struct instruction_list
*head
)
189 return last_ptr_list((struct ptr_list
*)head
);
192 static inline struct instruction
*first_instruction(struct instruction_list
*head
)
194 return first_ptr_list((struct ptr_list
*)head
);
197 static inline struct phi
*first_phi(struct phi_list
*head
)
199 return first_ptr_list((struct ptr_list
*)head
);
202 static inline int replace_basic_block_list(struct basic_block_list
*head
, struct basic_block
*from
, struct basic_block
*to
)
204 return replace_ptr_list((struct ptr_list
*)head
, (void*)from
, (void*)to
);
207 static inline void concat_symbol_list(struct symbol_list
*from
, struct symbol_list
**to
)
209 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
212 static inline void concat_basic_block_list(struct basic_block_list
*from
, struct basic_block_list
**to
)
214 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
217 static inline void concat_instruction_list(struct instruction_list
*from
, struct instruction_list
**to
)
219 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
222 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
224 add_ptr_list((struct ptr_list
**)list
, sym
);
227 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
229 add_ptr_list((struct ptr_list
**)list
, stmt
);
232 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
234 add_ptr_list((struct ptr_list
**)list
, expr
);
237 #define DO_PREPARE(head, ptr, __head, __list, __nr) \
239 struct ptr_list *__head = (struct ptr_list *) (head); \
240 struct ptr_list *__list = __head; \
242 if (__head) ptr = (__typeof__(ptr)) __head->list[0]; \
245 #define DO_NEXT(ptr, __head, __list, __nr) \
247 if (++__nr < __list->nr) { \
248 ptr = (__typeof__(ptr)) __list->list[__nr]; \
250 __list = __list->next; \
252 if (__list != __head) { \
254 ptr = (__typeof__(ptr)) __list->list[0]; \
259 #define DO_RESET(ptr, __head, __list, __nr) \
263 if (__head) ptr = (__typeof__(ptr)) __head->list[0]; \
266 #define DO_FINISH(ptr, __head, __list, __nr) \
267 (void)(__nr); /* Sanity-check nesting */ \
270 #define PREPARE_PTR_LIST(head, ptr) \
271 DO_PREPARE(head, ptr, __head##ptr, __list##ptr, __nr##ptr)
273 #define NEXT_PTR_LIST(ptr) \
274 DO_NEXT(ptr, __head##ptr, __list##ptr, __nr##ptr)
276 #define RESET_PTR_LIST(ptr) \
277 DO_RESET(ptr, __head##ptr, __list##ptr, __nr##ptr)
279 #define FINISH_PTR_LIST(ptr) \
280 DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr)
282 #define DO_FOR_EACH(head, ptr, __head, __list, __nr) do { \
283 struct ptr_list *__head = (struct ptr_list *) (head); \
284 struct ptr_list *__list = __head; \
287 for (__nr = 0; __nr < __list->nr; __nr++) { \
289 ptr = (__typeof__(ptr)) (__list->list[__nr]); \
292 #define DO_END_FOR_EACH(ptr, __head, __list, __nr) \
296 } while ((__list = __list->next) != __head); \
300 #define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr) do { \
301 struct ptr_list *__head = (struct ptr_list *) (head); \
302 struct ptr_list *__list = __head; \
305 __list = __list->prev; \
307 while (--__nr >= 0) { \
309 ptr = (__typeof__(ptr)) (__list->list[__nr]); \
313 #define DO_END_FOR_EACH_REVERSE(ptr, __head, __list, __nr) \
317 } while (__list != __head); \
321 #define DO_THIS_ADDRESS(ptr, __head, __list, __nr) \
322 ((__typeof__(&(ptr))) (__list->list + __nr))
324 #define FOR_EACH_PTR(head, ptr) \
325 DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr)
327 #define END_FOR_EACH_PTR(ptr) \
328 DO_END_FOR_EACH(ptr, __head##ptr, __list##ptr, __nr##ptr)
330 #define FOR_EACH_PTR_REVERSE(head, ptr) \
331 DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr)
333 #define END_FOR_EACH_PTR_REVERSE(ptr) \
334 DO_END_FOR_EACH_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr)
336 #define THIS_ADDRESS(ptr) \
337 DO_THIS_ADDRESS(ptr, __head##ptr, __list##ptr, __nr##ptr)
339 #define DO_DELETE_CURRENT(ptr, __head, __list, __nr) do { \
340 void **__this = __list->list + __nr; \
341 void **__last = __list->list + __list->nr - 1; \
342 while (__this < __last) { \
343 __this[0] = __this[1]; \
346 *__this = (void *)0xf0f0f0f0; \
347 __list->nr--; __nr--; \
350 #define DELETE_CURRENT_PTR(ptr) \
351 DO_DELETE_CURRENT(ptr, __head##ptr, __list##ptr, __nr##ptr)
353 #define REPLACE_CURRENT_PTR(ptr, new_ptr) \
354 do { *THIS_ADDRESS(ptr) = (new_ptr); } while (0)