2525class FortranBinding :
2626 """Class for generating the binding for a single function."""
2727
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 ):
2929 # Generate bigcount interface version
3030 self .bigcount = bigcount
3131 self .fn_name = template .prototype .name
3232 self .out = out
3333 self .template = template
3434 self .needs_ts = needs_ts
35+ self .gen_f90 = gen_f90
3536 self .parameters = []
3637 for param in self .template .prototype .params :
3738 self .parameters .append (param .construct (fn_name = self .fn_name ,
38- bigcount = bigcount ))
39+ bigcount = bigcount ,
40+ gen_f90 = gen_f90 ))
3941
4042 def dump (self , * pargs , ** kwargs ):
4143 """Write to the output file."""
@@ -74,6 +76,19 @@ def _use_stmts(self):
7476 stmts .append (f'use :: { mod } , only: { names } ' )
7577 return stmts
7678
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+
7792 def _print_fortran_interface (self ):
7893 """Output the C subroutine binding for the Fortran code."""
7994 name = self .c_func_name
@@ -92,6 +107,9 @@ def _print_fortran_interface(self):
92107 for stmt in use_stmts :
93108 self .dump (f' { stmt } ' )
94109 self .dump (' implicit none' )
110+ include_stmts = self ._include_stmts ()
111+ for stmt in include_stmts :
112+ self .dump (f' { stmt } ' )
95113 for param in self .parameters :
96114 self .dump (f' { param .declare_cbinding_fortran ()} ' )
97115 self .dump (f' INTEGER, INTENT(OUT) :: { consts .FORTRAN_ERROR_NAME } ' )
@@ -108,17 +126,24 @@ def _print_fortran_header(self, is_interface=False):
108126 for stmt in use_stmts :
109127 self .dump (f' { stmt } ' )
110128 self .dump (' implicit none' )
129+ # Include statements
130+ include_stmts = self ._include_stmts ()
131+ for stmt in include_stmts :
132+ self .dump (f' { stmt } ' )
111133 # Parameters/dummy variable declarations
112134 for param in self .parameters :
113135 if is_interface :
114136 self .dump_lines (param .interface_predeclare ())
115137 self .dump_lines (param .declare ())
116138 # 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 } ' )
118143
119144 def _print_fortran_subroutine (self ):
120145 """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 )
122147 params = [param .name for param in self .parameters ]
123148 params .append (consts .FORTRAN_ERROR_NAME )
124149 lines = util .break_param_lines_fortran (f'subroutine { sub_name } (' , params , ')' )
@@ -127,7 +152,7 @@ def _print_fortran_subroutine(self):
127152
128153 def _print_fortran_subroutine_end (self ):
129154 """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 )
131156 self .dump (f'end subroutine { sub_name } ' )
132157
133158 def dump_lines (self , line_text ):
@@ -210,18 +235,20 @@ def print_profiling_rename_macros(templates, out, args):
210235
211236 Previously hardcoded in mpi-f08-rename.h.
212237 """
238+ gen_f90 = True if args .fort_std == 'f90' else False
213239 out .dump ('#if OMPI_BUILD_MPI_PROFILING' )
214240 for template in templates :
215241 has_buffers = util .prototype_has_buffers (template .prototype )
216242 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 )
218244 out .dump (f'#define { name } P{ name } ' )
219245 # Check for bigcount version
220246 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 )
222248 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 } ' )
225252 out .dump ('#endif /* OMPI_BUILD_MPI_PROFILING */' )
226253
227254
@@ -246,9 +273,9 @@ def print_c_source_header(out):
246273 out .dump ('#include "bigcount.h"' )
247274
248275
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 ):
250277 """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 )
252279 if lang == 'fortran' :
253280 binding .print_f_source ()
254281 else :
@@ -267,6 +294,11 @@ def generate_code(args, out):
267294 """Generate binding code based on arguments."""
268295 templates = load_function_templates (args .prototype_files )
269296
297+ if args .fort_std == 'f08' or args .fort_std == None :
298+ gen_f90 = False
299+ else :
300+ gen_f90 = True
301+
270302 if args .lang == 'fortran' :
271303 print_f_source_header (out )
272304 out .dump ()
@@ -279,8 +311,8 @@ def generate_code(args, out):
279311 out .dump ()
280312 has_buffers = util .prototype_has_buffers (template .prototype )
281313 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 :
284316 out .dump ()
285317 print_binding (template .prototype , args .lang , bigcount = True , out = out , template = template , needs_ts = needs_ts )
286318
@@ -292,14 +324,19 @@ def generate_interface(args, out):
292324 templates = load_function_templates (args .prototype_files )
293325 print_profiling_rename_macros (templates , out , args )
294326
327+ if args .fort_std == 'f08' or args .fort_std == None :
328+ gen_f90 = False
329+ else :
330+ gen_f90 = True
331+
295332 for template in templates :
296333 ext_name = util .ext_api_func_name (template .prototype .name )
297334 out .dump (f'interface { ext_name } ' )
298335 has_buffers = util .prototype_has_buffers (template .prototype )
299336 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 )
301338 binding .print_interface ()
302- if util .prototype_has_bigcount (template .prototype ):
339+ if util .prototype_has_bigcount (template .prototype ) and gen_f90 == False :
303340 out .dump ()
304341 binding_c = FortranBinding (template .prototype , out = out , template = template ,
305342 needs_ts = needs_ts , bigcount = True )
0 commit comments