get compiler side of STM working
[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 = '-joptimize' ]]
227 then
228 JAVAOPTS="$JAVAOPTS -optimize"
229 elif [[ $1 = '-mlp' ]]
230 then
231 JAVAOPTS="$JAVAOPTS -mlp"
232 elif [[ $1 = '-check' ]]
233 then
234 CHECKFLAG=true
235 JAVAOPTS="$JAVAOPTS -conscheck"
236 elif [[ $1 = '-enable-assertions' ]]
237 then
238 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
239 elif [[ $1 = '-specdir' ]]
240 then
241 cd $2
242 SPECDIR=`pwd`
243 cd $CURDIR
244 shift
245 elif [[ $1 = '-debug' ]]
246 then
247 RAWDEBUGFLAG=true
248 EXTRAOPTIONS="$EXTRAOPTIONS -g"
249 elif [[ $1 = '-rawpath' ]]
250 then
251 RAWPATHFLAG=true
252 elif [[ $1 = '-runtimedebug' ]]
253 then
254 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
255 elif [[ $1 = '-dsmcaching' ]]
256 then
257 EXTRAOPTIONS="$EXTRAOPTIONS -DCACHE"
258 elif [[ $1 = '-rangeprefetch' ]]
259 then
260 EXTRAOPTIONS="$EXTRAOPTIONS -DRANGEPREFETCH"
261 elif [[ $1 = '-nooptimize' ]]
262 then
263 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
264 elif [[ $1 = '-optimize' ]]
265 then
266 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
267 elif [[ $1 = '-thread' ]]
268 then
269 JAVAOPTS="$JAVAOPTS -thread"
270 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
271 THREADFLAG=true
272 elif [[ $1 = '-distributioninfo' ]]
273 then
274 JAVAOPTS="$JAVAOPTS -distributioninfo"
275 elif [[ $1 = '-curdir' ]]
276 then
277 CURDIR=$2
278 shift
279 elif [[ $1 = '-outputdir' ]]
280 then
281 JAVAOPTS="$JAVAOPTS -outputdir $2"
282 shift
283 else
284 SRCFILES="$SRCFILES $1"
285 fi
286 shift
287 done
288
289 BUILDDIR="$CURDIR/tmpbuilddirectory"
290
291 cd $1
292 cd $CURDIR
293 shift
294
295 mkdir $BUILDDIR
296
297 if $CHECKFLAG #Generate structure files for repair tool
298 then
299 JAVAOPTS="$JAVAOPTS -struct structfile"
300 fi
301
302 # Setup class path
303
304 if $RECOVERFLAG
305 then
306 if $FASTCHECK
307 then
308 #fast transactions
309 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/FastCheck"
310 else
311 #base bristlecone files
312 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Bristlecone"
313 fi
314 else
315 if $DSMFLAG
316 then
317 #dsm stuff
318 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaDSM"
319 elif $SINGLETM
320 then
321 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaSTM"
322 elif $THREADFLAG
323 then
324 #threading java stuff
325 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaThread"
326 fi
327 #base java stuff
328 JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/Java"
329 fi
330
331 # Build bristlecone/java sources
332
333 if $MULTICOREFLAG
334 then
335 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx800m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
336 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ \
337 -dir $BUILDDIR $JAVAOPTS $SRCFILES
338 then exit $?
339 fi
340 else
341 #if ! ${ROBUSTROOT}/ourjava -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
342 if ! $NOJAVA
343 then
344 if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx600m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
345 $ROBUSTROOT/ClassLibrary/ -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ -dir $BUILDDIR -precise \
346 $JAVAOPTS $SRCFILES
347 then exit $?
348 fi
349 fi
350 fi
351
352 if $EXITAFTERANALYSIS
353 then
354 exit
355 fi
356
357 # Build all of the consistency specs
358
359 if $CHECKFLAG # CHECKFLAG
360 then
361 cd $SPECDIR
362 mkdir $BUILDDIR/specdir
363 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
364
365 echo > $BUILDDIR/specs
366
367 # compile specs into C code
368 for i in * # iterate over all directories
369 do
370 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
371 then
372 cd $SPECDIR/$i
373 cat $BUILDDIR/structfile.struct $i.label > $i.struct
374 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
375 cp size.[c,h] $BUILDDIR/specdir
376 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
377 echo $i >> $BUILDDIR/specs
378 fi # CVSDIR CHECK
379 done # iterate over all directories
380
381 #compile C code
382
383 cd $BUILDDIR/specdir
384 ./buildrobust
385 echo > $BUILDDIR/checkers.h
386 for i in `cat $BUILDDIR/specs`
387 do
388 gcc -O0 -g -fbounds-check -c $i\_aux.c
389 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
390 done
391 fi # CHECKFLAG
392
393 #build and link everything
394
395 if $RAWFLAG
396 then # RAWFLAG
397 RAWDIR="$CURDIR/raw"
398 MAKEFILE="../Makefile.raw"
399 mkdir $RAWDIR
400 cd $RAWDIR
401 make clean
402 rm ./*
403
404 export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW"
405
406 if $RAWCACHEFLUSHFLAG
407 then # print path
408 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWCACHEFLUSH"
409 fi
410
411 if $RAWPATHFLAG
412 then # print path
413 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPATH"
414 fi
415
416 if $RAWDEBUGFLAG
417 then #debug version
418 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG"
419 fi
420
421 if $RAWPROFILEFLAG
422 then # profile version
423 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPROFILE"
424 fi
425
426 if $RAWUSEIOFLAG
427 then # useio version
428 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWUSEIO"
429 fi
430
431 if $INTERRUPTFLAG
432 then #INTERRUPT version
433 RAWRGCCFLAGS="${RAWRGCCFLAGS} -DINTERRUPT"
434 fi #INTERRUPT version
435
436 if $RAWUSEIOFLAG
437 then # useio version
438 MAKEFILE="$MAKEFILE.io"
439 echo "+++++++++++use Makefile.raw.io++++++++++++++++"
440 else
441 MAKEFILE="$MAKEFILE.$RAWCONFIG"
442 fi #useio version
443
444 cp $MAKEFILE ./Makefile
445 cp ../Runtime/*.c ./
446 cp ../Runtime/*.h ./
447 cp ../Runtime/*.S ./
448 cp ../Runtime/*.s ./
449 cp ../tmpbuilddirectory/*.c ./
450 cp ../tmpbuilddirectory/*.h ./
451
452 make
453
454 else #!RAWFLAG
455 cd $CURDIR 
456
457 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
458 -I$BUILDDIR"
459
460 if $MULTICOREFLAG
461 then
462 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
463 else
464 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
465 fi
466
467 FILES="$RUNTIMEFILE \
468 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
469 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
470 $ROBUSTROOT/Runtime/ObjectHash.c \
471 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
472 $ROBUSTROOT/Runtime/math.c \
473 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
474
475 if $DSMFLAG
476 then
477 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
478 if $TRANSSTATSFLAG
479 then
480 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
481 fi
482 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"
483 fi
484
485 if $SINGLETM
486 then
487 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -I$DSMRUNTIME"
488 FILES="$FILES $DSMRUNTIME/dsmlock.c $DSMRUNTIME/singleTMCommit.c $DSMRUNTIME/clookup.c"
489 fi
490
491 if $ABORTREADERS
492 then
493 FILES="$FILES $DSMRUNTIME/abortreaders.c"
494 fi
495
496 if $FASTCHECK
497 then
498 FILES="$FILES $ROBUSTROOT/Runtime/localobjects.c"
499 fi
500
501 if $MLP
502 then
503 FILES="$FILES $ROBUSTROOT/Runtime/mlp_runtime.c"
504 fi
505
506 if $RECOVERFLAG
507 then
508 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
509 if $MULTICOREFLAG
510 then
511 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
512 fi
513 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/chash.c"
514 if $RAWFLAG
515 then
516 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
517 fi
518 if $THREADSIMULATEFLAG
519 then
520 # -lpthread for pthread functions, -lrt for message queue functions
521 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
522 fi
523 fi
524
525 if $OPTIONALFLAG
526 then
527 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
528 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
529 fi
530
531 if $THREADFLAG
532 then
533 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
534 fi
535
536 if $CHECKFLAG
537 then
538 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
539 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
540 fi
541
542 if $USEDMALLOC
543 then
544 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
545 fi
546
547 if $MULTICOREFLAG
548 then
549 gcc $INCLUDES $EXTRAOPTIONS \
550 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
551 else
552 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
553 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
554 fi
555
556 fi #!RAWFLAG
557
558 exit
559