#!/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 = (); foreach(@ARGV) { system("gcc -S '$_'"); /^(.+)\.c$/i; my $curname = 'none'; open(FILE, "$1.s") || die $!; while() { if(/^([^\.\s].+?):/) { $curname = $1; $dep{$curname} = (); } if(/call\s+(.+)/) { $dep{$curname}{$1} = 1 if(!exists $dep{$curname}{$1}); } } close(FILE); } print <<"EOT"; digraph "source tree" { overlap=scale; size="8,10"; ratio="fill"; fontsize="16"; fontname="Helvetica"; clusterrank="local"; EOT foreach my $d (keys %dep) { foreach(keys %{$dep{$d}}) { print STDERR "Warning: Symbol $_ unknown.\n" if(!exists $dep{$_}); print "\t\"$d\" -> \"$_\"\n"; } } print "}\n";