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