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