File: genstates

package info (click to toggle)
mpich2 1.2.1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,904 kB
  • ctags: 65,947
  • sloc: ansic: 343,583; makefile: 55,174; java: 34,959; sh: 27,558; perl: 17,355; cpp: 10,472; python: 9,649; f90: 5,753; fortran: 5,128; cs: 4,019; csh: 152; xml: 91; php: 8
file content (272 lines) | stat: -rwxr-xr-x 7,274 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#! /usr/bin/perl
use File::Find;

%states = ();

# Find all the source and header files and parse the states.
find sub
{
	if ($File::Find::name =~ /\.[ich]$/)
	{
		%local_states = ();
		$line_no = 1;
		$previous_line_no = 1;
		$filename = $File::Find::name;
		#printf("opening $_\n");
		open (F, "$_") or die "unable to open $_";
		while (<F>)
		{
			chomp;
			if (/STATE_DECL\((.+)\)/)
			{
				if (!/^#\s*define/)
				{
					if ($local_states{$1} eq "declared")
					{
						printf("$filename:$previous_line_no:$line_no\n");
						printf("ERROR: no FUNC_ENTER/EXIT for declared state '$1'\n");
					}
#					if ($local_states{$1} eq "entered")
#					{
#						# This actually could be a nested state declaration of the same name.
#						printf("$filename:$line_no\n");
#						printf("ERROR: no FUNC_EXIT for state '$1'\n");
#					}
					#printf("state declared: $1\n");
					if (/\s+\\\s*/)
					{
						# Assume that if the declared state is in a macro then it will be correctly entered and exited.
						# Otherwise it is too hard to parse the file.
						$local_states{$1} = "exited";
					}
					else
					{
						$local_states{$1} = "declared";
					}
					$previous_line_no = $line_no;
				}
			}
			if (/FUNC_ENTER.*\((.+)\)/)
			{
				if ( (!/^#\s*define/) && (!/\s+\\\s*/) )
				{
					if ($local_states{$1} eq "declared")
					{
						#printf("state entered: '$1'\n");
						$local_states{$1} = "entered";
					}
					else
					{
						if (!defined($local_states{$1}))
						{
							printf("$filename:$line_no\n");
							printf("ERROR: FUNC_ENTER for undefined state '$1'\n");
						}
						if ($local_states{$1} eq "entered")
						{
							printf("$filename:$line_no\n");
							printf("ERROR: FUNC_ENTER repeated for state '$1'\n");
						}
#						if ($local_states{$1} eq "exited")
#						{
#							printf("$filename:$line_no\n");
#							printf("Warning: FUNC_ENTER after FUNC_EXIT for state '$1'\n");
#						}
					}
				}
			}
			if (/FUNC_EXIT.*\((.+)\)/)
			{
				if ( (!/^#\s*define/) && (!/\s+\\\s*/) )
				{
					if (($local_states{$1} eq "entered") || ($local_states{$1} eq "exited"))
					{
						#printf("state exited: $1\n");
						$local_states{$1} = "exited";
					}
					else
					{
						if (!defined($local_states{$1}))
						{
							printf("$filename:$line_no\n");
							printf("ERROR: FUNC_EXIT for undefined state '$1'\n");
						}
						if ($local_states{$1} eq "declared")
						{
							printf("$filename:$line_no\n");
							printf("ERROR: FUNC_EXIT without FUNC_ENTER for state '$1'\n");
						}
					}
				}
			}
			$line_no = $line_no + 1;
		}
		close F;
		foreach (keys(%local_states))
		{
			if ($local_states{$_} eq "declared")
			{
				printf("$filename:\n");
				printf("ERROR: no FUNC_ENTER/EXIT for declared state $_\n");
			}
			else
			{
				if ($local_states{$_} eq "entered")
				{
					printf("$filename:\n");
					printf("ERROR: FUNC_ENTER without FUNC_EXIT for state $_\n");
				}
				else
				{
					if (!($_ eq ""))
					{
						$states{$_} = "NULL";
					}
				}
			}
		}
	}
}, "src";

@states = sort keys(%states);

# Remove the MPID_STATE_ prefix
foreach (@states)
{
	if ( !($_ eq "") )
	{
		/(MPID_STATE_)(.+)/;
		$display_names{"$1$2"} = "$2";
	}
}

# Find all the describe_states.txt files and parse them
find sub
{
	if ($_ eq "describe_states.txt")
	{
		open F, $_;
		$line_no = 1;
		while (<F>)
		{
			chomp;
			# Check for a line with a display name and a color
			/\s*(\S+)(\s+)(\S+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+).*/;
			if (defined($1) && defined($2) && defined($3) && defined($4) && defined($5) && defined($6) && defined($7) && defined($8) && defined($9))
			{
				if (!defined($states{$1}))
				{
					printf("Warning1: described state '$1' not used, consider removing it from $File::Find::name:$line_no\n");
				}
				$display_names{$1} = "$3";
				$states{$1} = "\"$5 $7 $9\"";
			}
			else
			{
				# Check for a line with just a color
				/\s*(\S+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+).*/;
				if (defined($1) && defined($2) && defined($3) && defined($4) && defined($5) && defined($6) && defined($7))
				{
					if (!defined($states{$1}))
					{
						printf("Warning2: described state '$1' not used, consider removing it from $File::Find::name:$line_no\n");
					}
					$states{$1} = "\"$3 $5 $7\"";
				}
				else
				{
					# Check for a line with just a display name
					/\s*(\S+)(\s+)(\S+).*/;
					if (defined($1) && defined($2) && defined($3))
					{
						if (!defined($states{$1}))
						{
							printf("Warning3: described state '$1' not used, consider removing it from $File::Find::name:$line_no\n");
						}
						$display_names{$1} = "$3";
					}
				}
			}
			$line_no = $line_no + 1;
		}
		close F;
	}
}, "src";

# FIXME: It would be better to assemble this from just the relevant 
# modules, rather than all files.  A directory-based approach, such as
# that from extractstrings, could be used.
#
open HFILE, ">src/include/mpiallstates.h"
	or die "Unable to open src/include/mpiallstates.h";
print HFILE "/* -*- Mode: C; c-basic-offset:4 ; -*- */\n";
print HFILE "/*\n";
print HFILE " *  (C) 2001 by Argonne National Laboratory.\n";
print HFILE " *      See COPYRIGHT in top-level directory.\n";
print HFILE " */\n";
print HFILE "\n";
print HFILE "/* automatically generated by maint/genstates */\n";
print HFILE "\n";
print HFILE "#ifndef MPIALLSTATES_H_INCLUDED\n";
print HFILE "#define MPIALLSTATES_H_INCLUDED\n";
print HFILE "\n";
print HFILE "/* Insert all the states to be logged here */\n";
print HFILE "\n";
print HFILE "enum MPID_TIMER_STATE\n";
print HFILE "{\n";
foreach (@states)
{
	if ( !($_ eq "") )
	{
		print HFILE "$_,\n";
	}
}
print HFILE "MPID_NUM_TIMER_STATES\n";
print HFILE "};\n";
print HFILE "\n";
print HFILE "#endif\n";
close HFILE;

# FIXME: This is RLOG specific and should be placed in the appropriate 
# RLOG directory, not common.  
# FIXME: It would also make more sense for the RLOG_Describe_state routine
# to perform the random color assignement when provided with an empty
# or null color string, rather than including all of this code in what is
# otherwise an RLOG-specific file.

open F, ">src/util/logging/common/describe_states.c"
	or die "Unable to open src/util/logging/common/describe_states.c";
print F "/* -*- Mode: C; c-basic-offset:4 ; -*- */\n";
print F "/*\n";
print F " *  (C) 2001 by Argonne National Laboratory.\n";
print F " *      See COPYRIGHT in top-level directory.\n";
print F " */\n";
print F "\n";
print F "/* automatically generated by maint/genstates */\n";
print F "\n";
print F "#include \"mpiimpl.h\"\n";
print F "\n";
print F "/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build\n";
print F "   the MPI routines */\n";
print F "#ifndef MPICH_MPI_FROM_PMPI\n";
print F "\n";
print F "#ifdef HAVE_TIMING\n";
print F "\n";
print F "#if (USE_LOGGING == MPID_LOGGING_RLOG)\n";
print F "\n";
print F "int MPIR_Describe_timer_states()\n";
print F "{\n";
print F "\n";
foreach (@states)
{
	if ( !($_ eq "") )
	{
		print F "    RLOG_DescribeState(g_pRLOG, $_, \"$display_names{$_}\", $states{$_});\n";
	}
}
print F "    return 0;\n";
print F "}\n";
print F "\n";
print F "#endif /* USE_LOGGING == MPID_LOGGING_RLOG */\n";
print F "#endif /* HAVE_TIMING */\n";
print F "#endif /* MPICH_MPI_FROM_PMPI */\n";