-
Notifications
You must be signed in to change notification settings - Fork 38
/
generate_bc.sh
executable file
·114 lines (97 loc) · 2.58 KB
/
generate_bc.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
#!/bin/sh
# Generate bitcode for the .c/.cpp tests in $test_dirs.
sysOS=$(uname -s)
test_dirs="
basic_c_tests
basic_cpp_tests
complex_tests
cpp_types
cs_tests
fs_tests
mem_leak
double_free
mta
non_annotated_tests
path_tests
objtype_tests
ae_overflow_tests
ae_assert_tests
"
root=$(cd "$(dirname "$0")"; pwd)
bc_path="$root/test_cases_bc"
if [[ $sysOS == "Linux" ]];then
########
# Remove previous bc folder and create a new one.
########
git rm -rf "$bc_path"
mkdir -p "$bc_path"
########
# Loops through each folder in test_dirs.
########
for td in $test_dirs; do
########
# Creates a directory for each listed folder.
########
bc_td="$bc_path/$td"
mkdir -p "$bc_td"
########
# Full path to the test dir.
########
full_td="$root/src/$td"
########
# Loops through each file within the folder.
########
for c_f in "$full_td/"*; do
########
# Obtains the text after the '.'.
########
ext=${c_f##*.}
########
# We only look for .c/.cpp files. Check $ext = $f in case the filename is c/cpp.
########
if [ \( "$ext" != "cpp" -a "$ext" != "c" \) -o "$ext" = "$f" ]
then
continue
fi
########
# The output .bc file name.
########
bc_f="$bc_td/`basename "$c_f"`.bc"
########
# If the .bc is newer than the .c/.cpp, then no need to compile.
########
if [ "$bc_f" -nt "$c_f" ]; then
continue
fi
########
# Set up the compiler to clang if the file extension is c else clang++.
########
compiler=""
if [ "$ext" = "c" ]; then
compiler="clang"
else
compiler="clang++"
fi
echo "$0: Compiling '$c_f'"
echo "$0: to '$bc_f'"
########
# created a .ll, let's make it .bc, as the filename suggests.
########
if test $td == "mem_leak"
then
$compiler -Wno-everything -S -emit-llvm -fno-discard-value-names -g -I"$root" "$c_f" -o "$bc_f"
# td = "ae_assert_tests" or "ae_overflow_tests"
elif test $td == "ae_assert_tests"
then
$compiler -Wno-everything -S -c -Xclang -DINCLUDEMAIN -Wno-implicit-function-declaration -fno-discard-value-names -g -emit-llvm -I"$root" "$c_f" -o "$bc_f"
elif test $td == "ae_overflow_tests"
then
$compiler -Wno-everything -S -c -Xclang -DINCLUDEMAIN -Wno-implicit-function-declaration -fno-discard-value-names -g -emit-llvm -I"$root" "$c_f" -o "$bc_f"
else
$compiler -Wno-everything -S -emit-llvm -fno-discard-value-names -I"$root" "$c_f" -o "$bc_f"
fi
#llvm-as "$bc_f" -o "$bc_f"
opt -S -p=mem2reg "$bc_f" -o "$bc_f"
done
done
fi