small changes to buildscript to add runtime check for STM
[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 -singleTM single machine committing transactions
7 echo -abortreaders abort readers immediately
8 echo -trueprob double - probabiltiy of true branch
9 echo -dsmcaching -enable caching in dsm runtime
10 echo -mac distributed shared memory mac support
11 echo -check generate check code
12 echo -dmalloc link in dmalloc
13 echo -recover compile task code
14 echo -fastcheck fast checkpointing for Bristlecone
15 echo -specdir directory
16 echo -printflat print out flat representation
17 echo -selfloop task - this task cannot self loop forever
18 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
19 echo -taskstate do task state analysis
20 echo -tagstate do tag state analysis
21 echo -scheduling do task scheduling
22 echo -multicore generate multi-core version binary
23 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
24 echo "-raw generate raw version binary (should be used together with -multicore)"
25 echo "-rawcacheflush enable cache flush in raw version binary (should be used togethere with -raw)"
26 echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)"
27 echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)"
28 echo "-rawpath print out execute path information for raw version (should be used together with -raw)"
29 echo "-useprofile use profiling data for scheduling (should be used together with -raw)"
30 echo -threadsimulate generate multi-thread simulate version binary
31 echo -printscheduling print out scheduling graphs
32 echo -printschedulesim print out scheduling simulator result graphs
33 echo -abcclose close the array boundary check
34 echo -optional enable optional
35 echo -debug generate debug symbols
36 echo -prefetch do prefetch analysis
37 echo -transstats generates transaction stats on commits and aborts
38 echo -webinterface enable web interface
39 echo -runtimedebug printout runtime debug messages
40 echo "-thread use support for multiple threads"
41 echo "-optimize call gcc with -O9 (optimize)"
42 echo "-nooptimize call gcc with -O0 (do not optimize)"
43 echo -curdir directory 
44 echo -mainclass class with main method
45 echo -o binary
46 echo -nojava do not run bristlecone compiler
47 echo -instructionfailures inject code for instructionfailures
48 echo -profile build with profile options
49 echo "-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version"
50 echo "-enable-assertions execute assert statements during compilation"
51 echo -justanalyze exit after compiler analyses complete
52 echo -help help
53 }
54
55 ABORTREADERS=false;
56 ROBUSTROOT=~/research/Robust/src
57 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
58 REPAIRROOT=~/research/Repair/RepairCompiler/
59 CURDIR=`pwd`
60 DSMFLAG=false
61 SINGLETM=false
62 NOJAVA=false
63 CHECKFLAG=false
64 RECOVERFLAG=false
65 MLPFLAG=false
66 MULTICOREFLAG=false
67 TRANSSTATSFLAG=false
68 RAWFLAG=false
69 RAWCACHEFLUSHFLAG=false
70 RAWCONFIG=''
71 RAWDEBUGFLAG=false
72 RAWPATHFLAG=false
73 RAWPROFILEFLAG=false
74 RAWUSEIOFLAG=false
75 INTERRUPTFLAG=false
76 THREADSIMULATEFLAG=false;
77 USEDMALLOC=false
78 THREADFLAG=false
79 FASTCHECK=false
80 SPECDIR=`pwd`
81 SRCFILES=''
82 EXTRAOPTIONS=''
83 MAINFILE='a'
84 JAVAFORWARDOPTS=''
85 JAVAOPTS=''
86 OPTIONALFLAG=false
87 EXITAFTERANALYSIS=false
88
89 if [[ -z $1 ]]
90 then
91 printhelp
92 exit
93 fi
94
95 while [[ -n $1 ]]
96 do
97 if [[ $1 = '-help' ]]
98 then
99 printhelp
100 exit
101 elif [[ $1 = '-justanalyze' ]]
102 then
103 EXITAFTERANALYSIS=true
104 elif [[ $1 = '-abortreaders' ]]
105 then
106 ABORTREADERS=true
107 EXTRAOPTIONS="$EXTRAOPTIONS -DABORTREADERS"
108 JAVAOPTS="$JAVAOPTS -abortreaders"
109 elif [[ $1 = '-robustroot' ]]
110 then
111 ROBUSTROOT="$2"
112 shift
113 elif [[ $1 = '-nojava' ]]
114 then
115 NOJAVA=true
116 elif [[ $1 = '-fastcheck' ]]
117 then
118 EXTRAOPTIONS="$EXTRAOPTIONS -DFASTCHECK"
119 JAVAOPTS="$JAVAOPTS -fastcheck"
120 FASTCHECK=true
121 elif [[ $1 = '-o' ]]
122 then
123 MAINFILE="$2"
124 shift
125 elif [[ $1 = '-mainclass' ]]
126 then
127 JAVAOPTS="$JAVAOPTS -mainclass $2"
128 shift
129 elif [[ $1 = '-selfloop' ]]
130 then
131 JAVAOPTS="$JAVAOPTS -selfloop $2"
132 shift
133 elif [[ $1 = '-excprefetch' ]]
134 then
135 JAVAOPTS="$JAVAOPTS -excprefetch $2"
136 shift
137 elif [[ $1 = '-dsm' ]]
138 then
139 JAVAOPTS="$JAVAOPTS -dsm"
140 DSMFLAG=true
141 elif [[ $1 = '-singleTM' ]]
142 then
143 JAVAOPTS="$JAVAOPTS -singleTM"
144 EXTRAOPTIONS="$EXTRAOPTIONS -DSTM"
145 SINGLETM=true
146 elif [[ $1 = '-prefetch' ]]
147 then
148 JAVAOPTS="$JAVAOPTS -prefetch"
149 elif [[ $1 = '-transstats' ]]
150 then
151 TRANSSTATSFLAG=true
152 elif [[ $1 = '-printflat' ]]
153 then
154 JAVAOPTS="$JAVAOPTS -printflat"
155 elif [[ $1 = '-trueprob' ]]
156 then
157 JAVAOPTS="$JAVAOPTS -trueprob $2"
158 shift
159 elif [[ $1 = '-mac' ]]
160 then
161 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
162 elif [[ $1 = '-profile' ]]
163 then
164 RAWPROFILEFLAG=true
165 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
166 elif [[ $1 = '-rawuseio' ]]
167 then
168 RAWUSEIOFLAG=true
169 elif [[ $1 = '-taskstate' ]]
170 then
171 JAVAOPTS="$JAVAOPTS -taskstate"
172 elif [[ $1 = '-tagstate' ]]
173 then
174 JAVAOPTS="$JAVAOPTS -tagstate"
175 elif [[ $1 = '-scheduling' ]]
176 then
177 JAVAOPTS="$JAVAOPTS -scheduling"
178 elif [[ $1 = '-multicore' ]]
179 then
180 MULTICOREFLAG=true
181 JAVAOPTS="$JAVAOPTS -multicore"
182 elif [[ $1 = '-numcore' ]]
183 then
184 JAVAOPTS="$JAVAOPTS -numcore $2"
185 shift
186 elif [[ $1 = '-raw' ]]
187 then
188 RAWFLAG=true
189 JAVAOPTS="$JAVAOPTS -raw"
190 elif [[ $1 = '-rawcacheflush' ]]
191 then
192 RAWCACHEFLUSHFLAG=true
193 elif [[ $1 = '-rawconfig' ]]
194 then
195 RAWCONFIG="$2"
196 shift
197 elif [[ $1 = '-interrupt' ]]
198 then
199 INTERRUPTFLAG=true
200 elif [[ $1 = '-threadsimulate' ]]
201 then
202 THREADSIMULATEFLAG=true
203 elif [[ $1 = '-abcclose' ]]
204 then
205 JAVAOPTS="$JAVAOPTS -abcclose"
206 elif [[ $1 = '-optional' ]]
207 then
208 JAVAOPTS="$JAVAOPTS -optional"
209 OPTIONALFLAG=true
210 elif [[ $1 = '-dmalloc' ]]
211 then
212 USEDMALLOC=true
213 elif [[ $1 = '-recover' ]]
214 then
215 RECOVERFLAG=true
216 JAVAOPTS="$JAVAOPTS -task"
217 elif [[ $1 = '-useprofile' ]]
218 then
219 JAVAOPTS="$JAVAOPTS -useprofile"
220 elif [[ $1 = '-webinterface' ]]
221 then
222 JAVAOPTS="$JAVAOPTS -webinterface"
223 elif [[ $1 = '-instructionfailures' ]]
224 then
225 JAVAOPTS="$JAVAOPTS -instructionfailures"
226 elif [[ $1 = '-mlp' ]]
227 then
228 JAVAOPTS="$JAVAOPTS -mlp"
229 elif [[ $1 = '-check' ]]
230 then
231 CHECKFLAG=true
232 JAVAOPTS="$JAVAOPTS -conscheck"
233 elif [[ $1 = '-enable-assertions' ]]
234 then
235 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
236 elif [[ $1 = '-specdir' ]]
237 then
238 cd $2
239 SPECDIR=`pwd`
240 cd $CURDIR
241 shift
242 elif [[ $1 = '-debug' ]]
243 then
244 RAWDEBUGFLAG=true
245 EXTRAOPTIONS="$EXTRAOPTIONS -g"
246 elif [[ $1 = '-rawpath' ]]
247 then
248 RAWPATHFLAG=true
249 elif [[ $1 = '-runtimedebug' ]]
250 then
251 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
252 elif [[ $1 = '-dsmcaching' ]]
253 then
254 EXTRAOPTIONS="$EXTRAOPTIONS -DCACHE"
255 elif [[ $1 = '-rangeprefetch' ]]
256 then
257 EXTRAOPTIONS="$EXTRAOPTIONS -DRANGEPREFETCH"
258 elif [[ $1 = '-nooptimize' ]]
259 then
260 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
261 elif [[ $1 = '-optimize' ]]
262 then
263 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
264 elif [[ $1 = '-thread' ]]
265 then
266 JAVAOPTS="$JAVAOPTS -thread"
267 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
268 THREADFLAG=true
269 elif [[ $1 = '-distributioninfo' ]]
270 then
271 JAVAOPTS="$JAVAOPTS -distributioninfo"
272 elif [[ $1 = '-curdir' ]]
273 then
274 CURDIR=$2
275 shift
276 elif [[ $1 = '-outputdir' ]]
277 then
278 JAVAOPTS="$JAVAOPTS -outputdir $2"
279 shift
280 else
281 SRCFILES="$SRCFILES $1"
282 fi
283 shift
284 done
285
286 BUILDDIR="$CURDIR/tmpbuilddirectory"
287
288 cd $1
289 cd $CURDIR
290 shift
291
292 mkdir $BUILDDIR
293
294 if $CHECKFLAG #Generate structure files for repair tool
295 then
296 JAVAOPTS="$JAVAOPTS -struct structfile"
297 fi
298
299 # Setup class path
300
301 if $RECOVERFLAG
302 then
303 if $FASTCHECK
304 then
305 #fast transactions
306 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/FastCheck"
307 else
308 #base bristlecone files
309 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Bristlecone"
310 fi
311 else
312 if $DSMFLAG
313 then
314 #dsm stuff
315 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaDSM"
316 elif $THREADFLAG
317 then
318 #threading java stuff
319 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaThread"
320 fi
321 #base java stuff
322 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Java"
323 fi
324
325 # Build bristlecone/java sources
326
327 if $MULTICOREFLAG
328 then
329 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx800m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
330 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ \
331 -dir $BUILDDIR $JAVAOPTS $SRCFILES
332 then exit $?
333 fi
334 else
335 #if ! ${ROBUSTROOT}/ourjava -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
336 if ! $NOJAVA
337 then
338 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx600m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
339 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ -dir $BUILDDIR -precise \
340 $JAVAOPTS $SRCFILES
341 then exit $?
342 fi
343 fi
344 fi
345
346 if $EXITAFTERANALYSIS
347 then
348 exit
349 fi
350
351 # Build all of the consistency specs
352
353 if $CHECKFLAG # CHECKFLAG
354 then
355 cd $SPECDIR
356 mkdir $BUILDDIR/specdir
357 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
358
359 echo > $BUILDDIR/specs
360
361 # compile specs into C code
362 for i in * # iterate over all directories
363 do
364 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
365 then
366 cd $SPECDIR/$i
367 cat $BUILDDIR/structfile.struct $i.label > $i.struct
368 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
369 cp size.[c,h] $BUILDDIR/specdir
370 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
371 echo $i >> $BUILDDIR/specs
372 fi # CVSDIR CHECK
373 done # iterate over all directories
374
375 #compile C code
376
377 cd $BUILDDIR/specdir
378 ./buildrobust
379 echo > $BUILDDIR/checkers.h
380 for i in `cat $BUILDDIR/specs`
381 do
382 gcc -O0 -g -fbounds-check -c $i\_aux.c
383 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
384 done
385 fi # CHECKFLAG
386
387 #build and link everything
388
389 if $RAWFLAG
390 then # RAWFLAG
391 RAWDIR="$CURDIR/raw"
392 MAKEFILE="../Makefile.raw"
393 mkdir $RAWDIR
394 cd $RAWDIR
395 make clean
396 rm ./*
397
398 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
399
400 if $RAWCACHEFLUSHFLAG
401 then # print path
402 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWCACHEFLUSH"
403 fi
404
405 if $RAWPATHFLAG
406 then # print path
407 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPATH"
408 fi
409
410 if $RAWDEBUGFLAG
411 then #debug version
412 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
413 fi
414
415 if $RAWPROFILEFLAG
416 then # profile version
417 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPROFILE"
418 fi
419
420 if $RAWUSEIOFLAG
421 then # useio version
422 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWUSEIO"
423 fi
424
425 if $INTERRUPTFLAG
426 then #INTERRUPT version
427 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
428 fi #INTERRUPT version
429
430 if $RAWUSEIOFLAG
431 then # useio version
432 MAKEFILE="$MAKEFILE.io"
433 echo "+++++++++++use Makefile.raw.io++++++++++++++++"
434 else
435 MAKEFILE="$MAKEFILE.$RAWCONFIG"
436 fi #useio version
437
438 cp $MAKEFILE ./Makefile
439 cp ../Runtime/*.c ./
440 cp ../Runtime/*.h ./
441 cp ../Runtime/*.S ./
442 cp ../Runtime/*.s ./
443 cp ../tmpbuilddirectory/*.c ./
444 cp ../tmpbuilddirectory/*.h ./
445
446 make
447
448 else #!RAWFLAG
449 cd $CURDIR 
450
451 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
452 -I$BUILDDIR"
453
454 if $MULTICOREFLAG
455 then
456 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
457 else
458 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
459 fi
460
461 FILES="$RUNTIMEFILE \
462 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
463 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
464 $ROBUSTROOT/Runtime/ObjectHash.c \
465 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
466 $ROBUSTROOT/Runtime/math.c \
467 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
468
469 if $DSMFLAG
470 then
471 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
472 if $TRANSSTATSFLAG
473 then
474 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
475 fi
476 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 $ROBUSTROOT/Runtime/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c $DSMRUNTIME/dsmlock.c $DSMRUNTIME/prefetch.c"
477 fi
478
479 if $SINGLETM
480 then
481 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER"
482 FILES="$FILES $DSMRUNTIME/dsmlock.c $DSMRUNTIME/singleTMCommit.c $DSMRUNTIME/clookup.c"
483 fi
484
485 if $ABORTREADERS
486 then
487 FILES="$FILES $DSMRUNTIME/abortreaders.c"
488 fi
489
490 if $FASTCHECK
491 then
492 FILES="$FILES $ROBUSTROOT/Runtime/localobjects.c"
493 fi
494
495 if $MLP
496 then
497 FILES="$FILES $ROBUSTROOT/Runtime/mlp_runtime.c"
498 fi
499
500 if $RECOVERFLAG
501 then
502 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
503 if $MULTICOREFLAG
504 then
505 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
506 fi
507 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/chash.c"
508 if $RAWFLAG
509 then
510 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
511 fi
512 if $THREADSIMULATEFLAG
513 then
514 # -lpthread for pthread functions, -lrt for message queue functions
515 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
516 fi
517 fi
518
519 if $OPTIONALFLAG
520 then
521 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
522 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
523 fi
524
525 if $THREADFLAG
526 then
527 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
528 fi
529
530 if $CHECKFLAG
531 then
532 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
533 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
534 fi
535
536 if $USEDMALLOC
537 then
538 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
539 fi
540
541 if $MULTICOREFLAG
542 then
543 gcc $INCLUDES $EXTRAOPTIONS \
544 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
545 else
546 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
547 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
548 fi
549
550 fi #!RAWFLAG
551
552 exit
553