fix warnings
[pluto.git] / inscop
blob29b468a70420adfcdc1156a49f8a831e2c49cfaf
1 #!/bin/bash
3 # arguments
4 # inscop <original> <transformed_kernel> <output_file>
5 # transformed_kernel and output_file can be the same
8 MAXLINES=`wc -l $1 | awk '{print $1}'`
10 # Get the FIRST scop and return all the lines above it
11 # Because we are returning the text preceding the first scop, it's ok to ignore that pragma
12 # which is what the grep -v call does
13 grep -B $MAXLINES -m 1 "#pragma[[:space:]]\+scop" $1 | grep -v "#pragma[[:space:]]\+scop" > .head
14 # Get the FIRST endscop and return all the lines below it
15 # We want to get all the text below the first endscop, but do not want that first endscop line to be returned
16 # which is accomplished with the awk call at the end.
17 sed -n '/\#pragma[[:space:]]endscop/,$p' $1 | awk '{if(NR>1)print}' > .tail
18 #grep -A $MAXLINES "#pragma[[:space:]]\+endscop" $1 | grep -v "#pragma[[:space:]]\+endscop" > .tail
20 cat .head > __tmp
22 # The gcc preprocessor inserts some useless comments like "# 1 "<built-in>"
23 # preprocessor doesn't like pragma's in #defines and so it was not put in from pluto
24 # when '--bee' was used - instead we will add it here
26 # Put all the include statements in a file
27 cat $2 | grep "^#include" > .includes
29 # Put everything that isn't an include into another file
30 cat $2 | grep -v "^#include" > .body.c
32 # Put those includes we got above into another file
33 cat .includes > .head
35 # Check if we've already inserted the extra includes and defines
36 # If we haven't, put them in the head
37 if ! grep -q "#define ceild(n,d)" __tmp
38 then
39 echo "#include <math.h>" >> .head
40 echo "#define ceild(n,d) ceil(((double)(n))/((double)(d)))" >> .head
41 echo "#define floord(n,d) floor(((double)(n))/((double)(d)))" >> .head
42 echo "#define max(x,y) ((x) > (y)? (x) : (y))" >> .head
43 echo -e "#define min(x,y) ((x) < (y)? (x) : (y))\n" >> .head
46 gcc -E -P -CC .body.c | grep -v "^# " | sed -e 's/__bee_schedule/#pragma schedule/' | \
47 sed -e 's/_NL_DELIMIT_/\n/' >> __tmp
49 cat .tail >> __tmp
51 # Checks to see if the openmp header has already been inserted into the file
52 # If not, it inserts it.
53 if grep -q "#include <omp.h>" __tmp
54 then
55 # Remove the existing omp.h include
56 sed -ie '\/\<omp\.h\>/d' __tmp
59 cat .head __tmp > $3
61 rm -f .head .tail __tmp .includes .body.c