Skip to content

Commit 7d79681

Browse files
Joe-DownsJoseph Downs
authored andcommitted
WIP: create ABI header file from template with categories
1 parent 99e9992 commit 7d79681

File tree

3 files changed

+259
-220
lines changed

3 files changed

+259
-220
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* $COPYRIGHT$
3+
*
4+
* Additional copyrights may follow
5+
*
6+
* $HEADER$
7+
*/
8+
9+
typedef struct MPI_ABI_Comm * MPI_Comm;
10+
typedef struct MPI_ABI_Datatype * MPI_Datatype;
11+
typedef struct MPI_ABI_Errhandler * MPI_Errhandler;
12+
typedef struct MPI_ABI_File * MPI_File;
13+
typedef struct MPI_ABI_Group * MPI_Group;
14+
typedef struct MPI_ABI_Info * MPI_Info;
15+
typedef struct MPI_ABI_Message * MPI_Message;
16+
typedef struct MPI_ABI_Op * MPI_Op;
17+
typedef struct MPI_ABI_Request * MPI_Request;
18+
typedef struct MPI_ABI_Session * MPI_Session;
19+
typedef struct MPI_ABI_Win * MPI_Win;
20+
21+
typedef struct {
22+
int MPI_SOURCE;
23+
int MPI_TAG;
24+
int MPI_ERROR;
25+
int MPI_internal[5];
26+
} MPI_Status;
27+
28+
/* Error classes */
29+
$CATEGORY:ERROR_CLASSES$
30+
31+
/* Buffer address constants */
32+
$CATEGORY:BUFFER_ADDR_CONSTANTS$
33+
34+
/* Constants specifying empty or ignored input */
35+
$CATEGORY:EMPTY_IGNORE_INPUT_CONSTANTS$
36+
37+
/* Maximum sizes for strings */
38+
$CATEGORY:MAX_STR_SIZE_CONSTANTS$
39+
40+
/* Mode constants */
41+
$CATEGORY:MODE_CONSTANTS$
42+
43+
/* Assorted constants */
44+
$CATEGORY:ASSORTED_CONSTANTS$
45+
46+
/* Threads constants */
47+
$CATEGORY:THREADS_CONSTANTS$
48+
49+
/* File operations constants */
50+
$CATEGORY:FILE_OPERATIONS_CONSTANTS$
51+
52+
/* Datatype decoding constants */
53+
$CATEGORY:DATATYPE_DECODING_CONSTANTS$
54+
55+
/* F90 datatype matching constants */
56+
$CATEGORY:F90_DATATYPE_MATCHING_CONSTANTS$
57+
58+
/* Results of communicator and group comparisons */
59+
$CATEGORY:COMMUNICATOR_GROUP_COMP_RESULTS$
60+
61+
/* Topologies */
62+
$CATEGORY:TOPOLOGIES$
63+
64+
/* Communicator split type constants */
65+
$CATEGORY:COMMUNICATOR_SPLIT_TYPE$
66+
67+
/* Window lock type constants */
68+
$CATEGORY:WINDOW_LOCK_TYPE_CONSTANTS$
69+
70+
/* MPI window create flavors */
71+
$CATEGORY:WINDOW_CREATE_FLAVORS$
72+
73+
/* MPI window models */
74+
$CATEGORY:WINDOW_MODELS$
75+
76+
/* File positioning constants */
77+
$CATEGORY:FILE_POS_CONSTANTS$
78+
79+
/* File operation constants */
80+
$CATEGORY:FILE_OP_CONSTANTS$
81+
82+
/* Environmental inquiry and predefined attribute keys */
83+
$CATEGORY:ENV_INQ_AND_ATTR_KEYS$
84+
85+
/* Fortran support method specific constants */
86+
/* $CATEGORY:FORTRAN_SUPPORT_METHOD_CONSTANTS$ */
87+
88+
/* Status array size and reserved index values (Fortran only) */
89+
/* $CATEGORY:STATUS_ARRAY_SIZE_AND_INDEX_FORTRAN$ */
90+
91+
/* Fortran status array size and reserved index values (C only) */
92+
$CATEGORY:FORTRAN_STATUS_ARRAY_SIZE_AND_INDEX_C$
93+
94+
/* Variable address size (Fortran only) */
95+
/* $CATEGORY:VARIABLE_ADDR_SIZE_FORTRAN$ */
96+
97+
/* Reserved communicators */
98+
$CATEGORY:RESERVED_COMMUNICATORS$
99+
100+
/* Named predefined datatypes */
101+
$CATEGORY:PREDEFINED_DATATYPES$
102+
103+
/* Optional datatypes (Fortran) */
104+
$CATEGORY:OPT_DATATYPES_FORTRAN$
105+
106+
/* Datatypes for reduction functions (C) */
107+
$CATEGORY:REDUCTION_FUNC_DATATYPES_C$
108+
109+
/* Datatypes for reduction functions (Fortran) */
110+
$CATEGORY:REDUCTION_FUNC_DATATYPES_FORTRAN$
111+
112+
/* Predefined message handles */
113+
$CATEGORY:MSG_HANDLES$
114+
115+
/* Predefined error-handling specifiers */
116+
$CATEGORY:ERROR_SPECIFIERS$
117+
118+
/* Environmental inquiry info key */
119+
$CATEGORY:ENV_INQ_INFO_KEY$
120+
121+
/* Collective operators */
122+
$CATEGORY:COLLECTIVE_OPS$
123+
124+
/* Predefined group handles */
125+
$CATEGORY:GROUP_HANDLES$
126+
127+
/* Other predefined handles */
128+
$CATEGORY:OTHER_HANDLES$
129+
130+
/* Predefined functions */
131+
$CATEGORY:FUNCTIONS$
132+
133+
/* Deprecated predefined functions */
134+
$CATEGORY:DEPRECATED_FUNCS$
135+
136+
/* C preprocessor constants and Fortran parameters */
137+
$CATEGORY:C_PREPROCESSOR_CONSTANTS_FORTRAN_PARAMETERS$
138+
139+
/* Handles used in the MPI tool information interface */
140+
$CATEGORY:TOOL_INFO_IFACE_HANDLES$
141+
142+
/* Verbosity levels in the MPI tool information interface */
143+
$CATEGORY:TOOL_INFO_IFACE_VERBOSITY_LEVELS$
144+
145+
/*
146+
* Constants to identify associations of variables in the MPI tool information
147+
* interface
148+
*/
149+
$CATEGORY:TOOL_INFO_IFACE_VAR_ASSOCIATIONS$
150+
151+
/*
152+
* Constants describing the scope of a control variable in the MPI tool
153+
* information interface
154+
*/
155+
$CATEGORY:TOOL_INFO_IFACE_VAR_SCOPES$
156+
157+
/* Performance variable classes used by the MPI tool information interface */
158+
$CATEGORY:TOOL_INFO_IFACE_PVAR_CLASSES$
159+
160+
/* Source event ordering guarantees in the MPI tool information interface */
161+
$CATEGORY:TOOL_INFO_IFACE_SOURCE_ORDERINGS$
162+
163+
/*
164+
* Callback safety requirement levels used in the MPI tool information interface
165+
*/
166+
$CATEGORY:TOOL_INFO_IFACE_CB_SAFETY_REQ_LEVELS$
Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,84 @@
1+
import re
2+
import textwrap
13
import consts
4+
from consts import Lang
25

