-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcompile.sh
executable file
·45 lines (34 loc) · 1.21 KB
/
compile.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
#!/bin/bash
set -e
compile_files() {
local src_dir="examples/source"
local gen_type=$1
find "$src_dir" -name "*.ola" | while read src_file; do
local base_name="${src_file%.*}"
local sub_dir="$(dirname "$base_name")"
local dst_dir="examples/$gen_type"
if [ "$sub_dir" != "$src_dir" ]; then
sub_dir=${sub_dir#$src_dir/}
dst_dir="$dst_dir/$sub_dir"
fi
mkdir -p "$dst_dir"
echo "Compiling $src_file..."
./target/debug/olac compile "$src_file" --gen "$gen_type" --output "$dst_dir"
if [ "$gen_type" = "llvm-ir" ]; then
local ir_file="$dst_dir/$(basename "$base_name").ll"
if [ -f "$ir_file" ]; then
echo "Validating LLVM IR for $ir_file..."
llc "$ir_file" -o /dev/null
if [ $? -ne 0 ]; then
echo "Validation failed for $ir_file"
else
echo "Validation successful for $ir_file"
fi
else
echo "Skipping validation, IR file not found for $src_file"
fi
fi
done
}
# Call the function with the command-line argument
compile_files $1