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/crsn/src/asm/data/rd.rs

56 lines
1.2 KiB

use std::fmt::{Debug, Display, Formatter};
use std::fmt;
use crate::asm::data::{RdData, Register};
use crate::asm::data::literal::Value;
/// Data source argument (read-only)
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct Rd(pub RdData);
impl Rd {
pub const fn new(src: RdData) -> Self {
Rd(src)
}
pub const fn immediate(val: Value) -> Rd {
Rd(RdData::Immediate(val))
}
}
impl Display for Rd {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0) // TODO mask, when implemented
}
}
impl Debug for Rd {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Rd({})", self.0)
}
}
/// Reference an object through a handle
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct RdObj(Register);
impl RdObj {
pub const fn new(reg: Register) -> Self {
RdObj(reg)
}
pub const fn reg(self) -> Register {
self.0
}
}
impl Display for RdObj {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "@{}", self.0)
}
}
impl Debug for RdObj {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Obj({})", self.reg())
}
}