Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | #!/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 |
| 18 | use Getopt::Long; |
| 19 | # Using functions: Set of subroutines to modify the testcode |
| 20 | use ompts_parserFunctions; |
| 21 | |
| 22 | # Getting given options |
| 23 | GetOptions("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 | |
| 28 | my $templatefile; |
| 29 | my $sourcefile; |
| 30 | my $mainprocsrc = "ompts_standaloneProc.f"; |
| 31 | |
| 32 | $templatefile = $ARGV[0]; |
| 33 | $outfile = $ARGV[1]; |
| 34 | |
| 35 | if (!-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 |
| 46 | open(TEST,$templatefile) or die "Error: Could not open template $srcfile\n"; |
| 47 | while(<TEST>){ $src .= $_; } |
| 48 | close(TEST); |
| 49 | |
| 50 | # Extracting the source for the mainprogramm and saving it in $mainprocsrc |
| 51 | open(MAINPROC,$mainprocsrc) or die "Could not open the sourcefile for the main program $mainprocsrc"; |
| 52 | while(<MAINPROC>){ $mainproc .= $_; } |
| 53 | close (MAINPROC); |
| 54 | |
| 55 | # Some temporary testinformation: |
| 56 | ($description) = get_tag_values ('ompts:testdescription',$src); |
| 57 | ($directive) = get_tag_values ('ompts:directive',$src); |
| 58 | ($functionname) = get_tag_values ('ompts:testcode:functionname',$src); |
| 59 | |
| 60 | open (OUTFILE,">$outfile") or die "Could not create the output file for $directive"; |
| 61 | |
| 62 | # Creating the source for the test: |
| 63 | ($code) = get_tag_values('ompts:testcode',$src); |
| 64 | # Putting together the functions and the mainprogramm: |
| 65 | $code .= $mainproc; |
| 66 | |
| 67 | #thanks to Dr. Yin Ma in Absoft, get the parameters <ompts:orphan:params> by joon |
| 68 | ($parms) = get_tag_values('ompts:orphan:parms',($code)); |
| 69 | ($parms) = leave_single_space($parms); |
| 70 | ($code) = replace_tags('ompts:orphan:parms','',$code); |
| 71 | |
| 72 | # Make modifications for the orphaned testversion if necessary: |
| 73 | if ($orphan) { |
| 74 | # Get the global variables: |
| 75 | @defs = get_tag_values("ompts:orphan:vars",$code); |
| 76 | $orphvarsdef = ""; |
| 77 | foreach (@defs) { |
| 78 | if (not /^[ ]*$/gs) { $orphvarsdef = join("\n",$orphvarsdef,$_); } |
| 79 | } |
| 80 | # Generate the orphan subroutines: |
| 81 | $orphfuncs = create_orph_fortranfunctions ("", ($code),($parms)); |
| 82 | # Replace orphan regions by functioncalls: |
| 83 | ($code) = orphan_regions2fortranfunctions ("", ($code),($parms)); |
| 84 | ($code) = enlarge_tags ('ompts:orphan:vars','','',($code)); |
| 85 | # to find orphan call statement and add parameters, by joon |
| 86 | ($code) = enlarge_tags('ompts:orphan:parms','','',($code)); |
| 87 | # Put all together: |
| 88 | $code = $code . $orphfuncs; |
| 89 | } |
| 90 | |
| 91 | # Remove remaining marks for the orpahn regions and its variables: |
| 92 | ($code) = enlarge_tags('ompts:orphan','','',($code)); |
| 93 | ($code) = enlarge_tags('ompts:orphan:vars','','',($code)); |
| 94 | # remove parameters between for orphaned directive parametes, added byjoon |
| 95 | ($code) = enlarge_tags('ompts:orphan:parms','','',($code)); |
| 96 | |
| 97 | if($test) { |
| 98 | # Remove the marks for the testcode and remove the code for the crosstests: |
| 99 | ($code) = enlarge_tags('ompts:check','','',($code)); |
| 100 | ($code) = delete_tags('ompts:crosscheck',($code)); |
| 101 | } |
| 102 | elsif($crosstest) { |
| 103 | # Remove the marks for the crosstestcode and remove the code for the tests: |
| 104 | ($code) = enlarge_tags('ompts:crosscheck','','',($code)); |
| 105 | ($code) = delete_tags('ompts:check',($code)); |
| 106 | } |
| 107 | # Making some final modifications: |
| 108 | ($code) = replace_tags('testfunctionname',"test_".$functionname,($code)); |
| 109 | ($code) = replace_tags('directive',$directive,($code)); |
| 110 | ($code) = replace_tags('description',$description,($code)); |
| 111 | ($code) = enlarge_tags('ompts:testcode:functionname',"test_",'',($code) ); |
| 112 | # $code = "\#include \"omp_testsuite.h\"\n".$code; |
| 113 | # Write the result into the file and close it: |
| 114 | print OUTFILE $code; |
| 115 | close(OUTFILE); |