57 lines
1.4 KiB
Bash
57 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# 定义输入和输出路径
|
|
input_dir="../test/"
|
|
output_dir="./"
|
|
|
|
# 默认不生成可执行文件
|
|
generate_executable=false
|
|
|
|
# 解析命令行参数
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
--executable|-e)
|
|
generate_executable=true
|
|
shift
|
|
;;
|
|
*)
|
|
echo "Unknown parameter: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# 确保输出目录存在
|
|
mkdir -p "$output_dir"
|
|
|
|
# 遍历输入路径中的所有 .sy 文件
|
|
for sy_file in "$input_dir"*.sy; do
|
|
# 获取文件名(不带路径和扩展名)
|
|
base_name=$(basename "$sy_file" .sy)
|
|
|
|
# 定义输出文件路径
|
|
output_file="${base_name}_clang.ll"
|
|
|
|
# 使用 clang 编译 .sy 文件为 .ll 文件
|
|
clang -x c -S -emit-llvm "$sy_file" -o "$output_file"
|
|
|
|
# 检查是否成功
|
|
if [ $? -eq 0 ]; then
|
|
echo "Compiled $sy_file -> $output_file"
|
|
else
|
|
echo "Failed to compile $sy_file"
|
|
continue
|
|
fi
|
|
|
|
# 如果指定了 --executable 或 -e 参数,则进一步编译为可执行文件
|
|
if $generate_executable; then
|
|
executable_file="${base_name}_clang"
|
|
clang "$output_file" -o "$executable_file"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "Generated executable: $executable_file"
|
|
else
|
|
echo "Failed to generate executable from $output_file"
|
|
fi
|
|
fi
|
|
done |