3-
lines = []
6+
categories = {}
7+
8+
def comment(message, lang=Lang.C, indentation=0):
9+
"""
10+
Take in a message and return a commented version of it.
11+
"""
12+
comment_lines = []
13+
width = 80
14+
#words = message.split()
15+
prefix = ""
16+
spaces = (indentation + 1) * ' '
17+
if lang == Lang.C or lang == Lang.CPP:
18+
comment_lines.append(spaces = "/*")
19+
prefix = " *"
20+
elif lang == Lang.FORTRAN:
21+
prefix ="!"
22+
23+
prefix = spaces + prefix + ' '
24+
comment_lines.append(textwrap.wrap(message,
25+
width=width,
26+
initial_indent=prefix,
27+
subsequent_indent=prefix))
28+
# for word in words:
29+
# line = [prefix]
30+
# cols_left = width - len(prefix)
31+
# len(word) <= cols_left:
32+
# line.append(word)
33+
# comment_lines.append()
34+
35+
if lang == Lang.C or lang == Lang.CPP:
36+
comment_lines.append(spaces + "*/")
37+
return '\n'.join(comment_lines)
38+
39+
for category in consts.categories.values():
40+
name = category["name"]
41+
categories[name] = []
42+
for value in consts.consts.values():
43+
if value["category"] == name:
44+
categories[name].append(value)
445

5-
for value in consts.consts.values():
6-
name = value["name"]
7-
abi_value = value["abi_value"]
8-
c_type = value["handle_types"]["c"]["type"]
46+
def output_constant(const):
47+
# TODO: Use enums for ints? (ask Howard)
48+
name = const["name"]
49+
abi_value = const["abi_value"]
50+
c_type = const["handle_types"]["c"]["type"]
951
if c_type is None:
10-
continue
52+
return None
1153
def_name = f"#define {name}"
1254
if c_type == "int":
13-
value = f"{abi_value}\n"
55+
value = f"{abi_value}"
56+
else:
57+
value = f"(({c_type}) {abi_value})"
58+
return def_name + " " * (45 - len(def_name)) + value + "\n"
59+
60+
lines = []
61+
with open(consts.DIR / "abi.h.in", 'r') as header_in:
62+
lines = header_in.readlines()
63+
64+
# Match lines that start with `$CATEGORY:`. Any amount of whitespace is allowed
65+
# in the case of indenting. However, only preceding whitespace is allowed so
66+
# that commented-out lines are NOT included.
67+
category_pattern = re.compile(r"^[\s]*\$CATEGORY:([A-Z_0-9]+)\$$")
68+
output = []
69+
70+
for line in lines:
71+
category = category_pattern.search(line)
72+
# If there's no match, category is None. Then we just want to preserve the
73+
# line as-is.
74+
if category:
75+
category = category.group(1)
76+
for constant in categories[category]:
77+
line = output_constant(constant)
78+
if line is not None:
79+
output.append(line)
1480
else:
15-
value = f"(({c_type}) {abi_value})\n"
16-
line = def_name + " " * (45 - len(def_name)) + value
17-
lines.append(line)
81+
output.append(line)
1882

19-
with open(consts.DIR / "mpi_abi.h", 'wt') as header:
20-
header.writelines(lines)
83+
with open(consts.DIR / "abi.h", 'tw') as header_out:
84+
header_out.writelines(output)

0 commit comments

Comments
 (0)