Crates.io | riscy-isa |
lib.rs | riscy-isa |
version | 0.1.1 |
source | src |
created_at | 2021-08-08 19:04:55.088403 |
updated_at | 2021-08-08 21:36:03.582796 |
description | Encodes and decodes streams of RISC-V instructions. |
homepage | |
repository | https://github.com/michaelmelanson/riscy |
max_upload_size | |
id | 433308 |
size | 69,410 |
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.
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);
This crate partially or fully supports the following RISC-V extensions:
MULHSU
is not implemented)