-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·96 lines (77 loc) · 1.71 KB
/
compile.sh
File metadata and controls
executable file
·96 lines (77 loc) · 1.71 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
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat >&2 <<'EOF'
Usage: ./compile.sh [-o OUTPUT] [COMPILER_FLAGS...] <file1.fc> [file2.fc ...]
OPTIONS:
-o NAME_OR_PATH Output filename
-h, --help Show this help
COMPILER_FLAGS:
-p, --print-ast
--trace-parsing
--trace-scanning
-d, --debug
-a, --alloc
--arch <sim|x64>
EOF
}
out="out"
arch="x64"
inputs=()
compiler_args=()
while [[ $# -gt 0 ]]; do
case "$1" in
-o)
shift
[[ $# -gt 0 ]] || { echo "error: -o requires an argument" >&2; usage; exit 2; }
out="$1"
shift
;;
-p|--print-ast|--trace-parsing|--trace-scanning|-d|--debug|-a|--alloc)
compiler_args+=("$1")
shift
;;
--arch)
shift
[[ $# -gt 0 ]] || { echo "error: --arch requires an argument" >&2; usage; exit 2; }
arch="$1"
compiler_args+=("--arch" "$1")
shift
;;
-h|--help)
usage
exit 0
;;
-*)
echo "error: unknown option: $1" >&2
usage
exit 2
;;
*)
inputs+=("$1")
shift
;;
esac
done
[[ ${#inputs[@]} -gt 0 ]] || { echo "error: no input files provided" >&2; usage; exit 2; }
mkdir -p ./build
if [[ "$arch" == "x64" ]]; then
nasm -f elf64 ./stdlib/stdfunc.asm -o ./build/stdfunc.o
fi
ll_files=()
for src in "${inputs[@]}"; do
[[ -f "$src" ]] || { echo "error: input not found: $src" >&2; exit 2; }
base="$(basename "$src")"
base="${base%.*}"
ll="./build/${base}.ll"
./build/compiler "${compiler_args[@]}" -o "$ll" "$src"
ll_files+=("$ll")
done
if [[ "$out" == */* ]]; then
clang_out="$out"
else
clang_out="./build/$out"
fi
if [[ "$arch" == "x64" ]]; then
clang "${ll_files[@]}" ./build/stdfunc.o -o "$clang_out"
fi