diff options
author | Christopher Li <sparse@chrisli.org> | 2006-11-30 02:11:36 -0800 |
---|---|---|
committer | Josh Triplett <josh@freedesktop.org> | 2006-12-04 23:27:58 -0800 |
commit | 4ad8ad708f80c91e70f8491e4d62dccc40358887 (patch) | |
tree | 7d09aa58e537095a1567568913ab233408dfc835 | |
parent | delay removing file scope (diff) | |
download | sparse-4ad8ad708f80c91e70f8491e4d62dccc40358887.tar.gz sparse-4ad8ad708f80c91e70f8491e4d62dccc40358887.tar.bz2 sparse-4ad8ad708f80c91e70f8491e4d62dccc40358887.zip |
cleanup write to argument array hack
The sparse interface is a kind of snaky that it change the input argument
array. The function sparse() does the same hack just to skip the files.
This patch add the ptr list for string. So sparse_initialize will
return list of file to compile. The string pointer is not aligned
at word boundary. This patch introduce non taged version of the ptr
list iteration function.
Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r-- | check.c | 10 | ||||
-rw-r--r-- | compile.c | 19 | ||||
-rw-r--r-- | example.c | 10 | ||||
-rw-r--r-- | graph.c | 11 | ||||
-rw-r--r-- | lib.c | 28 | ||||
-rw-r--r-- | lib.h | 7 | ||||
-rw-r--r-- | obfuscate.c | 10 | ||||
-rw-r--r-- | ptrlist.h | 44 | ||||
-rw-r--r-- | test-dissect.c | 10 | ||||
-rw-r--r-- | test-lexing.c | 10 | ||||
-rw-r--r-- | test-linearize.c | 10 | ||||
-rw-r--r-- | test-parsing.c | 10 | ||||
-rw-r--r-- | test-unssa.c | 11 |
13 files changed, 113 insertions, 77 deletions
@@ -271,9 +271,13 @@ static void check_symbols(struct symbol_list *list) int main(int argc, char **argv) { + struct string_list *filelist = NULL; + char *file; + // Expand, linearize and show it. - check_symbols(sparse_initialize(argc, argv)); - while (*argv) - check_symbols(sparse(argv)); + check_symbols(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { + check_symbols(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); return 0; } @@ -37,21 +37,22 @@ static void clean_up_symbols(struct symbol_list *list) int main(int argc, char **argv) { - const char *filename; + char *file; + struct string_list *filelist = NULL; - clean_up_symbols(sparse_initialize(argc, argv)); - while ((filename = *argv) != NULL) { + clean_up_symbols(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { struct symbol_list *list; - const char *basename = strrchr(filename, '/'); - if (basename) - filename = basename+1; - list = sparse(argv); + const char *basename = strrchr(file, '/'); + basename = basename ? basename+1 : file; + + list = sparse(file); // Do type evaluation and simplification - emit_unit_begin(filename); + emit_unit_begin(basename); clean_up_symbols(list); emit_unit_end(); - } + } END_FOR_EACH_PTR_NOTAG(file); #if 0 // And show the allocation statistics @@ -1942,9 +1942,13 @@ static int compile(struct symbol_list *list) int main(int argc, char **argv) { - compile(sparse_initialize(argc, argv)); - while (*argv) - compile(sparse(argv)); + struct string_list *filelist = NULL; + char *file; + + compile(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { + compile(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); return 0; } @@ -55,10 +55,15 @@ static void graph_symbols(struct symbol_list *list) int main(int argc, char **argv) { + struct string_list *filelist = NULL; + char *file; + printf("digraph control_flow {\n"); - graph_symbols(sparse_initialize(argc, argv)); - while (*argv) - graph_symbols(sparse(argv)); + graph_symbols(sparse_initialize(argc, argv, &filelist)); + + FOR_EACH_PTR_NOTAG(filelist, file) { + graph_symbols(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); printf("}\n"); return 0; } @@ -612,10 +612,9 @@ static struct symbol_list *sparse_initial(void) return sparse_tokenstream(token); } -struct symbol_list *sparse_initialize(int argc, char **argv) +struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **filelist) { char **args; - int files = 0; struct symbol_list *list; // Initialize symbol stream first, so that we can add defines etc @@ -631,17 +630,11 @@ struct symbol_list *sparse_initialize(int argc, char **argv) args = handle_switch(arg+1, args); continue; } - - /* - * Hacky hacky hacky: we re-use the argument space - * to save the filenames. - */ - argv[files++] = arg; + add_ptr_list_notag(filelist, arg); } list = NULL; - argv[files] = NULL; - if (files) { + if (!ptr_list_empty(filelist)) { // Initialize type system init_ctype(); @@ -661,22 +654,13 @@ struct symbol_list *sparse_initialize(int argc, char **argv) return list; } -struct symbol_list * __sparse(char **argv) +struct symbol_list * __sparse(char *filename) { struct symbol_list *res; - char *filename, *next; /* Clear previous symbol list */ translation_unit_used_list = NULL; - filename = *argv; - if (!filename) - return NULL; - do { - next = argv[1]; - *argv++ = next; - } while (next); - new_file_scope(); res = sparse_file(filename); @@ -687,9 +671,9 @@ struct symbol_list * __sparse(char **argv) return res; } -struct symbol_list * sparse(char **argv) +struct symbol_list * sparse(char *filename) { - struct symbol_list *res = __sparse(argv); + struct symbol_list *res = __sparse(filename); /* Evaluate the complete symbol list */ evaluate_symbol_list(res); @@ -51,6 +51,7 @@ DECLARE_PTR_LIST(basic_block_list, struct basic_block); DECLARE_PTR_LIST(instruction_list, struct instruction); DECLARE_PTR_LIST(multijmp_list, struct multijmp); DECLARE_PTR_LIST(pseudo_list, struct pseudo); +DECLARE_PTR_LIST(string_list, char); typedef struct pseudo *pseudo_t; @@ -89,9 +90,9 @@ extern int Wuninitialized; extern void declare_builtin_functions(void); extern void create_builtin_stream(void); -extern struct symbol_list *sparse_initialize(int argc, char **argv); -extern struct symbol_list *__sparse(char **argv); -extern struct symbol_list *sparse(char **argv); +extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list** files); +extern struct symbol_list *__sparse(char *filename); +extern struct symbol_list *sparse(char *filename); static inline int symbol_list_size(struct symbol_list* list) { diff --git a/obfuscate.c b/obfuscate.c index 1e10bf7..f2ed7b1 100644 --- a/obfuscate.c +++ b/obfuscate.c @@ -49,8 +49,12 @@ static void emit_symbol_list(struct symbol_list *list) int main(int argc, char **argv) { - emit_symbol_list(sparse_initialize(argc, argv)); - while (*argv) - emit_symbol_list(sparse(argv)); + struct string_list *filelist = NULL; + char *file; + + emit_symbol_list(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { + emit_symbol_list(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); return 0; } @@ -40,7 +40,7 @@ int delete_ptr_list_entry(struct ptr_list **, void *, int); int replace_ptr_list_entry(struct ptr_list **, void *old, void *new, int); extern void sort_list(struct ptr_list **, int (*)(const void *, const void *)); -extern void **__add_ptr_list(struct ptr_list **, void *, unsigned long tag); +extern void **__add_ptr_list(struct ptr_list **, void *, unsigned long); extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b); extern void __free_ptr_list(struct ptr_list **); extern int ptr_list_size(struct ptr_list *); @@ -54,12 +54,17 @@ extern int linearize_ptr_list(struct ptr_list *, void **, int); */ #define add_ptr_list_tag(list,entry,tag) \ MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list), (entry), (tag)))) +#define add_ptr_list_notag(list,entry) \ + MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list), \ + (void*)((unsigned long)(entry) & ~3UL), \ + (unsigned long)(entry) & 3))) #define add_ptr_list(list,entry) \ add_ptr_list_tag(list,entry,0) #define free_ptr_list(list) \ do { VRFY_PTR_LIST(*(list)); __free_ptr_list((struct ptr_list **)(list)); } while (0) -#define PTR_ENTRY(h,i) (void *)(~3UL & (unsigned long)(h)->list[i]) +#define PTR_ENTRY_NOTAG(h,i) ((h)->list[i]) +#define PTR_ENTRY(h,i) (void *)(~3UL & (unsigned long)PTR_ENTRY_NOTAG(h,i)) static inline void *first_ptr_list(struct ptr_list *list) { @@ -77,7 +82,7 @@ static inline void *last_ptr_list(struct ptr_list *list) return PTR_ENTRY(list, list->nr-1); } -#define DO_PREPARE(head, ptr, __head, __list, __nr) \ +#define DO_PREPARE(head, ptr, __head, __list, __nr, PTR_ENTRY) \ do { \ struct ptr_list *__head = (struct ptr_list *) (head); \ struct ptr_list *__list = __head; \ @@ -86,7 +91,7 @@ static inline void *last_ptr_list(struct ptr_list *list) if (__head) ptr = PTR_ENTRY(__head, 0); \ else ptr = NULL -#define DO_NEXT(ptr, __head, __list, __nr) \ +#define DO_NEXT(ptr, __head, __list, __nr, PTR_ENTRY) \ if (ptr) { \ if (++__nr < __list->nr) { \ ptr = PTR_ENTRY(__list,__nr); \ @@ -100,7 +105,7 @@ static inline void *last_ptr_list(struct ptr_list *list) } \ } -#define DO_RESET(ptr, __head, __list, __nr) \ +#define DO_RESET(ptr, __head, __list, __nr, PTR_ENTRY) \ do { \ __nr = 0; \ __list = __head; \ @@ -112,18 +117,18 @@ static inline void *last_ptr_list(struct ptr_list *list) } while (0) #define PREPARE_PTR_LIST(head, ptr) \ - DO_PREPARE(head, ptr, __head##ptr, __list##ptr, __nr##ptr) + DO_PREPARE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY) #define NEXT_PTR_LIST(ptr) \ - DO_NEXT(ptr, __head##ptr, __list##ptr, __nr##ptr) + DO_NEXT(ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY) #define RESET_PTR_LIST(ptr) \ - DO_RESET(ptr, __head##ptr, __list##ptr, __nr##ptr) + DO_RESET(ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY) #define FINISH_PTR_LIST(ptr) \ DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr) -#define DO_FOR_EACH(head, ptr, __head, __list, __nr) do { \ +#define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ struct ptr_list *__head = (struct ptr_list *) (head); \ struct ptr_list *__list = __head; \ CHECK_TYPE(head,ptr); \ @@ -142,7 +147,7 @@ static inline void *last_ptr_list(struct ptr_list *list) } \ } while (0) -#define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr) do { \ +#define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \ struct ptr_list *__head = (struct ptr_list *) (head); \ struct ptr_list *__list = __head; \ CHECK_TYPE(head,ptr); \ @@ -164,7 +169,8 @@ static inline void *last_ptr_list(struct ptr_list *list) } \ } while (0) -#define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead, __newlist, __newnr) do { \ +#define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead, \ + __newlist, __newnr, PTR_ENTRY) do { \ struct ptr_list *__newhead = __head; \ struct ptr_list *__newlist = __list; \ int __newnr = __nr; \ @@ -182,23 +188,33 @@ static inline void *last_ptr_list(struct ptr_list *list) #define RECURSE_PTR_REVERSE(ptr, new) \ DO_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr, \ - new, __head##new, __list##new, __nr##new) + new, __head##new, __list##new, __nr##new, PTR_ENTRY) #define DO_THIS_ADDRESS(ptr, __head, __list, __nr) \ ((__typeof__(&(ptr))) (__list->list + __nr)) #define FOR_EACH_PTR(head, ptr) \ - DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr) + DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY) #define END_FOR_EACH_PTR(ptr) \ DO_END_FOR_EACH(ptr, __head##ptr, __list##ptr, __nr##ptr) +#define FOR_EACH_PTR_NOTAG(head, ptr) \ + DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG) + +#define END_FOR_EACH_PTR_NOTAG(ptr) END_FOR_EACH_PTR(ptr) + #define FOR_EACH_PTR_REVERSE(head, ptr) \ - DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr) + DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY) #define END_FOR_EACH_PTR_REVERSE(ptr) \ DO_END_FOR_EACH_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr) +#define FOR_EACH_PTR_REVERSE_NOTAG(head, ptr) \ + DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG) + +#define END_FOR_EACH_PTR_REVERSE_NOTAG(ptr) END_FOR_EACH_PTR_REVERSE(ptr) + #define THIS_ADDRESS(ptr) \ DO_THIS_ADDRESS(ptr, __head##ptr, __list##ptr, __nr##ptr) diff --git a/test-dissect.c b/test-dissect.c index ccdf979..a2548b7 100644 --- a/test-dissect.c +++ b/test-dissect.c @@ -83,13 +83,15 @@ int main(int argc, char **argv) .r_symbol = r_symbol, .r_member = r_member, }; + struct string_list *filelist = NULL; + char *file; - sparse_initialize(argc, argv); + sparse_initialize(argc, argv, &filelist); - while (*argv) { + FOR_EACH_PTR_NOTAG(filelist, file) { dotc_stream = input_stream_nr; - dissect(__sparse(argv), &reporter); - } + dissect(__sparse(file), &reporter); + } END_FOR_EACH_PTR_NOTAG(file); return 0; } diff --git a/test-lexing.c b/test-lexing.c index 346cbe7..f4639ec 100644 --- a/test-lexing.c +++ b/test-lexing.c @@ -20,10 +20,14 @@ int main(int argc, char **argv) { + struct string_list *filelist = NULL; + char *file; + preprocess_only = 1; - sparse_initialize(argc, argv); - while (*argv) - sparse(argv); + sparse_initialize(argc, argv, &filelist); + FOR_EACH_PTR_NOTAG(filelist, file) { + sparse(file); + } END_FOR_EACH_PTR_NOTAG(file); show_identifier_stats(); return 0; } diff --git a/test-linearize.c b/test-linearize.c index ab6385b..5cc54cd 100644 --- a/test-linearize.c +++ b/test-linearize.c @@ -38,8 +38,12 @@ static void clean_up_symbols(struct symbol_list *list) int main(int argc, char **argv) { - clean_up_symbols(sparse_initialize(argc, argv)); - while (*argv) - clean_up_symbols(sparse(argv)); + struct string_list *filelist = NULL; + char *file; + + clean_up_symbols(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { + clean_up_symbols(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); return 0; } diff --git a/test-parsing.c b/test-parsing.c index 5aafae9..f29a730 100644 --- a/test-parsing.c +++ b/test-parsing.c @@ -35,8 +35,10 @@ static void clean_up_symbols(struct symbol_list *list) int main(int argc, char **argv) { struct symbol_list * list; + struct string_list * filelist = NULL; + char *file; - list = sparse_initialize(argc, argv); + list = sparse_initialize(argc, argv, &filelist); // Simplification clean_up_symbols(list); @@ -46,8 +48,8 @@ int main(int argc, char **argv) printf("\n\n"); #endif - while (*argv) { - list = sparse(argv); + FOR_EACH_PTR_NOTAG(filelist, file) { + list = sparse(file); // Simplification clean_up_symbols(list); @@ -57,7 +59,7 @@ int main(int argc, char **argv) show_symbol_list(list, "\n\n"); printf("\n\n"); #endif - } + } END_FOR_EACH_PTR_NOTAG(file); #if 0 // And show the allocation statistics diff --git a/test-unssa.c b/test-unssa.c index 15ff9d7..88ce025 100644 --- a/test-unssa.c +++ b/test-unssa.c @@ -74,8 +74,13 @@ static int compile(struct symbol_list *list) int main(int argc, char **argv) { - compile(sparse_initialize(argc, argv)); - while (*argv) - compile(sparse(argv)); + struct string_list * filelist = NULL; + char *file; + + compile(sparse_initialize(argc, argv, &filelist)); + FOR_EACH_PTR_NOTAG(filelist, file) { + compile(sparse(file)); + } END_FOR_EACH_PTR_NOTAG(file); + return 0; } |