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 v;
8pub mod zicond;
9pub mod zicsr;
10
11use crate::registers::general_purpose::Register;
12use core::fmt;
13use core::marker::Destruct;
14
15/// Generic instruction
16pub const trait Instruction:
17    fmt::Display + fmt::Debug + [const] Destruct + Copy + Send + Sync + Sized
18{
19    /// A register type used by the instruction
20    type Reg: Register;
21
22    /// Try to decode a single valid instruction
23    fn try_decode(instruction: u32) -> Option<Self>;
24
25    /// Instruction alignment in bytes
26    fn alignment() -> u8;
27
28    /// Instruction size in bytes
29    fn size(&self) -> u8;
30}