2024-03-19 09:20:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-06-04 08:29:20 +00:00
|
|
|
archs="AArch64 ARM PPC LoongArch Alpha"
|
2024-03-19 09:20:12 +00:00
|
|
|
file_names="GenAsmWriter GenDisassemblerTables GenInstrInfo GenRegisterInfo GenSubtargetInfo GenSystemOperands"
|
|
|
|
release="18"
|
2024-03-20 07:43:07 +00:00
|
|
|
repo_root=$(git rev-parse --show-toplevel)
|
|
|
|
gen_dir="$repo_root/output_tmp"
|
2024-03-19 09:20:12 +00:00
|
|
|
|
|
|
|
if [ ! -d $gen_dir ]; then
|
|
|
|
mkdir "$gen_dir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
|
|
echo "$0 [--rebuild]"
|
|
|
|
echo "\trebuild - Rebuild Capstone llvm-tblgen after upstream LLVM tables were generated."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
gen_all()
|
|
|
|
{
|
|
|
|
cd $gen_dir
|
|
|
|
table_type="$1"
|
|
|
|
postfix="$2"
|
|
|
|
echo "Generate inc files with $table_type as $postfix"
|
|
|
|
|
|
|
|
for arch in $archs; do
|
|
|
|
for file_name in $file_names; do
|
|
|
|
out_file="$arch$file_name""_$postfix.inc"
|
|
|
|
if [ "$arch" = "PPC" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
arch_include="$repo_root/llvm/lib/Target/PowerPC"
|
2024-03-19 09:20:12 +00:00
|
|
|
else
|
2024-03-20 07:43:07 +00:00
|
|
|
arch_include="$repo_root/llvm/lib/Target/$arch"
|
2024-03-19 09:20:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "\t$arch - $out_file"
|
|
|
|
|
|
|
|
if [ $file_name = "GenAsmWriter" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-asm-writer "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
elif [ $file_name = "GenDisassemblerTables" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-disassembler "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
elif [ $file_name = "GenInstrInfo" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-instr-info "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
elif [ $file_name = "GenRegisterInfo" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-register-info "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
elif [ $file_name = "GenSubtargetInfo" ]; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-subtarget "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
elif [ $file_name = "GenSystemOperands" ]; then
|
2024-06-04 08:29:20 +00:00
|
|
|
if [ $arch != "PPC" ] && [ $arch != "LoongArch" ] ; then
|
2024-03-20 07:43:07 +00:00
|
|
|
$repo_root/build/bin/llvm-tblgen --gen-searchable-tables "$table_type" -o "$out_file" -I "$arch_include" -I "$repo_root/llvm/include" "$arch_include/$arch.td"
|
2024-03-19 09:20:12 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "File $file_name not handled."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Generation of $out_file failed."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if gen_all "--color" "CPP_LLVM"; then
|
|
|
|
exit 1
|
|
|
|
fi
|