#!/home/ivan/bin/perl -s
$VERSION = '0.55';
use strict;
use warnings;
use CallGraph::Lang::Fortran;
our $indent = 8 unless defined $indent;
our $dups = 0 unless defined $dups;
our $type = 'tree' unless defined $type;
my $graph = CallGraph::Lang::Fortran->new(files => [@ARGV]);
if ($type eq 'reverse') {
for my $sub ($graph->subs) {
printf "%s:\t %s\n", $sub->name, join(", ", map {$_->name} $sub->callers);
}
} elsif ($type eq 'forward') {
for my $sub ($graph->subs) {
printf "%s:\t %s\n", $sub->name, join(", ", map {$_->name} $sub->calls);
}
} else {
print $graph->dump(indent => $indent, dups => $dups);
}
__END__
=head1 NAME
pflow - command line utility for printing the call graph of a fortran program
=head1 SYNOPSIS
pflow [-indent=8] [-dups=0] [-type=tree] *.f
=head1 DESCRIPTION
This is a simplified Perl version of the FLOW program
L<http://www.netlib.org/floppy/contents.html#link13>. It takes Fortran 77
source code and prints a call graph.
The output looks something like this:
MAIN
EXTSUB *
1 SUB1
SUB11
SUB12
SUB2
SUB1 (1)
SUB21
This means that MAIN calls EXTSUB, which is labeled with an asterisk because it
is external (meaning it is not defined within the program that was parsed),
SUB1, and SUB2. SUB1 calls SUB11 and SUB12. SUB2 calls SUB1; to avoid
duplication, a link is made by labeling SUB1 with a 1. This is the default
behavior, with 'dups' => 0. When dups => 1, the branch is duplicated:
MAIN
EXTSUB *
SUB1
SUB11
SUB12
SUB2
SUB1
SUB11
SUB12
SUB21
In case of recursion, the label system is used even with dups => 1, to avoid
an endless loop.
=head1 OPTIONS
=over
=item indent
The number of spaces to indent each call level. The default is 8.
=item dups
If true, duplicate a branch that has already been called. If false,
place a level pointing to the first place where the branch was defined.
The default is false.
=item type
Specify which type of dump should be used. There are several options:
=over
=item tree
The default; print a call tree (like the examples shown in the DESCRIPTION
section.
=item forward
Print one subroutine per line, followed by the list of all the subroutines that
it calls.
=item reverse
Print one subroutines per line, followed by the list of all the subroutines
that call it.
=back
=back
=head1 VERSION
0.55
=head1 SEE ALSO
L<CallGraph>, L<CallGraph::Node>, L<CallGraph::Dumper>,
L<CallGraph::Lang::Fortran>. The FLOPPY and FLOW user's guide at
L<http://www.netlib.org/floppy/contents.html>.
=head1 AUTHOR
Ivan Tubert E<lt>itub@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright (c) 2004 Ivan Tubert. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms as
Perl itself.
=cut