capstone/bindings/python/tests/test_all.py
مصطفي محمود كمال الدين 676893c1a8
RISC-V: add reg_access and test its usages in C and Python (#2895)
* RISC-V: add reg_access and test its usages in C and Python

reg_access is a convenience wrapper over the `operands` array that filters the register operands (including those used as memory base address) and returns them sorted into read
and written registers. It wasn't implemented for RISC-V, this PR implements it.

The following decisions were made for RISC-V:
1- System registers (CSRs) are not registers

This follows existing Capstone convention, where almost every archiceture that have system registers except x86 treats them as a seperate address space.

From a purely practical POV, the reg_access function API returns registers as an array of integers, and the address space of normal registers intersects with that of system registers
so there is nothing in the return value to distinguish them.

2- PC is not an implicit register

Whenever an instruction reads PC (e.g. all call-ish instructions JAL[R]?) this is NOT counted as an implicit read of the PC.

The reason is that the PC is somewhat "second class" in RISC-V, it's an archiectural register but has no actual index and can never be directly written to by any instruction in any
standard extension no matter the privliege.

Meanwhile, all instruction that read the PC have names that make it obvious they read the PC so adding that information to the implicit reads array would be redundant.
2026-04-17 17:40:16 +00:00

24 lines
641 B
Python
Executable file

#!/usr/bin/env python3
import test_lite
import test_iter
import test_skipdata
import test_customized_mnem
import test_compatibility_layer
import test_riscv_sysreg
import test_riscv_reg_access
errors = []
errors.extend(test_lite.test_class())
errors.extend(test_iter.test_class())
errors.extend(test_skipdata.test_class())
errors.extend(test_customized_mnem.test())
errors.extend(test_compatibility_layer.test_compatibility())
errors.extend(test_riscv_sysreg.test())
errors.extend(test_riscv_reg_access.test())
if errors:
print("Some errors happened. Please check the output")
for error in errors:
print(error)
exit(1)