55
66import pympistandard as std
77
8+ # ============================= Constants / Globals ============================
9+
10+ ABI_INTERNAL = "_ABI_INTERNAL"
11+
812categories = {}
13+ mangle_names = True
14+
15+ internal_datatypes = [
16+ "MPI_Comm" ,
17+ "MPI_Datatype" ,
18+ "MPI_Errhandler" ,
19+ "MPI_File" ,
20+ "MPI_Group" ,
21+ "MPI_Info" ,
22+ "MPI_Message" ,
23+ "MPI_Op" ,
24+ "MPI_Request" ,
25+ "MPI_Session" ,
26+ "MPI_Win" ,
27+ ]
928
29+ # Populating the `categories` dictionary
1030for category in consts .categories .values ():
1131 name = category ["name" ]
1232 categories [name ] = []
1333 for value in consts .consts .values ():
1434 if value ["category" ] == name :
1535 categories [name ].append (value )
1636
17- def output_constant (const , use_enum ):
37+ # ================================== Functions =================================
38+
39+ def output_constant (const , use_enum : bool , mangle_name : bool ):
1840 name = const ["name" ]
1941 abi_value = const ["abi_value" ]
2042 c_type = const ["handle_types" ]["c" ]["type" ]
2143 if c_type is None :
2244 return None
45+ if mangle_name :
46+ name = f"{ name } { ABI_INTERNAL } "
47+ c_type = f"{ c_type } { ABI_INTERNAL } "
2348 def_name = f"#define { name } "
2449 if use_enum :
2550 def_name = f" { name } "
@@ -55,7 +80,7 @@ def output_constant(const, use_enum):
5580 output .append ("enum {\n " )
5681 # Print out each `#define` / assignment for the constants
5782 for constant in categories [category ]:
58- line = output_constant (constant , use_enum )
83+ line = output_constant (constant , use_enum , mangle_names )
5984 if line is not None :
6085 output .append (line )
6186 if use_enum :
@@ -70,7 +95,8 @@ def cb_declaration(proc_expression):
7095 func_str = str (proc_expression ).replace (r"\ldots" , "..." )
7196 func_str_list = func_str .split ()
7297 func_name , arg_1 = func_str_list [2 ].split ("(" )
73- return f"{ ' ' .join (func_str_list [:2 ])} ({ func_name } )({ arg_1 } { ' ' .join (func_str_list [3 :])} ;\n "
98+ decl_string = f"{ ' ' .join (func_str_list [:2 ])} ({ func_name } )({ arg_1 } { ' ' .join (func_str_list [3 :])} ;\n "
99+ return decl_string
74100
75101std .use_api_version ()
76102
@@ -99,5 +125,21 @@ def cb_declaration(proc_expression):
99125 output .append (f"{ binding [0 ]} P{ ' ' .join (binding [1 :])} ;\n " )
100126
101127# ================================ Final Output ================================
128+ output .append ("""#ifndef _ABI_INTERNAL_
129+ #define _ABI_INTERNAL_
130+ #include "stddef.h"
131+ #include "stdint.h"
132+ """ )
133+ output .append ("#endif /* _ABI_INTERNAL_ */" )
134+
135+ # Iterate through all lines and replace datatypes with their internal ABI
136+ # counterparts
137+ if mangle_names :
138+ for i , line in enumerate (output ):
139+ mangled_line = line
140+ for datatype in internal_datatypes :
141+ mangled_line = mangled_line .replace (datatype , f"{ datatype } { ABI_INTERNAL } " )
142+ output [i ] = mangled_line
143+
102144with open (consts .DIR / "abi.h" , 'tw' ) as header_out :
103145 header_out .writelines (output )
0 commit comments