-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·80 lines (70 loc) · 1.75 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
dump=false
log_flag=""
release_flag="--release"
sources=()
fuse_lld_flag=""
run=true
simp_to_o() {
local simp_file="$1"
if [[ $simp_file != *.simp ]]; then
echo "Error: Input file must have a .simp extension, but provided $simp_file"
return 1
fi
local base_name="${simp_file%.simp}"
echo "${base_name}.o"
}
print_help() {
echo "flags:"
echo "--dump\tUse objdump to dump the asm per object"
echo "--log\tTell the compiler to log the CLIF IR"
echo "--debug\tUse debug build for the compiler instead of release"
echo "--use-lld\tUse lld linker for clang"
echo "--no-run\tOnly compile the program"
}
for arg in $@; do
if [[ $arg = "--help" ]]; then
print_help
exit 0
elif [[ $arg = "--dump" ]]; then
dump=true
elif [[ $arg = "--log" ]]; then
log_flag="--log"
elif [[ $arg = "--debug" ]]; then
release_flag=""
elif [[ $arg = "--use-lld" ]]; then
fuse_lld_flag="-fuse-ld=lld"
elif [[ $arg = "--no-run" ]]; then
run=false
else
sources+=($arg)
fi
done
if [[ ${#sources[@]} == 0 ]]; then
echo "no source files provided"
exit 1
fi
objects=()
for source in ${sources[@]}; do
out_path=$(simp_to_o $source)
objects+=($out_path)
echo "# $0: Compiling $source into $out_path"
cargo run $release_flag -- $log_flag $source -o $out_path
if [ $? -ne 0 ]; then
exit $?
fi
if $dump; then
objdump -Dr $out_path
fi
done
echo "# $0: Linking"
clang $fuse_lld_flag ${objects[@]} -o program
if [[ $? -ne 0 ]]; then
exit $?
fi
if $run; then
echo "# $0: Executing \`./program\`"
./program
echo "# $0: The program returned $?"
else
echo "# Finished compiling \`program\`"
fi