fix warnings
[pluto.git] / polycc.sh.in
blobc99ab2fa93720b5b949a8becc7ed3b45feef78c8
1 #!/bin/bash
3 # Top-level script that runs all components of the end-to-end
4 # system
6 # Just run 'polycc <C code>' when the program section to
7 # be parallelized/optimized around special comments as described
8 # in the `README'
9 #
10 # Copyright (C) 2007-2008 Uday Bondhugula
12 # Available under GNU GPL version 3 or (at your option) any later version
15 pluto=@SOURCE_DIR@/src/pluto
16 plann=@SOURCE_DIR@/plann
17 plorc=@SOURCE_DIR@/plorc
19 # Some additional setup here to ensure that variables are visible outside of the run function
20 SOURCEFILE=""
21 OUTFILE=""
22 dirname=""
23 PLUTOOUT=""
25 # check for command-line options
26 for arg in $*; do
27 if [ $arg == "--parallel" ]; then
28 PARALLEL=1
29 elif [ $arg == "--parallelize" ]; then
30 PARALLEL=1
31 elif [ $arg == "--unroll" ]; then
32 UNROLL=1
33 elif [ $arg == "--debug" ]; then
34 DEBUG=1
35 elif [ $arg == "--moredebug" ]; then
36 DEBUG=1
37 elif [ $arg == "-i" ]; then
38 INDENT=1
39 elif [ $arg == "--indent" ]; then
40 INDENT=1
41 elif [ $arg == "--silent" ]; then
42 SILENT=1
44 done
46 # some special processing for linearized accesses
47 #if [ "$SOURCEFILE" != "" ]; then
48 #grep __SPECIAL $SOURCEFILE > .nonlinearized
49 #grep __SPECIAL $SOURCEFILE | sed -e "s/.*__SPECIAL//" > .linearized
50 #fi
52 run()
54 $pluto $* || exit 1
56 SOURCEFILE=`cat .srcfilename`
57 OUTFILE=`cat .outfilename`
59 dirname=`dirname $SOURCEFILE`
60 basename=`basename $SOURCEFILE`
61 prefix=`basename $SOURCEFILE .c`
63 CLOOGFILE=`basename $OUTFILE`.pluto.cloog
64 PLUTOOUT=$OUTFILE
66 # generate and insert unrolling annotations, run ancc on it,
67 if [ "$UNROLL" == 1 ]; then
68 $plorc $PLUTOOUT @SOURCE_DIR@/orio-0.1.0
71 #if [ "$UNROLL" == 1 ]; then
72 #$plann $PLUTOOUT @SOURCE_DIR@/annotations
73 #fi
76 # put the original skeleton around the transformed code
77 @SOURCE_DIR@/inscop $SOURCEFILE $OUTFILE $OUTFILE
80 if [ "$INDENT" == 1 ] && [ -x /usr/bin/indent ]; then
81 indent -kr -br -ce -l125 $OUTFILE
86 run "$*"
87 WORK=1
88 TEMPFILE=""
89 while [ $WORK -eq 1 ]
91 if grep -q "#pragma scop" "$PLUTOOUT"
92 then
93 # Move the original file into a temporary location
94 TEMPFILE="$SOURCEFILE""_temp"
95 mv $SOURCEFILE $TEMPFILE
97 # Move the file that still has scope in it into
98 # place of the original source file, so $* will pick the
99 # correct file
100 mv $PLUTOOUT $SOURCEFILE
102 # Run pluto again
103 run "$*"
105 # Move the original back in place
106 mv $TEMPFILE $SOURCEFILE
107 else
108 # No more scops
109 WORK=0
111 done
113 cleanup()
115 # An attempt to move the original file back in place
116 # in the event of an exception
117 if [ -f "$TEMPFILE" ]
118 then
119 mv $TEMPFILE $SOURCEFILE
121 if [ "$DEBUG" != 1 ]; then
122 rm -rf .unroll .vectorize .pragmas .params .orcc .linearized .nonlinearized\
123 $CLOOGFILE .srcfilename .outfilename .distmem pi.cloog sigma.cloog \
124 *.sysloog .appendfilename
128 trap cleanup SIGINT exit