-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRUNME.sh
executable file
·144 lines (125 loc) · 3.5 KB
/
RUNME.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
#!/bin/bash
# stop whenever encountering errors
set -e
function check(){
if ! [[ -x "$(command -v opt)" ]]; then
echo "Error: opt can not be found." >&2
exit 1
fi
if [[ -z "$(opt --version |grep 4.0.1)" ]]; then
echo "Warning: the version of your opt is not 4.0.1, you might encounter errors." >&2
fi
}
function run(){
echo "Run pass analysis on $3 with $1, whose pass name is $2 ..."
if [[ -z "$4" ]]; then
echo "Get output file with name $4, output will be redirected to it ..."
fi
echo "Run opt -load \"$1\" -$2 -analyze \"$3\" |tee \"$4\""
#opt -load "$1" -$2 -analyze $3 |tee "$4"
}
function fullname(){
relp=$1
cwd=$(pwd)
cd "${relp}"
fullp=$(pwd)
cd $(cwd)
echo "${fullp}"
}
function getPassName(){
prefix="lib"
suffix=".so"
fname=$(basename $1)
pname=${fname#$prefix}
pname=${pname%$suffix}
echo "${pname}"
}
function batchRunPass(){
inputDir=$1
libDir=$2
outputDir=$3
outputPrefix=$4
for lib in `ls ${libDir}/*|grep .so`; do
echo "get ${lib} ..."
pname=$(getPassName "${lib}")
echo "get pass name ${pname} ..."
for llfile in `ls ${inputDir}/*|grep -E ".ll|.bc"`; do
echo "get ${llfile} ..."
suffix_ll=$(basename $llfile)
suffix_ll=${suffix_ll%.*}
run "${lib}" "${pname}" "${llfile}" "${outputDir}_${outputPrefix}_${pname}_${suffix_ll}.txt"
done
done
}
function usage(){
echo "usage: RUNME.sh [-h] [-i <input> -l <lib> -p <pass-name>] [-I <input-dir>] [-L <lib-dir>] [-o <output>] [-O <output-dir>]
-h display this help information.
-i <input> input file, could be a .ll file or a .bc
file.
-I <input-dir> input directory.
-l <lib> lib file, i.e., the LLVM pass library.
-L <lib-dir> lib directory.
-p <pass-name> pass name.
-o <output> output file (prefix).
-O <output-dir> output directory.
Note that if note directory information is provided, we will
use current directory as the default one. If no file name
is provided, we will search them automatically. If no pass name
is provided, we will assume its name is just the library name
by removing '.so' and 'lib'.
Enjoy it!"
exit 1
}
check
idir="$(pwd)"
libdir="$(pwd)"
odir="$(pwd)"
output="output"
while getopts "hi:I:l:L:p:o:O:" opt; do
case $opt in
h)
usage
;;
i)
ifile=$OPTARG
;;
I)
idir=$OPTARG
;;
l)
libfile=$OPTARG
;;
L)
libdir=$OPTARG
;;
p)
pname=$OPTARG
;;
o)
output=$OPTARG
;;
O)
odir=$OPTARG
;;
\?)
echo "Invalid option: $opt " >&2
usage
;;
esac
done
echo "lib: ${lib}"
echo "pname: ${pname}"
echo "ifile: ${ifile}"
echo "idir: ${idir}"
echo "libdir: ${libdir}"
if [ ! -z "${lib}" ] || [ ! -z "${pname}" ] || [ ! -z "${ifile}" ]; then
if [ ! -z "${lib}" ] && [ ! -z "${pname}" ] && [ ! -z "${ifile}" ]; then
run "${libdir}/${lib}" "${pname}" "${idir}/${input}" "${odir}/${output}.txt"
else
echo "Error: you should specify none or all of <lib>, <pass-name>, and <input>."
usage
fi
else
echo "Run batchRunPass ..."
batchRunPass "${idir}" "${libdir}" "${odir}" "${output}"
fi