Use official RISCV opcodes repository to parse RISCV instructions.
asm-riscv supports only RV32I instructions and is not actively developed.
rust-riscv-disasm supports more instructions however it is not maintained and lacks tests.
On the other hand, the official riscv-opcodes project offers full instruction set support for all sort of languages including rust. Also, it is actively used in multiple projects and in real fabbed chips.
Upon running make
, a rust file containing all the required constants is created:
/* Automatically generated by parse_opcodes */
const MATCH_ADD: u32 = 0x33;
const MASK_ADD: u32 = 0xfe00707f;
...
Usage:
if ((l & MASK_ADD) == MATCH_ADD)
...
After that, all it needs is to extract reg locations and immediate then print.