#![doc(html_root_url = "https://docs.rs/rucc-asm/0.3.8")]
mod att;
mod bytes;
mod data;
mod format;
pub use crate::att::print;
pub use crate::bytes::assemble;
pub use crate::data::{Globals, Piece, Variable, globals};
pub use crate::format::Directives;
use std::fmt;
pub const MILESTONE: &str = "M3";
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Opcode {
func: String,
opcode: String,
},
Virtual {
func: String,
opcode: String,
},
Encode {
func: String,
opcode: String,
why: String,
},
Distance {
func: String,
bytes: i64,
},
Machine {
triple: String,
},
Thread {
name: String,
},
Image {
name: String,
why: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Opcode { func, opcode } => {
write!(f, "'{func}' has a '{opcode}' and the target does not say what one is")
}
Error::Virtual { func, opcode } => {
write!(f, "'{func}' reached the assembler with a virtual register in a '{opcode}'")
}
Error::Encode { func, opcode, why } => {
write!(f, "'{func}' has a '{opcode}' the encoder refused: {why}")
}
Error::Distance { func, bytes } => {
write!(f, "'{func}' has a jump reaching {bytes} bytes, which does not fit in four")
}
Error::Machine { triple } => {
write!(f, "there is no assembly writer for {triple} in this compiler yet")
}
Error::Thread { name } => {
write!(f, "'{name}' is thread-local, which this compiler does not build yet")
}
Error::Image { name, why } => {
write!(f, "the initializer of '{name}' has {why} in it, which cannot be written")
}
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn milestone_is_recorded() {
assert!(super::MILESTONE.starts_with('M'));
}
}