changes to enable no caching and no prefetching by adding DCACHE flag to
[IRC.git] / Robust / src / buildscript
1 #!/bin/bash
2
3 printhelp() {
4 echo -robustroot set up the ROBUSTROOT to directory other than default one
5 echo -dsm distributed shared memory
6 echo -trueprob double - probabiltiy of true branch
7 echo -dsmcaching -enable caching in dsm runtime
8 echo -mac distributed shared memory mac support
9 echo -check generate check code
10 echo -dmalloc link in dmalloc
11 echo -recover compile task code
12 echo -specdir directory
13 echo -printflat print out flat representation
14 echo -selfloop task - this task cannot self loop forever
15 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
16 echo -taskstate do task state analysis
17 echo -tagstate do tag state analysis
18 echo -scheduling do task scheduling
19 echo -multicore generate multi-core version binary
20 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
21 echo "-raw generate raw version binary (should be used together with -multicore)"
22 echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)"
23 echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)"
24 echo -threadsimulate generate multi-thread simulate version binary
25 echo -optional enable optional
26 echo -debug generate debug symbols
27 echo -prefetch do prefetch analysis
28 echo -transstats generates transaction stats on commits and aborts
29 echo -webinterface enable web interface
30 echo -runtimedebug printout runtime debug messages
31 echo "-thread use support for multiple threads"
32 echo "-optimize call gcc with -O9 (optimize)"
33 echo "-nooptimize call gcc with -O0 (do not optimize)"
34 echo -curdir directory 
35 echo -mainclass class with main method
36 echo -o binary
37 echo -nojava do not run bristlecone compiler
38 echo -instructionfailures inject code for instructionfailures
39 echo -profile build with profile options
40 echo "-enable-assertions execute assert statements during compilation"
41 echo -help help
42 }
43
44 ROBUSTROOT=~/research/Robust/src
45 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
46 REPAIRROOT=~/research/Repair/RepairCompiler/
47 CURDIR=`pwd`
48 DSMFLAG=false
49 NOJAVA=false
50 CHECKFLAG=false
51 RECOVERFLAG=false
52 MULTICOREFLAG=false
53 TRANSSTATSFLAG=false
54 RAWFLAG=false
55 RAWCONFIG=''
56 RAWDEBUGFLAG=false
57 INTERRUPTFLAG=false
58 THREADSIMULATEFLAG=false;
59 USEDMALLOC=false
60 THREADFLAG=false
61 SPECDIR=`pwd`
62 SRCFILES=''
63 EXTRAOPTIONS=''
64 MAINFILE='a'
65 JAVAFORWARDOPTS=''
66 JAVAOPTS=''
67 OPTIONALFLAG=false
68
69 if [[ -z $1 ]]
70 then
71 printhelp
72 exit
73 fi
74
75 while [[ -n $1 ]]
76 do
77 if [[ $1 = '-help' ]]
78 then
79 printhelp
80 exit
81 elif [[ $1 = '-robustroot' ]]
82 then
83 ROBUSTROOT="$2"
84 shift
85 elif [[ $1 = '-nojava' ]]
86 then
87 NOJAVA=true
88 elif [[ $1 = '-o' ]]
89 then
90 MAINFILE="$2"
91 shift
92 elif [[ $1 = '-mainclass' ]]
93 then
94 JAVAOPTS="$JAVAOPTS -mainclass $2"
95 shift
96 elif [[ $1 = '-selfloop' ]]
97 then
98 JAVAOPTS="$JAVAOPTS -selfloop $2"
99 shift
100 elif [[ $1 = '-excprefetch' ]]
101 then
102 JAVAOPTS="$JAVAOPTS -excprefetch $2"
103 shift
104 elif [[ $1 = '-dsm' ]]
105 then
106 JAVAOPTS="$JAVAOPTS -dsm"
107 DSMFLAG=true
108 elif [[ $1 = '-prefetch' ]]
109 then
110 JAVAOPTS="$JAVAOPTS -prefetch"
111 elif [[ $1 = '-transstats' ]]
112 then
113 TRANSSTATSFLAG=true
114 elif [[ $1 = '-printflat' ]]
115 then
116 JAVAOPTS="$JAVAOPTS -printflat"
117 elif [[ $1 = '-trueprob' ]]
118 then
119 JAVAOPTS="$JAVAOPTS -trueprob $2"
120 shift
121 elif [[ $1 = '-mac' ]]
122 then
123 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
124 elif [[ $1 = '-profile' ]]
125 then
126 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
127 elif [[ $1 = '-taskstate' ]]
128 then
129 JAVAOPTS="$JAVAOPTS -taskstate"
130 elif [[ $1 = '-tagstate' ]]
131 then
132 JAVAOPTS="$JAVAOPTS -tagstate"
133 elif [[ $1 = '-scheduling' ]]
134 then
135 JAVAOPTS="$JAVAOPTS -scheduling"
136 elif [[ $1 = '-multicore' ]]
137 then
138 MULTICOREFLAG=true
139 JAVAOPTS="$JAVAOPTS -multicore"
140 elif [[ $1 = '-numcore' ]]
141 then
142 JAVAOPTS="$JAVAOPTS -numcore $2"
143 shift
144 elif [[ $1 = '-raw' ]]
145 then
146 RAWFLAG=true
147 JAVAOPTS="$JAVAOPTS -raw"
148 elif [[ $1 = '-rawconfig' ]]
149 then
150 RAWCONFIG="$2"
151 shift
152 elif [[ $1 = '-interrupt' ]]
153 then
154 INTERRUPTFLAG=true
155 elif [[ $1 = '-threadsimulate' ]]
156 then
157 THREADSIMULATEFLAG=true
158 elif [[ $1 = '-optional' ]]
159 then
160 JAVAOPTS="$JAVAOPTS -optional"
161 OPTIONALFLAG=true
162 elif [[ $1 = '-dmalloc' ]]
163 then
164 USEDMALLOC=true
165 elif [[ $1 = '-recover' ]]
166 then
167 RECOVERFLAG=true
168 JAVAOPTS="$JAVAOPTS -task"
169 elif [[ $1 = '-webinterface' ]]
170 then
171 JAVAOPTS="$JAVAOPTS -webinterface"
172 elif [[ $1 = '-instructionfailures' ]]
173 then
174 JAVAOPTS="$JAVAOPTS -instructionfailures"
175 elif [[ $1 = '-check' ]]
176 then
177 CHECKFLAG=true
178 JAVAOPTS="$JAVAOPTS -conscheck"
179 elif [[ $1 = '-enable-assertions' ]]
180 then
181 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
182 elif [[ $1 = '-specdir' ]]
183 then
184 cd $2
185 SPECDIR=`pwd`
186 cd $CURDIR
187 shift
188 elif [[ $1 = '-debug' ]]
189 then
190 RAWDEBUGFLAG=true
191 EXTRAOPTIONS="$EXTRAOPTIONS -g"
192 elif [[ $1 = '-runtimedebug' ]]
193 then
194 EXTRAOPTIONS="$EXTRAOPTIONS -DCHECKTA"
195 elif [[ $1 = '-dsmcaching' ]]
196 then
197 EXTRAOPTIONS="$EXTRAOPTIONS -DCACHE"
198 elif [[ $1 = '-nooptimize' ]]
199 then
200 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
201 elif [[ $1 = '-optimize' ]]
202 then
203 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
204 elif [[ $1 = '-thread' ]]
205 then
206 JAVAOPTS="$JAVAOPTS -thread"
207 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
208 THREADFLAG=true
209 elif [[ $1 = '-curdir' ]]
210 then
211 CURDIR=$2
212 shift
213 else
214 SRCFILES="$SRCFILES $1"
215 fi
216 shift
217 done
218
219 BUILDDIR="$CURDIR/tmpbuilddirectory"
220
221 cd $1
222 cd $CURDIR
223 shift
224
225 mkdir $BUILDDIR
226
227 if $CHECKFLAG #Generate structure files for repair tool
228 then
229 JAVAOPTS="$JAVAOPTS -struct structfile"
230 fi
231
232 # Build bristlecone/java sources
233
234 if $MULTICOREFLAG
235 then
236 if ! java $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
237 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR \
238 $JAVAOPTS $SRCFILES
239 then exit $?
240 fi
241 else
242 #if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
243 if ! $NOJAVA
244 then
245 if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
246 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
247 $JAVAOPTS $SRCFILES
248 then exit $?
249 fi
250 fi
251 fi
252
253 # Build all of the consistency specs
254
255 if $CHECKFLAG # CHECKFLAG
256 then
257 cd $SPECDIR
258 mkdir $BUILDDIR/specdir
259 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
260
261 echo > $BUILDDIR/specs
262
263 # compile specs into C code
264 for i in * # iterate over all directories
265 do
266 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
267 then
268 cd $SPECDIR/$i
269 cat $BUILDDIR/structfile.struct $i.label > $i.struct
270 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
271 cp size.[c,h] $BUILDDIR/specdir
272 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
273 echo $i >> $BUILDDIR/specs
274 fi # CVSDIR CHECK
275 done # iterate over all directories
276
277 #compile C code
278
279 cd $BUILDDIR/specdir
280 ./buildrobust
281 echo > $BUILDDIR/checkers.h
282 for i in `cat $BUILDDIR/specs`
283 do
284 gcc -O0 -g -fbounds-check -c $i\_aux.c
285 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
286 done
287 fi # CHECKFLAG
288
289 #build and link everything
290
291 if $RAWFLAG
292 then # RAWFLAG
293 RAWDIR="$CURDIR/raw"
294 MAKEFILE="../Makefile.raw"
295 mkdir $RAWDIR
296 cd $RAWDIR
297 make clean
298 rm ./*
299
300 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
301
302 if $RAWDEBUGFLAG
303 then #debug version
304 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
305 fi
306
307 if $INTERRUPTFLAG
308 then #INTERRUPT version
309 MAKEFILE="$MAKEFILE.i"
310 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
311 fi #INTERRUPT version
312
313 MAKEFILE="$MAKEFILE.$RAWCONFIG"
314
315 cp $MAKEFILE ./Makefile
316 cp ../Runtime/*.c ./
317 cp ../Runtime/*.h ./
318 cp ../Runtime/*.S ./
319 cp ../Runtime/*.s ./
320 cp ../tmpbuilddirectory/*.c ./
321 cp ../tmpbuilddirectory/*.h ./
322
323 make
324
325 else #!RAWFLAG
326 cd $CURDIR 
327
328 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
329 -I$BUILDDIR"
330
331 if $MULTICOREFLAG
332 then
333 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
334 else
335 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
336 fi
337
338 FILES="$RUNTIMEFILE \
339 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
340 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
341 $ROBUSTROOT/Runtime/ObjectHash.c \
342 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
343 $ROBUSTROOT/Runtime/math.c \
344 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
345
346 if $DSMFLAG
347 then
348 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
349 if $TRANSSTATSFLAG
350 then
351 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
352 fi
353 FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c"
354 fi
355
356 if $RECOVERFLAG
357 then
358 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
359 if $MULTICOREFLAG
360 then
361 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
362 fi
363 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
364 if $RAWFLAG
365 then
366 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
367 fi
368 if $THREADSIMULATEFLAG
369 then
370 # -lpthread for pthread functions, -lrt for message queue functions
371 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
372 fi
373 fi
374
375 if $OPTIONALFLAG
376 then
377 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
378 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
379 fi
380
381 if $THREADFLAG
382 then
383 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
384 fi
385
386 if $CHECKFLAG
387 then
388 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
389 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
390 fi
391
392 if $USEDMALLOC
393 then
394 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
395 fi
396
397 if $MULTICOREFLAG
398 then
399 gcc $INCLUDES $EXTRAOPTIONS \
400 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
401 else
402 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
403 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
404 fi
405
406 fi #!RAWFLAG
407
408 exit
409