From 8f076e195a0fff9b001d3cc9fa9380b66eedbf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 25 Sep 2020 22:53:19 +0200 Subject: [PATCH] format --- Cargo.lock | 94 ++++++++++++++++----------------- asm/src/data/literal.rs | 10 ++-- asm/src/data/mask.rs | 4 +- asm/src/data/mod.rs | 27 +++++----- asm/src/data/reg.rs | 9 ++-- asm/src/error.rs | 15 +++--- asm/src/instr/flatten.rs | 9 ++-- asm/src/instr/mod.rs | 13 ++--- asm/src/instr/op.rs | 14 ++--- asm/src/lib.rs | 31 +++++------ asm/src/parse/mod.rs | 12 ++--- asm/src/parse/parse_cond.rs | 5 +- asm/src/parse/parse_data.rs | 28 +++++----- asm/src/parse/parse_instr.rs | 10 ++-- asm/src/parse/parse_op.rs | 13 ++--- asm/src/parse/parse_routines.rs | 7 +-- asm/src/parse/sexp_expect.rs | 3 +- asm/src/patches/mod.rs | 5 +- crsn/src/main.rs | 39 +++++++------- runtime/src/exec/mod.rs | 13 +++-- runtime/src/fault.rs | 9 ++-- runtime/src/frame.rs | 10 ++-- runtime/src/frame/status.rs | 5 +- runtime/src/lib.rs | 3 +- runtime/src/mlock.rs | 7 +-- runtime/src/program.rs | 8 +-- runtime/src/run_thread.rs | 11 ++-- runtime/src/span.rs | 4 +- 28 files changed, 214 insertions(+), 204 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89a1407..73c2b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" name = "asm" version = "0.1.0" dependencies = [ - "anyhow", - "sexp", - "thiserror", + "anyhow", + "sexp", + "thiserror", ] [[package]] @@ -21,9 +21,9 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "hermit-abi", + "libc", + "winapi", ] [[package]] @@ -44,9 +44,9 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ - "num-integer", - "num-traits", - "time", + "num-integer", + "num-traits", + "time", ] [[package]] @@ -55,21 +55,21 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" dependencies = [ - "atty", - "lazy_static", - "winapi", + "atty", + "lazy_static", + "winapi", ] [[package]] name = "crsn" version = "0.1.0" dependencies = [ - "anyhow", - "asm", - "log", - "runtime", - "simple_logger", - "thiserror", + "anyhow", + "asm", + "log", + "runtime", + "simple_logger", + "thiserror", ] [[package]] @@ -78,7 +78,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" dependencies = [ - "libc", + "libc", ] [[package]] @@ -99,7 +99,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if", + "cfg-if", ] [[package]] @@ -108,8 +108,8 @@ version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ - "autocfg", - "num-traits", + "autocfg", + "num-traits", ] [[package]] @@ -118,7 +118,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ - "autocfg", + "autocfg", ] [[package]] @@ -127,7 +127,7 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" dependencies = [ - "unicode-xid", + "unicode-xid", ] [[package]] @@ -136,18 +136,18 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2", + "proc-macro2", ] [[package]] name = "runtime" version = "0.1.0" dependencies = [ - "anyhow", - "asm", - "log", - "num-traits", - "thiserror", + "anyhow", + "asm", + "log", + "num-traits", + "thiserror", ] [[package]] @@ -162,11 +162,11 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a53ed2efd04911c8280f2da7bf9abd350c931b86bc7f9f2386fbafbf525ff9" dependencies = [ - "atty", - "chrono", - "colored", - "log", - "winapi", + "atty", + "chrono", + "colored", + "log", + "winapi", ] [[package]] @@ -175,9 +175,9 @@ version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] @@ -186,7 +186,7 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" dependencies = [ - "thiserror-impl", + "thiserror-impl", ] [[package]] @@ -195,9 +195,9 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -206,9 +206,9 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "libc", - "wasi", - "winapi", + "libc", + "wasi", + "winapi", ] [[package]] @@ -229,8 +229,8 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] diff --git a/asm/src/data/literal.rs b/asm/src/data/literal.rs index e59e33a..6d345a1 100644 --- a/asm/src/data/literal.rs +++ b/asm/src/data/literal.rs @@ -1,21 +1,21 @@ +use std::borrow::Cow; use std::fmt::{self, Display, Formatter}; use std::sync::atomic::AtomicU32; -use std::borrow::Cow; pub type DebugMsg = Cow<'static, str>; /// Immediate value pub type Value = u64; -pub fn is_positive(val : Value) -> bool { +pub fn is_positive(val: Value) -> bool { 0 == (val & 0x8000_0000_0000_0000) } -pub fn is_negative(val : Value) -> bool { +pub fn is_negative(val: Value) -> bool { 0 != (val & 0x8000_0000_0000_0000) } -pub fn as_signed(val : Value) -> i64 { +pub fn as_signed(val: Value) -> i64 { i64::from_ne_bytes(val.to_ne_bytes()) } @@ -70,7 +70,7 @@ pub enum Label { impl Label { /// Generate a unique numbered label from a counter - pub fn unique(counter : &AtomicU32) -> Self { + pub fn unique(counter: &AtomicU32) -> Self { Label::Numbered(counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) } } diff --git a/asm/src/data/mask.rs b/asm/src/data/mask.rs index 6dc4462..1753ded 100644 --- a/asm/src/data/mask.rs +++ b/asm/src/data/mask.rs @@ -15,7 +15,7 @@ impl Default for Mask { fn default() -> Self { Mask { len: 64, - offset: 0 + offset: 0, } } } @@ -44,7 +44,7 @@ impl Mask { // create the invalid mask to display it in the error return Err(AsmError::BadMask(Mask { len, - offset + offset, })); } diff --git a/asm/src/data/mod.rs b/asm/src/data/mod.rs index 84df646..1103e1e 100644 --- a/asm/src/data/mod.rs +++ b/asm/src/data/mod.rs @@ -1,20 +1,19 @@ -use super::error::AsmError; +use std::convert::TryFrom; +use std::fmt::{Debug, Display, Formatter}; +use std::fmt; +use literal::Addr; +pub use mask::Mask; +pub use reg::Register; + +use crate::data::literal::{as_signed, Value}; + +use super::error::AsmError; pub mod literal; pub mod reg; pub mod mask; -pub use reg::Register; -pub use mask::Mask; -use literal::Addr; - -use std::convert::TryFrom; - -use crate::data::literal::{Value, as_signed}; -use std::fmt::{Debug, Formatter, Display}; -use std::fmt; - /// Data source disposition #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum DataDisp { @@ -154,7 +153,7 @@ impl Rd { self.1 } - pub fn immediate(val : Value) -> Rd { + pub fn immediate(val: Value) -> Rd { Rd(SrcDisp::Immediate(val), Mask::default()) } } @@ -185,7 +184,7 @@ impl Wr { impl Debug for Rd { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Rd(")?; - let disp : DataDisp = self.0.into(); + let disp: DataDisp = self.0.into(); write!(f, "{}", disp)?; if !self.mask().is_default() { write!(f, ",{:?}", self.mask())?; @@ -197,7 +196,7 @@ impl Debug for Rd { impl Debug for Wr { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Wr(")?; - let disp : DataDisp = self.0.into(); + let disp: DataDisp = self.0.into(); write!(f, "{}", disp)?; if !self.mask().is_default() { write!(f, ",{:?}", self.mask())?; diff --git a/asm/src/data/reg.rs b/asm/src/data/reg.rs index 2109817..3554c09 100644 --- a/asm/src/data/reg.rs +++ b/asm/src/data/reg.rs @@ -1,4 +1,5 @@ use std::fmt::{self, Display, Formatter}; + use crate::error::Error; /// Register name @@ -22,15 +23,15 @@ impl Display for Register { } } -pub fn parse_reg(name : &str) -> anyhow::Result { +pub fn parse_reg(name: &str) -> anyhow::Result { if let Some(rn) = name.strip_prefix("arg") { - let val : u8 = rn.parse()?; + let val: u8 = rn.parse()?; Ok(Register::Arg(val)) } else if let Some(rn) = name.strip_prefix("res") { - let val : u8 = rn.parse()?; + let val: u8 = rn.parse()?; Ok(Register::Res(val)) } else if let Some(rn) = name.strip_prefix("r") { - let val : u8 = rn.parse()?; + let val: u8 = rn.parse()?; Ok(Register::Gen(val)) } else { Err(Error::Parse(format!("Bad reg name: {}", name).into()))? diff --git a/asm/src/error.rs b/asm/src/error.rs index 9f66cd6..f8af247 100644 --- a/asm/src/error.rs +++ b/asm/src/error.rs @@ -1,12 +1,13 @@ -use crate::instr::{Cond}; -use crate::data::{Mask, Register}; -use thiserror::Error; use std::borrow::Cow; -use crate::data::literal::Label; +use thiserror::Error; + +use crate::data::{Mask, Register}; +use crate::data::literal::Label; +use crate::instr::Cond; /// csn_asm unified error type -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum Error { #[error("S-expression syntax error: {0:?}")] PreParse(#[from] Box), @@ -23,7 +24,7 @@ pub enum Error { } /// Error from the assembler stage (after parsing S-expressions and basic validation) -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum AsmError { #[error("Unknown instruction")] UnknownInstruction, @@ -44,7 +45,7 @@ pub enum AsmError { } /// Architectural error - the code is syntactically OK, but cannot run -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum ArchError { #[error("Register {0} does not exist")] RegisterNotExist(Register), diff --git a/asm/src/instr/flatten.rs b/asm/src/instr/flatten.rs index e2e4e11..001d22a 100644 --- a/asm/src/instr/flatten.rs +++ b/asm/src/instr/flatten.rs @@ -1,9 +1,10 @@ -use std::sync::atomic::AtomicU32; -use crate::instr::{HLOp, Instr, Cond, Routine, Op}; -use crate::error::{Error, AsmError}; use std::collections::HashMap; -use crate::data::literal::{Label, Value}; +use std::sync::atomic::AtomicU32; + use crate::data::{Rd, SrcDisp}; +use crate::data::literal::{Label, Value}; +use crate::error::{AsmError, Error}; +use crate::instr::{Cond, HLOp, Instr, Op, Routine}; /// A trait for something that can turn into multiple instructions pub trait Flatten { diff --git a/asm/src/instr/mod.rs b/asm/src/instr/mod.rs index 4c58a59..6c5d581 100644 --- a/asm/src/instr/mod.rs +++ b/asm/src/instr/mod.rs @@ -1,17 +1,14 @@ -mod op; -mod cond; -mod flatten; - +pub use cond::Cond; pub use flatten::Flatten; pub use flatten::lower; - pub use op::HLOp; pub use op::Op; -pub use cond::Cond; -use crate::data::literal::{RoutineName}; - +use crate::data::literal::RoutineName; +mod op; +mod cond; +mod flatten; /// A higher-level instruction #[derive(Debug, Clone, Eq, PartialEq)] diff --git a/asm/src/instr/op.rs b/asm/src/instr/op.rs index bb6a0bc..88ef47a 100644 --- a/asm/src/instr/op.rs +++ b/asm/src/instr/op.rs @@ -1,10 +1,10 @@ use crate::data::{ - Wr, Rd, - literal::Label, + literal::DebugMsg, literal::Label, literal::RoutineName, - literal::DebugMsg, + Rd, + Wr, }; -use crate::instr::{Cond}; +use crate::instr::Cond; /// A higher level simple opration #[derive(Clone, Debug, Eq, PartialEq)] @@ -64,9 +64,11 @@ pub enum Op { Or { dst: Wr, a: Rd, b: Rd }, Xor { dst: Wr, a: Rd, b: Rd }, Cpl { dst: Wr, a: Rd }, - Rol { dst: Wr, a: Rd, n: Rd }, // Rotate (with wrap-around) + Rol { dst: Wr, a: Rd, n: Rd }, + // Rotate (with wrap-around) Ror { dst: Wr, a: Rd, n: Rd }, - Lsl { dst: Wr, a: Rd, n: Rd }, // Shift + Lsl { dst: Wr, a: Rd, n: Rd }, + // Shift Lsr { dst: Wr, a: Rd, n: Rd }, Asr { dst: Wr, a: Rd, n: Rd }, } diff --git a/asm/src/lib.rs b/asm/src/lib.rs index a07830f..f1e9c51 100644 --- a/asm/src/lib.rs +++ b/asm/src/lib.rs @@ -1,25 +1,26 @@ +use crate::instr::{lower, Op}; + pub mod data; pub mod error; pub mod instr; pub mod parse; pub mod patches; -use crate::instr::{Op, lower}; - /// Parse a program from string and assemble a low level instruction sequence from it. -pub fn assemble(source : &str) -> Result, error::Error> { +pub fn assemble(source: &str) -> Result, error::Error> { let parsed = parse::parse(source)?; Ok(lower(parsed)?) } #[cfg(test)] mod tests { - use crate::parse::{parse, parse_instructions}; - use crate::instr::{HLOp, Op, Flatten, Instr, lower}; - use crate::data::{Wr, DstDisp, Register, SrcDisp, Rd}; - use crate::data::literal::{Addr, Label}; use std::sync::atomic::AtomicU32; + + use crate::data::{DstDisp, Rd, Register, SrcDisp, Wr}; + use crate::data::literal::{Addr, Label}; + use crate::instr::{Flatten, HLOp, Instr, lower, Op}; use crate::instr::Cond; + use crate::parse::{parse, parse_instructions}; #[test] fn test_parse_empty() { @@ -147,11 +148,11 @@ mod tests { ], parsed); } - fn parse_single_instr(src : &str) -> anyhow::Result { + fn parse_single_instr(src: &str) -> anyhow::Result { Ok(parse_instructions(vec![sexp::parse(src)?])?.remove(0)) } - fn parse_single_op(src : &str) -> anyhow::Result> { + fn parse_single_op(src: &str) -> anyhow::Result> { let num = AtomicU32::new(0); Ok(parse_single_instr(src)?.flatten(&num)?) } @@ -187,14 +188,14 @@ mod tests { Wr::new(DstDisp::Register(Register::Gen(0))), Rd::new(SrcDisp::Register(Register::Gen(0))), )), - branches: None + branches: None, }, Instr { op: HLOp::L(Op::Mov( Wr::new(DstDisp::Register(Register::Gen(1))), Rd::new(SrcDisp::Register(Register::Gen(2))), )), - branches: None + branches: None, } ] ), @@ -206,20 +207,20 @@ mod tests { Wr::new(DstDisp::Register(Register::Gen(0))), Rd::new(SrcDisp::Register(Register::Gen(0))), )), - branches: None + branches: None, }, Instr { op: HLOp::L(Op::Mov( Wr::new(DstDisp::Register(Register::Gen(1))), Rd::new(SrcDisp::Register(Register::Gen(1))), )), - branches: None + branches: None, } ] ) - ]) + ]), } - , parsed); + , parsed); } #[test] diff --git a/asm/src/parse/mod.rs b/asm/src/parse/mod.rs index 18845a7..c9a2c2a 100644 --- a/asm/src/parse/mod.rs +++ b/asm/src/parse/mod.rs @@ -1,9 +1,10 @@ +use std::sync::atomic::AtomicU32; -use crate::instr::{Routine, HLOp, Flatten}; -use crate::error::Error; - +pub use parse_instr::parse_instructions; +use parse_routines::parse_routines; -use std::sync::atomic::AtomicU32; +use crate::error::Error; +use crate::instr::{Flatten, HLOp, Routine}; use crate::parse::sexp_expect::expect_list; mod parse_cond; @@ -13,9 +14,6 @@ mod parse_routines; mod sexp_expect; mod parse_op; -use parse_routines::parse_routines; -pub use parse_instr::parse_instructions; - pub fn parse(source: &str) -> Result, Error> { let root = sexp::parse(source)?; diff --git a/asm/src/parse/parse_cond.rs b/asm/src/parse/parse_cond.rs index b4aec21..93fc262 100644 --- a/asm/src/parse/parse_cond.rs +++ b/asm/src/parse/parse_cond.rs @@ -1,8 +1,9 @@ -use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use sexp::Sexp; -use crate::instr::{Cond, Instr}; + use crate::error::Error; +use crate::instr::{Cond, Instr}; use crate::parse::parse_instr::parse_instructions; +use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use crate::patches::TryRemove; pub fn parse_cond_branch(tok: Sexp) -> Result<(Cond, Vec), Error> { diff --git a/asm/src/parse/parse_data.rs b/asm/src/parse/parse_data.rs index 1673cd7..207ff61 100644 --- a/asm/src/parse/parse_data.rs +++ b/asm/src/parse/parse_data.rs @@ -1,12 +1,14 @@ -use sexp::{Sexp, Atom}; -use crate::data::{DataDisp, Rd, Wr, DstDisp, SrcDisp, reg}; -use crate::error::Error; -use crate::data::literal::{Addr, Label}; use std::convert::TryFrom; + +use sexp::{Atom, Sexp}; + +use crate::data::{DataDisp, DstDisp, Rd, reg, SrcDisp, Wr}; +use crate::data::literal::{Addr, Label}; +use crate::error::Error; use crate::parse::sexp_expect::expect_string_atom; /// Parse a label -pub fn parse_label(name : Option) -> Result { +pub fn parse_label(name: Option) -> Result { let name = expect_string_atom(name)?; Ok(Label::Named(name.trim_start_matches(':').into())) } @@ -24,32 +26,32 @@ pub fn parse_data_disp(tok: Option) -> Result { match &tok { Sexp::Atom(Atom::I(val)) => { Ok(DataDisp::Immediate(unsafe { std::mem::transmute(*val) })) - }, + } Sexp::Atom(Atom::S(s)) => { if s == "_" { return Ok(DataDisp::Discard); } if let Some(reference) = s.strip_prefix('@') { - if reference.starts_with(|c : char| c.is_ascii_digit()) { - let val : u64 = parse_u64(reference)?; + if reference.starts_with(|c: char| c.is_ascii_digit()) { + let val: u64 = parse_u64(reference)?; Ok(DataDisp::ImmediatePtr(Addr(val))) } else { Ok(DataDisp::RegisterPtr(reg::parse_reg(reference)?)) } - } else if s.starts_with(|c : char| c.is_ascii_digit()) { + } else if s.starts_with(|c: char| c.is_ascii_digit()) { Ok(DataDisp::Immediate(unsafe { std::mem::transmute(parse_i64(s)?) })) } else { Ok(DataDisp::Register(reg::parse_reg(s)?)) } - }, + } _ => { Err(Error::Parse(format!("bad data disp: {:?}", tok).into())) - }, + } } } -pub fn parse_u64(literal : &str) -> anyhow::Result { +pub fn parse_u64(literal: &str) -> anyhow::Result { if let Some(hex) = literal.strip_prefix("0x") { Ok(u64::from_str_radix(hex, 16)?) } else if let Some(hex) = literal.strip_prefix("0b") { @@ -59,7 +61,7 @@ pub fn parse_u64(literal : &str) -> anyhow::Result { } } -pub fn parse_i64(literal : &str) -> anyhow::Result { +pub fn parse_i64(literal: &str) -> anyhow::Result { if let Some(_value) = literal.strip_prefix("-") { Ok(-1 * i64::try_from(parse_u64(literal)?)?) } else { diff --git a/asm/src/parse/parse_instr.rs b/asm/src/parse/parse_instr.rs index c51e83a..551dc03 100644 --- a/asm/src/parse/parse_instr.rs +++ b/asm/src/parse/parse_instr.rs @@ -1,11 +1,11 @@ use sexp::Sexp; -use crate::instr::{Instr}; -use crate::error::Error; -use crate::parse::parse_cond::{parse_cond_branch}; - +use crate::error::Error; +use crate::instr::Instr; +use crate::parse::parse_cond::parse_cond_branch; use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use crate::patches::SexpIsA; + use super::parse_op::parse_op; pub fn parse_instructions(instrs: Vec) -> Result, Error> { @@ -43,7 +43,7 @@ pub fn parse_instructions(instrs: Vec) -> Result, Error> { parsed.push(Instr { op: parse_op(name.as_str(), far, arg_tokens.into_iter())?, - branches + branches, }); } Ok(parsed) diff --git a/asm/src/parse/parse_op.rs b/asm/src/parse/parse_op.rs index ceb3483..4015a89 100644 --- a/asm/src/parse/parse_op.rs +++ b/asm/src/parse/parse_op.rs @@ -1,11 +1,12 @@ -use crate::instr::{HLOp, Op}; use sexp::Sexp; + +use crate::data::{Rd, Wr}; +use crate::data::literal::{Label, RoutineName}; use crate::error::Error; -use crate::data::literal::{RoutineName, Label}; -use crate::parse::sexp_expect::expect_string_atom; -use crate::parse::parse_data::{parse_rd, parse_wr, parse_label}; +use crate::instr::{HLOp, Op}; use crate::parse::parse_cond::parse_cond; -use crate::data::{Rd, Wr}; +use crate::parse::parse_data::{parse_label, parse_rd, parse_wr}; +use crate::parse::sexp_expect::expect_string_atom; pub fn parse_op(keyword: &str, far: bool, mut arg_tokens: impl ExactSizeIterator + Clone) -> Result { Ok(match keyword { @@ -193,7 +194,7 @@ pub fn parse_op(keyword: &str, far: bool, mut arg_tokens: impl ExactSizeIterator 4 => { Op::Div { dst: parse_wr(arg_tokens.next())?, - rem : parse_wr(arg_tokens.next())?, + rem: parse_wr(arg_tokens.next())?, a: parse_rd(arg_tokens.next())?, div: parse_rd(arg_tokens.next())?, } diff --git a/asm/src/parse/parse_routines.rs b/asm/src/parse/parse_routines.rs index 5d79e57..0c79a21 100644 --- a/asm/src/parse/parse_routines.rs +++ b/asm/src/parse/parse_routines.rs @@ -1,8 +1,9 @@ -use crate::parse::parse_instr::parse_instructions; -use crate::instr::Routine; -use crate::data::literal::RoutineName; use sexp::Sexp; + +use crate::data::literal::RoutineName; use crate::error::Error; +use crate::instr::Routine; +use crate::parse::parse_instr::parse_instructions; use crate::parse::sexp_expect::{expect_list, expect_string_atom}; use crate::patches::TryRemove; diff --git a/asm/src/parse/sexp_expect.rs b/asm/src/parse/sexp_expect.rs index 62cdf70..e6bd1b4 100644 --- a/asm/src/parse/sexp_expect.rs +++ b/asm/src/parse/sexp_expect.rs @@ -1,4 +1,5 @@ -use sexp::{Sexp, Atom}; +use sexp::{Atom, Sexp}; + use crate::error::Error; pub fn expect_list(expr: Option, allow_empty: bool) -> Result, Error> { diff --git a/asm/src/patches/mod.rs b/asm/src/patches/mod.rs index 2e90c4e..287f150 100644 --- a/asm/src/patches/mod.rs +++ b/asm/src/patches/mod.rs @@ -1,5 +1,6 @@ +pub use sexp_is_a::SexpIsA; +pub use try_remove::TryRemove; + mod try_remove; mod sexp_is_a; -pub use try_remove::TryRemove; -pub use sexp_is_a::SexpIsA; diff --git a/crsn/src/main.rs b/crsn/src/main.rs index 2ad8d9b..ddf2b50 100644 --- a/crsn/src/main.rs +++ b/crsn/src/main.rs @@ -2,9 +2,10 @@ extern crate log; use simple_logger::SimpleLogger; -use runtime::run_thread::{RunThread, ThreadToken}; -use runtime::program::Program; + use asm::data::literal::Addr; +use runtime::program::Program; +use runtime::run_thread::{RunThread, ThreadToken}; fn main() { SimpleLogger::new().init().unwrap(); @@ -21,24 +22,24 @@ fn main() { ) ) ";*/ -/* - let program = " - ( - (main - (ld r0 2) - (call add2x r0 15) - (ld r0 res0) - (fault \"that's it\") - ) - (add2x - (ld r0 arg0) - (ld r1 arg1) - (add r0 r1) - (add r0 r1) - (ret r0) + /* + let program = " + ( + (main + (ld r0 2) + (call add2x r0 15) + (ld r0 res0) + (fault \"that's it\") + ) + (add2x + (ld r0 arg0) + (ld r1 arg1) + (add r0 r1) + (add r0 r1) + (ret r0) + ) ) - ) - ";*/ + ";*/ let program = " ( diff --git a/runtime/src/exec/mod.rs b/runtime/src/exec/mod.rs index 5335d01..8995fb0 100644 --- a/runtime/src/exec/mod.rs +++ b/runtime/src/exec/mod.rs @@ -1,10 +1,13 @@ -use crate::run_thread::{RunThread}; -use asm::instr::{Op}; +use std::ops::Rem; + +use num_traits::PrimInt; + +use asm::data::literal::Addr; +use asm::instr::Op; + use crate::fault::Fault; use crate::frame::StackFrame; -use asm::data::literal::{Addr}; -use std::ops::{Rem}; -use num_traits::PrimInt; +use crate::run_thread::RunThread; pub type CyclesSpent = usize; diff --git a/runtime/src/fault.rs b/runtime/src/fault.rs index 14b9c6b..81ab773 100644 --- a/runtime/src/fault.rs +++ b/runtime/src/fault.rs @@ -1,15 +1,16 @@ use thiserror::Error; + // use super::span::MemorySpan; // use crate::run_thread::ThreadToken; // use crate::mlock::ClaimId; -use asm::data::literal::{DebugMsg, RoutineName, Label}; +use asm::data::literal::{DebugMsg, Label, RoutineName}; use asm::data::Register; -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum Fault { #[error("Bad instruction at addr {addr:#10x}: {cause}")] BadInstruction { - addr : u32, + addr: u32, cause: InstrError, }, @@ -64,7 +65,7 @@ pub enum Fault { CallStackUnderflow, } -#[derive(Error,Debug)] +#[derive(Error, Debug)] pub enum InstrError { #[error("Instruction not recognized")] UnknownInstruction, diff --git a/runtime/src/frame.rs b/runtime/src/frame.rs index 8ba6538..0617ca2 100644 --- a/runtime/src/frame.rs +++ b/runtime/src/frame.rs @@ -1,12 +1,10 @@ +use asm::data::{DstDisp, Rd, Register, SrcDisp, Wr}; use asm::data::literal::{Addr, Value}; -use asm::data::{Rd, SrcDisp, Register, Wr, DstDisp}; -use crate::fault::Fault; - - +use status::StatusFlags; +use crate::fault::Fault; mod status; -use status::StatusFlags; pub const REG_COUNT: usize = 8; @@ -35,7 +33,7 @@ impl StackFrame { sf } - pub fn set_retvals(&mut self, vals: &[Value]) { + pub fn set_retvals(&mut self, vals: &[Value]) { for n in 0..(vals.len().min(REG_COUNT)) { self.res[n] = vals[n]; } diff --git a/runtime/src/frame/status.rs b/runtime/src/frame/status.rs index d3d4f9e..cf181fb 100644 --- a/runtime/src/frame/status.rs +++ b/runtime/src/frame/status.rs @@ -1,6 +1,7 @@ use std::fmt::{Display, Formatter}; use std::fmt; -use asm::data::literal::{Value, is_positive, is_negative}; + +use asm::data::literal::{is_negative, is_positive, Value}; use asm::instr::Cond; #[derive(Default, Clone, Debug)] @@ -44,7 +45,7 @@ impl StatusFlags { val } - pub fn load(&mut self, val : Value) { + pub fn load(&mut self, val: Value) { if val & 0x01 != 0 { self.equal = true; } if val & 0x02 != 0 { self.lower = true; } if val & 0x04 != 0 { self.greater = true; } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 927b4b8..d8427f2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,4 +1,5 @@ -#[macro_use] extern crate log; +#[macro_use] +extern crate log; pub mod run_thread; // pub mod mlock; diff --git a/runtime/src/mlock.rs b/runtime/src/mlock.rs index 1503deb..f984444 100644 --- a/runtime/src/mlock.rs +++ b/runtime/src/mlock.rs @@ -1,8 +1,9 @@ -use std::sync::atomic::{AtomicU32, Ordering}; use std::fmt; use std::fmt::Formatter; -use crate::run_thread::ThreadToken; +use std::sync::atomic::{AtomicU32, Ordering}; + use crate::fault::Fault; +use crate::run_thread::ThreadToken; use crate::span::MemorySpan; /// Records memory claims and protects from illegal access @@ -85,7 +86,7 @@ impl MemoryGuard { /// Release all owned by a thread, with claim ID >= a given value /// (return from a subroutine) - pub fn release_owned_after(&mut self, owner: ThreadToken, epoch : ClaimId) { + pub fn release_owned_after(&mut self, owner: ThreadToken, epoch: ClaimId) { self.claims.retain(|c| c.owner != owner || c.id >= epoch); } } diff --git a/runtime/src/program.rs b/runtime/src/program.rs index 1f90435..85a3774 100644 --- a/runtime/src/program.rs +++ b/runtime/src/program.rs @@ -1,8 +1,10 @@ -use asm::instr::{Op}; -use asm::data::literal::{Addr, RoutineName, Label}; -use crate::fault::Fault; use std::collections::HashMap; +use asm::data::literal::{Addr, Label, RoutineName}; +use asm::instr::Op; + +use crate::fault::Fault; + #[derive(Clone, Debug)] pub struct Program { ops: Vec, diff --git a/runtime/src/run_thread.rs b/runtime/src/run_thread.rs index 072b23e..26d037c 100644 --- a/runtime/src/run_thread.rs +++ b/runtime/src/run_thread.rs @@ -1,16 +1,13 @@ -use std::time::Duration; use std::thread::JoinHandle; +use std::time::Duration; -use asm::data::literal::{Addr}; - - - +use asm::data::literal::Addr; +use crate::exec::EvalRes; use crate::frame::StackFrame; use crate::program::Program; -use crate::exec::EvalRes; -const CYCLE_TIME : Duration = Duration::from_millis(0); +const CYCLE_TIME: Duration = Duration::from_millis(0); //const CYCLE_TIME : Duration = Duration::from_millis(100); #[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)] diff --git a/runtime/src/span.rs b/runtime/src/span.rs index 787e3c0..f20c720 100644 --- a/runtime/src/span.rs +++ b/runtime/src/span.rs @@ -1,8 +1,6 @@ - - use asm::data::literal::Addr; -#[derive(Debug,Clone,Copy)] +#[derive(Debug, Clone, Copy)] pub struct MemorySpan { addr: usize, len: usize,