Skip to main content

ab_riscv_primitives/
instructions.rs

1//! This module defines the RISC-V instruction set instructions
2
3pub mod rv32;
4pub mod rv64;
5#[cfg(test)]
6mod test_utils;
7pub mod utils;
8pub mod v;
9pub mod zicond;
10pub mod zicsr;
11
12use crate::registers::general_purpose::Register;
13use core::fmt;
14use core::marker::Destruct;
15
16/// Generic instruction
17pub const trait Instruction:
18    fmt::Display + fmt::Debug + [const] Destruct + Copy + Send + Sync + Sized
19{
20    /// A register type used by the instruction
21    type Reg: Register;
22
23    /// Try to decode a single valid instruction
24    fn try_decode(instruction: u32) -> Option<Self>;
25
26    /// Instruction alignment in bytes
27    fn alignment() -> u8;
28
29    /// Instruction size in bytes
30    fn size(&self) -> u8;
31}