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