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