riscy-isa 0.1.1

Encodes and decodes streams of RISC-V instructions.
Documentation
  • Coverage
  • 1.42%
    4 out of 282 items documented2 out of 3 items with examples
  • Size
  • Source code size: 69.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • michaelmelanson/riscy
    21 2 3
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • michaelmelanson

RISC-V instruction encoding and decoding.

This crate allows you to encode and decode streams of RISC-V instructions to and from Rust structs.

To get the instruction streams out of an ELF binary, which is where you'll normally find them, I recommend the goblin crate.

Example

use riscy_isa::{Opcode, DecodingStream, Instruction, Register, OpImmFunction};
let bytes: [u8; 4] = [19, 5, 0, 0];
let mut stream = DecodingStream::new(&bytes);
// Decodes to an `addi a0, x0, 0` instruction
assert_eq!(stream.next(), Some(Instruction::I {
    opcode: Opcode::OpImm(OpImmFunction::ADDI),
    rd: Register::A0,
    rs1: Register::Zero,
    imm: 0,
}));
// There's only one instruction in the byte array so any further calls to
// `next` return `None`.
assert_eq!(stream.next(), None);

Compatibility

This crate partially or fully supports the following RISC-V extensions:

  • RV64I Base instruction set.
  • "M" Integer multiplication & division (exception: MULHSU is not implemented)
  • "A" Atomic operations (exception: Load-Reserved and Store-Condition are not implemented)
  • "Zicsr" Control & Status Register (partial)
  • "C" Compressed instructions (exception: instruction encoding is not implemented)