blob: 3d6f3467ddb2993c259d92ca06581a3b7c9fb99f [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001#!/usr/bin/env perl
2
3# ompts_parser [option] INFILE OUTFILE
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
11#
12# Return:
13# Succes: 0
14# Template not found -1
15#
16
17# Using Getopt::long to extract the programm options
18use Getopt::Long;
19# Using functions: Set of subroutines to modify the testcode
20use ompts_parserFunctions;
21
22# Getting given options
23GetOptions("test" => \$test,"crosstest" => \$crosstest, "orphan!" => \$orphan);
24
25# Remaining arguments are the templatefiles.
26# Adding these to the list of to be parsed files if they exist.
27
28my $templatefile;
29my $sourcefile;
30my $mainprocsrc = "ompts_standaloneProc.c";
31
32$templatefile = $ARGV[0];
33$outfile = $ARGV[1];
34
35if (!-e $templatefile) {
36 print "Temaplte file not found";
37 exit -1;
38}
39
40
41# Checking if options were valid:
42#################################################################
43# preparations and checks for sourcefiles
44
45# Reading the template for the tests
46open(TEST,$templatefile) or die "Error: Could not open template $srcfile\n";
47while(<TEST>){ $src .= $_; }
48close(TEST);
49
50# Extracting the source for the mainprogramm and saving it in $mainprocsrc
51open(MAINPROC,$mainprocsrc) or die "Could not open the sourcefile for the main program $mainprocsrc";
52while(<MAINPROC>){ $mainproc .= $_; }
53close (MAINPROC);
54
55# Some temporary testinformation:
56my ($description) = get_tag_values ('ompts:testdescription',$src);
57my ($directive) = get_tag_values ('ompts:directive',$src);
58my ($functionname) = get_tag_values ('ompts:testcode:functionname',$src);
59
60open (OUTFILE,">$outfile") or die "Could not create the output file for $directive";
61
62# Creating the source for the test:
63my ($code) = get_tag_values('ompts:testcode',$src);
64# Putting together the functions and the mainprogramm:
65$code .= $mainproc;
66
67my $testprefix = "";
68
69# Make modifications for the orphaned testversion if necessary:
70if ($orphan) {
71# Get the global variables:
72 @defs = get_tag_values("ompts:orphan:vars",$code);
73 $orphvarsdef = "";
74 foreach (@defs) {
75 $orphvarsdef = join("\n",$orphvarsdef,$_);
76 }
77# Generate predeclarations for orpahn functions:
78 $orphfuncsdefs = orph_functions_declarations($code);
79# Generate the orphan functions:
80 $orphfuncs = create_orph_cfunctions($code);
81# Repla:e orphan regions by functioncalls:
82 $code = orphan_regions2cfunctions($code);
83# Deleting the former declarations of the variables in the orphan regions:
84 ($code) = delete_tags('ompts:orphan:vars',($code));
85# Put all together:
86 $code = "#include \"omp_testsuite.h\"\n" . $orphvarsdef . $orphfuncsdefs . $code . $orphfuncs;
87 $testprefix .= "orph_";
88}
89
90# Remove remaining marks for the orpahn regions and its variables:
91($code) = enlarge_tags('ompts:orphan','','',($code));
92($code) = enlarge_tags('ompts:orphan:vars','','',($code));
93
94if($test) {
95# Remove the marks for the testcode and remove the code for the crosstests:
96 ($code) = enlarge_tags('ompts:check','','',($code));
97 ($code) = delete_tags('ompts:crosscheck',($code));
98 $testprefix .= "test_";
99}
100elsif($crosstest) {
101# Remove the marks for the crosstestcode and remove the code for the tests:
102 ($code) = enlarge_tags('ompts:crosscheck','','',($code));
103 ($code) = delete_tags('ompts:check',($code));
104 $testprefix .= "ctest_";
105}
106# Making some final modifications:
107($code) = replace_tags('testfunctionname',$testprefix.$functionname,($code));
108($code) = replace_tags('directive',$directive,($code));
109($code) = replace_tags('description',$description,($code));
110($code) = enlarge_tags('ompts:testcode:functionname',$testprefix,'',($code) );
111# $code = "\#include \"omp_testsuite.h\"\n".$code;
112# Write the result into the file and close it:
113print OUTFILE $code;
114close(OUTFILE);