diff options
| author | iximeow <me@iximeow.net> | 2020-01-03 22:53:09 -0800 | 
|---|---|---|
| committer | iximeow <me@iximeow.net> | 2020-01-12 16:26:39 -0800 | 
| commit | 014b7146f1f0b8ca70056fa45dd44dd70713e7a2 (patch) | |
| tree | 72b28d527f00fa0794c63a6e59d33df384d55da4 /src | |
| parent | a6c2fba0ffe00e2d7a86d9ca7f4dae1611c151dc (diff) | |
allow for granular and customizable errors when decoding instructions
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 25 | 
1 files changed, 19 insertions, 6 deletions
| @@ -159,24 +159,33 @@ impl Address for usize {      fn to_linear(&self) -> usize { *self }  } +pub trait DecodeError { +    fn data_exhausted(&self) -> bool; +    fn bad_opcode(&self) -> bool; +    fn bad_operand(&self) -> bool; +} +  pub trait Decoder<Inst> where Inst: Sized { -    fn decode<T: IntoIterator<Item=u8>>(&self, bytes: T) -> Option<Inst>; -    fn decode_into<T: IntoIterator<Item=u8>>(&self, &mut Inst, bytes: T) -> Option<()>; +    type Error: DecodeError + Debug + Display; +    fn decode<T: IntoIterator<Item=u8>>(&self, bytes: T) -> Result<Inst, Self::Error>; +    fn decode_into<T: IntoIterator<Item=u8>>(&self, &mut Inst, bytes: T) -> Result<(), Self::Error>;  }  #[cfg(feature="use-serde")]  pub trait Arch {      type Address: Address + Debug + Hash + PartialEq + Eq + Serialize + for<'de> Deserialize<'de>; -    type Instruction: LengthedInstruction<Unit=Self::Address> + Debug; -    type Decoder: Decoder<Self::Instruction> + Default; +    type Instruction: Instruction + LengthedInstruction<Unit=Self::Address> + Debug; +    type DecodeError: DecodeError + Debug + Display; +    type Decoder: Decoder<Self::Instruction, Error=Self::DecodeError> + Default;      type Operand;  }  #[cfg(not(feature="use-serde"))]  pub trait Arch {      type Address: Address + Debug + Hash + PartialEq + Eq; -    type Instruction: LengthedInstruction<Unit=Self::Address> + Debug; -    type Decoder: Decoder<Self::Instruction> + Default; +    type Instruction: Instruction + LengthedInstruction<Unit=Self::Address> + Debug; +    type DecodeError: DecodeError + Debug + Display; +    type Decoder: Decoder<Self::Instruction, Error=Self::DecodeError> + Default;      type Operand;  } @@ -186,6 +195,10 @@ pub trait LengthedInstruction {      fn min_size() -> Self::Unit;  } +pub trait Instruction { +    fn well_defined(&self) -> bool; +} +  #[cfg(feature="use-serde")]  impl Serialize for ColorSettings {      fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | 
