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