forked from MightyPork/crsn
parent
79d5aa3cd5
commit
d5de189af6
@ -0,0 +1,58 @@ |
||||
use crate::asm::data::{RdData, Mask, DataDisp, Register}; |
||||
use crate::asm::data::literal::Value; |
||||
use std::fmt::{Debug, Formatter}; |
||||
use std::fmt; |
||||
|
||||
/// Data source argument (read-only)
|
||||
#[derive(Clone, Copy, Eq, PartialEq)] |
||||
pub struct Rd(pub RdData, pub Mask); |
||||
|
||||
impl Rd { |
||||
pub const fn new(src: RdData) -> Self { |
||||
Rd(src, Mask::FULL) |
||||
} |
||||
pub fn data(self) -> RdData { |
||||
self.0 |
||||
} |
||||
pub fn mask(self) -> Mask { |
||||
self.1 |
||||
} |
||||
|
||||
pub fn immediate(val: Value) -> Rd { |
||||
Rd(RdData::Immediate(val), Mask::default()) |
||||
} |
||||
} |
||||
|
||||
impl Debug for Rd { |
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
||||
write!(f, "Rd(")?; |
||||
let disp: DataDisp = self.0.into(); |
||||
write!(f, "{}", disp)?; |
||||
if !self.mask().is_default() { |
||||
write!(f, ",{:?}", self.mask())?; |
||||
} |
||||
write!(f, ")") |
||||
} |
||||
} |
||||
|
||||
|
||||
/// Reference an object through a handle
|
||||
#[derive(Clone, Copy, Eq, PartialEq)] |
||||
pub struct RdObj(Register); |
||||
|
||||
impl RdObj { |
||||
pub fn new(reg: Register) -> Self { |
||||
RdObj(reg) |
||||
} |
||||
pub const fn reg(self) -> Register { |
||||
self.0 |
||||
} |
||||
} |
||||
|
||||
impl Debug for RdObj { |
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
||||
write!(f, "Obj(")?; |
||||
write!(f, "{}", self.reg())?; |
||||
write!(f, ")") |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
use crate::asm::data::{RdData, Mask, DataDisp, WrData, Rd}; |
||||
use crate::asm::data::literal::Value; |
||||
use std::fmt::{Debug, Formatter}; |
||||
use std::fmt; |
||||
|
||||
/// Data destination argument (read-write)
|
||||
#[derive(Clone, Copy, Eq, PartialEq)] |
||||
pub struct Wr(WrData, Mask); |
||||
|
||||
impl Wr { |
||||
pub fn new(dst: WrData) -> Self { |
||||
Wr(dst, Mask::default()) |
||||
} |
||||
pub fn d(self) -> WrData { |
||||
self.0 |
||||
} |
||||
pub fn mask(self) -> Mask { |
||||
self.1 |
||||
} |
||||
pub fn as_rd(&self) -> Rd { |
||||
Rd(self.0.into(), self.1) |
||||
} |
||||
|
||||
pub fn discard() -> Wr { |
||||
Wr(WrData::Discard, Mask::default()) |
||||
} |
||||
} |
||||
|
||||
impl Debug for Wr { |
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
||||
write!(f, "Wr(")?; |
||||
let disp: DataDisp = self.0.into(); |
||||
write!(f, "{}", disp)?; |
||||
if !self.mask().is_default() { |
||||
write!(f, ",{:?}", self.mask())?; |
||||
} |
||||
write!(f, ")") |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
use crate::runtime::run_thread::ThreadToken; |
||||
use std::sync::atomic::{AtomicU64, Ordering}; |
||||
use std::sync::Arc; |
||||
use crate::runtime::program::Program; |
||||
use std::time::Duration; |
||||
use crate::asm::data::literal::Value; |
||||
|
||||
pub struct ThreadInfo { |
||||
/// Thread ID
|
||||
pub id: ThreadToken, |
||||
/// Thread ID
|
||||
pub(crate) uniq: &'static AtomicU64, |
||||
/// Program to run
|
||||
pub program: Arc<Program>, |
||||
/// Program to run
|
||||
pub(crate) cycle_time: Duration, |
||||
} |
||||
|
||||
pub const UNIQ_BASE: u64 = 0x6372_736e_0000_0000; |
||||
|
||||
impl ThreadInfo { |
||||
pub fn uniq(&self) -> Value { |
||||
self.uniq.fetch_add(1, Ordering::Relaxed) |
||||
} |
||||
} |
@ -1,7 +1,8 @@ |
||||
use crsn::asm::data::{Rd, Wr}; |
||||
use crsn::asm::data::{Rd, Wr, RdObj}; |
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)] |
||||
pub enum StackOp { |
||||
Push { num: Rd, src: Rd }, |
||||
Pop { dst: Wr, num: Rd }, |
||||
NewStack { dst: Wr }, |
||||
Push { obj: RdObj, src: Rd }, |
||||
Pop { dst: Wr, obj: RdObj }, |
||||
} |
||||
|
Loading…
Reference in new issue