remove unused "mask" code

floats
Ondřej Hruška 4 years ago
parent 3a8895b790
commit 8ea60f52eb
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 65
      crsn/src/asm/data/mask.rs
  2. 2
      crsn/src/asm/data/mod.rs
  3. 26
      crsn/src/asm/data/rd.rs
  4. 23
      crsn/src/asm/data/wr.rs
  5. 6
      crsn/src/asm/error.rs
  6. 4
      crsn/src/asm/parse/arg_parser.rs
  7. 5
      crsn/src/module/mod.rs
  8. 18
      crsn/src/runtime/run_thread/state.rs
  9. 5
      crsn_stdio/src/lib.rs

@ -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<Self, AsmError> {
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()
}
}

@ -2,7 +2,6 @@ use std::convert::TryFrom;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
pub use mask::Mask;
pub use rd::Rd; pub use rd::Rd;
pub use rd::RdObj; pub use rd::RdObj;
pub use reg::Register; pub use reg::Register;
@ -14,7 +13,6 @@ use super::error::AsmError;
pub mod literal; pub mod literal;
pub mod reg; pub mod reg;
pub mod mask;
mod rd; mod rd;

@ -1,28 +1,22 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
use crate::asm::data::{DataDisp, Mask, RdData, Register}; use crate::asm::data::{RdData, Register};
use crate::asm::data::literal::Value; use crate::asm::data::literal::Value;
/// Data source argument (read-only) /// Data source argument (read-only)
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub struct Rd(pub RdData, pub Mask); pub struct Rd(pub RdData);
impl Rd { impl Rd {
pub const fn new(src: RdData) -> Self { pub const fn new(src: RdData) -> Self {
Rd(src, Mask::FULL) Rd(src)
} }
pub const fn data(self) -> RdData { pub const fn data(self) -> RdData {
self.0 self.0
} }
pub const fn mask(self) -> Mask {
self.1
}
pub const fn immediate(val: Value) -> Rd { 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 { impl Debug for Rd {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Rd(")?; write!(f, "Rd({})", self.0)
let disp: DataDisp = self.0.into();
write!(f, "{}", disp)?;
if !self.mask().is_default() {
write!(f, ",{:?}", self.mask())?;
}
write!(f, ")")
} }
} }
@ -66,8 +54,6 @@ impl Display for RdObj {
impl Debug for RdObj { impl Debug for RdObj {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Obj(")?; write!(f, "Obj({})", self.reg())
write!(f, "{}", self.reg())?;
write!(f, ")")
} }
} }

@ -1,28 +1,25 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
use crate::asm::data::{DataDisp, Mask, Rd, WrData}; use crate::asm::data::{Rd, WrData};
/// Data destination argument (read-write) /// Data destination argument (read-write)
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub struct Wr(WrData, Mask); pub struct Wr(WrData);
impl Wr { impl Wr {
pub fn new(dst: WrData) -> Self { pub fn new(dst: WrData) -> Self {
Wr(dst, Mask::default()) Wr(dst)
} }
pub fn d(self) -> WrData { pub fn d(self) -> WrData {
self.0 self.0
} }
pub fn mask(self) -> Mask {
self.1
}
pub fn as_rd(self) -> Rd { pub fn as_rd(self) -> Rd {
Rd(self.0.into(), self.1) Rd(self.0.into())
} }
pub fn discard() -> Wr { pub fn discard() -> Wr {
Wr(WrData::Discard, Mask::default()) Wr(WrData::Discard)
} }
pub fn is_discard(self) -> bool { pub fn is_discard(self) -> bool {
@ -35,18 +32,12 @@ impl Wr {
impl Display for Wr { impl Display for Wr {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0) // TODO mask, when implemented write!(f, "{}", self.0)
} }
} }
impl Debug for Wr { impl Debug for Wr {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Wr(")?; write!(f, "Wr({})", self.0)
let disp: DataDisp = self.0.into();
write!(f, "{}", disp)?;
if !self.mask().is_default() {
write!(f, ",{:?}", self.mask())?;
}
write!(f, ")")
} }
} }

@ -5,7 +5,7 @@ use thiserror::Error;
use sexp::SourcePosition; use sexp::SourcePosition;
use crate::asm::data::{Mask, Register}; use crate::asm::data::{Register};
use crate::asm::data::literal::Label; use crate::asm::data::literal::Label;
use crate::asm::instr::Cond; use crate::asm::instr::Cond;
@ -27,10 +27,6 @@ pub enum CrsnError {
pub enum AsmError { pub enum AsmError {
#[error("Unknown instruction")] #[error("Unknown instruction")]
UnknownInstruction, UnknownInstruction,
#[error("Bad bit mask")]
BadMask(Mask),
#[error("Uneven operand size")]
UnevenOperandSize(Mask, Mask),
#[error("Value provided as output argument")] #[error("Value provided as output argument")]
ValueAsOutput, ValueAsOutput,
#[error("Discard (_) provided as input argument")] #[error("Discard (_) provided as input argument")]

@ -1,6 +1,6 @@
use sexp::{Sexp, SourcePosition}; 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::error::CrsnError;
use crate::asm::parse::parse_data::{parse_rd, parse_wr}; use crate::asm::parse::parse_data::{parse_rd, parse_wr};
use crate::asm::parse::ParserContext; use crate::asm::parse::ParserContext;
@ -93,7 +93,7 @@ impl<'a> TokenParser<'a> {
/// Get the next entry as an object location /// Get the next entry as an object location
pub fn next_rdobj(&mut self) -> Result<RdObj, CrsnError> { pub fn next_rdobj(&mut self) -> Result<RdObj, CrsnError> {
match parse_rd(self.next_or_err()?, self.pcx)? { match parse_rd(self.next_or_err()?, self.pcx)? {
Rd(RdData::RegObject(reg), Mask::FULL) => { Rd(RdData::RegObject(reg)) => {
Ok(RdObj::new(reg)) Ok(RdObj::new(reg))
} }
other => { other => {

@ -6,7 +6,6 @@ pub use eval_res::EvalRes;
use sexp::{Sexp, SourcePosition}; use sexp::{Sexp, SourcePosition};
use crate::asm::data::literal::Value; use crate::asm::data::literal::Value;
use crate::asm::data::Mask;
use crate::asm::error::CrsnError; use crate::asm::error::CrsnError;
use crate::asm::instr::Flatten; use crate::asm::instr::Flatten;
use crate::asm::instr::op::OpKind; 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) /// 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<Option<Value>, Fault> -> Result<Option<Value>, Fault>
{ {
// Default impl - we do not support reading this object // 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) /// 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<Option<()>, Fault> fn write_obj(&self, state: &mut RunState, handle: Value, value: Value) -> Result<Option<()>, Fault>
{ {
// Default impl - we do not support writing this object // Default impl - we do not support writing this object
Ok(None) Ok(None)

@ -1,7 +1,7 @@
use std::any::{Any, TypeId}; use std::any::{Any, TypeId};
use std::collections::HashMap; 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::data::literal::{Addr, Value};
use crate::asm::instr::Cond; use crate::asm::instr::Cond;
use crate::runtime::fault::Fault; use crate::runtime::fault::Fault;
@ -122,22 +122,22 @@ impl RunState {
} }
RdData::RegObject(register) => { RdData::RegObject(register) => {
let reference = self.read(Rd::new(RdData::Register(register)))?; let reference = self.read(Rd::new(RdData::Register(register)))?;
self.read_object(reference, rd.mask()) self.read_object(reference)
} }
RdData::ImmObject(reference) => { RdData::ImmObject(reference) => {
self.read_object(reference, rd.mask()) self.read_object(reference)
} }
} }
} }
fn read_object(&mut self, reference: Value, mask: Mask) -> Result<Value, Fault> { fn read_object(&mut self, reference: Value) -> Result<Value, Fault> {
// This is a shitty dirty hack to allow iterating over the extensions while passing a mutable reference // 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 // 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. // 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... 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() { 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); return Ok(value);
} }
} }
@ -145,14 +145,14 @@ impl RunState {
Err(Fault::ObjectNotExist(reference)) 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 // 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 // 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. // 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... 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() { 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(()); return Ok(());
} }
} }
@ -193,10 +193,10 @@ impl RunState {
} }
WrData::RegObject(register) => { WrData::RegObject(register) => {
let reference = self.read(Rd::new(RdData::Register(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) => { WrData::ImmObject(reference) => {
self.write_object(reference, wr.mask(), val) self.write_object(reference, val)
} }
} }
} }

@ -6,7 +6,6 @@ use crsn::module::{CrsnExtension, ParseRes, CrsnUniq};
use crsn::runtime::fault::Fault; use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{RunState}; use crsn::runtime::run_thread::{RunState};
use crsn::sexp::SourcePosition; use crsn::sexp::SourcePosition;
use crsn::asm::data::Mask;
use std::io::{Write}; use std::io::{Write};
use std::convert::TryFrom; use std::convert::TryFrom;
use crsn::asm::instr::Cond; 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) /// 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<Option<Value>, Fault> -> Result<Option<Value>, Fault>
{ {
if handle == self.hdl_stdin { 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) /// 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<Option<()>, Fault> fn write_obj(&self, state: &mut RunState, handle: Value, value: Value) -> Result<Option<()>, Fault>
{ {
state.clear_status(); state.clear_status();

Loading…
Cancel
Save