use crate::convert::{ ToAssembly, Separator };
#[macro_export]
macro_rules! label {
($label:expr) => {
instruction::Mnemonic::Label(instruction::Label::with_colon($label))
}
}
#[macro_export]
macro_rules! operand_label {
($label:expr) => {
instruction::Operand::Label($label.to_string())
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Label {
label: String,
colon: bool,
}
impl Label {
pub fn new(label: &str, colon: bool) -> Self {
Self {
label: label.to_string(),
colon,
}
}
pub fn with_colon(label: &str) -> Self {
Self::new(label, true)
}
pub fn without_colon(label: &str) -> Self {
Self::new(label, false)
}
}
impl ToAssembly for Label {
fn to_assembly(&self, separator: Separator) -> String {
format!("{}{}", self.label, if self.colon {":"} else {""})
}
}