Skip to content

try 25 to fix CI

try 25 to fix CI #97

on:
- push
jobs:
smoke-test:
runs-on: ubuntu-latest
steps:
- name: Set up the Ocaml toolchain
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: 5
- name: Fetch the generator sources
uses: actions/checkout@v4
with:
path: generator
- name: Get the hash of the riscv sail model to fetch
id: sail-riscv-model-get-hash
run: cd generator && echo "h=$(cat conf/hash.txt)" >> "$GITHUB_OUTPUT" && echo "Fetching version $(cat sail.hash.txt) of the riscv sail model"
- name: Fetch the riscv sail model
uses: actions/checkout@v4
with:
repository: riscv/sail-riscv
ref: ${{ steps.sail-riscv-model-get-hash.outputs.h }}
path: sail-riscv/
sparse-checkout: model
- name: Install generator dependencies
run: |
cd generator && source ~/.bash_profile
export OPAMCONFIRMLEVEL=yes
opam update
sudo apt-get install build-essential libgmp-dev z3 pkg-config
opam install sail=0.19
sudo apt-get install z3
opam install . --deps-only
- name: Running the generator
run: |
cd generator && source ~/.bash_profile
mv riscv_disasm old_output
eval $(opam config env)
OCAMLRUNPARAM=b dune exec --profile release -- capstone_autosync_sail -f conf/sail-files-paths.txt
- name: Installing clang-format to automatically format the generated source code
run: |
python -m pip install clang-format
- name: Fetch the capstone sources (for SStream.c specifically)
uses: actions/checkout@v4
with:
repository: capstone-engine/capstone
path: capstone
- name: Checking the generated code compiles and is identical to the committed generated code
run: |
cd generator/riscv_disasm
touch test_main.c
echo '#include "RISCVAst.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVDecode.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVDecodeCompressed.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVAst2Str.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVAst2StrTbls.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVInsn.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVInsnMappings.gen.inc"' >> test_main.c
echo >> test_main.c
echo '#include "RISCVOperands.gen.inc"' >> test_main.c
echo >> test_main.c
echo 'void main() {}' >> test_main.c
mv ../old_output/RISCVAst2StrHelpers.h RISCVAst2StrHelpers.h
mv ../old_output/RISCVDecodeHelpers.h RISCVDecodeHelpers.h
mv ../old_output/RISCVOperandsHelpers.h RISCVOperandsHelpers.h
mv ../old_output/RISCVRVContextHelpers.h RISCVRVContextHelpers.h
# cs_vsnprintf is the same as vsnprintf outside of windows
# using vsnprintf directly allows avoiding to compile most of Capstone
sed 's/cs_vsnprintf/vsnprintf/g' ../../capstone/SStream.c -i
# for #include "../../SStream.h" to work in generated code
# also for #include "../../cs_priv.h" to work
cp ../../capstone/*.h ../../
mkdir -p ../../include/capstone/
cp ../../capstone/include/capstone/*.h ../../include/capstone/
# try compiling all generated code
gcc -I../../capstone/include test_main.c ../../capstone/SStream.c \
|| { \ # else
echo "Failure: Trying to compile the tool-generated C code failed."; \
exit 1; \
}
ll a.out && echo "Compilation Succeeded, formatting file using clang-format"
clang-format -i *
if ! diff -q RISCVAst.gen.inc ../old_output/RISCVAst.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated ast definition differ from the one committed in the repo."
exit 1
fi
if ! diff -q RISCVDecode.gen.inc ../old_output/RISCVDecode.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated decoding logic differ from the one committed in the repo."
exit 1
fi
if ! diff -q RISCVDecodeCompressed.gen.inc ../old_output/RISCVDecodeCompressed.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated compressed (16-bit) decoding logic differ from the one committed in the repo."
exit 1
fi
if ! diff -q RISCVAst2StrTbls.gen.inc ../old_output/RISCVAst2StrTbls.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated stringification helpers differ from the one committed in the repo"
exit 1
fi
if ! diff -q RISCVAst2Str.gen.inc ../old_output/RISCVAst2Str.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated ast stringification logic differ from the one committed in the repo"
exit 1
fi
if ! diff -q RISCVInsnMappings.gen.inc ../old_output/RISCVInsnMappings.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated ast-id->instruction-id mapping logic differ from the one committed in the repo"
exit 1
fi
if ! diff -q RISCVInsn.gen.inc ../old_output/RISCVInsn.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated instruction ids differ from the one committed in the repo"
exit 1
fi
if ! diff -q RISCVOperands.gen.inc ../old_output/RISCVOperands.gen.inc > /dev/null 2>&1; then
echo "Failure: The tool-generated operands extraction logic differ from the one committed in the repo"
exit 1
fi
echo "Success: The tool generates compiling C code that is identical to the files committed."