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