-
Notifications
You must be signed in to change notification settings - Fork 0
/
do.sh
executable file
·118 lines (107 loc) · 2.54 KB
/
do.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
#!/bin/bash
# if [ "$1" != "" ]; then
# echo "Compiling $1"
# ./simple < $1 > 2.ll || exit 1
# opt-3.8 -O3 2.ll -S -o 1.ll
# rm 2.ll
# llc-3.8 -O3 1.ll -o 1.s
# clang 1.s ./edsger_lib-master/lib.a -o a.out
# fi
# VAR=$(grep -m 1 'def' $1 | tr ' ' ' ')
# readonly VAR
# Entry_point="$(echo $VAR | awk '{print $NF}')"
# readonly Entry_point
# echo ${Entry_point}
#set -x
Oflag=0
layoutflag=true
blockflag=false
asmout=false
irout=false
file=""
while [ $# -gt 0 ]
do
case "$1" in
-O0) Oflag=0;;
-O1) Oflag=1;;
-O2) Oflag=2;;
-O3) Oflag=3;;
-i) irout=true;;
-l) layoutflag=true;;
-b) blockflag=true
layoutflag=false;;
-f) asmout=true;;
-*) ;;
*) file="$1"
esac
shift
done
optf=""
if [ $Oflag -ne 0 ]; then
optf=-O$Oflag
fi
if [ "$file" == "" ] || [ "$irout" == true ] || [ "$asmout" == true ] ; then
if [ "$layoutflag" = true ] ; then
echo "Compiling from stdin with layout"
./simple > 2.ll || exit 1
opt-3.8 $optf 2.ll -S -o 1.ll
rm 2.ll
if [ "$irout" = true ]
then
cat 1.ll
exit 0
fi
llc-3.8 $optf 1.ll -o 1.s
if [ "$asmout" = true ]
then
cat 1.s
exit 0
fi
clang 1.s ./edsger_lib-master/lib.a -o a.out
exit 0
fi
if [ "$blockflag" = true ] ; then
echo "Compiling from stdin with block"
./block > 2.ll || exit 1
opt-3.8 $optf 2.ll -S -o 1.ll
rm 2.ll
if [ "$irout" = true ]; then
cat 1.ll
exit 0
fi
llc-3.8 $optf 1.ll -o 1.s
if [ "$asmout" = true ]; then
cat 1.s
exit 0
fi
clang 1.s ./edsger_lib-master/lib.a -o a.out
exit 0
fi
fi
# var=$(grep -m 1 'def' "$file" )
# a=( $var )
# entry=${a[1]}
#echo $var
if [ "$layoutflag" = true ]; then
echo "Compiling $file with layout"
./simple < $file > 2.ll || exit 1
opt-3.8 $optf 2.ll -S -o 1.ll
llc-3.8 $optf 2.ll -o 1.s
clang 1.s ./edsger_lib-master/lib.a -o a.out
rm 2.ll
exit 0
fi
if [ "$blockflag" = true ]; then
echo "Compiling $file with block"
./block < $file > 2.ll || exit 1
# if [ "$entry" != "main" ];
# then
# sed -i 's/main/_main/g' 2.ll
# sed -i 's/'$entry'/main/g' 2.ll
# fi
opt-3.8 $optf 2.ll -S -o 1.ll
llc-3.8 $optf 1.ll -o 1.s
clang 1.s ./edsger_lib-master/lib.a -o a.out
rm 2.ll
exit 0
fi