#[non_exhaustive]pub enum EncodeError {
NoForm {
mnemonic: Mnemonic,
},
ImmediateOutOfRange {
value: i64,
},
TargetOutOfRange {
offset: i64,
},
HighByteWithRex,
BaseNotQword {
base: Reg,
},
IndexNotQword {
index: Reg,
},
RspIndex,
RipWithIndex,
}Expand description
Why an instruction could not be encoded.
The encoder tries every form of the mnemonic and reports the failure of the form that came closest: an operand-kind mismatch only when no form took the operand kinds at all.
§Examples
use isa_lang::x86_64::{encode, EncodeError, Inst, Mem, Mnemonic, Operand, Reg, Size};
// Memory to memory has no form.
let m = Mem::new(Size::Qword, Reg::RAX);
let err = encode(&Inst::new(Mnemonic::Mov, [m.into(), m.into()])).unwrap_err();
assert_eq!(err, EncodeError::NoForm { mnemonic: Mnemonic::Mov });
// A 64-bit add takes a sign-extended 32-bit immediate at most.
let err = encode(&Inst::new(Mnemonic::Add, [Reg::RAX.into(), Operand::Imm(1 << 40)])).unwrap_err();
assert_eq!(err, EncodeError::ImmediateOutOfRange { value: 1 << 40 });
assert_eq!(err.to_string(), "immediate 0x10000000000 does not fit any form for these operands");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NoForm
No form of the mnemonic takes operands of these kinds, sizes, and count. Check the operand order (destination first) and widths.
ImmediateOutOfRange
Forms take these operand kinds, but the immediate is outside every
one’s range. Immediates are signed values of the operation’s width;
write -1, not 0xFFFF_FFFF, for a 32-bit all-ones value, and load
wider constants into a register first.
TargetOutOfRange
The branch target is beyond the reach of a 32-bit displacement.
HighByteWithRex
AH, CH, DH, or BH appears in an instruction that needs a REX
prefix (64-bit operation, R8-R15, or SPL/BPL/SIL/DIL),
where those encodings mean SPL-DIL instead. Use another register.
BaseNotQword
A memory operand’s base register is not a 64-bit register.
IndexNotQword
A memory operand’s index register is not a 64-bit register.
RspIndex
RSP is used as an index register, which the SIB byte cannot express.
Swap base and index if the scale is 1.
RipWithIndex
A RIP-relative memory operand has an index register.
Trait Implementations§
Source§impl Clone for EncodeError
impl Clone for EncodeError
impl Copy for EncodeError
Source§impl Debug for EncodeError
impl Debug for EncodeError
Source§impl Display for EncodeError
impl Display for EncodeError
impl Eq for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()