From 91dd147c96b5a7c917a1f7eb5f1f45f174b59f5f Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 11:14:37 -0500 Subject: [PATCH 01/25] dev-support: bump `serialport` --- application-support/src/init/board.rs | 81 +++++++------------ device-support/Cargo.toml | 2 +- device-support/src/rpc/transport/uart_host.rs | 66 ++++++++------- 3 files changed, 66 insertions(+), 83 deletions(-) diff --git a/application-support/src/init/board.rs b/application-support/src/init/board.rs index 890e97af..440301bb 100644 --- a/application-support/src/init/board.rs +++ b/application-support/src/init/board.rs @@ -10,13 +10,14 @@ use lc3_traits::control::rpc::{ }; use lc3_device_support::{ rpc::{ - transport::uart_host::{HostUartTransport, SerialPortSettings}, + transport::uart_host::{HostUartTransport, SerialPortBuilder}, encoding::{PostcardEncode, PostcardDecode, Cobs}, }, util::Fifo, }; use std::{ + borrow::Cow, sync::Mutex, thread::Builder as ThreadBuilder, path::{Path, PathBuf}, @@ -43,34 +44,26 @@ type Cont<'ss, EncFunc: FnMut() -> Cobs>> = Controller< >; // #[derive(Debug)] -pub struct BoardDevice<'ss, EncFunc = Box Cobs>>, P = &'static Path> +pub struct BoardDevice<'ss, EncFunc = Box Cobs>>> where EncFunc: FnMut() -> Cobs>, - P: AsRef, { controller: Cont<'ss, EncFunc>, - _p: PhantomData

, } #[derive(Debug, Clone, PartialEq, Eq)] pub enum SerialSettings { - DefaultsWithBaudRate { baud_rate: u32 }, - Custom(SerialPortSettings), + DefaultsWithBaudRate { baud_rate: u32, path: String, }, + Custom(SerialPortBuilder), } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct BoardConfig> { - pub path: P, - pub serial_settings: SerialSettings, +pub struct BoardConfig { + pub settings: SerialSettings, } // TODO: use Strings instead? -impl> Default for BoardConfig<&'static P> -where - &'static P: AsRef, - P: 'static, - str: AsRef

-{ +impl Default for BoardConfig { fn default() -> Self { #[cfg(target_os = "windows")] { Self::detect_windows() } @@ -82,15 +75,7 @@ where { Self::detect_linux() } #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] - { Self::new(AsRef::

::as_ref("/dev/tm4c"), 1_500_000) } - } -} - -// TODO: actually have this use the platform stuff (spin off the functions below into -// things that just return a PathBuf, I think). -impl Default for BoardConfig { - fn default() -> Self { - Self::new(PathBuf::from("/dev/lm4f"), 1_500_000) + { Self::new("/dev/tm4c", 1_500_000) } } } @@ -98,67 +83,61 @@ impl Default for BoardConfig { // // [this script](https://github.com/ut-ras/Rasware/blob/f3750ff0b8f7f7791da2fee365462d4c78f62a49/RASLib/detect-board) -impl> BoardConfig<&'static P> -where - &'static P: AsRef, - P: 'static, - str: AsRef

-{ +impl BoardConfig { + #[cfg_attr(all(docs, not(doctest)), doc(cfg(target_os = "windows")))] #[cfg(target_os = "windows")] pub fn detect_windows() -> Self { unimplemented!() } - #[cfg(target_family = "unix")] + #[cfg_attr(all(docs, not(doctest)), doc(cfg(target_os = "linux")))] + #[cfg(target_os = "linux")] pub fn detect_linux() -> Self { - Self::new(AsRef::

::as_ref("/dev/lm4f"), 1_500_000) + Self::new("/dev/lm4f", 1_500_000) } + #[cfg_attr(all(docs, not(doctest)), doc(cfg(target_os = "macos")))] #[cfg(target_os = "macos")] pub fn detect_macos() -> Self { unimplemented!() } } -impl> BoardConfig

