diff options
author | Ken Raeburn <raeburn@cygnus> | 1995-02-08 02:35:44 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@cygnus> | 1995-02-08 02:35:44 +0000 |
commit | 12516a373c27abe4516c2a3c84cfe9d94f02e18f (patch) | |
tree | 20c1b81fb9d0ec20120f35bb71eb436f652788c8 /gprof/cg_dfn.c | |
parent | 28860f46fa46ce73225d72ad6a0f72739ca8295c (diff) | |
download | gdb-12516a373c27abe4516c2a3c84cfe9d94f02e18f.zip gdb-12516a373c27abe4516c2a3c84cfe9d94f02e18f.tar.gz gdb-12516a373c27abe4516c2a3c84cfe9d94f02e18f.tar.bz2 |
ran "indent -gnu"; have not fixed block comment style
Diffstat (limited to 'gprof/cg_dfn.c')
-rw-r--r-- | gprof/cg_dfn.c | 363 |
1 files changed, 204 insertions, 159 deletions
diff --git a/gprof/cg_dfn.c b/gprof/cg_dfn.c index f93a9d8..29eb64c 100644 --- a/gprof/cg_dfn.c +++ b/gprof/cg_dfn.c @@ -25,37 +25,40 @@ #define DFN_DEPTH 100 -typedef struct { +typedef struct + { Sym *sym; int cycle_top; -} DFN_Stack; + } +DFN_Stack; DFN_Stack dfn_stack[DFN_DEPTH]; -int dfn_depth = 0; -int dfn_counter = DFN_NAN; +int dfn_depth = 0; +int dfn_counter = DFN_NAN; /* * Is CHILD already numbered? */ static bool -DEFUN(is_numbered, (child), Sym *child) +DEFUN (is_numbered, (child), Sym * child) { - return child->cg.top_order != DFN_NAN && child->cg.top_order != DFN_BUSY; -} /* is_numbered */ + return child->cg.top_order != DFN_NAN && child->cg.top_order != DFN_BUSY; +} /* is_numbered */ /* * Is CHILD already busy? */ static bool -DEFUN(is_busy, (child), Sym *child) +DEFUN (is_busy, (child), Sym * child) { - if (child->cg.top_order == DFN_NAN) { - return FALSE; - } /* if */ - return TRUE; -} /* is_busy */ + if (child->cg.top_order == DFN_NAN) + { + return FALSE; + } /* if */ + return TRUE; +} /* is_busy */ /* @@ -65,92 +68,122 @@ DEFUN(is_busy, (child), Sym *child) * depth-first number). */ static void -DEFUN(find_cycle, (child), Sym *child) +DEFUN (find_cycle, (child), Sym * child) { - Sym *head = 0; - Sym *tail; - int cycle_top; - int index; - - for (cycle_top = dfn_depth; cycle_top > 0; --cycle_top) { - head = dfn_stack[cycle_top].sym; - if (child == head) { - break; - } /* if */ - if (child->cg.cyc.head != child && child->cg.cyc.head == head) { - break; - } /* if */ - } /* for */ - if (cycle_top <= 0) { - fprintf(stderr, "[find_cycle] couldn't find head of cycle\n"); - done(1); - } /* if */ - DBG(DFNDEBUG, printf("[find_cycle] dfn_depth %d cycle_top %d ", - dfn_depth, cycle_top); - if (head) { - print_name(head); - } else { - printf("<unknown>"); - } /* if */ - printf("\n")); - if (cycle_top == dfn_depth) { - /* - * This is previous function, e.g. this calls itself. Sort of - * boring. - * - * Since we are taking out self-cycles elsewhere no need for - * the special case, here. - */ - DBG(DFNDEBUG, - printf("[find_cycle] "); print_name(child); printf("\n")); - } else { - /* - * Glom intervening functions that aren't already glommed into - * this cycle. Things have been glommed when their cyclehead - * field points to the head of the cycle they are glommed - * into. - */ - for (tail = head; tail->cg.cyc.next; tail = tail->cg.cyc.next) { - /* void: chase down to tail of things already glommed */ - DBG(DFNDEBUG, - printf("[find_cycle] tail "); print_name(tail); printf("\n")); - } /* for */ - /* - * If what we think is the top of the cycle has a cyclehead - * field, then it's not really the head of the cycle, which is - * really what we want. - */ - if (head->cg.cyc.head != head) { - head = head->cg.cyc.head; - DBG(DFNDEBUG, printf("[find_cycle] new cyclehead "); - print_name(head); printf("\n")); - } /* if */ - for (index = cycle_top + 1; index <= dfn_depth; ++index) { - child = dfn_stack[index].sym; - if (child->cg.cyc.head == child) { - /* - * Not yet glommed anywhere, glom it and fix any - * children it has glommed. - */ - tail->cg.cyc.next = child; - child->cg.cyc.head = head; - DBG(DFNDEBUG, printf("[find_cycle] glomming "); - print_name(child); printf(" onto "); print_name(head); - printf("\n")); - for (tail = child; tail->cg.cyc.next; tail = tail->cg.cyc.next) + Sym *head = 0; + Sym *tail; + int cycle_top; + int index; + + for (cycle_top = dfn_depth; cycle_top > 0; --cycle_top) + { + head = dfn_stack[cycle_top].sym; + if (child == head) + { + break; + } /* if */ + if (child->cg.cyc.head != child && child->cg.cyc.head == head) + { + break; + } /* if */ + } /* for */ + if (cycle_top <= 0) + { + fprintf (stderr, "[find_cycle] couldn't find head of cycle\n"); + done (1); + } /* if */ +#ifdef DEBUG + if (debug_level & DFNDEBUG) + { + printf ("[find_cycle] dfn_depth %d cycle_top %d ", + dfn_depth, cycle_top); + if (head) + { + print_name (head); + } + else + { + printf ("<unknown>"); + } /* if */ + printf ("\n"); + } +#endif + if (cycle_top == dfn_depth) + { + /* + * This is previous function, e.g. this calls itself. Sort of + * boring. + * + * Since we are taking out self-cycles elsewhere no need for + * the special case, here. + */ + DBG (DFNDEBUG, + printf ("[find_cycle] "); + print_name (child); + printf ("\n")); + } + else + { + /* + * Glom intervening functions that aren't already glommed into + * this cycle. Things have been glommed when their cyclehead + * field points to the head of the cycle they are glommed + * into. + */ + for (tail = head; tail->cg.cyc.next; tail = tail->cg.cyc.next) + { + /* void: chase down to tail of things already glommed */ + DBG (DFNDEBUG, + printf ("[find_cycle] tail "); + print_name (tail); + printf ("\n")); + } /* for */ + /* + * If what we think is the top of the cycle has a cyclehead + * field, then it's not really the head of the cycle, which is + * really what we want. + */ + if (head->cg.cyc.head != head) + { + head = head->cg.cyc.head; + DBG (DFNDEBUG, printf ("[find_cycle] new cyclehead "); + print_name (head); + printf ("\n")); + } /* if */ + for (index = cycle_top + 1; index <= dfn_depth; ++index) + { + child = dfn_stack[index].sym; + if (child->cg.cyc.head == child) + { + /* + * Not yet glommed anywhere, glom it and fix any + * children it has glommed. + */ + tail->cg.cyc.next = child; + child->cg.cyc.head = head; + DBG (DFNDEBUG, printf ("[find_cycle] glomming "); + print_name (child); + printf (" onto "); + print_name (head); + printf ("\n")); + for (tail = child; tail->cg.cyc.next; tail = tail->cg.cyc.next) { - tail->cg.cyc.next->cg.cyc.head = head; - DBG(DFNDEBUG, printf("[find_cycle] and its tail "); - print_name(tail->cg.cyc.next); printf(" onto "); - print_name(head); printf("\n")); - } /* for */ - } else if (child->cg.cyc.head != head /* firewall */) { - fprintf(stderr, "[find_cycle] glommed, but not to head\n"); - done(1); - } /* if */ - } /* for */ - } /* if */ -} /* find_cycle */ + tail->cg.cyc.next->cg.cyc.head = head; + DBG (DFNDEBUG, printf ("[find_cycle] and its tail "); + print_name (tail->cg.cyc.next); + printf (" onto "); + print_name (head); + printf ("\n")); + } /* for */ + } + else if (child->cg.cyc.head != head /* firewall */ ) + { + fprintf (stderr, "[find_cycle] glommed, but not to head\n"); + done (1); + } /* if */ + } /* for */ + } /* if */ +} /* find_cycle */ /* @@ -158,19 +191,21 @@ DEFUN(find_cycle, (child), Sym *child) * the stack and mark it busy. */ static void -DEFUN(pre_visit, (parent), Sym *parent) +DEFUN (pre_visit, (parent), Sym * parent) { - ++dfn_depth; - if (dfn_depth >= DFN_DEPTH) { - fprintf(stderr, "[pre_visit] dfn_stack overflow\n"); - done(1); - } /* if */ - dfn_stack[dfn_depth].sym = parent; - dfn_stack[dfn_depth].cycle_top = dfn_depth; - parent->cg.top_order = DFN_BUSY; - DBG(DFNDEBUG, printf("[pre_visit]\t\t%d:", dfn_depth); print_name(parent); - printf("\n")); -} /* pre_visit */ + ++dfn_depth; + if (dfn_depth >= DFN_DEPTH) + { + fprintf (stderr, "[pre_visit] dfn_stack overflow\n"); + done (1); + } /* if */ + dfn_stack[dfn_depth].sym = parent; + dfn_stack[dfn_depth].cycle_top = dfn_depth; + parent->cg.top_order = DFN_BUSY; + DBG (DFNDEBUG, printf ("[pre_visit]\t\t%d:", dfn_depth); + print_name (parent); + printf ("\n")); +} /* pre_visit */ /* @@ -178,61 +213,71 @@ DEFUN(pre_visit, (parent), Sym *parent) * and number functions if PARENT is head of a cycle. */ static void -DEFUN(post_visit, (parent), Sym *parent) +DEFUN (post_visit, (parent), Sym * parent) { - Sym *member; - - DBG(DFNDEBUG, printf("[post_visit]\t%d: ", dfn_depth); - print_name(parent); printf("\n")); - /* - * Number functions and things in their cycles unless the function - * is itself part of a cycle: - */ - if (parent->cg.cyc.head == parent) { - ++dfn_counter; - for (member = parent; member; member = member->cg.cyc.next) { - member->cg.top_order = dfn_counter; - DBG(DFNDEBUG, printf("[post_visit]\t\tmember "); - print_name(member); - printf("-> cg.top_order = %d\n", dfn_counter)); - } /* for */ - } else { - DBG(DFNDEBUG, printf("[post_visit]\t\tis part of a cycle\n")); - } /* if */ - --dfn_depth; -} /* post_visit */ + Sym *member; + + DBG (DFNDEBUG, printf ("[post_visit]\t%d: ", dfn_depth); + print_name (parent); + printf ("\n")); + /* + * Number functions and things in their cycles unless the function + * is itself part of a cycle: + */ + if (parent->cg.cyc.head == parent) + { + ++dfn_counter; + for (member = parent; member; member = member->cg.cyc.next) + { + member->cg.top_order = dfn_counter; + DBG (DFNDEBUG, printf ("[post_visit]\t\tmember "); + print_name (member); + printf ("-> cg.top_order = %d\n", dfn_counter)); + } /* for */ + } + else + { + DBG (DFNDEBUG, printf ("[post_visit]\t\tis part of a cycle\n")); + } /* if */ + --dfn_depth; +} /* post_visit */ /* * Given this PARENT, depth first number its children. */ void -DEFUN(cg_dfn, (parent), Sym *parent) +DEFUN (cg_dfn, (parent), Sym * parent) { - Arc *arc; - - DBG(DFNDEBUG, printf("[dfn] dfn( "); print_name(parent); printf(")\n")); - /* - * If we're already numbered, no need to look any further: - */ - if (is_numbered(parent)) { - return; - } /* if */ - /* - * If we're already busy, must be a cycle: - */ - if (is_busy(parent)) { - find_cycle(parent); - return; - } /* if */ - pre_visit(parent); - /* - * Recursively visit children: - */ - for (arc = parent->cg.children; arc; arc = arc->next_child) { - cg_dfn(arc->child); - } /* for */ - post_visit(parent); -} /* cg_dfn */ - - /*** end of cg_dfn.c ***/ + Arc *arc; + + DBG (DFNDEBUG, printf ("[dfn] dfn( "); + print_name (parent); + printf (")\n")); + /* + * If we're already numbered, no need to look any further: + */ + if (is_numbered (parent)) + { + return; + } /* if */ + /* + * If we're already busy, must be a cycle: + */ + if (is_busy (parent)) + { + find_cycle (parent); + return; + } /* if */ + pre_visit (parent); + /* + * Recursively visit children: + */ + for (arc = parent->cg.children; arc; arc = arc->next_child) + { + cg_dfn (arc->child); + } /* for */ + post_visit (parent); +} /* cg_dfn */ + +/*** end of cg_dfn.c ***/ |