25
25
class FortranBinding :
26
26
"""Class for generating the binding for a single function."""
27
27
28
- def __init__ (self , prototype , out , template = None , bigcount = False , needs_ts = False ):
28
+ def __init__ (self , prototype , out , template = None , bigcount = False , needs_ts = False , gen_f90 = False ):
29
29
# Generate bigcount interface version
30
30
self .bigcount = bigcount
31
31
self .fn_name = template .prototype .name
32
32
self .out = out
33
33
self .template = template
34
34
self .needs_ts = needs_ts
35
+ self .gen_f90 = gen_f90
35
36
self .parameters = []
36
37
for param in self .template .prototype .params :
37
38
self .parameters .append (param .construct (fn_name = self .fn_name ,
38
- bigcount = bigcount ))
39
+ bigcount = bigcount ,
40
+ gen_f90 = gen_f90 ))
39
41
40
42
def dump (self , * pargs , ** kwargs ):
41
43
"""Write to the output file."""
@@ -74,6 +76,19 @@ def _use_stmts(self):
74
76
stmts .append (f'use :: { mod } , only: { names } ' )
75
77
return stmts
76
78
79
+ def _include_stmts (self ):
80
+ """Return a list of required includes needed."""
81
+ includes = []
82
+ names = []
83
+ for param in self .parameters :
84
+ name = param .include ()
85
+ if name != '' :
86
+ if name in names :
87
+ continue
88
+ includes .append (f'include \' { name } \' ' )
89
+ names .append (f'{ name } ' )
90
+ return includes
91
+
77
92
def _print_fortran_interface (self ):
78
93
"""Output the C subroutine binding for the Fortran code."""
79
94
name = self .c_func_name
@@ -92,6 +107,9 @@ def _print_fortran_interface(self):
92
107
for stmt in use_stmts :
93
108
self .dump (f' { stmt } ' )
94
109
self .dump (' implicit none' )
110
+ include_stmts = self ._include_stmts ()
111
+ for stmt in include_stmts :
112
+ self .dump (f' { stmt } ' )
95
113
for param in self .parameters :
96
114
self .dump (f' { param .declare_cbinding_fortran ()} ' )
97
115
self .dump (f' INTEGER, INTENT(OUT) :: { consts .FORTRAN_ERROR_NAME } ' )
@@ -108,17 +126,24 @@ def _print_fortran_header(self, is_interface=False):
108
126
for stmt in use_stmts :
109
127
self .dump (f' { stmt } ' )
110
128
self .dump (' implicit none' )
129
+ # Include statements
130
+ include_stmts = self ._include_stmts ()
131
+ for stmt in include_stmts :
132
+ self .dump (f' { stmt } ' )
111
133
# Parameters/dummy variable declarations
112
134
for param in self .parameters :
113
135
if is_interface :
114
136
self .dump_lines (param .interface_predeclare ())
115
137
self .dump_lines (param .declare ())
116
138
# Add the integer error manually
117
- self .dump (f' INTEGER, OPTIONAL, INTENT(OUT) :: { consts .FORTRAN_ERROR_NAME } ' )
139
+ if self .gen_f90 == True :
140
+ self .dump (f' INTEGER, INTENT(OUT) :: { consts .FORTRAN_ERROR_NAME } ' )
141
+ else :
142
+ self .dump (f' INTEGER, OPTIONAL, INTENT(OUT) :: { consts .FORTRAN_ERROR_NAME } ' )
118
143
119
144
def _print_fortran_subroutine (self ):
120
145
"""Output the Fortran subroutine line."""
121
- sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount , needs_ts = self .needs_ts )
146
+ sub_name = util .fortran_name (self .fn_name , bigcount = self .bigcount , gen_f90 = self . gen_f90 , needs_ts = self .needs_ts )
122
147
params = [param .name for param in self .parameters ]
123
148
params .append (consts .FORTRAN_ERROR_NAME )
124
149
lines = util .break_param_lines_fortran (f'subroutine { sub_name } (' , params , ')' )
@@ -127,7 +152,7 @@ def _print_fortran_subroutine(self):
127
152
128
153
def _print_fortran_subroutine_end (self ):
129
154
"""Output the Fortran end subroutine line."""
130
- sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount , needs_ts = self .needs_ts )
155
+ sub_name = util .fortran_name (self .fn_name , bigcount = self .bigcount , gen_f90 = self . gen_f90 , needs_ts = self .needs_ts )
131
156
self .dump (f'end subroutine { sub_name } ' )
132
157
133
158
def dump_lines (self , line_text ):
@@ -210,18 +235,20 @@ def print_profiling_rename_macros(templates, out, args):
210
235
211
236
Previously hardcoded in mpi-f08-rename.h.
212
237
"""
238
+ gen_f90 = True if args .fort_std == 'f90' else False
213
239
out .dump ('#if OMPI_BUILD_MPI_PROFILING' )
214
240
for template in templates :
215
241
has_buffers = util .prototype_has_buffers (template .prototype )
216
242
needs_ts = has_buffers and args .generate_ts_suffix
217
- name = util .fortran_f08_name (template .prototype .name , needs_ts = needs_ts )
243
+ name = util .fortran_name (template .prototype .name , gen_f90 = gen_f90 , needs_ts = needs_ts )
218
244
out .dump (f'#define { name } P{ name } ' )
219
245
# Check for bigcount version
220
246
if util .prototype_has_bigcount (template .prototype ):
221
- bigcount_name = util .fortran_f08_name (template .prototype .name , bigcount = True , needs_ts = needs_ts )
247
+ bigcount_name = util .fortran_name (template .prototype .name , bigcount = True , needs_ts = needs_ts )
222
248
out .dump (f'#define { bigcount_name } P{ bigcount_name } ' )
223
- name = util .fortran_f08_generic_interface_name (template .prototype .name )
224
- out .dump (f'#define { name } P{ name } ' )
249
+ if gen_f90 == False :
250
+ name = util .fortran_f08_generic_interface_name (template .prototype .name )
251
+ out .dump (f'#define { name } P{ name } ' )
225
252
out .dump ('#endif /* OMPI_BUILD_MPI_PROFILING */' )
226
253
227
254
@@ -246,9 +273,9 @@ def print_c_source_header(out):
246
273
out .dump ('#include "bigcount.h"' )
247
274
248
275
249
- def print_binding (prototype , lang , out , bigcount = False , template = None , needs_ts = False ):
276
+ def print_binding (prototype , lang , out , bigcount = False , template = None , needs_ts = False , gen_f90 = False ):
250
277
"""Print the binding with or without bigcount."""
251
- binding = FortranBinding (prototype , out = out , bigcount = bigcount , template = template , needs_ts = needs_ts )
278
+ binding = FortranBinding (prototype , out = out , bigcount = bigcount , template = template , needs_ts = needs_ts , gen_f90 = gen_f90 )
252
279
if lang == 'fortran' :
253
280
binding .print_f_source ()
254
281
else :
@@ -267,6 +294,11 @@ def generate_code(args, out):
267
294
"""Generate binding code based on arguments."""
268
295
templates = load_function_templates (args .prototype_files )
269
296
297
+ if args .fort_std == 'f08' or args .fort_std == None :
298
+ gen_f90 = False
299
+ else :
300
+ gen_f90 = True
301
+
270
302
if args .lang == 'fortran' :
271
303
print_f_source_header (out )
272
304
out .dump ()
@@ -279,8 +311,8 @@ def generate_code(args, out):
279
311
out .dump ()
280
312
has_buffers = util .prototype_has_buffers (template .prototype )
281
313
needs_ts = has_buffers and args .generate_ts_suffix
282
- print_binding (template .prototype , args .lang , out , template = template , needs_ts = needs_ts )
283
- if util .prototype_has_bigcount (template .prototype ):
314
+ print_binding (template .prototype , args .lang , out , template = template , needs_ts = needs_ts , gen_f90 = gen_f90 )
315
+ if util .prototype_has_bigcount (template .prototype ) and gen_f90 == False :
284
316
out .dump ()
285
317
print_binding (template .prototype , args .lang , bigcount = True , out = out , template = template , needs_ts = needs_ts )
286
318
@@ -292,14 +324,19 @@ def generate_interface(args, out):
292
324
templates = load_function_templates (args .prototype_files )
293
325
print_profiling_rename_macros (templates , out , args )
294
326
327
+ if args .fort_std == 'f08' or args .fort_std == None :
328
+ gen_f90 = False
329
+ else :
330
+ gen_f90 = True
331
+
295
332
for template in templates :
296
333
ext_name = util .ext_api_func_name (template .prototype .name )
297
334
out .dump (f'interface { ext_name } ' )
298
335
has_buffers = util .prototype_has_buffers (template .prototype )
299
336
needs_ts = has_buffers and args .generate_ts_suffix
300
- binding = FortranBinding (template .prototype , template = template , needs_ts = needs_ts , out = out )
337
+ binding = FortranBinding (template .prototype , template = template , needs_ts = needs_ts , gen_f90 = gen_f90 , out = out )
301
338
binding .print_interface ()
302
- if util .prototype_has_bigcount (template .prototype ):
339
+ if util .prototype_has_bigcount (template .prototype ) and gen_f90 == False :
303
340
out .dump ()
304
341
binding_c = FortranBinding (template .prototype , out = out , template = template ,
305
342
needs_ts = needs_ts , bigcount = True )
0 commit comments