all_romio_symbols 4.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#! /usr/bin/env perl
#
# (C) 2014 by Argonne National Laboratory.
#     See COPYRIGHT in top-level directory.
#

use warnings;
use strict;

# Check to make sure the file was passed in as a parameter
if ($#ARGV != 0) {
    print "Usage: buildiface <filename>\n";
    exit 1;
}

open(FD, $ARGV[0]) || die "Could not open file " . $ARGV[0];

while (<FD>) {
    if (/\/\*\s*Begin Prototypes/) { last; }
}

my $eol = 1;
my $fullline = "";
my $tab = "    ";
my $retarg;
my $routine;
my $args;
my @arglist;
my $fname;
my $cdesc_routine;
my $x;
my $y;
my @argbits;
my $num_dtypes;
my @dtype_bind;
my $io_header;
my $make_exists = 0;

open(OUTFD, ">all_romio_symbols.c") || die "Could not open file all_romio_symbols.c";
print OUTFD <<EOT;
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 *  (C) 2014 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 *
 * This file is automatically generated by buildiface
 * DO NOT EDIT
 */

/*
 * This file is created for the sole purpose of referencing all the symbols
 * in ROMIO.
 *
 * All ROMIO public symbols are being added into the libromio convenience
 * library, which is LIBADD'ed into libmpi.  The correct behavior would
 * be for libtool to add -Wl,--whole-archive to the link line, thus
 * forcing all symbols in libromio to end up in libmpi.  However, in some
 * cases, this is not working out correctly.  For example, with the
 * Absoft compiler, the linker flags were being reordered thus causing
 * the -Wl,--whole-archive flag to not correspond to libromio.
 * Consequently, only symbols that were used from within the other
 * functions of libmpi were being included.
 *
 * In the past, we got lucky in two ways:
 *
 * 1. We were including all the Fortran 77 symbols into libmpi.  Since
 * the Fortran symbols were calling the C ROMIO symbols, those ROMIO
 * symbols were pulled in even without -Wl,--whole-archive.
 *
 * 2. The problem only showed up with absoft and nag, both of which are
 * Fortran-only compilers.  If a C compiler has this issue, it should
 * have shown up when Fortran support is disabled.
 */

#include <stdio.h>
#include "mpi.h"

void MPIR_All_romio_symbols(void);
void MPIR_All_romio_symbols(void)
{
#ifdef MPI_MODE_RDONLY
EOT

while (<FD>) {
    if (/\/\*\s*End Prototypes/) { last; }

    if (/\/\*\s*Begin Skip Prototypes/) {
        while (<FD>) {
            if (/\/\*\s*End Skip Prototypes/) { last; }
        }
    }

    # If we found a semi-colon at the end, that's the end of the line.
    # This is not perfect (e.g., does not work when a single line has
    # multiple semi-colon separated statements), but should be good
    # enough for the MPICH mpi.h file
    if (/.*;/) { $eol = 1; }
    else { $eol = 0; }

    chomp($_);
    $fullline .= "$_";
    if ($eol == 0) { next; }

    # We got the entire prototype in a single line

    # parse out comments
    $fullline =~ s+/\*.*\*/++g;

    # parse out attributes
    $fullline =~ s/MPICH_ATTR_POINTER_WITH_TYPE_TAG\(.*\)//g;

    # cleanup pointer format
    $fullline =~ s/\s*\*/* /g;

    # parse out unnecessary spaces
    $fullline =~ s/^\s*//g;
    $fullline =~ s/\s*$//g;
    $fullline =~ s/\s*;/;/g;
    $fullline =~ s/\s\s*/ /g;

    # split the line into the return type, routine name, and arguments
    $fullline =~ m/([^ ]*) ([^(]*)\((.*)\)/;
    $retarg = $1;
    $routine = $2;
    $args = $3;

    # cleanup args
    $args =~ s/^\s*//g;
    $args =~ s/\s*$//g;

    @arglist = split(/,/, $args);

    for ($x = 0; $x <= $#arglist; $x++) {
	$arglist[$x] =~ s/^\s*//g;
	$arglist[$x] =~ s/\s*$//g;
    }

    print OUTFD "${tab}{\n";
    for ($x = 0; $x <= $#arglist; $x++) {
	print OUTFD "${tab}${tab}$arglist[$x]";
	if ($arglist[$x] =~ /\*/) {
	    print OUTFD " = NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_Comm/) {
	    print OUTFD " = MPI_COMM_NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_Info/) {
	    print OUTFD " = MPI_INFO_NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_File/) {
	    print OUTFD " = MPI_FILE_NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_Datatype/) {
	    print OUTFD " = MPI_DATATYPE_NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_Errhandler/) {
	    print OUTFD " = MPI_ERRHANDLER_NULL;\n";
	}
	elsif ($arglist[$x] =~ /MPI_Offset/) {
	    print OUTFD " = 0;\n";
	}
	elsif ($arglist[$x] =~ /int/) {
	    print OUTFD " = 0;\n";
	}
	else {
	    print "$arglist[$x]\n";
	    print OUTFD ";\n";
	}
    }
    print OUTFD "\n${tab}${tab}$routine(";
    for ($x = 0; $x <= $#arglist; $x++) {
	@argbits = split(/ /, $arglist[$x]);

	if ($x < $#arglist) {
	    print OUTFD "$argbits[$#argbits], ";
	}
	else {
	    print OUTFD "$argbits[$#argbits]);\n";
	}
    }
    print OUTFD "${tab}}\n\n";

    $fullline = "";
}

# A few symbols are not in mpio.h
print OUTFD <<EOT;
    {
        MPI_Fint fh = 0;

        MPI_File_f2c(fh);
    }

    {
        MPI_File fh = MPI_FILE_NULL;

        MPI_File_c2f(fh);
    }
#endif /* MPI_MODE_RDONLY */
}
EOT

close FD;
close OUTFD;