mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-12 12:59:56 +00:00
Moved inst::DecodeError to inst::error.
This commit is contained in:
@@ -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
23
dcb-exe/src/inst/error.rs
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user