Separate generating of tables into different scripts so we can use Github action for branch checkout.

This commit is contained in:
Rot127 2024-03-19 04:20:12 -05:00 committed by Rot127
parent 4392b8b518
commit 4d0bf508b2
5 changed files with 172 additions and 108 deletions

View File

@ -56,7 +56,7 @@ jobs:
git config --local user.name "github-actions[bot]"
cd ../llvm-project
echo "sparse checkout"
git sparse-checkout set llvm/ cmake/ third-party/
git sparse-checkout set llvm/ cmake/ third-party/ .github/
rm -rf .git/ .github/
ls -la
cd -

View File

@ -8,7 +8,7 @@ on:
- "README.md"
- "LICENSE.TXT"
- "SECURITY.md"
branches:
branches:
- auto-sync*
pull_request:
paths-ignore:
@ -17,12 +17,12 @@ on:
- "README.md"
- "LICENSE.TXT"
- "SECURITY.md"
branches:
branches:
- auto-sync*
- release/**
jobs:
build-llvm-tblgen:
build-and-test-llvm-tblgen:
runs-on: ubuntu-latest
steps:
- name: Checkout llvm-capstone
@ -34,16 +34,35 @@ jobs:
- name: Install dependencies
run: pip install cmake Ninja
- name: Build llvm tblgen
env:
CC: gcc-12
CXX: g++-12
- name: Build patched llvm-tblgen
run: |
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
cmake --build . --target llvm-tblgen --config Debug
cd ..
- name: Test generated tables
- name: Generate Capstone tables
run: |
./gen_cs_tables.sh
- name: Checkout llvm-capstone
uses: actions/checkout@v4
ref: auto-sync-18-base
- name: Build LLVM llvm-tblgen
run: |
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
cmake --build . --target llvm-tblgen --config Debug
cd ..
- name: Generate original LLVM tables
run: |
./gen_llvm_tables.sh
- name: Compare LLVM and Capstone tables and syntax
run: |
./compare_tblgen_output.sh

View File

@ -2,105 +2,7 @@
# Compare the generated tables of our refactored TableGen to the original ones.
# We skip Alpha because it is no longer supported by upstream LLVM
archs="AArch64 ARM PPC"
file_names="GenAsmWriter GenDisassemblerTables GenInstrInfo GenRegisterInfo GenSubtargetInfo GenSystemOperands"
release="18"
gen_dir="output_tmp"
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
build_upstream_llvm()
{
echo "Build upstream llvm-tblgen"
git checkout "auto-sync-$release-base"
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../llvm
cmake --build . --target llvm-tblgen --config Release
cd ..
git checkout "auto-sync-$release"
}
build_capstone_llvm()
{
echo "Build capstone llvm-tblgen"
git checkout "auto-sync-$release"
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../llvm
cmake --build . --target llvm-tblgen --config Release
cd ..
}
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
arch_include="../llvm/lib/Target/PowerPC"
else
arch_include="../llvm/lib/Target/$arch"
fi
echo "\t$arch - $out_file"
if [ $file_name = "GenAsmWriter" ]; then
../build/bin/llvm-tblgen --gen-asm-writer "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenDisassemblerTables" ]; then
../build/bin/llvm-tblgen --gen-disassembler "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenInstrInfo" ]; then
../build/bin/llvm-tblgen --gen-instr-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenRegisterInfo" ]; then
../build/bin/llvm-tblgen --gen-register-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSubtargetInfo" ]; then
../build/bin/llvm-tblgen --gen-subtarget "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSystemOperands" ]; then
if [ $arch != "PPC" ] ; then
../build/bin/llvm-tblgen --gen-searchable-tables "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
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
}
# Generate patched
if gen_all "--printerLang=C++" "CPP_CS"; then
exit 1
fi
if gen_all "--printerLang=CCS" "C_CS"; then
exit 1
fi
# Build original LLVM
build_upstream_llvm
if gen_all "--color" "CPP_LLVM"; then
exit 1
fi
# Requires that LLVM tables were generated before.
echo "Diff LLVM files"
for arch in $archs; do
for file_name in $file_names; do

76
gen_cs_tables.sh Normal file
View File

@ -0,0 +1,76 @@
#!/bin/sh
# Compare the generated tables of our refactored TableGen to the original ones.
# We skip Alpha because it is no longer supported by upstream LLVM
archs="AArch64 ARM PPC"
file_names="GenAsmWriter GenDisassemblerTables GenInstrInfo GenRegisterInfo GenSubtargetInfo GenSystemOperands"
release="18"
gen_dir="output_tmp"
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
arch_include="../llvm/lib/Target/PowerPC"
else
arch_include="../llvm/lib/Target/$arch"
fi
echo "\t$arch - $out_file"
if [ $file_name = "GenAsmWriter" ]; then
../build/bin/llvm-tblgen --gen-asm-writer "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenDisassemblerTables" ]; then
../build/bin/llvm-tblgen --gen-disassembler "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenInstrInfo" ]; then
../build/bin/llvm-tblgen --gen-instr-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenRegisterInfo" ]; then
../build/bin/llvm-tblgen --gen-register-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSubtargetInfo" ]; then
../build/bin/llvm-tblgen --gen-subtarget "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSystemOperands" ]; then
if [ $arch != "PPC" ] ; then
../build/bin/llvm-tblgen --gen-searchable-tables "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
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
}
# Generate patched
if gen_all "--printerLang=C++" "CPP_CS"; then
exit 1
fi
if gen_all "--printerLang=CCS" "C_CS"; then
exit 1
fi

67
gen_llvm_tables.sh Normal file
View File

@ -0,0 +1,67 @@
#!/bin/sh
archs="AArch64 ARM PPC"
file_names="GenAsmWriter GenDisassemblerTables GenInstrInfo GenRegisterInfo GenSubtargetInfo GenSystemOperands"
release="18"
gen_dir="output_tmp"
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
arch_include="../llvm/lib/Target/PowerPC"
else
arch_include="../llvm/lib/Target/$arch"
fi
echo "\t$arch - $out_file"
if [ $file_name = "GenAsmWriter" ]; then
../build/bin/llvm-tblgen --gen-asm-writer "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenDisassemblerTables" ]; then
../build/bin/llvm-tblgen --gen-disassembler "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenInstrInfo" ]; then
../build/bin/llvm-tblgen --gen-instr-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenRegisterInfo" ]; then
../build/bin/llvm-tblgen --gen-register-info "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSubtargetInfo" ]; then
../build/bin/llvm-tblgen --gen-subtarget "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
elif [ $file_name = "GenSystemOperands" ]; then
if [ $arch != "PPC" ] ; then
../build/bin/llvm-tblgen --gen-searchable-tables "$table_type" -o "$out_file" -I "$arch_include" -I "../llvm/include" "$arch_include/$arch.td"
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