annotate src/fftw-3.3.5/mpi/genf03-wrap.pl @ 43:5ea0608b923f

Current zlib source
author Chris Cannam
date Tue, 18 Oct 2016 14:33:52 +0100
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 #!/usr/bin/perl -w
Chris@42 2 # Generate Fortran 2003 wrappers (which translate MPI_Comm from f2c) from
Chris@42 3 # function declarations of the form (one per line):
Chris@42 4 # extern <type> fftw_mpi_<name>(...args...)
Chris@42 5 # extern <type> fftw_mpi_<name>(...args...)
Chris@42 6 # ...
Chris@42 7 # with no line breaks within a given function. (It's too much work to
Chris@42 8 # write a general parser, since we just have to handle FFTW's header files.)
Chris@42 9 # Each declaration has at least one MPI_Comm argument.
Chris@42 10
Chris@42 11 sub canonicalize_type {
Chris@42 12 my($type);
Chris@42 13 ($type) = @_;
Chris@42 14 $type =~ s/ +/ /g;
Chris@42 15 $type =~ s/^ //;
Chris@42 16 $type =~ s/ $//;
Chris@42 17 $type =~ s/([^\* ])\*/$1 \*/g;
Chris@42 18 $type =~ s/double/R/;
Chris@42 19 $type =~ s/fftw_([A-Za-z0-9_]+)/X(\1)/;
Chris@42 20 return $type;
Chris@42 21 }
Chris@42 22
Chris@42 23 while (<>) {
Chris@42 24 next if /^ *$/;
Chris@42 25 if (/^ *extern +([a-zA-Z_0-9 ]+[ \*]) *fftw_mpi_([a-zA-Z_0-9]+) *\((.*)\) *$/) {
Chris@42 26 $ret = &canonicalize_type($1);
Chris@42 27 $name = $2;
Chris@42 28
Chris@42 29 $args = $3;
Chris@42 30
Chris@42 31
Chris@42 32 print "\n$ret XM(${name}_f03)(";
Chris@42 33
Chris@42 34 $comma = "";
Chris@42 35 foreach $arg (split(/ *, */, $args)) {
Chris@42 36 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@42 37 $argtype = &canonicalize_type($1);
Chris@42 38 $argname = $2;
Chris@42 39 print $comma;
Chris@42 40 if ($argtype eq "MPI_Comm") {
Chris@42 41 print "MPI_Fint f_$argname";
Chris@42 42 }
Chris@42 43 else {
Chris@42 44 print "$argtype $argname";
Chris@42 45 }
Chris@42 46 $comma = ", ";
Chris@42 47 }
Chris@42 48 print ")\n{\n";
Chris@42 49
Chris@42 50 print " MPI_Comm ";
Chris@42 51 $comma = "";
Chris@42 52 foreach $arg (split(/ *, */, $args)) {
Chris@42 53 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@42 54 $argtype = &canonicalize_type($1);
Chris@42 55 $argname = $2;
Chris@42 56 if ($argtype eq "MPI_Comm") {
Chris@42 57 print "$comma$argname";
Chris@42 58 $comma = ", ";
Chris@42 59 }
Chris@42 60 }
Chris@42 61 print ";\n\n";
Chris@42 62
Chris@42 63 foreach $arg (split(/ *, */, $args)) {
Chris@42 64 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@42 65 $argtype = &canonicalize_type($1);
Chris@42 66 $argname = $2;
Chris@42 67 if ($argtype eq "MPI_Comm") {
Chris@42 68 print " $argname = MPI_Comm_f2c(f_$argname);\n";
Chris@42 69 }
Chris@42 70 }
Chris@42 71
Chris@42 72 $argnames = $args;
Chris@42 73 $argnames =~ s/([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) */$2/g;
Chris@42 74 print " ";
Chris@42 75 print "return " if ($ret ne "void");
Chris@42 76 print "XM($name)($argnames);\n}\n";
Chris@42 77 }
Chris@42 78 }