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