Renamed vasm to vasm_core
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use vcore::opcodes::InvalidMnemonic;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum ParseError {
|
||||
LineParseFailure,
|
||||
InvalidInstruction(String),
|
||||
}
|
||||
|
||||
impl<'a> From<InvalidMnemonic<'a>> for ParseError {
|
||||
fn from(err: InvalidMnemonic<'a>) -> Self {
|
||||
Self::InvalidInstruction(err.0.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ParseError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
use ParseError::*;
|
||||
match self {
|
||||
LineParseFailure => write!(f, "Failed to parse line"),
|
||||
InvalidInstruction(p) => write!(f, "Cannot parse {} as instruction", p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum AssembleError {
|
||||
ParseError(usize, ParseError),
|
||||
EquResolveError(usize, String, EvalError),
|
||||
EquDuplicateError(usize, String),
|
||||
OrgResolveError(usize, EvalError),
|
||||
ArgError(usize, EvalError),
|
||||
NoCode,
|
||||
IncludeError(usize, String),
|
||||
FileError(String),
|
||||
MacroError(usize),
|
||||
}
|
||||
|
||||
impl Display for AssembleError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AssembleError::EquResolveError(line, name, err) => {
|
||||
write!(f, "Cannot resolve .equ {} on line {}: {}", name, line, err)
|
||||
}
|
||||
AssembleError::EquDuplicateError(line, name) => {
|
||||
write!(f, "Duplicate .equ {} on line {}", name, line)
|
||||
}
|
||||
AssembleError::OrgResolveError(line, err) => {
|
||||
write!(f, "Cannot resolve .org on line {}: {}", line, err)
|
||||
}
|
||||
AssembleError::ArgError(line, err) => {
|
||||
write!(f, "Cannot calculate argument on line {}: {}", line, err)
|
||||
}
|
||||
AssembleError::NoCode => {
|
||||
write!(f, "No output would be generated by this code")
|
||||
}
|
||||
AssembleError::ParseError(line, err) => {
|
||||
write!(f, "Parse error on line {}: {}", line, err)
|
||||
}
|
||||
AssembleError::IncludeError(line, file) => {
|
||||
write!(f, "Cannot read \"{}\" on line {}", file, line)
|
||||
}
|
||||
AssembleError::MacroError(line) => {
|
||||
write!(f, "Malformed macro control structure on line {}", line)
|
||||
}
|
||||
AssembleError::FileError(file) => {
|
||||
write!(f, "File read error in {}", file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum EvalError {
|
||||
MissingLabel(String),
|
||||
UnknownAddress(usize),
|
||||
OffsetError(usize, i32),
|
||||
}
|
||||
|
||||
impl Display for EvalError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
EvalError::MissingLabel(label) => write!(f, "Unable to resolve label {}", label),
|
||||
EvalError::UnknownAddress(line_num) => write!(
|
||||
f,
|
||||
"Unable to calculate starting address of line {}",
|
||||
line_num
|
||||
),
|
||||
EvalError::OffsetError(line_num, offset) => {
|
||||
write!(f, "Invalid line offset {} on line {}", offset, line_num)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user