forked from ROCm/hcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathompts_parserFunctions.pm
executable file
·280 lines (253 loc) · 7.87 KB
/
ompts_parserFunctions.pm
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
273
274
275
276
277
278
279
280
#!/usr/bin/perl -w
# functions.pm
# This package contains a set of subroutines to modify the templates for the openMP Testuite.
################################################################################
# subroutines to extract, modify or delete tags from the template
################################################################################
# LIST get_tag_values( $tagname, $string )
# subrutine to get the text encloded by a tag.
# Returns a list containing the inner texts of the found tags
sub get_tag_values
{
my ( $tagname, $string );
( $tagname, $string ) = @_;
my (@tmp,@tmp2);
@tmp = split(/\<$tagname\>/,$string);
foreach $_(@tmp){
push(@tmp2,split(/\<\/$tagname\>/));
}
my(@result,$i);
$i=1; # couter to get only every second item
foreach $_(@tmp2){
if($i%2 eq 0){
push(@result,$_);
}
$i++;
}
return @result;
}
# LIST replace_tags( $tagname, $replacestring, @list )
# subrutine to replace tags by a replacestring.
# Returns a list of the srings after conversion.
sub replace_tags
{
my ($tagname, $replacestring, @stringlist, @result);
($tagname, $replacestring, @stringlist) = @_;
foreach $_(@stringlist) {
s#\<$tagname\>(.*?)\<\/$tagname\>#$replacestring#gs;
push(@result,$_);
}
return @result;
}
# LIST enlarge_tags( $tagname, $before, $after, @list )
# subrutine to replace tags by the tags added by a string before and after.
# Returns a list of the srings after conversion.
sub enlarge_tags
{
my ($tagname, $before, $after, @stringlist,@result);
($tagname, $before, $after, @stringlist) = @_;
foreach $_(@stringlist) {
s#\<$tagname\>(.*?)\<\/$tagname\>#$before$1$after#gs;
push(@result,$_);
}
return @result;
}
# LIST delete_tags( $tagname, @list )
# subrutine to delete tags in a string.
# Returns a list of the cleared strings
sub delete_tags
{
my($tagname,@stringlist);
($tagname, @stringlist) = @_;
my(@result);
foreach $_(@stringlist) {
s#\<$tagname\>(.*?)\<\/$tagname\>##gs;
push(@result,$_);
}
return @result;
}
################################################################################
# subroutines for generating "orpahned" tests
################################################################################
# SCALAR create_orph_cfunctions( $prefix, $code )
# returns a string containing the definitions of the functions for the
# orphan regions.
sub create_orph_cfunctions
{
my ($code,@defs);
($code) = @_;
@defs = get_tag_values('ompts:orphan',$code);
($functionname) = get_tag_values('ompts:testcode:functionname',$code);
my ( @result,$functionsrc, $i);
$functionsrc = "\n/* Automatically generated definitions of the orphan functions */\n";
$i = 1;
foreach (@defs) {
$functionsrc .= "\nvoid orph$i\_$functionname (FILE * logFile) {";
$functionsrc .= $_;
$functionsrc .= "\n}\n";
$i++;
}
$functionsrc .= "/* End of automatically generated definitions */\n";
return $functionsrc;
}
# SCALAR create_orph_fortranfunctions( $prefix, $code )
# returns a string containing the definitions of the functions for the
# orphan regions.
sub create_orph_fortranfunctions
{
my ($prefix,$code,@defs,$orphan_parms);
($prefix,$code,$orphan_parms) = @_;
@defs = get_tag_values('ompts:orphan',$code);
#to remove space and put a single space
if($orphan_parms ne "")
{
$orphan_parms =~ s/[ \t]+//sg;
$orphan_parms =~ s/[ \t]+\n/\n/sg;
}
($orphanvarsdefs) = get_tag_values('ompts:orphan:vars',$code);
foreach (@varsdef) {
if (not /[^ \n$]*/){ $orphanvarsdefs = join("\n",$orphanvarsdef,$_);}
}
($functionname) = get_tag_values('ompts:testcode:functionname',$code);
my ( @result,$functionsrc, $i);
$functionsrc = "\n! Definitions of the orphan functions\n";
$i = 1;
foreach $_(@defs)
{
$functionsrc .= "\n SUBROUTINE orph$i\_$prefix\_$functionname\($orphan_parms\)\n ";
$functionsrc .= "INCLUDE \"omp_testsuite.f\"\n";
$functionsrc .= $orphanvarsdefs."\n";
$functionsrc .= $_;
$functionsrc .= "\n";
$functionsrc .= " END SUBROUTINE\n! End of definition\n\n";
$i++;
}
return $functionsrc;
}
# LIST orphan_regions2cfunctions( $prefix, @code )
# replaces orphan regions by functioncalls in C/C++.
sub orphan_regions2cfunctions
{
my ($code, $i, $functionname);
($code) = @_;
$i = 1;
($functionname) = get_tag_values('ompts:testcode:functionname',$code);
while( /\<ompts\:orphan\>(.*)\<\/ompts\:orphan\>/s) {
s#\<ompts\:orphan\>(.*?)\<\/ompts\:orphan\>#orph$i\_$functionname (logFile);#s;
$i++;
}
return $code;
}
# LIST orphan_regions2fortranfunctions( $prefix, @code )
# replaces orphan regions by functioncalls in fortran
sub orphan_regions2fortranfunctions
{
my ( $prefix, @code, $my_parms, $i, $functionname);
($prefix, ($code), $my_parms) = @_;
$i = 1;
($functionname) = get_tag_values('ompts:testcode:functionname',$code);
foreach $_(($code))
{
while( /\<ompts\:orphan\>(.*)\<\/ompts\:orphan\>/s)
{
s#\<ompts\:orphan\>(.*?)\<\/ompts\:orphan\># CALL orph$i\_$prefix\_$functionname\($my_parms\);#s;
$i++;
}
}
return ($code);
}
# SCALAR orph_functions_declarations( $prefix, $code )
# returns a sring including the declaration of the functions used
# in the orphan regions. The function names are generated using
# the $prefix as prefix for the functionname.
sub orph_functions_declarations
{
my ($prefix, $code);
($prefix, $code) = @_;
my ( @defs, $result );
# creating declarations for later used functions
$result .= "\n\n/* Declaration of the functions containing the code for the orphan regions */\n#include <stdio.h>\n";
@defs = get_tag_values('ompts:orphan',$code);
my ($functionname,$i);
($functionname) = get_tag_values('ompts:testcode:functionname',$code);
$i = 1;
foreach $_(@defs) {
$result .= "\nvoid orph$i\_$prefix\_$functionname ( FILE * logFile );";
$i++;
}
$result .= "\n\n/* End of declaration */\n\n";
return $result;
}
# SCALAR make_global_vars_definition( $code )
# returns a sring including the declaration for the vars needed to
# be declared global for the orphan region.
sub make_global_vars_def
{
my ( $code );
($code) = @_;
my ( @defs, $result, @tmp, @tmp2 ,$predefinitions);
# creating global declarations for the variables.
$result = "\n\n/* Declaration of the variables used in the orphan region. */\n";
# get all tags containing the variable definitions
@defs = get_tag_values('ompts:orphan:vars',$code);
foreach $_(@defs)
{
# cutting the different declarations in the same tag by the ';' as cuttmark
@tmp = split(/;/,$_);
foreach $_(@tmp)
{
# replacing newlines and double spaces
s/\n//gs;
s/ //gs;
# put the new declaration at the end of $result
if($_ ne ""){ $result .= "\n $_;"; }
}
}
$result .= "\n\n/* End of declaration. */\n\n";
return $result;
}
# SCALAR extern_vars_definition( $code )
# returns a sring including the declaration for the vars needed to
# be declared extern for the orphan region.
sub extern_vars_def
{
my ( $code );
($code) = @_;
my ( @defs, $result, @tmp, @tmp2 ,$predefinitions);
# creating declarations for the extern variables.
$result = "\n\n/* Declaration of the extern variables used in the orphan region. */\n";
# $result .= "\n#include <stdio.h>\n#include <omp.h>\n";
$result .= "\nextern FILE * logFile;";
# get all tags containing the variable definitions
@defs = get_tag_values('ompts:orphan:vars',$code);
foreach $_(@defs)
{
# cutting the different declarations in the same tag by the ';' as cuttmark
@tmp = split(/;/,$_);
foreach $_(@tmp)
{
# replacing newlines and double spaces
s/\n//gs;
s/ //gs;
# cutting off definitions
@tmp2 = split("=",$_);
# put the new declaration at the end of $result
$result .= "\nextern $tmp2[0];";
}
}
$result .= "\n\n/* End of declaration. */\n\n";
return $result;
}
sub leave_single_space
{
my($str);
($str)=@_;
if($str ne "")
{
$str =~ s/^[ \t]+/ /;
$str =~ s/[ \t]+\n$/\n/;
$str =~ s/[ \t]+//g;
}
return $str;
}
return 1;