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