{ - pub /*const*/ fn new(path: P, baud_rate: u32) -> Self { +impl BoardConfig { + pub /*const*/ fn new<'a>(path: impl Into>, baud_rate: u32) -> Self { Self { - path, - serial_settings: SerialSettings::DefaultsWithBaudRate { baud_rate }, + settings: SerialSettings::DefaultsWithBaudRate { baud_rate, path: path.into().to_string() } } } - pub /*const*/ fn new_with_config(path: P, config: SerialPortSettings) -> Self { + pub /*const*/ fn new_with_config(config: SerialPortBuilder) -> Self { Self { - path, - serial_settings: SerialSettings::Custom(config), + settings: SerialSettings::Custom(config), } } } -impl> BoardConfig

{ +impl BoardConfig { fn new_transport(self) -> HostUartTransport { // Note: we unwrap here! This is probably not great! // (TODO) - match self.serial_settings { - SerialSettings::DefaultsWithBaudRate { baud_rate } => { - HostUartTransport::new(self.path, baud_rate).unwrap() + match self.settings { + SerialSettings::DefaultsWithBaudRate { path, baud_rate } => { + HostUartTransport::new(path, baud_rate).unwrap() }, SerialSettings::Custom(config) => { - HostUartTransport::new_with_config(self.path, config).unwrap() + HostUartTransport::new_with_config(config).unwrap() }, } } } -impl<'s, P> Init<'s> for BoardDevice<'static, Box Cobs>>, P> +impl<'s> Init<'s> for BoardDevice<'static, Box Cobs>>> where - P: AsRef, - P: 'static, - BoardConfig

: Default, + BoardConfig: Default, { - type Config = BoardConfig

; + type Config = BoardConfig; // Until we get existential types (or `impl Trait` in type aliases) we can't // just say a type parameter is some specific type that we can't name (i.e. @@ -172,7 +151,7 @@ where fn init_with_config( b: &'s mut BlackBox, - config: BoardConfig

, + config: BoardConfig, ) -> ( &'s mut Self::ControlImpl, Option>, @@ -188,7 +167,7 @@ where &*EVENT_FUTURE_SHARED_STATE_CONT ); - let storage: &'s mut _ = b.put(BoardDevice::<_, P> { controller, _p: PhantomData }); + let storage: &'s mut _ = b.put(BoardDevice::<_> { controller }); ( &mut storage.controller, diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index d1b2d474..707c25f3 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -43,7 +43,7 @@ bytes = { version = "0.5.3", default-features = false, optional = true } # host-transport deps: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -serialport = { version = "3.3.0", optional = true } +serialport = { version = "4.2", optional = true } [dev-dependencies] diff --git a/device-support/src/rpc/transport/uart_host.rs b/device-support/src/rpc/transport/uart_host.rs index b3a25b5f..82a1a24e 100644 --- a/device-support/src/rpc/transport/uart_host.rs +++ b/device-support/src/rpc/transport/uart_host.rs @@ -3,20 +3,21 @@ use crate::util::Fifo; use lc3_traits::control::rpc::Transport; -use lc3_traits::control::{Identifier, Version, version_from_crate}; +use lc3_traits::control::{version_from_crate, Identifier, Version}; use serialport::{ - DataBits, FlowControl, Parity, StopBits, SerialPort, - open_with_settings + DataBits, FlowControl, Parity, Result as SerialResult, SerialPort, + StopBits, }; -pub use serialport::SerialPortSettings; +pub use serialport::SerialPortBuilder; -use std::path::Path; -use std::io::{Read, Write, Error, ErrorKind, Result as IoResult}; -use std::convert::AsRef; +use std::borrow::Cow; use std::cell::RefCell; -use std::time::Duration; +use std::convert::AsRef; use std::ffi::OsStr; +use std::io::{Error, ErrorKind, Read, Result as IoResult, Write}; +use std::path::Path; +use std::time::Duration; // TODO: Debug impl pub struct HostUartTransport { @@ -25,21 +26,24 @@ pub struct HostUartTransport { } impl HostUartTransport { - pub fn new>(path: P, baud_rate: u32) -> IoResult { - let settings = SerialPortSettings { - baud_rate: baud_rate, - data_bits: DataBits::Eight, - flow_control: FlowControl::None, - parity: Parity::None, - stop_bits: StopBits::One, - timeout: Duration::from_secs(100), - }; - - Self::new_with_config(path, settings) + pub fn new<'a>( + path: impl Into>, + baud_rate: u32, + ) -> SerialResult { + let settings = serialport::new(path, baud_rate) + .data_bits(DataBits::Eight) + .flow_control(FlowControl::None) + .parity(Parity::None) + .stop_bits(StopBits::One) + .timeout(Duration::from_secs(10)); + + Self::new_with_config(settings) } - pub fn new_with_config>(path: P, config: SerialPortSettings) -> IoResult { - let serial = open_with_settings(AsRef::::as_ref(path.as_ref()), &config)?; + pub fn new_with_config( + config: SerialPortBuilder, + ) -> SerialResult { + let serial = config.open()?; Ok(Self { serial: RefCell::new(serial), @@ -54,11 +58,13 @@ impl Transport, Fifo> for HostUartTransport { type RecvErr = Error; type SendErr = Error; - const ID: Identifier = Identifier::new_from_str_that_crashes_on_invalid_inputs("UART"); + const ID: Identifier = + Identifier::new_from_str_that_crashes_on_invalid_inputs("UART"); const VER: Version = { let ver = version_from_crate!(); - let id = Identifier::new_from_str_that_crashes_on_invalid_inputs("host"); + let id = + Identifier::new_from_str_that_crashes_on_invalid_inputs("host"); Version::new(ver.major, ver.minor, ver.patch, Some(id)) }; @@ -75,7 +81,7 @@ impl Transport, Fifo> for HostUartTransport { Err(e) => match e.kind() { ErrorKind::WouldBlock => continue, _ => return Err(e), - } + }, } } }; @@ -100,13 +106,13 @@ impl Transport, Fifo> for HostUartTransport { match serial.read(&mut temp_buf) { Ok(1) => { if temp_buf[0] == 0 { - return Ok(core::mem::replace(&mut buf, Fifo::new())) + return Ok(core::mem::replace(&mut buf, Fifo::new())); } else { // TODO: don't panic here; see the note in uart_simple buf.push(temp_buf[0]).unwrap() } - }, - Ok(0) => {}, + } + Ok(0) => {} Ok(_) => unreachable!(), Err(err) => { // if let std::io::ErrorKind::Io(kind) = err.kind() { @@ -120,9 +126,9 @@ impl Transport, Fifo> for HostUartTransport { // } if let std::io::ErrorKind::WouldBlock = err.kind() { - return Err(None) + return Err(None); } else { - return Err(Some(err)) + return Err(Some(err)); } } } @@ -131,5 +137,3 @@ impl Transport, Fifo> for HostUartTransport { Err(None) } } - - From 8404e86aa5ec776726a83653703898005b6731fd Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:04:12 -0500 Subject: [PATCH 02/25] build: fix some warnings across the project --- application-support/src/event_loop/mod.rs | 2 - application-support/src/init/board.rs | 4 +- application-support/src/init/sim.rs | 2 + application-support/src/init/websocket.rs | 3 -- application-support/src/io_peripherals.rs | 4 +- baseline-sim/src/interp.rs | 16 ++++---- baseline-sim/src/mem_mapped.rs | 19 ++++----- baseline-sim/src/sim.rs | 12 ++++-- device-support/src/rpc/encoding/postcard.rs | 6 +-- device-support/src/rpc/transport/mod.rs | 2 +- device-support/src/rpc/transport/uart_host.rs | 5 +-- device-support/src/util/fifo.rs | 41 ++++++++++++------- macros/src/lib.rs | 4 +- os/src/lib.rs | 2 +- shims/src/peripherals/gpio.rs | 4 +- shims/src/peripherals/input.rs | 2 +- shims/src/peripherals/output.rs | 6 +-- shims/src/peripherals/pwm.rs | 11 ++--- test-infrastructure/src/lc3tools/runner.rs | 17 ++++---- test-infrastructure/src/macros.rs | 2 - test-infrastructure/src/runner.rs | 4 +- traits/src/control/control.rs | 12 +++--- traits/src/control/snapshot.rs | 2 +- traits/src/peripherals/stubs.rs | 6 +-- 24 files changed, 94 insertions(+), 94 deletions(-) diff --git a/application-support/src/event_loop/mod.rs b/application-support/src/event_loop/mod.rs index fd070bab..ce0b2ff3 100644 --- a/application-support/src/event_loop/mod.rs +++ b/application-support/src/event_loop/mod.rs @@ -125,8 +125,6 @@ specialize! { not: { mod not_wasm; } } -use lc3_traits::control::Control; - /* // To make sure that the `Backoff` interface is satisfied: #[doc(hidden)] diff --git a/application-support/src/init/board.rs b/application-support/src/init/board.rs index 440301bb..12d584a5 100644 --- a/application-support/src/init/board.rs +++ b/application-support/src/init/board.rs @@ -19,10 +19,7 @@ use lc3_device_support::{ use std::{ borrow::Cow, sync::Mutex, - thread::Builder as ThreadBuilder, - path::{Path, PathBuf}, default::Default, - marker::PhantomData, }; // Static data that we need: @@ -33,6 +30,7 @@ lazy_static::lazy_static! { SyncEventFutureSharedState::new(); } +#[allow(type_alias_bounds)] type Cont<'ss, EncFunc: FnMut() -> Cobs>> = Controller< 'ss, HostUartTransport, diff --git a/application-support/src/init/sim.rs b/application-support/src/init/sim.rs index 2d54a7d2..440423e9 100644 --- a/application-support/src/init/sim.rs +++ b/application-support/src/init/sim.rs @@ -55,7 +55,9 @@ pub(crate) fn new_sim<'io>(shims: ShimPeripheralSet<'static, 'io>) -> Sim<'io> { pub struct SimDevice<'io> { sim: Option>, + #[allow(unused)] // TODO: see below input: Option, + #[allow(unused)] // TODO: see below output: Option>>, } diff --git a/application-support/src/init/websocket.rs b/application-support/src/init/websocket.rs index c0aa5feb..1a0fe59d 100644 --- a/application-support/src/init/websocket.rs +++ b/application-support/src/init/websocket.rs @@ -1,8 +1,5 @@ //! TODO! -use super::{BlackBox, Init}; -use crate::shim_support::Shims; - #[derive(Debug)] pub struct WebSocketDevice {} diff --git a/application-support/src/io_peripherals.rs b/application-support/src/io_peripherals.rs index c636e8d0..da04a520 100644 --- a/application-support/src/io_peripherals.rs +++ b/application-support/src/io_peripherals.rs @@ -4,10 +4,8 @@ //! [`Input`]: `lc3_traits::peripherals::Input` //! [`Output`]: `lc3_traits::peripherals::Output` -use lc3_shims::peripherals::{Sink, SourceShim}; +use lc3_shims::peripherals::SourceShim; -use std::io::{Read, Write}; -use std::ops::{Deref, DerefMut}; use std::sync::{Arc, Mutex}; /// A trait for [`Input`] Peripherals that lets us, a controller, supply the diff --git a/baseline-sim/src/interp.rs b/baseline-sim/src/interp.rs index 11a25b31..738577d7 100644 --- a/baseline-sim/src/interp.rs +++ b/baseline-sim/src/interp.rs @@ -67,19 +67,21 @@ where } fn reset_peripherals(&mut self) { - use lc3_traits::peripherals::gpio::{GPIO_PINS, GpioPin, GpioState}; - use lc3_traits::peripherals::adc::{Adc, ADC_PINS, AdcPin, AdcState}; - use lc3_traits::peripherals::pwm::{Pwm, PWM_PINS, PwmPin, PwmState}; - use lc3_traits::peripherals::timers::{TIMERS, TimerId, TimerMode, TimerState}; + use lc3_traits::peripherals::gpio::{GPIO_PINS, GpioState}; + use lc3_traits::peripherals::adc::{Adc, ADC_PINS, AdcState}; + use lc3_traits::peripherals::pwm::{Pwm, PWM_PINS, PwmState}; + use lc3_traits::peripherals::timers::{TIMERS, TimerMode, TimerState}; use lc3_traits::peripherals::clock::Clock; + // TODO: do something with errors here? + for pin in GPIO_PINS.iter() { - Gpio::set_state(self.get_peripherals_mut(), *pin, GpioState::Disabled); + let _ = Gpio::set_state(self.get_peripherals_mut(), *pin, GpioState::Disabled); Gpio::reset_interrupt_flag(self.get_peripherals_mut(), *pin); } for pin in ADC_PINS.iter() { - Adc::set_state(self.get_peripherals_mut(), *pin, AdcState::Disabled); + let _ = Adc::set_state(self.get_peripherals_mut(), *pin, AdcState::Disabled); } for pin in PWM_PINS.iter() { @@ -1072,7 +1074,7 @@ impl<'a, M: Memory, P: Peripherals<'a>> InstructionInterpreter for Interpreter<' } // Increment PC (state 18): - let mut current_pc = self.get_pc(); + let current_pc = self.get_pc(); self.set_pc(current_pc.wrapping_add(1)); // TODO: ??? if self.check_interrupts() { diff --git a/baseline-sim/src/mem_mapped.rs b/baseline-sim/src/mem_mapped.rs index 6aca5efe..0bd7b51f 100644 --- a/baseline-sim/src/mem_mapped.rs +++ b/baseline-sim/src/mem_mapped.rs @@ -110,7 +110,7 @@ use lc3_isa::{Addr, Bits, SignedWord, Word, MCR as MCR_ADDR, PSR as PSR_ADDR, WO use lc3_traits::peripherals::Peripherals; use lc3_traits::error::Error; -use crate::interp::{Acv, InstructionInterpreter, WriteAttempt}; +use crate::interp::{Acv, WriteAttempt}; pub trait MemMapped: Deref + Sized { const ADDR: Addr; @@ -354,7 +354,7 @@ impl MemMapped for KBDR { Ok(Self::with_value(data)) } - fn set<'a, I>(interp: &mut I, value: Word) -> WriteAttempt + fn set<'a, I>(_interp: &mut I, _value: Word) -> WriteAttempt where I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, @@ -536,11 +536,12 @@ impl MemMapped for DDR { Self(value) } - fn from<'a, I>(interp: &I) -> Result + fn from<'a, I>(_interp: &I) -> Result where I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { + // TODO: error here? Ok(Self::with_value(0 as Word)) } @@ -549,7 +550,8 @@ impl MemMapped for DDR { I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { - Output::write_data(interp.get_peripherals_mut(), value as u8); + // TODO: propagate errors here! + let _ = Output::write_data(interp.get_peripherals_mut(), value as u8); Ok(()) } } @@ -667,8 +669,6 @@ macro_rules! gpio_mem_mapped { I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { - use lc3_traits::peripherals::gpio::GpioState::*; - let word = match Gpio::read(interp.get_peripherals(), $pin) { Ok(val) => val as Word, Err(err) => { @@ -685,8 +685,6 @@ macro_rules! gpio_mem_mapped { I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { - use lc3_traits::peripherals::gpio::GpioState::*; - let bit: bool = value.bit(0); match Gpio::write(interp.get_peripherals_mut(), $pin, bit) { Ok(()) => Ok(()), @@ -859,7 +857,6 @@ macro_rules! adc_mem_mapped { I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { - use lc3_traits::peripherals::adc::AdcState::*; let word = match Adc::read(interp.get_peripherals(), $pin) { Ok(val) => val as Word, @@ -872,7 +869,7 @@ macro_rules! adc_mem_mapped { Ok(Self::with_value(word)) } - fn set<'a, I>(interp: &mut I, value: Word) -> WriteAttempt + fn set<'a, I>(_interp: &mut I, _value: Word) -> WriteAttempt where I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, @@ -1006,8 +1003,6 @@ macro_rules! pwm_mem_mapped { I: InstructionInterpreterPeripheralAccess<'a>, ::Target: Peripherals<'a>, { - use lc3_traits::peripherals::pwm::PwmState::*; - let word = Pwm::get_duty_cycle(interp.get_peripherals(), $pin) as Word; Ok(Self::with_value(word)) diff --git a/baseline-sim/src/sim.rs b/baseline-sim/src/sim.rs index bc7220eb..801b7faa 100644 --- a/baseline-sim/src/sim.rs +++ b/baseline-sim/src/sim.rs @@ -6,7 +6,7 @@ use crate::mem_mapped::{MemMapped, KBDR}; use lc3_isa::{Addr, Reg, Word}; use lc3_traits::control::{Control, Event, State, UnifiedRange, Idx, ProcessorMode}; use lc3_traits::control::control::{MAX_BREAKPOINTS, MAX_MEMORY_WATCHPOINTS, MAX_CALL_STACK_DEPTH}; -use lc3_traits::control::metadata::{Identifier, ProgramMetadata, DeviceInfo, Version}; +use lc3_traits::control::metadata::{Identifier, ProgramMetadata, DeviceInfo}; use lc3_traits::control::load::{ PageIndex, PageWriteStart, StartPageWriteError, PageChunkError, FinishPageWriteError, LoadApiSession, Offset, CHUNK_SIZE_IN_WORDS, @@ -396,7 +396,7 @@ where // } for _ in 0..STEPS_IN_A_TICK { - if let Some(e) = self.step() { + if let Some(_e) = self.step() { // If we produced some event, we're no longer `RunningUntilEvent`. return STEPS_IN_A_TICK; // this is not accurate but this is allowed } @@ -555,7 +555,11 @@ where match self.get_state() { Halted | Paused => {}, // Nothing changes! RunningUntilEvent => { - self.shared_state.as_ref().expect("unreachable; must have a shared state to call a run_until_event and therefore be in `RunningUntilEvent`").resolve_all(Event::Interrupted); + self + .shared_state.as_ref() + .expect("unreachable; must have a shared state to call a run_until_event and therefore be in `RunningUntilEvent`") + .resolve_all(Event::Interrupted) + .expect("error: batch sealed!"); self.state = Paused; } } @@ -568,7 +572,7 @@ where fn reset(&mut self) { self.interp.halt(); - self.unset_depth_condition(); + let _ = self.unset_depth_condition(); // Resolve all futures! Doesn't cause problems if reset is called // multiple times. diff --git a/device-support/src/rpc/encoding/postcard.rs b/device-support/src/rpc/encoding/postcard.rs index df4dd549..d5d9fcd8 100644 --- a/device-support/src/rpc/encoding/postcard.rs +++ b/device-support/src/rpc/encoding/postcard.rs @@ -2,10 +2,10 @@ use crate::util::Fifo; -use lc3_traits::control::rpc::{Encode, Decode, RequestMessage, ResponseMessage}; +use lc3_traits::control::rpc::{Encode, Decode}; use serde::{Serialize, Deserialize}; -use postcard::flavors::{SerFlavor, Cobs, Slice}; +use postcard::flavors::{SerFlavor, Cobs}; use postcard::serialize_with_flavor; use postcard::take_from_bytes_cobs; @@ -165,7 +165,7 @@ mod decode { fn decode(&mut self, encoded: &Self::Encoded) -> Result { // This is bad and is a hack! let mut fifo: Fifo = Fifo::new(); - fifo.push_slice(encoded.as_ref()); + fifo.push_slice(encoded.as_ref()).unwrap(); // fifo.push_iter(&mut encoded.as_ref().iter()).unwrap(); // // TODO: remove this hack! diff --git a/device-support/src/rpc/transport/mod.rs b/device-support/src/rpc/transport/mod.rs index 4e88283d..5129bed7 100644 --- a/device-support/src/rpc/transport/mod.rs +++ b/device-support/src/rpc/transport/mod.rs @@ -1,6 +1,6 @@ //! TODO! -use crate::util::fifo::{self, Fifo}; +use crate::util::fifo; use lc3_traits::control::rpc::{RequestMessage, ResponseMessage}; diff --git a/device-support/src/rpc/transport/uart_host.rs b/device-support/src/rpc/transport/uart_host.rs index 82a1a24e..a1853258 100644 --- a/device-support/src/rpc/transport/uart_host.rs +++ b/device-support/src/rpc/transport/uart_host.rs @@ -13,10 +13,7 @@ pub use serialport::SerialPortBuilder; use std::borrow::Cow; use std::cell::RefCell; -use std::convert::AsRef; -use std::ffi::OsStr; use std::io::{Error, ErrorKind, Read, Result as IoResult, Write}; -use std::path::Path; use std::time::Duration; // TODO: Debug impl @@ -90,7 +87,7 @@ impl Transport, Fifo> for HostUartTransport { // serial.write(message.as_slice()).map(|_| ())?; // serial.flush() - block!(serial.write(message.as_slice()).map(|_| ())); + block!(serial.write(message.as_slice()).map(|_| ())).unwrap(); block!(serial.flush()) } diff --git a/device-support/src/util/fifo.rs b/device-support/src/util/fifo.rs index 7709989e..d64e2888 100644 --- a/device-support/src/util/fifo.rs +++ b/device-support/src/util/fifo.rs @@ -1,11 +1,11 @@ //! Stack allocated FIFO. (TODO) use core::{ + convert::{AsMut, AsRef}, fmt::{self, Debug}, - iter::{ExactSizeIterator, Iterator, FusedIterator}, + iter::{ExactSizeIterator, FusedIterator, Iterator}, mem::{replace, size_of, transmute, transmute_copy, MaybeUninit}, ops::{Index, IndexMut}, - convert::{AsRef, AsMut}, }; // Note: Capacity is a constant so that the transition to const generics (once @@ -305,7 +305,7 @@ impl Fifo { &[] } else { if self.ending > self.starting { - let s = & self.data + let s = &self.data [(self.starting as usize)..(self.ending as usize)]; #[allow(unsafe_code)] @@ -314,7 +314,7 @@ impl Fifo { } } else if self.ending <= self.starting { // Gotta do it in two parts then. - let s = & self.data[(self.starting as usize)..]; + let s = &self.data[(self.starting as usize)..]; #[allow(unsafe_code)] unsafe { @@ -491,9 +491,9 @@ impl Iterator for /*&mut */Fifo { } } -impl FusedIterator for Fifo { } +impl FusedIterator for Fifo {} -impl ExactSizeIterator for Fifo { } +impl ExactSizeIterator for Fifo {} using_alloc! { use core::convert::TryInto; @@ -558,7 +558,6 @@ sa::assert_eq_size!(&mut [MaybeUninit], &mut [u8]); sa::assert_eq_size!([MaybeUninit; CAPACITY], [u8; CAPACITY]); sa::assert_eq_align!([MaybeUninit; CAPACITY], [u8; CAPACITY]); - #[cfg(test)] mod tests { use super::*; @@ -575,17 +574,23 @@ mod tests { } impl Cloneable { - const fn new(n: usize) -> Self { Self { a: n, b: n, c: n } } + const fn new(n: usize) -> Self { + Self { a: n, b: n, c: n } + } } // A type this does *not* implement Clone. #[derive(Debug, PartialEq, Eq)] struct Uncloneable { - inner: Cloneable + inner: Cloneable, } impl Uncloneable { - const fn new(n: usize) -> Self { Self { inner: Cloneable::new(n) } } + const fn new(n: usize) -> Self { + Self { + inner: Cloneable::new(n), + } + } } // Also tests push_slice (requires Clone) @@ -645,7 +650,9 @@ mod tests { #[test] fn push_uncloneable() { let mut arr = [0; CAPACITY]; - for i in 0..CAPACITY { arr[i] = i; } + for i in 0..CAPACITY { + arr[i] = i; + } let mut iter = arr.iter().map(|i| Uncloneable::new(*i)); let mut fifo = Fifo::new(); @@ -661,7 +668,9 @@ mod tests { fn overpush() { let mut fifo = FIFO; - for i in 0..fifo.capacity() { assert_eq!(Ok(()), fifo.push(i)); } + for i in 0..fifo.capacity() { + assert_eq!(Ok(()), fifo.push(i)); + } assert_eq!(Err(()), fifo.push(123)); assert_eq!(Err(()), fifo.push(567)); @@ -674,10 +683,14 @@ mod tests { assert_eq!(None, fifo.pop()); assert_eq!(None, fifo.pop()); - for i in 0..fifo.capacity() { assert_eq!(Ok(()), fifo.push(i)); } + for i in 0..fifo.capacity() { + assert_eq!(Ok(()), fifo.push(i)); + } // Also tests ordering! - for i in 0..fifo.capacity() { assert_eq!(Some(i), fifo.pop()); } + for i in 0..fifo.capacity() { + assert_eq!(Some(i), fifo.pop()); + } assert_eq!(None, fifo.pop()); assert_eq!(None, fifo.pop()); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index b369a8fc..cbe715e8 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -50,9 +50,10 @@ use proc_macro2::Span; use quote::quote_spanned; /// Report an error with the given `span` and message. +#[allow(unused)] pub(crate) fn spanned_err(span: Span, msg: impl Into) -> proc_macro::TokenStream { let msg = msg.into(); - quote_spanned!(span.into() => { + quote_spanned!(span => { compile_error!(#msg); }) .into() @@ -62,7 +63,6 @@ pub(crate) fn spanned_err(span: Span, msg: impl Into) -> proc_macro::Tok // pub use lifetime_to_identifier::lifetime_to_ident; -use proc_macro::TokenTree; use quote::quote; use syn::{parse::Parse, parse::ParseStream, parse::Result as ParseResult, Ident}; use syn::{parse_macro_input, Lifetime}; diff --git a/os/src/lib.rs b/os/src/lib.rs index 921b7217..2cacd910 100644 --- a/os/src/lib.rs +++ b/os/src/lib.rs @@ -43,7 +43,7 @@ #![doc(test(attr(deny(warnings))))] #![doc(html_logo_url = "")] // TODO! -#![deny(intra_doc_link_resolution_failure)] // TODO: this is temporary +#![deny(rustdoc::broken_intra_doc_links)] // TODO: this is temporary // Enable the `doc_cfg` feature when running rustdoc. #![cfg_attr(all(docs, not(doctest)), feature(doc_cfg))] diff --git a/shims/src/peripherals/gpio.rs b/shims/src/peripherals/gpio.rs index 1b3b7dcf..c5cf1325 100644 --- a/shims/src/peripherals/gpio.rs +++ b/shims/src/peripherals/gpio.rs @@ -140,8 +140,8 @@ impl<'a> Gpio<'a> for GpioShim<'a> { (State::Input(_), Output) | (State::Interrupt(_), Output) => State::Output(false), - (State::Input(v), Interrupt) | - (State::Interrupt(v), Interrupt) => State::Interrupt(false), + (State::Input(_), Interrupt) | + (State::Interrupt(_), Interrupt) => State::Interrupt(false), (State::Disabled, Interrupt) | (State::Output(_), Interrupt) => State::Interrupt(false), diff --git a/shims/src/peripherals/input.rs b/shims/src/peripherals/input.rs index c2f7072f..29810a43 100644 --- a/shims/src/peripherals/input.rs +++ b/shims/src/peripherals/input.rs @@ -103,7 +103,7 @@ impl Default for InputShim<'_, '_> { } impl<'int, 'i> InputShim<'i, 'int> { - fn new() -> Self { + pub fn new() -> Self { Self::default() } diff --git a/shims/src/peripherals/output.rs b/shims/src/peripherals/output.rs index 7ef223c9..3b5ec344 100644 --- a/shims/src/peripherals/output.rs +++ b/shims/src/peripherals/output.rs @@ -1,5 +1,5 @@ use lc3_traits::peripherals::output::{Output, OutputError}; -use std::io::{stdout, Error as IoError, Write}; +use std::io::{stdout, Write}; use crate::peripherals::OwnedOrRef; @@ -28,11 +28,11 @@ impl Sink for Mutex { impl Sink for Arc { fn put_char(&self, c: u8) -> IoResult { - self.put_char(c) + (**self).put_char(c) } fn flush(&self) -> IoResult<()> { - self.flush() + (**self).flush() } } diff --git a/shims/src/peripherals/pwm.rs b/shims/src/peripherals/pwm.rs index 5cfe397b..dbbdfe9d 100644 --- a/shims/src/peripherals/pwm.rs +++ b/shims/src/peripherals/pwm.rs @@ -3,19 +3,14 @@ use core::num::NonZeroU8; use lc3_traits::peripherals::pwm::{ Pwm, PwmPin, PwmPinArr, PwmState, PwmDutyCycle, }; -use std::sync::mpsc; use std::sync::Arc; -use std::sync::Mutex; -use std::thread; use std::time::Duration; use timer; use chrono; -use core::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc::channel; +use core::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; use std::thread::sleep; -const MAX_PERIOD: u8 = u8::max_value(); const MAX_DUTY_CYCLE: PwmDutyCycle = PwmDutyCycle::max_value(); pub struct PwmShim { @@ -89,7 +84,7 @@ impl PwmShim { drop(feg); } - fn get_pin(&self, pin: PwmPin) -> bool { + pub fn get_pin(&self, pin: PwmPin) -> bool { return self.bit_states[pin].load(SeqCst); } @@ -130,6 +125,8 @@ mod tests { use super::*; use lc3_traits::peripherals::pwm::{self, Pwm, PwmPin::*, PwmState}; + const MAX_PERIOD: u8 = u8::max_value(); + use lc3_test_infrastructure::{ assert_eq, assert_is_about, run_periodically_for_a_time }; diff --git a/test-infrastructure/src/lc3tools/runner.rs b/test-infrastructure/src/lc3tools/runner.rs index c36cfd9d..9c6d7275 100644 --- a/test-infrastructure/src/lc3tools/runner.rs +++ b/test-infrastructure/src/lc3tools/runner.rs @@ -8,14 +8,14 @@ use crate::{ InstructionInterpreter, Addr, Word, Reg, }; -use lc3_baseline_sim::interp::{MachineState, InterpreterBuilder}; +use lc3_baseline_sim::interp::InterpreterBuilder; use lc3_traits::memory::Memory; use lc3_traits::peripherals::Peripherals; -use std::fs::{File, remove_file}; -use std::io::{self, BufReader, Write}; +use std::fs::File; +use std::io::{self, Write}; use std::process::Command; -use std::convert::{TryFrom, TryInto}; +use std::convert::TryInto; use std::iter::once; use std::env; @@ -36,7 +36,6 @@ pub struct MemEntry { // TODO: we assume that there are no branches or control flow instructions! This // is very limiting! -// TODO: actually check the final PC, PSR, CC, and MCR. const DEBUG: bool = false; @@ -50,6 +49,8 @@ macro_rules! d { }; } +// TODO: actually check the final PC, PSR, CC, and MCR. +#[allow(unused_assignments, unused_variables)] pub fn lc3tools_tester<'flags, M: Memory + Default + Clone, P: Peripherals<'flags>> ( insns: Vec, @@ -79,7 +80,7 @@ pub fn lc3tools_tester<'flags, M: Memory + Default + Clone, P: Peripherals<'flag } // Run the program in lc3tools and collect the trace. - let mut output = Command::new(format!("{}/lc3tools_executor.sh", OUT_DIR)) + let output = Command::new(format!("{}/lc3tools_executor.sh", OUT_DIR)) .arg(lc3_asm_file_path) .arg(lc3tools_bin_dir) .output()? @@ -96,7 +97,7 @@ pub fn lc3tools_tester<'flags, M: Memory + Default + Clone, P: Peripherals<'flag // for `0x25` style formatting fn parse_hex_val(v: &str) -> u16 { - d!(v); + let _ = d!(v); Word::from_str_radix(&v[2..], 16).unwrap() } @@ -208,7 +209,7 @@ pub fn lc3tools_tester<'flags, M: Memory + Default + Clone, P: Peripherals<'flag } for _ in 0..steps { - interp.step(); + let _ = interp.step(); } // Check registers: diff --git a/test-infrastructure/src/macros.rs b/test-infrastructure/src/macros.rs index c061e8c7..86d7e90f 100644 --- a/test-infrastructure/src/macros.rs +++ b/test-infrastructure/src/macros.rs @@ -1,7 +1,5 @@ //! Macros for writing Interpreter tests. -#![macro_use] - #[doc(inline)] pub use crate::single_test; diff --git a/test-infrastructure/src/runner.rs b/test-infrastructure/src/runner.rs index c7112f83..e1f0ae64 100644 --- a/test-infrastructure/src/runner.rs +++ b/test-infrastructure/src/runner.rs @@ -7,7 +7,7 @@ use lc3_traits::peripherals::Peripherals; use lc3_baseline_sim::interp::{PeripheralInterruptFlags, InstructionInterpreter, Interpreter, InterpreterBuilder, MachineState }; -use core::convert::{TryFrom, TryInto}; +use core::convert::TryInto; use pretty_assertions::assert_eq; @@ -87,7 +87,7 @@ where if let Some(num_steps) = num_steps { for _ in 0..num_steps { // println!("step: x{0:4X}", interp.get_pc()); - interp.step(); + let _ = interp.step(); } } else { while let MachineState::Running = interp.step() { } diff --git a/traits/src/control/control.rs b/traits/src/control/control.rs index 1411341a..b5e6bfb8 100644 --- a/traits/src/control/control.rs +++ b/traits/src/control/control.rs @@ -41,18 +41,18 @@ sa::const_assert!(MAX_CALL_STACK_DEPTH <= (Idx::max_value() as usize)); sa::const_assert!(core::mem::size_of::() <= core::mem::size_of::()); pub enum DebugStep { - STEP_OVER(usize), - STEP_IN(usize), - STEP_OUT(usize), + StepOver(usize), + StepIn(usize), + StepOut(usize), } use DebugStep::*; impl Into> for DebugStep { fn into(self) -> UnifiedRange { match self { - STEP_OVER(cur_depth) => (..=cur_depth).into(), - STEP_IN(cur_depth) => (cur_depth..).into(), - STEP_OUT(cur_depth) => (..cur_depth).into(), + StepOver(cur_depth) => (..=cur_depth).into(), + StepIn(cur_depth) => (cur_depth..).into(), + StepOut(cur_depth) => (..cur_depth).into(), } } } diff --git a/traits/src/control/snapshot.rs b/traits/src/control/snapshot.rs index 53e1c7a3..2426d38e 100644 --- a/traits/src/control/snapshot.rs +++ b/traits/src/control/snapshot.rs @@ -24,7 +24,7 @@ impl From for SnapshotError { } impl Display for SnapshotError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { // TODO unimplemented!() } diff --git a/traits/src/peripherals/stubs.rs b/traits/src/peripherals/stubs.rs index c198a573..0294c834 100644 --- a/traits/src/peripherals/stubs.rs +++ b/traits/src/peripherals/stubs.rs @@ -36,7 +36,7 @@ impl<'a> Gpio<'a> for GpioStub { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct AdcStub; -use super::adc::{AdcPin, AdcState, AdcPinArr, AdcReadError, AdcMiscError}; +use super::adc::{AdcPin, AdcState, AdcReadError, AdcMiscError}; impl Adc for AdcStub { fn set_state(&mut self, _pin: AdcPin, _: AdcState) -> Result<(), AdcMiscError> { Err(AdcMiscError) } fn get_state(&self, _pin: AdcPin) -> AdcState { AdcState::Disabled } @@ -47,7 +47,7 @@ impl Adc for AdcStub { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct PwmStub; -use super::pwm::{PwmPin, PwmState, PwmPinArr, PwmDutyCycle}; +use super::pwm::{PwmPin, PwmState, PwmDutyCycle}; impl Pwm for PwmStub { fn set_state(&mut self, _pin: PwmPin, _state: PwmState) { } fn get_state(&self, _pin: PwmPin) -> PwmState { PwmState::Disabled } @@ -103,7 +103,7 @@ pub struct OutputStub; use super::output::OutputError; impl<'a> Output<'a> for OutputStub { - fn write_data(&mut self, c: u8) -> Result<(), OutputError> { Ok(()) } + fn write_data(&mut self, _c: u8) -> Result<(), OutputError> { Ok(()) } fn current_data_written(&self) -> bool { true } fn register_interrupt_flag(&mut self, _flag: &'a AtomicBool) { } From e18524bd32cf0876b50fb500fa1d37078e84437c Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:26:44 -0500 Subject: [PATCH 03/25] isa: do away with some `nightly-const` feature requirements, update the match Rust 1.62 almost all of the nightly const fn features we required have been stabilized --- isa/Cargo.toml | 5 +++- isa/src/isa.rs | 4 +-- isa/src/lib.rs | 29 +++------------------ isa/src/macros.rs | 65 ++++++++++++++++++++++++++++++++++++----------- 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/isa/Cargo.toml b/isa/Cargo.toml index 27b00ba2..6421296c 100644 --- a/isa/Cargo.toml +++ b/isa/Cargo.toml @@ -45,7 +45,10 @@ std = [] strict = [] arbitrary = ["dep:arbitrary", "std"] -nightly-const = [] # Requires nightly; isn't tested by CI. + +# Requires nightly; enables some quality of life features in the LC-3 macros +# (better error messages). +nightly-const = [] [package.metadata.docs.rs] # targets = [""] diff --git a/isa/src/isa.rs b/isa/src/isa.rs index bf420975..35f9ffa5 100644 --- a/isa/src/isa.rs +++ b/isa/src/isa.rs @@ -768,7 +768,7 @@ impl Instruction { // #[doc(hidden)] #[rustfmt::skip] - nightly_const! { [pub] => [fn to_word(&self) -> u16 { + pub const fn to_word(&self) -> u16 { #![allow(non_snake_case)] use Instruction::*; @@ -808,7 +808,7 @@ impl Instruction { Str { sr, base, offset6 } => Op(0b0111) | Dr(sr) | Base(base) | O6(offset6), Trap { trapvec } => Op(0b1111) | Trapvec(trapvec) , } - }]} + } } // TODO: tests for Instruction diff --git a/isa/src/lib.rs b/isa/src/lib.rs index 7f0f1347..c8b924c3 100644 --- a/isa/src/lib.rs +++ b/isa/src/lib.rs @@ -50,31 +50,7 @@ // Note: this feature is not tested by CI (still dependent on nightly Rust) but // this is fine for now. -#![cfg_attr(feature = "nightly-const", feature(const_if_match))] -#![cfg_attr(feature = "nightly-const", feature(const_panic))] - -// Makes some an item const if the nightly-const feature is activated and not -// const otherwise. -#[macro_export] -#[doc(hidden)] -macro_rules! nightly_const { - ( - $( $(#[$m:meta])+ )? - [$($vis:tt)*] => [$($rest:tt)*] - ) => ( - #[cfg(not(feature = "nightly-const"))] - $( $(#[$m:meta])+ )? - /// - /// **NOTE**: This is only `const` when the `nightly-const` feature is enabled! - $($vis)* $($rest)* - - #[cfg(feature = "nightly-const")] - $( $(#[$m:meta])+ )? - /// - /// **NOTE**: This is only `const` when the `nightly-const` feature is enabled! - $($vis)* const $($rest)* - ); -} +#![cfg_attr(feature = "nightly-const", feature(const_format_args))] extern crate static_assertions as sa; @@ -143,5 +119,8 @@ mod isa; mod macros; mod misc; +#[doc(hidden)] +pub use macros::overlap_error as _macro_support; + pub use isa::*; pub use misc::util; diff --git a/isa/src/macros.rs b/isa/src/macros.rs index f815b688..9a6c0143 100644 --- a/isa/src/macros.rs +++ b/isa/src/macros.rs @@ -246,18 +246,13 @@ macro_rules! program { // let $label = $addr; // )? - // If we want to be const, we'll have to disable this check (or find a workaround). - // Right now the blocker for being const is that we can't match (or deal with enum - // variants at all) which breaks our ability to convert `Instruction`s to `Word`s - // (which is fairly required). + // This is the last bit of const fn functionality that we use that *isn't* on stable Rust. // - // Update: now that const if/match have landed on nightly, this macro can be - // const and *is* const when this crate is used with the `nightly-const` feature - // and a new enough nightly rustc build. - #[cfg(not(feature = "nightly-const"))] - { if $mem[$addr as usize].1 { panic!("Overlap at {:#4X}!", $addr); } } - #[cfg(feature = "nightly-const")] - { if $mem[$addr as usize].1 { panic!("Overlap!"); } } // Can't format in consts yet! + // Invocations of this macro are always const; it's just that you get worse errors for overlaps + // when _not_ using `nightly-const` and a nightly compiler. + // + // See the `overlap` macro for details. + { if $mem[$addr as usize].1 { $crate::overlap!($addr); } } $mem[$addr as usize] = ($crate::word!(FILL $($regs,)* $(#((($label_operand))))? $(#$num)*), true); $addr += 1; @@ -273,10 +268,7 @@ macro_rules! program { // )? // See the above comment about const contexts. - #[cfg(not(feature = "nightly-const"))] - { if $mem[$addr as usize].1 { panic!("Overlap at {:#4X}!", $addr); } } - #[cfg(feature = "nightly-const")] - { if $mem[$addr as usize].1 { panic!("Overlap!"); } } // Can't format in consts yet! + { if $mem[$addr as usize].1 { $crate::overlap!($addr); } } $mem[$addr as usize] = ($crate::word!($op $($regs,)* $(#((($label_operand as i64) - ($addr as i64) - 1) as $crate::SignedWord))? $(#$num)*), true); $addr += 1; @@ -312,6 +304,49 @@ macro_rules! program { }; } +/// This houses the last bit of unstable const fn functionality that we use. +/// +/// We want to tie uses of `panic!(..., ...)` (unstable as of 1.62) to the +/// `nightly-const` feature in _this_ crate and not in the crate where the macro +/// is expanded. +/// +/// This requires us to break out this part of the [`program`] macro into +/// separate macros that are `cfg`ed; hence: this module. +#[doc(hidden)] +pub mod overlap_error { + #[macro_export] + #[doc(hidden)] + #[cfg(feature = "nightly-const")] + macro_rules! overlap { + ($addr:ident) => { + // If we can use `feature(const_format_args)`, just panic normally: + $crate::_macro_support::err($addr); + }; + } + + // NOTE: we wrap this in a function so that it isn't reliant on nightly + // features being enabled in the crate of the caller of the macro. + #[doc(hidden)] + #[cfg(feature = "nightly-const")] + pub const fn err(addr: crate::Word) { + panic!("Overlap at {:#4X}!", addr); + } + + #[macro_export] + #[doc(hidden)] + #[cfg(not(feature = "nightly-const"))] + macro_rules! overlap { + ($addr:ident) => { + // If we can't use nightly features, panic in this weird way that kind of + // hints at what the overlap address is: + let _ = { + const OVERLAP_ERROR_AT_ADDRESS: [(); 0] = []; + let _ = OVERLAP_ERROR_AT_ADDRESS[$addr as usize]; + }; + }; + } +} + #[macro_export] /// (TODO!) /// From 4ef11a2f1d1af23faa52f360bb47828379e003a5 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:27:48 -0500 Subject: [PATCH 04/25] os: update `OS` to match the nightly const changes in `isa` now that `OS_CONST` can be const by default, we can do away with the `lazy_static!` `OS`! --- os/Cargo.toml | 5 ++++- os/src/lib.rs | 9 --------- os/src/os.rs | 16 +++++----------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/os/Cargo.toml b/os/Cargo.toml index 56f9ea82..f69c93c9 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -48,7 +48,10 @@ path = "tests/trap_tests/mod.rs" [features] default = [] -nightly-const = ["lc3-isa/nightly-const"] # Requires nightly; isn't tested by CI. + +# Requires nightly; enables some quality of life features in the LC-3 macros +# (better error messages). +nightly-const = ["lc3-isa/nightly-const"] [package.metadata.docs.rs] # targets = [""] diff --git a/os/src/lib.rs b/os/src/lib.rs index 2cacd910..2c0cf020 100644 --- a/os/src/lib.rs +++ b/os/src/lib.rs @@ -51,15 +51,6 @@ // We're a no_std crate! #![no_std] -// Note: this feature is not tested by CI (still dependent on nightly Rust) but -// this is fine for now. -#![cfg_attr(feature = "nightly-const", feature(const_if_match))] -#![cfg_attr(feature = "nightly-const", feature(const_panic))] - -// Makes some an item const if the nightly-const feature is activated and not -// const otherwise. -use lc3_isa::nightly_const; - extern crate static_assertions as sa; // Note that these are 'page' aligned with the default starting sp pointing at diff --git a/os/src/os.rs b/os/src/os.rs index b102bd49..ae56e9ca 100644 --- a/os/src/os.rs +++ b/os/src/os.rs @@ -15,19 +15,13 @@ use lazy_static::lazy_static; lazy_static! { /// The LC-3 OS this crate provides in [MemoryDump](lc3_isa::util::MemoryDump) form. pub static ref OS_IMAGE: MemoryDump = os().into(); - - /// The LC-3 OS this crate provides in raw - /// ([AssembledProgram](lc3_isa::util::AssembledProgram)) form. This can be turned - /// into a (Addr, Word) iterator over *only the words that are set. - pub static ref OS: AssembledProgram = os(); } -#[cfg_attr(all(docs, not(doctest)), doc(cfg(feature = "nightly-const")))] -#[cfg(feature = "nightly-const")] -pub const CONST_OS: AssembledProgram = os(); +/// The LC-3 OS this crate provides in raw ([`AssembledProgram`]) form. This can +/// be turned into a `(Addr, Word)` iterator over *only the words that are set. +pub const OS: AssembledProgram = os(); -crate::nightly_const! { [] => [ -fn os() -> AssembledProgram { +const fn os() -> AssembledProgram { use Word as W; let os = lc3_isa::program! { @@ -1816,7 +1810,7 @@ fn os() -> AssembledProgram { }; AssembledProgram::new(os) -}]} +} // TODO: offer a variant of this that has the OS be silent (no HALT, ACV, etc. messages). From f932908c719ab7ae151f605278ea7e4979703020 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:42:53 -0500 Subject: [PATCH 05/25] isa: drop the `nightly-const` feature the `const_panic` crate gives us the functionality we want on stable this was the last thing blocking `--all-features` from building on stable --- isa/Cargo.toml | 5 +---- isa/src/lib.rs | 4 ---- isa/src/macros.rs | 51 +++++++---------------------------------------- os/Cargo.toml | 4 ---- 4 files changed, 8 insertions(+), 56 deletions(-) diff --git a/isa/Cargo.toml b/isa/Cargo.toml index 6421296c..cec5cd9b 100644 --- a/isa/Cargo.toml +++ b/isa/Cargo.toml @@ -33,6 +33,7 @@ lc3-macros = { path = "../macros", version = "0.1.0" } serde = { version = "1.0", default-features = false, features = ["derive"]} static_assertions = "1.1.0" arbitrary = { version = "0.4.1", features = ["derive"], optional = true } +const_panic = "0.2" [dev-dependencies] itertools = "0.9.0" @@ -46,10 +47,6 @@ strict = [] arbitrary = ["dep:arbitrary", "std"] -# Requires nightly; enables some quality of life features in the LC-3 macros -# (better error messages). -nightly-const = [] - [package.metadata.docs.rs] # targets = [""] rustdoc-args = ["--cfg", "docs"] diff --git a/isa/src/lib.rs b/isa/src/lib.rs index c8b924c3..df5eb621 100644 --- a/isa/src/lib.rs +++ b/isa/src/lib.rs @@ -48,10 +48,6 @@ // Enable the `doc_cfg` feature when running rustdoc. #![cfg_attr(all(docs, not(doctest)), feature(doc_cfg))] -// Note: this feature is not tested by CI (still dependent on nightly Rust) but -// this is fine for now. -#![cfg_attr(feature = "nightly-const", feature(const_format_args))] - extern crate static_assertions as sa; use core::mem::size_of; diff --git a/isa/src/macros.rs b/isa/src/macros.rs index 9a6c0143..1d416191 100644 --- a/isa/src/macros.rs +++ b/isa/src/macros.rs @@ -241,17 +241,6 @@ macro_rules! program { (%%contd, $addr:ident, $mem:ident | $(@$label:ident)? $(.)? FILL $($regs:ident),* $(,)? $(@$label_operand:ident)? $(#$num:expr)? $(=> $($_a:ident$($_b:literal)?)*)?; $($rest:tt)* ) => { - // $( - // #[allow(non_snake_case)] - // let $label = $addr; - // )? - - // This is the last bit of const fn functionality that we use that *isn't* on stable Rust. - // - // Invocations of this macro are always const; it's just that you get worse errors for overlaps - // when _not_ using `nightly-const` and a nightly compiler. - // - // See the `overlap` macro for details. { if $mem[$addr as usize].1 { $crate::overlap!($addr); } } $mem[$addr as usize] = ($crate::word!(FILL $($regs,)* $(#((($label_operand))))? $(#$num)*), true); @@ -262,12 +251,6 @@ macro_rules! program { (%%contd, $addr:ident, $mem:ident | $(@$label:ident)? $(.)? $op:ident $($regs:ident),* $(,)? $(@$label_operand:ident)? $(#$num:expr)? $(=> $($_a:ident$($_b:literal)?)*)?; $($rest:tt)* ) => { - // $( - // #[allow(non_snake_case)] - // let $label = $addr; - // )? - - // See the above comment about const contexts. { if $mem[$addr as usize].1 { $crate::overlap!($addr); } } $mem[$addr as usize] = ($crate::word!($op $($regs,)* $(#((($label_operand as i64) - ($addr as i64) - 1) as $crate::SignedWord))? $(#$num)*), true); @@ -304,46 +287,26 @@ macro_rules! program { }; } -/// This houses the last bit of unstable const fn functionality that we use. -/// -/// We want to tie uses of `panic!(..., ...)` (unstable as of 1.62) to the -/// `nightly-const` feature in _this_ crate and not in the crate where the macro -/// is expanded. -/// -/// This requires us to break out this part of the [`program`] macro into -/// separate macros that are `cfg`ed; hence: this module. +/// We cannot yet format args in `panic!`s; this module exposes a macro that +/// uses the `const_panic` crate as a workaround. #[doc(hidden)] pub mod overlap_error { #[macro_export] #[doc(hidden)] - #[cfg(feature = "nightly-const")] macro_rules! overlap { ($addr:ident) => { - // If we can use `feature(const_format_args)`, just panic normally: $crate::_macro_support::err($addr); }; } - // NOTE: we wrap this in a function so that it isn't reliant on nightly - // features being enabled in the crate of the caller of the macro. + // NOTE: we wrap this in a function so that our dependence on `const_panic` + // doesn't leak into the callers of our macro. #[doc(hidden)] - #[cfg(feature = "nightly-const")] + #[track_caller] pub const fn err(addr: crate::Word) { - panic!("Overlap at {:#4X}!", addr); - } + // in lieu of `panic!("Overlap at {:#4X}!", addr);` - #[macro_export] - #[doc(hidden)] - #[cfg(not(feature = "nightly-const"))] - macro_rules! overlap { - ($addr:ident) => { - // If we can't use nightly features, panic in this weird way that kind of - // hints at what the overlap address is: - let _ = { - const OVERLAP_ERROR_AT_ADDRESS: [(); 0] = []; - let _ = OVERLAP_ERROR_AT_ADDRESS[$addr as usize]; - }; - }; + const_panic::concat_panic!("Overlap at ", {#X}: addr, "!"); } } diff --git a/os/Cargo.toml b/os/Cargo.toml index f69c93c9..ce4d8015 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -49,10 +49,6 @@ path = "tests/trap_tests/mod.rs" [features] default = [] -# Requires nightly; enables some quality of life features in the LC-3 macros -# (better error messages). -nightly-const = ["lc3-isa/nightly-const"] - [package.metadata.docs.rs] # targets = [""] rustdoc-args = ["--cfg", "docs"] From 1b9a910e17935d217eb3148296a9ba0360062dd2 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:49:25 -0500 Subject: [PATCH 06/25] build: drop `misc/serial`, `misc/lc3-tm4c` from core these have effectively already moved to the `tm4c` repo --- Cargo.toml | 2 - misc/lc3-tm4c/.cargo/config | 9 - misc/lc3-tm4c/.gitignore | 2 - misc/lc3-tm4c/Cargo.lock | 364 ------------------------- misc/lc3-tm4c/Cargo.toml | 46 ---- misc/lc3-tm4c/bins/bt-loop.rs | 73 ----- misc/lc3-tm4c/bins/hc05-at.rs | 74 ----- misc/lc3-tm4c/openocd.gdb | 34 --- misc/lc3-tm4c/src/main.rs | 278 ------------------- misc/lc3-tm4c/src/peripherals.rs | 369 ------------------------- misc/lc3-tm4c/src/transport.rs | 147 ---------- misc/lc3-tm4c/src/util/mod.rs | 5 - misc/serial/.gitignore | 1 - misc/serial/Cargo.lock | 452 ------------------------------- misc/serial/Cargo.toml | 12 - misc/serial/src/main.rs | 34 --- 16 files changed, 1902 deletions(-) delete mode 100644 misc/lc3-tm4c/.cargo/config delete mode 100644 misc/lc3-tm4c/.gitignore delete mode 100644 misc/lc3-tm4c/Cargo.lock delete mode 100644 misc/lc3-tm4c/Cargo.toml delete mode 100644 misc/lc3-tm4c/bins/bt-loop.rs delete mode 100644 misc/lc3-tm4c/bins/hc05-at.rs delete mode 100644 misc/lc3-tm4c/openocd.gdb delete mode 100644 misc/lc3-tm4c/src/main.rs delete mode 100644 misc/lc3-tm4c/src/peripherals.rs delete mode 100644 misc/lc3-tm4c/src/transport.rs delete mode 100644 misc/lc3-tm4c/src/util/mod.rs delete mode 100644 misc/serial/.gitignore delete mode 100644 misc/serial/Cargo.lock delete mode 100644 misc/serial/Cargo.toml delete mode 100644 misc/serial/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index b081acef..fb594395 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,6 @@ members = [ "test-infrastructure", "device-support" # TODO: spin off ] -exclude = [ "misc/lc3-tm4c", "misc/serial" ] # TODO: remove - [package] # TODO name = "lc3-utp" diff --git a/misc/lc3-tm4c/.cargo/config b/misc/lc3-tm4c/.cargo/config deleted file mode 100644 index bdab360b..00000000 --- a/misc/lc3-tm4c/.cargo/config +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -runner = "gdb-multiarch -q -x openocd.gdb" - -rustflags = [ - "-C", "link-arg=-Tlink.x", -] - -[build] -target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) diff --git a/misc/lc3-tm4c/.gitignore b/misc/lc3-tm4c/.gitignore deleted file mode 100644 index 53eaa219..00000000 --- a/misc/lc3-tm4c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -**/*.rs.bk diff --git a/misc/lc3-tm4c/Cargo.lock b/misc/lc3-tm4c/Cargo.lock deleted file mode 100644 index 010783a8..00000000 --- a/misc/lc3-tm4c/Cargo.lock +++ /dev/null @@ -1,364 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "aligned" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "as-slice 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "as-slice" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bare-metal" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bytes" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cast" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cortex-m" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cortex-m-rt" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cortex-m-rt-macros 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cortex-m-rt-macros" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cortex-m-semihosting" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "embedded-hal" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "generic-array" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "generic-array" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lc3-baseline-sim" -version = "0.1.0" -dependencies = [ - "lc3-isa 0.1.0", - "lc3-macros 0.1.0", - "lc3-traits 0.1.0", -] - -[[package]] -name = "lc3-isa" -version = "0.1.0" -dependencies = [ - "lc3-macros 0.1.0", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lc3-macros" -version = "0.1.0" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lc3-tm4c" -version = "0.1.0" -dependencies = [ - "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lc3-baseline-sim 0.1.0", - "lc3-isa 0.1.0", - "lc3-traits 0.1.0", - "panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tm4c123x-hal 0.10.0 (git+https://github.com/thejpster/tm4c-hal/)", -] - -[[package]] -name = "lc3-traits" -version = "0.1.0" -dependencies = [ - "lc3-isa 0.1.0", - "lc3-macros 0.1.0", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "nb" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "panic-semihosting" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "proc-macro2" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "r0" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stable_deref_trait" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "syn" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tm4c-hal" -version = "0.3.0" -source = "git+https://github.com/thejpster/tm4c-hal/#951e4613c287ab447af924ab33c198b547001b59" -dependencies = [ - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tm4c123x" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tm4c123x-hal" -version = "0.10.0" -source = "git+https://github.com/thejpster/tm4c-hal/#951e4613c287ab447af924ab33c198b547001b59" -dependencies = [ - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tm4c-hal 0.3.0 (git+https://github.com/thejpster/tm4c-hal/)", - "tm4c123x 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "typenum" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "vcell" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "volatile-register" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum aligned 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94" -"checksum as-slice 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "be6b7e95ac49d753f19cab5a825dea99a1149a04e4e3230b33ae16e120954c04" -"checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" -"checksum bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10004c15deb332055f7a4a208190aed362cf9a7c2f6ab70a305fba50e1105f38" -"checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum cortex-m 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "145da2fc379bbd378ed425e75e1748214add9bbd800d4d5b77abb54ca423dbca" -"checksum cortex-m-rt 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "33a716cd7d8627fae3892c2eede9249e50d2d79aedfb43ca28dad9a2b23876d9" -"checksum cortex-m-rt-macros 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "72b1073338d1e691b3b7aaf6bd61993e589ececce9242a02dfa5453e1b98918d" -"checksum cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "113ef0ecffee2b62b58f9380f4469099b30e9f9cbee2804771b4203ba1762cfa" -"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" -"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -"checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" -"checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c" -"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" -"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" -"checksum tm4c-hal 0.3.0 (git+https://github.com/thejpster/tm4c-hal/)" = "" -"checksum tm4c123x 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "097e7f60cc69f25d9bd189509c682b36057fd5f1519e6485b107aecca15c3e3f" -"checksum tm4c123x-hal 0.10.0 (git+https://github.com/thejpster/tm4c-hal/)" = "" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/misc/lc3-tm4c/Cargo.toml b/misc/lc3-tm4c/Cargo.toml deleted file mode 100644 index 3fa499b3..00000000 --- a/misc/lc3-tm4c/Cargo.toml +++ /dev/null @@ -1,46 +0,0 @@ -[package] -name = "lc3-tm4c" -version = "0.1.0" -authors = ["UT UTP "] -edition = "2018" -publish = false -default-run = "lc3-tm4c" - -# TODO: CI -# TODO: README -# TODO: CHANGELOG -# TODO: all the other keys -# TODO: lints and attributes for this crate -# (this is very much just a proof of concept! not a prototype!!) -# We'll do all these things when this graduates to being in its own repo - -[dependencies] -bytes = { version = "0.5.3", default-features = false } -static_assertions = "1.0.0" - -cortex-m = "0.6.0" -cortex-m-rt = "0.6.10" -cortex-m-semihosting = "0.3.3" -# panic-halt = "0.2.0" -panic-semihosting = "0.5.3" -# tm4c123x = "0.9.0" -# tm4c123x-hal = { version = "0.10.0", features = ["rt"] } -tm4c123x-hal = { git = "https://github.com/thejpster/tm4c-hal/", features = ["rt"] } - -lc3-baseline-sim = { path = "../../baseline-sim", version = "0.1.0" } -lc3-isa = { path = "../../isa", version = "0.1.0" } -lc3-traits = { path = "../../traits", version = "0.1.0" } - -[[bin]] -name = "hc05-at" -path = "bins/hc05-at.rs" - -[[bin]] -name = "bt-loop" -path = "bins/bt-loop.rs" - - -[profile.release] -codegen-units = 1 # better optimizations -debug = true # symbols are nice and they don't increase the size on Flash -lto = true # better optimizations diff --git a/misc/lc3-tm4c/bins/bt-loop.rs b/misc/lc3-tm4c/bins/bt-loop.rs deleted file mode 100644 index ec936513..00000000 --- a/misc/lc3-tm4c/bins/bt-loop.rs +++ /dev/null @@ -1,73 +0,0 @@ -#![cfg_attr(not(test), no_std)] -#![no_main] - -extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger -extern crate tm4c123x_hal as hal; - -use core::fmt::Write; -use cortex_m_rt::entry; -use hal::prelude::*; -use cortex_m::asm; - -#[entry] -fn main() -> ! { - let p = hal::Peripherals::take().unwrap(); - - let mut sc = p.SYSCTL.constrain(); - sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main( - hal::sysctl::CrystalFrequency::_16mhz, - hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz), - ); - let clocks = sc.clock_setup.freeze(); - - let mut porta = p.GPIO_PORTA.split(&sc.power_control); - let mut portb = p.GPIO_PORTB.split(&sc.power_control); - - let mut u0 = p.UART0; - let mut u1 = p.UART1; - - // Activate UART - let mut uart = hal::serial::Serial::uart0( - u0, - porta - .pa1 - .into_af_push_pull::(&mut porta.control), - porta - .pa0 - .into_af_push_pull::(&mut porta.control), - (), - (), - 1_500_000_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - &clocks, - &sc.power_control, - ); - - let mut bt = hal::serial::Serial::uart1( - u1, - portb - .pb1 - .into_af_push_pull::(&mut portb.control), - portb - .pb0 - .into_af_push_pull::(&mut portb.control), - (), - (), - // 1_382_400_u32.bps(), - // 115_200_u32.bps(), - 38_400_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - &clocks, - &sc.power_control, - ); - - let mut counter = 0u32; - - writeln!(uart, "HELLO!"); - write!(bt, "YO\r\n"); - - loop { - if let Ok(w) = uart.read() { bt.write(w); } - if let Ok(w) = bt.read() { uart.write(w); } - } -} diff --git a/misc/lc3-tm4c/bins/hc05-at.rs b/misc/lc3-tm4c/bins/hc05-at.rs deleted file mode 100644 index e54f4274..00000000 --- a/misc/lc3-tm4c/bins/hc05-at.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![cfg_attr(not(test), no_std)] -#![no_main] - -extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger -extern crate tm4c123x_hal as hal; - -use core::fmt::Write; -use cortex_m_rt::entry; -use hal::prelude::*; -use cortex_m::asm; - -#[entry] -fn main() -> ! { - let p = hal::Peripherals::take().unwrap(); - - let mut sc = p.SYSCTL.constrain(); - sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main( - hal::sysctl::CrystalFrequency::_16mhz, - hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz), - ); - let clocks = sc.clock_setup.freeze(); - - let mut porta = p.GPIO_PORTA.split(&sc.power_control); - let mut portb = p.GPIO_PORTB.split(&sc.power_control); - - let mut u0 = p.UART0; - let mut u1 = p.UART1; - - // Activate UART - let mut uart = hal::serial::Serial::uart0( - u0, - porta - .pa1 - .into_af_push_pull::(&mut porta.control), - porta - .pa0 - .into_af_push_pull::(&mut porta.control), - (), - (), - 1_500_000_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - &clocks, - &sc.power_control, - ); - - let mut hc = hal::serial::Serial::uart1( - u1, - portb - .pb1 - .into_af_push_pull::(&mut portb.control), - portb - .pb0 - .into_af_push_pull::(&mut portb.control), - (), - (), - 38400_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - &clocks, - &sc.power_control, - ); - - let mut counter = 0u32; - - writeln!(uart, "HELLO!"); - write!(hc, "AT\r\n"); - // write!(hc, "AT+UART=1382400,0,0\r\n"); - // write!(hc, "AT+UART=115200,0,0\r\n"); - write!(hc, "AT+UART=38400,0,0\r\n"); - - loop { - if let Ok(w) = uart.read() { hc.write(w); } - if let Ok(w) = hc.read() { uart.write(w); } - } -} diff --git a/misc/lc3-tm4c/openocd.gdb b/misc/lc3-tm4c/openocd.gdb deleted file mode 100644 index 577cf610..00000000 --- a/misc/lc3-tm4c/openocd.gdb +++ /dev/null @@ -1,34 +0,0 @@ -# target extended-remote :3333 - -target remote | openocd -c "source [find board/ek-tm4c123gxl.cfg]" -c "gdb_port pipe; log_output target/openocd.log" - -# print demangled symbols -set print asm-demangle on - -# detect unhandled exceptions, hard faults and panics -break DefaultHandler -break UserHardFault -break rust_begin_unwind - -# *try* to stop at the user entry point (it might be gone due to inlining) -break main - -monitor arm semihosting enable - -# # send captured ITM to the file itm.fifo -# # (the microcontroller SWO pin must be connected to the programmer SWO pin) -# # 8000000 must match the core clock frequency -# monitor tpiu config internal itm.txt uart off 8000000 - -# # OR: make the microcontroller SWO pin output compatible with UART (8N1) -# # 8000000 must match the core clock frequency -# # 2000000 is the frequency of the SWO pin -# monitor tpiu config external uart off 8000000 2000000 - -# # enable ITM port 0 -# monitor itm port 0 on - -load - -# start the process but immediately halt the processor -stepi diff --git a/misc/lc3-tm4c/src/main.rs b/misc/lc3-tm4c/src/main.rs deleted file mode 100644 index 89982988..00000000 --- a/misc/lc3-tm4c/src/main.rs +++ /dev/null @@ -1,278 +0,0 @@ -#![cfg_attr(not(test), no_std)] -// #![no_std] -#![no_main] - -extern crate static_assertions as sa; - -// pick a panicking behavior -// extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics -// extern crate panic_abort; // requires nightly -// extern crate panic_itm; // logs messages over ITM; requires ITM support -extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger -extern crate tm4c123x_hal as hal; - -mod memory; -mod peripherals; -// mod transport; -// mod util; - -// use bytes::{Buf, BufMut}; - - -use memory::Tm4cMemory; -use peripherals::{Tm4cGpio, Tm4cAdc, Tm4cPwm, Tm4cTimers, Tm4cClock, Tm4cInput, Tm4cOutput}; - -use core::fmt::Write; -use cortex_m_rt::entry; -use hal::prelude::*; -use cortex_m::asm; - -use lc3_traits::control::rpc::SimpleEventFutureSharedState; - -// static SHARED_STATE: SimpleEventFutureSharedState = SimpleEventFutureSharedState::new(); - -use lc3_baseline_sim::interp::{Interpreter, InstructionInterpreter, InterpreterBuilder, PeripheralInterruptFlags}; -use lc3_baseline_sim::sim::Simulator; - -use lc3_traits::peripherals::PeripheralSet; -use lc3_traits::control::Control; - -#[entry] -fn main() -> ! { - type Interp<'a> = Interpreter<'a, - Tm4cMemory, - PeripheralSet<'a, - Tm4cGpio<'a>, - Tm4cAdc, - Tm4cPwm, - Tm4cTimers<'a>, - Tm4cClock, - Tm4cInput<'a>, - Tm4cOutput<'a>, - > - >; - - let flags: PeripheralInterruptFlags = PeripheralInterruptFlags::new(); - let state: SimpleEventFutureSharedState = SimpleEventFutureSharedState::new(); - - let mut interp: Interp = InterpreterBuilder::new() - .with_defaults() - .build(); - - interp.reset(); - interp.init(&flags); - - let mut sim = Simulator::new_with_state(interp, &state); - sim.reset(); - - // loop { - // // your code goes here - // sim.step(); - // } - - let p = hal::Peripherals::take().unwrap(); - - let mut sc = p.SYSCTL.constrain(); - sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main( - hal::sysctl::CrystalFrequency::_16mhz, - hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz), - ); - let clocks = sc.clock_setup.freeze(); - - let mut porta = p.GPIO_PORTA.split(&sc.power_control); - let mut portb = p.GPIO_PORTB.split(&sc.power_control); - - let mut u0 = p.UART0; - let mut u1 = p.UART1; - - // u0.lcrh.modify(|_, w| w.eps().bit(true)); - - // Activate UART - let mut uart = hal::serial::Serial::uart0( - u0, - porta - .pa1 - .into_af_push_pull::(&mut porta.control), - porta - .pa0 - .into_af_push_pull::(&mut porta.control), - (), - (), - // 115200_u32.bps(), - // 3_686_400_u32.bps(), - // 460_800_u32.bps(), - // 1_000_000_u32.bps(), - // 921_600_u32.bps(), - // 1_500_000_u32.bps(), - 1_500_000_u32.bps(), - // 115200_u32.bps(), - // 2_300_000_u32.bps(), - // 2_300_000_u32.bps(), - // 115200.bps(), - // 200_000_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - // hal::serial::NewlineMode::Binary, - &clocks, - &sc.power_control, - ); - - let mut bt = hal::serial::Serial::uart1( - u1, - portb - .pb1 - .into_af_push_pull::(&mut portb.control), - portb - .pb0 - .into_af_push_pull::(&mut portb.control), - (), - (), - // 115200_u32.bps(), - // 3_686_400_u32.bps(), - // 460_800_u32.bps(), - // 1_000_000_u32.bps(), - // 921_600_u32.bps(), - // 1_500_000_u32.bps(), - // 9600_u32.bps(), - // 2_300_000_u32.bps(), - // 2_300_000_u32.bps(), - // 115200.bps(), - // 200_000_u32.bps(), - // 38400_u32.bps(), - // 1_382_400_u32.bps(), - // 115_200_u32.bps(), - 38_400_u32.bps(), - hal::serial::NewlineMode::SwapLFtoCRLF, - // hal::serial::NewlineMode::Binary, - &clocks, - &sc.power_control, - ); - - let mut counter = 0u16; - - // for i in 0..core::u16::MAX { - // for i in 0..0xFE00u16 { - // sim.write_word(i, counter as u16); - // // writeln!(uart, "Hello, world! counter={}", counter).unwrap(); - // // writeln!(uart, "{:#?}", sim.step()); - // writeln!(uart, "{:#04X} -> {:#04X}", i, sim.read_word(i)); - // // sim.write_word(i, counter as u16); - // counter = counter.wrapping_add(1); - // } - - // let mut buf: [u8; 1] = [0]; - // use core::io::Read; - - // loop { - // if let Ok(1) = uart.read(&mut buf) { - // write!(bt, buf[0]); - // } - - // if let Ok(1) = bt.read(&mut buf) { - // write!(uart, buf[0]); - // } - // } - - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - writeln!(uart, "HELLO!"); - - // write!(bt, "AT\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - // write!(bt, "AT+NAME\r\n"); - - // loop { - // if let Ok(w) = uart.read() { bt.write(w); } - // if let Ok(w) = bt.read() { uart.write(w); } - // } - - // loop { - // writeln!(uart, "Hello, world! counter={}", counter).unwrap(); - // writeln!(bt, "Hello, world! counter={}", counter).unwrap(); - // // writeln!(uart, "{:#?}", sim.step()); - // counter = counter.wrapping_add(1); - // } - - for i in 0..0xFE00u16 { - sim.write_word(i, counter as u16); - writeln!(uart, "{:#04X} -> {:#04X}", i, sim.read_word(i)); - // writeln!(bt, "{:#04X} -> {:#04X}", i, sim.read_word(i)); - counter = counter.wrapping_add(1); - } - - loop { - // writeln!(uart, "Hello, world! counter={}", counter).unwrap(); - // writeln!(uart, "c={}", counter).unwrap(); - // if counter == 0 { writeln!(bt, "Hello, world! counter={}", counter).unwrap(); } - // if counter % 10000 == 0 { writeln!(bt, "Hello, world! counter={}", counter).unwrap(); } - // if counter % 20 == 0 { writeln!(bt, "c={}", counter).unwrap(); } - writeln!(bt, "c={}", counter).unwrap(); - // writeln!(uart, "{:#?}", sim.step()); - counter = counter.wrapping_add(1); - } -} - -// #![no_std] -// #![no_main] - -// extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics -// extern crate tm4c123x_hal as hal; - -// use core::fmt::Write; -// use cortex_m_rt::entry; -// use hal::prelude::*; - -// #[entry] -// fn main() -> ! { -// let p = hal::Peripherals::take().unwrap(); - -// let mut sc = p.SYSCTL.constrain(); -// sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main( -// hal::sysctl::CrystalFrequency::_16mhz, -// hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz), -// ); -// let clocks = sc.clock_setup.freeze(); - -// let mut porta = p.GPIO_PORTA.split(&sc.power_control); - -// // Activate UART -// let mut uart = hal::serial::Serial::uart0( -// p.UART0, -// porta -// .pa1 -// .into_af_push_pull::(&mut porta.control), -// porta -// .pa0 -// .into_af_push_pull::(&mut porta.control), -// (), -// (), -// 115200_u32.bps(), -// hal::serial::NewlineMode::SwapLFtoCRLF, -// &clocks, -// &sc.power_control, -// ); - -// let mut counter = 0u32; -// loop { -// writeln!(uart, "Hello, world! counter={}", counter).unwrap(); -// counter = counter.wrapping_add(1); -// } -// } diff --git a/misc/lc3-tm4c/src/peripherals.rs b/misc/lc3-tm4c/src/peripherals.rs deleted file mode 100644 index 3fb3f04c..00000000 --- a/misc/lc3-tm4c/src/peripherals.rs +++ /dev/null @@ -1,369 +0,0 @@ -//! Peripheral Trait impls for the LC-3. (TODO!) -//! -//! ## Mappings -//! Gonna do this for pins for now: -//! -//! ``` -//! [For reference] | [Assignments] | -//! | | -//! J1 J3 J2 J4 | J1 J3 J2 J4 | -//! ┏━━━━━┯━━━━━┓ ┏━━━━━┯━━━━━┓ | ┏━━━━━┯━━━━━┓ ┏━━━━━┯━━━━━┓ | -//! ┃ 3.3 │ 5.0 ┃ ┃ PF2 │ GND ┃ | ┃ 3.3 │ 5.0 ┃ ┃ P0 │ GND ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PB5 │ GND ┃ ┃ PF3 │ PB2 ┃ | ┃ G5 │ GND ┃ ┃ P1 │ G2 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PB0 │ PD0 ┃ ┃ PB3 │ PE0 ┃ | ┃ G0 │ XXX ┃ ┃ G3 │ A0 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PB1 │ PD1 ┃ ┃ PC4 │ PF0 ┃ | ┃ G1 │ XXX ┃ ┃ PC4 │ Px ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PE4 │ PD2 ┃ ┃ PC5 │ RST ┃ | ┃ A4 │ PD2 ┃ ┃ PC5 │ RST ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PE5 │ PD3 ┃ ┃ PC6 │ PB7 ┃ | ┃ A5 │ PD3 ┃ ┃ PC6 │ G7 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PB4 │ PE1 ┃ ┃ PC7 │ PB6 ┃ | ┃ G4 │ A1 ┃ ┃ PC7 │ G6 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PA5 │ PE2 ┃ ┃ PD6 │ PA4 ┃ | ┃ PA5 │ A2 ┃ ┃ PD6 │ PA4 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PA6 │ PE3 ┃ ┃ PD7 │ PA3 ┃ | ┃ PA6 │ A3 ┃ ┃ PD7 │ PA3 ┃ | -//! ┠─────┼─────┨ ┠─────┼─────┨ | ┠─────┼─────┨ ┠─────┼─────┨ | -//! ┃ PA7 │ PF1 ┃ ┃ PF4 │ PA2 ┃ | ┃ PA7 │ Px ┃ ┃ PF4 │ PA2 ┃ | -//! ┗━━━━━┷━━━━━┛ ┗━━━━━┷━━━━━┛ | ┗━━━━━┷━━━━━┛ ┗━━━━━┷━━━━━┛ | -//! ┏━━━━━┓ ┏━━━━━┓ | ┏━━━━━┓ ┏━━━━━┓ | -//! ┃ GND ┃ ┃ GND ┃ | ┃ GND ┃ ┃ GND ┃ | -//! ┠─────┨ ┠─────┨ | ┠─────┨ ┠─────┨ | -//! ┃ GND ┃ ┃ GND ┃ | ┃ GND ┃ ┃ GND ┃ | -//! ┠─────┨ ┠─────┨ | ┠─────┨ ┠─────┨ | -//! ┃ 5.0 ┃ ┃ 3.3 ┃ | ┃ 5.0 ┃ ┃ 3.3 ┃ | -//! ┗━━━━━┛ ┗━━━━━┛ | ┗━━━━━┛ ┗━━━━━┛ | -//! ┏━━━━━┯━━━━━┓ ┏━━━━━┓ | ┏━━━━━┯━━━━━┓ ┏━━━━━┓ | -//! ┃ PD0<->PB6 ┃ ┃D7^VD┃ | ┃ PD0<->PB6 ┃ ┃D7^VD┃ | -//! ┠─────┼─────┨ ┗━━━━━┛ | ┠─────┼─────┨ ┗━━━━━┛ | -//! ┃ PD1<->PB7 ┃ | ┃ PD1<->PB7 ┃ | -//! ┗━━━━━┷━━━━━┛ | ┗━━━━━┷━━━━━┛ | -//! | | -//!-------------------------------------|--------------------------------------| -//!``` -//! -//! For GPIO: -//! - We want a full port so that `write_all` is easier. -//! + Port A is out because A0 and A1 are UART. -//! + Port C is out because C0 - C3 are used for debugging. -//! + Port E and F are out because they don't have 8 exposed pins. -//! + Port D's PD4 and PD5 are connected to USB and not connected to pins. -//! + This leaves Port B. We'll be sure to disable PD0 and PD1 so board -//! with the shunt resistors still work. -//! - Another way to go about this would be to assign pin mappings based on the -//! physical location of pins (i.e. take all of J1 to be GPIO). -//! + For now, we won't do this. -//! - Another consideration is that it would be nice for the two buttons (PF0 -//! and PF4) to be mapped to GPIO pins so users can use the buttons as an -//! input source. -//! + Whether this is more desirable than having a unified port is a -//! question for another time. -//! -//! For ADC: -//! - We need 6 pins. -//! - Our options are all of Port E (6 pins), 2 pins in Port B, and PD0 to PD3. -//! - Again, we'll opt for matching the numbering (Port E). -//! -//! For PWM: -//! - We need 2 pins. -//! - We've got lots of options (Ports B, C, D, F). -//! - Ultimately, I think it makes sense to go with Port F's LED pins so that -//! users can use them. -//! - We'll reserve Red for indicating hard faults so PF2 and PF3 it is! -//! + If we choose to have 4 PWM pins in the future we can do PF0 to PF3. -//! -//! This configuration leaves I2C, SPI, UART, QEI, and USB pins unused such that -//! those peripherals can still be used, which is a nice bonus. - -use core::cell::Cell; -use core::sync::atomic::{AtomicBool, Ordering}; - -use cortex_m::asm; - -use lc3_isa::{Word, Addr}; - -use lc3_traits::peripherals::{Gpio, Adc, Pwm, Timers, Clock, Input, Output}; -use lc3_traits::peripherals::gpio::{GpioPin, GpioState, GpioPinArr, GpioReadError, GpioWriteError, GpioMiscError}; - - -pub struct Tm4cGpio<'a> { - flags: Option<&'a GpioPinArr>, -} - -impl<'a> Gpio<'a> for Tm4cGpio<'a> { - fn set_state(&mut self, pin: GpioPin, state: GpioState) -> Result<(), GpioMiscError> { - Err(GpioMiscError) - } - - fn get_state(&self, pin: GpioPin) -> GpioState { - GpioState::Disabled - } - - fn read(&self, pin: GpioPin) -> Result { - Err(GpioReadError((pin, GpioState::Disabled))) - } - - fn write(&mut self, pin: GpioPin, bit: bool) -> Result<(), GpioWriteError> { - Err(GpioWriteError((pin, GpioState::Disabled))) - } - - fn register_interrupt_flags(&mut self, flags: &'a GpioPinArr) { - self.flags = Some(flags); - } - - fn interrupt_occurred(&self, pin: GpioPin) -> bool { - self.flags.unwrap()[pin].load(Ordering::SeqCst) - } - - fn reset_interrupt_flag(&mut self, pin: GpioPin) { - self.flags.unwrap()[pin].store(false, Ordering::SeqCst) - } - - fn interrupts_enabled(&self, pin: GpioPin) -> bool { - false - } -} - -impl<'a> Default for Tm4cGpio<'a> { - fn default() -> Self { - Self { - flags: None, - } - } -} - -use lc3_traits::peripherals::adc::{AdcPin, AdcState, AdcReadError/* , AdcPinArr */}; - -pub struct Tm4cAdc { - -} - -impl Adc for Tm4cAdc { - fn set_state(&mut self, pin: AdcPin, state: AdcState) -> Result<(), ()> { - Err(()) - } - - fn get_state(&self, pin: AdcPin) -> AdcState { - AdcState::Disabled - } - - fn read(&self, pin: AdcPin) -> Result { - Err(AdcReadError((pin, AdcState::Disabled))) - } -} - -impl Default for Tm4cAdc { - fn default() -> Self { Self {} } -} - -use lc3_traits::peripherals::pwm::{PwmState, PwmPin, PwmSetPeriodError, PwmSetDutyError, PwmPinArr}; - -pub struct Tm4cPwm { - -} - -impl Pwm for Tm4cPwm { - fn set_state(&mut self, pin: PwmPin, state: PwmState) -> Result<(), PwmSetPeriodError> { - Err(PwmSetPeriodError(pin)) - } - - fn get_state(&self, pin: PwmPin) -> PwmState { - PwmState::Disabled - } - - fn get_pin(&self, pin: PwmPin) -> bool { - false - } - - fn set_duty_cycle(&mut self, pin: PwmPin, duty: u8) -> Result<(), PwmSetDutyError> { - Err(PwmSetDutyError(pin)) - } - - fn get_duty_cycle(&self, pin: PwmPin) -> u8 { - 0 - } -} - -impl Default for Tm4cPwm { - fn default() -> Self { Self {} } -} - -use lc3_traits::peripherals::timers::{TimerId, TimerMiscError, TimerState, TimerArr}; - -pub struct Tm4cTimers<'a> { - flags: Option<&'a TimerArr>, -} - -impl<'a> Timers<'a> for Tm4cTimers<'a> { - fn set_state(&mut self, timer: TimerId, state: TimerState) -> Result<(), TimerMiscError> { - Err(TimerMiscError) - } - - fn get_state(&self, timer: TimerId) -> TimerState { - TimerState::Disabled - } - - fn set_period(&mut self, timer: TimerId, ms: Word) -> Result<(), TimerMiscError> { - Err(TimerMiscError) - } - - fn get_period(&self, timer: TimerId) -> Word { - 0 - } - - fn register_interrupt_flags(&mut self, flags: &'a TimerArr) { - self.flags = Some(flags) - } - - fn interrupt_occurred(&self, timer: TimerId) -> bool { - self.flags.unwrap()[timer].load(Ordering::SeqCst) - } - - fn reset_interrupt_flag(&mut self, timer: TimerId) { - self.flags.unwrap()[timer].store(false, Ordering::SeqCst) - } - - fn interrupts_enabled(&self, tiner: TimerId) -> bool { - false - } -} - -impl<'a> Default for Tm4cTimers<'a> { - fn default() -> Self { - Self { - flags: None, - } - } -} - -pub struct Tm4cClock { - -} - -impl Clock for Tm4cClock { - fn get_milliseconds(&self) -> Word { - 0 - } - - fn set_milliseconds(&mut self, ms: Word) { - asm::nop(); - } -} - -impl Default for Tm4cClock { - fn default() -> Self { Self { } } -} - -use lc3_traits::peripherals::input::InputError; - -pub struct Tm4cInput<'a> { - flag: Option<&'a AtomicBool>, - interrupts_enabled: bool, - current_char: Cell>, -} - -impl<'a> Tm4cInput<'a> { - fn fetch(&self) { - let new_data: Option = None; // TODO! - - if let Some(c) = new_data { - self.current_char.replace(Some(c)); - - self.flag.unwrap().store(true, Ordering::SeqCst); - } - } -} - -impl<'a> Input<'a> for Tm4cInput<'a> { - fn register_interrupt_flag(&mut self, flag: &'a AtomicBool) { - self.flag = Some(flag) - } - - fn interrupt_occurred(&self) -> bool { - self.current_data_unread() - } - - fn set_interrupt_enable_bit(&mut self, bit: bool) { - self.interrupts_enabled = bit - } - - fn interrupts_enabled(&self) -> bool { - self.interrupts_enabled - } - - fn read_data(&self) -> Result { - self.fetch(); - - self.flag.unwrap().store(false, Ordering::SeqCst); - self.current_char.get().ok_or(InputError) - } - - fn current_data_unread(&self) -> bool { - self.fetch(); - - self.flag.unwrap().load(Ordering::SeqCst) - } -} - -impl<'a> Default for Tm4cInput<'a> { - fn default() -> Self { - Self { - flag: None, - interrupts_enabled: false, - current_char: Cell::new(None) - } - } -} - -use lc3_traits::peripherals::output::OutputError; - -pub struct Tm4cOutput<'a> { - // tx: - flag: Option<&'a AtomicBool>, - interrupts_enabled: bool, -} - -impl<'a> Output<'a> for Tm4cOutput<'a> { - fn register_interrupt_flag(&mut self, flag: &'a AtomicBool) { - self.flag = Some(flag); - - flag.store(true, Ordering::SeqCst) - } - - fn interrupt_occurred(&self) -> bool { - self.flag.unwrap().load(Ordering::SeqCst) - } - - fn set_interrupt_enable_bit(&mut self, bit: bool) { - self.interrupts_enabled = bit; - } - - fn interrupts_enabled(&self) -> bool { - self.interrupts_enabled - } - - fn write_data(&mut self, c: u8) -> Result<(), OutputError> { - self.flag.unwrap().store(false, Ordering::SeqCst); - - // TODO: write the character! - - self.flag.unwrap().store(true, Ordering::SeqCst); - - Ok(()) - } - - fn current_data_written(&self) -> bool { - self.flag.unwrap().load(Ordering::SeqCst) - } -} - -impl<'a> Default for Tm4cOutput<'a> { - fn default() -> Self { - Self { - flag: None, - interrupts_enabled: false, - } - } -} diff --git a/misc/lc3-tm4c/src/transport.rs b/misc/lc3-tm4c/src/transport.rs deleted file mode 100644 index 85767ede..00000000 --- a/misc/lc3-tm4c/src/transport.rs +++ /dev/null @@ -1,147 +0,0 @@ -//! TODO! - -enum State { - WaitingForMessageType, - ControlMessageLengthUnknown, - ConsoleInputLengthUnknown, - ReadingControlMessage(u16), - ReadingConsoleInput(u16), -} - -static RX: Mutex>> = ..; -static RX_STATE: Mutex> = Mutex::new(RefCell::new(State::WaitingForMessageType)); -static RX_BUFFER: Mutex> = Mutex::new(RefCell::new(Fifo::::new())); - -static CONTROL_MESSAGE_PENDING: Mutex>> = Mutex::new(Cell::new(None)); // TODO: should this be more than one element big? -static CONTROL_MESSAGE_FLAG: AtomicBool = AtomicBool::new(false); - -const CONTROL_MESSAGE_SLUG: u8 = 0b1000_0000; -const CONSOLE_INPUT_SLUG: u8 = 0b1100_0000; - -// TODO: invoked on any new data or FIFO half full? -// any new data for now -#[interrupt] -fn uart_rx_handler() { - interrupt_free(|cs| { - let rx_guard = RX.lock(cs); - let rx = rx_guard.borrow_mut(); - - let rx_state_guard = RX_STATE.lock(cs); - let rx_state = rx_state_guard.borrow_mut(); - - let rx_buf_guard = RX_BUFFER.lock(cs); - let rx_buf = rx_state_guard.borrow_mut(); - - use State::*; - - while let Ok(c) = rx.read() { - rx_state = match (rx_state, c) { - (WaitingForMessageType, CONTROL_MESSAGE_SLUG) => ControlMessageLengthUnknown, - (WaitingForMessageType, CONSOLE_INPUT_SLUG) => ConsoleInputLengthUnknown, - (WaitingForMessageType, _) => panic!("unknown message type"), // TODO: how to actually handle? - - (ConsoleInputLengthUnknown, c) | (ControlMessageLengthUnknown, c) => { - rx_buf.push(c).unwrap(); // TODO: don't unwrap here... - if let Some(len) = prost::decode_length_delimiter(&mut rx_buf) { // TODO: will this behave correctly with a ref or do we need to extract and call decode_varint? - assert!(len <= Fifo::CAPACITY); - - match rx_state { - ConsoleInputLengthUnknown => ReadingConsoleInput(len), - ControlMessageLengthUnknown => ReadingControlMessage(len), - _ => unreachable!(), - } - } else { - rx_state // Keep reading bytes... - } - }, - - (ReadingConsoleInput(1), c) => { - rx_buf.push(c).unwrap(); // TODO: don't unwrap... - - // TODO! actually use the input by feeding it to the input peripheral! - }, - - (ReadingControlMessage(1), c) => { - rx_buf.push(c).unwrap(); // TODO: don't unwrap... - - let m = ControlMessage::decode(&mut rx_buf).unwrap(); - assert!(rx_buf.length() == 0); - - let cm = CONTROL_MESSAGE_PENDING.lock(cs); - assert_eq!(None, cm.replace(Some(m))); - - assert_eq!(CONTROL_MESSAGE_FLAG.load(Ordering::SeqCst), false); - CONTROL_MESSAGE_FLAG.store(true, Ordering::SeqCst); - }, - } - } - - // rx_state = match rx_state { - // WaitingForMessageType => { - // let ty: u8 = 0; - // rx.read(&mut ty).expect("at least one new character..."); - - // match ty { - // CONTROL_MESSAGE_SLUG => - // } - // } - // } - }) - - // TODO: acknowledge interrupt? -} - -struct UartTransport { - tx: Tx<_> // TODO -} - -impl TransportLayer for UartTransport { - fn get_message(&mut self) -> Option { - if CONTROL_MESSAGE_FLAG.load(Ordering::SeqCst) { - let cm = CONTROL_MESSAGE_PENDING.lock(); - let m = cm.take(); - - // assert!(m.is_some()); // This invariant should be maintained, but w/e. - m - } else { - None - } - } - - fn send_message(&mut self, message: ControlMessage) -> Result<(), ()> { - let m_len = message.encoded_len(); - let len_len = prost::length_delimiter_len(len); - - let len = m_len + len_len; - assert!(len <= TX_BUF_CAPACITY); - - const TX_BUF_CAPACITY: usize = 256; // TODO: again, compile time checks, etc. - let mut buf: [u8; TX_BUF_CAPACITY] = [0; TX_BUF_CAPACITY]; - - message.encode_length_delimited(&mut buf).unwrap(); // TODO: don't unwrap... - - // nb::block!(tx.) - // TODO: maybe use DMA instead of using a blocking write here.. - tx.write(CONTROL_MESSAGE_SLUG); - tx.write_all(buf[0..len]); - } -} - -fn main() { - let mut sim = ; - let mut control_client: Client = ; // got to create the UART pair, split it, give the Tx to a UartTransport, and then give that UartTransport to a Client. - - // Actually we need shared access to a Tx since the Output peripheral will need access to it too. - // So I guess UartTransport holds no state and we'll need more Mutex>s! - // (TODO) - - loop { - // Do simulator things, etc, etc. - - // if CONTROL_MESSAGE_FLAG.load(Ordering::SeqCst) { - // let cm - // } - - control_client.step(&mut sim); - } -} diff --git a/misc/lc3-tm4c/src/util/mod.rs b/misc/lc3-tm4c/src/util/mod.rs deleted file mode 100644 index 7949d566..00000000 --- a/misc/lc3-tm4c/src/util/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! Miscellaneous helper things. (TODO) - -mod fifo; - -pub use fifo::Fifo; diff --git a/misc/serial/.gitignore b/misc/serial/.gitignore deleted file mode 100644 index eb5a316c..00000000 --- a/misc/serial/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/misc/serial/Cargo.lock b/misc/serial/Cargo.lock deleted file mode 100644 index d0d38a2c..00000000 --- a/misc/serial/Cargo.lock +++ /dev/null @@ -1,452 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "CoreFoundation-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0e9889e6db118d49d88d84728d0e964d973a5680befb5f85f55141beea5c20b" -dependencies = [ - "libc", - "mach 0.1.2", -] - -[[package]] -name = "IOKit-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99696c398cbaf669d2368076bdb3d627fb0ce51a26899d7c61228c5c0af3bf4a" -dependencies = [ - "CoreFoundation-sys", - "libc", - "mach 0.1.2", -] - -[[package]] -name = "aho-corasick" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" -dependencies = [ - "memchr", -] - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "bytes" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10004c15deb332055f7a4a208190aed362cf9a7c2f6ab70a305fba50e1105f38" - -[[package]] -name = "cc" -version = "1.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" - -[[package]] -name = "libudev" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea626d3bdf40a1c5aee3bcd4f40826970cae8d80a8fec934c82a63840094dcfe" -dependencies = [ - "libc", - "libudev-sys", -] - -[[package]] -name = "libudev-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" -dependencies = [ - "libc", - "pkg-config", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "mach" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9" -dependencies = [ - "libc", -] - -[[package]] -name = "mach" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1" -dependencies = [ - "libc", -] - -[[package]] -name = "memchr" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" - -[[package]] -name = "mio" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" -dependencies = [ - "cfg-if", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.1", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio-named-pipes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" -dependencies = [ - "log", - "mio", - "miow 0.3.3", - "winapi 0.3.8", -] - -[[package]] -name = "mio-serial" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2ac176102252559749d8cc1e3f21a4c611b1c94d6c7247895f004460f46d2a" -dependencies = [ - "mio", - "mio-named-pipes", - "nix", - "serialport", - "winapi 0.3.8", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] -name = "miow" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" -dependencies = [ - "socket2", - "winapi 0.3.8", -] - -[[package]] -name = "net2" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -dependencies = [ - "cfg-if", - "libc", - "winapi 0.3.8", -] - -[[package]] -name = "nix" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "void", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" - -[[package]] -name = "pkg-config" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" - -[[package]] -name = "proc-macro2" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" - -[[package]] -name = "regex" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", - "thread_local", -] - -[[package]] -name = "regex-syntax" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" - -[[package]] -name = "serial" -version = "0.1.0" -dependencies = [ - "tokio", - "tokio-serial", -] - -[[package]] -name = "serialport" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8d3ecaf58010bedccae17be55d4ed6f2ecde5646fc48ce8c66ea2d35a1419c" -dependencies = [ - "CoreFoundation-sys", - "IOKit-sys", - "bitflags", - "cfg-if", - "libudev", - "mach 0.2.3", - "nix", - "regex", - "winapi 0.3.8", -] - -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "socket2" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi 0.3.8", -] - -[[package]] -name = "syn" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc157159e2a7df58cd67b1cace10b8ed256a404fb0070593f137d8ba6bef4de" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tokio" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1bef565a52394086ecac0a6fa3b8ace4cb3a138ee1d96bd2b93283b56824e3" -dependencies = [ - "bytes", - "lazy_static", - "memchr", - "mio", - "pin-project-lite", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de6c21a09bab0ce34614bb1071403ad9996db62715eb61e63be5d82f91342bc" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "tokio-serial" -version = "4.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad6436458f961b1345f55f2a771325f8dbdd9b5908285059d34a31e86779e38" -dependencies = [ - "mio-serial", - "tokio", -] - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - -[[package]] -name = "winapi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/misc/serial/Cargo.toml b/misc/serial/Cargo.toml deleted file mode 100644 index e9b99add..00000000 --- a/misc/serial/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "serial" -version = "0.1.0" -authors = ["Rahul Butani "] -edition = "2018" -publish = false - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tokio-serial = "4.3.3" -tokio = { version = "0.2.6", features = [ "io-util", "macros" ] } diff --git a/misc/serial/src/main.rs b/misc/serial/src/main.rs deleted file mode 100644 index 1c1d2e1e..00000000 --- a/misc/serial/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ - -use tokio_serial::{Serial, SerialPortSettings, DataBits, FlowControl, Parity, StopBits}; -use tokio::io::AsyncReadExt; - -use std::time::Duration; - -const BAUD_RATE: u32 = 1_500_000; -// const BAUD_RATE: u32 = 15200; -// const BAUD_RATE: u32 = 115_200; -// const BAUD_RATE: u32 = 2_300_000; -// const BAUD_RATE: u32 = 2_500_000; -// const BAUD_RATE: u32 = 2_500_000; - -// #[tokio::main(basic_scheduler)] -#[tokio::main] -async fn main() -> Result<(), Box> { - let settings = SerialPortSettings { - baud_rate: BAUD_RATE, - data_bits: DataBits::Eight, - flow_control: FlowControl::None, - // parity: Parity::Even, - parity: Parity::None, - stop_bits: StopBits::One, - timeout: Duration::from_secs(100), - }; - - let mut dev = Serial::from_path("/dev/lm4f", &settings)?; - - loop { - print!("{}", dev.read_u8().await? as char); - } - - Ok(()) -} From 2d5e23ea1b2a7695136eab18a879119738a36786 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:58:31 -0500 Subject: [PATCH 07/25] dev-support: bump the `postcard` dep to 1.0 --- device-support/Cargo.toml | 2 +- device-support/src/rpc/encoding/mod.rs | 2 +- device-support/src/rpc/encoding/postcard.rs | 12 ++++++------ device-support/src/util/fifo.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index 707c25f3..53fb4f9f 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -32,7 +32,7 @@ lc3-isa = { path = "../isa", version = "0.1.0", default-features = false } lc3-traits = { path = "../traits", version = "0.1.0", default-features = false } serde = { version = "1.0", default-features = false } # Disable the `std` feature -postcard = "0.5.0" +postcard = "1.0" # bbqueue = "0.4.4" # TODO embedded-hal = "0.2.3" nb = "0.1.2" diff --git a/device-support/src/rpc/encoding/mod.rs b/device-support/src/rpc/encoding/mod.rs index 27c7537e..4edae667 100644 --- a/device-support/src/rpc/encoding/mod.rs +++ b/device-support/src/rpc/encoding/mod.rs @@ -3,4 +3,4 @@ mod postcard; pub use self::postcard::PostcardEncode; pub use self::postcard::PostcardDecode; -pub use ::postcard::flavors::{Cobs, Slice}; +pub use ::postcard::ser_flavors::{Cobs, Slice}; diff --git a/device-support/src/rpc/encoding/postcard.rs b/device-support/src/rpc/encoding/postcard.rs index d5d9fcd8..fcb5248b 100644 --- a/device-support/src/rpc/encoding/postcard.rs +++ b/device-support/src/rpc/encoding/postcard.rs @@ -5,7 +5,7 @@ use crate::util::Fifo; use lc3_traits::control::rpc::{Encode, Decode}; use serde::{Serialize, Deserialize}; -use postcard::flavors::{SerFlavor, Cobs}; +use postcard::ser_flavors::{Flavor as SerFlavor, Cobs}; use postcard::serialize_with_flavor; use postcard::take_from_bytes_cobs; @@ -186,16 +186,16 @@ mod decode { impl SerFlavor for Fifo { type Output = Self; - fn try_push(&mut self, data: u8) -> Result<(), ()> { - self.push(data) + fn try_push(&mut self, data: u8) -> postcard::Result<()> { + self.push(data).map_err(|()| postcard::Error::SerializeBufferFull) } - fn release(self) -> Result { + fn finalize(self) -> postcard::Result { Ok(self) } - fn try_extend(&mut self, data: &[u8]) -> Result<(), ()> { - self.push_slice(data) + fn try_extend(&mut self, data: &[u8]) -> postcard::Result<()> { + self.push_slice(data).map_err(|()| postcard::Error::SerializeBufferFull) } } diff --git a/device-support/src/util/fifo.rs b/device-support/src/util/fifo.rs index d64e2888..6ac72511 100644 --- a/device-support/src/util/fifo.rs +++ b/device-support/src/util/fifo.rs @@ -478,7 +478,7 @@ impl AsMut<[T]> for Fifo { } // Use `Iterator::by_ref` to retain ownership of the iterator -impl Iterator for /*&mut */Fifo { +impl Iterator for Fifo { // /*&mut */ type Item = T; #[inline] From 98c6838096b06aeaf2b94afe3739494876947fa8 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:58:55 -0500 Subject: [PATCH 08/25] dev-support: bump the `bytes` dep to 1.1 --- device-support/Cargo.toml | 2 +- device-support/src/util/fifo.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index 53fb4f9f..6b331906 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -39,7 +39,7 @@ nb = "0.1.2" static_assertions = "1.1.0" # alloc deps: -bytes = { version = "0.5.3", default-features = false, optional = true } +bytes = { version = "1.1", default-features = false, optional = true } # host-transport deps: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/device-support/src/util/fifo.rs b/device-support/src/util/fifo.rs index 6ac72511..dfcd1241 100644 --- a/device-support/src/util/fifo.rs +++ b/device-support/src/util/fifo.rs @@ -498,14 +498,14 @@ impl ExactSizeIterator for Fifo {} using_alloc! { use core::convert::TryInto; - use bytes::{Buf, BufMut}; + use bytes::{{Buf, BufMut}, buf::UninitSlice}; impl Buf for Fifo { fn remaining(&self) -> usize { self.length() } - fn bytes(&self) -> &[u8] { + fn chunk(&self) -> &[u8] { self.as_slice() } @@ -514,7 +514,7 @@ using_alloc! { } } - impl BufMut for Fifo { + unsafe impl BufMut for Fifo { fn remaining_mut(&self) -> usize { self.remaining() } @@ -537,15 +537,22 @@ using_alloc! { self.ending = Self::add(self.ending, cnt_cur); } - fn bytes_mut(&mut self) -> &mut [MaybeUninit] { + fn chunk_mut(&mut self) -> &mut UninitSlice { + fn into_uninit_slice(m: &mut [MaybeUninit]) -> &mut UninitSlice { + let ptr = m as *mut _ as *mut u8; + let len = m.len(); + + unsafe { UninitSlice::from_raw_parts_mut(ptr, len) } + } + if Self::is_empty(self) { - &mut self.data + into_uninit_slice(&mut self.data) } else { if self.ending <= self.starting { - &mut self.data[(self.ending as usize)..(self.starting as usize)] + into_uninit_slice(&mut self.data[(self.ending as usize)..(self.starting as usize)]) } else if self.ending > self.starting { // Gotta do it in two parts then. - &mut self.data[(self.ending as usize)..] + into_uninit_slice(&mut self.data[(self.ending as usize)..]) } else { unreachable!() } } } From 605f29890515f0290cf1d5e36a3c9fa833e46b11 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 12:59:18 -0500 Subject: [PATCH 09/25] dev-support: add a todo (#166) --- device-support/src/util/fifo.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/device-support/src/util/fifo.rs b/device-support/src/util/fifo.rs index dfcd1241..f5d94354 100644 --- a/device-support/src/util/fifo.rs +++ b/device-support/src/util/fifo.rs @@ -11,6 +11,8 @@ use core::{ // Note: Capacity is a constant so that the transition to const generics (once // that lands on stable) will be not terrible painful. +// TODO: const generics! + pub(super) mod fifo_config { use core::mem::size_of; From 523f8976f95ae2c95179272c6036868efe07c65c Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:02:00 -0500 Subject: [PATCH 10/25] build: bump some deps (this are all the version bumps that did *not* require any changes in the codebase) --- Cargo.toml | 2 +- application-support/Cargo.toml | 2 +- baseline-sim/Cargo.toml | 2 +- device-support/Cargo.toml | 8 ++++---- isa/Cargo.toml | 10 +++++----- macros/Cargo.toml | 2 +- shims/Cargo.toml | 2 +- test-infrastructure/Cargo.toml | 4 ++-- traits/Cargo.toml | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb594395..3a95de9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ lc3tools-sys = "=1.0.6-alpha2" # We can use the next point release (TODO). criterion = "0.3.0" async-std = "1.4.0" lazy_static = "1.4.0" -pretty_assertions = "0.6.1" +pretty_assertions = "1.2" [[bench]] diff --git a/application-support/Cargo.toml b/application-support/Cargo.toml index 7e64ad19..f64f4db2 100644 --- a/application-support/Cargo.toml +++ b/application-support/Cargo.toml @@ -45,7 +45,7 @@ wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" [dev-dependencies] -pretty_assertions = "0.6.1" +pretty_assertions = "1.2" [package.metadata.docs.rs] # targets = [""] diff --git a/baseline-sim/Cargo.toml b/baseline-sim/Cargo.toml index 7c0c810d..62de3336 100644 --- a/baseline-sim/Cargo.toml +++ b/baseline-sim/Cargo.toml @@ -35,7 +35,7 @@ static_assertions = "1.1.0" [dev-dependencies] lc3-test-infrastructure = { path = "../test-infrastructure", version = "0.1.0" } -itertools = "0.9.0" +itertools = "0.10" [[test]] diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index 6b331906..cfae52c5 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -34,9 +34,9 @@ lc3-traits = { path = "../traits", version = "0.1.0", default-features = false } serde = { version = "1.0", default-features = false } # Disable the `std` feature postcard = "1.0" # bbqueue = "0.4.4" # TODO -embedded-hal = "0.2.3" -nb = "0.1.2" -static_assertions = "1.1.0" +embedded-hal = "0.2" +nb = "1.0" +static_assertions = "1.1" # alloc deps: bytes = { version = "1.1", default-features = false, optional = true } @@ -47,7 +47,7 @@ serialport = { version = "4.2", optional = true } [dev-dependencies] -pretty_assertions = "0.6.1" +pretty_assertions = "1.2" [features] diff --git a/isa/Cargo.toml b/isa/Cargo.toml index cec5cd9b..c003caf7 100644 --- a/isa/Cargo.toml +++ b/isa/Cargo.toml @@ -30,14 +30,14 @@ maintenance = { status = "actively-developed" } [dependencies] lc3-macros = { path = "../macros", version = "0.1.0" } -serde = { version = "1.0", default-features = false, features = ["derive"]} -static_assertions = "1.1.0" -arbitrary = { version = "0.4.1", features = ["derive"], optional = true } +arbitrary = { version = "1.1", features = ["derive"], optional = true } const_panic = "0.2" +serde = { version = "1.0", default-features = false, features = ["derive"] } +static_assertions = "1.1" [dev-dependencies] -itertools = "0.9.0" -pretty_assertions = "0.6.1" +itertools = "0.10" +pretty_assertions = "1.2" [features] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index c025e25a..f792ac78 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -38,7 +38,7 @@ syn = { version = "1.0.5" } # features = ["derive", "visit-mut", "parsing", "ful [dev-dependencies] -pretty_assertions = "0.6.1" +pretty_assertions = "1.2" [package.metadata.docs.rs] # targets = [""] diff --git a/shims/Cargo.toml b/shims/Cargo.toml index f9c6e552..67ac8a6c 100644 --- a/shims/Cargo.toml +++ b/shims/Cargo.toml @@ -34,7 +34,7 @@ lc3-traits = { path = "../traits", version = "0.1.0", features = ["std"] } byteorder = "1.3.2" timer = "0.2.0" -time = "0.1.42" +time = "0.3" chrono = "0.4.11" static_assertions = "1.1.0" diff --git a/test-infrastructure/Cargo.toml b/test-infrastructure/Cargo.toml index 1a32e38e..3702b9a1 100644 --- a/test-infrastructure/Cargo.toml +++ b/test-infrastructure/Cargo.toml @@ -35,8 +35,8 @@ lc3-shims = { path = "../shims", version = "0.1.0", default-features = false } lc3-traits = { path = "../traits", version = "0.1.0", default-features = false } lc3-application-support = { path = "../application-support", version = "0.1.0" } -rand = "0.7.3" -pretty_assertions = "0.6.1" +rand = "0.8" +pretty_assertions = "1.2" [features] diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 6bb55242..774abb52 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -37,7 +37,7 @@ serde_json = { version = "1.0.41", optional = true } static_assertions = "1.1.0" [dev-dependencies] -pretty_assertions = "0.6.1" +pretty_assertions = "1.2" [features] From b770eb58c74735a11917209089e0b2bfedbd1fd0 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:15:47 -0500 Subject: [PATCH 11/25] bench: fix some warnings --- Cargo.toml | 6 +++--- benches/common.rs | 16 +++++++++++++--- benches/io.rs | 8 ++++---- benches/overhead.rs | 2 +- benches/speed.rs | 3 ++- flake.nix | 3 +++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a95de9e..2edc0766 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,9 +27,9 @@ lc3-os = { path = "os", version = "0.1.0" } lc3tools-sys = "=1.0.6-alpha2" # We can use the next point release (TODO). -criterion = "0.3.0" -async-std = "1.4.0" -lazy_static = "1.4.0" +criterion = { version = "0.3", features = ["html_reports"] } +async-std = "1.4" +lazy_static = "1.4" pretty_assertions = "1.2" diff --git a/benches/common.rs b/benches/common.rs index 95c2741f..954922f7 100644 --- a/benches/common.rs +++ b/benches/common.rs @@ -18,13 +18,15 @@ pub use lc3_os::OS_IMAGE; pub use pretty_assertions::assert_eq as eq; +#[allow(unused)] pub const fn fib_program_executed_insn_count(num_iters: Word) -> u64 { - (159 * (num_iters as u64) + 347) + 159 * (num_iters as u64) + 347 } // TODO: new macro that basically does the below + sets the orig hook // TODO: have obj conv set the orig hook +#[allow(unused)] pub fn fib_program(num_iters: Word) -> AssembledProgram { const F: Word = 24; @@ -72,6 +74,7 @@ pub fn fib_program(num_iters: Word) -> AssembledProgram { prog } +#[allow(unused)] pub fn build_fib_memory_image(num_iters: Word) -> MemoryDump { let prog = fib_program(num_iters); @@ -81,6 +84,7 @@ pub fn build_fib_memory_image(num_iters: Word) -> MemoryDump { image } +#[allow(unused)] pub fn fib_closed_form(n: Word) -> u64 { let g: f64 = (1. + 5f64.sqrt()) / 2.0; let r: f64 = (g.powi(n as i32) - (-g).powi(-(n as i32))) / 5f64.sqrt(); @@ -101,6 +105,7 @@ pub use lc3_traits::control::Control; use lc3_traits::peripherals::stubs::PeripheralsStub; +#[allow(unused)] pub fn bare_interpreter<'a, 'b>( program: MemoryDump, flags: &'b PeripheralInterruptFlags, @@ -161,7 +166,8 @@ fn device_thread( } } } - }); + }) + .unwrap(); } lazy_static! { @@ -173,6 +179,7 @@ use lc3_traits::control::rpc::encoding::Transparent; use std::sync::mpsc::{channel, Receiver, Sender}; // TODO: test spin vs. sleep +#[allow(unused)] pub fn remote_simulator/**/(program: MemoryDump) -> (Sender<()>, Controller<'static, MpscTransport, SyncEventFutureSharedState>) // where // ::EventFuture: Sync + Send, @@ -188,6 +195,7 @@ pub fn remote_simulator/**/(program: MemoryDump) -> (Sender<()>, Con use lc3_traits::control::State; +#[allow(unused)] pub fn executor_thread(mut dev: C) -> (Sender>, impl Fn(&Sender>), impl Fn(&Sender>) -> C::EventFuture) where C: Send + 'static, @@ -217,17 +225,19 @@ where use lc3tools_sys::root::{ lc3::sim as Lc3ToolsSimInner, buffer_printer, buffer_inputter, callback_printer, callback_inputter, free_sim, - get_mem, load_program, new_sim, new_sim_with_no_op_io, run_program, + load_program, new_sim, new_sim_with_no_op_io, run_program, State as Lc3ToolsSimState, lc3::utils::PrintType_P_SIM_OUTPUT as PrintTypeSimOutput, }; +#[allow(unused)] pub struct Lc3ToolsSim<'inp, 'out> { sim: *mut Lc3ToolsSimInner, inp: Option<&'inp Vec>, out: Option<&'out mut Vec>, } +#[allow(unused)] impl<'inp, 'out> Lc3ToolsSim<'inp, 'out> { pub fn new() -> Self { Self { diff --git a/benches/io.rs b/benches/io.rs index 3f9d17ee..0c619462 100644 --- a/benches/io.rs +++ b/benches/io.rs @@ -13,10 +13,9 @@ extern crate lazy_static; mod common; use common::*; -use lc3_traits::peripherals::input::{Input, InputError}; use lc3_shims::peripherals::input::{InputShim, Source}; -use std::sync::{Arc, Mutex}; +use std::sync::Mutex; pub struct BufferedInput> { buffer: Mutex, @@ -92,6 +91,7 @@ fn byte_stream(elements: usize) -> impl Clone + Iterator { .map(|i| match i { 13 => 10, i => i }) } +#[allow(unused)] fn checksum(iter: impl Iterator) -> u128 { iter.fold(1u128, |acc, b| acc * ((b + 1) as u128)) } @@ -99,7 +99,7 @@ fn checksum(iter: impl Iterator) -> u128 { pub fn program(num_elements: u64) -> AssembledProgram { let prog = program! { // Disable PUTS to suppress the HALT message. - .ORIG #(lc3_os::traps::builtin::PUTS as Word); + .ORIG #lc3_os::traps::builtin::PUTS as Word; .FILL @NEW_PUTS; .ORIG #0x4000; @@ -248,7 +248,7 @@ pub fn raw_io_program(num_elements: u64) -> AssembledProgram { const SIZES: &[u64] = &[1, 10, 100, 1000, 10_000, 50_000]; -use criterion::{BatchSize, BenchmarkId, BenchmarkGroup, Bencher, Criterion, Throughput, PlotConfiguration, AxisScale}; +use criterion::{BenchmarkId, BenchmarkGroup, Criterion, Throughput, PlotConfiguration, AxisScale}; use criterion::measurement::WallTime; use lc3_baseline_sim::interp::MachineState; diff --git a/benches/overhead.rs b/benches/overhead.rs index cd3bba31..3b61017d 100644 --- a/benches/overhead.rs +++ b/benches/overhead.rs @@ -22,7 +22,7 @@ use common::*; //// Benches //// -use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, PlotConfiguration, AxisScale}; +use criterion::{BenchmarkId, Criterion, Throughput, PlotConfiguration, AxisScale}; use lc3_baseline_sim::interp::MachineState; // const ITERS: [Word; 10] = [1, 10, 100, 500, 1000, 5000, 10000, 25000, 50000, 65535]; diff --git a/benches/speed.rs b/benches/speed.rs index 136c82de..a041f8db 100644 --- a/benches/speed.rs +++ b/benches/speed.rs @@ -22,7 +22,7 @@ fn black_box(inp: T) -> T { inp } const ITERS: [Word; 5] = [1, 10, 100, 1000, 10_000]; -use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, PlotConfiguration, AxisScale}; +use criterion::{BenchmarkId, Criterion, Throughput, PlotConfiguration, AxisScale}; use lc3_baseline_sim::interp::MachineState; fn bench_fib(c: &mut Criterion) { @@ -67,6 +67,7 @@ fn bench_fib(c: &mut Criterion) { } } +#[allow(unused)] fn bench_fib_alt() { let flags = PeripheralInterruptFlags::default(); diff --git a/flake.nix b/flake.nix index 329e4b45..0afa19a0 100644 --- a/flake.nix +++ b/flake.nix @@ -100,6 +100,9 @@ cargo-nightly cargo-bloat cargo-asm cargo-expand + + # For `criterion`: + gnuplot ] ++ gdbPkgs; }; } From 9d661f601a2d9329f636ecea31e3dc00041e0bb4 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:23:22 -0500 Subject: [PATCH 12/25] rpc: fix the encode/decode tests --- traits/src/control/rpc/encoding.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/traits/src/control/rpc/encoding.rs b/traits/src/control/rpc/encoding.rs index a91c79bd..b72f9575 100644 --- a/traits/src/control/rpc/encoding.rs +++ b/traits/src/control/rpc/encoding.rs @@ -956,6 +956,7 @@ where } using_std! { + #[cfg(feature = "json_encoding_layer")] use serde::{Serialize, de::DeserializeOwned}; #[cfg_attr(all(docs, not(doctest)), doc(cfg(feature = "json_encoding_layer")))] @@ -998,7 +999,7 @@ mod tests { impl Encode<$src> for $unit { type Encoded = $dest; - fn encode(&mut self, m: $src) -> $dest { m as $dest } + fn encode(&mut self, m: &$src) -> $dest { *m as $dest } } impl Decode<$src> for $unit { @@ -1036,7 +1037,7 @@ mod tests { // This really does nothing at run time; if this function compiles, the // blanket impl works. fn encoding_blanket_impl() { - fn ser>(m: M) -> >::Encoded { E::default().encode(m) } + fn ser>(m: M) -> >::Encoded { E::default().encode(&m) } fn de>(e: >::Encoded) -> Result>::Err> { E::default().decode(&e) } @@ -1057,7 +1058,7 @@ mod tests { // This really does nothing at run time; if this function compiles, the // `ChainedEncoding` types and functions work. fn chained_encoding() { - fn ser>(mut e: E, m: M) -> >::Encoded { e.encode(m) } + fn ser>(mut e: E, m: M) -> >::Encoded { e.encode(&m) } fn de>(mut e: E, enc: >::Encoded) -> Result>::Err> { e.decode(&enc) } let chain = ChainedEncoding::new(U8ToU16) @@ -1075,7 +1076,7 @@ mod tests { // This really does nothing at run time; if this function compiles, the // `ChainedEncode` types and functions work. fn chained_back_encode() { - fn ser>(mut e: E, m: M) -> E::Encoded { e.encode(m) } + fn ser>(mut e: E, m: M) -> E::Encoded { e.encode(&m) } let chain = ChainedEncode::new(U64ToU128) .chain_back(U32ToU64) @@ -1103,7 +1104,7 @@ mod tests { // This really does nothing at run time; if this function compiles, the // `ChainedEncode` types and functions work. fn chained_encode() { - fn ser>(mut e: E, m: M) -> E::Encoded { e.encode(m) } + fn ser>(mut e: E, m: M) -> E::Encoded { e.encode(&m) } let chain = ChainedEncode::new(U8ToU16) .chain(U16ToU32) @@ -1133,7 +1134,7 @@ mod tests { fn pair() { // This is basically the same test as `chained_encoding` except we // assemble the encode pipeline and the decode pipeline ourselves. - fn ser>(mut e: E, m: M) -> >::Encoded { e.encode(m) } + fn ser>(mut e: E, m: M) -> >::Encoded { e.encode(&m) } fn de>(mut e: E, enc: >::Encoded) -> Result>::Err> { e.decode(&enc) } fn check>(chain: E, m: M) where >::Err: PartialEq { From 62ab1fabebf466558d17296336f4b006a4ab4f3d Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:23:52 -0500 Subject: [PATCH 13/25] build: add a missing macOS dep to the flake --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0afa19a0..52b4c557 100644 --- a/flake.nix +++ b/flake.nix @@ -103,7 +103,9 @@ # For `criterion`: gnuplot - ] ++ gdbPkgs; + ] ++ gdbPkgs ++ lib.optionals (pkgs.stdenv.isDarwin) [ + darwin.apple_sdk.frameworks.IOKit + ]; }; } ); From 6f3971185a06dd2384743d965d498b2579d38f79 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:40:51 -0500 Subject: [PATCH 14/25] bench: drop the nightly feature whatever LLVM bug we were hitting with `black_box` seems to be resolved? --- Cargo.toml | 1 - benches/speed.rs | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2edc0766..516f7041 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,6 @@ harness = false [features] default = [] -nightly = [] # For benchmarking. lto = ["lc3tools-sys/lto"] # For benchmarking. diff --git a/benches/speed.rs b/benches/speed.rs index a041f8db..ce3ea0b5 100644 --- a/benches/speed.rs +++ b/benches/speed.rs @@ -1,7 +1,5 @@ //! A benchmark that just tries to measure execution speed. -#![cfg_attr(feature = "nightly", feature(test))] -// #![feature(test)] // TODO: have CI run this and give us reports extern crate criterion; @@ -10,13 +8,8 @@ extern crate criterion; mod common; use common::*; -#[cfg(feature = "nightly")] -use std::hint::black_box; -// use criterion::black_box; -// ^ doesn't work so we just provide a shim for when we're not on nightly: -#[cfg(not(feature = "nightly"))] -fn black_box(inp: T) -> T { inp } +use criterion::black_box; // const ITERS: [Word; 6] = [1, 10, 100, 1000, 10_000, 50_000]; const ITERS: [Word; 5] = [1, 10, 100, 1000, 10_000]; From ef52e746987ede58b68eff07dcf2be14f5e5d5ed Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 13:43:40 -0500 Subject: [PATCH 15/25] build: fix some warnings throughout the workspace's tests cosmetic changes only --- .../device_register_tests/mem_mapped/adc.rs | 62 ++++++----- .../device_register_tests/mem_mapped/clock.rs | 14 +-- .../device_register_tests/mem_mapped/gpio.rs | 100 +++++++++--------- .../device_register_tests/mem_mapped/input.rs | 8 +- .../mem_mapped/output.rs | 9 +- .../device_register_tests/mem_mapped/pwm.rs | 5 - .../mem_mapped/timers.rs | 6 +- .../tests/device_register_tests/mod.rs | 4 +- baseline-sim/tests/interp.rs | 4 +- baseline-sim/tests/single_instructions.rs | 1 - isa/tests/macros.rs | 2 +- os/tests/trap_tests/traps/adc.rs | 12 +-- os/tests/trap_tests/traps/clock.rs | 8 +- os/tests/trap_tests/traps/gpio.rs | 10 +- os/tests/trap_tests/traps/mod.rs | 2 - os/tests/trap_tests/traps/pwm.rs | 2 +- shims/src/peripherals/adc.rs | 4 +- shims/src/peripherals/clock.rs | 1 - shims/src/peripherals/input.rs | 4 +- shims/src/peripherals/pwm.rs | 45 ++++---- test-infrastructure/src/macros.rs | 18 ++-- 21 files changed, 151 insertions(+), 170 deletions(-) diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/adc.rs b/baseline-sim/tests/device_register_tests/mem_mapped/adc.rs index 336c6aeb..60e72f3c 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/adc.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/adc.rs @@ -18,7 +18,7 @@ mod states { // TODO: Clean this up! #[test] fn exhaustive_state_testing() { with_larger_stack(None, || { - assert_eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); + eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); fn state_to_word(s: AdcState) -> SignedWord { match s { @@ -164,9 +164,9 @@ mod read { #[test] fn read_testing() { with_larger_stack(None, || { - assert_eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); + eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); + - let state_iter = [Disabled, Enabled].iter(); @@ -186,12 +186,10 @@ mod read { let permutations = ADC_PINS.iter() .map(|_| state_iter.clone()) .multi_cartesian_product(); - - let mut counter = 0; // easier than starting an rng thread... - for states in permutations { - - + #[allow(unused)] // TODO + let counter = 0; // easier than starting an rng thread... + for states in permutations { single_test_inner! { prefill: { @@ -219,20 +217,20 @@ mod read { R4: match_state(*states[4]), R5: match_state(*states[5]), }, - pre: |p| { + pre: |p| { for (pin, state) in ADC_PINS.iter().zip(states.clone()) { - let _set = Adc::set_state(p, *pin, *state).unwrap(); + let _set = Adc::set_state(p, *pin, *state).unwrap(); // let _set_val = Adc::set_value(p, *pin, counter); - no implementation for RwLock } - }, + }, } - } + } })} - + /* single_test! { Adc_cr_pin0_read_input1, @@ -253,7 +251,7 @@ mod read { steps: 3, regs: { R0: 0b01111111}, memory: { }, - post: |i| { assert_eq!(0b01111111, Adc::read(i.get_peripherals(), A2)); } + post: |i| { eq!(0b01111111, Adc::read(i.get_peripherals(), A2)); } } single_test! { Adc_cr_pin3_read_input, @@ -263,7 +261,7 @@ mod read { steps: 3, regs: { R0: 0b00000000}, memory: { }, - post: |i| { assert_eq!(0b00000000, Adc::read(i.get_peripherals(), A3)); } + post: |i| { eq!(0b00000000, Adc::read(i.get_peripherals(), A3)); } } single_test! { Adc_cr_pin4_read_input, @@ -273,7 +271,7 @@ mod read { steps: 3, regs: { R0: 0b00001101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A4)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A4)); } } single_test! { Adc_cr_pin1_read_input, @@ -283,7 +281,7 @@ mod read { steps: 3, regs: { R0: 0b00001101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A1)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A1)); } } single_test! { Adc_cr_pin5_read_input, @@ -293,7 +291,7 @@ mod read { steps: 3, regs: { R0: 0b00000101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A5)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A5)); } } single_test! { Adc_cr_pin6_read_input, @@ -303,7 +301,7 @@ mod read { steps: 3, regs: { R0: 0b00101111}, memory: { }, - post: |i| { assert_eq!(0b00101111, Adc::read(i.get_peripherals(), A6)); } + post: |i| { eq!(0b00101111, Adc::read(i.get_peripherals(), A6)); } } single_test! { Adc_cr_pin7_read_input, @@ -313,7 +311,7 @@ mod read { steps: 3, regs: { R0: 0b00000001}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A7)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A7)); } } single_test! { Adc_cr_pin0_read_input1, @@ -323,7 +321,7 @@ mod read { steps: 3, regs: { R0: 0b00001101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A0)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A0)); } } single_test! { @@ -334,7 +332,7 @@ mod read { steps: 3, regs: { R0: 0b01111111}, memory: { }, - post: |i| { assert_eq!(0b01111111, Adc::read(i.get_peripherals(), A2)); } + post: |i| { eq!(0b01111111, Adc::read(i.get_peripherals(), A2)); } } single_test! { Adc_cr_pin3_read_input, @@ -344,7 +342,7 @@ mod read { steps: 3, regs: { R0: 0b00000000}, memory: { }, - post: |i| { assert_eq!(0b00000000, Adc::read(i.get_peripherals(), A3)); } + post: |i| { eq!(0b00000000, Adc::read(i.get_peripherals(), A3)); } } single_test! { Adc_cr_pin4_read_input, @@ -354,7 +352,7 @@ mod read { steps: 3, regs: { R0: 0b00001101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A4)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A4)); } } single_test! { Adc_cr_pin1_read_input, @@ -364,7 +362,7 @@ mod read { steps: 3, regs: { R0: 0b00001101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A1)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A1)); } } single_test! { Adc_cr_pin5_read_input, @@ -374,7 +372,7 @@ mod read { steps: 3, regs: { R0: 0b00000101}, memory: { }, - post: |i| { assert_eq!(0b00001101, Adc::read(i.get_peripherals(), A5)); } + post: |i| { eq!(0b00001101, Adc::read(i.get_peripherals(), A5)); } }*/ } //} @@ -385,15 +383,15 @@ mod write { #[test] fn write_testing() { with_larger_stack(None, || { - assert_eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); + eq!(AdcPin::NUM_PINS, 6, "Number of Adc Pins has changed!"); + - let state_iter = [Disabled, Enabled].iter(); let permutations = ADC_PINS.iter() .map(|_| state_iter.clone()) .multi_cartesian_product(); - + fn state_to_word(s: AdcState) -> SignedWord { match s { @@ -442,13 +440,13 @@ mod write { ], steps: AdcPin::NUM_PINS * 3, post: |i| { - for (pin, state) in ADC_PINS.iter().zip(states.clone()) { + for (pin, _) in ADC_PINS.iter().zip(states.clone()) { let got = Adc::get_state(i.get_peripherals(), *pin); let read_adc = Adc::read(i.get_peripherals(), *pin); match got { Enabled => { - eq!(read_adc, Ok(0), + eq!(read_adc, Ok(0), "Adc Pin {}: expected val `{:?}`, got `{:?}`.\ \n\n[Test Case: {:?}]", pin, 0, read_adc, states @@ -463,7 +461,7 @@ mod write { } } - + } } } diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/clock.rs b/baseline-sim/tests/device_register_tests/mem_mapped/clock.rs index b1f2df65..7d13e9db 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/clock.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/clock.rs @@ -1,14 +1,8 @@ use super::*; -use lc3_traits::peripherals::clock::Clock; -use lc3_baseline_sim::{ - mem_mapped::CLKR_ADDR, - interp::InstructionInterpreter, -}; +use lc3_baseline_sim::mem_mapped::CLKR_ADDR; use std::thread::sleep; use std::time::Duration; -use lc3_test_infrastructure::assert_is_about; -use lc3_isa::Reg::*; const TOLERANCE: u16 = 5; @@ -25,7 +19,7 @@ single_test! { prefill: { 0x3010: CLKR_ADDR }, insns: [ { LDI R0, #0xF } ], steps: 1, - pre: |p| { sleep(Duration::from_millis(100)); }, + pre: |_| { sleep(Duration::from_millis(100)); }, post: |i| { assert_is_about(i.get_register(R0), 100, TOLERANCE); } } @@ -38,7 +32,7 @@ single_test! { { LDI R0, #0xD }, ], steps: 3, - pre: |p| { sleep(Duration::from_millis(100)); }, + pre: |_| { sleep(Duration::from_millis(100)); }, post: |i| { assert_is_about(i.get_register(R0), 0, TOLERANCE); } } @@ -54,6 +48,6 @@ single_test! { { LDI R0, #0xD } ], steps: 3, - pre: |p| { sleep(Duration::from_millis(100)); }, + pre: |_| { sleep(Duration::from_millis(100)); }, post: |i| { assert_is_about(i.get_register(R0), 1000, TOLERANCE); } } diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/gpio.rs b/baseline-sim/tests/device_register_tests/mem_mapped/gpio.rs index a0d89878..94c39512 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/gpio.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/gpio.rs @@ -3,24 +3,19 @@ use super::*; use lc3_traits::peripherals::gpio::{Gpio, GpioPin, GpioState, GPIO_PINS}; use lc3_baseline_sim::interp::InstructionInterpreter; use lc3_baseline_sim::mem_mapped::{ - G0CR_ADDR, G0DR_ADDR, G0_INT_VEC, - G1CR_ADDR, G1DR_ADDR, G1_INT_VEC, - G2CR_ADDR, G2DR_ADDR, G2_INT_VEC, - G3CR_ADDR, G3DR_ADDR, G3_INT_VEC, - G4CR_ADDR, G4DR_ADDR, G4_INT_VEC, - G5CR_ADDR, G5DR_ADDR, G5_INT_VEC, - G6CR_ADDR, G6DR_ADDR, G6_INT_VEC, - G7CR_ADDR, G7DR_ADDR, G7_INT_VEC, - GPIODR_ADDR, + G0CR_ADDR, G0DR_ADDR, /* G0_INT_VEC, */ // TODO! + G1CR_ADDR, G1DR_ADDR, /* G1_INT_VEC, */ // TODO! + G2CR_ADDR, G2DR_ADDR, /* G2_INT_VEC, */ // TODO! + G3CR_ADDR, G3DR_ADDR, /* G3_INT_VEC, */ // TODO! + G4CR_ADDR, G4DR_ADDR, /* G4_INT_VEC, */ // TODO! + G5CR_ADDR, G5DR_ADDR, /* G5_INT_VEC, */ // TODO! + G6CR_ADDR, G6DR_ADDR, /* G6_INT_VEC, */ // TODO! + G7CR_ADDR, G7DR_ADDR, /* G7_INT_VEC, */ // TODO! + // GPIODR_ADDR, // TODO! }; use GpioState::*; use GpioPin::*; -use std::sync::mpsc::channel; -use std::thread; -use std::time::Duration; - - mod states { use super::*; @@ -36,7 +31,7 @@ mod states { fn exhaustive_state_testing() { with_larger_stack(None, || { // The actual assembly assumes that there are 8 pins and needs to be // updated if this changes. - assert_eq!(GpioPin::NUM_PINS, 8, "Number of Gpio Pins has changed!"); + eq!(GpioPin::NUM_PINS, 8, "Number of Gpio Pins has changed!"); // We're also assuming that the states in GpioState won't change: // TODO: make this a `From` impl on the GpioState type so we don't have @@ -193,7 +188,6 @@ mod states { mod read { use super::*; - use lc3_traits::peripherals::gpio::*; // Test that reads of [0, 1] work for all the pins when everything is // configured as inputs (i think we can skip the full 2 ^ 8 possibilities @@ -381,7 +375,6 @@ mod read { mod write { use super::*; - use lc3_traits::peripherals::gpio::*; // test that when you write in output mode that you can read the values back in #[test] @@ -521,41 +514,44 @@ mod write { } mod interrupt { - use super::*; - use lc3_traits::peripherals::gpio::*; - // Reading from pins in interrupt mode should already be covered; the only - // thing left is to test that interrupts actually trigger. - - // Here are the variables: - // - rising edge or falling edge - // - in interrupt mode or some other mode (i.e. 3 other modes) - - // Interrupts should only trigger on rising edges AND when interrupts are - // enabled AND when in interrupt mode. If we do an exhaustive test, this - // is (2 * 4) ^ 8 = 16,777,216 states... - // - // So, maybe don't do an exhaustive test or randomly pick a few thousand - // combinations from the full set of possibilities. - // Should also test that multiple interrupts are handled (i.e. they all - // run). - - // Also need to test that when multiple interrupts occur, they trigger in - // the documented order! - // - // i.e. if G0 through G7 all trigger, G0 runs first, then G1, then G2, etc. - // - // One way we can actually test this is to have each handler increment R0 - // and to have each handler store R0 into a fixed memory location for that - // handler. - // - // i.e. G0's handler -> 0x1000 - // G1's handler -> 0x1001 - // G2's handler -> 0x1002 - // G3's handler -> 0x1003 - // etc. - // - // If the handlers trigger in the right order, the values in 0x1000..0x1007 - // should be sequential; if the handlers get run out of order they won't be. + // use super::*; + // use lc3_traits::peripherals::gpio::*; + + // TODO! + + // Reading from pins in interrupt mode should already be covered; the only + // thing left is to test that interrupts actually trigger. + + // Here are the variables: + // - rising edge or falling edge + // - in interrupt mode or some other mode (i.e. 3 other modes) + + // Interrupts should only trigger on rising edges AND when interrupts are + // enabled AND when in interrupt mode. If we do an exhaustive test, this + // is (2 * 4) ^ 8 = 16,777,216 states... + // + // So, maybe don't do an exhaustive test or randomly pick a few thousand + // combinations from the full set of possibilities. + // Should also test that multiple interrupts are handled (i.e. they all + // run). + + // Also need to test that when multiple interrupts occur, they trigger in + // the documented order! + // + // i.e. if G0 through G7 all trigger, G0 runs first, then G1, then G2, etc. + // + // One way we can actually test this is to have each handler increment R0 + // and to have each handler store R0 into a fixed memory location for that + // handler. + // + // i.e. G0's handler -> 0x1000 + // G1's handler -> 0x1001 + // G2's handler -> 0x1002 + // G3's handler -> 0x1003 + // etc. + // + // If the handlers trigger in the right order, the values in 0x1000..0x1007 + // should be sequential; if the handlers get run out of order they won't be. diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/input.rs b/baseline-sim/tests/device_register_tests/mem_mapped/input.rs index f0e8d5cd..72c8fd82 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/input.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/input.rs @@ -1,4 +1,6 @@ -use super::*; -use lc3_traits::peripherals::input::Input; -use lc3_baseline_sim::mem_mapped::{KBSR_ADDR, KBDR_ADDR, KEYBOARD_INT_VEC}; +// TODO! +// use super::*; + +// use lc3_traits::peripherals::input::Input; +// use lc3_baseline_sim::mem_mapped::{KBSR_ADDR, KBDR_ADDR, KEYBOARD_INT_VEC}; diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/output.rs b/baseline-sim/tests/device_register_tests/mem_mapped/output.rs index a6f9086d..2a30196c 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/output.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/output.rs @@ -1,4 +1,7 @@ -use super::*; +// TODO! +// TODO! -use lc3_traits::peripherals::output::Output; -use lc3_baseline_sim::mem_mapped::{DSR_ADDR, DDR_ADDR, DISPLAY_INT_VEC}; +// use super::*; + +// use lc3_traits::peripherals::output::Output; +// use lc3_baseline_sim::mem_mapped::{DSR_ADDR, DDR_ADDR, DISPLAY_INT_VEC}; diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/pwm.rs b/baseline-sim/tests/device_register_tests/mem_mapped/pwm.rs index 4a674178..35b88dde 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/pwm.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/pwm.rs @@ -1,14 +1,9 @@ use super::*; -use lc3_traits::peripherals::pwm::{Pwm, PwmPin, PwmState, PWM_PINS}; use lc3_baseline_sim::mem_mapped::{ P0CR_ADDR, P0DR_ADDR, - P1CR_ADDR, P1DR_ADDR, }; -use PwmState::*; -use PwmPin::*; - single_test! { get_initial_state, prefill: { 0x3010: P0CR_ADDR, }, diff --git a/baseline-sim/tests/device_register_tests/mem_mapped/timers.rs b/baseline-sim/tests/device_register_tests/mem_mapped/timers.rs index afb93bd1..927f08b1 100644 --- a/baseline-sim/tests/device_register_tests/mem_mapped/timers.rs +++ b/baseline-sim/tests/device_register_tests/mem_mapped/timers.rs @@ -1,17 +1,13 @@ use super::*; -use lc3_traits::peripherals::timers::{Timers, TimerId, TIMERS}; use lc3_baseline_sim::mem_mapped::{ MemMapped, T0CR_ADDR, T0DR_ADDR, - T1CR_ADDR, T1DR_ADDR, - TIMER_BASE_INT_VEC, T0_INT_VEC, + TIMER_BASE_INT_VEC, PSR, MCR }; -use TimerId::*; - single_test! { singleshot_100ms, prefill: { diff --git a/baseline-sim/tests/device_register_tests/mod.rs b/baseline-sim/tests/device_register_tests/mod.rs index de395242..2db65719 100644 --- a/baseline-sim/tests/device_register_tests/mod.rs +++ b/baseline-sim/tests/device_register_tests/mod.rs @@ -1,5 +1,5 @@ -#[macro_use] extern crate itertools; -#[macro_use] extern crate lc3_test_infrastructure; +extern crate itertools; +extern crate lc3_test_infrastructure; // So that we can run `cargo test mem_mapped` diff --git a/baseline-sim/tests/interp.rs b/baseline-sim/tests/interp.rs index 42896554..babdfcfa 100644 --- a/baseline-sim/tests/interp.rs +++ b/baseline-sim/tests/interp.rs @@ -1,4 +1,4 @@ -use lc3_baseline_sim::interp::{Interpreter, InstructionInterpreter, InstructionInterpreterPeripheralAccess}; +use lc3_baseline_sim::interp::{Interpreter, InstructionInterpreter}; mod reset { use super::*; @@ -13,4 +13,4 @@ mod reset { } -} \ No newline at end of file +} diff --git a/baseline-sim/tests/single_instructions.rs b/baseline-sim/tests/single_instructions.rs index 10fd60ec..1c8cc141 100644 --- a/baseline-sim/tests/single_instructions.rs +++ b/baseline-sim/tests/single_instructions.rs @@ -8,7 +8,6 @@ mod single_instructions { use super::*; use Reg::*; - use lti::assert_eq; use lti::{interp_test_runner, with_larger_stack}; // Test that the instructions work diff --git a/isa/tests/macros.rs b/isa/tests/macros.rs index a4276175..ce30c336 100644 --- a/isa/tests/macros.rs +++ b/isa/tests/macros.rs @@ -109,7 +109,7 @@ use lc3_isa::{Addr, Instruction::*, Reg::*, Word}; fn loadable_full() { // TODO: remove - let LOADABLE: [(lc3_isa::Addr, lc3_isa::Word); 28] = lc3_isa::loadable! { + const LOADABLE: [(lc3_isa::Addr, lc3_isa::Word); 28] = lc3_isa::loadable! { .ORIG #0x3000 => is the program start; ADD R0, R0, R1 => you can use comments like this; ADD R1, R1, #0 => careful though there are things you cannot stick in these weird comments; diff --git a/os/tests/trap_tests/traps/adc.rs b/os/tests/trap_tests/traps/adc.rs index c34c00ab..8aab309e 100644 --- a/os/tests/trap_tests/traps/adc.rs +++ b/os/tests/trap_tests/traps/adc.rs @@ -6,8 +6,6 @@ use lc3_shims::peripherals::AdcShim; use AdcState::*; use AdcPin::*; -use std::sync::RwLock; - single_test! { enable, insns: [ @@ -29,7 +27,7 @@ single_test! { { TRAP #0x41 }, { TRAP #0x25 }, ], - pre: |p| { Adc::set_state(p, A0, Enabled); }, + pre: |p| { Adc::set_state(p, A0, Enabled).unwrap() }, post: |i| { let p = i.get_peripherals(); eq!(Adc::get_state(p, A0), Disabled); @@ -46,7 +44,7 @@ single_test! { { ST R0, #1 }, { TRAP #0x25 }, ], - pre: |p| { Adc::set_state(p, A0, Disabled); }, + pre: |p| { Adc::set_state(p, A0, Disabled).unwrap() }, post: |i| { eq!(i.get_word_unchecked(0x3004), 0); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR } @@ -60,7 +58,7 @@ single_test! { { ST R0, #1 }, { TRAP #0x25 }, ], - pre: |p| { Adc::set_state(p, A0, Enabled); }, + pre: |p| { Adc::set_state(p, A0, Enabled).unwrap() }, post: |i| { eq!(i.get_word_unchecked(0x3004), 1); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR } @@ -75,8 +73,8 @@ single_test! { { TRAP #0x25 }, ], pre: |p| { - Adc::set_state(p, A0, Enabled); - AdcShim::set_value(&mut *p.get_adc().write().unwrap(), A0, 10); + Adc::set_state(p, A0, Enabled).unwrap(); + AdcShim::set_value(&mut *p.get_adc().write().unwrap(), A0, 10).unwrap(); }, post: |i| { eq!(i.get_word_unchecked(0x3004), 10); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR diff --git a/os/tests/trap_tests/traps/clock.rs b/os/tests/trap_tests/traps/clock.rs index ca0ba250..b57d3907 100644 --- a/os/tests/trap_tests/traps/clock.rs +++ b/os/tests/trap_tests/traps/clock.rs @@ -2,9 +2,7 @@ use super::*; use std::thread::sleep; use std::time::Duration; -use super::lti::{assert_is_about, single_test}; -use lc3_test_infrastructure; -use lc3_isa::Reg::*; +use super::lti::single_test; use lc3_traits::peripherals::Clock; const TOLERANCE: u16 = 5; @@ -16,7 +14,7 @@ single_test! { { TRAP #0x70 }, { TRAP #0x25 }, ], - pre: |p| { sleep(Duration::from_millis(100)); }, + pre: |_| { sleep(Duration::from_millis(100)); }, post: |i| { assert_is_about(Clock::get_milliseconds(i.get_peripherals()), 0, TOLERANCE); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR } @@ -29,7 +27,7 @@ single_test! { { ST R0, #1 }, { TRAP #0x25 }, ], - pre: |p| { sleep(Duration::from_millis(200)); }, + pre: |_| { sleep(Duration::from_millis(200)); }, post: |i| { assert_is_about(i.get_word_unchecked(0x3003), 200, TOLERANCE); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR } diff --git a/os/tests/trap_tests/traps/gpio.rs b/os/tests/trap_tests/traps/gpio.rs index 866f413e..9ba0e212 100644 --- a/os/tests/trap_tests/traps/gpio.rs +++ b/os/tests/trap_tests/traps/gpio.rs @@ -1,10 +1,6 @@ use super::*; -use lc3_traits::peripherals::gpio::{Gpio, GpioPin, GpioState, GPIO_PINS}; -use lc3_baseline_sim::mem_mapped::{ - G0_INT_VEC, G1_INT_VEC, G2_INT_VEC, G3_INT_VEC, - G4_INT_VEC, G5_INT_VEC, G6_INT_VEC, G7_INT_VEC, -}; +use lc3_traits::peripherals::gpio::{Gpio, GpioPin, GpioState}; use GpioState::*; use GpioPin::*; @@ -49,7 +45,7 @@ mod states { { TRAP #0x33 }, { TRAP #0x25 }, ], - pre: |p| { Gpio::set_state(p, G0, Output); }, + pre: |p| { Gpio::set_state(p, G0, Output).unwrap() }, post: |i| { let p = i.get_peripherals(); eq!(Gpio::get_state(p, G0), Disabled); @@ -66,7 +62,7 @@ mod states { { ST R0, #1 }, { TRAP #0x25 }, ], - pre: |p| { Gpio::set_state(p, G0, Output); }, + pre: |p| { Gpio::set_state(p, G0, Output).unwrap() }, post: |i| { eq!(i.get_word_unchecked(0x3004), 1); }, with os { MemoryShim::new(**OS_IMAGE) } @ OS_START_ADDR } diff --git a/os/tests/trap_tests/traps/mod.rs b/os/tests/trap_tests/traps/mod.rs index 8d5e0110..ba0c80ba 100644 --- a/os/tests/trap_tests/traps/mod.rs +++ b/os/tests/trap_tests/traps/mod.rs @@ -8,8 +8,6 @@ extern crate lc3_test_infrastructure as lti; use lti::*; -use lti::Reg::*; - use lti::assert_eq as eq; use lc3_baseline_sim::interp::InstructionInterpreter; diff --git a/os/tests/trap_tests/traps/pwm.rs b/os/tests/trap_tests/traps/pwm.rs index f01e6f6d..dece515e 100644 --- a/os/tests/trap_tests/traps/pwm.rs +++ b/os/tests/trap_tests/traps/pwm.rs @@ -1,7 +1,7 @@ use super::*; use core::num::NonZeroU8; -use lc3_traits::peripherals::pwm::{Pwm, PwmPin, PwmState, PwmDutyCycle}; +use lc3_traits::peripherals::pwm::{Pwm, PwmPin, PwmState}; use PwmState::*; use PwmPin::*; diff --git a/shims/src/peripherals/adc.rs b/shims/src/peripherals/adc.rs index bc21c567..91189a40 100644 --- a/shims/src/peripherals/adc.rs +++ b/shims/src/peripherals/adc.rs @@ -105,7 +105,7 @@ mod tests { "TEST FAULTY: new_val must not equal INIT_VALUE" ); let mut shim = AdcShim::new(); - shim.set_state(A0, AdcState::Enabled); + shim.set_state(A0, AdcState::Enabled).unwrap(); let res = shim.set_value(A0, new_val); assert_eq!(res, Ok(())); let val = shim.read(A0); @@ -114,7 +114,7 @@ mod tests { #[test] fn read_disabled() { - let mut shim = AdcShim::new(); + let shim = AdcShim::new(); let val = shim.read(A0); assert_eq!(val, Err(ReadError((A0, AdcState::Disabled)))) } diff --git a/shims/src/peripherals/clock.rs b/shims/src/peripherals/clock.rs index 4432f73d..594af316 100644 --- a/shims/src/peripherals/clock.rs +++ b/shims/src/peripherals/clock.rs @@ -72,7 +72,6 @@ mod tests { #[test] fn get_and_set() { let mut clock = ClockShim::default(); - let start = Instant::now(); sleep(Duration::from_millis(2)); assert_eq!(clock.get_milliseconds(), 2); diff --git a/shims/src/peripherals/input.rs b/shims/src/peripherals/input.rs index 29810a43..15518ad5 100644 --- a/shims/src/peripherals/input.rs +++ b/shims/src/peripherals/input.rs @@ -193,7 +193,9 @@ impl<'inp, 'int> Input<'int> for InputShim<'inp, 'int> { #[cfg(test)] mod tests { + // TODO! + /* use super::*; - use lc3_test_infrastructure::{assert_eq, assert_ne}; + */ } diff --git a/shims/src/peripherals/pwm.rs b/shims/src/peripherals/pwm.rs index dbbdfe9d..9b19e8ae 100644 --- a/shims/src/peripherals/pwm.rs +++ b/shims/src/peripherals/pwm.rs @@ -123,26 +123,27 @@ impl Pwm for PwmShim { #[cfg(test)] mod tests { use super::*; + + use std::{thread, sync::Mutex}; + use lc3_traits::peripherals::pwm::{self, Pwm, PwmPin::*, PwmState}; const MAX_PERIOD: u8 = u8::max_value(); - use lc3_test_infrastructure::{ - assert_eq, assert_is_about, run_periodically_for_a_time - }; + use lc3_test_infrastructure::assert_eq; #[test] fn get_disabled() { let mut shim = PwmShim::new(); assert_eq!(shim.get_state(P0), PwmState::Disabled); - let res = shim.set_state(P1, PwmState::Disabled); + shim.set_state(P1, PwmState::Disabled); assert_eq!(shim.get_state(P0), PwmState::Disabled); } #[test] fn get_enabled() { let mut shim = PwmShim::new(); - let res = shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); + shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); let val = shim.get_state(P0); assert_eq!(val, pwm::PwmState::Enabled((NonZeroU8::new(MAX_PERIOD)).unwrap())); } @@ -150,8 +151,8 @@ mod tests { #[test] fn get_duty() { let mut shim = PwmShim::new(); - let res = shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); - let res2 = shim.set_duty_cycle(P0, 100); + shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); + shim.set_duty_cycle(P0, 100); assert_eq!(shim.get_duty_cycle(P0), 100); shim.set_state(P0, pwm::PwmState::Disabled); } @@ -159,7 +160,7 @@ mod tests { #[test] fn get_pin_initial() { let mut shim = PwmShim::new(); - let res = shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); + shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); let b = shim.get_pin(P0); assert_eq!(b, true); @@ -168,9 +169,9 @@ mod tests { #[test] fn get_pin_on() { let mut shim = PwmShim::new(); - let res = shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); + shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(MAX_PERIOD).unwrap())); - let res = shim.set_duty_cycle(P0, MAX_DUTY_CYCLE); // should always be on + shim.set_duty_cycle(P0, MAX_DUTY_CYCLE); // should always be on thread::sleep(Duration::from_millis(10)); let b = shim.get_pin(P0); assert_eq!(b, true); @@ -179,8 +180,8 @@ mod tests { #[test] fn start_pwm() { let mut shim = PwmShim::new(); - let res0 = shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(255).unwrap())); - let res1 = shim.set_duty_cycle(P0, 100); // this starts pwm + shim.set_state(P0, pwm::PwmState::Enabled(NonZeroU8::new(255).unwrap())); + shim.set_duty_cycle(P0, 100); // this starts pwm let b = shim.get_pin(P0); thread::sleep(Duration::from_millis(100)); @@ -190,16 +191,16 @@ mod tests { } #[test] - fn P0_toggle_once_check() { + fn p0_toggle_once_check() { let mut shim = PwmShim::new(); - let res = shim.set_state(P0, pwm::PwmState::Enabled((NonZeroU8::new(MAX_PERIOD)).unwrap())); + shim.set_state(P0, pwm::PwmState::Enabled((NonZeroU8::new(MAX_PERIOD)).unwrap())); shim.set_duty_cycle(P0, MAX_DUTY_CYCLE / 2); let pin_state = shim.get_pin(P0); thread::sleep(Duration::from_millis(1 as u64)); let mut toggle_flag = 0; - for i in 0..4 { // let it run for 2 complete cycles + for _ in 0..4 { // let it run for 2 complete cycles if shim.get_pin(P0) != pin_state { toggle_flag = 1; } @@ -211,17 +212,17 @@ mod tests { #[test] - fn P1_toggle_once_check() { + fn p1_toggle_once_check() { let mut shim = PwmShim::new(); - let res = shim.set_state(P1, pwm::PwmState::Enabled((NonZeroU8::new(MAX_PERIOD)).unwrap())); + shim.set_state(P1, pwm::PwmState::Enabled((NonZeroU8::new(MAX_PERIOD)).unwrap())); shim.set_duty_cycle(P1, MAX_DUTY_CYCLE / 2); let pin_state = shim.get_pin(P1); thread::sleep(Duration::from_millis(1 as u64)); let mut toggle_flag = 0; - for i in 0..4 { // let it run for 2 complete cycles + for _ in 0..4 { // let it run for 2 complete cycles if shim.get_pin(P1) != pin_state { toggle_flag = 1; } @@ -234,7 +235,7 @@ mod tests { #[test] - fn P0_duty_cycle() { + fn p0_duty_cycle() { let mut shim = PwmShim::new(); @@ -253,7 +254,7 @@ mod tests { shim.set_duty_cycle(P0, MAX_DUTY_CYCLE/duty_cycle_ratio); thread::sleep(Duration::from_millis(1 as u64)); // give wiggle room - let mut actual_cycles = Arc::new(Mutex::new(0)); + let actual_cycles = Arc::new(Mutex::new(0)); let timer = timer::Timer::new(); let duration = chrono::Duration::milliseconds(MAX_DUTY_CYCLE as i64); @@ -300,7 +301,7 @@ mod tests { } #[test] - fn P1_duty_cycle() { + fn p1_duty_cycle() { let mut shim = PwmShim::new(); @@ -316,7 +317,7 @@ mod tests { shim.set_duty_cycle(P1, MAX_DUTY_CYCLE/duty_cycle_ratio); thread::sleep(Duration::from_millis(1 as u64)); // give wiggle room - let mut actual_cycles = Arc::new(Mutex::new(0)); + let actual_cycles = Arc::new(Mutex::new(0)); let timer = timer::Timer::new(); let duration = chrono::Duration::milliseconds(MAX_DUTY_CYCLE as i64); diff --git a/test-infrastructure/src/macros.rs b/test-infrastructure/src/macros.rs index 86d7e90f..67e9f08a 100644 --- a/test-infrastructure/src/macros.rs +++ b/test-infrastructure/src/macros.rs @@ -22,8 +22,8 @@ macro_rules! single_test { $(memory: { $($addr:literal: $val:expr),* $(,)?} $(,)?)? $(with io peripherals: { source as $inp:ident, sink as $out:ident } $(,)?)? $(with custom peripherals: $custom_per:block -> [$custom_per_ty:tt] $(,)?)? - $(pre: |$peripherals_s:ident| $setup:block $(,)?)? - $(post: |$peripherals_t:ident| $teardown:block $(,)?)? + $(pre: |$peripherals_s:pat_param| $setup:block $(,)?)? + $(post: |$peripherals_t:pat_param| $teardown:block $(,)?)? $(with os { $os:expr } @ $os_addr:expr $(,)?)? ) => { $(#[doc = $panics] #[should_panic])? @@ -65,8 +65,8 @@ macro_rules! single_test_inner { $(memory: { $($addr:literal: $val:expr),* $(,)?} $(,)?)? $(with io peripherals: { source as $inp:ident, sink as $out:ident } $(,)?)? $(with custom peripherals: $custom_per:block -> [$custom_per_ty:tt] $(,)?)? - $(pre: |$peripherals_s:ident| $setup:block $(,)?)? - $(post: |$peripherals_t:ident| $teardown:block $(,)?)? + $(pre: |$peripherals_s:pat_param| $setup:block $(,)?)? + $(post: |$peripherals_t:pat_param| $teardown:block $(,)?)? $(with os { $os:expr } @ $os_addr:expr $(,)?)? ) => {{ #[allow(unused_imports)] @@ -182,6 +182,7 @@ mod smoke_tests { use std::io::Read; // // Just some compile tests: + #[test] fn io_perip() { single_test_inner! { insns: [ { LDI R0, #0xF }, ], @@ -189,6 +190,7 @@ mod smoke_tests { } } + #[test] fn io_perip_used() { single_test_inner! { insns: [{ LDI R0, #0xF }], @@ -205,6 +207,7 @@ mod smoke_tests { #[allow(unused_lifetimes)] type PeripheralsStubAlias<'int, 'io> = PeripheralsStub<'int>; + #[test] fn custom_perip() { single_test_inner! { insns: [], @@ -248,6 +251,7 @@ mod smoke_tests { } */ + #[test] fn all_with_custom_and_commas() { single_test_inner! { prefill: { @@ -277,6 +281,7 @@ mod smoke_tests { } } + #[test] fn all_with_io_and_no_commas() { single_test_inner! { prefill: { 0x3000: 2_109 * 1, } @@ -299,18 +304,19 @@ mod smoke_tests { let mut s = String::new(); - <&[u8]>::read_to_string(&mut out.lock().unwrap().as_ref(), &mut s); + <&[u8]>::read_to_string(&mut out.lock().unwrap().as_ref(), &mut s).unwrap(); } } } + #[test] fn thread_safe() { use lc3_application_support::io_peripherals::{InputSink, OutputSource}; single_test_inner! { insns: [], with io peripherals: { source as inp, sink as out }, - pre: |p| { + pre: |_| { let inp = inp.clone(); let out = out.clone(); From 50d2d1a23b7c8a209c47f2a037cfcee87ed3b7f9 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 10 Jul 2022 23:50:19 -0500 Subject: [PATCH 16/25] build: update to edition 2021 we actually had a little breakage! (`a'b` now parses `a` as a string/character prefix) --- application-support/Cargo.toml | 2 +- baseline-sim/Cargo.toml | 2 +- device-support/Cargo.toml | 2 +- isa/Cargo.toml | 2 +- isa/src/macros.rs | 2 +- macros/Cargo.toml | 2 +- os/Cargo.toml | 2 +- shims/Cargo.toml | 2 +- test-infrastructure/Cargo.toml | 2 +- traits/Cargo.toml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/application-support/Cargo.toml b/application-support/Cargo.toml index f64f4db2..b90fe661 100644 --- a/application-support/Cargo.toml +++ b/application-support/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-application-support" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/baseline-sim/Cargo.toml b/baseline-sim/Cargo.toml index 62de3336..1ec034ed 100644 --- a/baseline-sim/Cargo.toml +++ b/baseline-sim/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-baseline-sim" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index cfae52c5..b312001e 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-device-support" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/isa/Cargo.toml b/isa/Cargo.toml index c003caf7..5fe8539c 100644 --- a/isa/Cargo.toml +++ b/isa/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-isa" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/isa/src/macros.rs b/isa/src/macros.rs index 1d416191..7c48d0ba 100644 --- a/isa/src/macros.rs +++ b/isa/src/macros.rs @@ -381,7 +381,7 @@ mod tests { #[test] fn misc() { let insn = - insn!(AND R0, R0, R0, => Unfortunately we'll take trailing commas, but don't do this!); + insn!(AND R0, R0, R0, => Unfortunately we will take trailing commas, but please do not do this!); assert_eq!(insn, insn!(AND R0, R0, R0)); diff --git a/macros/Cargo.toml b/macros/Cargo.toml index f792ac78..2c5a29e6 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-macros" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/os/Cargo.toml b/os/Cargo.toml index ce4d8015..5a294cf7 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-os" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/shims/Cargo.toml b/shims/Cargo.toml index 67ac8a6c..a22647d3 100644 --- a/shims/Cargo.toml +++ b/shims/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-shims" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." diff --git a/test-infrastructure/Cargo.toml b/test-infrastructure/Cargo.toml index 3702b9a1..f506324f 100644 --- a/test-infrastructure/Cargo.toml +++ b/test-infrastructure/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-test-infrastructure" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" publish = false # Only really useful for us workspace = ".." diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 774abb52..31ae2920 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -2,7 +2,7 @@ name = "lc3-traits" version = "0.1.0" authors = ["UT UTP "] -edition = "2018" +edition = "2021" workspace = ".." From 0e25f0e7f5b0d6cc9d9661dc2d95df1e745b8962 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:28:47 -0500 Subject: [PATCH 17/25] build: switch to having a global list of lints the comment in .cargo/config outlines the upsides and downsides pretty well but just to recap, quickly: - this is nice because it lets us: + avoid duplicating the same list of lints across all the crates + avoid blocking the build on these lints passing + give developers an easy way to run the same set of lints that CI will run without needing to push/make a PR/etc. - the downsides are that: + this does not integrate with your editor in the future we'd want a solution like clippy.toml if we're okay with requiring that developers install something, cargo-cranky works today and works great as a `cargo clippy` replacement with rust-analyzer so you can get the lint errors in your editor but for now, this will do --- .cargo/config | 35 ++++++++++++++++++++++++++++ application-support/src/lib.rs | 37 ------------------------------ baseline-sim/src/lib.rs | 42 ---------------------------------- device-support/src/lib.rs | 37 ------------------------------ isa/src/lib.rs | 37 ------------------------------ macros/src/lib.rs | 37 ------------------------------ os/src/lib.rs | 39 ++----------------------------- shims/src/lib.rs | 37 ------------------------------ test-infrastructure/src/lib.rs | 36 ----------------------------- traits/src/lib.rs | 37 ------------------------------ 10 files changed, 37 insertions(+), 337 deletions(-) diff --git a/.cargo/config b/.cargo/config index 4e0eaca3..b8e10f46 100644 --- a/.cargo/config +++ b/.cargo/config @@ -14,3 +14,38 @@ docs = [ docs-stable = [ "doc", "--all", "--document-private-items" ] + +# We put this list here instead of in `lib.rs`/`main.rs`/CI workflows for a +# couple of reasons: +# 1) We'd like to not have to duplicate/update this list in every crate in +# this workspace +# 2) For local development, we want running these lints to be _opt in_. +# Having, for example, missing documentation prevent you from compiling +# and testing while you're still figuring out how to implement something +# is counterproductive. +# +# These lints *are* enforced by CI however we don't want to put this list +# in the CI workflow definition either because: we still want to have an +# easy way for developers to run exactly the checks CI will run, locally. +# +# The downside to this approach, as detailed in `.vscode/core.code-workspace`, +# is that this alias does not play well with rust analyzer so there isn't an +# easy way for developers to see these errors in their editor. +# +# In the future we may want to switch to: +# - clippy.toml, when it is implemented +# + https://github.com/rust-lang/rust-clippy/issues/1313 +# + https://github.com/rust-lang/cargo/issues/5034 +# - `cargo-cranky`, if we decide we're okay requiring developers to install it +# + https://github.com/ericseppanen/cargo-cranky +# + this supports rustc lints and also plays well with `rust-analyzer` +clippy-all = ["clippy", "--all", "--all-features", "--all-targets", "--", + ### [rustc] allow by default lints: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html + + ### [rustc] warn by default lints: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html + + ### [rustc] deny by default lints: https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html + +] +lint = ["clippy-all"] + diff --git a/application-support/src/lib.rs b/application-support/src/lib.rs index e4419aa1..6ff30463 100644 --- a/application-support/src/lib.rs +++ b/application-support/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/baseline-sim/src/lib.rs b/baseline-sim/src/lib.rs index 7caa36ad..5dd9d963 100644 --- a/baseline-sim/src/lib.rs +++ b/baseline-sim/src/lib.rs @@ -2,48 +2,6 @@ //! //! TODO! -// #![feature(try_trait)] - -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] - -#![warn(clippy::missing_docs_in_private_items)] // TODO: add to all - #![doc(test(attr(deny(warnings))))] #![doc(html_logo_url = "")] // TODO! // TODO: add doc URL to all diff --git a/device-support/src/lib.rs b/device-support/src/lib.rs index 2aa59a2c..e47a2bfd 100644 --- a/device-support/src/lib.rs +++ b/device-support/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/isa/src/lib.rs b/isa/src/lib.rs index df5eb621..2f144b80 100644 --- a/isa/src/lib.rs +++ b/isa/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/macros/src/lib.rs b/macros/src/lib.rs index cbe715e8..19d0e943 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/os/src/lib.rs b/os/src/lib.rs index 2c0cf020..33f96d6a 100644 --- a/os/src/lib.rs +++ b/os/src/lib.rs @@ -2,44 +2,9 @@ //! //! TODO! +// The OS's `program! { }` macro needs this! #![recursion_limit = "2048"] -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] + #![doc(test(attr(deny(warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/shims/src/lib.rs b/shims/src/lib.rs index 0e169acf..3773197d 100644 --- a/shims/src/lib.rs +++ b/shims/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/test-infrastructure/src/lib.rs b/test-infrastructure/src/lib.rs index 1154a4f9..07c67136 100644 --- a/test-infrastructure/src/lib.rs +++ b/test-infrastructure/src/lib.rs @@ -1,41 +1,5 @@ //! Functions and bits that are useful for testing the interpreter. -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! diff --git a/traits/src/lib.rs b/traits/src/lib.rs index cb86e1f7..9c9707b9 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -2,43 +2,6 @@ //! //! TODO! -// TODO: forbid -#![warn( - bad_style, - const_err, - dead_code, - improper_ctypes, - legacy_directory_ownership, - non_shorthand_field_patterns, - no_mangle_generic_items, - overflowing_literals, - path_statements, - patterns_in_fns_without_body, - plugin_as_library, - private_in_public, - safe_extern_statics, - unconditional_recursion, - unused, - unused_allocation, - unused_lifetimes, - unused_comparisons, - unused_parens, - while_true -)] -// TODO: deny -#![warn( - missing_debug_implementations, - intra_doc_link_resolution_failure, - missing_docs, - unsafe_code, - trivial_casts, - trivial_numeric_casts, - unused_extern_crates, - unused_import_braces, - unused_qualifications, - unused_results, - rust_2018_idioms -)] #![doc(test(attr(deny(rust_2018_idioms, warnings))))] #![doc(html_logo_url = "")] // TODO! From 0456cd2864b7f1afc4cc9e309cee728c67be41cd Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:32:23 -0500 Subject: [PATCH 18/25] build: tweak docs.rs settings --- application-support/Cargo.toml | 7 ++++--- baseline-sim/Cargo.toml | 7 ++++--- device-support/Cargo.toml | 7 ++++--- isa/Cargo.toml | 7 ++++--- macros/Cargo.toml | 7 ++++--- os/Cargo.toml | 7 ++++--- shims/Cargo.toml | 7 ++++--- traits/Cargo.toml | 7 ++++--- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/application-support/Cargo.toml b/application-support/Cargo.toml index b90fe661..45c7bcf6 100644 --- a/application-support/Cargo.toml +++ b/application-support/Cargo.toml @@ -48,7 +48,8 @@ wasm-bindgen-futures = "0.4" pretty_assertions = "1.2" [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/baseline-sim/Cargo.toml b/baseline-sim/Cargo.toml index 1ec034ed..05eed0df 100644 --- a/baseline-sim/Cargo.toml +++ b/baseline-sim/Cargo.toml @@ -48,7 +48,8 @@ default = [] std = ["lc3-traits/std", "lc3-isa/std"] [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/device-support/Cargo.toml b/device-support/Cargo.toml index b312001e..cd9c70ed 100644 --- a/device-support/Cargo.toml +++ b/device-support/Cargo.toml @@ -57,7 +57,8 @@ alloc = ["bytes"] host_transport = ["std", "serialport"] [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/isa/Cargo.toml b/isa/Cargo.toml index 5fe8539c..9a148e6b 100644 --- a/isa/Cargo.toml +++ b/isa/Cargo.toml @@ -48,7 +48,8 @@ strict = [] arbitrary = ["dep:arbitrary", "std"] [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 2c5a29e6..599b242b 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -41,7 +41,8 @@ syn = { version = "1.0.5" } # features = ["derive", "visit-mut", "parsing", "ful pretty_assertions = "1.2" [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/os/Cargo.toml b/os/Cargo.toml index 5a294cf7..99ec6513 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -50,7 +50,8 @@ path = "tests/trap_tests/mod.rs" default = [] [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/shims/Cargo.toml b/shims/Cargo.toml index a22647d3..9a0fff52 100644 --- a/shims/Cargo.toml +++ b/shims/Cargo.toml @@ -44,7 +44,8 @@ static_assertions = "1.1.0" lc3-test-infrastructure = { path = "../test-infrastructure", version = "0.1.0" } [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 31ae2920..145ef7cb 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -46,7 +46,8 @@ std = ["lc3-isa/std"] json_encoding_layer = ["std", "serde_json"] [package.metadata.docs.rs] -# targets = [""] -rustdoc-args = ["--cfg", "docs"] +targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "wasm32-unknown-unknown", "thumbv7em-none-eabihf"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] +rustdoc-args = ["--cfg", "docs"] # "--scrape-tests" all-features = true -# default-target = "" +default-target = "x86_64-unknown-linux-gnu" From 102d6a39d2eb31b1e545927fcf4f563da2ee4b0b Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:33:07 -0500 Subject: [PATCH 19/25] build: tweaks the rustdoc configuration the comments explain; similar kind of thing as the regular lints --- .cargo/config | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.cargo/config b/.cargo/config index b8e10f46..c04e0ffe 100644 --- a/.cargo/config +++ b/.cargo/config @@ -3,16 +3,45 @@ # Ordinarily we would just set this but: we don't want to break regular # `cargo doc` for developers that don't have a nightly toolchain installed. # rustdocflags = ["--cfg", "docs"] +# +# Instead, we provide the `docs` alias. +# +# Similar to regular lints and clippy lints (below), we want to have one place +# to stick our rustdoc lints. +# +# Sticking these in `rustdocflags` has two downsides: +# - these lints will not show up in your editor! +# - these lints block building docs! +# +# Unfortunately, I don't currently know of a better way. +# +# As a stopgap, we _do_ pass rustdoc `--cap-lints allow` in the `cargo docs` +# alias below but that requires nightly Rust. +rustdocflags = [ + ### [rustdoc] https://doc.rust-lang.org/rustdoc/lints.html + "--deny", "rustdoc::broken_intra_doc_links", + "--deny", "missing-docs", + "--deny", "rustdoc::missing_crate_level_docs", + "--deny", "rustdoc::bare_urls", + + # NOTE: `cargo` still sets `--cap-lints` when building docs for deps so + # these lints don't trigger there/break the docs build. +] + +# TODO: in CI, set RUSTDOCFLAGS to `--cap-lints forbid`. +# TODO: in CI, run rustdoc with "--show-coverage" [alias] # Requires `nightly` Rust! docs = [ - "-Z", "unstable-options", '--config=build.rustdocflags=["--cfg", "docs"]', - "doc", "--all", "--document-private-items", "--all-features" + "-Z", "unstable-options", + "-Z", "rustdoc-scrape-examples=examples", + '--config=build.rustdocflags=["--cfg", "docs", "-Zunstable-options", "--show-type-layout", "--cap-lints=allow"]', # `--scrape-examples`, '--check-cfg', '--generate-link-to-definition' + "doc", "--workspace", "--document-private-items", "--all-features", # "--bins", "--examples", ] # Stable equivalent of the above. docs-stable = [ - "doc", "--all", "--document-private-items" + "doc", "--workspace", "--document-private-items", "--all-features", # "--bins", "--examples" ] # We put this list here instead of in `lib.rs`/`main.rs`/CI workflows for a From dc714eaeaa180a5f0606239d09c3ef91e732f2cd Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:35:23 -0500 Subject: [PATCH 20/25] build: add some rustc lints --- .cargo/config | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/.cargo/config b/.cargo/config index c04e0ffe..d3fbf264 100644 --- a/.cargo/config +++ b/.cargo/config @@ -70,10 +70,93 @@ docs-stable = [ # + this supports rustc lints and also plays well with `rust-analyzer` clippy-all = ["clippy", "--all", "--all-features", "--all-targets", "--", ### [rustc] allow by default lints: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html + # "--warn", "fuzzy_provenance_casts", # nightly + "--deny", "keyword_idents", + # "--warn", "lossy_provenance_casts", # nightly + "--deny", "missing_abi", + "--deny", "missing_debug_implementations", + "--deny", "missing_docs", + # "--deny", "must_not_suspend", # nightly + # "--warn", "non_exhaustive_omitted_patterns", # TODO: might be too noisy # nightly + "--deny", "noop_method_call", + "--deny", "unreachable_pub", + "--deny", "unsafe_op_in_unsafe_fn", # We want separate "SAFETY" comments! + "--warn", "unused_crate_dependencies", # TODO: might be too noisy + "--warn", "unused_extern_crates", + "--deny", "unused_import_braces", + "--deny", "unused_lifetimes", + "--deny", "unused_macro_rules", + "--deny", "unused_qualifications", + "--deny", "unused_results", + "--deny", "variant_size_differences", ### [rustc] warn by default lints: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html + "--deny", "warnings", # TODO: maybe don't do this.. + "--deny", "asm_sub_register", + "--deny", "bad_asm_style", + "--deny", "bindings_with_variant_name", + "--deny", "clashing_extern_declarations", + "--deny", "coherence_leak_check", + "--deny", "const_evaluatable_unchecked", + "--deny", "const_item_mutation", + "--deny", "dead_code", + "--deny", "deprecated", + "--deny", "deprecated_cfg_attr_crate_type_name", + "--deny", "deprecated_where_clause_location", + "--deny", "deref_into_dyn_supertrait", + "--deny", "deref_nullptr", + "--deny", "duplicate_macro_attributes", + "--deny", "exported_private_dependencies", + "--deny", "forbidden_lint_groups", + "--deny", "improper_ctypes", + "--deny", "improper_ctypes_definitions", + "--deny", "invalid_doc_attributes", + "--deny", "invalid_value", + "--deny", "irrefutable_let_patterns", + "--deny", "large_assignments", + "--deny", "legacy_derive_helpers", + "--deny", "no_mangle_generic_items", + "--deny", "non_camel_case_types", + "--deny", "non_shorthand_field_patterns", + "--deny", "non_snake_case", + "--deny", "non_upper_case_globals", + "--deny", "overlapping_range_endpoints", + "--deny", "path_statements", + "--deny", "private_in_public", + "--deny", "redundant_semicolons", + "--deny", "renamed_and_removed_lints", + "--deny", "semicolon_in_expressions_from_macros", + "--deny", "suspicious_auto_trait_impls", + "--allow", "type_alias_bounds", + "--deny", "unconditional_recursion", + # "--deny", "undefined_naked_function_abi", # nightly + "--deny", "unexpected_cfgs", + "--deny", "unknown_lints", + "--deny", "unnameable_test_items", + "--deny", "unreachable_code", + "--deny", "unreachable_patterns", + "--deny", "unstable_name_collisions", + "--deny", "unsupported_calling_conventions", + "--deny", "unused_allocation", + "--deny", "unused_assignments", + "--deny", "unused_attributes", + "--deny", "unused_braces", + "--deny", "unused_comparisons", + "--deny", "unused_doc_comments", + "--deny", "unused_features", + "--deny", "unused_imports", + "--deny", "unused_macros", + "--deny", "unused_must_use", + "--deny", "unused_mut", + "--deny", "unused_parens", + "--deny", "unused_variables", + "--deny", "where_clauses_object_safety", + "--deny", "while_true", ### [rustc] deny by default lints: https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html + "--forbid", "macro_expanded_macro_exports_accessed_by_absolute_paths", + "--forbid", "unknown_crate_types", + ] lint = ["clippy-all"] From b76341cb528b6c0066945e191f03c1c28c43d730 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:35:44 -0500 Subject: [PATCH 21/25] build: add some clippy lints --- .cargo/config | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.cargo/config b/.cargo/config index d3fbf264..45dab573 100644 --- a/.cargo/config +++ b/.cargo/config @@ -157,7 +157,16 @@ clippy-all = ["clippy", "--all", "--all-features", "--all-targets", "--", "--forbid", "macro_expanded_macro_exports_accessed_by_absolute_paths", "--forbid", "unknown_crate_types", + ####### Clippy Lints: https://rust-lang.github.io/rust-clippy/master/ ####### + ### [clippy] cargo + "--deny", "clippy::cargo_common_metadata", + "--warn", "clippy::multiple_crate_versions", + "--deny", "clippy::negative_feature_names", + "--deny", "clippy::redundant_feature_names", + "--deny", "clippy::wildcard_dependencies", + + # TODO: peruse the other clippy lints (the defaults are pretty good though) ] lint = ["clippy-all"] From d17a7337da459554e2ca4d81db5f63e99221a5d6 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:36:01 -0500 Subject: [PATCH 22/25] build: add some cargo aliases --- .cargo/config | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.cargo/config b/.cargo/config index 45dab573..acd00880 100644 --- a/.cargo/config +++ b/.cargo/config @@ -44,6 +44,11 @@ docs-stable = [ "doc", "--workspace", "--document-private-items", "--all-features", # "--bins", "--examples" ] +build-all = ["build", "--workspace", "--all-features", "--all-targets"] +check-all = ["check", "--workspace", "--all-features", "--all-targets"] +fmt-all = ["fmt", "--workspace"] +test-all = ["test", "--workspace", "--all-features", "--all-targets", "--no-fail-fast"] + # We put this list here instead of in `lib.rs`/`main.rs`/CI workflows for a # couple of reasons: # 1) We'd like to not have to duplicate/update this list in every crate in @@ -170,3 +175,9 @@ clippy-all = ["clippy", "--all", "--all-features", "--all-targets", "--", ] lint = ["clippy-all"] +b = "build-all" +c = "check-all" +d = "docs-stable" +f = "fmt-all" +t = "test-all" +l = "lint" From a22feed46e25796cbc698fdd295f7b06f5a2fe25 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:38:04 -0500 Subject: [PATCH 23/25] docs: add the cargo aliases to the readme --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a20d52c5..68312704 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,29 @@ At the moment, the primary 'users' of the platform are the following: TODO: fill in +To check that the project _will_ build: + - `cargo c` or `cargo check-all` + +To actually build the project: + - `cargo b` or `cargo build-all` to build everything + - `cargo build -p ` to build a particular crate + + i.e. `cargo build -p lc3-isa` + +To run the project's tests: + - `cargo t` or `cargo test-all` to run all the tests + - `cargo test -p ` to run a particular crate's tests + +To run the project's benchmarks: + - `cargo bench` to run them all + - `cargo bench --bench ` to run a particular benchmark + To build the docs for the project: - `cargo +nightly docs` (`cargo-nightly docs` if using `nix`) + NOTE: this requires a nightly Rust toolchain! - + If you're on stable you can instead run: `cargo docs-stable` to get mostly identical output + + If you're on stable you can instead run: `cargo d` (or `cargo docs-stable`) to get mostly identical output + +To run the project's lints (that CI runs): + - `cargo lint` TODO: From a9d7177518f866caca69a17ab73a3e847eaae685 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:38:17 -0500 Subject: [PATCH 24/25] build: add a vscode workspace --- .vscode/core.code-workspace | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .vscode/core.code-workspace diff --git a/.vscode/core.code-workspace b/.vscode/core.code-workspace new file mode 100644 index 00000000..b537a403 --- /dev/null +++ b/.vscode/core.code-workspace @@ -0,0 +1,82 @@ +{ + "folders": [ + { "path": ".." } + ], + "settings": { + "files.exclude": { + "target": true + }, + + "rust-analyzer": { + "cargo.features": "all", + "checkOnSave": { + "allTargets": true, + "features": "all", + + // Note: we cannot actually use `lint` here because it cannot + // accept `cargo clippy` args `--workspace` and `--all-features` + // (because it uses `--` and passes the underlying clippy + // invocation args). + // + // This means developers must run the `lint` build task to see + // the errors CI will complain about *and* that there isn't an + // easy way for developers to see these errors in their editor. + "command": "clippy", + } + }, + }, + "extensions": { + "recommendations": [ + // Rust: + "rust-lang.rust-analyzer", + "bungcip.better-toml", + "serayuzgur.crates", + // Misc: + "eamodio.gitlens", + // Nix: + "jnoortheen.nix-ide", + "mkhl.direnv" + ] + }, + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "Build All", + "type": "cargo", + "command": "b", + "problemMatcher": ["$rustc"], + }, + { + "label": "Open Docs", + "type": "cargo", + "command": "d --open", + "problemMatcher": ["$rustc"], + }, + { + "label": "Format Workspace", + "type": "cargo", + "command": "f", + "problemMatcher": ["$rustc"], + }, + { + "label": "Test All", + "type": "cargo", + "command": "t", + "problemMatcher": ["$rustc"], + }, + { + "label": "Lint All", + "type": "cargo", + "command": "l", + "problemMatcher": ["$rustc"], + }, + { + "label": "Run Benchmarks", + "type": "cargo", + "command": "bench", + "problemMatcher": ["$rustc"], + } + ] + }, +} From d46b1da1c4c89bf663f99e105c1f1facda0f004e Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 11 Jul 2022 22:53:52 -0500 Subject: [PATCH 25/25] traits: fix one last warning --- traits/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/traits/src/lib.rs b/traits/src/lib.rs index 9c9707b9..ad8b76fa 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -18,6 +18,7 @@ macro_rules! using_std { ($($i:item)*) => ($( )*) } macro_rules! not_wasm { ($($i:item)*) => ($(#[cfg(not(target_arch = "wasm32"))]$i)*) } +#[allow(unused_macros)] macro_rules! wasm { ($($i:item)*) => ($(#[cfg(target_arch = "wasm32")]$i)*) } extern crate static_assertions as sa;