diff --git a/crsn/src/asm/data/mask.rs b/crsn/src/asm/data/mask.rs deleted file mode 100644 index e56d598..0000000 --- a/crsn/src/asm/data/mask.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! Mask applied to a data source or destination - -use crate::asm::error::AsmError; - -/// Bit mask to apply to a value -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub struct Mask { - /// Length of the selected bit slice - len: u8, - /// Offset of the selected bit slice from bit zero - offset: u8, -} - -impl Default for Mask { - fn default() -> Self { - Mask { - len: 64, - offset: 0, - } - } -} - -impl Mask { - pub const BYTE: Mask = Mask { - len: 8, - offset: 0, - }; - pub const HALF_WORD: Mask = Mask { - len: 16, - offset: 0, - }; - pub const WORD: Mask = Mask { - len: 32, - offset: 0, - }; - pub const DOUBLE_WORD: Mask = Mask { - len: 64, - offset: 0, - }; - pub const FULL: Mask = Self::DOUBLE_WORD; - - pub fn new(len: u8, offset: u8) -> Result { - if len == 0 || offset >= 64 { - // create the invalid mask to display it in the error - return Err(AsmError::BadMask(Mask { - len, - offset, - })); - } - - Ok(Self { - len: len.min(64 - offset), - offset, - }) - } - - /// Get a binary mask representing the span - pub fn as_bitmask(self) -> u64 { - ((1 << self.len) - 1) << self.offset - } - - pub fn is_default(self) -> bool { - self == Self::default() - } -} diff --git a/crsn/src/asm/data/mod.rs b/crsn/src/asm/data/mod.rs index dfe55c8..179cd37 100644 --- a/crsn/src/asm/data/mod.rs +++ b/crsn/src/asm/data/mod.rs @@ -2,7 +2,6 @@ use std::convert::TryFrom; use std::fmt::{Debug, Display, Formatter}; use std::fmt; -pub use mask::Mask; pub use rd::Rd; pub use rd::RdObj; pub use reg::Register; @@ -14,7 +13,6 @@ use super::error::AsmError; pub mod literal; pub mod reg; -pub mod mask; mod rd; diff --git a/crsn/src/asm/data/rd.rs b/crsn/src/asm/data/rd.rs index 43ae689..04908fc 100644 --- a/crsn/src/asm/data/rd.rs +++ b/crsn/src/asm/data/rd.rs @@ -1,28 +1,22 @@ use std::fmt::{Debug, Display, Formatter}; use std::fmt; -use crate::asm::data::{DataDisp, Mask, RdData, Register}; +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, pub Mask); +pub struct Rd(pub RdData); impl Rd { pub const fn new(src: RdData) -> Self { - Rd(src, Mask::FULL) + Rd(src) } - pub const fn data(self) -> RdData { self.0 } - - pub const fn mask(self) -> Mask { - self.1 - } - pub const fn immediate(val: Value) -> Rd { - Rd(RdData::Immediate(val), Mask::FULL) + Rd(RdData::Immediate(val)) } } @@ -34,13 +28,7 @@ impl Display for Rd { 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, ")") + write!(f, "Rd({})", self.0) } } @@ -66,8 +54,6 @@ impl Display for RdObj { impl Debug for RdObj { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "Obj(")?; - write!(f, "{}", self.reg())?; - write!(f, ")") + write!(f, "Obj({})", self.reg()) } } diff --git a/crsn/src/asm/data/wr.rs b/crsn/src/asm/data/wr.rs index 8a7d8e8..e18ec6e 100644 --- a/crsn/src/asm/data/wr.rs +++ b/crsn/src/asm/data/wr.rs @@ -1,28 +1,25 @@ use std::fmt::{Debug, Display, Formatter}; use std::fmt; -use crate::asm::data::{DataDisp, Mask, Rd, WrData}; +use crate::asm::data::{Rd, WrData}; /// Data destination argument (read-write) #[derive(Clone, Copy, Eq, PartialEq)] -pub struct Wr(WrData, Mask); +pub struct Wr(WrData); impl Wr { pub fn new(dst: WrData) -> Self { - Wr(dst, Mask::default()) + Wr(dst) } 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) + Rd(self.0.into()) } pub fn discard() -> Wr { - Wr(WrData::Discard, Mask::default()) + Wr(WrData::Discard) } pub fn is_discard(self) -> bool { @@ -35,18 +32,12 @@ impl Wr { impl Display for Wr { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) // TODO mask, when implemented + write!(f, "{}", self.0) } } 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, ")") + write!(f, "Wr({})", self.0) } } diff --git a/crsn/src/asm/error.rs b/crsn/src/asm/error.rs index 0f8bc49..80d2364 100644 --- a/crsn/src/asm/error.rs +++ b/crsn/src/asm/error.rs @@ -5,7 +5,7 @@ use thiserror::Error; use sexp::SourcePosition; -use crate::asm::data::{Mask, Register}; +use crate::asm::data::{Register}; use crate::asm::data::literal::Label; use crate::asm::instr::Cond; @@ -27,10 +27,6 @@ pub enum CrsnError { pub enum AsmError { #[error("Unknown instruction")] UnknownInstruction, - #[error("Bad bit mask")] - BadMask(Mask), - #[error("Uneven operand size")] - UnevenOperandSize(Mask, Mask), #[error("Value provided as output argument")] ValueAsOutput, #[error("Discard (_) provided as input argument")] diff --git a/crsn/src/asm/parse/arg_parser.rs b/crsn/src/asm/parse/arg_parser.rs index f040251..59cbe7b 100644 --- a/crsn/src/asm/parse/arg_parser.rs +++ b/crsn/src/asm/parse/arg_parser.rs @@ -1,6 +1,6 @@ use sexp::{Sexp, SourcePosition}; -use crate::asm::data::{Mask, Rd, RdData, RdObj, Wr}; +use crate::asm::data::{Rd, RdData, RdObj, Wr}; use crate::asm::error::CrsnError; use crate::asm::parse::parse_data::{parse_rd, parse_wr}; use crate::asm::parse::ParserContext; @@ -93,7 +93,7 @@ impl<'a> TokenParser<'a> { /// Get the next entry as an object location pub fn next_rdobj(&mut self) -> Result { match parse_rd(self.next_or_err()?, self.pcx)? { - Rd(RdData::RegObject(reg), Mask::FULL) => { + Rd(RdData::RegObject(reg)) => { Ok(RdObj::new(reg)) } other => { diff --git a/crsn/src/module/mod.rs b/crsn/src/module/mod.rs index 8ea65c7..941ffc6 100644 --- a/crsn/src/module/mod.rs +++ b/crsn/src/module/mod.rs @@ -6,7 +6,6 @@ pub use eval_res::EvalRes; use sexp::{Sexp, SourcePosition}; use crate::asm::data::literal::Value; -use crate::asm::data::Mask; use crate::asm::error::CrsnError; use crate::asm::instr::Flatten; use crate::asm::instr::op::OpKind; @@ -107,7 +106,7 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { } /// Run-time method called to read an object (using the object handle syntax) - fn read_obj(&self, state: &mut RunState, handle: Value, _mask: Mask) + fn read_obj(&self, state: &mut RunState, handle: Value) -> Result, Fault> { // Default impl - we do not support reading this object @@ -115,7 +114,7 @@ pub trait CrsnExtension: Debug + Send + Sync + 'static { } /// Run-time method called to write an object (using the object handle syntax) - fn write_obj(&self, state: &mut RunState, handle: Value, _mask: Mask, value: Value) -> Result, Fault> + fn write_obj(&self, state: &mut RunState, handle: Value, value: Value) -> Result, Fault> { // Default impl - we do not support writing this object Ok(None) diff --git a/crsn/src/runtime/run_thread/state.rs b/crsn/src/runtime/run_thread/state.rs index 0aa5e96..043e8eb 100644 --- a/crsn/src/runtime/run_thread/state.rs +++ b/crsn/src/runtime/run_thread/state.rs @@ -1,7 +1,7 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; -use crate::asm::data::{Rd, RdData, RdObj, Register, Wr, WrData, Mask}; +use crate::asm::data::{Rd, RdData, RdObj, Register, Wr, WrData}; use crate::asm::data::literal::{Addr, Value}; use crate::asm::instr::Cond; use crate::runtime::fault::Fault; @@ -122,22 +122,22 @@ impl RunState { } RdData::RegObject(register) => { let reference = self.read(Rd::new(RdData::Register(register)))?; - self.read_object(reference, rd.mask()) + self.read_object(reference) } RdData::ImmObject(reference) => { - self.read_object(reference, rd.mask()) + self.read_object(reference) } } } - fn read_object(&mut self, reference: Value, mask: Mask) -> Result { + fn read_object(&mut self, reference: Value) -> Result { // This is a shitty dirty hack to allow iterating over the extensions while passing a mutable reference // to self to the reading methods. Since the extensions array is in an Arc, it can't be mutated internally // anyway, and we know it will still live after the method returns - unless someone does something incredibly stupid. let ti: &ThreadInfo = unsafe { &*(self.thread_info.as_ref() as *const _) }; // If this fails, just clone the arc for the loop... for ext in ti.extensions.iter() { - if let Some(value) = ext.read_obj(self, reference, mask)? { + if let Some(value) = ext.read_obj(self, reference)? { return Ok(value); } } @@ -145,14 +145,14 @@ impl RunState { Err(Fault::ObjectNotExist(reference)) } - fn write_object(&mut self, reference: Value, mask: Mask, value: Value) -> Result<(), Fault> { + fn write_object(&mut self, reference: Value, value: Value) -> Result<(), Fault> { // This is a shitty dirty hack to allow iterating over the extensions while passing a mutable reference // to self to the reading methods. Since the extensions array is in an Arc, it can't be mutated internally // anyway, and we know it will still live after the method returns - unless someone does something incredibly stupid. let ti: &ThreadInfo = unsafe { &*(self.thread_info.as_ref() as *const _) }; // If this fails, just clone the arc for the loop... for ext in ti.extensions.iter() { - if ext.write_obj(self, reference, mask, value)?.is_some() { + if ext.write_obj(self, reference, value)?.is_some() { return Ok(()); } } @@ -193,10 +193,10 @@ impl RunState { } WrData::RegObject(register) => { let reference = self.read(Rd::new(RdData::Register(register)))?; - self.write_object(reference, wr.mask(), val) + self.write_object(reference, val) } WrData::ImmObject(reference) => { - self.write_object(reference, wr.mask(), val) + self.write_object(reference, val) } } } diff --git a/crsn_stdio/src/lib.rs b/crsn_stdio/src/lib.rs index 133921e..1d58cb6 100644 --- a/crsn_stdio/src/lib.rs +++ b/crsn_stdio/src/lib.rs @@ -6,7 +6,6 @@ use crsn::module::{CrsnExtension, ParseRes, CrsnUniq}; use crsn::runtime::fault::Fault; use crsn::runtime::run_thread::{RunState}; use crsn::sexp::SourcePosition; -use crsn::asm::data::Mask; use std::io::{Write}; use std::convert::TryFrom; use crsn::asm::instr::Cond; @@ -66,7 +65,7 @@ impl CrsnExtension for StdioOps { } /// Run-time method called to read an object (using the object handle syntax) - fn read_obj(&self, state: &mut RunState, handle: Value, _mask: Mask) + fn read_obj(&self, state: &mut RunState, handle: Value) -> Result, Fault> { if handle == self.hdl_stdin { @@ -82,7 +81,7 @@ impl CrsnExtension for StdioOps { } /// Run-time method called to write an object (using the object handle syntax) - fn write_obj(&self, state: &mut RunState, handle: Value, _mask: Mask, value: Value) -> Result, Fault> + fn write_obj(&self, state: &mut RunState, handle: Value, value: Value) -> Result, Fault> { state.clear_status();