add multi-thread simulator for multi-core version codes. Also add two new files in...
[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 -mac distributed shared memory mac support
8 echo -check generate check code
9 echo -dmalloc link in dmalloc
10 echo -recover compile task code
11 echo -specdir directory
12 echo -printflat print out flat representation
13 echo -selfloop task - this task cannot self loop forever
14 echo "-excprefetch methoddescriptor - exclude prefetches for this method (specified as class.method)"
15 echo -taskstate do task state analysis
16 echo -tagstate do tag state analysis
17 echo -scheduling do task scheduling
18 echo -multicore generate multi-core version binary
19 echo "-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"
20 echo "-raw generate raw version binary (should be used together with -multicore)"
21 echo -threadsimulate generate multi-thread simulate version binary
22 echo -optional enable optional
23 echo -debug generate debug symbols
24 echo -prefetch do prefetch analysis
25 echo -webinterface enable web interface
26 echo -runtimedebug printout runtime debug messages
27 echo "-thread use support for multiple threads"
28 echo "-optimize call gcc with -O9 (optimize)"
29 echo "-nooptimize call gcc with -O0 (do not optimize)"
30 echo -curdir directory 
31 echo -mainclass class with main method
32 echo -o binary
33 echo -instructionfailures inject code for instructionfailures
34 echo -profile build with profile options
35 echo "-enable-assertions execute assert statements during compilation"
36 echo -help help
37 }
38
39 ROBUSTROOT=~/research/Robust/src
40 DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
41 REPAIRROOT=~/research/Repair/RepairCompiler/
42 CURDIR=`pwd`
43 DSMFLAG=false
44 CHECKFLAG=false
45 RECOVERFLAG=false
46 MULTICOREFLAG=false
47 RAWFLAG=false
48 THREADSIMULATEFLAG=false;
49 USEDMALLOC=false
50 THREADFLAG=false
51 SPECDIR=`pwd`
52 SRCFILES=''
53 EXTRAOPTIONS=''
54 MAINFILE='a'
55 JAVAFORWARDOPTS=''
56 JAVAOPTS=''
57 OPTIONALFLAG=false
58
59 if [[ -z $1 ]]
60 then
61 printhelp
62 exit
63 fi
64
65 while [[ -n $1 ]]
66 do
67 if [[ $1 = '-help' ]]
68 then
69 printhelp
70 exit
71 elif [[ $1 = '-robustroot' ]]
72 then
73 ROBUSTROOT="$2"
74 shift
75 elif [[ $1 = '-o' ]]
76 then
77 MAINFILE="$2"
78 shift
79 elif [[ $1 = '-mainclass' ]]
80 then
81 JAVAOPTS="$JAVAOPTS -mainclass $2"
82 shift
83 elif [[ $1 = '-selfloop' ]]
84 then
85 JAVAOPTS="$JAVAOPTS -selfloop $2"
86 shift
87 elif [[ $1 = '-excprefetch' ]]
88 then
89 JAVAOPTS="$JAVAOPTS -excprefetch $2"
90 shift
91 elif [[ $1 = '-dsm' ]]
92 then
93 JAVAOPTS="$JAVAOPTS -dsm"
94 DSMFLAG=true
95 elif [[ $1 = '-prefetch' ]]
96 then
97 JAVAOPTS="$JAVAOPTS -prefetch"
98 elif [[ $1 = '-printflat' ]]
99 then
100 JAVAOPTS="$JAVAOPTS -printflat"
101 elif [[ $1 = '-trueprob' ]]
102 then
103 JAVAOPTS="$JAVAOPTS -trueprob $2"
104 shift
105 elif [[ $1 = '-mac' ]]
106 then
107 EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
108 elif [[ $1 = '-profile' ]]
109 then
110 EXTRAOPTIONS="$EXTRAOPTIONS -pg"
111 elif [[ $1 = '-taskstate' ]]
112 then
113 JAVAOPTS="$JAVAOPTS -taskstate"
114 elif [[ $1 = '-tagstate' ]]
115 then
116 JAVAOPTS="$JAVAOPTS -tagstate"
117 elif [[ $1 = '-scheduling' ]]
118 then
119 JAVAOPTS="$JAVAOPTS -scheduling"
120 elif [[ $1 = '-multicore' ]]
121 then
122 MULTICOREFLAG=true
123 JAVAOPTS="$JAVAOPTS -multicore"
124 elif [[ $1 = '-numcore' ]]
125 then
126 JAVAOPTS="$JAVAOPTS -numcore $2"
127 shift
128 elif [[ $1 = '-raw' ]]
129 then
130 RAWFLAG=true
131 #JAVAOPTS="$JAVAOPTS -raw"
132 elif [[ $1 = '-threadsimulate' ]]
133 then
134 THREADSIMULATEFLAG=true
135 elif [[ $1 = '-optional' ]]
136 then
137 JAVAOPTS="$JAVAOPTS -optional"
138 OPTIONALFLAG=true
139 elif [[ $1 = '-dmalloc' ]]
140 then
141 USEDMALLOC=true
142 elif [[ $1 = '-recover' ]]
143 then
144 RECOVERFLAG=true
145 JAVAOPTS="$JAVAOPTS -task"
146 elif [[ $1 = '-webinterface' ]]
147 then
148 JAVAOPTS="$JAVAOPTS -webinterface"
149 elif [[ $1 = '-instructionfailures' ]]
150 then
151 JAVAOPTS="$JAVAOPTS -instructionfailures"
152 elif [[ $1 = '-check' ]]
153 then
154 CHECKFLAG=true
155 JAVAOPTS="$JAVAOPTS -conscheck"
156 elif [[ $1 = '-enable-assertions' ]]
157 then
158 JAVAFORWARDOPTS="$JAVAFORWARDOPTS -ea"
159 elif [[ $1 = '-specdir' ]]
160 then
161 cd $2
162 SPECDIR=`pwd`
163 cd $CURDIR
164 shift
165 elif [[ $1 = '-debug' ]]
166 then
167 EXTRAOPTIONS="$EXTRAOPTIONS -g"
168 elif [[ $1 = '-runtimedebug' ]]
169 then
170 EXTRAOPTIONS="$EXTRAOPTIONS -DDEBUG"
171 elif [[ $1 = '-nooptimize' ]]
172 then
173 EXTRAOPTIONS="$EXTRAOPTIONS -O0"
174 elif [[ $1 = '-optimize' ]]
175 then
176 EXTRAOPTIONS="$EXTRAOPTIONS -O9"
177 elif [[ $1 = '-thread' ]]
178 then
179 JAVAOPTS="$JAVAOPTS -thread"
180 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread"
181 THREADFLAG=true
182 elif [[ $1 = '-curdir' ]]
183 then
184 CURDIR=$2
185 shift
186 else
187 SRCFILES="$SRCFILES $1"
188 fi
189 shift
190 done
191
192 BUILDDIR="$CURDIR/tmpbuilddirectory"
193
194 cd $1
195 cd $CURDIR
196 shift
197
198 mkdir $BUILDDIR
199
200 if $CHECKFLAG #Generate structure files for repair tool
201 then
202 JAVAOPTS="$JAVAOPTS -struct structfile"
203 fi
204
205 # Build bristlecone/java sources
206
207 if $MULTICOREFLAG
208 then
209 if ! java $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
210 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR \
211 $JAVAOPTS $SRCFILES
212 then exit $?
213 fi
214 else
215 #if ! java -Xms5m -Xmx100m $JAVAFORWARDOPTS -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
216 if ! java $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \
217 $ROBUSTROOT/ClassLibrary/ -dir $BUILDDIR -precise \
218 $JAVAOPTS $SRCFILES
219 then exit $?
220 fi
221 fi
222
223 # Build all of the consistency specs
224
225 if $CHECKFLAG # CHECKFLAG
226 then
227 cd $SPECDIR
228 mkdir $BUILDDIR/specdir
229 cp $REPAIRROOT/MCC/CRuntime/* $BUILDDIR/specdir
230
231 echo > $BUILDDIR/specs
232
233 # compile specs into C code
234 for i in * # iterate over all directories
235 do
236 if [[ "$i" != "CVS" ]] # CVSDIR CHECK
237 then
238 cd $SPECDIR/$i
239 cat $BUILDDIR/structfile.struct $i.label > $i.struct
240 java -cp $REPAIRROOT/:. MCC.Compiler -name $i -checkonly $i
241 cp size.[c,h] $BUILDDIR/specdir
242 cp $i.c $i\_aux.[c,h] $BUILDDIR/specdir
243 echo $i >> $BUILDDIR/specs
244 fi # CVSDIR CHECK
245 done # iterate over all directories
246
247 #compile C code
248
249 cd $BUILDDIR/specdir
250 ./buildrobust
251 echo > $BUILDDIR/checkers.h
252 for i in `cat $BUILDDIR/specs`
253 do
254 gcc -O0 -g -fbounds-check -c $i\_aux.c
255 echo \#include \"specdir\/$i\_aux.h\" >> $BUILDDIR/checkers.h
256 done
257 fi # CHECKFLAG
258
259 #build and link everything
260
261 cd $CURDIR 
262
263 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
264 -I$BUILDDIR"
265
266 if $MULTICOREFLAG
267 then
268 RUNTIMEFILE="$ROBUSTROOT/Runtime/multicoreruntime.c $ROBUSTROOT/Runtime/multicoretask.c"
269 else
270 RUNTIMEFILE="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/task.c"
271 fi
272
273 FILES="$RUNTIMEFILE \
274 $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c \
275 $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
276 $ROBUSTROOT/Runtime/ObjectHash.c \
277 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
278 $ROBUSTROOT/Runtime/math.c \
279 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
280
281 if $DSMFLAG
282 then
283 EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME"
284 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" 
285 fi
286
287 if $RECOVERFLAG
288 then
289 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
290 if $MULTICOREFLAG
291 then
292 EXTRAOPTIONS="$EXTRAOPTIONS -DMULTICORE"
293 fi
294 FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
295 if $RAWFLAG
296 then
297 EXTRAOPTIONS="$EXTRAOPTIONS -DRAW"
298 fi
299 if $THREADSIMULATEFLAG
300 then
301 # -lpthread for pthread functions, -lrt for message queue functions
302 EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADSIMULATE -lpthread -lrt"
303 fi
304 fi
305
306 if $OPTIONALFLAG
307 then
308 EXTRAOPTIONS="$EXTRAOPTIONS -DOPTIONAL"
309 FILES="$FILES tmpbuilddirectory/optionalarrays.c"
310 fi
311
312 if $THREADFLAG
313 then
314 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
315 fi
316
317 if $CHECKFLAG
318 then
319 EXTRAOPTIONS="$EXTRAOPTIONS -DCONSCHECK $BUILDDIR/specdir/*.o"
320 INCLUDES="$INCLUDES -I$BUILDDIR/specdir"
321 fi
322
323 if $USEDMALLOC
324 then
325 EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC"
326 fi
327
328 if $MULTICOREFLAG
329 then
330 gcc $INCLUDES $EXTRAOPTIONS \
331 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
332 else
333 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
334 tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin
335 fi
336
337 exit
338