-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsahlc
More file actions
executable file
·97 lines (83 loc) · 1.96 KB
/
sahlc
File metadata and controls
executable file
·97 lines (83 loc) · 1.96 KB
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
#!/usr/bin/bash
print_usage() {
printf "Usage: "
printf " %s [options] <file.sahl>\n" "$0"
printf " %s [options] <file.c> <file.sahl> ...\n" "$0"
printf " %s [options] <file.o> <file.sahl> ...\n" "$0"
printf "Options:\n"
printf " -o <file> Output file name\n"
printf " -h Print this help message\n"
}
check() {
if [ $? -ne 0 ]; then
echo "error: failed to compile $file"
exit 1
fi
}
if [ $# -eq 0 ]; then
print_usage
exit 1
fi
files=()
while [ $# -gt 0 ]; do
case "$1" in
-o)
shift
o=$1
;;
-h)
print_usage
exit 0
;;
*)
files+=("$1")
;;
esac
shift
done
# if there is no $o then set it to exe
if [ -z "$o" ]; then
o="exe"
fi
files_str=$(printf " %s" "${files[@]}")
echo "compiling $file_str to $o"
# $rt=./runtime/target/release/libruntime.so
base_dir=$(dirname "$0")
rt=$base_dir/runtime/rt.c
sahl_compiler=$base_dir/frontend/target/release/sahl
cmds=()
compiled_files=()
for f in "${files[@]}"; do
# if sahl file
if [[ $f == *.sahl ]]; then
f_o=${f%.*}.o
f_ll=${f%.*}.ll
cmds+=("$sahl_compiler $f -n 2>$f_ll")
cmds+=("clang -O3 -c -o ./$f_o $f_ll")
compiled_files+=("./$f_o")
elif [[ $f == *.c ]]; then
f_o=${f%.*}.o
cmds+=("clang -O3 -c $f -o $f_o")
compiled_files+=("./$f_o")
elif [[ $f == *.o ]]; then
# do nothing
object=1
else
echo "error: invalid file type $f"
exit 1
fi
done
for cmd in "${cmds[@]}"; do
echo $cmd
eval "$cmd; check $1"
done
compiled=$(printf " %s" "${compiled_files[@]}")
rt_compile="clang -O3 -c $base_dir/$rt -o $base_dir/rt.o"
if [ ! -f $base_dir/rt.o ];
then
echo $rt_compile
eval "$rt_compile; check $1"
fi
linker="clang -lm -O3 $base_dir/rt.o $compiled $base_dir/libs/libgc.a -o ./$o"
echo $linker
eval "$linker; check $1"