Moved inst::DecodeError to inst::error.

This commit is contained in:
2021-04-10 05:17:58 +01:00
parent e2ba82e8af
commit 64aacedaf6
2 changed files with 27 additions and 20 deletions

View File

@@ -21,6 +21,7 @@
// Modules
pub mod basic;
pub mod directive;
pub mod error;
pub mod fmt;
pub mod iter;
pub mod pseudo;
@@ -30,6 +31,7 @@ pub mod target;
// Exports
pub use directive::Directive;
pub use error::DecodeError;
pub use fmt::{InstFmt, InstTargetFmt};
pub use iter::ParseIter;
pub use reg::Register;
@@ -37,8 +39,8 @@ pub use size::InstSize;
pub use target::InstTarget;
// Imports
use self::{basic::Decodable as _, directive::DecodeWithDataError, pseudo::Decodable as _};
use crate::{Data, DataTable, FuncTable, Pos};
use self::{basic::Decodable as _, pseudo::Decodable as _};
use crate::{DataTable, FuncTable, Pos};
/// An assembler instruction.
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
@@ -54,24 +56,6 @@ pub enum Inst<'a> {
Directive(Directive<'a>),
}
/// Error type for [`Inst::decode`]
#[derive(Debug, thiserror::Error)]
pub enum DecodeError<'a> {
/// Invalid data location to read from
#[error("Attempted to decode instruction from within data location")]
InvalidDataLocation {
/// The data location
data: &'a Data,
/// Underlying error
err: DecodeWithDataError,
},
/// Bytes is empty
#[error("No more bytes")]
NoBytes,
}
impl<'a> Inst<'a> {
/// Decodes an instruction from bytes and it's position.
pub fn decode(pos: Pos, bytes: &'a [u8], data_table: &'a DataTable, _func_table: &'a FuncTable) -> Result<Self, DecodeError<'a>> {

23
dcb-exe/src/inst/error.rs Normal file
View File

@@ -0,0 +1,23 @@
//! Errors
// Imports
use super::directive::DecodeWithDataError;
use crate::Data;
/// Error type for [`Inst::decode`](super::Inst::decode)
#[derive(Debug, thiserror::Error)]
pub enum DecodeError<'a> {
/// Invalid data location to read from
#[error("Attempted to decode instruction from within data location")]
InvalidDataLocation {
/// The data location
data: &'a Data,
/// Underlying error
err: DecodeWithDataError,
},
/// Bytes is empty
#[error("No more bytes")]
NoBytes,
}