Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crsn/csn_asm/src/error.rs

49 lines
1.4 KiB

4 years ago
use crate::instr::{Cond};
use crate::data::{Mask, Register};
use thiserror::Error;
use std::borrow::Cow;
/// csn_asm unified error type
#[derive(Error,Debug)]
pub enum Error {
#[error("S-expression syntax error: {0:?}")]
PreParse(#[from] Box<sexp::Error>),
#[error("Parse error: {0:?}")]
Parse(Cow<'static, str>),
#[error("Parse error in {1:?}: {0:?}")]
ParseIn(Cow<'static, str>, sexp::Sexp),
#[error("Assembler error: {0:?}")]
Asm(AsmError),
#[error("Architecture error: {0:?}")]
Arch(ArchError),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
/// Error from the assembler stage (after parsing S-expressions and basic validation)
#[derive(Error,Debug)]
pub enum AsmError {
#[error("Unknown instruction")]
UnknownInstruction,
#[error("Bad bit mask")]
BadMask(Mask),
#[error("Uneven operand size")]
UnevenOperandSize(Mask, Mask),
#[error("Value provided as output argument")]
ValueAsOutput,
#[error("Conditional branch already defined for \"{0}\"")]
ConditionalAlreadyUsed(Cond),
}
/// Architectural error - the code is syntactically OK, but cannot run
#[derive(Error,Debug)]
pub enum ArchError {
#[error("Register {0} does not exist")]
RegisterNotExist(Register),
#[error("Register {0} is not writable")]
RegisterNotWritable(Register),
#[error("Register {0} is not readable")]
RegisterNotReadable(Register),
}