pub struct Decoder { /* private fields */ }Expand description
Decodes instructions for a base ISA with a chosen set of extensions.
Decoder::new enables every supported extension that does not
conflict with another (Extensions::DEFAULT), as the free functions
such as decode do. Presets such as
Decoder::RVA23U64, Decoder::with_only and
Decoder::from_march choose the extensions of a particular target, so
that instructions from other extensions are shown as .insn (or without
aliases, such as lpad, that need them).
use disc_v::{Decoder, Extension, Isa};
// czero.eqz a0,a1,a2
assert_eq!(Decoder::new(Isa::Rv64).decode(0, 0x0ec5d533).to_string(), "czero.eqz a0,a1,a2");
assert_eq!(Decoder::RV64GC.decode(0, 0x0ec5d533).to_string(), ".insn 4, 0x0ec5d533");
let dec = Decoder::RV64GC.with(Extension::Zicond).unwrap();
assert_eq!(dec.decode(0, 0x0ec5d533).to_string(), "czero.eqz a0,a1,a2");
let dec = Decoder::from_march("rv64gc_zicond").unwrap();
assert_eq!(dec, Decoder::RV64GC.with(Extension::Zicond).unwrap());Implementations§
Source§impl Decoder
impl Decoder
Sourcepub const RVA23S64: Decoder
pub const RVA23S64: Decoder
The RVA23S64 profile, which adds the supervisor-mode and hypervisor instructions to RVA23U64.
Sourcepub const fn new(isa: Isa) -> Decoder
pub const fn new(isa: Isa) -> Decoder
A decoder for isa with every supported extension that does not
conflict with another (Extensions::DEFAULT).
Sourcepub fn with_only(
isa: Isa,
extensions: impl Into<Extensions>,
) -> Result<Decoder, Conflict>
pub fn with_only( isa: Isa, extensions: impl Into<Extensions>, ) -> Result<Decoder, Conflict>
A decoder for isa with exactly extensions (and the extensions
they imply), or an error if two of them conflict.
use disc_v::{Decoder, Extension, Isa};
let dec = Decoder::with_only(Isa::Rv32, [Extension::M, Extension::C]).unwrap();
assert_eq!(dec.decode(0, 0x02b50533).to_string(), "mul a0,a0,a1");
assert_eq!(dec.decode(0, 0x00b57553).to_string(), ".insn 4, 0x00b57553"); // fadd.sSourcepub fn with(self, ext: Extension) -> Result<Decoder, Conflict>
pub fn with(self, ext: Extension) -> Result<Decoder, Conflict>
The decoder with ext (and the extensions it implies) enabled, or an
error if it conflicts with an extension already enabled.
Sourcepub fn try_with(self, ext: Extension) -> Decoder
pub fn try_with(self, ext: Extension) -> Decoder
The decoder with ext (and the extensions it implies) enabled, or
the decoder unchanged if ext conflicts with an extension already
enabled.
Sourcepub fn without(self, ext: Extension) -> Decoder
pub fn without(self, ext: Extension) -> Decoder
The decoder with ext (and the extensions that imply it) disabled.
Sourcepub fn extensions(&self) -> Extensions
pub fn extensions(&self) -> Extensions
The enabled extensions.
Sourcepub fn decode(&self, pc: u64, inst: u64) -> Instruction
pub fn decode(&self, pc: u64, inst: u64) -> Instruction
Decodes the instruction inst, located at address pc. See
decode.
Sourcepub fn decode_bytes(&self, pc: u64, bytes: &[u8]) -> Option<Instruction>
pub fn decode_bytes(&self, pc: u64, bytes: &[u8]) -> Option<Instruction>
Decodes the instruction at the start of bytes, located at address
pc. See decode_bytes.
Sourcepub fn disassemble<'a>(&self, pc: u64, bytes: &'a [u8]) -> Disassembler<'a> ⓘ
pub fn disassemble<'a>(&self, pc: u64, bytes: &'a [u8]) -> Disassembler<'a> ⓘ
Disassembles bytes, the first of which is at address pc. See
disassemble.
Sourcepub fn from_march(march: &str) -> Result<Decoder, MarchError<'_>>
pub fn from_march(march: &str) -> Result<Decoder, MarchError<'_>>
A decoder for an ISA string, as passed to compilers with -march,
such as "rv64gc" or "rv32imac_zicsr_zba_zbb".
Version numbers (rv64i2p1) are ignored, as are extensions that
define no instructions (such as Zkt, Sstc or Zvl128b). Some
extensions are decoded as a larger extension that contains them:
Zmmul as M, Zaamo and Zalrsc as A, the Zve embedded vector extensions
as V, and Sha as H. The Zce, Zk, Zkn and Zks bundles are
expanded.
Unknown supervisor- and machine-level extensions (names starting
with s) are also ignored, since nearly all of them define no
instructions, while unknown z and x extensions are errors.
use disc_v::{Decoder, MarchError};
assert_eq!(Decoder::from_march("rv64gc"), Ok(Decoder::RV64GC));
assert_eq!(
Decoder::from_march("rv64gc_xventanacondops"),
Err(MarchError::UnsupportedExtension("xventanacondops")),
);