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