#!/usr/bin/perl -w # by Hagen Fritsch # Released under the terms of the GPL # Generates a depency tree in dot-format based upon c-files. # Requires gcc to compile the c-sources to asm-files for a simple # parsing process... # # usage: perl $0 *.c | springgraph > graph.png my %dep = (); my @color_list = qw(MidnightBlue DarkGreen red brown VioletRed SeaGreen MediumBlue ForestGreen sienna DarkOrange black DarkViolet DarkSlateBlue MediumBlue); my $curcol = 0; my %cols = (); foreach(@ARGV) { system("gcc -S '$_'"); /^(.+)\.c$/i; my $curname = 'none'; open(FILE, "$1.s") || die $!; while() { if(/^([^\.\s].+?):/) { $curname = $1; $dep{$curname} = (); $cols{$curname} = $curcol; } if(/call\s+(.+)/) { $dep{$curname}{$1} = 1 if(!exists $dep{$curname}{$1}); } } close(FILE); $curcol++; } print <<"EOT"; digraph "source tree" { overlap=false; size="8,10"; ratio="fill"; // fontsize="16"; // fontname="Helvetica"; // clusterrank="local"; splines="true"; EOT my %clist = (); foreach my $d (keys %dep) { foreach(keys %{$dep{$d}}) { next if(!exists $dep{$_}); next if($_ eq 'printout' || $_ eq 'cpy');# || $_ eq 'get_msg' || $_ eq 'issue_cmd'); print "\t\"$d\" -> \"$_\"\n"; $clist{$d} = 1; $clist{$_} = 1; } } foreach my $d (keys %clist) { print "\t\"$d\" [color=$color_list[$cols{$d}]]\n"; } print "}\n";