blob: 98d7271fcbd05b0a717240ca5a88c2e776b1102f [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001#!/usr/bin/env perl
2
3# ompts_parser [option] SOURCEFILE
4#
5# Creats the tests and the crosstests for the OpenMP-Testsuite out of an templatefiles which are given to the programm.
6#
7# Options:
8# -test: make test
9# -crosstest: make crosstest
10# -orphan if possible generate tests using orphan regions (not implemented yet)
11# -lang=LANG preprocessing for language LANG, where LANG is one of the following languages:
12# c, fortran
13# -o=FILENAME outputfile (only when one templatefile is specified)
14
15
16# Using Getopt::long to extract the programm options
17use Getopt::Long;
18# Using functions: Set of subroutines to modify the testcode
19use ompts_parserFunctions;
20
21# Getting given options
22GetOptions("-test" => \$test,"-crosstest" => \$crosstest, "-o=s" => \$outputfile, "-orphan" => \$orphan, "-f!", "-lang=s" => \$language);
23
24# Remaining arguments are the templatefiles.
25# Adding these to the list of to be parsed files if they exist.
26foreach $file(@ARGV)
27{
28 if(-e $file){ push(@sourcefiles,$file); }
29 else { print "Error: Unknown Option $file\n"; }
30}
31
32# Checking if options were valid:
33#################################################################
34# preparations and checks for sourcefiles
35if(@sourcefiles == 0){die "No files to parse are specified!";}
36if($outputfile && (@sourcefiles != 1 || ($test && $crosstest) ) ){die "There were multiple files for one outputfiles specified!";}
37# preparations fopr orphan tests
38if($orphan){ $orphanprefix = "orphaned"; }
39else { $orphanprefix = ""; }
40# preparations for test / crosstest
41if($test){push(@testtypes,"test");
42# %checks['test']="check";
43}
44if($crosstest){push(@testtypes,"ctest");
45# %checks['crosstest']="crosscheck";
46}
47# preparations and checks for language
48if($language eq"c") { $extension = "c";}
49elsif($language eq "fortran" or $language eq "f") { $language = "f"; $extension = "f";}
50else { die "You must specify a valid language!"; }
51
52
53# Reading the templates for the tests into @sources
54foreach $srcfile (@sourcefiles)
55{
56 # Reading the content of the current sourcefile into $src
57 open(TEST,$srcfile) or print "Error: Could not open template $srcfile\n";
58 while(<TEST>){ $src .= $_; }
59 close(TEST);
60 # Adding the content $src to the end of the list @sources
61 push(@sources,$src);
62}
63
64# Extracting the source for the mainprogramm and saving it in $mainprocsrc
65if($language eq "c") { $mainprocsrc = "ompts_standaloneProc.c"; }
66elsif($language eq "f") { $mainprocsrc = "ompts_standaloneProc.f"; }
67open(MAINPROC,$mainprocsrc) or die "Could not open the sourcefile for the main program $mainprocsrc";
68while(<MAINPROC>){
69 $mainproc .= $_;
70}
71
72foreach $testtype (@testtypes)
73{
74 foreach $src(@sources)
75 {
76# Some temporary testinformation:
77 ($description) = get_tag_values('ompts:testdescription',$src);
78 ($directive) = get_tag_values('ompts:directive',$src);
79 ($functionname) = get_tag_values('ompts:testcode:functionname',$src);
80
81 open(OUTFILE,">".$language.$orphanprefix.$testtype."_".$functionname.".".$extension) or die("Could not create the output file for $directive");
82
83# Creating the source for the test:
84 ($code) = get_tag_values('ompts:testcode',$src);
85# Putting together the functions and the mainprogramm:
86 $code .= $mainproc;
87
88# get the parameters <ompts:orphan:params> by joon
89# thanks to Dr. Yin Ma in Absoft
90 ($parms) = get_tag_values('ompts:orphan:parms',$code);
91 ($parms) = leave_single_space($parms);
92# to remove parameters tag between 'ompts:orphan:parms' by joon
93 ($code) = replace_tags('ompts:orphan:parms','',$code);
94
95# Make modifications for the orphaned testversion if necessary:
96 if($orphan)
97 {
98# Get the global variables:
99 @defs = get_tag_values("ompts:orphan:vars",$code);
100 $orphvarsdef = "";
101 foreach $_ (@defs)
102 {
103 #print $_;
104 if(not /^[ ]*$/gs) { $orphvarsdef = join("\n",$orphvarsdef,$_); }
105 #print "OK\n".$orphvarsdef;
106 }
107 if($language eq "f")
108 {
109# Generate the orphan subroutines:
110 $orphfuncs = create_orph_fortranfunctions("$testtype_", $code);
111# Replace orphan regions by functioncalls:
112 ($code) = orphan_regions2fortranfunctions( "$testtype_", ($code) );
113 ($code) = enlarge_tags('ompts:orphan:vars','','',($code));
114 ($code) = enlarge_tags('ompts:orphan:parms','','',($code));
115 #to find orphan call statemetn and add parameters
116
117# Put all together:
118 $code = $code . $orphfuncs;
119 }
120 elsif($language eq "c")
121 {
122# Generate predeclarations for orpahn functions:
123 $orphfuncsdefs = orph_functions_declarations("$testtype_",$code);
124# Generate the orphan functions:
125 $orphfuncs = create_orph_cfunctions("$testtype_",$code);
126# Repla:e orphan regions by functioncalls:
127 ($code) = orphan_regions2cfunctions( "$testtype_", ($code) );
128# Deleting the former declarations of the variables in the orphan regions:
129 ($code) = delete_tags('ompts:orphan:vars',($code));
130# Put all together:
131 $code = "#include \"omp_testsuite.h\"\n".$orphvarsdef . $orphfuncsdefs . $code . $orphfuncs;
132 }
133 else {
Alp Tokerc2d5e612014-06-01 18:28:36 +0000134 print "An error occurred!";
Jim Cownie18d84732014-05-10 17:02:09 +0000135 }
136 }
137# remove parameters between <ompts:orphan:parms> tags, added by joon
138 ($code)= replace_tags('ompts:orphan:parms',$code);
139
140# Remove the marks for the orpahn regions and its variables:
141 ($code) = enlarge_tags('ompts:orphan','','',($code));
142 ($code) = enlarge_tags('ompts:orphan:vars','','',($code));
143
144# remove parameters between for orphaned directive parametes, added by joon
145 ($code) = enlarge_tags('ompts:orphan:parms','','',($code));
146
147 if($testtype eq "test") {
148# Remove the marks for the testcode and remove the code for the crosstests:
149 ($code) = enlarge_tags('ompts:check','','',($code));
150 ($code) = delete_tags('ompts:crosscheck',($code));
151 }
152 elsif($testtype eq "ctest") {
153# Remove the marks for the crosstestcode and remove the code for the tests:
154 ($code) = enlarge_tags('ompts:crosscheck','','',($code));
155 ($code) = delete_tags('ompts:check',($code));
156 }
157# Making some final modifications:
158 ($code) = replace_tags('testfunctionname',$testtype."_".$functionname,($code));
159 ($code) = replace_tags('directive',$directive,($code));
160 ($code) = replace_tags('description',$description,($code));
161 ($code) = enlarge_tags('ompts:testcode:functionname',$testtype."_",'',($code) );
162# $code = "\#include \"omp_testsuite.h\"\n".$code;
163# Write the result into the file and close it:
164 print OUTFILE $code;
165 close(OUTFILE);
166 }
167}