comparison src/fftw-3.3.3/mpi/genf03-wrap.pl @ 10:37bf6b4a2645

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