binbun_aarch64/error.rs
1//! Decoding errors.
2
3use core::fmt;
4
5/// Why bytes do not decode to an A64 instruction.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7pub enum Error {
8 /// Fewer than 4 bytes.
9 TooShort,
10 /// No encoding has this word: the space is unallocated.
11 Unallocated,
12 /// The word is an instance of an encoding, but a check in its decode
13 /// pseudocode makes it UNDEFINED (a reserved field value, such as
14 /// `shift == '11'` for an add with shifted register).
15 Undefined,
16 /// The word is an instance of an encoding, but CONSTRAINED UNPREDICTABLE
17 /// (should-be bits not as specified, a load pair loading one register
18 /// twice, …), and rejected as LLVM's disassembler rejects it.
19 Unpredictable,
20}
21
22impl fmt::Display for Error {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.write_str(match self {
25 Self::TooShort => "instruction is truncated",
26 Self::Unallocated => "unallocated encoding",
27 Self::Undefined => "undefined instruction",
28 Self::Unpredictable => "constrained unpredictable instruction",
29 })
30 }
31}
32
33impl core::error::Error for Error {}