Skip to content

Commit c303345

Browse files
Joe-DownsJoseph Downs
authored andcommitted
WIP: use enums for most int values
1 parent 7d79681 commit c303345

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

ompi/mpi/bindings/ompi_bindings/c_header.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ def comment(message, lang=Lang.C, indentation=0):
4343
if value["category"] == name:
4444
categories[name].append(value)
4545

46-
def output_constant(const):
47-
# TODO: Use enums for ints? (ask Howard)
46+
def output_constant(const, use_enum):
4847
name = const["name"]
4948
abi_value = const["abi_value"]
5049
c_type = const["handle_types"]["c"]["type"]
5150
if c_type is None:
5251
return None
5352
def_name = f"#define {name}"
54-
if c_type == "int":
53+
if use_enum:
54+
def_name = f" {name}"
55+
value = f"= {abi_value},"
56+
elif c_type == "int":
5557
value = f"{abi_value}"
5658
else:
5759
value = f"(({c_type}) {abi_value})"
@@ -73,10 +75,19 @@ def output_constant(const):
7375
# line as-is.
7476
if category:
7577
category = category.group(1)
78+
use_enum = False
79+
# Only some values should be in `enums`, otherwise just use `#define`s
80+
if category in consts.ENUM_CATEGORIES:
81+
use_enum = True
82+
if use_enum:
83+
output.append("enum {\n")
84+
# Print out each `#define` / assignment for the constants
7685
for constant in categories[category]:
77-
line = output_constant(constant)
86+
line = output_constant(constant, use_enum)
7887
if line is not None:
7988
output.append(line)
89+
if use_enum:
90+
output.append("};\n")
8091
else:
8192
output.append(line)
8293

ompi/mpi/bindings/ompi_bindings/consts.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ class Lang(Enum):
3737
#
3838
# C type: const int
3939

40+
ENUM_CATEGORIES = [
41+
"ERROR_CLASSES",
42+
"MODE_CONSTANTS",
43+
"ASSORTED_CONSTANTS",
44+
"THREADS_CONSTANTS",
45+
"FILE_OPERATIONS_CONSTANTS",
46+
"DATATYPE_DECODING_CONSTANTS",
47+
"F90_DATATYPE_MATCHING_CONSTANTS",
48+
"COMMUNICATOR_GROUP_COMP_RESULTS",
49+
"TOPOLOGIES",
50+
"COMMUNICATOR_SPLIT_TYPE",
51+
"WINDOW_LOCK_TYPE_CONSTANTS",
52+
"WINDOW_CREATE_FLAVORS",
53+
"WINDOW_MODELS",
54+
"FILE_POS_CONSTANTS",
55+
"FILE_OP_CONSTANTS",
56+
"ENV_INQ_AND_ATTR_KEYS",
57+
"FORTRAN_STATUS_ARRAY_SIZE_AND_INDEX_C",
58+
"C_PREPROCESSOR_CONSTANTS_FORTRAN_PARAMETERS",
59+
"TOOL_INFO_IFACE_VERBOSITY_LEVELS",
60+
"TOOL_INFO_IFACE_VAR_ASSOCIATIONS",
61+
"TOOL_INFO_IFACE_VAR_SCOPES",
62+
"TOOL_INFO_IFACE_PVAR_CLASSES",
63+
"TOOL_INFO_IFACE_SOURCE_ORDERINGS",
64+
"TOOL_INFO_IFACE_CB_SAFETY_REQ_LEVELS",
65+
]
66+
67+
4068
C_OPAQUE_TYPES = {
4169
'MPI_Aint': 'intptr_t',
4270
'MPI_Offset': 'int64_t',

0 commit comments

Comments
 (0)