bug-cflow
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-cflow] cflow: static functions in inverted trees


From: Sergey Poznyakoff
Subject: Re: [bug-cflow] cflow: static functions in inverted trees
Date: Sat, 12 Nov 2016 14:18:11 +0200

Chris Smith <address@hidden> ha escrit:

> Yes, static functions are included in the lists of callers of each
> function. The issue is that the inverted graph iterates through all
> your functions and gives the callers for each, but that it doesn't
> include static functions as starting points for that process. 

Ah, I see.  Then I would propose the following patch instead.  It is a
bit more compact than yours and the resulting code honors the -i option.
Please give it a try.

Regards,
Sergey

>From 84bc599adc35abf19966746b61e63744a0835504 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <address@hidden>
Date: Sat, 12 Nov 2016 14:09:49 +0200
Subject: [PATCH] Include static symbols as root points in inverted graphs.

* src/cflow.h (linked_list_size): New function.
* src/linked-list.c (linked_list_size): New function.
* src/symbol.c (collect_symbols): Include static symbols,
if allowed by sel.
---
 src/cflow.h       |  1 +
 src/linked-list.c | 15 ++++++++++++++-
 src/symbol.c      | 35 +++++++++++++++++++++++------------
 3 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/src/cflow.h b/src/cflow.h
index 5867a18..0e3ee44 100644
--- a/src/cflow.h
+++ b/src/cflow.h
@@ -198,6 +198,7 @@ void linked_list_iterate(struct linked_list **plist,
                         int (*itr) (void *, void *), void *data);
 void linked_list_unlink(struct linked_list *list,
                        struct linked_list_entry *ent);
+size_t linked_list_size(struct linked_list *list);

 int data_in_list(void *data, struct linked_list *list);

diff --git a/src/linked-list.c b/src/linked-list.c
index 095b63e..3c57bf0 100644
--- a/src/linked-list.c
+++ b/src/linked-list.c
@@ -17,7 +17,7 @@
 #include <cflow.h>

 static struct linked_list *
-deref_linked_list (struct linked_list **plist)
+deref_linked_list(struct linked_list **plist)
 {
      if (!*plist) {
          struct linked_list *list = xmalloc(sizeof(*list));
@@ -144,3 +144,16 @@ data_in_list(void *data, struct linked_list *list)
               return 1;
      return 0;
 }
+
+size_t
+linked_list_size(struct linked_list *list)
+{
+     size_t size = 0;
+     if (list) {
+         struct linked_list_entry *p;
+         for (p = linked_list_head(list); p; p = p->next)
+              size++;
+     }
+     return size;
+}
+
diff --git a/src/symbol.c b/src/symbol.c
index 460f954..5f7dec2 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -297,21 +297,35 @@ collect_processor(void *data, void *proc_data)
      return true;
 }

+static int
+collect_list_entry(void *item, void *proc_data)
+{
+     Symbol *s = item;
+     struct collect_data *cd = proc_data;
+     if (cd->sel(s)) {
+         cd->sym[cd->index] = s;
+         cd->index++;
+     }
+     return 0;
+}
+
 size_t
 collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p),
                size_t reserved_slots)
 {
      struct collect_data cdata;
-
-     cdata.sym = NULL;
+     size_t size;
+
+     size = hash_get_n_entries(symbol_table)
+            + linked_list_size(static_func_list);
+     cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym));
      cdata.index = 0;
      cdata.sel = sel;
-     hash_do_for_each (symbol_table, collect_processor, &cdata);
-     cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym));
-     if (!cdata.sym)
-         xalloc_die();
-     cdata.index = 0;
-     hash_do_for_each (symbol_table, collect_processor, &cdata);
+     hash_do_for_each(symbol_table, collect_processor, &cdata);
+     linked_list_iterate(&static_func_list, collect_list_entry, &cdata);
+
+     cdata.sym = xrealloc(cdata.sym,
+                         (cdata.index + reserved_slots) * sizeof(*cdata.sym));
      *return_sym = cdata.sym;
      return cdata.index;
 }
@@ -324,10 +338,7 @@ collect_functions(Symbol ***return_sym)
      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++;
+     snum = linked_list_size(static_func_list);

      /* Collect global functions */
      num = collect_symbols(&symbols, symbol_is_function, snum);
--
1.8.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]