예제 #1
0
파일: output.c 프로젝트: samael65535/cflow
static void
tree_output()
{
     Symbol **symbols, *main_sym;
     int i, num;
     
     /* Collect and sort symbols */
     num = collect_symbols(&symbols, is_var);
     qsort(symbols, num, sizeof(*symbols), compare);
     /* Scan and mark the recursive ones */
     for (i = 0; i < num; i++) {
	  if (symbols[i]->callee)
	       scan_tree(0, symbols[i]);
     }
     
     /* Produce output */
    begin();
    
    if (reverse_tree) {
	 for (i = 0; i < num; i++) {
	      inverted_tree(0, 0, symbols[i]);
	      separator();
	 }
    } else {
	 main_sym = lookup(start_name);
	 if (main_sym) {
	      direct_tree(0, 0, main_sym);
	      separator();
	 } else {
	      for (i = 0; i < num; i++) {
		   if (symbols[i]->callee == NULL)
			continue;
		   direct_tree(0, 0, symbols[i]);
		   separator();
	      }
	 }
    }
    
    end();
    
    free(symbols);
}
예제 #2
0
파일: output.c 프로젝트: lizh06/cflow
/* Produce direct call tree output
 */
static void
direct_tree(int lev, int last, Symbol *sym)
{
     struct linked_list_entry *p;
     int rc;
     
     if (sym->type == SymUndefined
	 || (max_depth && lev >= max_depth)
	 || !include_symbol(sym))
	  return;

     rc = print_symbol(1, lev, last, sym);
     newline();
     if (rc || sym->active)
	  return;
     set_active(sym);
     for (p = linked_list_head(sym->callee); p; p = p->next) {
	  set_level_mark(lev+1, !is_last(p));
	  direct_tree(lev+1, is_last(p), (Symbol*)p->data);
     }
     clear_active(sym);
}
예제 #3
0
파일: output.c 프로젝트: samael65535/cflow
/* Produce direct call tree output
 */
static void
direct_tree(int lev, int last, Symbol *sym)
{
     Consptr cons;
     int rc;
     
     if (sym->type == SymUndefined
	 || (max_depth && lev >= max_depth)
	 || !include_symbol(sym))
	  return;

     rc = print_symbol(1, lev, last, sym);
     newline();
     if (rc || sym->active)
	  return;
     set_active(sym);
     for (cons = sym->callee; cons; cons = CDR(cons)) {
	  set_level_mark(lev+1, is_printable(CDR(cons)));
	  direct_tree(lev+1, is_last(cons), (Symbol*)CAR(cons));
     }
     clear_active(sym);
}
예제 #4
0
파일: output.c 프로젝트: lizh06/cflow
static void
tree_output()
{
     Symbol **symbols, *main_sym;
     size_t i, num;
     cflow_depmap_t depmap;
     
     /* Collect functions and assign them ordinal numbers */
     num = collect_functions(&symbols);
     for (i = 0; i < num; i++)
	  symbols[i]->ord = i;
     
     /* Create a dependency matrix */
     depmap = depmap_alloc(num);
     for (i = 0; i < num; i++) {
	  if (symbols[i]->callee) {
	       struct linked_list_entry *p;
	       
	       for (p = linked_list_head(symbols[i]->callee); p;
		    p = p->next) {
		    Symbol *s = (Symbol*) p->data;
		    if (symbol_is_function(s))
			 depmap_set(depmap, i, ((Symbol*)p->data)->ord);
	       }		    
	  }
     }
     
     depmap_tc(depmap);

     /* Mark recursive calls */
     for (i = 0; i < num; i++)
	  if (depmap_isset(depmap, i, i))
	       symbols[i]->recursive = 1;
     free(depmap);
     free(symbols);
     
     /* Collect and sort all symbols */
     num = collect_symbols(&symbols, is_var, 0);
     qsort(symbols, num, sizeof(*symbols), compare);
	       
     /* Produce output */
     begin();
    
     if (reverse_tree) {
	  for (i = 0; i < num; i++) {
	       inverted_tree(0, 0, symbols[i]);
	       separator();
	  }
     } else {
	  main_sym = lookup(start_name);
	  if (main_sym) {
	       direct_tree(0, 0, main_sym);
	       separator();
	  } else {
	       for (i = 0; i < num; i++) {
		    if (symbols[i]->callee == NULL)
			 continue;
		    direct_tree(0, 0, symbols[i]);
		    separator();
	       }
	  }
     }
     
     end();
     
     free(symbols);
}