diff options
-rw-r--r-- | lib.c | 4 | ||||
-rw-r--r-- | lib.h | 23 | ||||
-rw-r--r-- | linearize.h | 10 |
3 files changed, 25 insertions, 12 deletions
@@ -292,7 +292,7 @@ restart: } } -void **add_ptr_list(struct ptr_list **listp, void *ptr) +void **__add_ptr_list(struct ptr_list **listp, void *ptr) { struct ptr_list *list = *listp; struct ptr_list *last = NULL; /* gcc complains needlessly */ @@ -382,7 +382,7 @@ void concat_ptr_list(struct ptr_list *a, struct ptr_list **b) } END_FOR_EACH_PTR(entry); } -void free_ptr_list(struct ptr_list **listp) +void __free_ptr_list(struct ptr_list **listp) { struct ptr_list *tmp, *list = *listp; @@ -48,6 +48,8 @@ struct pseudo; /* Silly type-safety check ;) */ #define DECLARE_PTR_LIST(listname,type) struct listname { type *list[1]; } #define CHECK_TYPE(head,ptr) (void)(&(ptr) == &(head)->list[0]) +#define TYPEOF(head) __typeof__(&(head)->list[0]) +#define VRFY_PTR_LIST(head) (void)(sizeof((head)->list[0])) DECLARE_PTR_LIST(symbol_list, struct symbol); DECLARE_PTR_LIST(statement_list, struct statement); @@ -111,14 +113,25 @@ int delete_ptr_list_entry(struct ptr_list **, void *); int replace_ptr_list_entry(struct ptr_list **, void *old, void *new); extern void sort_list(struct ptr_list **, int (*)(const void *, const void *)); -extern void **add_ptr_list(struct ptr_list **, void *); +extern void **__add_ptr_list(struct ptr_list **, void *); extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b); -extern void free_ptr_list(struct ptr_list **); +extern void __free_ptr_list(struct ptr_list **); extern int ptr_list_size(struct ptr_list *); extern char **handle_switch(char *arg, char **next); extern void add_pre_buffer(const char *fmt, ...); int linearize_ptr_list(struct ptr_list *, void **, int); +/* + * Hey, who said that you can't do overloading in C? + * + * You just have to be creative, and use some gcc + * extensions.. + */ +#define add_ptr_list(list,entry) \ + (TYPEOF(*(list))) (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list), (entry))) +#define free_ptr_list(list) \ + do { VRFY_PTR_LIST(*(list)); __free_ptr_list((struct ptr_list **)(list)); } while (0) + extern unsigned int pre_buffer_size; extern unsigned char pre_buffer[8192]; extern int include_fd; @@ -229,17 +242,17 @@ static inline void concat_instruction_list(struct instruction_list *from, struct static inline void add_symbol(struct symbol_list **list, struct symbol *sym) { - add_ptr_list((struct ptr_list **)list, sym); + add_ptr_list(list, sym); } static inline void add_statement(struct statement_list **list, struct statement *stmt) { - add_ptr_list((struct ptr_list **)list, stmt); + add_ptr_list(list, stmt); } static inline void add_expression(struct expression_list **list, struct expression *expr) { - add_ptr_list((struct ptr_list **)list, expr); + add_ptr_list(list, expr); } #define DO_PREPARE(head, ptr, __head, __list, __nr) \ diff --git a/linearize.h b/linearize.h index e2f5365..524c209 100644 --- a/linearize.h +++ b/linearize.h @@ -182,22 +182,22 @@ static inline int is_branch_goto(struct instruction *br) static inline void add_bb(struct basic_block_list **list, struct basic_block *bb) { - add_ptr_list((struct ptr_list **)list, bb); + add_ptr_list(list, bb); } static inline void add_instruction(struct instruction_list **list, struct instruction *insn) { - add_ptr_list((struct ptr_list **)list, insn); + add_ptr_list(list, insn); } static inline void add_multijmp(struct multijmp_list **list, struct multijmp *multijmp) { - add_ptr_list((struct ptr_list **)list, multijmp); + add_ptr_list(list, multijmp); } static inline void *add_pseudo(struct pseudo_list **list, struct pseudo *pseudo) { - return add_ptr_list((struct ptr_list **)list, pseudo); + return add_ptr_list(list, pseudo); } @@ -217,7 +217,7 @@ static inline int bb_reachable(struct basic_block *bb) static inline void add_pseudo_ptr(pseudo_t *ptr, struct pseudo_ptr_list **list) { - add_ptr_list((struct ptr_list **)list, ptr); + add_ptr_list(list, ptr); } static inline int has_use_list(pseudo_t p) |