-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun.sh
executable file
·195 lines (150 loc) · 3.55 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
trap 'echo "Killing build_exec.sh script" ; exit' INT TERM
# -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # --
function cleanup() {
rm -f *.bc
rm -f *.rbc
rm -f *.ibc
rm -f *.o
}
function cleanup_all() {
rm -f *.bc
rm -f *.rbc
rm -f *.ibc
rm -f *.o
rm -f *.exe
rm -f *.txt
}
function unset_vars() {
unset COMPILER
unset STDIN
unset STDOUT
unset RUN_OPTIONS
unset CPU2006
}
function set_vars(){
source info.sh
# Let's set the variables that are unset
# sometimes we need to use clang++
[[ -n $COMPILER ]] || COMPILER=clang
# We can specify STDIN to something other than /dev/stdin
[[ -n $STDIN ]] || STDIN=/dev/null
# And STDOUT default is /dev/null.
[[ -n $STDOUT ]] || STDOUT=/dev/null
# But if we set DEBUG=1, than we ignore the previous definition of STDOUT
if [[ $DEBUG == 1 ]]; then
STDOUT=/dev/stdout ;
fi
if [[ $(pwd) =~ "cpu2006" ]]; then
echo "Setting CPU2006=1"
CPU2006=1
fi
# Common files used by comp.sh and instrument.sh
if [[ -n $CPU2006 && $CPU2006 -eq 1 ]]; then
if [[ $(uname -s) == "Linux" ]]; then
rbc_name="$bench_name.linux"
else
rbc_name="$bench_name.llvm"
fi
fi
lnk_name="$bench_name.rbc"
prf_name="$bench_name.ibc"
obj_name="$bench_name.o"
exe_name="$bench_name.exe"
# options for exe name
if [[ -n $INSTRUMENT && $INSTRUMENT -eq 1 ]]; then
exe_name=INS_$exe_name
fi
if [[ -n $ASAN && $ASAN -eq 1 ]]; then
exe_name=ASAN_$exe_name
fi
if [[ $SSA -eq 0 ]]; then
exe_name=NO_SSA_$exe_name ;
fi
}
# -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # --
function walk() {
if [[ $# == 0 ]]; then
echo "Error, you must specify the directories this script must compile"
echo 'ex: walk $( ls -d */ )'
exit
else
dirs=("$@")
fi
parent_dir=$(pwd)
for dir in "${dirs[@]}"; do
cd "$parent_dir"/"$dir" ;
d=$(basename $(pwd))
echo "Sourcing info.sh from $(pwd)" ;
if [[ -n $CLEAN && $CLEAN -eq 1 ]]; then
cleanup_all ;
continue ;
fi
set_vars ;
cleanup ;
if [[ $COMPILE -eq 1 ]]; then
compile ;
fi
execute ;
unset_vars ;
echo
echo "###############"
echo
cd "$parent_dir"
done
}
# -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # -- # --
source "vars.sh"
source "benchs.sh"
source "comp.sh"
source "exec.sh"
if [[ -n $CLEAN && $CLEAN -eq 1 ]]; then
echo "REMOVING ALL TEMP FILES!"
for bench in "${benchs[@]}"; do
cd $BENCHSDIR
echo "Removing from $bench" ;
cd $bench ;
$bench ;
echo "" ;
done
exit 0
fi
if [[ -n $PIN && $PIN -eq 1 ]]; then
# replace the function `execute`
source "exec_pin.sh"
fi
if [[ -n $OCPERF && $OCPERF -eq 1 ]]; then
# replace the function `execute`
source "exec_perf.sh"
fi
if [[ -n $INSTRUMENT && $INSTRUMENT -eq 1 ]]; then
# replace the compile function
source "instrument.sh"
fi
if [[ -n $SANITIZE && $SANITIZE -eq 1 ]]; then
# replace the compile function
source "sanitize.sh"
fi
rm -f /tmp/run.txt
touch /tmp/run.txt
if [[ "$#" -ne 0 ]]; then
# check if the input is a file
if [[ -f "$@" ]]; then
echo "Reading input file..."
# Read the content into "${benchs[@]}" array
IFS=$'\n' read -d '' -r -a benchs < "$@"
else
benchs=( "$@" )
fi
walk "${benchs[@]}" ;
else
for bench in "${benchs[@]}"; do
cd $BENCHSDIR
echo "Starting $bench" ;
cd $bench ;
$bench ;
done
fi
cd $BASEDIR ;
source "parallel.sh"
source "collect.sh"