aboutsummaryrefslogtreecommitdiff
path: root/src/symbol.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-11-09 01:50:43 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-11-09 01:50:43 +0200
commitdc1a81526099095b12ef6edb655cf1a773dfa983 (patch)
tree17defadb706683a3a59ee41428200ee66d91d34b /src/symbol.c
parent4d75955e833201c4f1d0219d48676521aeee1afa (diff)
downloadcflow-dc1a81526099095b12ef6edb655cf1a773dfa983.tar.gz
cflow-dc1a81526099095b12ef6edb655cf1a773dfa983.tar.bz2
Speed-up recursive call detection.
* src/depmap.c: New file. * src/Makefile.am: Add depmap.c. * src/cflow.h (struct symbol.ord): New member. (collect_symbols): Change signature. All callers updated. (collect_functions): New proto. (symbol_is_function): New proto. (cflow_depmap_t): New data type. (depmap_alloc, depmap_set) (depmap_isset, depmap_tc): New prototypes. * src/output.c (symbol_is_function): New function. (scan_tree): Remove. (tree_output): Use depmap to find out recursive calls. * src/symbol.c (static_func_list): New list. (static_free): Add static functions to static_func_list. (collect_symbols): Return size_t. Take additional number of slots in the 3rd argument. (collect_functions): New function.
Diffstat (limited to 'src/symbol.c')
-rw-r--r--src/symbol.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/symbol.c b/src/symbol.c
index 80c01a3..677f510 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -24,6 +24,7 @@ static Hash_table *symbol_table;
static struct linked_list *static_symbol_list;
static struct linked_list *auto_symbol_list;
+static struct linked_list *static_func_list;
static void
append_symbol(struct linked_list **plist, Symbol *sp)
@@ -207,11 +208,13 @@ static_free(void *data)
if (!t)
return;
- if (sym->flag == symbol_temp
- || globals_only())
+ if (sym->flag == symbol_temp)
delete_symbol(sym);
- else
+ else {
unlink_symbol(sym);
+ if (symbol_is_function(sym))
+ linked_list_append(&static_func_list, sym);
+ }
}
void
@@ -280,8 +283,9 @@ collect_processor(void *data, void *proc_data)
return true;
}
-int
-collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p))
+size_t
+collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p),
+ size_t reserved_slots)
{
struct collect_data cdata;
@@ -289,7 +293,7 @@ collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p))
cdata.index = 0;
cdata.sel = sel;
hash_do_for_each (symbol_table, collect_processor, &cdata);
- cdata.sym = calloc(cdata.index, sizeof(*cdata.sym));
+ cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym));
if (!cdata.sym)
xalloc_die();
cdata.index = 0;
@@ -298,6 +302,31 @@ collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p))
return cdata.index;
}
+size_t
+collect_functions(Symbol ***return_sym)
+{
+ Symbol **symbols;
+ size_t num, snum;
+ struct linked_list_entry *p;
+
+ /* Count static functions */
+ snum = 0;
+ if (static_func_list)
+ for (p = linked_list_head(static_func_list); p; p = p->next)
+ snum++;
+
+ /* Collect global functions */
+ num = collect_symbols(&symbols, symbol_is_function, snum);
+
+ /* Collect static functions */
+ if (snum)
+ for (p = linked_list_head(static_func_list); p; p = p->next)
+ symbols[num++] = p->data;
+ *return_sym = symbols;
+ return num;
+}
+
+
/* Special handling for function parameters */

Return to:

Send suggestions and report system problems to the System administrator.